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