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