Gnash  0.8.11dev
DefineVideoStreamTag.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
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.
9 //
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.
14 //
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
18 
19 #ifndef GNASH_SWF_DEFINEVIDEOSTREAMTAG_H
20 #define GNASH_SWF_DEFINEVIDEOSTREAMTAG_H
21 
22 #include <mutex>
23 #include <boost/ptr_container/ptr_vector.hpp>
24 #include <memory>
25 #include <vector>
26 
27 #include "DefinitionTag.h"
28 #include "SWF.h"
29 #include "SWFRect.h" // for composition
30 #include "MediaParser.h" // for videoFrameType and videoCodecType enums
31 
32 // Forward declarations
33 namespace gnash {
34  class movie_definition;
35  class SWFStream;
36  class RunResources;
37 }
38 
39 namespace gnash {
40 
41 namespace SWF {
42 
44 {
45 
47  //
50  typedef boost::ptr_vector<media::EncodedVideoFrame> EmbeddedFrames;
51 
53  //
57  struct FrameFinder
58  {
59  typedef EmbeddedFrames::const_reference Frame;
60 
61  bool operator()(Frame frame, size_t i) const {
62  return frame.frameNum() < i;
63  }
64 
65  bool operator()(size_t i, Frame frame) const {
66  return i < frame.frameNum();
67  }
68  };
69 
70 public:
71 
73 
75  const;
76 
78  //
84  static void loader(SWFStream& in, SWF::TagType tag, movie_definition& m,
85  const RunResources& r);
86 
87 
89  //
97 
99  const SWFRect& bounds() const {
100  return m_bound;
101  }
102 
104  //
108  media::VideoInfo* getVideoInfo() const { return _videoInfo.get(); }
109 
111  //
116  template<typename T>
117  size_t visitSlice(const T& t, std::uint32_t from, std::uint32_t to) const {
118 
119  std::lock_guard<std::mutex> lock(_video_mutex);
120 
121  // It's assumed that frame numbers are in order.
122  EmbeddedFrames::const_iterator lower = std::lower_bound(
123  _video_frames.begin(), _video_frames.end(), from, FrameFinder());
124 
125  EmbeddedFrames::const_iterator upper = std::upper_bound(
126  lower, _video_frames.end(), to, FrameFinder());
127 
128  std::for_each(lower, upper, t);
129  return (upper - lower);
130  }
131 
132  void addVideoFrameTag(std::unique_ptr<media::EncodedVideoFrame> frame);
133 
134 private:
135 
137  //
143  DefineVideoStreamTag(SWFStream& in, std::uint16_t id);
144 
145  void read(SWFStream& in);
146 
148  std::uint8_t m_reserved_flags;
149 
151  std::uint8_t m_deblocking_flags;
152 
154  bool m_smoothing_flags;
155 
157  //std::uint16_t m_start_frame;
158 
162  std::uint16_t m_num_frames;
163 
165  //
172  media::videoCodecType m_codec_id;
173 
175  SWFRect m_bound;
176 
177  // Mutable for locking in const member functions.
178  mutable std::mutex _video_mutex;
179 
180  EmbeddedFrames _video_frames;
181 
183  std::uint32_t _width;
184 
186  std::uint32_t _height;
187 
189  //
192  std::unique_ptr<media::VideoInfo> _videoInfo;
193 
194 };
195 
196 } // namespace SWF
197 } // namespace gnash
198 
199 
200 #endif // GNASH_VIDEO_STREAM_DEF_H
Video_as.h
gnash::SWF::DefineVideoStreamTag::addVideoFrameTag
void addVideoFrameTag(std::unique_ptr< media::EncodedVideoFrame > frame)
Definition: DefineVideoStreamTag.cpp:107
gnash::SWF::DefineVideoStreamTag
Definition: DefineVideoStreamTag.h:44
gnash::SWFRect::expand_to_point
void expand_to_point(std::int32_t x, std::int32_t y)
Expand this rectangle to enclose the given point.
Definition: SWFRect.h:171
gnash::SWFStream::read_uint
unsigned read_uint(unsigned short bitcount)
Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the...
Definition: SWFStream.cpp:102
gnash::SWF::DefineVideoStreamTag::createDisplayObject
DisplayObject * createDisplayObject(Global_as &gl, DisplayObject *parent) const
Create a DisplayObject with the given parent.
Definition: DefineVideoStreamTag.cpp:115
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::SWF::TagType
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:31
gnash::key::T
@ T
Definition: GnashKey.h:132
gnash::SWF::DefinitionTag
Immutable data representing the definition of a movie display element.
Definition: DefinitionTag.h:48
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::key::i
@ i
Definition: GnashKey.h:155
Video.h
gnash::pixelsToTwips
std::int32_t pixelsToTwips(double a)
Definition: GnashNumeric.h:144
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::createVideoObject
as_object * createVideoObject(Global_as &gl)
Native function to create a plain object with Video properties.
Definition: Video_as.cpp:46
gnash::SWF::DefineVideoStreamTag::visitSlice
size_t visitSlice(const T &t, std::uint32_t from, std::uint32_t to) const
Visit a slice of encoded video frames.
Definition: DefineVideoStreamTag.h:117
gnash::media::VideoInfo
Information about a video stream.
Definition: MediaParser.h:323
gnash::key::m
@ m
Definition: GnashKey.h:159
Global_as.h
SWFRect.h
gnash::movie_definition
Client program's interface to the definition of a movie or sprite.
Definition: movie_definition.h:96
gnash::SWF::DefineVideoStreamTag::getVideoInfo
media::VideoInfo * getVideoInfo() const
Get info about video embedded in this definition.
Definition: DefineVideoStreamTag.h:108
gnash::SWFRect
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:45
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::SWFRect::set_to_point
void set_to_point(std::int32_t x, std::int32_t y)
Set ourself to bound the given point.
Definition: SWFRect.h:154
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::Video
VideoStream ActionScript object.
Definition: Video.h:50
gnash::SWF::DefineVideoStreamTag::loader
static void loader(SWFStream &in, SWF::TagType tag, movie_definition &m, const RunResources &r)
Read tag SWF::DEFINEVIDEOSTREAM.
Definition: DefineVideoStreamTag.cpp:54
gnash::SWF::DefineVideoStreamTag::~DefineVideoStreamTag
~DefineVideoStreamTag()
Definition: DefineVideoStreamTag.cpp:48
MediaParser.h
gnash::media::CODEC_TYPE_FLASH
@ CODEC_TYPE_FLASH
The internal flash codec ids.
Definition: MediaParser.h:68
VideoDecoder.h
GnashNumeric.h
gnash::RunResources
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:54
IF_VERBOSE_PARSE
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
gnash::SWF::DefineVideoStreamTag::bounds
const SWFRect & bounds() const
Return local video bounds in twips.
Definition: DefineVideoStreamTag.h:99
gnash::media::videoCodecType
videoCodecType
Video codec ids as defined in flash.
Definition: MediaParser.h:76
DefinitionTag.h
SWF.h
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
gnash::SWFStream::read_u16
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
RunResources.h
gnash::SWF::DefineVideoStreamTag::readDefineVideoFrame
void readDefineVideoFrame(SWFStream &in, SWF::TagType tag, movie_definition &m)
Read tag SWF::VIDEOFRAME.
DefineVideoStreamTag.h
gnash::SWFStream::read_u8
std::uint8_t read_u8()
Read a aligned unsigned 8-bit value from the stream.
Definition: SWFStream.cpp:319
gnash::SWFStream::read_bit
bool read_bit()
Reads a single bit off the stream and returns it.
Definition: SWFStream.cpp:88
movie_definition.h
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::SWFStream
SWF stream wrapper class.
Definition: SWFStream.h:59
gnash::SWFStream::ensureBytes
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag.
Definition: SWFStream.cpp:50
gnash::key::SWF
@ SWF
Definition: GnashKey.h:331
SWFStream.h
gnash::SWF::DEFINEVIDEOSTREAM
@ DEFINEVIDEOSTREAM
Definition: SWF.h:90