oops, revert accidental checkin
[libav.git] / libavformat / raw.c
CommitLineData
115329f1 1/*
7fbde343 2 * RAW muxer and demuxer
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];
708e3e7d
BC
186
187 block_align = st->codec->block_align ? st->codec->block_align :
188 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
189 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
190 block_align * st->codec->sample_rate;
115329f1 191
4986a429
FB
192 if (block_align <= 0 || byte_rate <= 0)
193 return -1;
194
195 /* compute the position by aligning it to block_align */
115329f1
DB
196 pos = av_rescale_rnd(timestamp * byte_rate,
197 st->time_base.num,
7b3c1382
MN
198 st->time_base.den * (int64_t)block_align,
199 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
200 pos *= block_align;
4986a429
FB
201
202 /* recompute exact position */
77405fc8 203 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
4986a429
FB
204 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
205 return 0;
206}
207
cd66005d
FB
208/* ac3 read */
209static int ac3_read_header(AVFormatContext *s,
210 AVFormatParameters *ap)
211{
212 AVStream *st;
213
214 st = av_new_stream(s, 0);
215 if (!st)
216 return AVERROR_NOMEM;
217
01f4895c
MN
218 st->codec->codec_type = CODEC_TYPE_AUDIO;
219 st->codec->codec_id = CODEC_ID_AC3;
4986a429 220 st->need_parsing = 1;
cd66005d
FB
221 /* the parameters will be extracted from the compressed bitstream */
222 return 0;
223}
224
85ad5695
MN
225static int shorten_read_header(AVFormatContext *s,
226 AVFormatParameters *ap)
227{
228 AVStream *st;
229
230 st = av_new_stream(s, 0);
231 if (!st)
232 return AVERROR_NOMEM;
01f4895c
MN
233 st->codec->codec_type = CODEC_TYPE_AUDIO;
234 st->codec->codec_id = CODEC_ID_SHORTEN;
85ad5695
MN
235 st->need_parsing = 1;
236 /* the parameters will be extracted from the compressed bitstream */
237 return 0;
238}
239
89ca8c49
BL
240/* flac read */
241static int flac_read_header(AVFormatContext *s,
242 AVFormatParameters *ap)
243{
244 AVStream *st;
245
246 st = av_new_stream(s, 0);
247 if (!st)
248 return AVERROR_NOMEM;
249 st->codec->codec_type = CODEC_TYPE_AUDIO;
250 st->codec->codec_id = CODEC_ID_FLAC;
251 st->need_parsing = 1;
252 /* the parameters will be extracted from the compressed bitstream */
253 return 0;
254}
255
23c99253
MN
256/* dts read */
257static int dts_read_header(AVFormatContext *s,
258 AVFormatParameters *ap)
259{
260 AVStream *st;
261
262 st = av_new_stream(s, 0);
263 if (!st)
264 return AVERROR_NOMEM;
265
01f4895c
MN
266 st->codec->codec_type = CODEC_TYPE_AUDIO;
267 st->codec->codec_id = CODEC_ID_DTS;
23c99253
MN
268 st->need_parsing = 1;
269 /* the parameters will be extracted from the compressed bitstream */
270 return 0;
271}
272
fda885c7
MR
273/* aac read */
274static int aac_read_header(AVFormatContext *s,
275 AVFormatParameters *ap)
276{
277 AVStream *st;
278
279 st = av_new_stream(s, 0);
280 if (!st)
281 return AVERROR_NOMEM;
282
283 st->codec->codec_type = CODEC_TYPE_AUDIO;
284 st->codec->codec_id = CODEC_ID_AAC;
285 st->need_parsing = 1;
286 /* the parameters will be extracted from the compressed bitstream */
287 return 0;
288}
289
de6d9b64
FB
290/* mpeg1/h263 input */
291static int video_read_header(AVFormatContext *s,
292 AVFormatParameters *ap)
293{
294 AVStream *st;
295
c9a65ca8 296 st = av_new_stream(s, 0);
de6d9b64 297 if (!st)
c9a65ca8 298 return AVERROR_NOMEM;
de6d9b64 299
01f4895c
MN
300 st->codec->codec_type = CODEC_TYPE_VIDEO;
301 st->codec->codec_id = s->iformat->value;
4986a429
FB
302 st->need_parsing = 1;
303
27e084bd 304 /* for mjpeg, specify frame rate */
7866eeff 305 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
c04c3282 306 if (ap->time_base.num) {
80ce3254 307 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
115329f1 308 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
01f4895c
MN
309 st->codec->codec_id == CODEC_ID_MPEG4 ||
310 st->codec->codec_id == CODEC_ID_H264) {
80ce3254 311 av_set_pts_info(st, 64, 1, 25);
27e084bd 312 }
80ce3254 313
de6d9b64
FB
314 return 0;
315}
316
bb270c08
DB
317#define SEQ_START_CODE 0x000001b3
318#define GOP_START_CODE 0x000001b8
319#define PICTURE_START_CODE 0x00000100
93d3e278
MN
320#define SLICE_START_CODE 0x00000101
321#define PACK_START_CODE 0x000001ba
e01dc227
MR
322#define VIDEO_ID 0x000001e0
323#define AUDIO_ID 0x000001c0
c9a65ca8 324
c9a65ca8
FB
325static int mpegvideo_probe(AVProbeData *p)
326{
93d3e278 327 uint32_t code= -1;
e01dc227 328 int pic=0, seq=0, slice=0, pspack=0, pes=0;
93d3e278
MN
329 int i;
330
331 for(i=0; i<p->buf_size; i++){
332 code = (code<<8) + p->buf[i];
333 if ((code & 0xffffff00) == 0x100) {
334 switch(code){
335 case SEQ_START_CODE: seq++; break;
336 case PICTURE_START_CODE: pic++; break;
337 case SLICE_START_CODE: slice++; break;
338 case PACK_START_CODE: pspack++; break;
e01dc227
MR
339 case VIDEO_ID:
340 case AUDIO_ID: pes++; break;
93d3e278
MN
341 }
342 }
c9a65ca8 343 }
e01dc227 344 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
93d3e278 345 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
c9a65ca8
FB
346 return 0;
347}
348
8f57cc5a
TV
349#define VIDEO_OBJECT_START_CODE 0x00000100
350#define VIDEO_OBJECT_LAYER_START_CODE 0x00000120
351#define VISUAL_OBJECT_START_CODE 0x000001b5
352#define VOP_START_CODE 0x000001b6
353
354static int mpeg4video_probe(AVProbeData *probe_packet)
355{
356 uint32_t temp_buffer= -1;
357 int VO=0, VOL=0, VOP = 0, VISO = 0;
358 int i;
359
360 for(i=0; i<probe_packet->buf_size; i++){
361 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
362 if ((temp_buffer & 0xffffff00) == 0x100) {
363 switch(temp_buffer){
364 case VOP_START_CODE: VOP++; break;
365 case VISUAL_OBJECT_START_CODE: VISO++; break;
366 }
367 switch(temp_buffer & 0xfffffff0){
368 case VIDEO_OBJECT_START_CODE: VO++; break;
369 case VIDEO_OBJECT_LAYER_START_CODE: VOL++; break;
370 }
371 }
372 }
373
374 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0)
375 return AVPROBE_SCORE_MAX/2;
376 return 0;
377}
378
d07f9043
MN
379static int h263_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] << 14) | (d[1] << 6) | (d[2] >> 2);
388 if (code == 0x20) {
389 return 50;
390 }
391 return 0;
392}
393
c6148de2
MN
394static int h261_probe(AVProbeData *p)
395{
396 int code;
397 const uint8_t *d;
398
399 if (p->buf_size < 6)
400 return 0;
401 d = p->buf;
402 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
403 if (code == 0x10) {
404 return 50;
405 }
406 return 0;
407}
408
d2a067d1 409AVInputFormat shorten_demuxer = {
85ad5695 410 "shn",
84c63c01 411 "raw shorten",
85ad5695
MN
412 0,
413 NULL,
414 shorten_read_header,
415 raw_read_partial_packet,
416 raw_read_close,
417 .extensions = "shn",
418};
419
d2a067d1 420AVInputFormat flac_demuxer = {
89ca8c49
BL
421 "flac",
422 "raw flac",
423 0,
424 NULL,
425 flac_read_header,
426 raw_read_partial_packet,
427 raw_read_close,
428 .extensions = "flac",
429};
430
ce1d2a95 431#ifdef CONFIG_MUXERS
d2a067d1 432AVOutputFormat flac_muxer = {
ce1d2a95
JR
433 "flac",
434 "raw flac",
435 "audio/x-flac",
436 "flac",
437 0,
438 CODEC_ID_FLAC,
439 0,
440 flac_write_header,
441 raw_write_packet,
442 raw_write_trailer,
494bbf58 443 .flags= AVFMT_NOTIMESTAMPS,
ce1d2a95
JR
444};
445#endif //CONFIG_MUXERS
446
d2a067d1 447AVInputFormat ac3_demuxer = {
c9a65ca8
FB
448 "ac3",
449 "raw ac3",
450 0,
451 NULL,
cd66005d 452 ac3_read_header,
e15dec10 453 raw_read_partial_packet,
de6d9b64 454 raw_read_close,
bb76a117 455 .extensions = "ac3",
de6d9b64
FB
456};
457
a9e35095 458#ifdef CONFIG_MUXERS
d2a067d1 459AVOutputFormat ac3_muxer = {
de6d9b64
FB
460 "ac3",
461 "raw ac3",
115329f1 462 "audio/x-ac3",
de6d9b64 463 "ac3",
c9a65ca8 464 0,
de6d9b64
FB
465 CODEC_ID_AC3,
466 0,
467 raw_write_header,
468 raw_write_packet,
469 raw_write_trailer,
494bbf58 470 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 471};
a9e35095 472#endif //CONFIG_MUXERS
de6d9b64 473
d2a067d1 474AVInputFormat dts_demuxer = {
23c99253
MN
475 "dts",
476 "raw dts",
477 0,
478 NULL,
479 dts_read_header,
480 raw_read_partial_packet,
481 raw_read_close,
482 .extensions = "dts",
483};
484
d2a067d1 485AVInputFormat aac_demuxer = {
fda885c7
MR
486 "aac",
487 "ADTS AAC",
488 0,
489 NULL,
490 aac_read_header,
491 raw_read_partial_packet,
492 raw_read_close,
493 .extensions = "aac",
494};
495
d2a067d1 496AVInputFormat h261_demuxer = {
c6148de2
MN
497 "h261",
498 "raw h261",
499 0,
500 h261_probe,
501 video_read_header,
502 raw_read_partial_packet,
503 raw_read_close,
504 .extensions = "h261",
505 .value = CODEC_ID_H261,
506};
507
a9e35095 508#ifdef CONFIG_MUXERS
d2a067d1 509AVOutputFormat h261_muxer = {
1c3990db
MN
510 "h261",
511 "raw h261",
512 "video/x-h261",
513 "h261",
514 0,
515 0,
516 CODEC_ID_H261,
517 raw_write_header,
518 raw_write_packet,
519 raw_write_trailer,
494bbf58 520 .flags= AVFMT_NOTIMESTAMPS,
1c3990db 521};
a9e35095 522#endif //CONFIG_MUXERS
1c3990db 523
d2a067d1 524AVInputFormat h263_demuxer = {
d07f9043
MN
525 "h263",
526 "raw h263",
527 0,
528 h263_probe,
529 video_read_header,
e15dec10 530 raw_read_partial_packet,
d07f9043
MN
531 raw_read_close,
532// .extensions = "h263", //FIXME remove after writing mpeg4_probe
533 .value = CODEC_ID_H263,
534};
535
a9e35095 536#ifdef CONFIG_MUXERS
d2a067d1 537AVOutputFormat h263_muxer = {
de6d9b64
FB
538 "h263",
539 "raw h263",
540 "video/x-h263",
541 "h263",
542 0,
c9a65ca8 543 0,
de6d9b64
FB
544 CODEC_ID_H263,
545 raw_write_header,
546 raw_write_packet,
547 raw_write_trailer,
494bbf58 548 .flags= AVFMT_NOTIMESTAMPS,
c9a65ca8 549};
a9e35095 550#endif //CONFIG_MUXERS
c9a65ca8 551
d2a067d1 552AVInputFormat m4v_demuxer = {
7866eeff
MN
553 "m4v",
554 "raw MPEG4 video format",
555 0,
8f57cc5a 556 mpeg4video_probe, /** probing for mpeg4 data */
7866eeff 557 video_read_header,
e15dec10 558 raw_read_partial_packet,
7866eeff 559 raw_read_close,
bb76a117
MR
560 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
561 .value = CODEC_ID_MPEG4,
7866eeff
MN
562};
563
a9e35095 564#ifdef CONFIG_MUXERS
d2a067d1 565AVOutputFormat m4v_muxer = {
89b3d7c9
MK
566 "m4v",
567 "raw MPEG4 video format",
568 NULL,
569 "m4v",
570 0,
571 CODEC_ID_NONE,
572 CODEC_ID_MPEG4,
573 raw_write_header,
574 raw_write_packet,
575 raw_write_trailer,
494bbf58 576 .flags= AVFMT_NOTIMESTAMPS,
89b3d7c9 577};
a9e35095 578#endif //CONFIG_MUXERS
89b3d7c9 579
d2a067d1 580AVInputFormat h264_demuxer = {
0da71265
MN
581 "h264",
582 "raw H264 video format",
583 0,
584 NULL /*mpegvideo_probe*/,
585 video_read_header,
e15dec10 586 raw_read_partial_packet,
0da71265 587 raw_read_close,
ba5697d5 588 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
0da71265
MN
589 .value = CODEC_ID_H264,
590};
591
a9e35095 592#ifdef CONFIG_MUXERS
d2a067d1 593AVOutputFormat h264_muxer = {
0da71265
MN
594 "h264",
595 "raw H264 video format",
596 NULL,
597 "h264",
598 0,
599 CODEC_ID_NONE,
600 CODEC_ID_H264,
601 raw_write_header,
602 raw_write_packet,
603 raw_write_trailer,
494bbf58 604 .flags= AVFMT_NOTIMESTAMPS,
0da71265 605};
a9e35095 606#endif //CONFIG_MUXERS
0da71265 607
d2a067d1 608AVInputFormat mpegvideo_demuxer = {
c9a65ca8
FB
609 "mpegvideo",
610 "MPEG video",
611 0,
612 mpegvideo_probe,
de6d9b64 613 video_read_header,
e15dec10 614 raw_read_partial_packet,
de6d9b64 615 raw_read_close,
bb76a117 616 .value = CODEC_ID_MPEG1VIDEO,
de6d9b64
FB
617};
618
a9e35095 619#ifdef CONFIG_MUXERS
d2a067d1 620AVOutputFormat mpeg1video_muxer = {
c9a65ca8 621 "mpeg1video",
de6d9b64
FB
622 "MPEG video",
623 "video/x-mpeg",
e0827ba4 624 "mpg,mpeg,m1v",
de6d9b64 625 0,
c9a65ca8 626 0,
de6d9b64
FB
627 CODEC_ID_MPEG1VIDEO,
628 raw_write_header,
629 raw_write_packet,
630 raw_write_trailer,
494bbf58 631 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 632};
a9e35095 633#endif //CONFIG_MUXERS
de6d9b64 634
a9e35095 635#ifdef CONFIG_MUXERS
d2a067d1 636AVOutputFormat mpeg2video_muxer = {
6ec864da
MN
637 "mpeg2video",
638 "MPEG2 video",
639 NULL,
640 "m2v",
641 0,
642 0,
643 CODEC_ID_MPEG2VIDEO,
644 raw_write_header,
645 raw_write_packet,
646 raw_write_trailer,
494bbf58 647 .flags= AVFMT_NOTIMESTAMPS,
6ec864da 648};
a9e35095 649#endif //CONFIG_MUXERS
6ec864da 650
d2a067d1 651AVInputFormat mjpeg_demuxer = {
27e084bd
FB
652 "mjpeg",
653 "MJPEG video",
27e084bd 654 0,
c9a65ca8 655 NULL,
27e084bd 656 video_read_header,
e15dec10 657 raw_read_partial_packet,
27e084bd 658 raw_read_close,
bb76a117
MR
659 .extensions = "mjpg,mjpeg",
660 .value = CODEC_ID_MJPEG,
27e084bd
FB
661};
662
d2a067d1 663AVInputFormat ingenient_demuxer = {
84c63c01
AB
664 "ingenient",
665 "Ingenient MJPEG",
666 0,
667 NULL,
668 video_read_header,
669 ingenient_read_packet,
670 raw_read_close,
671 .extensions = "cgi", // FIXME
672 .value = CODEC_ID_MJPEG,
673};
674
a9e35095 675#ifdef CONFIG_MUXERS
d2a067d1 676AVOutputFormat mjpeg_muxer = {
c9a65ca8
FB
677 "mjpeg",
678 "MJPEG video",
679 "video/x-mjpeg",
680 "mjpg,mjpeg",
5ed8fafc 681 0,
5ed8fafc 682 0,
c9a65ca8 683 CODEC_ID_MJPEG,
5ed8fafc
FB
684 raw_write_header,
685 raw_write_packet,
686 raw_write_trailer,
494bbf58 687 .flags= AVFMT_NOTIMESTAMPS,
5ed8fafc 688};
a9e35095 689#endif //CONFIG_MUXERS
5ed8fafc 690
c9a65ca8 691/* pcm formats */
764ef400 692
4986a429 693#define PCMINPUTDEF(name, long_name, ext, codec) \
d2a067d1 694AVInputFormat pcm_ ## name ## _demuxer = {\
764ef400
MM
695 #name,\
696 long_name,\
697 0,\
698 NULL,\
699 raw_read_header,\
700 raw_read_packet,\
701 raw_read_close,\
4986a429 702 pcm_read_seek,\
764ef400
MM
703 .extensions = ext,\
704 .value = codec,\
705};
706
2c8e2014 707#define PCMOUTPUTDEF(name, long_name, ext, codec) \
d2a067d1 708AVOutputFormat pcm_ ## name ## _muxer = {\
c9a65ca8
FB
709 #name,\
710 long_name,\
711 NULL,\
712 ext,\
713 0,\
714 codec,\
715 0,\
716 raw_write_header,\
717 raw_write_packet,\
718 raw_write_trailer,\
494bbf58 719 .flags= AVFMT_NOTIMESTAMPS,\
5ed8fafc 720};
2c8e2014
DB
721
722
723#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
724#define PCMDEF(name, long_name, ext, codec) \
725 PCMINPUTDEF(name, long_name, ext, codec)
726#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
727#define PCMDEF(name, long_name, ext, codec) \
728 PCMOUTPUTDEF(name, long_name, ext, codec)
729#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
730#define PCMDEF(name, long_name, ext, codec) \
731 PCMINPUTDEF(name, long_name, ext, codec)\
732 PCMOUTPUTDEF(name, long_name, ext, codec)
733#else
734#define PCMDEF(name, long_name, ext, codec)
735#endif
5ed8fafc 736
5ed8fafc 737#ifdef WORDS_BIGENDIAN
c9a65ca8
FB
738#define BE_DEF(s) s
739#define LE_DEF(s) NULL
5ed8fafc 740#else
c9a65ca8
FB
741#define BE_DEF(s) NULL
742#define LE_DEF(s) s
5ed8fafc 743#endif
5ed8fafc 744
5ed8fafc 745
115329f1 746PCMDEF(s16le, "pcm signed 16 bit little endian format",
c9a65ca8 747 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
5ed8fafc 748
115329f1 749PCMDEF(s16be, "pcm signed 16 bit big endian format",
c9a65ca8 750 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
5ed8fafc 751
115329f1 752PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
c9a65ca8 753 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
5ed8fafc 754
115329f1 755PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
c9a65ca8 756 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
5ed8fafc 757
115329f1 758PCMDEF(s8, "pcm signed 8 bit format",
c9a65ca8 759 "sb", CODEC_ID_PCM_S8)
5ed8fafc 760
115329f1 761PCMDEF(u8, "pcm unsigned 8 bit format",
c9a65ca8 762 "ub", CODEC_ID_PCM_U8)
5ed8fafc 763
115329f1 764PCMDEF(mulaw, "pcm mu law format",
c9a65ca8 765 "ul", CODEC_ID_PCM_MULAW)
de6d9b64 766
115329f1 767PCMDEF(alaw, "pcm A law format",
c9a65ca8 768 "al", CODEC_ID_PCM_ALAW)
de6d9b64 769
5c91a675 770static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64
FB
771{
772 int packet_size, ret, width, height;
773 AVStream *st = s->streams[0];
774
01f4895c
MN
775 width = st->codec->width;
776 height = st->codec->height;
de6d9b64 777
01f4895c 778 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
63167088 779 if (packet_size < 0)
71c32f19 780 return -1;
de6d9b64 781
2692067a 782 ret= av_get_packet(&s->pb, pkt, packet_size);
de6d9b64
FB
783
784 pkt->stream_index = 0;
2692067a 785 if (ret != packet_size) {
0bd586c5 786 return AVERROR_IO;
de6d9b64
FB
787 } else {
788 return 0;
789 }
790}
791
d2a067d1 792AVInputFormat rawvideo_demuxer = {
c9a65ca8
FB
793 "rawvideo",
794 "raw video format",
795 0,
796 NULL,
797 raw_read_header,
798 rawvideo_read_packet,
799 raw_read_close,
bfc7f165 800 .extensions = "yuv,cif,qcif",
bb76a117 801 .value = CODEC_ID_RAWVIDEO,
c9a65ca8
FB
802};
803
a9e35095 804#ifdef CONFIG_MUXERS
d2a067d1 805AVOutputFormat rawvideo_muxer = {
de6d9b64
FB
806 "rawvideo",
807 "raw video format",
808 NULL,
809 "yuv",
c9a65ca8 810 0,
de6d9b64
FB
811 CODEC_ID_NONE,
812 CODEC_ID_RAWVIDEO,
813 raw_write_header,
814 raw_write_packet,
815 raw_write_trailer,
494bbf58 816 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 817};
a9e35095 818#endif //CONFIG_MUXERS
c9a65ca8 819
a9e35095 820#ifdef CONFIG_MUXERS
e928649b 821static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
87bdd3e5
FB
822{
823 return 0;
824}
825
d2a067d1 826AVOutputFormat null_muxer = {
87bdd3e5
FB
827 "null",
828 "null video format",
829 NULL,
830 NULL,
831 0,
832#ifdef WORDS_BIGENDIAN
833 CODEC_ID_PCM_S16BE,
834#else
835 CODEC_ID_PCM_S16LE,
836#endif
837 CODEC_ID_RAWVIDEO,
838 raw_write_header,
839 null_write_packet,
840 raw_write_trailer,
494bbf58 841 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
87bdd3e5 842};
a9e35095 843#endif //CONFIG_MUXERS