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