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