Rename var: val -> energy
[FFMpeg-mirror/DVCPRO-HD.git] / libavformat / raw.c
blobed629fa1788d19a68e15f1339eaaf945b79e719a
1 /*
2 * RAW muxer and demuxer
3 * Copyright (c) 2001 Fabrice Bellard.
4 * Copyright (c) 2005 Alex Beregszaszi
6 * This file is part of FFmpeg.
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.
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.
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
23 #include "libavutil/crc.h"
24 #include "libavcodec/ac3_parser.h"
25 #include "libavcodec/bitstream.h"
26 #include "libavcodec/bytestream.h"
27 #include "avformat.h"
28 #include "raw.h"
30 #ifdef CONFIG_MUXERS
31 /* simple formats */
32 static int flac_write_header(struct AVFormatContext *s)
34 static const uint8_t header[8] = {
35 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
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);
43 return 0;
47 static int roq_write_header(struct AVFormatContext *s)
49 static const uint8_t header[] = {
50 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
53 put_buffer(s->pb, header, 8);
54 put_flush_packet(s->pb);
56 return 0;
59 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
61 put_buffer(s->pb, pkt->data, pkt->size);
62 put_flush_packet(s->pb);
63 return 0;
65 #endif //CONFIG_MUXERS
67 /* raw input */
68 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
70 AVStream *st;
71 int id;
73 st = av_new_stream(s, 0);
74 if (!st)
75 return AVERROR(ENOMEM);
77 id = s->iformat->value;
78 if (id == CODEC_ID_RAWVIDEO) {
79 st->codec->codec_type = CODEC_TYPE_VIDEO;
80 } else {
81 st->codec->codec_type = CODEC_TYPE_AUDIO;
83 st->codec->codec_id = id;
85 switch(st->codec->codec_type) {
86 case CODEC_TYPE_AUDIO:
87 st->codec->sample_rate = ap->sample_rate;
88 st->codec->channels = ap->channels;
89 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
90 break;
91 case CODEC_TYPE_VIDEO:
92 if(ap->time_base.num)
93 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
94 else
95 av_set_pts_info(st, 64, 1, 25);
96 st->codec->width = ap->width;
97 st->codec->height = ap->height;
98 st->codec->pix_fmt = ap->pix_fmt;
99 if(st->codec->pix_fmt == PIX_FMT_NONE)
100 st->codec->pix_fmt= PIX_FMT_YUV420P;
101 break;
102 default:
103 return -1;
105 return 0;
108 #define RAW_PACKET_SIZE 1024
110 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
112 int ret, size, bps;
113 // AVStream *st = s->streams[0];
115 size= RAW_PACKET_SIZE;
117 ret= av_get_packet(s->pb, pkt, size);
119 pkt->stream_index = 0;
120 if (ret <= 0) {
121 return AVERROR(EIO);
123 /* note: we need to modify the packet size here to handle the last
124 packet */
125 pkt->size = ret;
127 bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
128 assert(bps); // if false there IS a bug elsewhere (NOT in this function)
129 pkt->dts=
130 pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
132 return ret;
135 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
137 int ret, size;
139 size = RAW_PACKET_SIZE;
141 if (av_new_packet(pkt, size) < 0)
142 return AVERROR(EIO);
144 pkt->pos= url_ftell(s->pb);
145 pkt->stream_index = 0;
146 ret = get_partial_buffer(s->pb, pkt->data, size);
147 if (ret <= 0) {
148 av_free_packet(pkt);
149 return AVERROR(EIO);
151 pkt->size = ret;
152 return ret;
155 // http://www.artificis.hu/files/texts/ingenient.txt
156 static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
158 int ret, size, w, h, unk1, unk2;
160 if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
161 return AVERROR(EIO); // FIXME
163 size = get_le32(s->pb);
165 w = get_le16(s->pb);
166 h = get_le16(s->pb);
168 url_fskip(s->pb, 8); // zero + size (padded?)
169 url_fskip(s->pb, 2);
170 unk1 = get_le16(s->pb);
171 unk2 = get_le16(s->pb);
172 url_fskip(s->pb, 22); // ascii timestamp
174 av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
175 size, w, h, unk1, unk2);
177 if (av_new_packet(pkt, size) < 0)
178 return AVERROR(EIO);
180 pkt->pos = url_ftell(s->pb);
181 pkt->stream_index = 0;
182 ret = get_buffer(s->pb, pkt->data, size);
183 if (ret <= 0) {
184 av_free_packet(pkt);
185 return AVERROR(EIO);
187 pkt->size = ret;
188 return ret;
191 static int raw_read_close(AVFormatContext *s)
193 return 0;
196 int pcm_read_seek(AVFormatContext *s,
197 int stream_index, int64_t timestamp, int flags)
199 AVStream *st;
200 int block_align, byte_rate;
201 int64_t pos;
203 st = s->streams[0];
205 block_align = st->codec->block_align ? st->codec->block_align :
206 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
207 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
208 block_align * st->codec->sample_rate;
210 if (block_align <= 0 || byte_rate <= 0)
211 return -1;
213 /* compute the position by aligning it to block_align */
214 pos = av_rescale_rnd(timestamp * byte_rate,
215 st->time_base.num,
216 st->time_base.den * (int64_t)block_align,
217 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
218 pos *= block_align;
220 /* recompute exact position */
221 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
222 url_fseek(s->pb, pos + s->data_offset, SEEK_SET);
223 return 0;
226 static int audio_read_header(AVFormatContext *s,
227 AVFormatParameters *ap)
229 AVStream *st = av_new_stream(s, 0);
230 if (!st)
231 return AVERROR(ENOMEM);
232 st->codec->codec_type = CODEC_TYPE_AUDIO;
233 st->codec->codec_id = s->iformat->value;
234 st->need_parsing = AVSTREAM_PARSE_FULL;
235 /* the parameters will be extracted from the compressed bitstream */
236 return 0;
239 /* mpeg1/h263 input */
240 static int video_read_header(AVFormatContext *s,
241 AVFormatParameters *ap)
243 AVStream *st;
245 st = av_new_stream(s, 0);
246 if (!st)
247 return AVERROR(ENOMEM);
249 st->codec->codec_type = CODEC_TYPE_VIDEO;
250 st->codec->codec_id = s->iformat->value;
251 st->need_parsing = AVSTREAM_PARSE_FULL;
253 /* for mjpeg, specify frame rate */
254 /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
255 if (ap->time_base.num) {
256 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
257 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
258 st->codec->codec_id == CODEC_ID_MPEG4 ||
259 st->codec->codec_id == CODEC_ID_DIRAC ||
260 st->codec->codec_id == CODEC_ID_H264) {
261 av_set_pts_info(st, 64, 1, 25);
264 return 0;
267 #define SEQ_START_CODE 0x000001b3
268 #define GOP_START_CODE 0x000001b8
269 #define PICTURE_START_CODE 0x00000100
270 #define SLICE_START_CODE 0x00000101
271 #define PACK_START_CODE 0x000001ba
272 #define VIDEO_ID 0x000001e0
273 #define AUDIO_ID 0x000001c0
275 static int mpegvideo_probe(AVProbeData *p)
277 uint32_t code= -1;
278 int pic=0, seq=0, slice=0, pspack=0, pes=0;
279 int i;
281 for(i=0; i<p->buf_size; i++){
282 code = (code<<8) + p->buf[i];
283 if ((code & 0xffffff00) == 0x100) {
284 switch(code){
285 case SEQ_START_CODE: seq++; break;
286 case PICTURE_START_CODE: pic++; break;
287 case SLICE_START_CODE: slice++; break;
288 case PACK_START_CODE: pspack++; break;
290 if ((code & 0x1f0) == VIDEO_ID) pes++;
291 else if((code & 0x1e0) == AUDIO_ID) pes++;
294 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
295 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
296 return 0;
299 #define VISUAL_OBJECT_START_CODE 0x000001b5
300 #define VOP_START_CODE 0x000001b6
302 static int mpeg4video_probe(AVProbeData *probe_packet)
304 uint32_t temp_buffer= -1;
305 int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
306 int i;
308 for(i=0; i<probe_packet->buf_size; i++){
309 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
310 if ((temp_buffer & 0xffffff00) != 0x100)
311 continue;
313 if (temp_buffer == VOP_START_CODE) VOP++;
314 else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++;
315 else if (temp_buffer < 0x120) VO++;
316 else if (temp_buffer < 0x130) VOL++;
317 else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
318 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
321 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
322 return AVPROBE_SCORE_MAX/2;
323 return 0;
326 static int h263_probe(AVProbeData *p)
328 int code;
329 const uint8_t *d;
331 d = p->buf;
332 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
333 if (code == 0x20) {
334 return 50;
336 return 0;
339 static int h261_probe(AVProbeData *p)
341 int code;
342 const uint8_t *d;
344 d = p->buf;
345 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
346 if (code == 0x10) {
347 return 50;
349 return 0;
352 #define DCA_MARKER_14B_BE 0x1FFFE800
353 #define DCA_MARKER_14B_LE 0xFF1F00E8
354 #define DCA_MARKER_RAW_BE 0x7FFE8001
355 #define DCA_MARKER_RAW_LE 0xFE7F0180
356 static int dts_probe(AVProbeData *p)
358 const uint8_t *buf, *bufp;
359 uint32_t state = -1;
361 buf = p->buf;
363 for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
364 bufp = buf;
365 state = (state << 16) | bytestream_get_be16(&bufp);
367 /* Regular bitstream */
368 if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
369 return AVPROBE_SCORE_MAX/2+1;
371 /* 14 bits big endian bitstream */
372 if (state == DCA_MARKER_14B_BE)
373 if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
374 return AVPROBE_SCORE_MAX/2+1;
376 /* 14 bits little endian bitstream */
377 if (state == DCA_MARKER_14B_LE)
378 if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
379 return AVPROBE_SCORE_MAX/2+1;
382 return 0;
385 static int dirac_probe(AVProbeData *p)
387 if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
388 return AVPROBE_SCORE_MAX;
389 else
390 return 0;
393 static int ac3_probe(AVProbeData *p)
395 int max_frames, first_frames = 0, frames;
396 uint8_t *buf, *buf2, *end;
397 AC3HeaderInfo hdr;
398 GetBitContext gbc;
400 max_frames = 0;
401 buf = p->buf;
402 end = buf + p->buf_size;
404 for(; buf < end; buf++) {
405 buf2 = buf;
407 for(frames = 0; buf2 < end; frames++) {
408 init_get_bits(&gbc, buf2, 54);
409 if(ff_ac3_parse_header(&gbc, &hdr) < 0)
410 break;
411 if(buf2 + hdr.frame_size > end ||
412 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
413 break;
414 buf2 += hdr.frame_size;
416 max_frames = FFMAX(max_frames, frames);
417 if(buf == p->buf)
418 first_frames = frames;
420 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
421 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
422 else if(max_frames>=1) return 1;
423 else return 0;
426 static int flac_probe(AVProbeData *p)
428 if(memcmp(p->buf, "fLaC", 4)) return 0;
429 else return AVPROBE_SCORE_MAX / 2;
432 AVInputFormat shorten_demuxer = {
433 "shn",
434 "raw shorten",
436 NULL,
437 audio_read_header,
438 raw_read_partial_packet,
439 raw_read_close,
440 .flags= AVFMT_GENERIC_INDEX,
441 .extensions = "shn",
442 .value = CODEC_ID_SHORTEN,
445 AVInputFormat flac_demuxer = {
446 "flac",
447 "raw flac",
449 flac_probe,
450 audio_read_header,
451 raw_read_partial_packet,
452 raw_read_close,
453 .flags= AVFMT_GENERIC_INDEX,
454 .extensions = "flac",
455 .value = CODEC_ID_FLAC,
458 #ifdef CONFIG_MUXERS
459 AVOutputFormat flac_muxer = {
460 "flac",
461 "raw flac",
462 "audio/x-flac",
463 "flac",
465 CODEC_ID_FLAC,
466 CODEC_ID_NONE,
467 flac_write_header,
468 raw_write_packet,
469 .flags= AVFMT_NOTIMESTAMPS,
471 #endif //CONFIG_MUXERS
473 #ifdef CONFIG_AC3_DEMUXER
474 AVInputFormat ac3_demuxer = {
475 "ac3",
476 "raw ac3",
478 ac3_probe,
479 audio_read_header,
480 raw_read_partial_packet,
481 raw_read_close,
482 .flags= AVFMT_GENERIC_INDEX,
483 .extensions = "ac3",
484 .value = CODEC_ID_AC3,
486 #endif
488 #ifdef CONFIG_MUXERS
489 AVOutputFormat ac3_muxer = {
490 "ac3",
491 "raw ac3",
492 "audio/x-ac3",
493 "ac3",
495 CODEC_ID_AC3,
496 CODEC_ID_NONE,
497 NULL,
498 raw_write_packet,
499 .flags= AVFMT_NOTIMESTAMPS,
502 AVOutputFormat dts_muxer = {
503 "dts",
504 "raw dts",
505 "audio/x-dca",
506 "dts",
508 CODEC_ID_DTS,
509 CODEC_ID_NONE,
510 NULL,
511 raw_write_packet,
512 .flags= AVFMT_NOTIMESTAMPS,
515 #endif //CONFIG_MUXERS
517 AVInputFormat dirac_demuxer = {
518 "dirac",
519 "raw dirac",
521 dirac_probe,
522 video_read_header,
523 raw_read_partial_packet,
524 raw_read_close,
525 .flags= AVFMT_GENERIC_INDEX,
526 .value = CODEC_ID_DIRAC,
529 #ifdef CONFIG_MUXERS
530 AVOutputFormat dirac_muxer = {
531 "dirac",
532 "raw dirac",
533 NULL,
534 "drc",
536 CODEC_ID_NONE,
537 CODEC_ID_DIRAC,
538 NULL,
539 raw_write_packet,
540 .flags= AVFMT_NOTIMESTAMPS,
542 #endif
544 AVInputFormat dts_demuxer = {
545 "dts",
546 "raw dts",
548 dts_probe,
549 audio_read_header,
550 raw_read_partial_packet,
551 raw_read_close,
552 .flags= AVFMT_GENERIC_INDEX,
553 .extensions = "dts",
554 .value = CODEC_ID_DTS,
557 AVInputFormat aac_demuxer = {
558 "aac",
559 "ADTS AAC",
561 NULL,
562 audio_read_header,
563 raw_read_partial_packet,
564 raw_read_close,
565 .flags= AVFMT_GENERIC_INDEX,
566 .extensions = "aac",
567 .value = CODEC_ID_AAC,
570 AVInputFormat gsm_demuxer = {
571 "gsm",
572 "GSM",
574 NULL,
575 audio_read_header,
576 raw_read_partial_packet,
577 raw_read_close,
578 .flags= AVFMT_GENERIC_INDEX,
579 .extensions = "gsm",
580 .value = CODEC_ID_GSM,
583 #ifdef CONFIG_ROQ_MUXER
584 AVOutputFormat roq_muxer =
586 "RoQ",
587 "Id RoQ format",
588 NULL,
589 "roq",
591 CODEC_ID_ROQ_DPCM,
592 CODEC_ID_ROQ,
593 roq_write_header,
594 raw_write_packet,
596 #endif //CONFIG_ROQ_MUXER
598 AVInputFormat h261_demuxer = {
599 "h261",
600 "raw h261",
602 h261_probe,
603 video_read_header,
604 raw_read_partial_packet,
605 raw_read_close,
606 .flags= AVFMT_GENERIC_INDEX,
607 .extensions = "h261",
608 .value = CODEC_ID_H261,
611 #ifdef CONFIG_MUXERS
612 AVOutputFormat h261_muxer = {
613 "h261",
614 "raw h261",
615 "video/x-h261",
616 "h261",
618 CODEC_ID_NONE,
619 CODEC_ID_H261,
620 NULL,
621 raw_write_packet,
622 .flags= AVFMT_NOTIMESTAMPS,
624 #endif //CONFIG_MUXERS
626 AVInputFormat h263_demuxer = {
627 "h263",
628 "raw h263",
630 h263_probe,
631 video_read_header,
632 raw_read_partial_packet,
633 raw_read_close,
634 .flags= AVFMT_GENERIC_INDEX,
635 // .extensions = "h263", //FIXME remove after writing mpeg4_probe
636 .value = CODEC_ID_H263,
639 #ifdef CONFIG_MUXERS
640 AVOutputFormat h263_muxer = {
641 "h263",
642 "raw h263",
643 "video/x-h263",
644 "h263",
646 CODEC_ID_NONE,
647 CODEC_ID_H263,
648 NULL,
649 raw_write_packet,
650 .flags= AVFMT_NOTIMESTAMPS,
652 #endif //CONFIG_MUXERS
654 AVInputFormat m4v_demuxer = {
655 "m4v",
656 "raw MPEG4 video format",
658 mpeg4video_probe, /** probing for mpeg4 data */
659 video_read_header,
660 raw_read_partial_packet,
661 raw_read_close,
662 .flags= AVFMT_GENERIC_INDEX,
663 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
664 .value = CODEC_ID_MPEG4,
667 #ifdef CONFIG_MUXERS
668 AVOutputFormat m4v_muxer = {
669 "m4v",
670 "raw MPEG4 video format",
671 NULL,
672 "m4v",
674 CODEC_ID_NONE,
675 CODEC_ID_MPEG4,
676 NULL,
677 raw_write_packet,
678 .flags= AVFMT_NOTIMESTAMPS,
680 #endif //CONFIG_MUXERS
682 AVInputFormat h264_demuxer = {
683 "h264",
684 "raw H264 video format",
686 NULL /*mpegvideo_probe*/,
687 video_read_header,
688 raw_read_partial_packet,
689 raw_read_close,
690 .flags= AVFMT_GENERIC_INDEX,
691 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
692 .value = CODEC_ID_H264,
695 #ifdef CONFIG_MUXERS
696 AVOutputFormat h264_muxer = {
697 "h264",
698 "raw H264 video format",
699 NULL,
700 "h264",
702 CODEC_ID_NONE,
703 CODEC_ID_H264,
704 NULL,
705 raw_write_packet,
706 .flags= AVFMT_NOTIMESTAMPS,
708 #endif //CONFIG_MUXERS
710 AVInputFormat mpegvideo_demuxer = {
711 "mpegvideo",
712 "MPEG video",
714 mpegvideo_probe,
715 video_read_header,
716 raw_read_partial_packet,
717 raw_read_close,
718 .flags= AVFMT_GENERIC_INDEX,
719 .value = CODEC_ID_MPEG1VIDEO,
722 #ifdef CONFIG_MUXERS
723 AVOutputFormat mpeg1video_muxer = {
724 "mpeg1video",
725 "MPEG video",
726 "video/x-mpeg",
727 "mpg,mpeg,m1v",
729 CODEC_ID_NONE,
730 CODEC_ID_MPEG1VIDEO,
731 NULL,
732 raw_write_packet,
733 .flags= AVFMT_NOTIMESTAMPS,
735 #endif //CONFIG_MUXERS
737 #ifdef CONFIG_MUXERS
738 AVOutputFormat mpeg2video_muxer = {
739 "mpeg2video",
740 "MPEG2 video",
741 NULL,
742 "m2v",
744 CODEC_ID_NONE,
745 CODEC_ID_MPEG2VIDEO,
746 NULL,
747 raw_write_packet,
748 .flags= AVFMT_NOTIMESTAMPS,
750 #endif //CONFIG_MUXERS
752 AVInputFormat mjpeg_demuxer = {
753 "mjpeg",
754 "MJPEG video",
756 NULL,
757 video_read_header,
758 raw_read_partial_packet,
759 raw_read_close,
760 .flags= AVFMT_GENERIC_INDEX,
761 .extensions = "mjpg,mjpeg",
762 .value = CODEC_ID_MJPEG,
765 AVInputFormat ingenient_demuxer = {
766 "ingenient",
767 "Ingenient MJPEG",
769 NULL,
770 video_read_header,
771 ingenient_read_packet,
772 raw_read_close,
773 .flags= AVFMT_GENERIC_INDEX,
774 .extensions = "cgi", // FIXME
775 .value = CODEC_ID_MJPEG,
778 #ifdef CONFIG_MUXERS
779 AVOutputFormat mjpeg_muxer = {
780 "mjpeg",
781 "MJPEG video",
782 "video/x-mjpeg",
783 "mjpg,mjpeg",
785 CODEC_ID_NONE,
786 CODEC_ID_MJPEG,
787 NULL,
788 raw_write_packet,
789 .flags= AVFMT_NOTIMESTAMPS,
791 #endif //CONFIG_MUXERS
793 AVInputFormat vc1_demuxer = {
794 "vc1",
795 "raw vc1",
797 NULL /* vc1_probe */,
798 video_read_header,
799 raw_read_partial_packet,
800 raw_read_close,
801 .extensions = "vc1",
802 .value = CODEC_ID_VC1,
805 /* pcm formats */
807 #define PCMINPUTDEF(name, long_name, ext, codec) \
808 AVInputFormat pcm_ ## name ## _demuxer = {\
809 #name,\
810 long_name,\
812 NULL,\
813 raw_read_header,\
814 raw_read_packet,\
815 raw_read_close,\
816 pcm_read_seek,\
817 .flags= AVFMT_GENERIC_INDEX,\
818 .extensions = ext,\
819 .value = codec,\
822 #define PCMOUTPUTDEF(name, long_name, ext, codec) \
823 AVOutputFormat pcm_ ## name ## _muxer = {\
824 #name,\
825 long_name,\
826 NULL,\
827 ext,\
829 codec,\
830 CODEC_ID_NONE,\
831 NULL,\
832 raw_write_packet,\
833 .flags= AVFMT_NOTIMESTAMPS,\
837 #if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
838 #define PCMDEF(name, long_name, ext, codec) \
839 PCMINPUTDEF(name, long_name, ext, codec)
840 #elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
841 #define PCMDEF(name, long_name, ext, codec) \
842 PCMOUTPUTDEF(name, long_name, ext, codec)
843 #elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
844 #define PCMDEF(name, long_name, ext, codec) \
845 PCMINPUTDEF(name, long_name, ext, codec)\
846 PCMOUTPUTDEF(name, long_name, ext, codec)
847 #else
848 #define PCMDEF(name, long_name, ext, codec)
849 #endif
851 #ifdef WORDS_BIGENDIAN
852 #define BE_DEF(s) s
853 #define LE_DEF(s) NULL
854 #else
855 #define BE_DEF(s) NULL
856 #define LE_DEF(s) s
857 #endif
860 PCMDEF(s16le, "pcm signed 16 bit little endian format",
861 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
863 PCMDEF(s16be, "pcm signed 16 bit big endian format",
864 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
866 PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
867 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
869 PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
870 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
872 PCMDEF(s8, "pcm signed 8 bit format",
873 "sb", CODEC_ID_PCM_S8)
875 PCMDEF(u8, "pcm unsigned 8 bit format",
876 "ub", CODEC_ID_PCM_U8)
878 PCMDEF(mulaw, "pcm mu law format",
879 "ul", CODEC_ID_PCM_MULAW)
881 PCMDEF(alaw, "pcm A law format",
882 "al", CODEC_ID_PCM_ALAW)
884 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
886 int packet_size, ret, width, height;
887 AVStream *st = s->streams[0];
889 width = st->codec->width;
890 height = st->codec->height;
892 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
893 if (packet_size < 0)
894 return -1;
896 ret= av_get_packet(s->pb, pkt, packet_size);
897 pkt->pts=
898 pkt->dts= pkt->pos / packet_size;
900 pkt->stream_index = 0;
901 if (ret != packet_size) {
902 return AVERROR(EIO);
903 } else {
904 return 0;
908 AVInputFormat rawvideo_demuxer = {
909 "rawvideo",
910 "raw video format",
912 NULL,
913 raw_read_header,
914 rawvideo_read_packet,
915 raw_read_close,
916 .flags= AVFMT_GENERIC_INDEX,
917 .extensions = "yuv,cif,qcif,rgb",
918 .value = CODEC_ID_RAWVIDEO,
921 #ifdef CONFIG_MUXERS
922 AVOutputFormat rawvideo_muxer = {
923 "rawvideo",
924 "raw video format",
925 NULL,
926 "yuv,rgb",
928 CODEC_ID_NONE,
929 CODEC_ID_RAWVIDEO,
930 NULL,
931 raw_write_packet,
932 .flags= AVFMT_NOTIMESTAMPS,
934 #endif //CONFIG_MUXERS
936 #ifdef CONFIG_MUXERS
937 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
939 return 0;
942 AVOutputFormat null_muxer = {
943 "null",
944 "null video format",
945 NULL,
946 NULL,
948 #ifdef WORDS_BIGENDIAN
949 CODEC_ID_PCM_S16BE,
950 #else
951 CODEC_ID_PCM_S16LE,
952 #endif
953 CODEC_ID_RAWVIDEO,
954 NULL,
955 null_write_packet,
956 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
958 #endif //CONFIG_MUXERS