Gnash  0.8.10
DefineVideoStreamTag.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_SWF_DEFINEVIDEOSTREAMTAG_H
00020 #define GNASH_SWF_DEFINEVIDEOSTREAMTAG_H
00021 
00022 #include <boost/shared_array.hpp>
00023 #include <boost/thread/mutex.hpp>
00024 #include <boost/ptr_container/ptr_vector.hpp>
00025 #include <memory> 
00026 #include <vector> 
00027 
00028 #include "DefinitionTag.h"
00029 #include "SWF.h"
00030 #include "SWFRect.h" // for composition
00031 #include "MediaParser.h" // for videoFrameType and videoCodecType enums
00032 
00033 // Forward declarations
00034 namespace gnash {
00035     class movie_definition;
00036     class SWFStream;
00037     class RunResources;
00038 }
00039 
00040 namespace gnash {
00041 
00044 class VideoData
00045 {
00046 public:
00047         VideoData(boost::shared_array<boost::uint8_t> data, boost::uint32_t size,
00048             media::videoFrameType ft)
00049                 :
00050                 videoData(data),
00051                 dataSize(size),
00052                 frameType(ft)
00053         {
00054         }
00055 
00056         ~VideoData()
00057         {
00058         }
00059 
00060         boost::shared_array<boost::uint8_t> videoData;
00061         boost::uint32_t dataSize;
00062         media::videoFrameType frameType;
00063 };
00064 
00065 namespace SWF {
00066 
00067 class DefineVideoStreamTag : public DefinitionTag
00068 {
00069         
00071         //
00074         typedef boost::ptr_vector<media::EncodedVideoFrame> EmbeddedFrames;
00075 
00077     //
00081     struct FrameFinder
00082     {
00083         typedef EmbeddedFrames::const_reference Frame;
00084 
00085         bool operator()(Frame frame, size_t i) const {
00086             return frame.frameNum() < i;
00087         }
00088         
00089         bool operator()(size_t i, Frame frame) const {
00090             return i < frame.frameNum();
00091         }
00092     };
00093 
00094 public:
00095 
00096         ~DefineVideoStreamTag();
00097 
00098         DisplayObject* createDisplayObject(Global_as& gl, DisplayObject* parent)
00099         const;
00100 
00102         //
00108         static void loader(SWFStream& in, SWF::TagType tag, movie_definition& m,
00109             const RunResources& r);
00110 
00111 
00113         //
00119         void readDefineVideoFrame(SWFStream& in, SWF::TagType tag,
00120             movie_definition& m);
00121 
00123         const SWFRect& bounds() const {
00124                 return m_bound;
00125         }
00126 
00128         //
00132         media::VideoInfo* getVideoInfo() const { return _videoInfo.get(); }
00133 
00135         //
00140     template<typename T>
00141     size_t visitSlice(const T& t, boost::uint32_t from, boost::uint32_t to) const {
00142 
00143         boost::mutex::scoped_lock lock(_video_mutex);
00144 
00145         // It's assumed that frame numbers are in order.
00146         EmbeddedFrames::const_iterator lower = std::lower_bound(
00147                 _video_frames.begin(), _video_frames.end(), from, FrameFinder());
00148 
00149         EmbeddedFrames::const_iterator upper = std::upper_bound(
00150                 lower, _video_frames.end(), to, FrameFinder());
00151 
00152         std::for_each(lower, upper, t);
00153         return (upper - lower);
00154     }
00155     
00156     void addVideoFrameTag(std::auto_ptr<media::EncodedVideoFrame> frame);
00157 
00158 private:
00159 
00161         //
00167         DefineVideoStreamTag(SWFStream& in, boost::uint16_t id);
00168 
00169         void read(SWFStream& in);
00170 
00172         boost::uint8_t m_reserved_flags;
00173 
00175         boost::uint8_t m_deblocking_flags;
00176 
00178         bool m_smoothing_flags;
00179 
00181         //boost::uint16_t m_start_frame;
00182 
00186         boost::uint16_t m_num_frames;
00187 
00189         //
00196         media::videoCodecType m_codec_id;
00197 
00199         SWFRect m_bound;
00200 
00201     // Mutable for locking in const member functions.
00202         mutable boost::mutex _video_mutex;
00203         
00204         EmbeddedFrames _video_frames;
00205 
00207         boost::uint32_t _width;
00208 
00210         boost::uint32_t _height;
00211 
00213         //
00216         std::auto_ptr<media::VideoInfo> _videoInfo;
00217 
00218 };
00219 
00220 } // namespace SWF
00221 } // namespace gnash
00222 
00223 
00224 #endif // GNASH_VIDEO_STREAM_DEF_H