Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 63613fe6

History | View | Annotate | Download (30.7 KB)

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_ROQ_MUXER
35
static int roq_write_header(struct AVFormatContext *s)
36
{
37
    static const uint8_t header[] = {
38
        0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
39
    };
40

    
41
    put_buffer(s->pb, header, 8);
42
    put_flush_packet(s->pb);
43

    
44
    return 0;
45
}
46
#endif
47

    
48
#if CONFIG_NULL_MUXER
49
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
50
{
51
    return 0;
52
}
53
#endif
54

    
55
#if CONFIG_MUXERS
56
static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
57
{
58
    put_buffer(s->pb, pkt->data, pkt->size);
59
    put_flush_packet(s->pb);
60
    return 0;
61
}
62
#endif
63

    
64
#if CONFIG_DEMUXERS
65
/* raw input */
66
static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
67
{
68
    AVStream *st;
69
    int id;
70

    
71
    st = av_new_stream(s, 0);
72
    if (!st)
73
        return AVERROR(ENOMEM);
74

    
75
        id = s->iformat->value;
76
        if (id == CODEC_ID_RAWVIDEO) {
77
            st->codec->codec_type = CODEC_TYPE_VIDEO;
78
        } else {
79
            st->codec->codec_type = CODEC_TYPE_AUDIO;
80
        }
81
        st->codec->codec_id = id;
82

    
83
        switch(st->codec->codec_type) {
84
        case CODEC_TYPE_AUDIO:
85
            st->codec->sample_rate = ap->sample_rate;
86
            if(ap->channels) st->codec->channels = ap->channels;
87
            else             st->codec->channels = 1;
88
            st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
89
            assert(st->codec->bits_per_coded_sample > 0);
90
            st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
91
            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
92
            break;
93
        case CODEC_TYPE_VIDEO:
94
            if(ap->time_base.num)
95
                av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
96
            else
97
                av_set_pts_info(st, 64, 1, 25);
98
            st->codec->width = ap->width;
99
            st->codec->height = ap->height;
100
            st->codec->pix_fmt = ap->pix_fmt;
101
            if(st->codec->pix_fmt == PIX_FMT_NONE)
102
                st->codec->pix_fmt= PIX_FMT_YUV420P;
103
            break;
104
        default:
105
            return -1;
106
        }
107
    return 0;
108
}
109

    
110
#define RAW_PACKET_SIZE 1024
111
#define RAW_SAMPLES     1024
112

    
113
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
114
{
115
    int ret, size, bps;
116
    //    AVStream *st = s->streams[0];
117

    
118
    size= RAW_SAMPLES*s->streams[0]->codec->block_align;
119

    
120
    ret= av_get_packet(s->pb, pkt, size);
121

    
122
    pkt->stream_index = 0;
123
    if (ret <= 0) {
124
        return AVERROR(EIO);
125
    }
126
    /* note: we need to modify the packet size here to handle the last
127
       packet */
128
    pkt->size = ret;
129

    
130
    bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
131
    assert(bps); // if false there IS a bug elsewhere (NOT in this function)
132
    pkt->dts=
133
    pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
134

    
135
    return ret;
136
}
137

    
138
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
139
{
140
    int ret, size;
141

    
142
    size = RAW_PACKET_SIZE;
143

    
144
    if (av_new_packet(pkt, size) < 0)
145
        return AVERROR(EIO);
146

    
147
    pkt->pos= url_ftell(s->pb);
148
    pkt->stream_index = 0;
149
    ret = get_partial_buffer(s->pb, pkt->data, size);
150
    if (ret <= 0) {
151
        av_free_packet(pkt);
152
        return AVERROR(EIO);
153
    }
154
    pkt->size = ret;
155
    return ret;
156
}
157
#endif
158

    
159
#if CONFIG_RAWVIDEO_DEMUXER
160
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
161
{
162
    int packet_size, ret, width, height;
163
    AVStream *st = s->streams[0];
164

    
165
    width = st->codec->width;
166
    height = st->codec->height;
167

    
168
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
169
    if (packet_size < 0)
170
        return -1;
171

    
172
    ret= av_get_packet(s->pb, pkt, packet_size);
173
    pkt->pts=
174
    pkt->dts= pkt->pos / packet_size;
175

    
176
    pkt->stream_index = 0;
177
    if (ret != packet_size) {
178
        return AVERROR(EIO);
179
    } else {
180
        return 0;
181
    }
182
}
183
#endif
184

    
185
#if CONFIG_INGENIENT_DEMUXER
186
// http://www.artificis.hu/files/texts/ingenient.txt
187
static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
188
{
189
    int ret, size, w, h, unk1, unk2;
190

    
191
    if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
192
        return AVERROR(EIO); // FIXME
193

    
194
    size = get_le32(s->pb);
195

    
196
    w = get_le16(s->pb);
197
    h = get_le16(s->pb);
198

    
199
    url_fskip(s->pb, 8); // zero + size (padded?)
200
    url_fskip(s->pb, 2);
201
    unk1 = get_le16(s->pb);
202
    unk2 = get_le16(s->pb);
203
    url_fskip(s->pb, 22); // ASCII timestamp
204

    
205
    av_log(s, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
206
        size, w, h, unk1, unk2);
207

    
208
    if (av_new_packet(pkt, size) < 0)
209
        return AVERROR(EIO);
210

    
211
    pkt->pos = url_ftell(s->pb);
212
    pkt->stream_index = 0;
213
    ret = get_buffer(s->pb, pkt->data, size);
214
    if (ret <= 0) {
215
        av_free_packet(pkt);
216
        return AVERROR(EIO);
217
    }
218
    pkt->size = ret;
219
    return ret;
220
}
221
#endif
222

    
223
#if CONFIG_DEMUXERS
224
int pcm_read_seek(AVFormatContext *s,
225
                  int stream_index, int64_t timestamp, int flags)
226
{
227
    AVStream *st;
228
    int block_align, byte_rate, ret;
229
    int64_t pos;
230

    
231
    st = s->streams[0];
232

    
233
    block_align = st->codec->block_align ? st->codec->block_align :
234
        (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
235
    byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
236
        block_align * st->codec->sample_rate;
237

    
238
    if (block_align <= 0 || byte_rate <= 0)
239
        return -1;
240
    if (timestamp < 0) timestamp = 0;
241

    
242
    /* compute the position by aligning it to block_align */
243
    pos = av_rescale_rnd(timestamp * byte_rate,
244
                         st->time_base.num,
245
                         st->time_base.den * (int64_t)block_align,
246
                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
247
    pos *= block_align;
248

    
249
    /* recompute exact position */
250
    st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
251
    if ((ret = url_fseek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
252
        return ret;
253
    return 0;
254
}
255

    
256
static int audio_read_header(AVFormatContext *s,
257
                             AVFormatParameters *ap)
258
{
259
    AVStream *st = av_new_stream(s, 0);
260
    if (!st)
261
        return AVERROR(ENOMEM);
262
    st->codec->codec_type = CODEC_TYPE_AUDIO;
263
    st->codec->codec_id = s->iformat->value;
264
    st->need_parsing = AVSTREAM_PARSE_FULL;
265
    /* the parameters will be extracted from the compressed bitstream */
266

    
267
    return 0;
268
}
269

    
270
/* MPEG-1/H.263 input */
271
static int video_read_header(AVFormatContext *s,
272
                             AVFormatParameters *ap)
273
{
274
    AVStream *st;
275

    
276
    st = av_new_stream(s, 0);
277
    if (!st)
278
        return AVERROR(ENOMEM);
279

    
280
    st->codec->codec_type = CODEC_TYPE_VIDEO;
281
    st->codec->codec_id = s->iformat->value;
282
    st->need_parsing = AVSTREAM_PARSE_FULL;
283

    
284
    /* for MJPEG, specify frame rate */
285
    /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
286
    if (ap->time_base.num) {
287
        st->codec->time_base= ap->time_base;
288
    } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
289
                st->codec->codec_id == CODEC_ID_MPEG4 ||
290
                st->codec->codec_id == CODEC_ID_DIRAC ||
291
                st->codec->codec_id == CODEC_ID_H264) {
292
        st->codec->time_base= (AVRational){1,25};
293
    }
294
    av_set_pts_info(st, 64, 1, 1200000);
295

    
296
    return 0;
297
}
298
#endif
299

    
300
#if CONFIG_MPEGVIDEO_DEMUXER
301
#define SEQ_START_CODE          0x000001b3
302
#define GOP_START_CODE          0x000001b8
303
#define PICTURE_START_CODE      0x00000100
304
#define SLICE_START_CODE        0x00000101
305
#define PACK_START_CODE         0x000001ba
306
#define VIDEO_ID                0x000001e0
307
#define AUDIO_ID                0x000001c0
308

    
309
static int mpegvideo_probe(AVProbeData *p)
310
{
311
    uint32_t code= -1;
312
    int pic=0, seq=0, slice=0, pspack=0, pes=0;
313
    int i;
314

    
315
    for(i=0; i<p->buf_size; i++){
316
        code = (code<<8) + p->buf[i];
317
        if ((code & 0xffffff00) == 0x100) {
318
            switch(code){
319
            case     SEQ_START_CODE:   seq++; break;
320
            case PICTURE_START_CODE:   pic++; break;
321
            case   SLICE_START_CODE: slice++; break;
322
            case    PACK_START_CODE: pspack++; break;
323
            }
324
            if     ((code & 0x1f0) == VIDEO_ID)   pes++;
325
            else if((code & 0x1e0) == AUDIO_ID)   pes++;
326
        }
327
    }
328
    if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
329
        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
330
    return 0;
331
}
332
#endif
333

    
334
#if CONFIG_CAVSVIDEO_DEMUXER
335
#define CAVS_SEQ_START_CODE       0x000001b0
336
#define CAVS_PIC_I_START_CODE     0x000001b3
337
#define CAVS_UNDEF_START_CODE     0x000001b4
338
#define CAVS_PIC_PB_START_CODE    0x000001b6
339
#define CAVS_VIDEO_EDIT_CODE      0x000001b7
340
#define CAVS_PROFILE_JIZHUN       0x20
341

    
342
static int cavsvideo_probe(AVProbeData *p)
343
{
344
    uint32_t code= -1;
345
    int pic=0, seq=0, slice_pos = 0;
346
    int i;
347

    
348
    for(i=0; i<p->buf_size; i++){
349
        code = (code<<8) + p->buf[i];
350
        if ((code & 0xffffff00) == 0x100) {
351
            if(code < CAVS_SEQ_START_CODE) {
352
                /* slices have to be consecutive */
353
                if(code < slice_pos)
354
                    return 0;
355
                slice_pos = code;
356
            } else {
357
                slice_pos = 0;
358
            }
359
            if (code == CAVS_SEQ_START_CODE) {
360
                seq++;
361
                /* check for the only currently supported profile */
362
                if(p->buf[i+1] != CAVS_PROFILE_JIZHUN)
363
                    return 0;
364
            } else if ((code == CAVS_PIC_I_START_CODE) ||
365
                       (code == CAVS_PIC_PB_START_CODE)) {
366
                pic++;
367
            } else if ((code == CAVS_UNDEF_START_CODE) ||
368
                       (code >  CAVS_VIDEO_EDIT_CODE)) {
369
                return 0;
370
            }
371
        }
372
    }
373
    if(seq && seq*9<=pic*10)
374
        return AVPROBE_SCORE_MAX/2;
375
    return 0;
376
}
377
#endif
378

    
379
#if CONFIG_M4V_DEMUXER
380
#define VISUAL_OBJECT_START_CODE       0x000001b5
381
#define VOP_START_CODE                 0x000001b6
382

    
383
static int mpeg4video_probe(AVProbeData *probe_packet)
384
{
385
    uint32_t temp_buffer= -1;
386
    int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
387
    int i;
388

    
389
    for(i=0; i<probe_packet->buf_size; i++){
390
        temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
391
        if ((temp_buffer & 0xffffff00) != 0x100)
392
            continue;
393

    
394
        if (temp_buffer == VOP_START_CODE)                         VOP++;
395
        else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
396
        else if (temp_buffer < 0x120)                              VO++;
397
        else if (temp_buffer < 0x130)                              VOL++;
398
        else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
399
                 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
400
    }
401

    
402
    if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
403
        return AVPROBE_SCORE_MAX/2;
404
    return 0;
405
}
406
#endif
407

    
408
#if CONFIG_H264_DEMUXER
409
static int h264_probe(AVProbeData *p)
410
{
411
    uint32_t code= -1;
412
    int sps=0, pps=0, idr=0, res=0, sli=0;
413
    int i;
414

    
415
    for(i=0; i<p->buf_size; i++){
416
        code = (code<<8) + p->buf[i];
417
        if ((code & 0xffffff00) == 0x100) {
418
            int ref_idc= (code>>5)&3;
419
            int type   = code & 0x1F;
420
            static const int8_t ref_zero[32]={
421
                2, 0, 0, 0, 0,-1, 1,-1,
422
               -1, 1, 1, 1, 1,-1, 2, 2,
423
                2, 2, 2, 0, 2, 2, 2, 2,
424
                2, 2, 2, 2, 2, 2, 2, 2
425
            };
426

    
427
            if(code & 0x80) //forbidden bit
428
                return 0;
429

    
430
            if(ref_zero[type] == 1 && ref_idc)
431
                return 0;
432
            if(ref_zero[type] ==-1 && !ref_idc)
433
                return 0;
434
            if(ref_zero[type] == 2)
435
                res++;
436

    
437
            switch(type){
438
            case     1:   sli++; break;
439
            case     5:   idr++; break;
440
            case     7:
441
                if(p->buf[i+2]&0x0F)
442
                    return 0;
443
                sps++;
444
                break;
445
            case     8:   pps++; break;
446
            }
447
        }
448
    }
449
    if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
450
        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
451
    return 0;
452
}
453
#endif
454

    
455
#if CONFIG_H263_DEMUXER
456
static int h263_probe(AVProbeData *p)
457
{
458
    int code;
459
    const uint8_t *d;
460

    
461
    d = p->buf;
462
    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
463
    if (code == 0x20) {
464
        return 50;
465
    }
466
    return 0;
467
}
468
#endif
469

    
470
#if CONFIG_H261_DEMUXER
471
static int h261_probe(AVProbeData *p)
472
{
473
    int code;
474
    const uint8_t *d;
475

    
476
    d = p->buf;
477
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
478
    if (code == 0x10) {
479
        return 50;
480
    }
481
    return 0;
482
}
483
#endif
484

    
485
#if CONFIG_DTS_DEMUXER
486
#define DCA_MARKER_14B_BE 0x1FFFE800
487
#define DCA_MARKER_14B_LE 0xFF1F00E8
488
#define DCA_MARKER_RAW_BE 0x7FFE8001
489
#define DCA_MARKER_RAW_LE 0xFE7F0180
490
static int dts_probe(AVProbeData *p)
491
{
492
    const uint8_t *buf, *bufp;
493
    uint32_t state = -1;
494

    
495
    buf = p->buf;
496

    
497
    for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
498
        bufp = buf;
499
        state = (state << 16) | bytestream_get_be16(&bufp);
500

    
501
        /* regular bitstream */
502
        if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
503
            return AVPROBE_SCORE_MAX/2+1;
504

    
505
        /* 14 bits big-endian bitstream */
506
        if (state == DCA_MARKER_14B_BE)
507
            if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
508
                return AVPROBE_SCORE_MAX/2+1;
509

    
510
        /* 14 bits little-endian bitstream */
511
        if (state == DCA_MARKER_14B_LE)
512
            if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
513
                return AVPROBE_SCORE_MAX/2+1;
514
    }
515

    
516
    return 0;
517
}
518
#endif
519

    
520
#if CONFIG_DIRAC_DEMUXER
521
static int dirac_probe(AVProbeData *p)
522
{
523
    if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
524
        return AVPROBE_SCORE_MAX;
525
    else
526
        return 0;
527
}
528
#endif
529

    
530
#if CONFIG_DNXHD_DEMUXER
531
static int dnxhd_probe(AVProbeData *p)
532
{
533
    static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01};
534
    if (!memcmp(p->buf, header, 5))
535
        return AVPROBE_SCORE_MAX;
536
    else
537
        return 0;
538
}
539
#endif
540

    
541
#if CONFIG_AC3_DEMUXER || CONFIG_EAC3_DEMUXER
542
static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
543
{
544
    int max_frames, first_frames = 0, frames;
545
    uint8_t *buf, *buf2, *end;
546
    AC3HeaderInfo hdr;
547
    GetBitContext gbc;
548
    enum CodecID codec_id = CODEC_ID_AC3;
549

    
550
    max_frames = 0;
551
    buf = p->buf;
552
    end = buf + p->buf_size;
553

    
554
    for(; buf < end; buf++) {
555
        buf2 = buf;
556

    
557
        for(frames = 0; buf2 < end; frames++) {
558
            init_get_bits(&gbc, buf2, 54);
559
            if(ff_ac3_parse_header(&gbc, &hdr) < 0)
560
                break;
561
            if(buf2 + hdr.frame_size > end ||
562
               av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
563
                break;
564
            if (hdr.bitstream_id > 10)
565
                codec_id = CODEC_ID_EAC3;
566
            buf2 += hdr.frame_size;
567
        }
568
        max_frames = FFMAX(max_frames, frames);
569
        if(buf == p->buf)
570
            first_frames = frames;
571
    }
572
    if(codec_id != expected_codec_id) return 0;
573
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
574
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
575
    else if(max_frames>=1) return 1;
576
    else                   return 0;
577
}
578
#endif
579

    
580
#if CONFIG_AC3_DEMUXER
581
static int ac3_probe(AVProbeData *p)
582
{
583
    return ac3_eac3_probe(p, CODEC_ID_AC3);
584
}
585
#endif
586

    
587
#if CONFIG_EAC3_DEMUXER
588
static int eac3_probe(AVProbeData *p)
589
{
590
    return ac3_eac3_probe(p, CODEC_ID_EAC3);
591
}
592
#endif
593

    
594
#if CONFIG_AAC_DEMUXER
595
static int adts_aac_probe(AVProbeData *p)
596
{
597
    int max_frames = 0, first_frames = 0;
598
    int fsize, frames;
599
    uint8_t *buf0 = p->buf;
600
    uint8_t *buf2;
601
    uint8_t *buf;
602
    uint8_t *end = buf0 + p->buf_size - 7;
603

    
604
    if (ff_id3v2_match(buf0)) {
605
        buf0 += ff_id3v2_tag_len(buf0);
606
    }
607
    buf = buf0;
608

    
609
    for(; buf < end; buf= buf2+1) {
610
        buf2 = buf;
611

    
612
        for(frames = 0; buf2 < end; frames++) {
613
            uint32_t header = AV_RB16(buf2);
614
            if((header&0xFFF6) != 0xFFF0)
615
                break;
616
            fsize = (AV_RB32(buf2+3)>>13) & 0x8FFF;
617
            if(fsize < 7)
618
                break;
619
            buf2 += fsize;
620
        }
621
        max_frames = FFMAX(max_frames, frames);
622
        if(buf == buf0)
623
            first_frames= frames;
624
    }
625
    if   (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
626
    else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
627
    else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
628
    else if(max_frames>=1) return 1;
629
    else                   return 0;
630
}
631

    
632
static int adts_aac_read_header(AVFormatContext *s,
633
                                AVFormatParameters *ap)
634
{
635
    AVStream *st;
636

    
637
    st = av_new_stream(s, 0);
638
    if (!st)
639
        return AVERROR(ENOMEM);
640

    
641
    st->codec->codec_type = CODEC_TYPE_AUDIO;
642
    st->codec->codec_id = s->iformat->value;
643
    st->need_parsing = AVSTREAM_PARSE_FULL;
644

    
645
    ff_id3v1_read(s);
646
    ff_id3v2_read(s);
647

    
648
    return 0;
649
}
650

    
651
#endif
652

    
653
/* Note: Do not forget to add new entries to the Makefile as well. */
654

    
655
#if CONFIG_AAC_DEMUXER
656
AVInputFormat aac_demuxer = {
657
    "aac",
658
    NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
659
    0,
660
    adts_aac_probe,
661
    adts_aac_read_header,
662
    ff_raw_read_partial_packet,
663
    .flags= AVFMT_GENERIC_INDEX,
664
    .extensions = "aac",
665
    .value = CODEC_ID_AAC,
666
};
667
#endif
668

    
669
#if CONFIG_AC3_DEMUXER
670
AVInputFormat ac3_demuxer = {
671
    "ac3",
672
    NULL_IF_CONFIG_SMALL("raw AC-3"),
673
    0,
674
    ac3_probe,
675
    audio_read_header,
676
    ff_raw_read_partial_packet,
677
    .flags= AVFMT_GENERIC_INDEX,
678
    .extensions = "ac3",
679
    .value = CODEC_ID_AC3,
680
};
681
#endif
682

    
683
#if CONFIG_AC3_MUXER
684
AVOutputFormat ac3_muxer = {
685
    "ac3",
686
    NULL_IF_CONFIG_SMALL("raw AC-3"),
687
    "audio/x-ac3",
688
    "ac3",
689
    0,
690
    CODEC_ID_AC3,
691
    CODEC_ID_NONE,
692
    NULL,
693
    raw_write_packet,
694
    .flags= AVFMT_NOTIMESTAMPS,
695
};
696
#endif
697

    
698
#if CONFIG_DIRAC_DEMUXER
699
AVInputFormat dirac_demuxer = {
700
    "dirac",
701
    NULL_IF_CONFIG_SMALL("raw Dirac"),
702
    0,
703
    dirac_probe,
704
    video_read_header,
705
    ff_raw_read_partial_packet,
706
    .flags= AVFMT_GENERIC_INDEX,
707
    .value = CODEC_ID_DIRAC,
708
};
709
#endif
710

    
711
#if CONFIG_DIRAC_MUXER
712
AVOutputFormat dirac_muxer = {
713
    "dirac",
714
    NULL_IF_CONFIG_SMALL("raw Dirac"),
715
    NULL,
716
    "drc",
717
    0,
718
    CODEC_ID_NONE,
719
    CODEC_ID_DIRAC,
720
    NULL,
721
    raw_write_packet,
722
    .flags= AVFMT_NOTIMESTAMPS,
723
};
724
#endif
725

    
726
#if CONFIG_DNXHD_DEMUXER
727
AVInputFormat dnxhd_demuxer = {
728
    "dnxhd",
729
    NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
730
    0,
731
    dnxhd_probe,
732
    video_read_header,
733
    ff_raw_read_partial_packet,
734
    .flags= AVFMT_GENERIC_INDEX,
735
    .value = CODEC_ID_DNXHD,
736
};
737
#endif
738

    
739
#if CONFIG_DNXHD_MUXER
740
AVOutputFormat dnxhd_muxer = {
741
    "dnxhd",
742
    NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
743
    NULL,
744
    "dnxhd",
745
    0,
746
    CODEC_ID_NONE,
747
    CODEC_ID_DNXHD,
748
    NULL,
749
    raw_write_packet,
750
    .flags= AVFMT_NOTIMESTAMPS,
751
};
752
#endif
753

    
754
#if CONFIG_DTS_DEMUXER
755
AVInputFormat dts_demuxer = {
756
    "dts",
757
    NULL_IF_CONFIG_SMALL("raw DTS"),
758
    0,
759
    dts_probe,
760
    audio_read_header,
761
    ff_raw_read_partial_packet,
762
    .flags= AVFMT_GENERIC_INDEX,
763
    .extensions = "dts",
764
    .value = CODEC_ID_DTS,
765
};
766
#endif
767

    
768
#if CONFIG_DTS_MUXER
769
AVOutputFormat dts_muxer = {
770
    "dts",
771
    NULL_IF_CONFIG_SMALL("raw DTS"),
772
    "audio/x-dca",
773
    "dts",
774
    0,
775
    CODEC_ID_DTS,
776
    CODEC_ID_NONE,
777
    NULL,
778
    raw_write_packet,
779
    .flags= AVFMT_NOTIMESTAMPS,
780
};
781
#endif
782

    
783
#if CONFIG_EAC3_DEMUXER
784
AVInputFormat eac3_demuxer = {
785
    "eac3",
786
    NULL_IF_CONFIG_SMALL("raw E-AC-3"),
787
    0,
788
    eac3_probe,
789
    audio_read_header,
790
    ff_raw_read_partial_packet,
791
    .flags= AVFMT_GENERIC_INDEX,
792
    .extensions = "eac3",
793
    .value = CODEC_ID_EAC3,
794
};
795
#endif
796

    
797
#if CONFIG_EAC3_MUXER
798
AVOutputFormat eac3_muxer = {
799
    "eac3",
800
    NULL_IF_CONFIG_SMALL("raw E-AC-3"),
801
    "audio/x-eac3",
802
    "eac3",
803
    0,
804
    CODEC_ID_EAC3,
805
    CODEC_ID_NONE,
806
    NULL,
807
    raw_write_packet,
808
    .flags= AVFMT_NOTIMESTAMPS,
809
};
810
#endif
811

    
812
#if CONFIG_GSM_DEMUXER
813
AVInputFormat gsm_demuxer = {
814
    "gsm",
815
    NULL_IF_CONFIG_SMALL("raw GSM"),
816
    0,
817
    NULL,
818
    audio_read_header,
819
    ff_raw_read_partial_packet,
820
    .flags= AVFMT_GENERIC_INDEX,
821
    .extensions = "gsm",
822
    .value = CODEC_ID_GSM,
823
};
824
#endif
825

    
826
#if CONFIG_H261_DEMUXER
827
AVInputFormat h261_demuxer = {
828
    "h261",
829
    NULL_IF_CONFIG_SMALL("raw H.261"),
830
    0,
831
    h261_probe,
832
    video_read_header,
833
    ff_raw_read_partial_packet,
834
    .flags= AVFMT_GENERIC_INDEX,
835
    .extensions = "h261",
836
    .value = CODEC_ID_H261,
837
};
838
#endif
839

    
840
#if CONFIG_H261_MUXER
841
AVOutputFormat h261_muxer = {
842
    "h261",
843
    NULL_IF_CONFIG_SMALL("raw H.261"),
844
    "video/x-h261",
845
    "h261",
846
    0,
847
    CODEC_ID_NONE,
848
    CODEC_ID_H261,
849
    NULL,
850
    raw_write_packet,
851
    .flags= AVFMT_NOTIMESTAMPS,
852
};
853
#endif
854

    
855
#if CONFIG_H263_DEMUXER
856
AVInputFormat h263_demuxer = {
857
    "h263",
858
    NULL_IF_CONFIG_SMALL("raw H.263"),
859
    0,
860
    h263_probe,
861
    video_read_header,
862
    ff_raw_read_partial_packet,
863
    .flags= AVFMT_GENERIC_INDEX,
864
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
865
    .value = CODEC_ID_H263,
866
};
867
#endif
868

    
869
#if CONFIG_H263_MUXER
870
AVOutputFormat h263_muxer = {
871
    "h263",
872
    NULL_IF_CONFIG_SMALL("raw H.263"),
873
    "video/x-h263",
874
    "h263",
875
    0,
876
    CODEC_ID_NONE,
877
    CODEC_ID_H263,
878
    NULL,
879
    raw_write_packet,
880
    .flags= AVFMT_NOTIMESTAMPS,
881
};
882
#endif
883

    
884
#if CONFIG_H264_DEMUXER
885
AVInputFormat h264_demuxer = {
886
    "h264",
887
    NULL_IF_CONFIG_SMALL("raw H.264 video format"),
888
    0,
889
    h264_probe,
890
    video_read_header,
891
    ff_raw_read_partial_packet,
892
    .flags= AVFMT_GENERIC_INDEX,
893
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
894
    .value = CODEC_ID_H264,
895
};
896
#endif
897

    
898
#if CONFIG_H264_MUXER
899
AVOutputFormat h264_muxer = {
900
    "h264",
901
    NULL_IF_CONFIG_SMALL("raw H.264 video format"),
902
    NULL,
903
    "h264",
904
    0,
905
    CODEC_ID_NONE,
906
    CODEC_ID_H264,
907
    NULL,
908
    raw_write_packet,
909
    .flags= AVFMT_NOTIMESTAMPS,
910
};
911
#endif
912

    
913
#if CONFIG_INGENIENT_DEMUXER
914
AVInputFormat ingenient_demuxer = {
915
    "ingenient",
916
    NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"),
917
    0,
918
    NULL,
919
    video_read_header,
920
    ingenient_read_packet,
921
    .flags= AVFMT_GENERIC_INDEX,
922
    .extensions = "cgi", // FIXME
923
    .value = CODEC_ID_MJPEG,
924
};
925
#endif
926

    
927
#if CONFIG_M4V_DEMUXER
928
AVInputFormat m4v_demuxer = {
929
    "m4v",
930
    NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
931
    0,
932
    mpeg4video_probe, /** probing for MPEG-4 data */
933
    video_read_header,
934
    ff_raw_read_partial_packet,
935
    .flags= AVFMT_GENERIC_INDEX,
936
    .extensions = "m4v",
937
    .value = CODEC_ID_MPEG4,
938
};
939
#endif
940

    
941
#if CONFIG_M4V_MUXER
942
AVOutputFormat m4v_muxer = {
943
    "m4v",
944
    NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
945
    NULL,
946
    "m4v",
947
    0,
948
    CODEC_ID_NONE,
949
    CODEC_ID_MPEG4,
950
    NULL,
951
    raw_write_packet,
952
    .flags= AVFMT_NOTIMESTAMPS,
953
};
954
#endif
955

    
956
#if CONFIG_MJPEG_DEMUXER
957
AVInputFormat mjpeg_demuxer = {
958
    "mjpeg",
959
    NULL_IF_CONFIG_SMALL("raw MJPEG video"),
960
    0,
961
    NULL,
962
    video_read_header,
963
    ff_raw_read_partial_packet,
964
    .flags= AVFMT_GENERIC_INDEX,
965
    .extensions = "mjpg,mjpeg",
966
    .value = CODEC_ID_MJPEG,
967
};
968
#endif
969

    
970
#if CONFIG_MJPEG_MUXER
971
AVOutputFormat mjpeg_muxer = {
972
    "mjpeg",
973
    NULL_IF_CONFIG_SMALL("raw MJPEG video"),
974
    "video/x-mjpeg",
975
    "mjpg,mjpeg",
976
    0,
977
    CODEC_ID_NONE,
978
    CODEC_ID_MJPEG,
979
    NULL,
980
    raw_write_packet,
981
    .flags= AVFMT_NOTIMESTAMPS,
982
};
983
#endif
984

    
985
#if CONFIG_MLP_DEMUXER
986
AVInputFormat mlp_demuxer = {
987
    "mlp",
988
    NULL_IF_CONFIG_SMALL("raw MLP"),
989
    0,
990
    NULL,
991
    audio_read_header,
992
    ff_raw_read_partial_packet,
993
    .flags= AVFMT_GENERIC_INDEX,
994
    .extensions = "mlp",
995
    .value = CODEC_ID_MLP,
996
};
997
#endif
998

    
999
#if CONFIG_MLP_MUXER
1000
AVOutputFormat mlp_muxer = {
1001
    "mlp",
1002
    NULL_IF_CONFIG_SMALL("raw MLP"),
1003
    NULL,
1004
    "mlp",
1005
    0,
1006
    CODEC_ID_MLP,
1007
    CODEC_ID_NONE,
1008
    NULL,
1009
    raw_write_packet,
1010
    .flags= AVFMT_NOTIMESTAMPS,
1011
};
1012
#endif
1013

    
1014
#if CONFIG_TRUEHD_DEMUXER
1015
AVInputFormat truehd_demuxer = {
1016
    "truehd",
1017
    NULL_IF_CONFIG_SMALL("raw TrueHD"),
1018
    0,
1019
    NULL,
1020
    audio_read_header,
1021
    ff_raw_read_partial_packet,
1022
    .flags= AVFMT_GENERIC_INDEX,
1023
    .extensions = "thd",
1024
    .value = CODEC_ID_TRUEHD,
1025
};
1026
#endif
1027

    
1028
#if CONFIG_TRUEHD_MUXER
1029
AVOutputFormat truehd_muxer = {
1030
    "truehd",
1031
    NULL_IF_CONFIG_SMALL("raw TrueHD"),
1032
    NULL,
1033
    "thd",
1034
    0,
1035
    CODEC_ID_TRUEHD,
1036
    CODEC_ID_NONE,
1037
    NULL,
1038
    raw_write_packet,
1039
    .flags= AVFMT_NOTIMESTAMPS,
1040
};
1041
#endif
1042

    
1043
#if CONFIG_MPEG1VIDEO_MUXER
1044
AVOutputFormat mpeg1video_muxer = {
1045
    "mpeg1video",
1046
    NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
1047
    "video/x-mpeg",
1048
    "mpg,mpeg,m1v",
1049
    0,
1050
    CODEC_ID_NONE,
1051
    CODEC_ID_MPEG1VIDEO,
1052
    NULL,
1053
    raw_write_packet,
1054
    .flags= AVFMT_NOTIMESTAMPS,
1055
};
1056
#endif
1057

    
1058
#if CONFIG_MPEG2VIDEO_MUXER
1059
AVOutputFormat mpeg2video_muxer = {
1060
    "mpeg2video",
1061
    NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
1062
    NULL,
1063
    "m2v",
1064
    0,
1065
    CODEC_ID_NONE,
1066
    CODEC_ID_MPEG2VIDEO,
1067
    NULL,
1068
    raw_write_packet,
1069
    .flags= AVFMT_NOTIMESTAMPS,
1070
};
1071
#endif
1072

    
1073
#if CONFIG_MPEGVIDEO_DEMUXER
1074
AVInputFormat mpegvideo_demuxer = {
1075
    "mpegvideo",
1076
    NULL_IF_CONFIG_SMALL("raw MPEG video"),
1077
    0,
1078
    mpegvideo_probe,
1079
    video_read_header,
1080
    ff_raw_read_partial_packet,
1081
    .flags= AVFMT_GENERIC_INDEX,
1082
    .value = CODEC_ID_MPEG1VIDEO,
1083
};
1084
#endif
1085

    
1086
#if CONFIG_CAVSVIDEO_DEMUXER
1087
AVInputFormat cavsvideo_demuxer = {
1088
    "cavsvideo",
1089
    NULL_IF_CONFIG_SMALL("raw Chinese AVS video"),
1090
    0,
1091
    cavsvideo_probe,
1092
    video_read_header,
1093
    ff_raw_read_partial_packet,
1094
    .flags= AVFMT_GENERIC_INDEX,
1095
    .value = CODEC_ID_CAVS,
1096
};
1097
#endif
1098

    
1099
#if CONFIG_NULL_MUXER
1100
AVOutputFormat null_muxer = {
1101
    "null",
1102
    NULL_IF_CONFIG_SMALL("raw null video format"),
1103
    NULL,
1104
    NULL,
1105
    0,
1106
#if HAVE_BIGENDIAN
1107
    CODEC_ID_PCM_S16BE,
1108
#else
1109
    CODEC_ID_PCM_S16LE,
1110
#endif
1111
    CODEC_ID_RAWVIDEO,
1112
    NULL,
1113
    null_write_packet,
1114
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
1115
};
1116
#endif
1117

    
1118
#if CONFIG_RAWVIDEO_DEMUXER
1119
AVInputFormat rawvideo_demuxer = {
1120
    "rawvideo",
1121
    NULL_IF_CONFIG_SMALL("raw video format"),
1122
    0,
1123
    NULL,
1124
    raw_read_header,
1125
    rawvideo_read_packet,
1126
    .flags= AVFMT_GENERIC_INDEX,
1127
    .extensions = "yuv,cif,qcif,rgb",
1128
    .value = CODEC_ID_RAWVIDEO,
1129
};
1130
#endif
1131

    
1132
#if CONFIG_RAWVIDEO_MUXER
1133
AVOutputFormat rawvideo_muxer = {
1134
    "rawvideo",
1135
    NULL_IF_CONFIG_SMALL("raw video format"),
1136
    NULL,
1137
    "yuv,rgb",
1138
    0,
1139
    CODEC_ID_NONE,
1140
    CODEC_ID_RAWVIDEO,
1141
    NULL,
1142
    raw_write_packet,
1143
    .flags= AVFMT_NOTIMESTAMPS,
1144
};
1145
#endif
1146

    
1147
#if CONFIG_ROQ_MUXER
1148
AVOutputFormat roq_muxer =
1149
{
1150
    "RoQ",
1151
    NULL_IF_CONFIG_SMALL("raw id RoQ format"),
1152
    NULL,
1153
    "roq",
1154
    0,
1155
    CODEC_ID_ROQ_DPCM,
1156
    CODEC_ID_ROQ,
1157
    roq_write_header,
1158
    raw_write_packet,
1159
};
1160
#endif
1161

    
1162
#if CONFIG_SHORTEN_DEMUXER
1163
AVInputFormat shorten_demuxer = {
1164
    "shn",
1165
    NULL_IF_CONFIG_SMALL("raw Shorten"),
1166
    0,
1167
    NULL,
1168
    audio_read_header,
1169
    ff_raw_read_partial_packet,
1170
    .flags= AVFMT_GENERIC_INDEX,
1171
    .extensions = "shn",
1172
    .value = CODEC_ID_SHORTEN,
1173
};
1174
#endif
1175

    
1176
#if CONFIG_VC1_DEMUXER
1177
AVInputFormat vc1_demuxer = {
1178
    "vc1",
1179
    NULL_IF_CONFIG_SMALL("raw VC-1"),
1180
    0,
1181
    NULL /* vc1_probe */,
1182
    video_read_header,
1183
    ff_raw_read_partial_packet,
1184
    .extensions = "vc1",
1185
    .value = CODEC_ID_VC1,
1186
};
1187
#endif
1188

    
1189
/* PCM formats */
1190

    
1191
#define PCMINPUTDEF(name, long_name, ext, codec) \
1192
AVInputFormat pcm_ ## name ## _demuxer = {\
1193
    #name,\
1194
    NULL_IF_CONFIG_SMALL(long_name),\
1195
    0,\
1196
    NULL,\
1197
    raw_read_header,\
1198
    raw_read_packet,\
1199
    NULL,\
1200
    pcm_read_seek,\
1201
    .flags= AVFMT_GENERIC_INDEX,\
1202
    .extensions = ext,\
1203
    .value = codec,\
1204
};
1205

    
1206
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
1207
AVOutputFormat pcm_ ## name ## _muxer = {\
1208
    #name,\
1209
    NULL_IF_CONFIG_SMALL(long_name),\
1210
    NULL,\
1211
    ext,\
1212
    0,\
1213
    codec,\
1214
    CODEC_ID_NONE,\
1215
    NULL,\
1216
    raw_write_packet,\
1217
    .flags= AVFMT_NOTIMESTAMPS,\
1218
};
1219

    
1220

    
1221
#if  !CONFIG_MUXERS && CONFIG_DEMUXERS
1222
#define PCMDEF(name, long_name, ext, codec) \
1223
        PCMINPUTDEF(name, long_name, ext, codec)
1224
#elif CONFIG_MUXERS && !CONFIG_DEMUXERS
1225
#define PCMDEF(name, long_name, ext, codec) \
1226
        PCMOUTPUTDEF(name, long_name, ext, codec)
1227
#elif CONFIG_MUXERS && CONFIG_DEMUXERS
1228
#define PCMDEF(name, long_name, ext, codec) \
1229
        PCMINPUTDEF(name, long_name, ext, codec)\
1230
        PCMOUTPUTDEF(name, long_name, ext, codec)
1231
#else
1232
#define PCMDEF(name, long_name, ext, codec)
1233
#endif
1234

    
1235
#if HAVE_BIGENDIAN
1236
#define BE_DEF(s) s
1237
#define LE_DEF(s) NULL
1238
#else
1239
#define BE_DEF(s) NULL
1240
#define LE_DEF(s) s
1241
#endif
1242

    
1243
PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
1244
       NULL, CODEC_ID_PCM_F64BE)
1245

    
1246
PCMDEF(f64le, "PCM 64 bit floating-point little-endian format",
1247
       NULL, CODEC_ID_PCM_F64LE)
1248

    
1249
PCMDEF(f32be, "PCM 32 bit floating-point big-endian format",
1250
       NULL, CODEC_ID_PCM_F32BE)
1251

    
1252
PCMDEF(f32le, "PCM 32 bit floating-point little-endian format",
1253
       NULL, CODEC_ID_PCM_F32LE)
1254

    
1255
PCMDEF(s32be, "PCM signed 32 bit big-endian format",
1256
       NULL, CODEC_ID_PCM_S32BE)
1257

    
1258
PCMDEF(s32le, "PCM signed 32 bit little-endian format",
1259
       NULL, CODEC_ID_PCM_S32LE)
1260

    
1261
PCMDEF(s24be, "PCM signed 24 bit big-endian format",
1262
       NULL, CODEC_ID_PCM_S24BE)
1263

    
1264
PCMDEF(s24le, "PCM signed 24 bit little-endian format",
1265
       NULL, CODEC_ID_PCM_S24LE)
1266

    
1267
PCMDEF(s16be, "PCM signed 16 bit big-endian format",
1268
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
1269

    
1270
PCMDEF(s16le, "PCM signed 16 bit little-endian format",
1271
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
1272

    
1273
PCMDEF(s8, "PCM signed 8 bit format",
1274
       "sb", CODEC_ID_PCM_S8)
1275

    
1276
PCMDEF(u32be, "PCM unsigned 32 bit big-endian format",
1277
       NULL, CODEC_ID_PCM_U32BE)
1278

    
1279
PCMDEF(u32le, "PCM unsigned 32 bit little-endian format",
1280
       NULL, CODEC_ID_PCM_U32LE)
1281

    
1282
PCMDEF(u24be, "PCM unsigned 24 bit big-endian format",
1283
       NULL, CODEC_ID_PCM_U24BE)
1284

    
1285
PCMDEF(u24le, "PCM unsigned 24 bit little-endian format",
1286
       NULL, CODEC_ID_PCM_U24LE)
1287

    
1288
PCMDEF(u16be, "PCM unsigned 16 bit big-endian format",
1289
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
1290

    
1291
PCMDEF(u16le, "PCM unsigned 16 bit little-endian format",
1292
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
1293

    
1294
PCMDEF(u8, "PCM unsigned 8 bit format",
1295
       "ub", CODEC_ID_PCM_U8)
1296

    
1297
PCMDEF(alaw, "PCM A-law format",
1298
       "al", CODEC_ID_PCM_ALAW)
1299

    
1300
PCMDEF(mulaw, "PCM mu-law format",
1301
       "ul", CODEC_ID_PCM_MULAW)