• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

flv.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   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_FLV_H
00020 #define GNASH_FLV_H
00021 
00022 #include <vector>
00023 #include <string>
00024 #include <cstring>
00025 #include <boost/cstdint.hpp>    // for boost::?int??_t
00026 #include <boost/shared_ptr.hpp>
00027 
00028 //#include "buffer.h"
00029 #include "element.h"
00030 #include "buffer.h"
00031 #include "dsodefs.h" // DSOEXPORT
00032 
00036 namespace cygnal
00037 {
00038 
00040 const size_t FLV_HEADER_SIZE = 0x9;
00041 
00043 const boost::uint32_t FLV_MAX_LENGTH = 0xffffff;
00044 
00047 class DSOEXPORT Flv {
00048   public:
00051     typedef boost::uint32_t previous_size_t;
00054     typedef enum {
00055         FLV_VIDEO = 0x1,
00056         FLV_AUDIO = 0x4
00057     } flv_type_e;
00060     typedef enum {
00061         TAG_VIDEO = 0x8,
00062         TAG_AUDIO = 0x9,
00063         TAG_METADATA = 0x12
00064     } flv_tag_type_e;
00065     // The Audio Tag types
00066     
00070     typedef enum {
00071         AUDIO_MONO = 0x0,
00072         AUDIO_STEREO = 0x1
00073     } flv_sound_type_e;
00077     typedef enum {
00078         AUDIO_8BIT = 0x0,
00079         AUDIO_16BIT = 0x1
00080     } flv_sound_size_e;
00084     typedef enum {
00085         AUDIO_55KHZ = 0x0,
00086         AUDIO_11KHZ = 0x1,
00087         AUDIO_22KHZ = 0x2,
00088         AUDIO_44KHZ = 0x3
00089     } flv_sound_rate_e;
00093     typedef enum {
00094         AUDIO_UNCOMPRESSED = 0x0,
00095         AUDIO_ADPCM = 0x1,
00096         AUDIO_MP3 = 0x2,
00097         AUDIO_NELLYMOSER_8KHZ = 0x5,
00098         AUDIO_NELLYMOSER = 0x6,
00099         // These next are only supported by Gnash
00100         AUDIO_VORBIS = 0x7
00101     } flv_sound_format_e;
00102 
00103     // Video Tag types
00104     
00108     typedef enum {
00109         VIDEO_NONE = 0x0,
00110         VIDEO_H263 = 0x2,       // sorenson
00111         VIDEO_SCREEN = 0x3,
00112         VIDEO_VP6 = 0x4,
00113         VIDEO_VP6_ALPHA = 0x5,
00114         VIDEO_SCREEN2 = 0x6,
00115         VIDEO_THEORA = 0x7,
00116         VIDEO_DIRAC = 0x8,
00117         VIDEO_SPEEX = 0x9
00118     } flv_video_codec_e;
00119     
00123     typedef enum {
00124         NO_FRAME = 0x0,
00125         KEYFRAME = 0x1,
00126         INTERFRAME = 0x2,
00127         DISPOSABLE = 0x3
00128     } flv_video_frame_type_e;
00129 
00131     typedef struct {
00132         flv_sound_type_e   type;
00133         flv_sound_size_e   size;
00134         flv_sound_rate_e   rate;
00135         flv_sound_format_e format;
00136     } flv_audio_t;
00138     typedef struct {
00139         flv_video_codec_e codecID;
00140         flv_video_frame_type_e type;
00141     } flv_video_t;
00142 
00144     
00146     typedef struct {
00147         boost::uint8_t  sig[3];      // always "FLV"
00148         boost::uint8_t  version;     // version, always seems to be 1
00149         boost::uint8_t  type;        // Bitmask: 0x4 for audio, 0x1 for video
00150         boost::uint8_t  head_size[4];// size of header, always seems to be 9
00151     } flv_header_t;
00152 
00154     typedef struct {
00155         boost::uint8_t  type;         // the type. audio, video, or meta
00156         boost::uint8_t  bodysize[3];  // body size (tag size - sizeof(flv_tag_t))
00157         boost::uint8_t  timestamp[3]; // timestamp in milliseconds
00158         boost::uint8_t  extended;     // extended timestamp
00159         boost::uint8_t  streamid[3];  // always 0
00160     } flv_tag_t;
00161     
00162     Flv();
00163     ~Flv();
00164 
00170     boost::shared_ptr<cygnal::Buffer> encodeHeader(boost::uint8_t type);
00171     
00177     boost::shared_ptr<flv_header_t> decodeHeader(boost::shared_ptr<cygnal::Buffer> buf) { return decodeHeader(buf->reference()); };
00178     boost::shared_ptr<flv_header_t> decodeHeader(boost::uint8_t *data);
00179 
00186     boost::shared_ptr<cygnal::Element> decodeMetaData(boost::shared_ptr<cygnal::Buffer> buf);
00187 
00196     boost::shared_ptr<cygnal::Element> decodeMetaData(boost::uint8_t *data, size_t size);
00197 
00203     boost::shared_ptr<flv_audio_t> decodeAudioData(boost::uint8_t flags);
00204 
00210     boost::shared_ptr<flv_video_t> decodeVideoData(boost::uint8_t flags);
00211     
00217     boost::shared_ptr<flv_tag_t> decodeTagHeader(boost::shared_ptr<cygnal::Buffer> &buf) { return decodeTagHeader(buf->reference()); };
00218     boost::shared_ptr<flv_tag_t> decodeTagHeader(boost::uint8_t *data);
00219 
00226     boost::shared_ptr<cygnal::Element> findProperty(const std::string &name);
00227 
00233     void setProperties(std::vector<boost::shared_ptr<cygnal::Element> > array)
00234                         { _properties = array; };
00235 
00239     boost::uint32_t convert24(boost::uint8_t *);
00240     
00243     void dump();
00244     
00245   private:
00248     flv_header_t                _header;
00249     
00250 //    boost::uint32_t             _previous_tag_size;
00256     flv_tag_t                   _tag;
00257 
00261     std::vector<boost::shared_ptr<cygnal::Element> > _properties;
00262 
00266     boost::shared_ptr<cygnal::Element> _metadata;
00267     
00268 }; // end of class definition
00269 
00270 
00271 } // end of amf namespace
00272 
00273 // end of _FLV_H_
00274 #endif
00275 
00276 // local Variables:
00277 // mode: C++
00278 // indent-tabs-mode: t
00279 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1