Make the declaration of AVInputFormat ac3_demuxer conditional
[libav.git] / libavformat / raw.c
CommitLineData
115329f1 1/*
7fbde343 2 * RAW muxer and demuxer
19720f15 3 * Copyright (c) 2001 Fabrice Bellard.
84c63c01 4 * Copyright (c) 2005 Alex Beregszaszi
de6d9b64 5 *
b78e7197
DB
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
19720f15
FB
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
b78e7197 11 * version 2.1 of the License, or (at your option) any later version.
de6d9b64 12 *
b78e7197 13 * FFmpeg is distributed in the hope that it will be useful,
de6d9b64 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19720f15
FB
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
de6d9b64 17 *
19720f15 18 * You should have received a copy of the GNU Lesser General Public
b78e7197 19 * License along with FFmpeg; if not, write to the Free Software
5509bffa 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64 21 */
de6d9b64 22#include "avformat.h"
98d02051 23#include "parser.h"
de6d9b64 24
a9e35095 25#ifdef CONFIG_MUXERS
de6d9b64 26/* simple formats */
5c91a675 27static int raw_write_header(struct AVFormatContext *s)
de6d9b64
FB
28{
29 return 0;
30}
31
ce1d2a95
JR
32static int flac_write_header(struct AVFormatContext *s)
33{
34 static const uint8_t header[8] = {
35 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
36 };
37 uint8_t *streaminfo = s->streams[0]->codec->extradata;
38 int len = s->streams[0]->codec->extradata_size;
39 if(streaminfo != NULL && len > 0) {
40 put_buffer(&s->pb, header, 8);
41 put_buffer(&s->pb, streaminfo, len);
42 }
43 return 0;
44}
45
e928649b 46static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
de6d9b64 47{
e928649b 48 put_buffer(&s->pb, pkt->data, pkt->size);
de6d9b64
FB
49 put_flush_packet(&s->pb);
50 return 0;
51}
52
5c91a675 53static int raw_write_trailer(struct AVFormatContext *s)
de6d9b64
FB
54{
55 return 0;
56}
a9e35095 57#endif //CONFIG_MUXERS
de6d9b64
FB
58
59/* raw input */
0c1a9eda 60static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
de6d9b64
FB
61{
62 AVStream *st;
c9a65ca8 63 int id;
de6d9b64 64
c9a65ca8 65 st = av_new_stream(s, 0);
de6d9b64 66 if (!st)
c9a65ca8 67 return AVERROR_NOMEM;
c04c3282 68
c9a65ca8
FB
69 id = s->iformat->value;
70 if (id == CODEC_ID_RAWVIDEO) {
01f4895c 71 st->codec->codec_type = CODEC_TYPE_VIDEO;
de6d9b64 72 } else {
01f4895c 73 st->codec->codec_type = CODEC_TYPE_AUDIO;
de6d9b64 74 }
01f4895c 75 st->codec->codec_id = id;
c9a65ca8 76
01f4895c 77 switch(st->codec->codec_type) {
de6d9b64 78 case CODEC_TYPE_AUDIO:
01f4895c
MN
79 st->codec->sample_rate = ap->sample_rate;
80 st->codec->channels = ap->channels;
81 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
de6d9b64
FB
82 break;
83 case CODEC_TYPE_VIDEO:
c0df9d75 84 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
01f4895c
MN
85 st->codec->width = ap->width;
86 st->codec->height = ap->height;
87 st->codec->pix_fmt = ap->pix_fmt;
88 if(st->codec->pix_fmt == PIX_FMT_NONE)
89 st->codec->pix_fmt= PIX_FMT_YUV420P;
de6d9b64
FB
90 break;
91 default:
27e084bd 92 return -1;
de6d9b64 93 }
de6d9b64
FB
94 return 0;
95}
96
2e93e3aa 97#define RAW_PACKET_SIZE 1024
de6d9b64 98
5c91a675 99static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64 100{
7866eeff 101 int ret, size;
2a6874fd 102 // AVStream *st = s->streams[0];
115329f1 103
231dd3f3 104 size= RAW_PACKET_SIZE;
de6d9b64 105
2692067a 106 ret= av_get_packet(&s->pb, pkt, size);
de6d9b64
FB
107
108 pkt->stream_index = 0;
2e93e3aa 109 if (ret <= 0) {
0bd586c5 110 return AVERROR_IO;
2e93e3aa
FB
111 }
112 /* note: we need to modify the packet size here to handle the last
113 packet */
114 pkt->size = ret;
de6d9b64
FB
115 return ret;
116}
117
e15dec10
LS
118static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
119{
120 int ret, size;
121
122 size = RAW_PACKET_SIZE;
123
124 if (av_new_packet(pkt, size) < 0)
0bd586c5 125 return AVERROR_IO;
115329f1 126
2692067a 127 pkt->pos= url_ftell(&s->pb);
e15dec10
LS
128 pkt->stream_index = 0;
129 ret = get_partial_buffer(&s->pb, pkt->data, size);
130 if (ret <= 0) {
131 av_free_packet(pkt);
0bd586c5 132 return AVERROR_IO;
e15dec10
LS
133 }
134 pkt->size = ret;
135 return ret;
136}
137
84c63c01
AB
138// http://www.artificis.hu/files/texts/ingenient.txt
139static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
140{
141 int ret, size, w, h, unk1, unk2;
115329f1 142
84c63c01 143 if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
bb270c08 144 return AVERROR_IO; // FIXME
84c63c01
AB
145
146 size = get_le32(&s->pb);
115329f1 147
84c63c01
AB
148 w = get_le16(&s->pb);
149 h = get_le16(&s->pb);
115329f1 150
84c63c01
AB
151 url_fskip(&s->pb, 8); // zero + size (padded?)
152 url_fskip(&s->pb, 2);
153 unk1 = get_le16(&s->pb);
154 unk2 = get_le16(&s->pb);
155 url_fskip(&s->pb, 22); // ascii timestamp
115329f1 156
84c63c01 157 av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
bb270c08 158 size, w, h, unk1, unk2);
84c63c01
AB
159
160 if (av_new_packet(pkt, size) < 0)
161 return AVERROR_IO;
162
163 pkt->pos = url_ftell(&s->pb);
164 pkt->stream_index = 0;
165 ret = get_buffer(&s->pb, pkt->data, size);
166 if (ret <= 0) {
167 av_free_packet(pkt);
168 return AVERROR_IO;
169 }
170 pkt->size = ret;
171 return ret;
172}
173
5c91a675 174static int raw_read_close(AVFormatContext *s)
de6d9b64
FB
175{
176 return 0;
177}
178
115329f1 179int pcm_read_seek(AVFormatContext *s,
7b3c1382 180 int stream_index, int64_t timestamp, int flags)
4986a429
FB
181{
182 AVStream *st;
183 int block_align, byte_rate;
184 int64_t pos;
185
186 st = s->streams[0];
708e3e7d
BC
187
188 block_align = st->codec->block_align ? st->codec->block_align :
189 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
190 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
191 block_align * st->codec->sample_rate;
115329f1 192
4986a429
FB
193 if (block_align <= 0 || byte_rate <= 0)
194 return -1;
195
196 /* compute the position by aligning it to block_align */
115329f1
DB
197 pos = av_rescale_rnd(timestamp * byte_rate,
198 st->time_base.num,
7b3c1382
MN
199 st->time_base.den * (int64_t)block_align,
200 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
201 pos *= block_align;
4986a429
FB
202
203 /* recompute exact position */
77405fc8 204 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
4986a429
FB
205 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
206 return 0;
207}
208
cd66005d
FB
209/* ac3 read */
210static int ac3_read_header(AVFormatContext *s,
211 AVFormatParameters *ap)
212{
213 AVStream *st;
214
215 st = av_new_stream(s, 0);
216 if (!st)
217 return AVERROR_NOMEM;
218
01f4895c
MN
219 st->codec->codec_type = CODEC_TYPE_AUDIO;
220 st->codec->codec_id = CODEC_ID_AC3;
4986a429 221 st->need_parsing = 1;
cd66005d
FB
222 /* the parameters will be extracted from the compressed bitstream */
223 return 0;
224}
225
85ad5695
MN
226static int shorten_read_header(AVFormatContext *s,
227 AVFormatParameters *ap)
228{
229 AVStream *st;
230
231 st = av_new_stream(s, 0);
232 if (!st)
233 return AVERROR_NOMEM;
01f4895c
MN
234 st->codec->codec_type = CODEC_TYPE_AUDIO;
235 st->codec->codec_id = CODEC_ID_SHORTEN;
85ad5695
MN
236 st->need_parsing = 1;
237 /* the parameters will be extracted from the compressed bitstream */
238 return 0;
239}
240
89ca8c49
BL
241/* flac read */
242static int flac_read_header(AVFormatContext *s,
243 AVFormatParameters *ap)
244{
245 AVStream *st;
246
247 st = av_new_stream(s, 0);
248 if (!st)
249 return AVERROR_NOMEM;
250 st->codec->codec_type = CODEC_TYPE_AUDIO;
251 st->codec->codec_id = CODEC_ID_FLAC;
252 st->need_parsing = 1;
253 /* the parameters will be extracted from the compressed bitstream */
254 return 0;
255}
256
23c99253
MN
257/* dts read */
258static int dts_read_header(AVFormatContext *s,
259 AVFormatParameters *ap)
260{
261 AVStream *st;
262
263 st = av_new_stream(s, 0);
264 if (!st)
265 return AVERROR_NOMEM;
266
01f4895c
MN
267 st->codec->codec_type = CODEC_TYPE_AUDIO;
268 st->codec->codec_id = CODEC_ID_DTS;
23c99253
MN
269 st->need_parsing = 1;
270 /* the parameters will be extracted from the compressed bitstream */
271 return 0;
272}
273
fda885c7
MR
274/* aac read */
275static int aac_read_header(AVFormatContext *s,
276 AVFormatParameters *ap)
277{
278 AVStream *st;
279
280 st = av_new_stream(s, 0);
281 if (!st)
282 return AVERROR_NOMEM;
283
284 st->codec->codec_type = CODEC_TYPE_AUDIO;
285 st->codec->codec_id = CODEC_ID_AAC;
286 st->need_parsing = 1;
287 /* the parameters will be extracted from the compressed bitstream */
288 return 0;
289}
290
de6d9b64
FB
291/* mpeg1/h263 input */
292static int video_read_header(AVFormatContext *s,
293 AVFormatParameters *ap)
294{
295 AVStream *st;
296
c9a65ca8 297 st = av_new_stream(s, 0);
de6d9b64 298 if (!st)
c9a65ca8 299 return AVERROR_NOMEM;
de6d9b64 300
01f4895c
MN
301 st->codec->codec_type = CODEC_TYPE_VIDEO;
302 st->codec->codec_id = s->iformat->value;
4986a429
FB
303 st->need_parsing = 1;
304
27e084bd 305 /* for mjpeg, specify frame rate */
7866eeff 306 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
c04c3282 307 if (ap->time_base.num) {
80ce3254 308 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
115329f1 309 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
01f4895c
MN
310 st->codec->codec_id == CODEC_ID_MPEG4 ||
311 st->codec->codec_id == CODEC_ID_H264) {
80ce3254 312 av_set_pts_info(st, 64, 1, 25);
27e084bd 313 }
80ce3254 314
de6d9b64
FB
315 return 0;
316}
317
bb270c08
DB
318#define SEQ_START_CODE 0x000001b3
319#define GOP_START_CODE 0x000001b8
320#define PICTURE_START_CODE 0x00000100
93d3e278
MN
321#define SLICE_START_CODE 0x00000101
322#define PACK_START_CODE 0x000001ba
e01dc227
MR
323#define VIDEO_ID 0x000001e0
324#define AUDIO_ID 0x000001c0
c9a65ca8 325
c9a65ca8
FB
326static int mpegvideo_probe(AVProbeData *p)
327{
93d3e278 328 uint32_t code= -1;
e01dc227 329 int pic=0, seq=0, slice=0, pspack=0, pes=0;
93d3e278
MN
330 int i;
331
332 for(i=0; i<p->buf_size; i++){
333 code = (code<<8) + p->buf[i];
334 if ((code & 0xffffff00) == 0x100) {
335 switch(code){
336 case SEQ_START_CODE: seq++; break;
337 case PICTURE_START_CODE: pic++; break;
338 case SLICE_START_CODE: slice++; break;
339 case PACK_START_CODE: pspack++; break;
340 }
e9f6c8ea
MN
341 if ((code & 0x1f0) == VIDEO_ID) pes++;
342 else if((code & 0x1e0) == AUDIO_ID) pes++;
93d3e278 343 }
c9a65ca8 344 }
e01dc227 345 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
93d3e278 346 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
c9a65ca8
FB
347 return 0;
348}
349
8f57cc5a
TV
350#define VIDEO_OBJECT_START_CODE 0x00000100
351#define VIDEO_OBJECT_LAYER_START_CODE 0x00000120
352#define VISUAL_OBJECT_START_CODE 0x000001b5
353#define VOP_START_CODE 0x000001b6
354
355static int mpeg4video_probe(AVProbeData *probe_packet)
356{
357 uint32_t temp_buffer= -1;
358 int VO=0, VOL=0, VOP = 0, VISO = 0;
359 int i;
360
361 for(i=0; i<probe_packet->buf_size; i++){
362 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
363 if ((temp_buffer & 0xffffff00) == 0x100) {
364 switch(temp_buffer){
365 case VOP_START_CODE: VOP++; break;
366 case VISUAL_OBJECT_START_CODE: VISO++; break;
367 }
368 switch(temp_buffer & 0xfffffff0){
369 case VIDEO_OBJECT_START_CODE: VO++; break;
370 case VIDEO_OBJECT_LAYER_START_CODE: VOL++; break;
371 }
372 }
373 }
374
375 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0)
376 return AVPROBE_SCORE_MAX/2;
377 return 0;
378}
379
d07f9043
MN
380static int h263_probe(AVProbeData *p)
381{
382 int code;
383 const uint8_t *d;
384
d07f9043
MN
385 d = p->buf;
386 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
387 if (code == 0x20) {
388 return 50;
389 }
390 return 0;
391}
392
c6148de2
MN
393static int h261_probe(AVProbeData *p)
394{
395 int code;
396 const uint8_t *d;
397
c6148de2
MN
398 d = p->buf;
399 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
400 if (code == 0x10) {
401 return 50;
402 }
403 return 0;
404}
405
7156aeb9
JR
406static int ac3_probe(AVProbeData *p)
407{
f8b9830b
JR
408 int max_frames, first_frames, frames;
409 uint8_t *buf, *buf2, *end;
410 AC3HeaderInfo hdr;
7156aeb9 411
f8b9830b 412 if(p->buf_size < 7)
7156aeb9
JR
413 return 0;
414
f8b9830b
JR
415 max_frames = 0;
416 buf = p->buf;
417 end = buf + FFMIN(4096, p->buf_size - 7);
418
419 for(; buf < end; buf++) {
420 buf2 = buf;
7156aeb9 421
f8b9830b
JR
422 for(frames = 0; buf2 < end; frames++) {
423 if(ff_ac3_parse_header(buf2, &hdr) < 0)
424 break;
425 buf2 += hdr.frame_size;
426 }
427 max_frames = FFMAX(max_frames, frames);
428 if(buf == p->buf)
429 first_frames = frames;
430 }
431 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
432 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
433 else if(max_frames>=1) return 1;
434 else return 0;
7156aeb9
JR
435}
436
d2a067d1 437AVInputFormat shorten_demuxer = {
85ad5695 438 "shn",
84c63c01 439 "raw shorten",
85ad5695
MN
440 0,
441 NULL,
442 shorten_read_header,
443 raw_read_partial_packet,
444 raw_read_close,
e9b78eeb 445 .flags= AVFMT_GENERIC_INDEX,
85ad5695
MN
446 .extensions = "shn",
447};
448
d2a067d1 449AVInputFormat flac_demuxer = {
89ca8c49
BL
450 "flac",
451 "raw flac",
452 0,
453 NULL,
454 flac_read_header,
455 raw_read_partial_packet,
456 raw_read_close,
e9b78eeb 457 .flags= AVFMT_GENERIC_INDEX,
89ca8c49
BL
458 .extensions = "flac",
459};
460
ce1d2a95 461#ifdef CONFIG_MUXERS
d2a067d1 462AVOutputFormat flac_muxer = {
ce1d2a95
JR
463 "flac",
464 "raw flac",
465 "audio/x-flac",
466 "flac",
467 0,
468 CODEC_ID_FLAC,
469 0,
470 flac_write_header,
471 raw_write_packet,
472 raw_write_trailer,
494bbf58 473 .flags= AVFMT_NOTIMESTAMPS,
ce1d2a95
JR
474};
475#endif //CONFIG_MUXERS
476
cefd4907 477#ifdef CONFIG_AC3_DEMUXER
d2a067d1 478AVInputFormat ac3_demuxer = {
c9a65ca8
FB
479 "ac3",
480 "raw ac3",
481 0,
7156aeb9 482 ac3_probe,
cd66005d 483 ac3_read_header,
e15dec10 484 raw_read_partial_packet,
de6d9b64 485 raw_read_close,
e9b78eeb 486 .flags= AVFMT_GENERIC_INDEX,
bb76a117 487 .extensions = "ac3",
de6d9b64 488};
cefd4907 489#endif
de6d9b64 490
a9e35095 491#ifdef CONFIG_MUXERS
d2a067d1 492AVOutputFormat ac3_muxer = {
de6d9b64
FB
493 "ac3",
494 "raw ac3",
115329f1 495 "audio/x-ac3",
de6d9b64 496 "ac3",
c9a65ca8 497 0,
de6d9b64
FB
498 CODEC_ID_AC3,
499 0,
500 raw_write_header,
501 raw_write_packet,
502 raw_write_trailer,
494bbf58 503 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 504};
a9e35095 505#endif //CONFIG_MUXERS
de6d9b64 506
d2a067d1 507AVInputFormat dts_demuxer = {
23c99253
MN
508 "dts",
509 "raw dts",
510 0,
511 NULL,
512 dts_read_header,
513 raw_read_partial_packet,
514 raw_read_close,
e9b78eeb 515 .flags= AVFMT_GENERIC_INDEX,
23c99253
MN
516 .extensions = "dts",
517};
518
d2a067d1 519AVInputFormat aac_demuxer = {
fda885c7
MR
520 "aac",
521 "ADTS AAC",
522 0,
523 NULL,
524 aac_read_header,
525 raw_read_partial_packet,
526 raw_read_close,
e9b78eeb 527 .flags= AVFMT_GENERIC_INDEX,
fda885c7
MR
528 .extensions = "aac",
529};
530
d2a067d1 531AVInputFormat h261_demuxer = {
c6148de2
MN
532 "h261",
533 "raw h261",
534 0,
535 h261_probe,
536 video_read_header,
537 raw_read_partial_packet,
538 raw_read_close,
e9b78eeb 539 .flags= AVFMT_GENERIC_INDEX,
c6148de2
MN
540 .extensions = "h261",
541 .value = CODEC_ID_H261,
542};
543
a9e35095 544#ifdef CONFIG_MUXERS
d2a067d1 545AVOutputFormat h261_muxer = {
1c3990db
MN
546 "h261",
547 "raw h261",
548 "video/x-h261",
549 "h261",
550 0,
551 0,
552 CODEC_ID_H261,
553 raw_write_header,
554 raw_write_packet,
555 raw_write_trailer,
494bbf58 556 .flags= AVFMT_NOTIMESTAMPS,
1c3990db 557};
a9e35095 558#endif //CONFIG_MUXERS
1c3990db 559
d2a067d1 560AVInputFormat h263_demuxer = {
d07f9043
MN
561 "h263",
562 "raw h263",
563 0,
564 h263_probe,
565 video_read_header,
e15dec10 566 raw_read_partial_packet,
d07f9043 567 raw_read_close,
e9b78eeb 568 .flags= AVFMT_GENERIC_INDEX,
d07f9043
MN
569// .extensions = "h263", //FIXME remove after writing mpeg4_probe
570 .value = CODEC_ID_H263,
571};
572
a9e35095 573#ifdef CONFIG_MUXERS
d2a067d1 574AVOutputFormat h263_muxer = {
de6d9b64
FB
575 "h263",
576 "raw h263",
577 "video/x-h263",
578 "h263",
579 0,
c9a65ca8 580 0,
de6d9b64
FB
581 CODEC_ID_H263,
582 raw_write_header,
583 raw_write_packet,
584 raw_write_trailer,
494bbf58 585 .flags= AVFMT_NOTIMESTAMPS,
c9a65ca8 586};
a9e35095 587#endif //CONFIG_MUXERS
c9a65ca8 588
d2a067d1 589AVInputFormat m4v_demuxer = {
7866eeff
MN
590 "m4v",
591 "raw MPEG4 video format",
592 0,
8f57cc5a 593 mpeg4video_probe, /** probing for mpeg4 data */
7866eeff 594 video_read_header,
e15dec10 595 raw_read_partial_packet,
7866eeff 596 raw_read_close,
e9b78eeb 597 .flags= AVFMT_GENERIC_INDEX,
bb76a117
MR
598 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
599 .value = CODEC_ID_MPEG4,
7866eeff
MN
600};
601
a9e35095 602#ifdef CONFIG_MUXERS
d2a067d1 603AVOutputFormat m4v_muxer = {
89b3d7c9
MK
604 "m4v",
605 "raw MPEG4 video format",
606 NULL,
607 "m4v",
608 0,
609 CODEC_ID_NONE,
610 CODEC_ID_MPEG4,
611 raw_write_header,
612 raw_write_packet,
613 raw_write_trailer,
494bbf58 614 .flags= AVFMT_NOTIMESTAMPS,
89b3d7c9 615};
a9e35095 616#endif //CONFIG_MUXERS
89b3d7c9 617
d2a067d1 618AVInputFormat h264_demuxer = {
0da71265
MN
619 "h264",
620 "raw H264 video format",
621 0,
622 NULL /*mpegvideo_probe*/,
623 video_read_header,
e15dec10 624 raw_read_partial_packet,
0da71265 625 raw_read_close,
e9b78eeb 626 .flags= AVFMT_GENERIC_INDEX,
ba5697d5 627 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
0da71265
MN
628 .value = CODEC_ID_H264,
629};
630
a9e35095 631#ifdef CONFIG_MUXERS
d2a067d1 632AVOutputFormat h264_muxer = {
0da71265
MN
633 "h264",
634 "raw H264 video format",
635 NULL,
636 "h264",
637 0,
638 CODEC_ID_NONE,
639 CODEC_ID_H264,
640 raw_write_header,
641 raw_write_packet,
642 raw_write_trailer,
494bbf58 643 .flags= AVFMT_NOTIMESTAMPS,
0da71265 644};
a9e35095 645#endif //CONFIG_MUXERS
0da71265 646
d2a067d1 647AVInputFormat mpegvideo_demuxer = {
c9a65ca8
FB
648 "mpegvideo",
649 "MPEG video",
650 0,
651 mpegvideo_probe,
de6d9b64 652 video_read_header,
e15dec10 653 raw_read_partial_packet,
de6d9b64 654 raw_read_close,
e9b78eeb 655 .flags= AVFMT_GENERIC_INDEX,
bb76a117 656 .value = CODEC_ID_MPEG1VIDEO,
de6d9b64
FB
657};
658
a9e35095 659#ifdef CONFIG_MUXERS
d2a067d1 660AVOutputFormat mpeg1video_muxer = {
c9a65ca8 661 "mpeg1video",
de6d9b64
FB
662 "MPEG video",
663 "video/x-mpeg",
e0827ba4 664 "mpg,mpeg,m1v",
de6d9b64 665 0,
c9a65ca8 666 0,
de6d9b64
FB
667 CODEC_ID_MPEG1VIDEO,
668 raw_write_header,
669 raw_write_packet,
670 raw_write_trailer,
494bbf58 671 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 672};
a9e35095 673#endif //CONFIG_MUXERS
de6d9b64 674
a9e35095 675#ifdef CONFIG_MUXERS
d2a067d1 676AVOutputFormat mpeg2video_muxer = {
6ec864da
MN
677 "mpeg2video",
678 "MPEG2 video",
679 NULL,
680 "m2v",
681 0,
682 0,
683 CODEC_ID_MPEG2VIDEO,
684 raw_write_header,
685 raw_write_packet,
686 raw_write_trailer,
494bbf58 687 .flags= AVFMT_NOTIMESTAMPS,
6ec864da 688};
a9e35095 689#endif //CONFIG_MUXERS
6ec864da 690
d2a067d1 691AVInputFormat mjpeg_demuxer = {
27e084bd
FB
692 "mjpeg",
693 "MJPEG video",
27e084bd 694 0,
c9a65ca8 695 NULL,
27e084bd 696 video_read_header,
e15dec10 697 raw_read_partial_packet,
27e084bd 698 raw_read_close,
e9b78eeb 699 .flags= AVFMT_GENERIC_INDEX,
bb76a117
MR
700 .extensions = "mjpg,mjpeg",
701 .value = CODEC_ID_MJPEG,
27e084bd
FB
702};
703
d2a067d1 704AVInputFormat ingenient_demuxer = {
84c63c01
AB
705 "ingenient",
706 "Ingenient MJPEG",
707 0,
708 NULL,
709 video_read_header,
710 ingenient_read_packet,
711 raw_read_close,
e9b78eeb 712 .flags= AVFMT_GENERIC_INDEX,
84c63c01
AB
713 .extensions = "cgi", // FIXME
714 .value = CODEC_ID_MJPEG,
715};
716
a9e35095 717#ifdef CONFIG_MUXERS
d2a067d1 718AVOutputFormat mjpeg_muxer = {
c9a65ca8
FB
719 "mjpeg",
720 "MJPEG video",
721 "video/x-mjpeg",
722 "mjpg,mjpeg",
5ed8fafc 723 0,
5ed8fafc 724 0,
c9a65ca8 725 CODEC_ID_MJPEG,
5ed8fafc
FB
726 raw_write_header,
727 raw_write_packet,
728 raw_write_trailer,
494bbf58 729 .flags= AVFMT_NOTIMESTAMPS,
5ed8fafc 730};
a9e35095 731#endif //CONFIG_MUXERS
5ed8fafc 732
7bb5c2a6
KS
733AVInputFormat vc1_demuxer = {
734 "vc1",
735 "raw vc1",
736 0,
737 NULL /* vc1_probe */,
738 video_read_header,
739 raw_read_partial_packet,
740 raw_read_close,
741 .extensions = "vc1",
742 .value = CODEC_ID_VC1,
743};
744
c9a65ca8 745/* pcm formats */
764ef400 746
4986a429 747#define PCMINPUTDEF(name, long_name, ext, codec) \
d2a067d1 748AVInputFormat pcm_ ## name ## _demuxer = {\
764ef400
MM
749 #name,\
750 long_name,\
751 0,\
752 NULL,\
753 raw_read_header,\
754 raw_read_packet,\
755 raw_read_close,\
4986a429 756 pcm_read_seek,\
e9b78eeb 757 .flags= AVFMT_GENERIC_INDEX,\
764ef400
MM
758 .extensions = ext,\
759 .value = codec,\
760};
761
2c8e2014 762#define PCMOUTPUTDEF(name, long_name, ext, codec) \
d2a067d1 763AVOutputFormat pcm_ ## name ## _muxer = {\
c9a65ca8
FB
764 #name,\
765 long_name,\
766 NULL,\
767 ext,\
768 0,\
769 codec,\
770 0,\
771 raw_write_header,\
772 raw_write_packet,\
773 raw_write_trailer,\
494bbf58 774 .flags= AVFMT_NOTIMESTAMPS,\
5ed8fafc 775};
2c8e2014
DB
776
777
778#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
779#define PCMDEF(name, long_name, ext, codec) \
780 PCMINPUTDEF(name, long_name, ext, codec)
781#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
782#define PCMDEF(name, long_name, ext, codec) \
783 PCMOUTPUTDEF(name, long_name, ext, codec)
784#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
785#define PCMDEF(name, long_name, ext, codec) \
786 PCMINPUTDEF(name, long_name, ext, codec)\
787 PCMOUTPUTDEF(name, long_name, ext, codec)
788#else
789#define PCMDEF(name, long_name, ext, codec)
790#endif
5ed8fafc 791
5ed8fafc 792#ifdef WORDS_BIGENDIAN
c9a65ca8
FB
793#define BE_DEF(s) s
794#define LE_DEF(s) NULL
5ed8fafc 795#else
c9a65ca8
FB
796#define BE_DEF(s) NULL
797#define LE_DEF(s) s
5ed8fafc 798#endif
5ed8fafc 799
5ed8fafc 800
115329f1 801PCMDEF(s16le, "pcm signed 16 bit little endian format",
c9a65ca8 802 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
5ed8fafc 803
115329f1 804PCMDEF(s16be, "pcm signed 16 bit big endian format",
c9a65ca8 805 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
5ed8fafc 806
115329f1 807PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
c9a65ca8 808 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
5ed8fafc 809
115329f1 810PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
c9a65ca8 811 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
5ed8fafc 812
115329f1 813PCMDEF(s8, "pcm signed 8 bit format",
c9a65ca8 814 "sb", CODEC_ID_PCM_S8)
5ed8fafc 815
115329f1 816PCMDEF(u8, "pcm unsigned 8 bit format",
c9a65ca8 817 "ub", CODEC_ID_PCM_U8)
5ed8fafc 818
115329f1 819PCMDEF(mulaw, "pcm mu law format",
c9a65ca8 820 "ul", CODEC_ID_PCM_MULAW)
de6d9b64 821
115329f1 822PCMDEF(alaw, "pcm A law format",
c9a65ca8 823 "al", CODEC_ID_PCM_ALAW)
de6d9b64 824
5c91a675 825static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64
FB
826{
827 int packet_size, ret, width, height;
828 AVStream *st = s->streams[0];
829
01f4895c
MN
830 width = st->codec->width;
831 height = st->codec->height;
de6d9b64 832
01f4895c 833 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
63167088 834 if (packet_size < 0)
71c32f19 835 return -1;
de6d9b64 836
2692067a 837 ret= av_get_packet(&s->pb, pkt, packet_size);
de6d9b64
FB
838
839 pkt->stream_index = 0;
2692067a 840 if (ret != packet_size) {
0bd586c5 841 return AVERROR_IO;
de6d9b64
FB
842 } else {
843 return 0;
844 }
845}
846
d2a067d1 847AVInputFormat rawvideo_demuxer = {
c9a65ca8
FB
848 "rawvideo",
849 "raw video format",
850 0,
851 NULL,
852 raw_read_header,
853 rawvideo_read_packet,
854 raw_read_close,
e9b78eeb 855 .flags= AVFMT_GENERIC_INDEX,
bfc7f165 856 .extensions = "yuv,cif,qcif",
bb76a117 857 .value = CODEC_ID_RAWVIDEO,
c9a65ca8
FB
858};
859
a9e35095 860#ifdef CONFIG_MUXERS
d2a067d1 861AVOutputFormat rawvideo_muxer = {
de6d9b64
FB
862 "rawvideo",
863 "raw video format",
864 NULL,
865 "yuv",
c9a65ca8 866 0,
de6d9b64
FB
867 CODEC_ID_NONE,
868 CODEC_ID_RAWVIDEO,
869 raw_write_header,
870 raw_write_packet,
871 raw_write_trailer,
494bbf58 872 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 873};
a9e35095 874#endif //CONFIG_MUXERS
c9a65ca8 875
a9e35095 876#ifdef CONFIG_MUXERS
e928649b 877static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
87bdd3e5
FB
878{
879 return 0;
880}
881
d2a067d1 882AVOutputFormat null_muxer = {
87bdd3e5
FB
883 "null",
884 "null video format",
885 NULL,
886 NULL,
887 0,
888#ifdef WORDS_BIGENDIAN
889 CODEC_ID_PCM_S16BE,
890#else
891 CODEC_ID_PCM_S16LE,
892#endif
893 CODEC_ID_RAWVIDEO,
894 raw_write_header,
895 null_write_packet,
896 raw_write_trailer,
494bbf58 897 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
87bdd3e5 898};
a9e35095 899#endif //CONFIG_MUXERS