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