yading@11
|
1 /**
|
yading@11
|
2 Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
|
yading@11
|
3
|
yading@11
|
4 Permission is hereby granted, free of charge, to any person
|
yading@11
|
5 obtaining a copy of this software and associated documentation
|
yading@11
|
6 files (the "Software"), to deal in the Software without
|
yading@11
|
7 restriction, including without limitation the rights to use, copy,
|
yading@11
|
8 modify, merge, publish, distribute, sublicense, and/or sell copies
|
yading@11
|
9 of the Software, and to permit persons to whom the Software is
|
yading@11
|
10 furnished to do so, subject to the following conditions:
|
yading@11
|
11
|
yading@11
|
12 The above copyright notice and this permission notice shall be
|
yading@11
|
13 included in all copies or substantial portions of the Software.
|
yading@11
|
14
|
yading@11
|
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
yading@11
|
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
yading@11
|
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
yading@11
|
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
yading@11
|
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
yading@11
|
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
yading@11
|
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
yading@11
|
22 DEALINGS IN THE SOFTWARE.
|
yading@11
|
23 **/
|
yading@11
|
24
|
yading@11
|
25 #ifndef AVFORMAT_OGGDEC_H
|
yading@11
|
26 #define AVFORMAT_OGGDEC_H
|
yading@11
|
27
|
yading@11
|
28 #include "avformat.h"
|
yading@11
|
29 #include "metadata.h"
|
yading@11
|
30
|
yading@11
|
31 struct ogg_codec {
|
yading@11
|
32 const int8_t *magic;
|
yading@11
|
33 uint8_t magicsize;
|
yading@11
|
34 const int8_t *name;
|
yading@11
|
35 /**
|
yading@11
|
36 * Attempt to process a packet as a header
|
yading@11
|
37 * @return 1 if the packet was a valid header,
|
yading@11
|
38 * 0 if the packet was not a header (was a data packet)
|
yading@11
|
39 * -1 if an error occurred or for unsupported stream
|
yading@11
|
40 */
|
yading@11
|
41 int (*header)(AVFormatContext *, int);
|
yading@11
|
42 int (*packet)(AVFormatContext *, int);
|
yading@11
|
43 /**
|
yading@11
|
44 * Translate a granule into a timestamp.
|
yading@11
|
45 * Will set dts if non-null and known.
|
yading@11
|
46 * @return pts
|
yading@11
|
47 */
|
yading@11
|
48 uint64_t (*gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts);
|
yading@11
|
49 /**
|
yading@11
|
50 * 1 if granule is the start time of the associated packet.
|
yading@11
|
51 * 0 if granule is the end time of the associated packet.
|
yading@11
|
52 */
|
yading@11
|
53 int granule_is_start;
|
yading@11
|
54 /**
|
yading@11
|
55 * Number of expected headers
|
yading@11
|
56 */
|
yading@11
|
57 int nb_header;
|
yading@11
|
58 void (*cleanup)(AVFormatContext *s, int idx);
|
yading@11
|
59 };
|
yading@11
|
60
|
yading@11
|
61 struct ogg_stream {
|
yading@11
|
62 uint8_t *buf;
|
yading@11
|
63 unsigned int bufsize;
|
yading@11
|
64 unsigned int bufpos;
|
yading@11
|
65 unsigned int pstart;
|
yading@11
|
66 unsigned int psize;
|
yading@11
|
67 unsigned int pflags;
|
yading@11
|
68 unsigned int pduration;
|
yading@11
|
69 uint32_t serial;
|
yading@11
|
70 uint64_t granule;
|
yading@11
|
71 uint64_t start_granule;
|
yading@11
|
72 int64_t lastpts;
|
yading@11
|
73 int64_t lastdts;
|
yading@11
|
74 int64_t sync_pos; ///< file offset of the first page needed to reconstruct the current packet
|
yading@11
|
75 int64_t page_pos; ///< file offset of the current page
|
yading@11
|
76 int flags;
|
yading@11
|
77 const struct ogg_codec *codec;
|
yading@11
|
78 int header;
|
yading@11
|
79 int nsegs, segp;
|
yading@11
|
80 uint8_t segments[255];
|
yading@11
|
81 int incomplete; ///< whether we're expecting a continuation in the next page
|
yading@11
|
82 int page_end; ///< current packet is the last one completed in the page
|
yading@11
|
83 int keyframe_seek;
|
yading@11
|
84 int got_start;
|
yading@11
|
85 int got_data; ///< 1 if the stream got some data (non-initial packets), 0 otherwise
|
yading@11
|
86 int nb_header; ///< set to the number of parsed headers
|
yading@11
|
87 void *private;
|
yading@11
|
88 };
|
yading@11
|
89
|
yading@11
|
90 struct ogg_state {
|
yading@11
|
91 uint64_t pos;
|
yading@11
|
92 int curidx;
|
yading@11
|
93 struct ogg_state *next;
|
yading@11
|
94 int nstreams;
|
yading@11
|
95 struct ogg_stream streams[1];
|
yading@11
|
96 };
|
yading@11
|
97
|
yading@11
|
98 struct ogg {
|
yading@11
|
99 struct ogg_stream *streams;
|
yading@11
|
100 int nstreams;
|
yading@11
|
101 int headers;
|
yading@11
|
102 int curidx;
|
yading@11
|
103 int64_t page_pos; ///< file offset of the current page
|
yading@11
|
104 struct ogg_state *state;
|
yading@11
|
105 };
|
yading@11
|
106
|
yading@11
|
107 #define OGG_FLAG_CONT 1
|
yading@11
|
108 #define OGG_FLAG_BOS 2
|
yading@11
|
109 #define OGG_FLAG_EOS 4
|
yading@11
|
110
|
yading@11
|
111 #define OGG_NOGRANULE_VALUE (-1ull)
|
yading@11
|
112
|
yading@11
|
113 extern const struct ogg_codec ff_celt_codec;
|
yading@11
|
114 extern const struct ogg_codec ff_dirac_codec;
|
yading@11
|
115 extern const struct ogg_codec ff_flac_codec;
|
yading@11
|
116 extern const struct ogg_codec ff_ogm_audio_codec;
|
yading@11
|
117 extern const struct ogg_codec ff_ogm_old_codec;
|
yading@11
|
118 extern const struct ogg_codec ff_ogm_text_codec;
|
yading@11
|
119 extern const struct ogg_codec ff_ogm_video_codec;
|
yading@11
|
120 extern const struct ogg_codec ff_old_dirac_codec;
|
yading@11
|
121 extern const struct ogg_codec ff_old_flac_codec;
|
yading@11
|
122 extern const struct ogg_codec ff_opus_codec;
|
yading@11
|
123 extern const struct ogg_codec ff_skeleton_codec;
|
yading@11
|
124 extern const struct ogg_codec ff_speex_codec;
|
yading@11
|
125 extern const struct ogg_codec ff_theora_codec;
|
yading@11
|
126 extern const struct ogg_codec ff_vorbis_codec;
|
yading@11
|
127
|
yading@11
|
128 int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size);
|
yading@11
|
129
|
yading@11
|
130 static inline int
|
yading@11
|
131 ogg_find_stream (struct ogg * ogg, int serial)
|
yading@11
|
132 {
|
yading@11
|
133 int i;
|
yading@11
|
134
|
yading@11
|
135 for (i = 0; i < ogg->nstreams; i++)
|
yading@11
|
136 if (ogg->streams[i].serial == serial)
|
yading@11
|
137 return i;
|
yading@11
|
138
|
yading@11
|
139 return -1;
|
yading@11
|
140 }
|
yading@11
|
141
|
yading@11
|
142 static inline uint64_t
|
yading@11
|
143 ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts)
|
yading@11
|
144 {
|
yading@11
|
145 struct ogg *ogg = s->priv_data;
|
yading@11
|
146 struct ogg_stream *os = ogg->streams + i;
|
yading@11
|
147 uint64_t pts = AV_NOPTS_VALUE;
|
yading@11
|
148
|
yading@11
|
149 if(os->codec && os->codec->gptopts){
|
yading@11
|
150 pts = os->codec->gptopts(s, i, gp, dts);
|
yading@11
|
151 } else {
|
yading@11
|
152 pts = gp;
|
yading@11
|
153 if (dts)
|
yading@11
|
154 *dts = pts;
|
yading@11
|
155 }
|
yading@11
|
156
|
yading@11
|
157 return pts;
|
yading@11
|
158 }
|
yading@11
|
159
|
yading@11
|
160 #endif /* AVFORMAT_OGGDEC_H */
|