libavformat/oggdec.h
Go to the documentation of this file.
00001 
00025 #ifndef AVFORMAT_OGGDEC_H
00026 #define AVFORMAT_OGGDEC_H
00027 
00028 #include "avformat.h"
00029 #include "metadata.h"
00030 
00031 struct ogg_codec {
00032     const int8_t *magic;
00033     uint8_t magicsize;
00034     const int8_t *name;
00041     int (*header)(AVFormatContext *, int);
00042     int (*packet)(AVFormatContext *, int);
00048     uint64_t (*gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts);
00053     int granule_is_start;
00054 };
00055 
00056 struct ogg_stream {
00057     uint8_t *buf;
00058     unsigned int bufsize;
00059     unsigned int bufpos;
00060     unsigned int pstart;
00061     unsigned int psize;
00062     unsigned int pflags;
00063     unsigned int pduration;
00064     uint32_t serial;
00065     uint64_t granule;
00066     int64_t lastpts;
00067     int64_t lastdts;
00068     int64_t sync_pos;   
00069     int64_t page_pos;   
00070     int flags;
00071     const struct ogg_codec *codec;
00072     int header;
00073     int nsegs, segp;
00074     uint8_t segments[255];
00075     int incomplete; 
00076     int page_end;   
00077     int keyframe_seek;
00078     int got_start;
00079     void *private;
00080 };
00081 
00082 struct ogg_state {
00083     uint64_t pos;
00084     int curidx;
00085     struct ogg_state *next;
00086     int nstreams;
00087     struct ogg_stream streams[1];
00088 };
00089 
00090 struct ogg {
00091     struct ogg_stream *streams;
00092     int nstreams;
00093     int headers;
00094     int curidx;
00095     struct ogg_state *state;
00096 };
00097 
00098 #define OGG_FLAG_CONT 1
00099 #define OGG_FLAG_BOS  2
00100 #define OGG_FLAG_EOS  4
00101 
00102 extern const struct ogg_codec ff_celt_codec;
00103 extern const struct ogg_codec ff_dirac_codec;
00104 extern const struct ogg_codec ff_flac_codec;
00105 extern const struct ogg_codec ff_ogm_audio_codec;
00106 extern const struct ogg_codec ff_ogm_old_codec;
00107 extern const struct ogg_codec ff_ogm_text_codec;
00108 extern const struct ogg_codec ff_ogm_video_codec;
00109 extern const struct ogg_codec ff_old_dirac_codec;
00110 extern const struct ogg_codec ff_old_flac_codec;
00111 extern const struct ogg_codec ff_skeleton_codec;
00112 extern const struct ogg_codec ff_speex_codec;
00113 extern const struct ogg_codec ff_theora_codec;
00114 extern const struct ogg_codec ff_vorbis_codec;
00115 
00116 int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size);
00117 
00118 static inline int
00119 ogg_find_stream (struct ogg * ogg, int serial)
00120 {
00121     int i;
00122 
00123     for (i = 0; i < ogg->nstreams; i++)
00124         if (ogg->streams[i].serial == serial)
00125             return i;
00126 
00127     return -1;
00128 }
00129 
00130 static inline uint64_t
00131 ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts)
00132 {
00133     struct ogg *ogg = s->priv_data;
00134     struct ogg_stream *os = ogg->streams + i;
00135     uint64_t pts = AV_NOPTS_VALUE;
00136 
00137     if(os->codec && os->codec->gptopts){
00138         pts = os->codec->gptopts(s, i, gp, dts);
00139     } else {
00140         pts = gp;
00141         if (dts)
00142             *dts = pts;
00143     }
00144 
00145     return pts;
00146 }
00147 
00148 #endif /* AVFORMAT_OGGDEC_H */