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