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