2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "DefineVideoStreamTag.h"
23 #include "RunResources.h"
24 #include "VideoFrameTag.h"
25 #include "VideoDecoder.h"
26 #include "SWFStream.h" // for read()
27 #include "movie_definition.h"
29 #include "smart_ptr.h"
36 VideoFrameTag::loader(SWFStream
& in
, SWF::TagType tag
, movie_definition
& m
,
37 const RunResources
& /*r*/)
39 assert(tag
== SWF::VIDEOFRAME
);
42 boost::uint16_t id
= in
.read_u16();
43 DefinitionTag
* chdef
= m
.getDefinitionTag(id
);
47 IF_VERBOSE_MALFORMED_SWF(
48 log_swferror(_("VideoFrame tag refers to unknown video "
54 DefineVideoStreamTag
* vs
= dynamic_cast<DefineVideoStreamTag
*> (chdef
);
57 IF_VERBOSE_MALFORMED_SWF(
58 log_swferror(_("VideoFrame tag refers to a non-video DisplayObject "
59 "%d (%s)"), id
, typeName(*chdef
));
64 // TODO: skip if there's no MediaHandler registered ?
66 const unsigned short padding
= 8;
69 unsigned int frameNum
= in
.read_u16();
71 const unsigned int dataLength
= in
.get_tag_end_position() - in
.tell();
73 // FIXME: catch bad_alloc
74 boost::uint8_t* buffer
= new boost::uint8_t[dataLength
+ padding
];
76 const size_t bytesRead
= in
.read(reinterpret_cast<char*>(buffer
),
79 if (bytesRead
< dataLength
)
81 throw ParserException(_("Could not read enough bytes when parsing "
82 "VideoFrame tag. Perhaps we reached the "
83 "end of the stream!"));
86 std::fill_n(buffer
+ bytesRead
, padding
, 0);
88 using namespace media
;
90 std::auto_ptr
<EncodedVideoFrame
> frame(
91 new EncodedVideoFrame(buffer
, dataLength
, frameNum
));
93 vs
->addVideoFrameTag(frame
);