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