Import Dirac demuxer/muxer from SoC branch; written by Marco Gerards,
[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 256 st->codec->codec_id == CODEC_ID_MPEG4 ||
17ac9f1c 257 st->codec->codec_id == CODEC_ID_DIRAC ||
01f4895c 258 st->codec->codec_id == CODEC_ID_H264) {
80ce3254 259 av_set_pts_info(st, 64, 1, 25);
27e084bd 260 }
80ce3254 261
de6d9b64
FB
262 return 0;
263}
264
bb270c08
DB
265#define SEQ_START_CODE 0x000001b3
266#define GOP_START_CODE 0x000001b8
267#define PICTURE_START_CODE 0x00000100
93d3e278
MN
268#define SLICE_START_CODE 0x00000101
269#define PACK_START_CODE 0x000001ba
e01dc227
MR
270#define VIDEO_ID 0x000001e0
271#define AUDIO_ID 0x000001c0
c9a65ca8 272
c9a65ca8
FB
273static int mpegvideo_probe(AVProbeData *p)
274{
93d3e278 275 uint32_t code= -1;
e01dc227 276 int pic=0, seq=0, slice=0, pspack=0, pes=0;
93d3e278
MN
277 int i;
278
279 for(i=0; i<p->buf_size; i++){
280 code = (code<<8) + p->buf[i];
281 if ((code & 0xffffff00) == 0x100) {
282 switch(code){
283 case SEQ_START_CODE: seq++; break;
284 case PICTURE_START_CODE: pic++; break;
285 case SLICE_START_CODE: slice++; break;
286 case PACK_START_CODE: pspack++; break;
287 }
e9f6c8ea
MN
288 if ((code & 0x1f0) == VIDEO_ID) pes++;
289 else if((code & 0x1e0) == AUDIO_ID) pes++;
93d3e278 290 }
c9a65ca8 291 }
e01dc227 292 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
93d3e278 293 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
c9a65ca8
FB
294 return 0;
295}
296
8f57cc5a
TV
297#define VISUAL_OBJECT_START_CODE 0x000001b5
298#define VOP_START_CODE 0x000001b6
299
300static int mpeg4video_probe(AVProbeData *probe_packet)
301{
302 uint32_t temp_buffer= -1;
5fd5d0ef 303 int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
8f57cc5a
TV
304 int i;
305
306 for(i=0; i<probe_packet->buf_size; i++){
307 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
c21f308e
RS
308 if ((temp_buffer & 0xffffff00) != 0x100)
309 continue;
310
311 if (temp_buffer == VOP_START_CODE) VOP++;
312 else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++;
313 else if (temp_buffer < 0x120) VO++;
314 else if (temp_buffer < 0x130) VOL++;
315 else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
316 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
8f57cc5a
TV
317 }
318
5fd5d0ef 319 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
8f57cc5a
TV
320 return AVPROBE_SCORE_MAX/2;
321 return 0;
322}
323
d07f9043
MN
324static int h263_probe(AVProbeData *p)
325{
326 int code;
327 const uint8_t *d;
328
d07f9043
MN
329 d = p->buf;
330 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
331 if (code == 0x20) {
332 return 50;
333 }
334 return 0;
335}
336
c6148de2
MN
337static int h261_probe(AVProbeData *p)
338{
339 int code;
340 const uint8_t *d;
341
c6148de2
MN
342 d = p->buf;
343 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
344 if (code == 0x10) {
345 return 50;
346 }
347 return 0;
348}
349
17ac9f1c
LB
350static int dirac_probe(AVProbeData *p)
351{
352 if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
353 return AVPROBE_SCORE_MAX;
354 else
355 return 0;
356}
357
7156aeb9
JR
358static int ac3_probe(AVProbeData *p)
359{
8c222bb4 360 int max_frames, first_frames = 0, frames;
f8b9830b
JR
361 uint8_t *buf, *buf2, *end;
362 AC3HeaderInfo hdr;
55736cfb 363 GetBitContext gbc;
7156aeb9 364
f8b9830b
JR
365 max_frames = 0;
366 buf = p->buf;
ecc8fc11 367 end = buf + p->buf_size;
f8b9830b
JR
368
369 for(; buf < end; buf++) {
370 buf2 = buf;
7156aeb9 371
f8b9830b 372 for(frames = 0; buf2 < end; frames++) {
55736cfb
BW
373 init_get_bits(&gbc, buf2, 54);
374 if(ff_ac3_parse_header(&gbc, &hdr) < 0)
f8b9830b 375 break;
c675ef70
376 if(buf2 + hdr.frame_size > end ||
377 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
378 break;
f8b9830b
JR
379 buf2 += hdr.frame_size;
380 }
381 max_frames = FFMAX(max_frames, frames);
382 if(buf == p->buf)
383 first_frames = frames;
384 }
385 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
2477ce23 386 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
f8b9830b
JR
387 else if(max_frames>=1) return 1;
388 else return 0;
7156aeb9
JR
389}
390
e020dbd2
MN
391static int flac_probe(AVProbeData *p)
392{
393 if(memcmp(p->buf, "fLaC", 4)) return 0;
fbd69f51 394 else return AVPROBE_SCORE_MAX / 2;
e020dbd2
MN
395}
396
d2a067d1 397AVInputFormat shorten_demuxer = {
85ad5695 398 "shn",
84c63c01 399 "raw shorten",
85ad5695
MN
400 0,
401 NULL,
a0af2fa4 402 audio_read_header,
85ad5695
MN
403 raw_read_partial_packet,
404 raw_read_close,
e9b78eeb 405 .flags= AVFMT_GENERIC_INDEX,
85ad5695 406 .extensions = "shn",
a0af2fa4 407 .value = CODEC_ID_SHORTEN,
85ad5695
MN
408};
409
d2a067d1 410AVInputFormat flac_demuxer = {
89ca8c49
BL
411 "flac",
412 "raw flac",
413 0,
e020dbd2 414 flac_probe,
a0af2fa4 415 audio_read_header,
89ca8c49
BL
416 raw_read_partial_packet,
417 raw_read_close,
e9b78eeb 418 .flags= AVFMT_GENERIC_INDEX,
89ca8c49 419 .extensions = "flac",
a0af2fa4 420 .value = CODEC_ID_FLAC,
89ca8c49
BL
421};
422
ce1d2a95 423#ifdef CONFIG_MUXERS
d2a067d1 424AVOutputFormat flac_muxer = {
ce1d2a95
JR
425 "flac",
426 "raw flac",
427 "audio/x-flac",
428 "flac",
429 0,
430 CODEC_ID_FLAC,
431 0,
432 flac_write_header,
433 raw_write_packet,
494bbf58 434 .flags= AVFMT_NOTIMESTAMPS,
ce1d2a95
JR
435};
436#endif //CONFIG_MUXERS
437
cefd4907 438#ifdef CONFIG_AC3_DEMUXER
d2a067d1 439AVInputFormat ac3_demuxer = {
c9a65ca8
FB
440 "ac3",
441 "raw ac3",
442 0,
7156aeb9 443 ac3_probe,
a0af2fa4 444 audio_read_header,
e15dec10 445 raw_read_partial_packet,
de6d9b64 446 raw_read_close,
e9b78eeb 447 .flags= AVFMT_GENERIC_INDEX,
bb76a117 448 .extensions = "ac3",
a0af2fa4 449 .value = CODEC_ID_AC3,
de6d9b64 450};
cefd4907 451#endif
de6d9b64 452
a9e35095 453#ifdef CONFIG_MUXERS
d2a067d1 454AVOutputFormat ac3_muxer = {
de6d9b64
FB
455 "ac3",
456 "raw ac3",
115329f1 457 "audio/x-ac3",
de6d9b64 458 "ac3",
c9a65ca8 459 0,
de6d9b64
FB
460 CODEC_ID_AC3,
461 0,
7a97dd84 462 NULL,
de6d9b64 463 raw_write_packet,
494bbf58 464 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 465};
63d86443
BL
466
467AVOutputFormat dts_muxer = {
468 "dts",
469 "raw dts",
470 "audio/x-dca",
471 "dts",
472 0,
473 CODEC_ID_DTS,
474 0,
475 NULL,
476 raw_write_packet,
477 .flags= AVFMT_NOTIMESTAMPS,
478};
479
a9e35095 480#endif //CONFIG_MUXERS
de6d9b64 481
17ac9f1c
LB
482AVInputFormat dirac_demuxer = {
483 "dirac",
484 "raw dirac",
485 0,
486 dirac_probe,
487 video_read_header,
488 raw_read_partial_packet,
489 raw_read_close,
490 .flags= AVFMT_GENERIC_INDEX,
491 .value = CODEC_ID_DIRAC,
492};
493
494#ifdef CONFIG_MUXERS
495AVOutputFormat dirac_muxer = {
496 "dirac",
497 "raw dirac",
498 NULL,
499 "drc",
500 0,
501 0,
502 CODEC_ID_DIRAC,
503 NULL,
504 raw_write_packet,
505 .flags= AVFMT_NOTIMESTAMPS,
506};
507#endif
508
d2a067d1 509AVInputFormat dts_demuxer = {
23c99253
MN
510 "dts",
511 "raw dts",
512 0,
513 NULL,
a0af2fa4 514 audio_read_header,
23c99253
MN
515 raw_read_partial_packet,
516 raw_read_close,
e9b78eeb 517 .flags= AVFMT_GENERIC_INDEX,
23c99253 518 .extensions = "dts",
a0af2fa4 519 .value = CODEC_ID_DTS,
23c99253
MN
520};
521
d2a067d1 522AVInputFormat aac_demuxer = {
fda885c7
MR
523 "aac",
524 "ADTS AAC",
525 0,
526 NULL,
a0af2fa4 527 audio_read_header,
fda885c7
MR
528 raw_read_partial_packet,
529 raw_read_close,
e9b78eeb 530 .flags= AVFMT_GENERIC_INDEX,
fda885c7 531 .extensions = "aac",
a0af2fa4 532 .value = CODEC_ID_AAC,
fda885c7
MR
533};
534
60711e95
MN
535AVInputFormat gsm_demuxer = {
536 "gsm",
537 "GSM",
538 0,
539 NULL,
540 audio_read_header,
541 raw_read_partial_packet,
542 raw_read_close,
543 .flags= AVFMT_GENERIC_INDEX,
544 .extensions = "gsm",
545 .value = CODEC_ID_GSM,
546};
547
13dec857
VS
548#ifdef CONFIG_ROQ_MUXER
549AVOutputFormat roq_muxer =
550{
551 "RoQ",
552 "Id RoQ format",
553 NULL,
554 "roq",
555 0,
556 CODEC_ID_ROQ_DPCM,
557 CODEC_ID_ROQ,
558 roq_write_header,
559 raw_write_packet,
13dec857
VS
560};
561#endif //CONFIG_ROQ_MUXER
562
d2a067d1 563AVInputFormat h261_demuxer = {
c6148de2
MN
564 "h261",
565 "raw h261",
566 0,
567 h261_probe,
568 video_read_header,
569 raw_read_partial_packet,
570 raw_read_close,
e9b78eeb 571 .flags= AVFMT_GENERIC_INDEX,
c6148de2
MN
572 .extensions = "h261",
573 .value = CODEC_ID_H261,
574};
575
a9e35095 576#ifdef CONFIG_MUXERS
d2a067d1 577AVOutputFormat h261_muxer = {
1c3990db
MN
578 "h261",
579 "raw h261",
580 "video/x-h261",
581 "h261",
582 0,
583 0,
584 CODEC_ID_H261,
7a97dd84 585 NULL,
1c3990db 586 raw_write_packet,
494bbf58 587 .flags= AVFMT_NOTIMESTAMPS,
1c3990db 588};
a9e35095 589#endif //CONFIG_MUXERS
1c3990db 590
d2a067d1 591AVInputFormat h263_demuxer = {
d07f9043
MN
592 "h263",
593 "raw h263",
594 0,
595 h263_probe,
596 video_read_header,
e15dec10 597 raw_read_partial_packet,
d07f9043 598 raw_read_close,
e9b78eeb 599 .flags= AVFMT_GENERIC_INDEX,
d07f9043
MN
600// .extensions = "h263", //FIXME remove after writing mpeg4_probe
601 .value = CODEC_ID_H263,
602};
603
a9e35095 604#ifdef CONFIG_MUXERS
d2a067d1 605AVOutputFormat h263_muxer = {
de6d9b64
FB
606 "h263",
607 "raw h263",
608 "video/x-h263",
609 "h263",
610 0,
c9a65ca8 611 0,
de6d9b64 612 CODEC_ID_H263,
7a97dd84 613 NULL,
de6d9b64 614 raw_write_packet,
494bbf58 615 .flags= AVFMT_NOTIMESTAMPS,
c9a65ca8 616};
a9e35095 617#endif //CONFIG_MUXERS
c9a65ca8 618
d2a067d1 619AVInputFormat m4v_demuxer = {
7866eeff
MN
620 "m4v",
621 "raw MPEG4 video format",
622 0,
8f57cc5a 623 mpeg4video_probe, /** probing for mpeg4 data */
7866eeff 624 video_read_header,
e15dec10 625 raw_read_partial_packet,
7866eeff 626 raw_read_close,
e9b78eeb 627 .flags= AVFMT_GENERIC_INDEX,
bb76a117
MR
628 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
629 .value = CODEC_ID_MPEG4,
7866eeff
MN
630};
631
a9e35095 632#ifdef CONFIG_MUXERS
d2a067d1 633AVOutputFormat m4v_muxer = {
89b3d7c9
MK
634 "m4v",
635 "raw MPEG4 video format",
636 NULL,
637 "m4v",
638 0,
639 CODEC_ID_NONE,
640 CODEC_ID_MPEG4,
7a97dd84 641 NULL,
89b3d7c9 642 raw_write_packet,
494bbf58 643 .flags= AVFMT_NOTIMESTAMPS,
89b3d7c9 644};
a9e35095 645#endif //CONFIG_MUXERS
89b3d7c9 646
d2a067d1 647AVInputFormat h264_demuxer = {
0da71265
MN
648 "h264",
649 "raw H264 video format",
650 0,
651 NULL /*mpegvideo_probe*/,
652 video_read_header,
e15dec10 653 raw_read_partial_packet,
0da71265 654 raw_read_close,
e9b78eeb 655 .flags= AVFMT_GENERIC_INDEX,
ba5697d5 656 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
0da71265
MN
657 .value = CODEC_ID_H264,
658};
659
a9e35095 660#ifdef CONFIG_MUXERS
d2a067d1 661AVOutputFormat h264_muxer = {
0da71265
MN
662 "h264",
663 "raw H264 video format",
664 NULL,
665 "h264",
666 0,
667 CODEC_ID_NONE,
668 CODEC_ID_H264,
7a97dd84 669 NULL,
0da71265 670 raw_write_packet,
494bbf58 671 .flags= AVFMT_NOTIMESTAMPS,
0da71265 672};
a9e35095 673#endif //CONFIG_MUXERS
0da71265 674
d2a067d1 675AVInputFormat mpegvideo_demuxer = {
c9a65ca8
FB
676 "mpegvideo",
677 "MPEG video",
678 0,
679 mpegvideo_probe,
de6d9b64 680 video_read_header,
e15dec10 681 raw_read_partial_packet,
de6d9b64 682 raw_read_close,
e9b78eeb 683 .flags= AVFMT_GENERIC_INDEX,
bb76a117 684 .value = CODEC_ID_MPEG1VIDEO,
de6d9b64
FB
685};
686
a9e35095 687#ifdef CONFIG_MUXERS
d2a067d1 688AVOutputFormat mpeg1video_muxer = {
c9a65ca8 689 "mpeg1video",
de6d9b64
FB
690 "MPEG video",
691 "video/x-mpeg",
e0827ba4 692 "mpg,mpeg,m1v",
de6d9b64 693 0,
c9a65ca8 694 0,
de6d9b64 695 CODEC_ID_MPEG1VIDEO,
7a97dd84 696 NULL,
de6d9b64 697 raw_write_packet,
494bbf58 698 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 699};
a9e35095 700#endif //CONFIG_MUXERS
de6d9b64 701
a9e35095 702#ifdef CONFIG_MUXERS
d2a067d1 703AVOutputFormat mpeg2video_muxer = {
6ec864da
MN
704 "mpeg2video",
705 "MPEG2 video",
706 NULL,
707 "m2v",
708 0,
709 0,
710 CODEC_ID_MPEG2VIDEO,
7a97dd84 711 NULL,
6ec864da 712 raw_write_packet,
494bbf58 713 .flags= AVFMT_NOTIMESTAMPS,
6ec864da 714};
a9e35095 715#endif //CONFIG_MUXERS
6ec864da 716
d2a067d1 717AVInputFormat mjpeg_demuxer = {
27e084bd
FB
718 "mjpeg",
719 "MJPEG video",
27e084bd 720 0,
c9a65ca8 721 NULL,
27e084bd 722 video_read_header,
e15dec10 723 raw_read_partial_packet,
27e084bd 724 raw_read_close,
e9b78eeb 725 .flags= AVFMT_GENERIC_INDEX,
bb76a117
MR
726 .extensions = "mjpg,mjpeg",
727 .value = CODEC_ID_MJPEG,
27e084bd
FB
728};
729
d2a067d1 730AVInputFormat ingenient_demuxer = {
84c63c01
AB
731 "ingenient",
732 "Ingenient MJPEG",
733 0,
734 NULL,
735 video_read_header,
736 ingenient_read_packet,
737 raw_read_close,
e9b78eeb 738 .flags= AVFMT_GENERIC_INDEX,
84c63c01
AB
739 .extensions = "cgi", // FIXME
740 .value = CODEC_ID_MJPEG,
741};
742
a9e35095 743#ifdef CONFIG_MUXERS
d2a067d1 744AVOutputFormat mjpeg_muxer = {
c9a65ca8
FB
745 "mjpeg",
746 "MJPEG video",
747 "video/x-mjpeg",
748 "mjpg,mjpeg",
5ed8fafc 749 0,
5ed8fafc 750 0,
c9a65ca8 751 CODEC_ID_MJPEG,
7a97dd84 752 NULL,
5ed8fafc 753 raw_write_packet,
494bbf58 754 .flags= AVFMT_NOTIMESTAMPS,
5ed8fafc 755};
a9e35095 756#endif //CONFIG_MUXERS
5ed8fafc 757
7bb5c2a6
KS
758AVInputFormat vc1_demuxer = {
759 "vc1",
760 "raw vc1",
761 0,
762 NULL /* vc1_probe */,
763 video_read_header,
764 raw_read_partial_packet,
765 raw_read_close,
766 .extensions = "vc1",
767 .value = CODEC_ID_VC1,
768};
769
c9a65ca8 770/* pcm formats */
764ef400 771
4986a429 772#define PCMINPUTDEF(name, long_name, ext, codec) \
d2a067d1 773AVInputFormat pcm_ ## name ## _demuxer = {\
764ef400
MM
774 #name,\
775 long_name,\
776 0,\
777 NULL,\
778 raw_read_header,\
779 raw_read_packet,\
780 raw_read_close,\
4986a429 781 pcm_read_seek,\
e9b78eeb 782 .flags= AVFMT_GENERIC_INDEX,\
764ef400
MM
783 .extensions = ext,\
784 .value = codec,\
785};
786
2c8e2014 787#define PCMOUTPUTDEF(name, long_name, ext, codec) \
d2a067d1 788AVOutputFormat pcm_ ## name ## _muxer = {\
c9a65ca8
FB
789 #name,\
790 long_name,\
791 NULL,\
792 ext,\
793 0,\
794 codec,\
795 0,\
7a97dd84 796 NULL,\
c9a65ca8 797 raw_write_packet,\
494bbf58 798 .flags= AVFMT_NOTIMESTAMPS,\
5ed8fafc 799};
2c8e2014
DB
800
801
802#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
803#define PCMDEF(name, long_name, ext, codec) \
804 PCMINPUTDEF(name, long_name, ext, codec)
805#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
806#define PCMDEF(name, long_name, ext, codec) \
807 PCMOUTPUTDEF(name, long_name, ext, codec)
808#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
809#define PCMDEF(name, long_name, ext, codec) \
810 PCMINPUTDEF(name, long_name, ext, codec)\
811 PCMOUTPUTDEF(name, long_name, ext, codec)
812#else
813#define PCMDEF(name, long_name, ext, codec)
814#endif
5ed8fafc 815
5ed8fafc 816#ifdef WORDS_BIGENDIAN
c9a65ca8
FB
817#define BE_DEF(s) s
818#define LE_DEF(s) NULL
5ed8fafc 819#else
c9a65ca8
FB
820#define BE_DEF(s) NULL
821#define LE_DEF(s) s
5ed8fafc 822#endif
5ed8fafc 823
5ed8fafc 824
115329f1 825PCMDEF(s16le, "pcm signed 16 bit little endian format",
c9a65ca8 826 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
5ed8fafc 827
115329f1 828PCMDEF(s16be, "pcm signed 16 bit big endian format",
c9a65ca8 829 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
5ed8fafc 830
115329f1 831PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
c9a65ca8 832 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
5ed8fafc 833
115329f1 834PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
c9a65ca8 835 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
5ed8fafc 836
115329f1 837PCMDEF(s8, "pcm signed 8 bit format",
c9a65ca8 838 "sb", CODEC_ID_PCM_S8)
5ed8fafc 839
115329f1 840PCMDEF(u8, "pcm unsigned 8 bit format",
c9a65ca8 841 "ub", CODEC_ID_PCM_U8)
5ed8fafc 842
115329f1 843PCMDEF(mulaw, "pcm mu law format",
c9a65ca8 844 "ul", CODEC_ID_PCM_MULAW)
de6d9b64 845
115329f1 846PCMDEF(alaw, "pcm A law format",
c9a65ca8 847 "al", CODEC_ID_PCM_ALAW)
de6d9b64 848
5c91a675 849static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64
FB
850{
851 int packet_size, ret, width, height;
852 AVStream *st = s->streams[0];
853
01f4895c
MN
854 width = st->codec->width;
855 height = st->codec->height;
de6d9b64 856
01f4895c 857 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
63167088 858 if (packet_size < 0)
71c32f19 859 return -1;
de6d9b64 860
899681cd 861 ret= av_get_packet(s->pb, pkt, packet_size);
f5b41031
MN
862 pkt->pts=
863 pkt->dts= pkt->pos / packet_size;
de6d9b64
FB
864
865 pkt->stream_index = 0;
2692067a 866 if (ret != packet_size) {
6f3e0b21 867 return AVERROR(EIO);
de6d9b64
FB
868 } else {
869 return 0;
870 }
871}
872
d2a067d1 873AVInputFormat rawvideo_demuxer = {
c9a65ca8
FB
874 "rawvideo",
875 "raw video format",
876 0,
877 NULL,
878 raw_read_header,
879 rawvideo_read_packet,
880 raw_read_close,
e9b78eeb 881 .flags= AVFMT_GENERIC_INDEX,
5faf2d36 882 .extensions = "yuv,cif,qcif,rgb",
bb76a117 883 .value = CODEC_ID_RAWVIDEO,
c9a65ca8
FB
884};
885
a9e35095 886#ifdef CONFIG_MUXERS
d2a067d1 887AVOutputFormat rawvideo_muxer = {
de6d9b64
FB
888 "rawvideo",
889 "raw video format",
890 NULL,
b47f86c4 891 "yuv,rgb",
c9a65ca8 892 0,
de6d9b64
FB
893 CODEC_ID_NONE,
894 CODEC_ID_RAWVIDEO,
7a97dd84 895 NULL,
de6d9b64 896 raw_write_packet,
494bbf58 897 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 898};
a9e35095 899#endif //CONFIG_MUXERS
c9a65ca8 900
a9e35095 901#ifdef CONFIG_MUXERS
e928649b 902static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
87bdd3e5
FB
903{
904 return 0;
905}
906
d2a067d1 907AVOutputFormat null_muxer = {
87bdd3e5
FB
908 "null",
909 "null video format",
910 NULL,
911 NULL,
912 0,
913#ifdef WORDS_BIGENDIAN
914 CODEC_ID_PCM_S16BE,
915#else
916 CODEC_ID_PCM_S16LE,
917#endif
918 CODEC_ID_RAWVIDEO,
7a97dd84 919 NULL,
87bdd3e5 920 null_write_packet,
494bbf58 921 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
87bdd3e5 922};
a9e35095 923#endif //CONFIG_MUXERS