Raw dts muxer
[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
26 #ifdef CONFIG_MUXERS
27 /* simple formats */
28 static int flac_write_header(struct AVFormatContext *s)
29 {
30 static const uint8_t header[8] = {
31 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
32 };
33 uint8_t *streaminfo = s->streams[0]->codec->extradata;
34 int len = s->streams[0]->codec->extradata_size;
35 if(streaminfo != NULL && len > 0) {
36 put_buffer(s->pb, header, 8);
37 put_buffer(s->pb, streaminfo, len);
38 }
39 return 0;
40 }
41
42
43 static int roq_write_header(struct AVFormatContext *s)
44 {
45 static const uint8_t header[] = {
46 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
47 };
48
49 put_buffer(s->pb, header, 8);
50 put_flush_packet(s->pb);
51
52 return 0;
53 }
54
55 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
56 {
57 put_buffer(s->pb, pkt->data, pkt->size);
58 put_flush_packet(s->pb);
59 return 0;
60 }
61 #endif //CONFIG_MUXERS
62
63 /* raw input */
64 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
65 {
66 AVStream *st;
67 int id;
68
69 st = av_new_stream(s, 0);
70 if (!st)
71 return AVERROR(ENOMEM);
72
73 id = s->iformat->value;
74 if (id == CODEC_ID_RAWVIDEO) {
75 st->codec->codec_type = CODEC_TYPE_VIDEO;
76 } else {
77 st->codec->codec_type = CODEC_TYPE_AUDIO;
78 }
79 st->codec->codec_id = id;
80
81 switch(st->codec->codec_type) {
82 case CODEC_TYPE_AUDIO:
83 st->codec->sample_rate = ap->sample_rate;
84 st->codec->channels = ap->channels;
85 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
86 break;
87 case CODEC_TYPE_VIDEO:
88 if(ap->time_base.num)
89 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
90 else
91 av_set_pts_info(st, 64, 1, 25);
92 st->codec->width = ap->width;
93 st->codec->height = ap->height;
94 st->codec->pix_fmt = ap->pix_fmt;
95 if(st->codec->pix_fmt == PIX_FMT_NONE)
96 st->codec->pix_fmt= PIX_FMT_YUV420P;
97 break;
98 default:
99 return -1;
100 }
101 return 0;
102 }
103
104 #define RAW_PACKET_SIZE 1024
105
106 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
107 {
108 int ret, size, bps;
109 // AVStream *st = s->streams[0];
110
111 size= RAW_PACKET_SIZE;
112
113 ret= av_get_packet(s->pb, pkt, size);
114
115 pkt->stream_index = 0;
116 if (ret <= 0) {
117 return AVERROR(EIO);
118 }
119 /* note: we need to modify the packet size here to handle the last
120 packet */
121 pkt->size = ret;
122
123 bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
124 assert(bps); // if false there IS a bug elsewhere (NOT in this function)
125 pkt->dts=
126 pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
127
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(EIO);
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(EIO);
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(EIO); // 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(EIO);
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(EIO);
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(ENOMEM);
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(ENOMEM);
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(ENOMEM);
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(ENOMEM);
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(ENOMEM);
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(ENOMEM);
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 do not 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 continue;
376
377 if (temp_buffer == VOP_START_CODE) VOP++;
378 else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++;
379 else if (temp_buffer < 0x120) VO++;
380 else if (temp_buffer < 0x130) VOL++;
381 else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
382 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
383 }
384
385 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
386 return AVPROBE_SCORE_MAX/2;
387 return 0;
388 }
389
390 static int h263_probe(AVProbeData *p)
391 {
392 int code;
393 const uint8_t *d;
394
395 d = p->buf;
396 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
397 if (code == 0x20) {
398 return 50;
399 }
400 return 0;
401 }
402
403 static int h261_probe(AVProbeData *p)
404 {
405 int code;
406 const uint8_t *d;
407
408 d = p->buf;
409 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
410 if (code == 0x10) {
411 return 50;
412 }
413 return 0;
414 }
415
416 static int ac3_probe(AVProbeData *p)
417 {
418 int max_frames, first_frames = 0, frames;
419 uint8_t *buf, *buf2, *end;
420 AC3HeaderInfo hdr;
421
422 max_frames = 0;
423 buf = p->buf;
424 end = buf + p->buf_size;
425
426 for(; buf < end; buf++) {
427 buf2 = buf;
428
429 for(frames = 0; buf2 < end; frames++) {
430 if(ff_ac3_parse_header(buf2, &hdr) < 0)
431 break;
432 buf2 += hdr.frame_size;
433 }
434 max_frames = FFMAX(max_frames, frames);
435 if(buf == p->buf)
436 first_frames = frames;
437 }
438 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
439 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
440 else if(max_frames>=1) return 1;
441 else return 0;
442 }
443
444 static int flac_probe(AVProbeData *p)
445 {
446 if(memcmp(p->buf, "fLaC", 4)) return 0;
447 else return AVPROBE_SCORE_MAX / 2;
448 }
449
450 AVInputFormat shorten_demuxer = {
451 "shn",
452 "raw shorten",
453 0,
454 NULL,
455 shorten_read_header,
456 raw_read_partial_packet,
457 raw_read_close,
458 .flags= AVFMT_GENERIC_INDEX,
459 .extensions = "shn",
460 };
461
462 AVInputFormat flac_demuxer = {
463 "flac",
464 "raw flac",
465 0,
466 flac_probe,
467 flac_read_header,
468 raw_read_partial_packet,
469 raw_read_close,
470 .flags= AVFMT_GENERIC_INDEX,
471 .extensions = "flac",
472 };
473
474 #ifdef CONFIG_MUXERS
475 AVOutputFormat flac_muxer = {
476 "flac",
477 "raw flac",
478 "audio/x-flac",
479 "flac",
480 0,
481 CODEC_ID_FLAC,
482 0,
483 flac_write_header,
484 raw_write_packet,
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 NULL,
513 raw_write_packet,
514 .flags= AVFMT_NOTIMESTAMPS,
515 };
516
517 AVOutputFormat dts_muxer = {
518 "dts",
519 "raw dts",
520 "audio/x-dca",
521 "dts",
522 0,
523 CODEC_ID_DTS,
524 0,
525 NULL,
526 raw_write_packet,
527 .flags= AVFMT_NOTIMESTAMPS,
528 };
529
530 #endif //CONFIG_MUXERS
531
532 AVInputFormat dts_demuxer = {
533 "dts",
534 "raw dts",
535 0,
536 NULL,
537 dts_read_header,
538 raw_read_partial_packet,
539 raw_read_close,
540 .flags= AVFMT_GENERIC_INDEX,
541 .extensions = "dts",
542 };
543
544 AVInputFormat aac_demuxer = {
545 "aac",
546 "ADTS AAC",
547 0,
548 NULL,
549 aac_read_header,
550 raw_read_partial_packet,
551 raw_read_close,
552 .flags= AVFMT_GENERIC_INDEX,
553 .extensions = "aac",
554 };
555
556 #ifdef CONFIG_ROQ_MUXER
557 AVOutputFormat roq_muxer =
558 {
559 "RoQ",
560 "Id RoQ format",
561 NULL,
562 "roq",
563 0,
564 CODEC_ID_ROQ_DPCM,
565 CODEC_ID_ROQ,
566 roq_write_header,
567 raw_write_packet,
568 };
569 #endif //CONFIG_ROQ_MUXER
570
571 AVInputFormat h261_demuxer = {
572 "h261",
573 "raw h261",
574 0,
575 h261_probe,
576 video_read_header,
577 raw_read_partial_packet,
578 raw_read_close,
579 .flags= AVFMT_GENERIC_INDEX,
580 .extensions = "h261",
581 .value = CODEC_ID_H261,
582 };
583
584 #ifdef CONFIG_MUXERS
585 AVOutputFormat h261_muxer = {
586 "h261",
587 "raw h261",
588 "video/x-h261",
589 "h261",
590 0,
591 0,
592 CODEC_ID_H261,
593 NULL,
594 raw_write_packet,
595 .flags= AVFMT_NOTIMESTAMPS,
596 };
597 #endif //CONFIG_MUXERS
598
599 AVInputFormat h263_demuxer = {
600 "h263",
601 "raw h263",
602 0,
603 h263_probe,
604 video_read_header,
605 raw_read_partial_packet,
606 raw_read_close,
607 .flags= AVFMT_GENERIC_INDEX,
608 // .extensions = "h263", //FIXME remove after writing mpeg4_probe
609 .value = CODEC_ID_H263,
610 };
611
612 #ifdef CONFIG_MUXERS
613 AVOutputFormat h263_muxer = {
614 "h263",
615 "raw h263",
616 "video/x-h263",
617 "h263",
618 0,
619 0,
620 CODEC_ID_H263,
621 NULL,
622 raw_write_packet,
623 .flags= AVFMT_NOTIMESTAMPS,
624 };
625 #endif //CONFIG_MUXERS
626
627 AVInputFormat m4v_demuxer = {
628 "m4v",
629 "raw MPEG4 video format",
630 0,
631 mpeg4video_probe, /** probing for mpeg4 data */
632 video_read_header,
633 raw_read_partial_packet,
634 raw_read_close,
635 .flags= AVFMT_GENERIC_INDEX,
636 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
637 .value = CODEC_ID_MPEG4,
638 };
639
640 #ifdef CONFIG_MUXERS
641 AVOutputFormat m4v_muxer = {
642 "m4v",
643 "raw MPEG4 video format",
644 NULL,
645 "m4v",
646 0,
647 CODEC_ID_NONE,
648 CODEC_ID_MPEG4,
649 NULL,
650 raw_write_packet,
651 .flags= AVFMT_NOTIMESTAMPS,
652 };
653 #endif //CONFIG_MUXERS
654
655 AVInputFormat h264_demuxer = {
656 "h264",
657 "raw H264 video format",
658 0,
659 NULL /*mpegvideo_probe*/,
660 video_read_header,
661 raw_read_partial_packet,
662 raw_read_close,
663 .flags= AVFMT_GENERIC_INDEX,
664 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
665 .value = CODEC_ID_H264,
666 };
667
668 #ifdef CONFIG_MUXERS
669 AVOutputFormat h264_muxer = {
670 "h264",
671 "raw H264 video format",
672 NULL,
673 "h264",
674 0,
675 CODEC_ID_NONE,
676 CODEC_ID_H264,
677 NULL,
678 raw_write_packet,
679 .flags= AVFMT_NOTIMESTAMPS,
680 };
681 #endif //CONFIG_MUXERS
682
683 AVInputFormat mpegvideo_demuxer = {
684 "mpegvideo",
685 "MPEG video",
686 0,
687 mpegvideo_probe,
688 video_read_header,
689 raw_read_partial_packet,
690 raw_read_close,
691 .flags= AVFMT_GENERIC_INDEX,
692 .value = CODEC_ID_MPEG1VIDEO,
693 };
694
695 #ifdef CONFIG_MUXERS
696 AVOutputFormat mpeg1video_muxer = {
697 "mpeg1video",
698 "MPEG video",
699 "video/x-mpeg",
700 "mpg,mpeg,m1v",
701 0,
702 0,
703 CODEC_ID_MPEG1VIDEO,
704 NULL,
705 raw_write_packet,
706 .flags= AVFMT_NOTIMESTAMPS,
707 };
708 #endif //CONFIG_MUXERS
709
710 #ifdef CONFIG_MUXERS
711 AVOutputFormat mpeg2video_muxer = {
712 "mpeg2video",
713 "MPEG2 video",
714 NULL,
715 "m2v",
716 0,
717 0,
718 CODEC_ID_MPEG2VIDEO,
719 NULL,
720 raw_write_packet,
721 .flags= AVFMT_NOTIMESTAMPS,
722 };
723 #endif //CONFIG_MUXERS
724
725 AVInputFormat mjpeg_demuxer = {
726 "mjpeg",
727 "MJPEG video",
728 0,
729 NULL,
730 video_read_header,
731 raw_read_partial_packet,
732 raw_read_close,
733 .flags= AVFMT_GENERIC_INDEX,
734 .extensions = "mjpg,mjpeg",
735 .value = CODEC_ID_MJPEG,
736 };
737
738 AVInputFormat ingenient_demuxer = {
739 "ingenient",
740 "Ingenient MJPEG",
741 0,
742 NULL,
743 video_read_header,
744 ingenient_read_packet,
745 raw_read_close,
746 .flags= AVFMT_GENERIC_INDEX,
747 .extensions = "cgi", // FIXME
748 .value = CODEC_ID_MJPEG,
749 };
750
751 #ifdef CONFIG_MUXERS
752 AVOutputFormat mjpeg_muxer = {
753 "mjpeg",
754 "MJPEG video",
755 "video/x-mjpeg",
756 "mjpg,mjpeg",
757 0,
758 0,
759 CODEC_ID_MJPEG,
760 NULL,
761 raw_write_packet,
762 .flags= AVFMT_NOTIMESTAMPS,
763 };
764 #endif //CONFIG_MUXERS
765
766 AVInputFormat vc1_demuxer = {
767 "vc1",
768 "raw vc1",
769 0,
770 NULL /* vc1_probe */,
771 video_read_header,
772 raw_read_partial_packet,
773 raw_read_close,
774 .extensions = "vc1",
775 .value = CODEC_ID_VC1,
776 };
777
778 /* pcm formats */
779
780 #define PCMINPUTDEF(name, long_name, ext, codec) \
781 AVInputFormat pcm_ ## name ## _demuxer = {\
782 #name,\
783 long_name,\
784 0,\
785 NULL,\
786 raw_read_header,\
787 raw_read_packet,\
788 raw_read_close,\
789 pcm_read_seek,\
790 .flags= AVFMT_GENERIC_INDEX,\
791 .extensions = ext,\
792 .value = codec,\
793 };
794
795 #define PCMOUTPUTDEF(name, long_name, ext, codec) \
796 AVOutputFormat pcm_ ## name ## _muxer = {\
797 #name,\
798 long_name,\
799 NULL,\
800 ext,\
801 0,\
802 codec,\
803 0,\
804 NULL,\
805 raw_write_packet,\
806 .flags= AVFMT_NOTIMESTAMPS,\
807 };
808
809
810 #if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
811 #define PCMDEF(name, long_name, ext, codec) \
812 PCMINPUTDEF(name, long_name, ext, codec)
813 #elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
814 #define PCMDEF(name, long_name, ext, codec) \
815 PCMOUTPUTDEF(name, long_name, ext, codec)
816 #elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
817 #define PCMDEF(name, long_name, ext, codec) \
818 PCMINPUTDEF(name, long_name, ext, codec)\
819 PCMOUTPUTDEF(name, long_name, ext, codec)
820 #else
821 #define PCMDEF(name, long_name, ext, codec)
822 #endif
823
824 #ifdef WORDS_BIGENDIAN
825 #define BE_DEF(s) s
826 #define LE_DEF(s) NULL
827 #else
828 #define BE_DEF(s) NULL
829 #define LE_DEF(s) s
830 #endif
831
832
833 PCMDEF(s16le, "pcm signed 16 bit little endian format",
834 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
835
836 PCMDEF(s16be, "pcm signed 16 bit big endian format",
837 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
838
839 PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
840 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
841
842 PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
843 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
844
845 PCMDEF(s8, "pcm signed 8 bit format",
846 "sb", CODEC_ID_PCM_S8)
847
848 PCMDEF(u8, "pcm unsigned 8 bit format",
849 "ub", CODEC_ID_PCM_U8)
850
851 PCMDEF(mulaw, "pcm mu law format",
852 "ul", CODEC_ID_PCM_MULAW)
853
854 PCMDEF(alaw, "pcm A law format",
855 "al", CODEC_ID_PCM_ALAW)
856
857 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
858 {
859 int packet_size, ret, width, height;
860 AVStream *st = s->streams[0];
861
862 width = st->codec->width;
863 height = st->codec->height;
864
865 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
866 if (packet_size < 0)
867 return -1;
868
869 ret= av_get_packet(s->pb, pkt, packet_size);
870 pkt->pts=
871 pkt->dts= pkt->pos / packet_size;
872
873 pkt->stream_index = 0;
874 if (ret != packet_size) {
875 return AVERROR(EIO);
876 } else {
877 return 0;
878 }
879 }
880
881 AVInputFormat rawvideo_demuxer = {
882 "rawvideo",
883 "raw video format",
884 0,
885 NULL,
886 raw_read_header,
887 rawvideo_read_packet,
888 raw_read_close,
889 .flags= AVFMT_GENERIC_INDEX,
890 .extensions = "yuv,cif,qcif,rgb",
891 .value = CODEC_ID_RAWVIDEO,
892 };
893
894 #ifdef CONFIG_MUXERS
895 AVOutputFormat rawvideo_muxer = {
896 "rawvideo",
897 "raw video format",
898 NULL,
899 "yuv,rgb",
900 0,
901 CODEC_ID_NONE,
902 CODEC_ID_RAWVIDEO,
903 NULL,
904 raw_write_packet,
905 .flags= AVFMT_NOTIMESTAMPS,
906 };
907 #endif //CONFIG_MUXERS
908
909 #ifdef CONFIG_MUXERS
910 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
911 {
912 return 0;
913 }
914
915 AVOutputFormat null_muxer = {
916 "null",
917 "null video format",
918 NULL,
919 NULL,
920 0,
921 #ifdef WORDS_BIGENDIAN
922 CODEC_ID_PCM_S16BE,
923 #else
924 CODEC_ID_PCM_S16LE,
925 #endif
926 CODEC_ID_RAWVIDEO,
927 NULL,
928 null_write_packet,
929 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
930 };
931 #endif //CONFIG_MUXERS