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 <boost/shared_array.hpp>
23 #include <boost/thread/mutex.hpp>
24 #include <boost/ptr_container/ptr_vector.hpp>
25 #include <memory>
26 #include <vector>
27 
28 #include "DefinitionTag.h"
29 #include "SWF.h"
30 #include "SWFRect.h" // for composition
31 #include "MediaParser.h" // for videoFrameType and videoCodecType enums
32 
33 // Forward declarations
34 namespace gnash {
35  class movie_definition;
36  class SWFStream;
37  class RunResources;
38 }
39 
40 namespace gnash {
41 
44 class VideoData
45 {
46 public:
47  VideoData(boost::shared_array<boost::uint8_t> data, boost::uint32_t size,
49  :
50  videoData(data),
51  dataSize(size),
52  frameType(ft)
53  {
54  }
55 
57  {
58  }
59 
60  boost::shared_array<boost::uint8_t> videoData;
61  boost::uint32_t dataSize;
63 };
64 
65 namespace SWF {
66 
68 {
69 
71  //
74  typedef boost::ptr_vector<media::EncodedVideoFrame> EmbeddedFrames;
75 
77  //
81  struct FrameFinder
82  {
83  typedef EmbeddedFrames::const_reference Frame;
84 
85  bool operator()(Frame frame, size_t i) const {
86  return frame.frameNum() < i;
87  }
88 
89  bool operator()(size_t i, Frame frame) const {
90  return i < frame.frameNum();
91  }
92  };
93 
94 public:
95 
97 
99  const;
100 
102  //
108  static void loader(SWFStream& in, SWF::TagType tag, movie_definition& m,
109  const RunResources& r);
110 
111 
113  //
120  movie_definition& m);
121 
123  const SWFRect& bounds() const {
124  return m_bound;
125  }
126 
128  //
132  media::VideoInfo* getVideoInfo() const { return _videoInfo.get(); }
133 
135  //
140  template<typename T>
141  size_t visitSlice(const T& t, boost::uint32_t from, boost::uint32_t to) const {
142 
143  boost::mutex::scoped_lock lock(_video_mutex);
144 
145  // It's assumed that frame numbers are in order.
146  EmbeddedFrames::const_iterator lower = std::lower_bound(
147  _video_frames.begin(), _video_frames.end(), from, FrameFinder());
148 
149  EmbeddedFrames::const_iterator upper = std::upper_bound(
150  lower, _video_frames.end(), to, FrameFinder());
151 
152  std::for_each(lower, upper, t);
153  return (upper - lower);
154  }
155 
156  void addVideoFrameTag(std::auto_ptr<media::EncodedVideoFrame> frame);
157 
158 private:
159 
161  //
167  DefineVideoStreamTag(SWFStream& in, boost::uint16_t id);
168 
169  void read(SWFStream& in);
170 
172  boost::uint8_t m_reserved_flags;
173 
175  boost::uint8_t m_deblocking_flags;
176 
178  bool m_smoothing_flags;
179 
181  //boost::uint16_t m_start_frame;
182 
186  boost::uint16_t m_num_frames;
187 
189  //
196  media::videoCodecType m_codec_id;
197 
199  SWFRect m_bound;
200 
201  // Mutable for locking in const member functions.
202  mutable boost::mutex _video_mutex;
203 
204  EmbeddedFrames _video_frames;
205 
207  boost::uint32_t _width;
208 
210  boost::uint32_t _height;
211 
213  //
216  std::auto_ptr<media::VideoInfo> _videoInfo;
217 
218 };
219 
220 } // namespace SWF
221 } // namespace gnash
222 
223 
224 #endif // GNASH_VIDEO_STREAM_DEF_H
Client program's interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:692
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
void readDefineVideoFrame(SWFStream &in, SWF::TagType tag, movie_definition &m)
Read tag SWF::VIDEOFRAME.
Information about a video stream.
Definition: MediaParser.h:289
media::VideoInfo * getVideoInfo() const
Get info about video embedded in this definition.
Definition: DefineVideoStreamTag.h:132
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
Immutable data representing the definition of a movie display element.
Definition: DefinitionTag.h:48
Definition: GnashKey.h:164
boost::shared_array< boost::uint8_t > videoData
Definition: DefineVideoStreamTag.h:60
Definition: GnashKey.h:166
static void loader(SWFStream &in, SWF::TagType tag, movie_definition &m, const RunResources &r)
Read tag SWF::DEFINEVIDEOSTREAM.
Definition: DefineVideoStreamTag.cpp:55
videoFrameType
Video frame types.
Definition: MediaParser.h:53
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:43
DisplayObject * createDisplayObject(Global_as &gl, DisplayObject *parent) const
Create a DisplayObject with the given parent.
Definition: DefineVideoStreamTag.cpp:116
videoCodecType
Video codec ids as defined in flash.
Definition: MediaParser.h:76
VideoData(boost::shared_array< boost::uint8_t > data, boost::uint32_t size, media::videoFrameType ft)
Definition: DefineVideoStreamTag.h:47
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:55
media::videoFrameType frameType
Definition: DefineVideoStreamTag.h:62
Definition: DefineVideoStreamTag.h:67
size_t visitSlice(const T &t, boost::uint32_t from, boost::uint32_t to) const
Visit a slice of encoded video frames.
Definition: DefineVideoStreamTag.h:141
Definition: GnashKey.h:132
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
~DefineVideoStreamTag()
Definition: DefineVideoStreamTag.cpp:49
Definition: GnashKey.h:155
void addVideoFrameTag(std::auto_ptr< media::EncodedVideoFrame > frame)
Definition: DefineVideoStreamTag.cpp:108
Definition: GnashKey.h:159
boost::uint32_t dataSize
Definition: DefineVideoStreamTag.h:61
const SWFRect & bounds() const
Return local video bounds in twips.
Definition: DefineVideoStreamTag.h:123
~VideoData()
Definition: DefineVideoStreamTag.h:56
Definition: DefineVideoStreamTag.h:44
Definition: GnashKey.h:331
SWF stream wrapper class.
Definition: SWFStream.h:58