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