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