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