() 10l
[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
d2a067d1 392AVInputFormat shorten_demuxer = {
85ad5695 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
d2a067d1 403AVInputFormat flac_demuxer = {
89ca8c49
BL
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 414#ifdef CONFIG_MUXERS
d2a067d1 415AVOutputFormat flac_muxer = {
ce1d2a95
JR
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,
494bbf58 426 .flags= AVFMT_NOTIMESTAMPS,
ce1d2a95
JR
427};
428#endif //CONFIG_MUXERS
429
d2a067d1 430AVInputFormat ac3_demuxer = {
c9a65ca8
FB
431 "ac3",
432 "raw ac3",
433 0,
434 NULL,
cd66005d 435 ac3_read_header,
e15dec10 436 raw_read_partial_packet,
de6d9b64 437 raw_read_close,
bb76a117 438 .extensions = "ac3",
de6d9b64
FB
439};
440
a9e35095 441#ifdef CONFIG_MUXERS
d2a067d1 442AVOutputFormat ac3_muxer = {
de6d9b64
FB
443 "ac3",
444 "raw ac3",
115329f1 445 "audio/x-ac3",
de6d9b64 446 "ac3",
c9a65ca8 447 0,
de6d9b64
FB
448 CODEC_ID_AC3,
449 0,
450 raw_write_header,
451 raw_write_packet,
452 raw_write_trailer,
494bbf58 453 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 454};
a9e35095 455#endif //CONFIG_MUXERS
de6d9b64 456
d2a067d1 457AVInputFormat dts_demuxer = {
23c99253
MN
458 "dts",
459 "raw dts",
460 0,
461 NULL,
462 dts_read_header,
463 raw_read_partial_packet,
464 raw_read_close,
465 .extensions = "dts",
466};
467
d2a067d1 468AVInputFormat aac_demuxer = {
fda885c7
MR
469 "aac",
470 "ADTS AAC",
471 0,
472 NULL,
473 aac_read_header,
474 raw_read_partial_packet,
475 raw_read_close,
476 .extensions = "aac",
477};
478
d2a067d1 479AVInputFormat h261_demuxer = {
c6148de2
MN
480 "h261",
481 "raw h261",
482 0,
483 h261_probe,
484 video_read_header,
485 raw_read_partial_packet,
486 raw_read_close,
487 .extensions = "h261",
488 .value = CODEC_ID_H261,
489};
490
a9e35095 491#ifdef CONFIG_MUXERS
d2a067d1 492AVOutputFormat h261_muxer = {
1c3990db
MN
493 "h261",
494 "raw h261",
495 "video/x-h261",
496 "h261",
497 0,
498 0,
499 CODEC_ID_H261,
500 raw_write_header,
501 raw_write_packet,
502 raw_write_trailer,
494bbf58 503 .flags= AVFMT_NOTIMESTAMPS,
1c3990db 504};
a9e35095 505#endif //CONFIG_MUXERS
1c3990db 506
d2a067d1 507AVInputFormat h263_demuxer = {
d07f9043
MN
508 "h263",
509 "raw h263",
510 0,
511 h263_probe,
512 video_read_header,
e15dec10 513 raw_read_partial_packet,
d07f9043
MN
514 raw_read_close,
515// .extensions = "h263", //FIXME remove after writing mpeg4_probe
516 .value = CODEC_ID_H263,
517};
518
a9e35095 519#ifdef CONFIG_MUXERS
d2a067d1 520AVOutputFormat h263_muxer = {
de6d9b64
FB
521 "h263",
522 "raw h263",
523 "video/x-h263",
524 "h263",
525 0,
c9a65ca8 526 0,
de6d9b64
FB
527 CODEC_ID_H263,
528 raw_write_header,
529 raw_write_packet,
530 raw_write_trailer,
494bbf58 531 .flags= AVFMT_NOTIMESTAMPS,
c9a65ca8 532};
a9e35095 533#endif //CONFIG_MUXERS
c9a65ca8 534
d2a067d1 535AVInputFormat m4v_demuxer = {
7866eeff
MN
536 "m4v",
537 "raw MPEG4 video format",
538 0,
2f0f5b20 539 NULL /*mpegvideo_probe*/,
7866eeff 540 video_read_header,
e15dec10 541 raw_read_partial_packet,
7866eeff 542 raw_read_close,
bb76a117
MR
543 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
544 .value = CODEC_ID_MPEG4,
7866eeff
MN
545};
546
a9e35095 547#ifdef CONFIG_MUXERS
d2a067d1 548AVOutputFormat m4v_muxer = {
89b3d7c9
MK
549 "m4v",
550 "raw MPEG4 video format",
551 NULL,
552 "m4v",
553 0,
554 CODEC_ID_NONE,
555 CODEC_ID_MPEG4,
556 raw_write_header,
557 raw_write_packet,
558 raw_write_trailer,
494bbf58 559 .flags= AVFMT_NOTIMESTAMPS,
89b3d7c9 560};
a9e35095 561#endif //CONFIG_MUXERS
89b3d7c9 562
d2a067d1 563AVInputFormat h264_demuxer = {
0da71265
MN
564 "h264",
565 "raw H264 video format",
566 0,
567 NULL /*mpegvideo_probe*/,
568 video_read_header,
e15dec10 569 raw_read_partial_packet,
0da71265 570 raw_read_close,
ba5697d5 571 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
0da71265
MN
572 .value = CODEC_ID_H264,
573};
574
a9e35095 575#ifdef CONFIG_MUXERS
d2a067d1 576AVOutputFormat h264_muxer = {
0da71265
MN
577 "h264",
578 "raw H264 video format",
579 NULL,
580 "h264",
581 0,
582 CODEC_ID_NONE,
583 CODEC_ID_H264,
584 raw_write_header,
585 raw_write_packet,
586 raw_write_trailer,
494bbf58 587 .flags= AVFMT_NOTIMESTAMPS,
0da71265 588};
a9e35095 589#endif //CONFIG_MUXERS
0da71265 590
d2a067d1 591AVInputFormat mpegvideo_demuxer = {
c9a65ca8
FB
592 "mpegvideo",
593 "MPEG video",
594 0,
595 mpegvideo_probe,
de6d9b64 596 video_read_header,
e15dec10 597 raw_read_partial_packet,
de6d9b64 598 raw_read_close,
bb76a117 599 .value = CODEC_ID_MPEG1VIDEO,
de6d9b64
FB
600};
601
a9e35095 602#ifdef CONFIG_MUXERS
d2a067d1 603AVOutputFormat mpeg1video_muxer = {
c9a65ca8 604 "mpeg1video",
de6d9b64
FB
605 "MPEG video",
606 "video/x-mpeg",
e0827ba4 607 "mpg,mpeg,m1v",
de6d9b64 608 0,
c9a65ca8 609 0,
de6d9b64
FB
610 CODEC_ID_MPEG1VIDEO,
611 raw_write_header,
612 raw_write_packet,
613 raw_write_trailer,
494bbf58 614 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 615};
a9e35095 616#endif //CONFIG_MUXERS
de6d9b64 617
a9e35095 618#ifdef CONFIG_MUXERS
d2a067d1 619AVOutputFormat mpeg2video_muxer = {
6ec864da
MN
620 "mpeg2video",
621 "MPEG2 video",
622 NULL,
623 "m2v",
624 0,
625 0,
626 CODEC_ID_MPEG2VIDEO,
627 raw_write_header,
628 raw_write_packet,
629 raw_write_trailer,
494bbf58 630 .flags= AVFMT_NOTIMESTAMPS,
6ec864da 631};
a9e35095 632#endif //CONFIG_MUXERS
6ec864da 633
d2a067d1 634AVInputFormat mjpeg_demuxer = {
27e084bd
FB
635 "mjpeg",
636 "MJPEG video",
27e084bd 637 0,
c9a65ca8 638 NULL,
27e084bd 639 video_read_header,
e15dec10 640 raw_read_partial_packet,
27e084bd 641 raw_read_close,
bb76a117
MR
642 .extensions = "mjpg,mjpeg",
643 .value = CODEC_ID_MJPEG,
27e084bd
FB
644};
645
d2a067d1 646AVInputFormat ingenient_demuxer = {
84c63c01
AB
647 "ingenient",
648 "Ingenient MJPEG",
649 0,
650 NULL,
651 video_read_header,
652 ingenient_read_packet,
653 raw_read_close,
654 .extensions = "cgi", // FIXME
655 .value = CODEC_ID_MJPEG,
656};
657
a9e35095 658#ifdef CONFIG_MUXERS
d2a067d1 659AVOutputFormat mjpeg_muxer = {
c9a65ca8
FB
660 "mjpeg",
661 "MJPEG video",
662 "video/x-mjpeg",
663 "mjpg,mjpeg",
5ed8fafc 664 0,
5ed8fafc 665 0,
c9a65ca8 666 CODEC_ID_MJPEG,
5ed8fafc
FB
667 raw_write_header,
668 raw_write_packet,
669 raw_write_trailer,
494bbf58 670 .flags= AVFMT_NOTIMESTAMPS,
5ed8fafc 671};
a9e35095 672#endif //CONFIG_MUXERS
5ed8fafc 673
c9a65ca8 674/* pcm formats */
764ef400 675
4986a429 676#define PCMINPUTDEF(name, long_name, ext, codec) \
d2a067d1 677AVInputFormat pcm_ ## name ## _demuxer = {\
764ef400
MM
678 #name,\
679 long_name,\
680 0,\
681 NULL,\
682 raw_read_header,\
683 raw_read_packet,\
684 raw_read_close,\
4986a429 685 pcm_read_seek,\
764ef400
MM
686 .extensions = ext,\
687 .value = codec,\
688};
689
2c8e2014 690#define PCMOUTPUTDEF(name, long_name, ext, codec) \
d2a067d1 691AVOutputFormat pcm_ ## name ## _muxer = {\
c9a65ca8
FB
692 #name,\
693 long_name,\
694 NULL,\
695 ext,\
696 0,\
697 codec,\
698 0,\
699 raw_write_header,\
700 raw_write_packet,\
701 raw_write_trailer,\
494bbf58 702 .flags= AVFMT_NOTIMESTAMPS,\
5ed8fafc 703};
2c8e2014
DB
704
705
706#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
707#define PCMDEF(name, long_name, ext, codec) \
708 PCMINPUTDEF(name, long_name, ext, codec)
709#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
710#define PCMDEF(name, long_name, ext, codec) \
711 PCMOUTPUTDEF(name, long_name, ext, codec)
712#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
713#define PCMDEF(name, long_name, ext, codec) \
714 PCMINPUTDEF(name, long_name, ext, codec)\
715 PCMOUTPUTDEF(name, long_name, ext, codec)
716#else
717#define PCMDEF(name, long_name, ext, codec)
718#endif
5ed8fafc 719
5ed8fafc 720#ifdef WORDS_BIGENDIAN
c9a65ca8
FB
721#define BE_DEF(s) s
722#define LE_DEF(s) NULL
5ed8fafc 723#else
c9a65ca8
FB
724#define BE_DEF(s) NULL
725#define LE_DEF(s) s
5ed8fafc 726#endif
5ed8fafc 727
5ed8fafc 728
115329f1 729PCMDEF(s16le, "pcm signed 16 bit little endian format",
c9a65ca8 730 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
5ed8fafc 731
115329f1 732PCMDEF(s16be, "pcm signed 16 bit big endian format",
c9a65ca8 733 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
5ed8fafc 734
115329f1 735PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
c9a65ca8 736 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
5ed8fafc 737
115329f1 738PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
c9a65ca8 739 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
5ed8fafc 740
115329f1 741PCMDEF(s8, "pcm signed 8 bit format",
c9a65ca8 742 "sb", CODEC_ID_PCM_S8)
5ed8fafc 743
115329f1 744PCMDEF(u8, "pcm unsigned 8 bit format",
c9a65ca8 745 "ub", CODEC_ID_PCM_U8)
5ed8fafc 746
115329f1 747PCMDEF(mulaw, "pcm mu law format",
c9a65ca8 748 "ul", CODEC_ID_PCM_MULAW)
de6d9b64 749
115329f1 750PCMDEF(alaw, "pcm A law format",
c9a65ca8 751 "al", CODEC_ID_PCM_ALAW)
de6d9b64 752
5c91a675 753static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64
FB
754{
755 int packet_size, ret, width, height;
756 AVStream *st = s->streams[0];
757
01f4895c
MN
758 width = st->codec->width;
759 height = st->codec->height;
de6d9b64 760
01f4895c 761 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
63167088 762 if (packet_size < 0)
71c32f19 763 return -1;
de6d9b64 764
2692067a 765 ret= av_get_packet(&s->pb, pkt, packet_size);
de6d9b64
FB
766
767 pkt->stream_index = 0;
2692067a 768 if (ret != packet_size) {
0bd586c5 769 return AVERROR_IO;
de6d9b64
FB
770 } else {
771 return 0;
772 }
773}
774
d2a067d1 775AVInputFormat rawvideo_demuxer = {
c9a65ca8
FB
776 "rawvideo",
777 "raw video format",
778 0,
779 NULL,
780 raw_read_header,
781 rawvideo_read_packet,
782 raw_read_close,
bfc7f165 783 .extensions = "yuv,cif,qcif",
bb76a117 784 .value = CODEC_ID_RAWVIDEO,
c9a65ca8
FB
785};
786
a9e35095 787#ifdef CONFIG_MUXERS
d2a067d1 788AVOutputFormat rawvideo_muxer = {
de6d9b64
FB
789 "rawvideo",
790 "raw video format",
791 NULL,
792 "yuv",
c9a65ca8 793 0,
de6d9b64
FB
794 CODEC_ID_NONE,
795 CODEC_ID_RAWVIDEO,
796 raw_write_header,
797 raw_write_packet,
798 raw_write_trailer,
494bbf58 799 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 800};
a9e35095 801#endif //CONFIG_MUXERS
c9a65ca8 802
a9e35095 803#ifdef CONFIG_MUXERS
e928649b 804static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
87bdd3e5
FB
805{
806 return 0;
807}
808
d2a067d1 809AVOutputFormat null_muxer = {
87bdd3e5
FB
810 "null",
811 "null video format",
812 NULL,
813 NULL,
814 0,
815#ifdef WORDS_BIGENDIAN
816 CODEC_ID_PCM_S16BE,
817#else
818 CODEC_ID_PCM_S16LE,
819#endif
820 CODEC_ID_RAWVIDEO,
821 raw_write_header,
822 null_write_packet,
823 raw_write_trailer,
494bbf58 824 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
87bdd3e5 825};
a9e35095 826#endif //CONFIG_MUXERS