Import Dirac demuxer/muxer from SoC branch; written by Marco Gerards,
[libav.git] / libavformat / raw.c
1 /*
2 * RAW muxer and demuxer
3 * Copyright (c) 2001 Fabrice Bellard.
4 * Copyright (c) 2005 Alex Beregszaszi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include "avformat.h"
23 #include "ac3_parser.h"
24 #include "raw.h"
25 #include "crc.h"
26 #include "bitstream.h"
27
28 #ifdef CONFIG_MUXERS
29 /* simple formats */
30 static int flac_write_header(struct AVFormatContext *s)
31 {
32 static const uint8_t header[8] = {
33 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
34 };
35 uint8_t *streaminfo = s->streams[0]->codec->extradata;
36 int len = s->streams[0]->codec->extradata_size;
37 if(streaminfo != NULL && len > 0) {
38 put_buffer(s->pb, header, 8);
39 put_buffer(s->pb, streaminfo, len);
40 }
41 return 0;
42 }
43
44
45 static int roq_write_header(struct AVFormatContext *s)
46 {
47 static const uint8_t header[] = {
48 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
49 };
50
51 put_buffer(s->pb, header, 8);
52 put_flush_packet(s->pb);
53
54 return 0;
55 }
56
57 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
58 {
59 put_buffer(s->pb, pkt->data, pkt->size);
60 put_flush_packet(s->pb);
61 return 0;
62 }
63 #endif //CONFIG_MUXERS
64
65 /* raw input */
66 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
67 {
68 AVStream *st;
69 int id;
70
71 st = av_new_stream(s, 0);
72 if (!st)
73 return AVERROR(ENOMEM);
74
75 id = s->iformat->value;
76 if (id == CODEC_ID_RAWVIDEO) {
77 st->codec->codec_type = CODEC_TYPE_VIDEO;
78 } else {
79 st->codec->codec_type = CODEC_TYPE_AUDIO;
80 }
81 st->codec->codec_id = id;
82
83 switch(st->codec->codec_type) {
84 case CODEC_TYPE_AUDIO:
85 st->codec->sample_rate = ap->sample_rate;
86 st->codec->channels = ap->channels;
87 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
88 break;
89 case CODEC_TYPE_VIDEO:
90 if(ap->time_base.num)
91 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
92 else
93 av_set_pts_info(st, 64, 1, 25);
94 st->codec->width = ap->width;
95 st->codec->height = ap->height;
96 st->codec->pix_fmt = ap->pix_fmt;
97 if(st->codec->pix_fmt == PIX_FMT_NONE)
98 st->codec->pix_fmt= PIX_FMT_YUV420P;
99 break;
100 default:
101 return -1;
102 }
103 return 0;
104 }
105
106 #define RAW_PACKET_SIZE 1024
107
108 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
109 {
110 int ret, size, bps;
111 // AVStream *st = s->streams[0];
112
113 size= RAW_PACKET_SIZE;
114
115 ret= av_get_packet(s->pb, pkt, size);
116
117 pkt->stream_index = 0;
118 if (ret <= 0) {
119 return AVERROR(EIO);
120 }
121 /* note: we need to modify the packet size here to handle the last
122 packet */
123 pkt->size = ret;
124
125 bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
126 assert(bps); // if false there IS a bug elsewhere (NOT in this function)
127 pkt->dts=
128 pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
129
130 return ret;
131 }
132
133 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
134 {
135 int ret, size;
136
137 size = RAW_PACKET_SIZE;
138
139 if (av_new_packet(pkt, size) < 0)
140 return AVERROR(EIO);
141
142 pkt->pos= url_ftell(s->pb);
143 pkt->stream_index = 0;
144 ret = get_partial_buffer(s->pb, pkt->data, size);
145 if (ret <= 0) {
146 av_free_packet(pkt);
147 return AVERROR(EIO);
148 }
149 pkt->size = ret;
150 return ret;
151 }
152
153 // http://www.artificis.hu/files/texts/ingenient.txt
154 static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
155 {
156 int ret, size, w, h, unk1, unk2;
157
158 if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
159 return AVERROR(EIO); // FIXME
160
161 size = get_le32(s->pb);
162
163 w = get_le16(s->pb);
164 h = get_le16(s->pb);
165
166 url_fskip(s->pb, 8); // zero + size (padded?)
167 url_fskip(s->pb, 2);
168 unk1 = get_le16(s->pb);
169 unk2 = get_le16(s->pb);
170 url_fskip(s->pb, 22); // ascii timestamp
171
172 av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
173 size, w, h, unk1, unk2);
174
175 if (av_new_packet(pkt, size) < 0)
176 return AVERROR(EIO);
177
178 pkt->pos = url_ftell(s->pb);
179 pkt->stream_index = 0;
180 ret = get_buffer(s->pb, pkt->data, size);
181 if (ret <= 0) {
182 av_free_packet(pkt);
183 return AVERROR(EIO);
184 }
185 pkt->size = ret;
186 return ret;
187 }
188
189 static int raw_read_close(AVFormatContext *s)
190 {
191 return 0;
192 }
193
194 int pcm_read_seek(AVFormatContext *s,
195 int stream_index, int64_t timestamp, int flags)
196 {
197 AVStream *st;
198 int block_align, byte_rate;
199 int64_t pos;
200
201 st = s->streams[0];
202
203 block_align = st->codec->block_align ? st->codec->block_align :
204 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
205 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
206 block_align * st->codec->sample_rate;
207
208 if (block_align <= 0 || byte_rate <= 0)
209 return -1;
210
211 /* compute the position by aligning it to block_align */
212 pos = av_rescale_rnd(timestamp * byte_rate,
213 st->time_base.num,
214 st->time_base.den * (int64_t)block_align,
215 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
216 pos *= block_align;
217
218 /* recompute exact position */
219 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
220 url_fseek(s->pb, pos + s->data_offset, SEEK_SET);
221 return 0;
222 }
223
224 static int audio_read_header(AVFormatContext *s,
225 AVFormatParameters *ap)
226 {
227 AVStream *st = av_new_stream(s, 0);
228 if (!st)
229 return AVERROR(ENOMEM);
230 st->codec->codec_type = CODEC_TYPE_AUDIO;
231 st->codec->codec_id = s->iformat->value;
232 st->need_parsing = AVSTREAM_PARSE_FULL;
233 /* the parameters will be extracted from the compressed bitstream */
234 return 0;
235 }
236
237 /* mpeg1/h263 input */
238 static int video_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(ENOMEM);
246
247 st->codec->codec_type = CODEC_TYPE_VIDEO;
248 st->codec->codec_id = s->iformat->value;
249 st->need_parsing = AVSTREAM_PARSE_FULL;
250
251 /* for mjpeg, specify frame rate */
252 /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
253 if (ap->time_base.num) {
254 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
255 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
256 st->codec->codec_id == CODEC_ID_MPEG4 ||
257 st->codec->codec_id == CODEC_ID_DIRAC ||
258 st->codec->codec_id == CODEC_ID_H264) {
259 av_set_pts_info(st, 64, 1, 25);
260 }
261
262 return 0;
263 }
264
265 #define SEQ_START_CODE 0x000001b3
266 #define GOP_START_CODE 0x000001b8
267 #define PICTURE_START_CODE 0x00000100
268 #define SLICE_START_CODE 0x00000101
269 #define PACK_START_CODE 0x000001ba
270 #define VIDEO_ID 0x000001e0
271 #define AUDIO_ID 0x000001c0
272
273 static int mpegvideo_probe(AVProbeData *p)
274 {
275 uint32_t code= -1;
276 int pic=0, seq=0, slice=0, pspack=0, pes=0;
277 int i;
278
279 for(i=0; i<p->buf_size; i++){
280 code = (code<<8) + p->buf[i];
281 if ((code & 0xffffff00) == 0x100) {
282 switch(code){
283 case SEQ_START_CODE: seq++; break;
284 case PICTURE_START_CODE: pic++; break;
285 case SLICE_START_CODE: slice++; break;
286 case PACK_START_CODE: pspack++; break;
287 }
288 if ((code & 0x1f0) == VIDEO_ID) pes++;
289 else if((code & 0x1e0) == AUDIO_ID) pes++;
290 }
291 }
292 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
293 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
294 return 0;
295 }
296
297 #define VISUAL_OBJECT_START_CODE 0x000001b5
298 #define VOP_START_CODE 0x000001b6
299
300 static int mpeg4video_probe(AVProbeData *probe_packet)
301 {
302 uint32_t temp_buffer= -1;
303 int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
304 int i;
305
306 for(i=0; i<probe_packet->buf_size; i++){
307 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
308 if ((temp_buffer & 0xffffff00) != 0x100)
309 continue;
310
311 if (temp_buffer == VOP_START_CODE) VOP++;
312 else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++;
313 else if (temp_buffer < 0x120) VO++;
314 else if (temp_buffer < 0x130) VOL++;
315 else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
316 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
317 }
318
319 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
320 return AVPROBE_SCORE_MAX/2;
321 return 0;
322 }
323
324 static int h263_probe(AVProbeData *p)
325 {
326 int code;
327 const uint8_t *d;
328
329 d = p->buf;
330 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
331 if (code == 0x20) {
332 return 50;
333 }
334 return 0;
335 }
336
337 static int h261_probe(AVProbeData *p)
338 {
339 int code;
340 const uint8_t *d;
341
342 d = p->buf;
343 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
344 if (code == 0x10) {
345 return 50;
346 }
347 return 0;
348 }
349
350 static int dirac_probe(AVProbeData *p)
351 {
352 if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
353 return AVPROBE_SCORE_MAX;
354 else
355 return 0;
356 }
357
358 static int ac3_probe(AVProbeData *p)
359 {
360 int max_frames, first_frames = 0, frames;
361 uint8_t *buf, *buf2, *end;
362 AC3HeaderInfo hdr;
363 GetBitContext gbc;
364
365 max_frames = 0;
366 buf = p->buf;
367 end = buf + p->buf_size;
368
369 for(; buf < end; buf++) {
370 buf2 = buf;
371
372 for(frames = 0; buf2 < end; frames++) {
373 init_get_bits(&gbc, buf2, 54);
374 if(ff_ac3_parse_header(&gbc, &hdr) < 0)
375 break;
376 if(buf2 + hdr.frame_size > end ||
377 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
378 break;
379 buf2 += hdr.frame_size;
380 }
381 max_frames = FFMAX(max_frames, frames);
382 if(buf == p->buf)
383 first_frames = frames;
384 }
385 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
386 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
387 else if(max_frames>=1) return 1;
388 else return 0;
389 }
390
391 static int flac_probe(AVProbeData *p)
392 {
393 if(memcmp(p->buf, "fLaC", 4)) return 0;
394 else return AVPROBE_SCORE_MAX / 2;
395 }
396
397 AVInputFormat shorten_demuxer = {
398 "shn",
399 "raw shorten",
400 0,
401 NULL,
402 audio_read_header,
403 raw_read_partial_packet,
404 raw_read_close,
405 .flags= AVFMT_GENERIC_INDEX,
406 .extensions = "shn",
407 .value = CODEC_ID_SHORTEN,
408 };
409
410 AVInputFormat flac_demuxer = {
411 "flac",
412 "raw flac",
413 0,
414 flac_probe,
415 audio_read_header,
416 raw_read_partial_packet,
417 raw_read_close,
418 .flags= AVFMT_GENERIC_INDEX,
419 .extensions = "flac",
420 .value = CODEC_ID_FLAC,
421 };
422
423 #ifdef CONFIG_MUXERS
424 AVOutputFormat flac_muxer = {
425 "flac",
426 "raw flac",
427 "audio/x-flac",
428 "flac",
429 0,
430 CODEC_ID_FLAC,
431 0,
432 flac_write_header,
433 raw_write_packet,
434 .flags= AVFMT_NOTIMESTAMPS,
435 };
436 #endif //CONFIG_MUXERS
437
438 #ifdef CONFIG_AC3_DEMUXER
439 AVInputFormat ac3_demuxer = {
440 "ac3",
441 "raw ac3",
442 0,
443 ac3_probe,
444 audio_read_header,
445 raw_read_partial_packet,
446 raw_read_close,
447 .flags= AVFMT_GENERIC_INDEX,
448 .extensions = "ac3",
449 .value = CODEC_ID_AC3,
450 };
451 #endif
452
453 #ifdef CONFIG_MUXERS
454 AVOutputFormat ac3_muxer = {
455 "ac3",
456 "raw ac3",
457 "audio/x-ac3",
458 "ac3",
459 0,
460 CODEC_ID_AC3,
461 0,
462 NULL,
463 raw_write_packet,
464 .flags= AVFMT_NOTIMESTAMPS,
465 };
466
467 AVOutputFormat dts_muxer = {
468 "dts",
469 "raw dts",
470 "audio/x-dca",
471 "dts",
472 0,
473 CODEC_ID_DTS,
474 0,
475 NULL,
476 raw_write_packet,
477 .flags= AVFMT_NOTIMESTAMPS,
478 };
479
480 #endif //CONFIG_MUXERS
481
482 AVInputFormat dirac_demuxer = {
483 "dirac",
484 "raw dirac",
485 0,
486 dirac_probe,
487 video_read_header,
488 raw_read_partial_packet,
489 raw_read_close,
490 .flags= AVFMT_GENERIC_INDEX,
491 .value = CODEC_ID_DIRAC,
492 };
493
494 #ifdef CONFIG_MUXERS
495 AVOutputFormat dirac_muxer = {
496 "dirac",
497 "raw dirac",
498 NULL,
499 "drc",
500 0,
501 0,
502 CODEC_ID_DIRAC,
503 NULL,
504 raw_write_packet,
505 .flags= AVFMT_NOTIMESTAMPS,
506 };
507 #endif
508
509 AVInputFormat dts_demuxer = {
510 "dts",
511 "raw dts",
512 0,
513 NULL,
514 audio_read_header,
515 raw_read_partial_packet,
516 raw_read_close,
517 .flags= AVFMT_GENERIC_INDEX,
518 .extensions = "dts",
519 .value = CODEC_ID_DTS,
520 };
521
522 AVInputFormat aac_demuxer = {
523 "aac",
524 "ADTS AAC",
525 0,
526 NULL,
527 audio_read_header,
528 raw_read_partial_packet,
529 raw_read_close,
530 .flags= AVFMT_GENERIC_INDEX,
531 .extensions = "aac",
532 .value = CODEC_ID_AAC,
533 };
534
535 AVInputFormat gsm_demuxer = {
536 "gsm",
537 "GSM",
538 0,
539 NULL,
540 audio_read_header,
541 raw_read_partial_packet,
542 raw_read_close,
543 .flags= AVFMT_GENERIC_INDEX,
544 .extensions = "gsm",
545 .value = CODEC_ID_GSM,
546 };
547
548 #ifdef CONFIG_ROQ_MUXER
549 AVOutputFormat roq_muxer =
550 {
551 "RoQ",
552 "Id RoQ format",
553 NULL,
554 "roq",
555 0,
556 CODEC_ID_ROQ_DPCM,
557 CODEC_ID_ROQ,
558 roq_write_header,
559 raw_write_packet,
560 };
561 #endif //CONFIG_ROQ_MUXER
562
563 AVInputFormat h261_demuxer = {
564 "h261",
565 "raw h261",
566 0,
567 h261_probe,
568 video_read_header,
569 raw_read_partial_packet,
570 raw_read_close,
571 .flags= AVFMT_GENERIC_INDEX,
572 .extensions = "h261",
573 .value = CODEC_ID_H261,
574 };
575
576 #ifdef CONFIG_MUXERS
577 AVOutputFormat h261_muxer = {
578 "h261",
579 "raw h261",
580 "video/x-h261",
581 "h261",
582 0,
583 0,
584 CODEC_ID_H261,
585 NULL,
586 raw_write_packet,
587 .flags= AVFMT_NOTIMESTAMPS,
588 };
589 #endif //CONFIG_MUXERS
590
591 AVInputFormat h263_demuxer = {
592 "h263",
593 "raw h263",
594 0,
595 h263_probe,
596 video_read_header,
597 raw_read_partial_packet,
598 raw_read_close,
599 .flags= AVFMT_GENERIC_INDEX,
600 // .extensions = "h263", //FIXME remove after writing mpeg4_probe
601 .value = CODEC_ID_H263,
602 };
603
604 #ifdef CONFIG_MUXERS
605 AVOutputFormat h263_muxer = {
606 "h263",
607 "raw h263",
608 "video/x-h263",
609 "h263",
610 0,
611 0,
612 CODEC_ID_H263,
613 NULL,
614 raw_write_packet,
615 .flags= AVFMT_NOTIMESTAMPS,
616 };
617 #endif //CONFIG_MUXERS
618
619 AVInputFormat m4v_demuxer = {
620 "m4v",
621 "raw MPEG4 video format",
622 0,
623 mpeg4video_probe, /** probing for mpeg4 data */
624 video_read_header,
625 raw_read_partial_packet,
626 raw_read_close,
627 .flags= AVFMT_GENERIC_INDEX,
628 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
629 .value = CODEC_ID_MPEG4,
630 };
631
632 #ifdef CONFIG_MUXERS
633 AVOutputFormat m4v_muxer = {
634 "m4v",
635 "raw MPEG4 video format",
636 NULL,
637 "m4v",
638 0,
639 CODEC_ID_NONE,
640 CODEC_ID_MPEG4,
641 NULL,
642 raw_write_packet,
643 .flags= AVFMT_NOTIMESTAMPS,
644 };
645 #endif //CONFIG_MUXERS
646
647 AVInputFormat h264_demuxer = {
648 "h264",
649 "raw H264 video format",
650 0,
651 NULL /*mpegvideo_probe*/,
652 video_read_header,
653 raw_read_partial_packet,
654 raw_read_close,
655 .flags= AVFMT_GENERIC_INDEX,
656 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
657 .value = CODEC_ID_H264,
658 };
659
660 #ifdef CONFIG_MUXERS
661 AVOutputFormat h264_muxer = {
662 "h264",
663 "raw H264 video format",
664 NULL,
665 "h264",
666 0,
667 CODEC_ID_NONE,
668 CODEC_ID_H264,
669 NULL,
670 raw_write_packet,
671 .flags= AVFMT_NOTIMESTAMPS,
672 };
673 #endif //CONFIG_MUXERS
674
675 AVInputFormat mpegvideo_demuxer = {
676 "mpegvideo",
677 "MPEG video",
678 0,
679 mpegvideo_probe,
680 video_read_header,
681 raw_read_partial_packet,
682 raw_read_close,
683 .flags= AVFMT_GENERIC_INDEX,
684 .value = CODEC_ID_MPEG1VIDEO,
685 };
686
687 #ifdef CONFIG_MUXERS
688 AVOutputFormat mpeg1video_muxer = {
689 "mpeg1video",
690 "MPEG video",
691 "video/x-mpeg",
692 "mpg,mpeg,m1v",
693 0,
694 0,
695 CODEC_ID_MPEG1VIDEO,
696 NULL,
697 raw_write_packet,
698 .flags= AVFMT_NOTIMESTAMPS,
699 };
700 #endif //CONFIG_MUXERS
701
702 #ifdef CONFIG_MUXERS
703 AVOutputFormat mpeg2video_muxer = {
704 "mpeg2video",
705 "MPEG2 video",
706 NULL,
707 "m2v",
708 0,
709 0,
710 CODEC_ID_MPEG2VIDEO,
711 NULL,
712 raw_write_packet,
713 .flags= AVFMT_NOTIMESTAMPS,
714 };
715 #endif //CONFIG_MUXERS
716
717 AVInputFormat mjpeg_demuxer = {
718 "mjpeg",
719 "MJPEG video",
720 0,
721 NULL,
722 video_read_header,
723 raw_read_partial_packet,
724 raw_read_close,
725 .flags= AVFMT_GENERIC_INDEX,
726 .extensions = "mjpg,mjpeg",
727 .value = CODEC_ID_MJPEG,
728 };
729
730 AVInputFormat ingenient_demuxer = {
731 "ingenient",
732 "Ingenient MJPEG",
733 0,
734 NULL,
735 video_read_header,
736 ingenient_read_packet,
737 raw_read_close,
738 .flags= AVFMT_GENERIC_INDEX,
739 .extensions = "cgi", // FIXME
740 .value = CODEC_ID_MJPEG,
741 };
742
743 #ifdef CONFIG_MUXERS
744 AVOutputFormat mjpeg_muxer = {
745 "mjpeg",
746 "MJPEG video",
747 "video/x-mjpeg",
748 "mjpg,mjpeg",
749 0,
750 0,
751 CODEC_ID_MJPEG,
752 NULL,
753 raw_write_packet,
754 .flags= AVFMT_NOTIMESTAMPS,
755 };
756 #endif //CONFIG_MUXERS
757
758 AVInputFormat vc1_demuxer = {
759 "vc1",
760 "raw vc1",
761 0,
762 NULL /* vc1_probe */,
763 video_read_header,
764 raw_read_partial_packet,
765 raw_read_close,
766 .extensions = "vc1",
767 .value = CODEC_ID_VC1,
768 };
769
770 /* pcm formats */
771
772 #define PCMINPUTDEF(name, long_name, ext, codec) \
773 AVInputFormat pcm_ ## name ## _demuxer = {\
774 #name,\
775 long_name,\
776 0,\
777 NULL,\
778 raw_read_header,\
779 raw_read_packet,\
780 raw_read_close,\
781 pcm_read_seek,\
782 .flags= AVFMT_GENERIC_INDEX,\
783 .extensions = ext,\
784 .value = codec,\
785 };
786
787 #define PCMOUTPUTDEF(name, long_name, ext, codec) \
788 AVOutputFormat pcm_ ## name ## _muxer = {\
789 #name,\
790 long_name,\
791 NULL,\
792 ext,\
793 0,\
794 codec,\
795 0,\
796 NULL,\
797 raw_write_packet,\
798 .flags= AVFMT_NOTIMESTAMPS,\
799 };
800
801
802 #if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
803 #define PCMDEF(name, long_name, ext, codec) \
804 PCMINPUTDEF(name, long_name, ext, codec)
805 #elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
806 #define PCMDEF(name, long_name, ext, codec) \
807 PCMOUTPUTDEF(name, long_name, ext, codec)
808 #elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
809 #define PCMDEF(name, long_name, ext, codec) \
810 PCMINPUTDEF(name, long_name, ext, codec)\
811 PCMOUTPUTDEF(name, long_name, ext, codec)
812 #else
813 #define PCMDEF(name, long_name, ext, codec)
814 #endif
815
816 #ifdef WORDS_BIGENDIAN
817 #define BE_DEF(s) s
818 #define LE_DEF(s) NULL
819 #else
820 #define BE_DEF(s) NULL
821 #define LE_DEF(s) s
822 #endif
823
824
825 PCMDEF(s16le, "pcm signed 16 bit little endian format",
826 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
827
828 PCMDEF(s16be, "pcm signed 16 bit big endian format",
829 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
830
831 PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
832 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
833
834 PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
835 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
836
837 PCMDEF(s8, "pcm signed 8 bit format",
838 "sb", CODEC_ID_PCM_S8)
839
840 PCMDEF(u8, "pcm unsigned 8 bit format",
841 "ub", CODEC_ID_PCM_U8)
842
843 PCMDEF(mulaw, "pcm mu law format",
844 "ul", CODEC_ID_PCM_MULAW)
845
846 PCMDEF(alaw, "pcm A law format",
847 "al", CODEC_ID_PCM_ALAW)
848
849 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
850 {
851 int packet_size, ret, width, height;
852 AVStream *st = s->streams[0];
853
854 width = st->codec->width;
855 height = st->codec->height;
856
857 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
858 if (packet_size < 0)
859 return -1;
860
861 ret= av_get_packet(s->pb, pkt, packet_size);
862 pkt->pts=
863 pkt->dts= pkt->pos / packet_size;
864
865 pkt->stream_index = 0;
866 if (ret != packet_size) {
867 return AVERROR(EIO);
868 } else {
869 return 0;
870 }
871 }
872
873 AVInputFormat rawvideo_demuxer = {
874 "rawvideo",
875 "raw video format",
876 0,
877 NULL,
878 raw_read_header,
879 rawvideo_read_packet,
880 raw_read_close,
881 .flags= AVFMT_GENERIC_INDEX,
882 .extensions = "yuv,cif,qcif,rgb",
883 .value = CODEC_ID_RAWVIDEO,
884 };
885
886 #ifdef CONFIG_MUXERS
887 AVOutputFormat rawvideo_muxer = {
888 "rawvideo",
889 "raw video format",
890 NULL,
891 "yuv,rgb",
892 0,
893 CODEC_ID_NONE,
894 CODEC_ID_RAWVIDEO,
895 NULL,
896 raw_write_packet,
897 .flags= AVFMT_NOTIMESTAMPS,
898 };
899 #endif //CONFIG_MUXERS
900
901 #ifdef CONFIG_MUXERS
902 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
903 {
904 return 0;
905 }
906
907 AVOutputFormat null_muxer = {
908 "null",
909 "null video format",
910 NULL,
911 NULL,
912 0,
913 #ifdef WORDS_BIGENDIAN
914 CODEC_ID_PCM_S16BE,
915 #else
916 CODEC_ID_PCM_S16LE,
917 #endif
918 CODEC_ID_RAWVIDEO,
919 NULL,
920 null_write_packet,
921 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
922 };
923 #endif //CONFIG_MUXERS