Mercurial > libavformat.hg
annotate raw.c @ 496:112057e05179 libavformat
libdts support by (Benjamin Zores <ben at geexbox dot org>)
author | michael |
---|---|
date | Wed, 14 Jul 2004 01:32:14 +0000 |
parents | f4e9e55f703c |
children | 558a093b04db |
rev | line source |
---|---|
0 | 1 /* |
2 * RAW encoder and decoder | |
3 * Copyright (c) 2001 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
21 #ifdef CONFIG_ENCODERS |
0 | 22 /* simple formats */ |
64 | 23 static int raw_write_header(struct AVFormatContext *s) |
0 | 24 { |
25 return 0; | |
26 } | |
27 | |
468 | 28 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
0 | 29 { |
468 | 30 put_buffer(&s->pb, pkt->data, pkt->size); |
0 | 31 put_flush_packet(&s->pb); |
32 return 0; | |
33 } | |
34 | |
64 | 35 static int raw_write_trailer(struct AVFormatContext *s) |
0 | 36 { |
37 return 0; | |
38 } | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
39 #endif //CONFIG_ENCODERS |
0 | 40 |
41 /* raw input */ | |
65 | 42 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) |
0 | 43 { |
44 AVStream *st; | |
45 int id; | |
46 | |
47 st = av_new_stream(s, 0); | |
48 if (!st) | |
49 return AVERROR_NOMEM; | |
50 if (ap) { | |
51 id = s->iformat->value; | |
52 if (id == CODEC_ID_RAWVIDEO) { | |
53 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
54 } else { | |
55 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
56 } | |
57 st->codec.codec_id = id; | |
58 | |
59 switch(st->codec.codec_type) { | |
60 case CODEC_TYPE_AUDIO: | |
61 st->codec.sample_rate = ap->sample_rate; | |
62 st->codec.channels = ap->channels; | |
63 break; | |
64 case CODEC_TYPE_VIDEO: | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
65 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
66 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 67 st->codec.width = ap->width; |
68 st->codec.height = ap->height; | |
128 | 69 st->codec.pix_fmt = ap->pix_fmt; |
0 | 70 break; |
71 default: | |
72 return -1; | |
73 } | |
74 } else { | |
75 return -1; | |
76 } | |
77 return 0; | |
78 } | |
79 | |
80 #define RAW_PACKET_SIZE 1024 | |
81 | |
64 | 82 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 83 { |
84 int ret, size; | |
28 | 85 // AVStream *st = s->streams[0]; |
0 | 86 |
87 size= RAW_PACKET_SIZE; | |
88 | |
89 if (av_new_packet(pkt, size) < 0) | |
482 | 90 return AVERROR_IO; |
0 | 91 |
92 pkt->stream_index = 0; | |
93 ret = get_buffer(&s->pb, pkt->data, size); | |
94 if (ret <= 0) { | |
95 av_free_packet(pkt); | |
482 | 96 return AVERROR_IO; |
0 | 97 } |
98 /* note: we need to modify the packet size here to handle the last | |
99 packet */ | |
100 pkt->size = ret; | |
101 return ret; | |
102 } | |
103 | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
104 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
105 { |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
106 int ret, size; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
107 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
108 size = RAW_PACKET_SIZE; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
109 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
110 if (av_new_packet(pkt, size) < 0) |
482 | 111 return AVERROR_IO; |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
112 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
113 pkt->stream_index = 0; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
114 ret = get_partial_buffer(&s->pb, pkt->data, size); |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
115 if (ret <= 0) { |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
116 av_free_packet(pkt); |
482 | 117 return AVERROR_IO; |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
118 } |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
119 pkt->size = ret; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
120 return ret; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
121 } |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
122 |
64 | 123 static int raw_read_close(AVFormatContext *s) |
0 | 124 { |
125 return 0; | |
126 } | |
127 | |
306 | 128 int pcm_read_seek(AVFormatContext *s, |
129 int stream_index, int64_t timestamp) | |
130 { | |
131 AVStream *st; | |
132 int block_align, byte_rate; | |
133 int64_t pos; | |
134 | |
135 st = s->streams[0]; | |
136 switch(st->codec.codec_id) { | |
137 case CODEC_ID_PCM_S16LE: | |
138 case CODEC_ID_PCM_S16BE: | |
139 case CODEC_ID_PCM_U16LE: | |
140 case CODEC_ID_PCM_U16BE: | |
141 block_align = 2 * st->codec.channels; | |
142 byte_rate = block_align * st->codec.sample_rate; | |
143 break; | |
144 case CODEC_ID_PCM_S8: | |
145 case CODEC_ID_PCM_U8: | |
146 case CODEC_ID_PCM_MULAW: | |
147 case CODEC_ID_PCM_ALAW: | |
148 block_align = st->codec.channels; | |
149 byte_rate = block_align * st->codec.sample_rate; | |
150 break; | |
151 default: | |
152 block_align = st->codec.block_align; | |
153 byte_rate = st->codec.bit_rate / 8; | |
154 break; | |
155 } | |
156 | |
157 if (block_align <= 0 || byte_rate <= 0) | |
158 return -1; | |
159 | |
160 /* compute the position by aligning it to block_align */ | |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
389
diff
changeset
|
161 pos = av_rescale(timestamp * byte_rate, st->time_base.num, st->time_base.den); |
306 | 162 pos = (pos / block_align) * block_align; |
163 | |
164 /* recompute exact position */ | |
464 | 165 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); |
306 | 166 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); |
167 return 0; | |
168 } | |
169 | |
63 | 170 /* ac3 read */ |
171 static int ac3_read_header(AVFormatContext *s, | |
172 AVFormatParameters *ap) | |
173 { | |
174 AVStream *st; | |
175 | |
176 st = av_new_stream(s, 0); | |
177 if (!st) | |
178 return AVERROR_NOMEM; | |
179 | |
180 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
181 st->codec.codec_id = CODEC_ID_AC3; | |
306 | 182 st->need_parsing = 1; |
63 | 183 /* the parameters will be extracted from the compressed bitstream */ |
184 return 0; | |
185 } | |
186 | |
496
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
187 /* dts read */ |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
188 static int dts_read_header(AVFormatContext *s, |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
189 AVFormatParameters *ap) |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
190 { |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
191 AVStream *st; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
192 |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
193 st = av_new_stream(s, 0); |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
194 if (!st) |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
195 return AVERROR_NOMEM; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
196 |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
197 st->codec.codec_type = CODEC_TYPE_AUDIO; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
198 st->codec.codec_id = CODEC_ID_DTS; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
199 st->need_parsing = 1; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
200 /* the parameters will be extracted from the compressed bitstream */ |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
201 return 0; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
202 } |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
203 |
0 | 204 /* mpeg1/h263 input */ |
205 static int video_read_header(AVFormatContext *s, | |
206 AVFormatParameters *ap) | |
207 { | |
208 AVStream *st; | |
209 | |
210 st = av_new_stream(s, 0); | |
211 if (!st) | |
212 return AVERROR_NOMEM; | |
213 | |
214 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
215 st->codec.codec_id = s->iformat->value; | |
306 | 216 st->need_parsing = 1; |
217 | |
0 | 218 /* for mjpeg, specify frame rate */ |
219 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ | |
306 | 220 if (st->codec.codec_id == CODEC_ID_MJPEG || |
221 st->codec.codec_id == CODEC_ID_MPEG4) { | |
222 if (ap && ap->frame_rate) { | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
223 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
224 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 225 } else { |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
226 st->codec.frame_rate = 25; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
227 st->codec.frame_rate_base = 1; |
0 | 228 } |
229 } | |
230 return 0; | |
231 } | |
232 | |
233 #define SEQ_START_CODE 0x000001b3 | |
234 #define GOP_START_CODE 0x000001b8 | |
235 #define PICTURE_START_CODE 0x00000100 | |
236 | |
237 /* XXX: improve that by looking at several start codes */ | |
238 static int mpegvideo_probe(AVProbeData *p) | |
239 { | |
49 | 240 int code; |
241 const uint8_t *d; | |
0 | 242 |
243 /* we search the first start code. If it is a sequence, gop or | |
244 picture start code then we decide it is an mpeg video | |
245 stream. We do not send highest value to give a chance to mpegts */ | |
49 | 246 /* NOTE: the search range was restricted to avoid too many false |
247 detections */ | |
248 | |
249 if (p->buf_size < 6) | |
250 return 0; | |
251 d = p->buf; | |
252 code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]); | |
253 if ((code & 0xffffff00) == 0x100) { | |
254 if (code == SEQ_START_CODE || | |
255 code == GOP_START_CODE || | |
256 code == PICTURE_START_CODE) | |
257 return 50 - 1; | |
258 else | |
259 return 0; | |
0 | 260 } |
261 return 0; | |
262 } | |
263 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
264 static int h263_probe(AVProbeData *p) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
265 { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
266 int code; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
267 const uint8_t *d; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
268 |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
269 if (p->buf_size < 6) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
270 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
271 d = p->buf; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
272 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
273 if (code == 0x20) { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
274 return 50; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
275 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
276 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
277 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
278 |
473
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
279 static int h261_probe(AVProbeData *p) |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
280 { |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
281 int code; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
282 const uint8_t *d; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
283 |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
284 if (p->buf_size < 6) |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
285 return 0; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
286 d = p->buf; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
287 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4); |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
288 if (code == 0x10) { |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
289 return 50; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
290 } |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
291 return 0; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
292 } |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
293 |
0 | 294 AVInputFormat ac3_iformat = { |
295 "ac3", | |
296 "raw ac3", | |
297 0, | |
298 NULL, | |
63 | 299 ac3_read_header, |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
300 raw_read_partial_packet, |
0 | 301 raw_read_close, |
302 .extensions = "ac3", | |
303 }; | |
304 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
305 #ifdef CONFIG_ENCODERS |
0 | 306 AVOutputFormat ac3_oformat = { |
307 "ac3", | |
308 "raw ac3", | |
309 "audio/x-ac3", | |
310 "ac3", | |
311 0, | |
312 CODEC_ID_AC3, | |
313 0, | |
314 raw_write_header, | |
315 raw_write_packet, | |
316 raw_write_trailer, | |
317 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
318 #endif //CONFIG_ENCODERS |
0 | 319 |
496
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
320 AVInputFormat dts_iformat = { |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
321 "dts", |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
322 "raw dts", |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
323 0, |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
324 NULL, |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
325 dts_read_header, |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
326 raw_read_partial_packet, |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
327 raw_read_close, |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
328 .extensions = "dts", |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
329 }; |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
330 |
473
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
331 AVInputFormat h261_iformat = { |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
332 "h261", |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
333 "raw h261", |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
334 0, |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
335 h261_probe, |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
336 video_read_header, |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
337 raw_read_partial_packet, |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
338 raw_read_close, |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
339 .extensions = "h261", |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
340 .value = CODEC_ID_H261, |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
341 }; |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
342 |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
343 AVInputFormat h263_iformat = { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
344 "h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
345 "raw h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
346 0, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
347 h263_probe, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
348 video_read_header, |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
349 raw_read_partial_packet, |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
350 raw_read_close, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
351 // .extensions = "h263", //FIXME remove after writing mpeg4_probe |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
352 .value = CODEC_ID_H263, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
353 }; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
354 |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
355 #ifdef CONFIG_ENCODERS |
0 | 356 AVOutputFormat h263_oformat = { |
357 "h263", | |
358 "raw h263", | |
359 "video/x-h263", | |
360 "h263", | |
361 0, | |
362 0, | |
363 CODEC_ID_H263, | |
364 raw_write_header, | |
365 raw_write_packet, | |
366 raw_write_trailer, | |
367 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
368 #endif //CONFIG_ENCODERS |
0 | 369 |
370 AVInputFormat m4v_iformat = { | |
371 "m4v", | |
372 "raw MPEG4 video format", | |
373 0, | |
374 NULL /*mpegvideo_probe*/, | |
375 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
376 raw_read_partial_packet, |
0 | 377 raw_read_close, |
378 .extensions = "m4v", //FIXME remove after writing mpeg4_probe | |
379 .value = CODEC_ID_MPEG4, | |
380 }; | |
381 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
382 #ifdef CONFIG_ENCODERS |
0 | 383 AVOutputFormat m4v_oformat = { |
384 "m4v", | |
385 "raw MPEG4 video format", | |
386 NULL, | |
387 "m4v", | |
388 0, | |
389 CODEC_ID_NONE, | |
390 CODEC_ID_MPEG4, | |
391 raw_write_header, | |
392 raw_write_packet, | |
393 raw_write_trailer, | |
394 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
395 #endif //CONFIG_ENCODERS |
0 | 396 |
100 | 397 AVInputFormat h264_iformat = { |
398 "h264", | |
399 "raw H264 video format", | |
400 0, | |
401 NULL /*mpegvideo_probe*/, | |
402 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
403 raw_read_partial_packet, |
100 | 404 raw_read_close, |
405 .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe | |
406 .value = CODEC_ID_H264, | |
407 }; | |
408 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
409 #ifdef CONFIG_ENCODERS |
100 | 410 AVOutputFormat h264_oformat = { |
411 "h264", | |
412 "raw H264 video format", | |
413 NULL, | |
414 "h264", | |
415 0, | |
416 CODEC_ID_NONE, | |
417 CODEC_ID_H264, | |
418 raw_write_header, | |
419 raw_write_packet, | |
420 raw_write_trailer, | |
421 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
422 #endif //CONFIG_ENCODERS |
100 | 423 |
0 | 424 AVInputFormat mpegvideo_iformat = { |
425 "mpegvideo", | |
426 "MPEG video", | |
427 0, | |
428 mpegvideo_probe, | |
429 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
430 raw_read_partial_packet, |
0 | 431 raw_read_close, |
432 .value = CODEC_ID_MPEG1VIDEO, | |
433 }; | |
434 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
435 #ifdef CONFIG_ENCODERS |
0 | 436 AVOutputFormat mpeg1video_oformat = { |
437 "mpeg1video", | |
438 "MPEG video", | |
439 "video/x-mpeg", | |
440 "mpg,mpeg", | |
441 0, | |
442 0, | |
443 CODEC_ID_MPEG1VIDEO, | |
444 raw_write_header, | |
445 raw_write_packet, | |
446 raw_write_trailer, | |
447 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
448 #endif //CONFIG_ENCODERS |
0 | 449 |
450 AVInputFormat mjpeg_iformat = { | |
451 "mjpeg", | |
452 "MJPEG video", | |
453 0, | |
454 NULL, | |
455 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
456 raw_read_partial_packet, |
0 | 457 raw_read_close, |
458 .extensions = "mjpg,mjpeg", | |
459 .value = CODEC_ID_MJPEG, | |
460 }; | |
461 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
462 #ifdef CONFIG_ENCODERS |
0 | 463 AVOutputFormat mjpeg_oformat = { |
464 "mjpeg", | |
465 "MJPEG video", | |
466 "video/x-mjpeg", | |
467 "mjpg,mjpeg", | |
468 0, | |
469 0, | |
470 CODEC_ID_MJPEG, | |
471 raw_write_header, | |
472 raw_write_packet, | |
473 raw_write_trailer, | |
474 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
475 #endif //CONFIG_ENCODERS |
0 | 476 |
477 /* pcm formats */ | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
478 |
306 | 479 #define PCMINPUTDEF(name, long_name, ext, codec) \ |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
480 AVInputFormat pcm_ ## name ## _iformat = {\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
481 #name,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
482 long_name,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
483 0,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
484 NULL,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
485 raw_read_header,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
486 raw_read_packet,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
487 raw_read_close,\ |
306 | 488 pcm_read_seek,\ |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
489 .extensions = ext,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
490 .value = codec,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
491 }; |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
492 |
306 | 493 #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) |
494 | |
495 #define PCMDEF(name, long_name, ext, codec) \ | |
496 PCMINPUTDEF(name, long_name, ext, codec) | |
497 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
498 #else |
0 | 499 |
500 #define PCMDEF(name, long_name, ext, codec) \ | |
306 | 501 PCMINPUTDEF(name, long_name, ext, codec)\ |
0 | 502 \ |
503 AVOutputFormat pcm_ ## name ## _oformat = {\ | |
504 #name,\ | |
505 long_name,\ | |
506 NULL,\ | |
507 ext,\ | |
508 0,\ | |
509 codec,\ | |
510 0,\ | |
511 raw_write_header,\ | |
512 raw_write_packet,\ | |
513 raw_write_trailer,\ | |
514 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
515 #endif //CONFIG_ENCODERS |
0 | 516 |
517 #ifdef WORDS_BIGENDIAN | |
518 #define BE_DEF(s) s | |
519 #define LE_DEF(s) NULL | |
520 #else | |
521 #define BE_DEF(s) NULL | |
522 #define LE_DEF(s) s | |
523 #endif | |
524 | |
525 | |
526 PCMDEF(s16le, "pcm signed 16 bit little endian format", | |
527 LE_DEF("sw"), CODEC_ID_PCM_S16LE) | |
528 | |
529 PCMDEF(s16be, "pcm signed 16 bit big endian format", | |
530 BE_DEF("sw"), CODEC_ID_PCM_S16BE) | |
531 | |
532 PCMDEF(u16le, "pcm unsigned 16 bit little endian format", | |
533 LE_DEF("uw"), CODEC_ID_PCM_U16LE) | |
534 | |
535 PCMDEF(u16be, "pcm unsigned 16 bit big endian format", | |
536 BE_DEF("uw"), CODEC_ID_PCM_U16BE) | |
537 | |
538 PCMDEF(s8, "pcm signed 8 bit format", | |
539 "sb", CODEC_ID_PCM_S8) | |
540 | |
541 PCMDEF(u8, "pcm unsigned 8 bit format", | |
542 "ub", CODEC_ID_PCM_U8) | |
543 | |
544 PCMDEF(mulaw, "pcm mu law format", | |
545 "ul", CODEC_ID_PCM_MULAW) | |
546 | |
547 PCMDEF(alaw, "pcm A law format", | |
548 "al", CODEC_ID_PCM_ALAW) | |
549 | |
64 | 550 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 551 { |
552 int packet_size, ret, width, height; | |
553 AVStream *st = s->streams[0]; | |
554 | |
555 width = st->codec.width; | |
556 height = st->codec.height; | |
557 | |
128 | 558 packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); |
559 if (packet_size < 0) | |
0 | 560 av_abort(); |
561 | |
562 if (av_new_packet(pkt, packet_size) < 0) | |
482 | 563 return AVERROR_IO; |
0 | 564 |
565 pkt->stream_index = 0; | |
566 #if 0 | |
567 /* bypass buffered I/O */ | |
568 ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size); | |
569 #else | |
570 ret = get_buffer(&s->pb, pkt->data, pkt->size); | |
571 #endif | |
572 if (ret != pkt->size) { | |
573 av_free_packet(pkt); | |
482 | 574 return AVERROR_IO; |
0 | 575 } else { |
576 return 0; | |
577 } | |
578 } | |
579 | |
580 AVInputFormat rawvideo_iformat = { | |
581 "rawvideo", | |
582 "raw video format", | |
583 0, | |
584 NULL, | |
585 raw_read_header, | |
586 rawvideo_read_packet, | |
587 raw_read_close, | |
588 .extensions = "yuv", | |
589 .value = CODEC_ID_RAWVIDEO, | |
590 }; | |
591 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
592 #ifdef CONFIG_ENCODERS |
0 | 593 AVOutputFormat rawvideo_oformat = { |
594 "rawvideo", | |
595 "raw video format", | |
596 NULL, | |
597 "yuv", | |
598 0, | |
599 CODEC_ID_NONE, | |
600 CODEC_ID_RAWVIDEO, | |
601 raw_write_header, | |
602 raw_write_packet, | |
603 raw_write_trailer, | |
604 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
605 #endif //CONFIG_ENCODERS |
0 | 606 |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
607 #ifdef CONFIG_ENCODERS |
468 | 608 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
0 | 609 { |
610 return 0; | |
611 } | |
612 | |
613 AVOutputFormat null_oformat = { | |
614 "null", | |
615 "null video format", | |
616 NULL, | |
617 NULL, | |
618 0, | |
619 #ifdef WORDS_BIGENDIAN | |
620 CODEC_ID_PCM_S16BE, | |
621 #else | |
622 CODEC_ID_PCM_S16LE, | |
623 #endif | |
624 CODEC_ID_RAWVIDEO, | |
625 raw_write_header, | |
626 null_write_packet, | |
627 raw_write_trailer, | |
628 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE, | |
629 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
630 #endif //CONFIG_ENCODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
631 |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
632 #ifndef CONFIG_ENCODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
633 #define av_register_output_format(format) |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
634 #endif |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
635 #ifndef CONFIG_DECODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
636 #define av_register_input_format(format) |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
637 #endif |
0 | 638 |
639 int raw_init(void) | |
640 { | |
641 av_register_input_format(&ac3_iformat); | |
642 av_register_output_format(&ac3_oformat); | |
643 | |
496
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
644 av_register_input_format(&dts_iformat); |
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
483
diff
changeset
|
645 |
473
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
646 av_register_input_format(&h261_iformat); |
e0a66a870b7f
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
468
diff
changeset
|
647 |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
648 av_register_input_format(&h263_iformat); |
0 | 649 av_register_output_format(&h263_oformat); |
650 | |
651 av_register_input_format(&m4v_iformat); | |
652 av_register_output_format(&m4v_oformat); | |
100 | 653 |
654 av_register_input_format(&h264_iformat); | |
655 av_register_output_format(&h264_oformat); | |
0 | 656 |
657 av_register_input_format(&mpegvideo_iformat); | |
658 av_register_output_format(&mpeg1video_oformat); | |
659 | |
660 av_register_input_format(&mjpeg_iformat); | |
661 av_register_output_format(&mjpeg_oformat); | |
662 | |
663 av_register_input_format(&pcm_s16le_iformat); | |
664 av_register_output_format(&pcm_s16le_oformat); | |
665 av_register_input_format(&pcm_s16be_iformat); | |
666 av_register_output_format(&pcm_s16be_oformat); | |
667 av_register_input_format(&pcm_u16le_iformat); | |
668 av_register_output_format(&pcm_u16le_oformat); | |
669 av_register_input_format(&pcm_u16be_iformat); | |
670 av_register_output_format(&pcm_u16be_oformat); | |
671 av_register_input_format(&pcm_s8_iformat); | |
672 av_register_output_format(&pcm_s8_oformat); | |
673 av_register_input_format(&pcm_u8_iformat); | |
674 av_register_output_format(&pcm_u8_oformat); | |
675 av_register_input_format(&pcm_mulaw_iformat); | |
676 av_register_output_format(&pcm_mulaw_oformat); | |
677 av_register_input_format(&pcm_alaw_iformat); | |
678 av_register_output_format(&pcm_alaw_oformat); | |
679 | |
680 av_register_input_format(&rawvideo_iformat); | |
681 av_register_output_format(&rawvideo_oformat); | |
682 | |
683 av_register_output_format(&null_oformat); | |
684 return 0; | |
685 } |