Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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>
00026 #include <boost/shared_ptr.hpp>
00027
00028
00029 #include "element.h"
00030 #include "buffer.h"
00031 #include "dsodefs.h"
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
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
00100 AUDIO_VORBIS = 0x7
00101 } flv_sound_format_e;
00102
00103
00104
00108 typedef enum {
00109 VIDEO_NONE = 0x0,
00110 VIDEO_H263 = 0x2,
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];
00148 boost::uint8_t version;
00149 boost::uint8_t type;
00150 boost::uint8_t head_size[4];
00151 } flv_header_t;
00152
00154 typedef struct {
00155 boost::uint8_t type;
00156 boost::uint8_t bodysize[3];
00157 boost::uint8_t timestamp[3];
00158 boost::uint8_t extended;
00159 boost::uint8_t streamid[3];
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
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 };
00269
00270
00271 }
00272
00273
00274 #endif
00275
00276
00277
00278
00279