Handle ID3v2 tags in raw FLAC streams by skipping them.
[ffmpeg.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
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"
29 #include "id3v2.h"
30
31 /* simple formats */
32 #if CONFIG_FLAC_MUXER
33 static int flac_write_header(struct AVFormatContext *s)
34 {
35     static const uint8_t header[8] = {
36         0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
37     };
38     uint8_t *streaminfo = s->streams[0]->codec->extradata;
39     int len = s->streams[0]->codec->extradata_size;
40     if(streaminfo != NULL && len > 0) {
41         put_buffer(s->pb, header, 8);
42         put_buffer(s->pb, streaminfo, len);
43     }
44     return 0;
45 }
46
47 static int flac_write_trailer(struct AVFormatContext *s)
48 {
49     ByteIOContext *pb = s->pb;
50     uint8_t *streaminfo = s->streams[0]->codec->extradata;
51     int len = s->streams[0]->codec->extradata_size;
52     int64_t file_size;
53
54     if (streaminfo && len > 0 && !url_is_streamed(s->pb)) {
55         file_size = url_ftell(pb);
56         url_fseek(pb, 8, SEEK_SET);
57         put_buffer(pb, streaminfo, len);
58         url_fseek(pb, file_size, SEEK_SET);
59         put_flush_packet(pb);
60     }
61     return 0;
62 }
63 #endif
64
65 #if CONFIG_ROQ_MUXER
66 static int roq_write_header(struct AVFormatContext *s)
67 {
68     static const uint8_t header[] = {
69         0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
70     };
71
72     put_buffer(s->pb, header, 8);
73     put_flush_packet(s->pb);
74
75     return 0;
76 }
77 #endif
78
79 #if CONFIG_NULL_MUXER
80 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
81 {
82     return 0;
83 }
84 #endif
85
86 #if CONFIG_MUXERS
87 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
88 {
89     put_buffer(s->pb, pkt->data, pkt->size);
90     put_flush_packet(s->pb);
91     return 0;
92 }
93 #endif
94
95 #if CONFIG_DEMUXERS
96 /* raw input */
97 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
98 {
99     AVStream *st;
100     int id;
101
102     st = av_new_stream(s, 0);
103     if (!st)
104         return AVERROR(ENOMEM);
105
106         id = s->iformat->value;
107         if (id == CODEC_ID_RAWVIDEO) {
108             st->codec->codec_type = CODEC_TYPE_VIDEO;
109         } else {
110             st->codec->codec_type = CODEC_TYPE_AUDIO;
111         }
112         st->codec->codec_id = id;
113
114         switch(st->codec->codec_type) {
115         case CODEC_TYPE_AUDIO:
116             st->codec->sample_rate = ap->sample_rate;
117             if(ap->channels) st->codec->channels = ap->channels;
118             else             st->codec->channels = 1;
119             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
120             break;
121         case CODEC_TYPE_VIDEO:
122             if(ap->time_base.num)
123                 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
124             else
125                 av_set_pts_info(st, 64, 1, 25);
126             st->codec->width = ap->width;
127             st->codec->height = ap->height;
128             st->codec->pix_fmt = ap->pix_fmt;
129             if(st->codec->pix_fmt == PIX_FMT_NONE)
130                 st->codec->pix_fmt= PIX_FMT_YUV420P;
131             break;
132         default:
133             return -1;
134         }
135     return 0;
136 }
137
138 #define RAW_PACKET_SIZE 1024
139
140 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
141 {
142     int ret, size, bps;
143     //    AVStream *st = s->streams[0];
144
145     size= RAW_PACKET_SIZE;
146
147     ret= av_get_packet(s->pb, pkt, size);
148
149     pkt->stream_index = 0;
150     if (ret <= 0) {
151         return AVERROR(EIO);
152     }
153     /* note: we need to modify the packet size here to handle the last
154        packet */
155     pkt->size = ret;
156
157     bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
158     assert(bps); // if false there IS a bug elsewhere (NOT in this function)
159     pkt->dts=
160     pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
161
162     return ret;
163 }
164
165 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
166 {
167     int ret, size;
168
169     size = RAW_PACKET_SIZE;
170
171     if (av_new_packet(pkt, size) < 0)
172         return AVERROR(EIO);
173
174     pkt->pos= url_ftell(s->pb);
175     pkt->stream_index = 0;
176     ret = get_partial_buffer(s->pb, pkt->data, size);
177     if (ret <= 0) {
178         av_free_packet(pkt);
179         return AVERROR(EIO);
180     }
181     pkt->size = ret;
182     return ret;
183 }
184 #endif
185
186 #if CONFIG_RAWVIDEO_DEMUXER
187 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
188 {
189     int packet_size, ret, width, height;
190     AVStream *st = s->streams[0];
191
192     width = st->codec->width;
193     height = st->codec->height;
194
195     packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
196     if (packet_size < 0)
197         return -1;
198
199     ret= av_get_packet(s->pb, pkt, packet_size);
200     pkt->pts=
201     pkt->dts= pkt->pos / packet_size;
202
203     pkt->stream_index = 0;
204     if (ret != packet_size) {
205         return AVERROR(EIO);
206     } else {
207         return 0;
208     }
209 }
210 #endif
211
212 #if CONFIG_INGENIENT_DEMUXER
213 // http://www.artificis.hu/files/texts/ingenient.txt
214 static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
215 {
216     int ret, size, w, h, unk1, unk2;
217
218     if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
219         return AVERROR(EIO); // FIXME
220
221     size = get_le32(s->pb);
222
223     w = get_le16(s->pb);
224     h = get_le16(s->pb);
225
226     url_fskip(s->pb, 8); // zero + size (padded?)
227     url_fskip(s->pb, 2);
228     unk1 = get_le16(s->pb);
229     unk2 = get_le16(s->pb);
230     url_fskip(s->pb, 22); // ASCII timestamp
231
232     av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
233         size, w, h, unk1, unk2);
234
235     if (av_new_packet(pkt, size) < 0)
236         return AVERROR(EIO);
237
238     pkt->pos = url_ftell(s->pb);
239     pkt->stream_index = 0;
240     ret = get_buffer(s->pb, pkt->data, size);
241     if (ret <= 0) {
242         av_free_packet(pkt);
243         return AVERROR(EIO);
244     }
245     pkt->size = ret;
246     return ret;
247 }
248 #endif
249
250 #if CONFIG_DEMUXERS
251 int pcm_read_seek(AVFormatContext *s,
252                   int stream_index, int64_t timestamp, int flags)
253 {
254     AVStream *st;
255     int block_align, byte_rate, ret;
256     int64_t pos;
257
258     st = s->streams[0];
259
260     block_align = st->codec->block_align ? st->codec->block_align :
261         (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
262     byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
263         block_align * st->codec->sample_rate;
264
265     if (block_align <= 0 || byte_rate <= 0)
266         return -1;
267
268     /* compute the position by aligning it to block_align */
269     pos = av_rescale_rnd(timestamp * byte_rate,
270                          st->time_base.num,
271                          st->time_base.den * (int64_t)block_align,
272                          (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
273     pos *= block_align;
274
275     /* recompute exact position */
276     st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
277     if ((ret = url_fseek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
278         return ret;
279     return 0;
280 }
281
282 static int audio_read_header(AVFormatContext *s,
283                              AVFormatParameters *ap)
284 {
285     AVStream *st = av_new_stream(s, 0);
286     if (!st)
287         return AVERROR(ENOMEM);
288     st->codec->codec_type = CODEC_TYPE_AUDIO;
289     st->codec->codec_id = s->iformat->value;
290     st->need_parsing = AVSTREAM_PARSE_FULL;
291     /* the parameters will be extracted from the compressed bitstream */
292
293     if(st->codec->codec_id == CODEC_ID_FLAC) {
294         /* skip ID3v2 header if found */
295         uint8_t buf[ID3v2_HEADER_SIZE];
296         int ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
297         if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
298             int len = ff_id3v2_tag_len(buf);
299             url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
300         } else {
301             url_fseek(s->pb, 0, SEEK_SET);
302         }
303     }
304     return 0;
305 }
306
307 /* MPEG-1/H.263 input */
308 static int video_read_header(AVFormatContext *s,
309                              AVFormatParameters *ap)
310 {
311     AVStream *st;
312
313     st = av_new_stream(s, 0);
314     if (!st)
315         return AVERROR(ENOMEM);
316
317     st->codec->codec_type = CODEC_TYPE_VIDEO;
318     st->codec->codec_id = s->iformat->value;
319     st->need_parsing = AVSTREAM_PARSE_FULL;
320
321     /* for MJPEG, specify frame rate */
322     /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
323     if (ap->time_base.num) {
324         av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
325     } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
326                 st->codec->codec_id == CODEC_ID_MPEG4 ||
327                 st->codec->codec_id == CODEC_ID_DIRAC ||
328                 st->codec->codec_id == CODEC_ID_H264) {
329         av_set_pts_info(st, 64, 1, 25);
330     }
331
332     return 0;
333 }
334 #endif
335
336 #if CONFIG_MPEGVIDEO_DEMUXER
337 #define SEQ_START_CODE          0x000001b3
338 #define GOP_START_CODE          0x000001b8
339 #define PICTURE_START_CODE      0x00000100
340 #define SLICE_START_CODE        0x00000101
341 #define PACK_START_CODE         0x000001ba
342 #define VIDEO_ID                0x000001e0
343 #define AUDIO_ID                0x000001c0
344
345 static int mpegvideo_probe(AVProbeData *p)
346 {
347     uint32_t code= -1;
348     int pic=0, seq=0, slice=0, pspack=0, pes=0;
349     int i;
350
351     for(i=0; i<p->buf_size; i++){
352         code = (code<<8) + p->buf[i];
353         if ((code & 0xffffff00) == 0x100) {
354             switch(code){
355             case     SEQ_START_CODE:   seq++; break;
356             case PICTURE_START_CODE:   pic++; break;
357             case   SLICE_START_CODE: slice++; break;
358             case    PACK_START_CODE: pspack++; break;
359             }
360             if     ((code & 0x1f0) == VIDEO_ID)   pes++;
361             else if((code & 0x1e0) == AUDIO_ID)   pes++;
362         }
363     }
364     if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
365         return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
366     return 0;
367 }
368 #endif
369
370 #if CONFIG_M4V_DEMUXER
371 #define VISUAL_OBJECT_START_CODE       0x000001b5
372 #define VOP_START_CODE                 0x000001b6
373
374 static int mpeg4video_probe(AVProbeData *probe_packet)
375 {
376     uint32_t temp_buffer= -1;
377     int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
378     int i;
379
380     for(i=0; i<probe_packet->buf_size; i++){
381         temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
382         if ((temp_buffer & 0xffffff00) != 0x100)
383             continue;
384
385         if (temp_buffer == VOP_START_CODE)                         VOP++;
386         else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
387         else if (temp_buffer < 0x120)                              VO++;
388         else if (temp_buffer < 0x130)                              VOL++;
389         else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
390                  && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
391     }
392
393     if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
394         return AVPROBE_SCORE_MAX/2;
395     return 0;
396 }
397 #endif
398
399 #if CONFIG_H264_DEMUXER
400 static int h264_probe(AVProbeData *p)
401 {
402     uint32_t code= -1;
403     int sps=0, pps=0, idr=0, res=0, sli=0;
404     int i;
405
406     for(i=0; i<p->buf_size; i++){
407         code = (code<<8) + p->buf[i];
408         if ((code & 0xffffff00) == 0x100) {
409             int ref_idc= (code>>5)&3;
410             int type   = code & 0x1F;
411             static const int8_t ref_zero[32]={
412                 2, 0, 0, 0, 0,-1, 1,-1,
413                -1, 1, 1, 1, 1,-1, 2, 2,
414                 2, 2, 2, 0, 2, 2, 2, 2,
415                 2, 2, 2, 2, 2, 2, 2, 2
416             };
417
418             if(code & 0x80) //forbidden bit
419                 return 0;
420
421             if(ref_zero[type] == 1 && ref_idc)
422                 return 0;
423             if(ref_zero[type] ==-1 && !ref_idc)
424                 return 0;
425             if(ref_zero[type] == 2)
426                 res++;
427
428             switch(type){
429             case     1:   sli++; break;
430             case     5:   idr++; break;
431             case     7:
432                 if(p->buf[i+2]&0x0F)
433                     return 0;
434                 sps++;
435                 break;
436             case     8:   pps++; break;
437             }
438         }
439     }
440     if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
441         return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
442     return 0;
443 }
444 #endif
445
446 #if CONFIG_H263_DEMUXER
447 static int h263_probe(AVProbeData *p)
448 {
449     int code;
450     const uint8_t *d;
451
452     d = p->buf;
453     code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
454     if (code == 0x20) {
455         return 50;
456     }
457     return 0;
458 }
459 #endif
460
461 #if CONFIG_H261_DEMUXER
462 static int h261_probe(AVProbeData *p)
463 {
464     int code;
465     const uint8_t *d;
466
467     d = p->buf;
468     code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
469     if (code == 0x10) {
470         return 50;
471     }
472     return 0;
473 }
474 #endif
475
476 #if CONFIG_DTS_DEMUXER
477 #define DCA_MARKER_14B_BE 0x1FFFE800
478 #define DCA_MARKER_14B_LE 0xFF1F00E8
479 #define DCA_MARKER_RAW_BE 0x7FFE8001
480 #define DCA_MARKER_RAW_LE 0xFE7F0180
481 static int dts_probe(AVProbeData *p)
482 {
483     const uint8_t *buf, *bufp;
484     uint32_t state = -1;
485
486     buf = p->buf;
487
488     for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
489         bufp = buf;
490         state = (state << 16) | bytestream_get_be16(&bufp);
491
492         /* regular bitstream */
493         if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
494             return AVPROBE_SCORE_MAX/2+1;
495
496         /* 14 bits big-endian bitstream */
497         if (state == DCA_MARKER_14B_BE)
498             if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
499                 return AVPROBE_SCORE_MAX/2+1;
500
501         /* 14 bits little-endian bitstream */
502         if (state == DCA_MARKER_14B_LE)
503             if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
504                 return AVPROBE_SCORE_MAX/2+1;
505     }
506
507     return 0;
508 }
509 #endif
510
511 #if CONFIG_DIRAC_DEMUXER
512 static int dirac_probe(AVProbeData *p)
513 {
514     if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
515         return AVPROBE_SCORE_MAX;
516     else
517         return 0;
518 }
519 #endif
520
521 #if CONFIG_DNXHD_DEMUXER
522 static int dnxhd_probe(AVProbeData *p)
523 {
524     static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01};
525     if (!memcmp(p->buf, header, 5))
526         return AVPROBE_SCORE_MAX;
527     else
528         return 0;
529 }
530 #endif
531
532 #if CONFIG_AC3_DEMUXER || CONFIG_EAC3_DEMUXER
533 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
534 {
535     int max_frames, first_frames = 0, frames;
536     uint8_t *buf, *buf2, *end;
537     AC3HeaderInfo hdr;
538     GetBitContext gbc;
539     enum CodecID codec_id = CODEC_ID_AC3;
540
541     max_frames = 0;
542     buf = p->buf;
543     end = buf + p->buf_size;
544
545     for(; buf < end; buf++) {
546         buf2 = buf;
547
548         for(frames = 0; buf2 < end; frames++) {
549             init_get_bits(&gbc, buf2, 54);
550             if(ff_ac3_parse_header(&gbc, &hdr) < 0)
551                 break;
552             if(buf2 + hdr.frame_size > end ||
553                av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
554                 break;
555             if (hdr.bitstream_id > 10)
556                 codec_id = CODEC_ID_EAC3;
557             buf2 += hdr.frame_size;
558         }
559         max_frames = FFMAX(max_frames, frames);
560         if(buf == p->buf)
561             first_frames = frames;
562     }
563     if(codec_id != expected_codec_id) return 0;
564     if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
565     else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
566     else if(max_frames>=1) return 1;
567     else                   return 0;
568 }
569 #endif
570
571 #if CONFIG_AC3_DEMUXER
572 static int ac3_probe(AVProbeData *p)
573 {
574     return ac3_eac3_probe(p, CODEC_ID_AC3);
575 }
576 #endif
577
578 #if CONFIG_EAC3_DEMUXER
579 static int eac3_probe(AVProbeData *p)
580 {
581     return ac3_eac3_probe(p, CODEC_ID_EAC3);
582 }
583 #endif
584
585 #if CONFIG_FLAC_DEMUXER
586 static int flac_probe(AVProbeData *p)
587 {
588     uint8_t *bufptr = p->buf;
589
590     if(ff_id3v2_match(bufptr))
591         bufptr += ff_id3v2_tag_len(bufptr);
592
593     if(memcmp(bufptr, "fLaC", 4)) return 0;
594     else                          return AVPROBE_SCORE_MAX / 2;
595 }
596 #endif
597
598 #if CONFIG_AAC_DEMUXER
599 static int adts_aac_probe(AVProbeData *p)
600 {
601     int max_frames = 0, first_frames = 0;
602     int fsize, frames;
603     uint8_t *buf0 = p->buf;
604     uint8_t *buf2;
605     uint8_t *buf;
606     uint8_t *end = buf0 + p->buf_size - 7;
607
608     if (ff_id3v2_match(buf0)) {
609         buf0 += ff_id3v2_tag_len(buf0);
610     }
611     buf = buf0;
612
613     for(; buf < end; buf= buf2+1) {
614         buf2 = buf;
615
616         for(frames = 0; buf2 < end; frames++) {
617             uint32_t header = AV_RB16(buf2);
618             if((header&0xFFF6) != 0xFFF0)
619                 break;
620             fsize = (AV_RB32(buf2+3)>>13) & 0x8FFF;
621             if(fsize < 7)
622                 break;
623             buf2 += fsize;
624         }
625         max_frames = FFMAX(max_frames, frames);
626         if(buf == buf0)
627             first_frames= frames;
628     }
629     if   (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
630     else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
631     else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
632     else if(max_frames>=1) return 1;
633     else                   return 0;
634 }
635 #endif
636
637 /* Note: Do not forget to add new entries to the Makefile as well. */
638
639 #if CONFIG_AAC_DEMUXER
640 AVInputFormat aac_demuxer = {
641     "aac",
642     NULL_IF_CONFIG_SMALL("ADTS AAC"),
643     0,
644     adts_aac_probe,
645     audio_read_header,
646     raw_read_partial_packet,
647     .flags= AVFMT_GENERIC_INDEX,
648     .extensions = "aac",
649     .value = CODEC_ID_AAC,
650 };
651 #endif
652
653 #if CONFIG_AC3_DEMUXER
654 AVInputFormat ac3_demuxer = {
655     "ac3",
656     NULL_IF_CONFIG_SMALL("raw AC-3"),
657     0,
658     ac3_probe,
659     audio_read_header,
660     raw_read_partial_packet,
661     .flags= AVFMT_GENERIC_INDEX,
662     .extensions = "ac3",
663     .value = CODEC_ID_AC3,
664 };
665 #endif
666
667 #if CONFIG_AC3_MUXER
668 AVOutputFormat ac3_muxer = {
669     "ac3",
670     NULL_IF_CONFIG_SMALL("raw AC-3"),
671     "audio/x-ac3",
672     "ac3",
673     0,
674     CODEC_ID_AC3,
675     CODEC_ID_NONE,
676     NULL,
677     raw_write_packet,
678     .flags= AVFMT_NOTIMESTAMPS,
679 };
680 #endif
681
682 #if CONFIG_DIRAC_DEMUXER
683 AVInputFormat dirac_demuxer = {
684     "dirac",
685     NULL_IF_CONFIG_SMALL("raw Dirac"),
686     0,
687     dirac_probe,
688     video_read_header,
689     raw_read_partial_packet,
690     .flags= AVFMT_GENERIC_INDEX,
691     .value = CODEC_ID_DIRAC,
692 };
693 #endif
694
695 #if CONFIG_DIRAC_MUXER
696 AVOutputFormat dirac_muxer = {
697     "dirac",
698     NULL_IF_CONFIG_SMALL("raw Dirac"),
699     NULL,
700     "drc",
701     0,
702     CODEC_ID_NONE,
703     CODEC_ID_DIRAC,
704     NULL,
705     raw_write_packet,
706     .flags= AVFMT_NOTIMESTAMPS,
707 };
708 #endif
709
710 #if CONFIG_DNXHD_DEMUXER
711 AVInputFormat dnxhd_demuxer = {
712     "dnxhd",
713     NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
714     0,
715     dnxhd_probe,
716     video_read_header,
717     raw_read_partial_packet,
718     .flags= AVFMT_GENERIC_INDEX,
719     .value = CODEC_ID_DNXHD,
720 };
721 #endif
722
723 #if CONFIG_DNXHD_MUXER
724 AVOutputFormat dnxhd_muxer = {
725     "dnxhd",
726     NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
727     NULL,
728     "dnxhd",
729     0,
730     CODEC_ID_NONE,
731     CODEC_ID_DNXHD,
732     NULL,
733     raw_write_packet,
734     .flags= AVFMT_NOTIMESTAMPS,
735 };
736 #endif
737
738 #if CONFIG_DTS_DEMUXER
739 AVInputFormat dts_demuxer = {
740     "dts",
741     NULL_IF_CONFIG_SMALL("raw DTS"),
742     0,
743     dts_probe,
744     audio_read_header,
745     raw_read_partial_packet,
746     .flags= AVFMT_GENERIC_INDEX,
747     .extensions = "dts",
748     .value = CODEC_ID_DTS,
749 };
750 #endif
751
752 #if CONFIG_DTS_MUXER
753 AVOutputFormat dts_muxer = {
754     "dts",
755     NULL_IF_CONFIG_SMALL("raw DTS"),
756     "audio/x-dca",
757     "dts",
758     0,
759     CODEC_ID_DTS,
760     CODEC_ID_NONE,
761     NULL,
762     raw_write_packet,
763     .flags= AVFMT_NOTIMESTAMPS,
764 };
765 #endif
766
767 #if CONFIG_EAC3_DEMUXER
768 AVInputFormat eac3_demuxer = {
769     "eac3",
770     NULL_IF_CONFIG_SMALL("raw E-AC-3"),
771     0,
772     eac3_probe,
773     audio_read_header,
774     raw_read_partial_packet,
775     .flags= AVFMT_GENERIC_INDEX,
776     .extensions = "eac3",
777     .value = CODEC_ID_EAC3,
778 };
779 #endif
780
781 #if CONFIG_EAC3_MUXER
782 AVOutputFormat eac3_muxer = {
783     "eac3",
784     NULL_IF_CONFIG_SMALL("raw E-AC-3"),
785     "audio/x-eac3",
786     "eac3",
787     0,
788     CODEC_ID_EAC3,
789     CODEC_ID_NONE,
790     NULL,
791     raw_write_packet,
792     .flags= AVFMT_NOTIMESTAMPS,
793 };
794 #endif
795
796 #if CONFIG_FLAC_DEMUXER
797 AVInputFormat flac_demuxer = {
798     "flac",
799     NULL_IF_CONFIG_SMALL("raw FLAC"),
800     0,
801     flac_probe,
802     audio_read_header,
803     raw_read_partial_packet,
804     .flags= AVFMT_GENERIC_INDEX,
805     .extensions = "flac",
806     .value = CODEC_ID_FLAC,
807 };
808 #endif
809
810 #if CONFIG_FLAC_MUXER
811 AVOutputFormat flac_muxer = {
812     "flac",
813     NULL_IF_CONFIG_SMALL("raw FLAC"),
814     "audio/x-flac",
815     "flac",
816     0,
817     CODEC_ID_FLAC,
818     CODEC_ID_NONE,
819     flac_write_header,
820     raw_write_packet,
821     flac_write_trailer,
822     .flags= AVFMT_NOTIMESTAMPS,
823 };
824 #endif
825
826 #if CONFIG_GSM_DEMUXER
827 AVInputFormat gsm_demuxer = {
828     "gsm",
829     NULL_IF_CONFIG_SMALL("GSM"),
830     0,
831     NULL,
832     audio_read_header,
833     raw_read_partial_packet,
834     .flags= AVFMT_GENERIC_INDEX,
835     .extensions = "gsm",
836     .value = CODEC_ID_GSM,
837 };
838 #endif
839
840 #if CONFIG_H261_DEMUXER
841 AVInputFormat h261_demuxer = {
842     "h261",
843     NULL_IF_CONFIG_SMALL("raw H.261"),
844     0,
845     h261_probe,
846     video_read_header,
847     raw_read_partial_packet,
848     .flags= AVFMT_GENERIC_INDEX,
849     .extensions = "h261",
850     .value = CODEC_ID_H261,
851 };
852 #endif
853
854 #if CONFIG_H261_MUXER
855 AVOutputFormat h261_muxer = {
856     "h261",
857     NULL_IF_CONFIG_SMALL("raw H.261"),
858     "video/x-h261",
859     "h261",
860     0,
861     CODEC_ID_NONE,
862     CODEC_ID_H261,
863     NULL,
864     raw_write_packet,
865     .flags= AVFMT_NOTIMESTAMPS,
866 };
867 #endif
868
869 #if CONFIG_H263_DEMUXER
870 AVInputFormat h263_demuxer = {
871     "h263",
872     NULL_IF_CONFIG_SMALL("raw H.263"),
873     0,
874     h263_probe,
875     video_read_header,
876     raw_read_partial_packet,
877     .flags= AVFMT_GENERIC_INDEX,
878 //    .extensions = "h263", //FIXME remove after writing mpeg4_probe
879     .value = CODEC_ID_H263,
880 };
881 #endif
882
883 #if CONFIG_H263_MUXER
884 AVOutputFormat h263_muxer = {
885     "h263",
886     NULL_IF_CONFIG_SMALL("raw H.263"),
887     "video/x-h263",
888     "h263",
889     0,
890     CODEC_ID_NONE,
891     CODEC_ID_H263,
892     NULL,
893     raw_write_packet,
894     .flags= AVFMT_NOTIMESTAMPS,
895 };
896 #endif
897
898 #if CONFIG_H264_DEMUXER
899 AVInputFormat h264_demuxer = {
900     "h264",
901     NULL_IF_CONFIG_SMALL("raw H.264 video format"),
902     0,
903     h264_probe,
904     video_read_header,
905     raw_read_partial_packet,
906     .flags= AVFMT_GENERIC_INDEX,
907     .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
908     .value = CODEC_ID_H264,
909 };
910 #endif
911
912 #if CONFIG_H264_MUXER
913 AVOutputFormat h264_muxer = {
914     "h264",
915     NULL_IF_CONFIG_SMALL("raw H.264 video format"),
916     NULL,
917     "h264",
918     0,
919     CODEC_ID_NONE,
920     CODEC_ID_H264,
921     NULL,
922     raw_write_packet,
923     .flags= AVFMT_NOTIMESTAMPS,
924 };
925 #endif
926
927 #if CONFIG_INGENIENT_DEMUXER
928 AVInputFormat ingenient_demuxer = {
929     "ingenient",
930     NULL_IF_CONFIG_SMALL("Ingenient MJPEG"),
931     0,
932     NULL,
933     video_read_header,
934     ingenient_read_packet,
935     .flags= AVFMT_GENERIC_INDEX,
936     .extensions = "cgi", // FIXME
937     .value = CODEC_ID_MJPEG,
938 };
939 #endif
940
941 #if CONFIG_M4V_DEMUXER
942 AVInputFormat m4v_demuxer = {
943     "m4v",
944     NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
945     0,
946     mpeg4video_probe, /** probing for MPEG-4 data */
947     video_read_header,
948     raw_read_partial_packet,
949     .flags= AVFMT_GENERIC_INDEX,
950     .extensions = "m4v",
951     .value = CODEC_ID_MPEG4,
952 };
953 #endif
954
955 #if CONFIG_M4V_MUXER
956 AVOutputFormat m4v_muxer = {
957     "m4v",
958     NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
959     NULL,
960     "m4v",
961     0,
962     CODEC_ID_NONE,
963     CODEC_ID_MPEG4,
964     NULL,
965     raw_write_packet,
966     .flags= AVFMT_NOTIMESTAMPS,
967 };
968 #endif
969
970 #if CONFIG_MJPEG_DEMUXER
971 AVInputFormat mjpeg_demuxer = {
972     "mjpeg",
973     NULL_IF_CONFIG_SMALL("MJPEG video"),
974     0,
975     NULL,
976     video_read_header,
977     raw_read_partial_packet,
978     .flags= AVFMT_GENERIC_INDEX,
979     .extensions = "mjpg,mjpeg",
980     .value = CODEC_ID_MJPEG,
981 };
982 #endif
983
984 #if CONFIG_MJPEG_MUXER
985 AVOutputFormat mjpeg_muxer = {
986     "mjpeg",
987     NULL_IF_CONFIG_SMALL("MJPEG video"),
988     "video/x-mjpeg",
989     "mjpg,mjpeg",
990     0,
991     CODEC_ID_NONE,
992     CODEC_ID_MJPEG,
993     NULL,
994     raw_write_packet,
995     .flags= AVFMT_NOTIMESTAMPS,
996 };
997 #endif
998
999 #if CONFIG_MLP_DEMUXER
1000 AVInputFormat mlp_demuxer = {
1001     "mlp",
1002     NULL_IF_CONFIG_SMALL("raw MLP"),
1003     0,
1004     NULL,
1005     audio_read_header,
1006     raw_read_partial_packet,
1007     .flags= AVFMT_GENERIC_INDEX,
1008     .extensions = "mlp",
1009     .value = CODEC_ID_MLP,
1010 };
1011 #endif
1012
1013 #if CONFIG_MPEG1VIDEO_MUXER
1014 AVOutputFormat mpeg1video_muxer = {
1015     "mpeg1video",
1016     NULL_IF_CONFIG_SMALL("MPEG video"),
1017     "video/x-mpeg",
1018     "mpg,mpeg,m1v",
1019     0,
1020     CODEC_ID_NONE,
1021     CODEC_ID_MPEG1VIDEO,
1022     NULL,
1023     raw_write_packet,
1024     .flags= AVFMT_NOTIMESTAMPS,
1025 };
1026 #endif
1027
1028 #if CONFIG_MPEG2VIDEO_MUXER
1029 AVOutputFormat mpeg2video_muxer = {
1030     "mpeg2video",
1031     NULL_IF_CONFIG_SMALL("MPEG-2 video"),
1032     NULL,
1033     "m2v",
1034     0,
1035     CODEC_ID_NONE,
1036     CODEC_ID_MPEG2VIDEO,
1037     NULL,
1038     raw_write_packet,
1039     .flags= AVFMT_NOTIMESTAMPS,
1040 };
1041 #endif
1042
1043 #if CONFIG_MPEGVIDEO_DEMUXER
1044 AVInputFormat mpegvideo_demuxer = {
1045     "mpegvideo",
1046     NULL_IF_CONFIG_SMALL("MPEG video"),
1047     0,
1048     mpegvideo_probe,
1049     video_read_header,
1050     raw_read_partial_packet,
1051     .flags= AVFMT_GENERIC_INDEX,
1052     .value = CODEC_ID_MPEG1VIDEO,
1053 };
1054 #endif
1055
1056 #if CONFIG_NULL_MUXER
1057 AVOutputFormat null_muxer = {
1058     "null",
1059     NULL_IF_CONFIG_SMALL("null video format"),
1060     NULL,
1061     NULL,
1062     0,
1063 #ifdef WORDS_BIGENDIAN
1064     CODEC_ID_PCM_S16BE,
1065 #else
1066     CODEC_ID_PCM_S16LE,
1067 #endif
1068     CODEC_ID_RAWVIDEO,
1069     NULL,
1070     null_write_packet,
1071     .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
1072 };
1073 #endif
1074
1075 #if CONFIG_RAWVIDEO_DEMUXER
1076 AVInputFormat rawvideo_demuxer = {
1077     "rawvideo",
1078     NULL_IF_CONFIG_SMALL("raw video format"),
1079     0,
1080     NULL,
1081     raw_read_header,
1082     rawvideo_read_packet,
1083     .flags= AVFMT_GENERIC_INDEX,
1084     .extensions = "yuv,cif,qcif,rgb",
1085     .value = CODEC_ID_RAWVIDEO,
1086 };
1087 #endif
1088
1089 #if CONFIG_RAWVIDEO_MUXER
1090 AVOutputFormat rawvideo_muxer = {
1091     "rawvideo",
1092     NULL_IF_CONFIG_SMALL("raw video format"),
1093     NULL,
1094     "yuv,rgb",
1095     0,
1096     CODEC_ID_NONE,
1097     CODEC_ID_RAWVIDEO,
1098     NULL,
1099     raw_write_packet,
1100     .flags= AVFMT_NOTIMESTAMPS,
1101 };
1102 #endif
1103
1104 #if CONFIG_ROQ_MUXER
1105 AVOutputFormat roq_muxer =
1106 {
1107     "RoQ",
1108     NULL_IF_CONFIG_SMALL("id RoQ format"),
1109     NULL,
1110     "roq",
1111     0,
1112     CODEC_ID_ROQ_DPCM,
1113     CODEC_ID_ROQ,
1114     roq_write_header,
1115     raw_write_packet,
1116 };
1117 #endif
1118
1119 #if CONFIG_SHORTEN_DEMUXER
1120 AVInputFormat shorten_demuxer = {
1121     "shn",
1122     NULL_IF_CONFIG_SMALL("raw Shorten"),
1123     0,
1124     NULL,
1125     audio_read_header,
1126     raw_read_partial_packet,
1127     .flags= AVFMT_GENERIC_INDEX,
1128     .extensions = "shn",
1129     .value = CODEC_ID_SHORTEN,
1130 };
1131 #endif
1132
1133 #if CONFIG_VC1_DEMUXER
1134 AVInputFormat vc1_demuxer = {
1135     "vc1",
1136     NULL_IF_CONFIG_SMALL("raw VC-1"),
1137     0,
1138     NULL /* vc1_probe */,
1139     video_read_header,
1140     raw_read_partial_packet,
1141     .extensions = "vc1",
1142     .value = CODEC_ID_VC1,
1143 };
1144 #endif
1145
1146 /* PCM formats */
1147
1148 #define PCMINPUTDEF(name, long_name, ext, codec) \
1149 AVInputFormat pcm_ ## name ## _demuxer = {\
1150     #name,\
1151     NULL_IF_CONFIG_SMALL(long_name),\
1152     0,\
1153     NULL,\
1154     raw_read_header,\
1155     raw_read_packet,\
1156     NULL,\
1157     pcm_read_seek,\
1158     .flags= AVFMT_GENERIC_INDEX,\
1159     .extensions = ext,\
1160     .value = codec,\
1161 };
1162
1163 #define PCMOUTPUTDEF(name, long_name, ext, codec) \
1164 AVOutputFormat pcm_ ## name ## _muxer = {\
1165     #name,\
1166     NULL_IF_CONFIG_SMALL(long_name),\
1167     NULL,\
1168     ext,\
1169     0,\
1170     codec,\
1171     CODEC_ID_NONE,\
1172     NULL,\
1173     raw_write_packet,\
1174     .flags= AVFMT_NOTIMESTAMPS,\
1175 };
1176
1177
1178 #if  !CONFIG_MUXERS && CONFIG_DEMUXERS
1179 #define PCMDEF(name, long_name, ext, codec) \
1180         PCMINPUTDEF(name, long_name, ext, codec)
1181 #elif CONFIG_MUXERS && !CONFIG_DEMUXERS
1182 #define PCMDEF(name, long_name, ext, codec) \
1183         PCMOUTPUTDEF(name, long_name, ext, codec)
1184 #elif CONFIG_MUXERS && CONFIG_DEMUXERS
1185 #define PCMDEF(name, long_name, ext, codec) \
1186         PCMINPUTDEF(name, long_name, ext, codec)\
1187         PCMOUTPUTDEF(name, long_name, ext, codec)
1188 #else
1189 #define PCMDEF(name, long_name, ext, codec)
1190 #endif
1191
1192 #ifdef WORDS_BIGENDIAN
1193 #define BE_DEF(s) s
1194 #define LE_DEF(s) NULL
1195 #else
1196 #define BE_DEF(s) NULL
1197 #define LE_DEF(s) s
1198 #endif
1199
1200 PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
1201        NULL, CODEC_ID_PCM_F64BE)
1202
1203 PCMDEF(f64le, "PCM 64 bit floating-point little-endian format",
1204        NULL, CODEC_ID_PCM_F64LE)
1205
1206 PCMDEF(f32be, "PCM 32 bit floating-point big-endian format",
1207        NULL, CODEC_ID_PCM_F32BE)
1208
1209 PCMDEF(f32le, "PCM 32 bit floating-point little-endian format",
1210        NULL, CODEC_ID_PCM_F32LE)
1211
1212 PCMDEF(s32be, "PCM signed 32 bit big-endian format",
1213        NULL, CODEC_ID_PCM_S32BE)
1214
1215 PCMDEF(s32le, "PCM signed 32 bit little-endian format",
1216        NULL, CODEC_ID_PCM_S32LE)
1217
1218 PCMDEF(s24be, "PCM signed 24 bit big-endian format",
1219        NULL, CODEC_ID_PCM_S24BE)
1220
1221 PCMDEF(s24le, "PCM signed 24 bit little-endian format",
1222        NULL, CODEC_ID_PCM_S24LE)
1223
1224 PCMDEF(s16be, "PCM signed 16 bit big-endian format",
1225        BE_DEF("sw"), CODEC_ID_PCM_S16BE)
1226
1227 PCMDEF(s16le, "PCM signed 16 bit little-endian format",
1228        LE_DEF("sw"), CODEC_ID_PCM_S16LE)
1229
1230 PCMDEF(s8, "PCM signed 8 bit format",
1231        "sb", CODEC_ID_PCM_S8)
1232
1233 PCMDEF(u32be, "PCM unsigned 32 bit big-endian format",
1234        NULL, CODEC_ID_PCM_U32BE)
1235
1236 PCMDEF(u32le, "PCM unsigned 32 bit little-endian format",
1237        NULL, CODEC_ID_PCM_U32LE)
1238
1239 PCMDEF(u24be, "PCM unsigned 24 bit big-endian format",
1240        NULL, CODEC_ID_PCM_U24BE)
1241
1242 PCMDEF(u24le, "PCM unsigned 24 bit little-endian format",
1243        NULL, CODEC_ID_PCM_U24LE)
1244
1245 PCMDEF(u16be, "PCM unsigned 16 bit big-endian format",
1246        BE_DEF("uw"), CODEC_ID_PCM_U16BE)
1247
1248 PCMDEF(u16le, "PCM unsigned 16 bit little-endian format",
1249        LE_DEF("uw"), CODEC_ID_PCM_U16LE)
1250
1251 PCMDEF(u8, "PCM unsigned 8 bit format",
1252        "ub", CODEC_ID_PCM_U8)
1253
1254 PCMDEF(alaw, "PCM A-law format",
1255        "al", CODEC_ID_PCM_ALAW)
1256
1257 PCMDEF(mulaw, "PCM mu-law format",
1258        "ul", CODEC_ID_PCM_MULAW)