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