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