Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 16e861e3

History | View | Annotate | Download (22.3 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/bitstream.h"
26
#include "libavcodec/bytestream.h"
27
#include "avformat.h"
28
#include "raw.h"
29

    
30
#ifdef CONFIG_MUXERS
31
/* simple formats */
32
static int flac_write_header(struct AVFormatContext *s)
33
{
34
    static const uint8_t header[8] = {
35
        0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
36
    };
37
    uint8_t *streaminfo = s->streams[0]->codec->extradata;
38
    int len = s->streams[0]->codec->extradata_size;
39
    if(streaminfo != NULL && len > 0) {
40
        put_buffer(s->pb, header, 8);
41
        put_buffer(s->pb, streaminfo, len);
42
    }
43
    return 0;
44
}
45

    
46

    
47
static int roq_write_header(struct AVFormatContext *s)
48
{
49
    static const uint8_t header[] = {
50
        0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
51
    };
52

    
53
    put_buffer(s->pb, header, 8);
54
    put_flush_packet(s->pb);
55

    
56
    return 0;
57
}
58

    
59
static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
60
{
61
    put_buffer(s->pb, pkt->data, pkt->size);
62
    put_flush_packet(s->pb);
63
    return 0;
64
}
65
#endif //CONFIG_MUXERS
66

    
67
/* raw input */
68
static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
69
{
70
    AVStream *st;
71
    int id;
72

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

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

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

    
108
#define RAW_PACKET_SIZE 1024
109

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

    
115
    size= RAW_PACKET_SIZE;
116

    
117
    ret= av_get_packet(s->pb, pkt, size);
118

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

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

    
132
    return ret;
133
}
134

    
135
static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
136
{
137
    int ret, size;
138

    
139
    size = RAW_PACKET_SIZE;
140

    
141
    if (av_new_packet(pkt, size) < 0)
142
        return AVERROR(EIO);
143

    
144
    pkt->pos= url_ftell(s->pb);
145
    pkt->stream_index = 0;
146
    ret = get_partial_buffer(s->pb, pkt->data, size);
147
    if (ret <= 0) {
148
        av_free_packet(pkt);
149
        return AVERROR(EIO);
150
    }
151
    pkt->size = ret;
152
    return ret;
153
}
154

    
155
// http://www.artificis.hu/files/texts/ingenient.txt
156
static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
157
{
158
    int ret, size, w, h, unk1, unk2;
159

    
160
    if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
161
        return AVERROR(EIO); // FIXME
162

    
163
    size = get_le32(s->pb);
164

    
165
    w = get_le16(s->pb);
166
    h = get_le16(s->pb);
167

    
168
    url_fskip(s->pb, 8); // zero + size (padded?)
169
    url_fskip(s->pb, 2);
170
    unk1 = get_le16(s->pb);
171
    unk2 = get_le16(s->pb);
172
    url_fskip(s->pb, 22); // ascii timestamp
173

    
174
    av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
175
        size, w, h, unk1, unk2);
176

    
177
    if (av_new_packet(pkt, size) < 0)
178
        return AVERROR(EIO);
179

    
180
    pkt->pos = url_ftell(s->pb);
181
    pkt->stream_index = 0;
182
    ret = get_buffer(s->pb, pkt->data, size);
183
    if (ret <= 0) {
184
        av_free_packet(pkt);
185
        return AVERROR(EIO);
186
    }
187
    pkt->size = ret;
188
    return ret;
189
}
190

    
191
static int raw_read_close(AVFormatContext *s)
192
{
193
    return 0;
194
}
195

    
196
int pcm_read_seek(AVFormatContext *s,
197
                  int stream_index, int64_t timestamp, int flags)
198
{
199
    AVStream *st;
200
    int block_align, byte_rate;
201
    int64_t pos;
202

    
203
    st = s->streams[0];
204

    
205
    block_align = st->codec->block_align ? st->codec->block_align :
206
        (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
207
    byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
208
        block_align * st->codec->sample_rate;
209

    
210
    if (block_align <= 0 || byte_rate <= 0)
211
        return -1;
212

    
213
    /* compute the position by aligning it to block_align */
214
    pos = av_rescale_rnd(timestamp * byte_rate,
215
                         st->time_base.num,
216
                         st->time_base.den * (int64_t)block_align,
217
                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
218
    pos *= block_align;
219

    
220
    /* recompute exact position */
221
    st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
222
    url_fseek(s->pb, pos + s->data_offset, SEEK_SET);
223
    return 0;
224
}
225

    
226
static int audio_read_header(AVFormatContext *s,
227
                             AVFormatParameters *ap)
228
{
229
    AVStream *st = av_new_stream(s, 0);
230
    if (!st)
231
        return AVERROR(ENOMEM);
232
    st->codec->codec_type = CODEC_TYPE_AUDIO;
233
    st->codec->codec_id = s->iformat->value;
234
    st->need_parsing = AVSTREAM_PARSE_FULL;
235
    /* the parameters will be extracted from the compressed bitstream */
236
    return 0;
237
}
238

    
239
/* mpeg1/h263 input */
240
static int video_read_header(AVFormatContext *s,
241
                             AVFormatParameters *ap)
242
{
243
    AVStream *st;
244

    
245
    st = av_new_stream(s, 0);
246
    if (!st)
247
        return AVERROR(ENOMEM);
248

    
249
    st->codec->codec_type = CODEC_TYPE_VIDEO;
250
    st->codec->codec_id = s->iformat->value;
251
    st->need_parsing = AVSTREAM_PARSE_FULL;
252

    
253
    /* for mjpeg, specify frame rate */
254
    /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
255
    if (ap->time_base.num) {
256
        av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
257
    } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
258
                st->codec->codec_id == CODEC_ID_MPEG4 ||
259
                st->codec->codec_id == CODEC_ID_DIRAC ||
260
                st->codec->codec_id == CODEC_ID_H264) {
261
        av_set_pts_info(st, 64, 1, 25);
262
    }
263

    
264
    return 0;
265
}
266

    
267
#define SEQ_START_CODE          0x000001b3
268
#define GOP_START_CODE          0x000001b8
269
#define PICTURE_START_CODE      0x00000100
270
#define SLICE_START_CODE        0x00000101
271
#define PACK_START_CODE         0x000001ba
272
#define VIDEO_ID                0x000001e0
273
#define AUDIO_ID                0x000001c0
274

    
275
static int mpegvideo_probe(AVProbeData *p)
276
{
277
    uint32_t code= -1;
278
    int pic=0, seq=0, slice=0, pspack=0, pes=0;
279
    int i;
280

    
281
    for(i=0; i<p->buf_size; i++){
282
        code = (code<<8) + p->buf[i];
283
        if ((code & 0xffffff00) == 0x100) {
284
            switch(code){
285
            case     SEQ_START_CODE:   seq++; break;
286
            case PICTURE_START_CODE:   pic++; break;
287
            case   SLICE_START_CODE: slice++; break;
288
            case    PACK_START_CODE: pspack++; break;
289
            }
290
            if     ((code & 0x1f0) == VIDEO_ID)   pes++;
291
            else if((code & 0x1e0) == AUDIO_ID)   pes++;
292
        }
293
    }
294
    if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
295
        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
296
    return 0;
297
}
298

    
299
#define VISUAL_OBJECT_START_CODE       0x000001b5
300
#define VOP_START_CODE                 0x000001b6
301

    
302
static int mpeg4video_probe(AVProbeData *probe_packet)
303
{
304
    uint32_t temp_buffer= -1;
305
    int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
306
    int i;
307

    
308
    for(i=0; i<probe_packet->buf_size; i++){
309
        temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
310
        if ((temp_buffer & 0xffffff00) != 0x100)
311
            continue;
312

    
313
        if (temp_buffer == VOP_START_CODE)                         VOP++;
314
        else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
315
        else if (temp_buffer < 0x120)                              VO++;
316
        else if (temp_buffer < 0x130)                              VOL++;
317
        else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
318
                 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
319
    }
320

    
321
    if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
322
        return AVPROBE_SCORE_MAX/2;
323
    return 0;
324
}
325

    
326
static int h263_probe(AVProbeData *p)
327
{
328
    int code;
329
    const uint8_t *d;
330

    
331
    d = p->buf;
332
    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
333
    if (code == 0x20) {
334
        return 50;
335
    }
336
    return 0;
337
}
338

    
339
static int h261_probe(AVProbeData *p)
340
{
341
    int code;
342
    const uint8_t *d;
343

    
344
    d = p->buf;
345
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
346
    if (code == 0x10) {
347
        return 50;
348
    }
349
    return 0;
350
}
351

    
352
#define DCA_MARKER_14B_BE 0x1FFFE800
353
#define DCA_MARKER_14B_LE 0xFF1F00E8
354
#define DCA_MARKER_RAW_BE 0x7FFE8001
355
#define DCA_MARKER_RAW_LE 0xFE7F0180
356
static int dts_probe(AVProbeData *p)
357
{
358
    const uint8_t *buf, *bufp;
359
    uint32_t state = -1;
360

    
361
    buf = p->buf;
362

    
363
    for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
364
        bufp = buf;
365
        state = (state << 16) | bytestream_get_be16(&bufp);
366

    
367
        /* Regular bitstream */
368
        if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
369
            return AVPROBE_SCORE_MAX/2+1;
370

    
371
        /* 14 bits big endian bitstream */
372
        if (state == DCA_MARKER_14B_BE)
373
            if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
374
                return AVPROBE_SCORE_MAX/2+1;
375

    
376
        /* 14 bits little endian bitstream */
377
        if (state == DCA_MARKER_14B_LE)
378
            if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
379
                return AVPROBE_SCORE_MAX/2+1;
380
    }
381

    
382
    return 0;
383
}
384

    
385
static int dirac_probe(AVProbeData *p)
386
{
387
    if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
388
        return AVPROBE_SCORE_MAX;
389
    else
390
        return 0;
391
}
392

    
393
static int ac3_probe(AVProbeData *p)
394
{
395
    int max_frames, first_frames = 0, frames;
396
    uint8_t *buf, *buf2, *end;
397
    AC3HeaderInfo hdr;
398
    GetBitContext gbc;
399

    
400
    max_frames = 0;
401
    buf = p->buf;
402
    end = buf + p->buf_size;
403

    
404
    for(; buf < end; buf++) {
405
        buf2 = buf;
406

    
407
        for(frames = 0; buf2 < end; frames++) {
408
            init_get_bits(&gbc, buf2, 54);
409
            if(ff_ac3_parse_header(&gbc, &hdr) < 0)
410
                break;
411
            if(buf2 + hdr.frame_size > end ||
412
               av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
413
                break;
414
            buf2 += hdr.frame_size;
415
        }
416
        max_frames = FFMAX(max_frames, frames);
417
        if(buf == p->buf)
418
            first_frames = frames;
419
    }
420
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
421
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
422
    else if(max_frames>=1) return 1;
423
    else                   return 0;
424
}
425

    
426
static int flac_probe(AVProbeData *p)
427
{
428
    if(memcmp(p->buf, "fLaC", 4)) return 0;
429
    else                          return AVPROBE_SCORE_MAX / 2;
430
}
431

    
432
AVInputFormat shorten_demuxer = {
433
    "shn",
434
    "raw shorten",
435
    0,
436
    NULL,
437
    audio_read_header,
438
    raw_read_partial_packet,
439
    raw_read_close,
440
    .flags= AVFMT_GENERIC_INDEX,
441
    .extensions = "shn",
442
    .value = CODEC_ID_SHORTEN,
443
};
444

    
445
AVInputFormat mlp_demuxer = {
446
    "mlp",
447
    "raw mlp",
448
    0,
449
    NULL,
450
    audio_read_header,
451
    raw_read_partial_packet,
452
    raw_read_close,
453
    .flags= AVFMT_GENERIC_INDEX,
454
    .extensions = "mlp",
455
    .value = CODEC_ID_MLP,
456
};
457

    
458
AVInputFormat flac_demuxer = {
459
    "flac",
460
    "raw flac",
461
    0,
462
    flac_probe,
463
    audio_read_header,
464
    raw_read_partial_packet,
465
    raw_read_close,
466
    .flags= AVFMT_GENERIC_INDEX,
467
    .extensions = "flac",
468
    .value = CODEC_ID_FLAC,
469
};
470

    
471
#ifdef CONFIG_MUXERS
472
AVOutputFormat flac_muxer = {
473
    "flac",
474
    "raw flac",
475
    "audio/x-flac",
476
    "flac",
477
    0,
478
    CODEC_ID_FLAC,
479
    CODEC_ID_NONE,
480
    flac_write_header,
481
    raw_write_packet,
482
    .flags= AVFMT_NOTIMESTAMPS,
483
};
484
#endif //CONFIG_MUXERS
485

    
486
#ifdef CONFIG_AC3_DEMUXER
487
AVInputFormat ac3_demuxer = {
488
    "ac3",
489
    "raw ac3",
490
    0,
491
    ac3_probe,
492
    audio_read_header,
493
    raw_read_partial_packet,
494
    raw_read_close,
495
    .flags= AVFMT_GENERIC_INDEX,
496
    .extensions = "ac3",
497
    .value = CODEC_ID_AC3,
498
};
499
#endif
500

    
501
#ifdef CONFIG_MUXERS
502
AVOutputFormat ac3_muxer = {
503
    "ac3",
504
    "raw ac3",
505
    "audio/x-ac3",
506
    "ac3",
507
    0,
508
    CODEC_ID_AC3,
509
    CODEC_ID_NONE,
510
    NULL,
511
    raw_write_packet,
512
    .flags= AVFMT_NOTIMESTAMPS,
513
};
514

    
515
AVOutputFormat dts_muxer = {
516
    "dts",
517
    "raw dts",
518
    "audio/x-dca",
519
    "dts",
520
    0,
521
    CODEC_ID_DTS,
522
    CODEC_ID_NONE,
523
    NULL,
524
    raw_write_packet,
525
    .flags= AVFMT_NOTIMESTAMPS,
526
};
527

    
528
#endif //CONFIG_MUXERS
529

    
530
AVInputFormat dirac_demuxer = {
531
    "dirac",
532
    "raw dirac",
533
    0,
534
    dirac_probe,
535
    video_read_header,
536
    raw_read_partial_packet,
537
    raw_read_close,
538
    .flags= AVFMT_GENERIC_INDEX,
539
    .value = CODEC_ID_DIRAC,
540
};
541

    
542
#ifdef CONFIG_MUXERS
543
AVOutputFormat dirac_muxer = {
544
    "dirac",
545
    "raw dirac",
546
    NULL,
547
    "drc",
548
    0,
549
    CODEC_ID_NONE,
550
    CODEC_ID_DIRAC,
551
    NULL,
552
    raw_write_packet,
553
    .flags= AVFMT_NOTIMESTAMPS,
554
};
555
#endif
556

    
557
AVInputFormat dts_demuxer = {
558
    "dts",
559
    "raw dts",
560
    0,
561
    dts_probe,
562
    audio_read_header,
563
    raw_read_partial_packet,
564
    raw_read_close,
565
    .flags= AVFMT_GENERIC_INDEX,
566
    .extensions = "dts",
567
    .value = CODEC_ID_DTS,
568
};
569

    
570
AVInputFormat aac_demuxer = {
571
    "aac",
572
    "ADTS AAC",
573
    0,
574
    NULL,
575
    audio_read_header,
576
    raw_read_partial_packet,
577
    raw_read_close,
578
    .flags= AVFMT_GENERIC_INDEX,
579
    .extensions = "aac",
580
    .value = CODEC_ID_AAC,
581
};
582

    
583
AVInputFormat gsm_demuxer = {
584
    "gsm",
585
    "GSM",
586
    0,
587
    NULL,
588
    audio_read_header,
589
    raw_read_partial_packet,
590
    raw_read_close,
591
    .flags= AVFMT_GENERIC_INDEX,
592
    .extensions = "gsm",
593
    .value = CODEC_ID_GSM,
594
};
595

    
596
#ifdef CONFIG_ROQ_MUXER
597
AVOutputFormat roq_muxer =
598
{
599
    "RoQ",
600
    "Id RoQ format",
601
    NULL,
602
    "roq",
603
    0,
604
    CODEC_ID_ROQ_DPCM,
605
    CODEC_ID_ROQ,
606
    roq_write_header,
607
    raw_write_packet,
608
};
609
#endif //CONFIG_ROQ_MUXER
610

    
611
AVInputFormat h261_demuxer = {
612
    "h261",
613
    "raw h261",
614
    0,
615
    h261_probe,
616
    video_read_header,
617
    raw_read_partial_packet,
618
    raw_read_close,
619
    .flags= AVFMT_GENERIC_INDEX,
620
    .extensions = "h261",
621
    .value = CODEC_ID_H261,
622
};
623

    
624
#ifdef CONFIG_MUXERS
625
AVOutputFormat h261_muxer = {
626
    "h261",
627
    "raw h261",
628
    "video/x-h261",
629
    "h261",
630
    0,
631
    CODEC_ID_NONE,
632
    CODEC_ID_H261,
633
    NULL,
634
    raw_write_packet,
635
    .flags= AVFMT_NOTIMESTAMPS,
636
};
637
#endif //CONFIG_MUXERS
638

    
639
AVInputFormat h263_demuxer = {
640
    "h263",
641
    "raw h263",
642
    0,
643
    h263_probe,
644
    video_read_header,
645
    raw_read_partial_packet,
646
    raw_read_close,
647
    .flags= AVFMT_GENERIC_INDEX,
648
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
649
    .value = CODEC_ID_H263,
650
};
651

    
652
#ifdef CONFIG_MUXERS
653
AVOutputFormat h263_muxer = {
654
    "h263",
655
    "raw h263",
656
    "video/x-h263",
657
    "h263",
658
    0,
659
    CODEC_ID_NONE,
660
    CODEC_ID_H263,
661
    NULL,
662
    raw_write_packet,
663
    .flags= AVFMT_NOTIMESTAMPS,
664
};
665
#endif //CONFIG_MUXERS
666

    
667
AVInputFormat m4v_demuxer = {
668
    "m4v",
669
    "raw MPEG4 video format",
670
    0,
671
    mpeg4video_probe, /** probing for mpeg4 data */
672
    video_read_header,
673
    raw_read_partial_packet,
674
    raw_read_close,
675
    .flags= AVFMT_GENERIC_INDEX,
676
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
677
    .value = CODEC_ID_MPEG4,
678
};
679

    
680
#ifdef CONFIG_MUXERS
681
AVOutputFormat m4v_muxer = {
682
    "m4v",
683
    "raw MPEG4 video format",
684
    NULL,
685
    "m4v",
686
    0,
687
    CODEC_ID_NONE,
688
    CODEC_ID_MPEG4,
689
    NULL,
690
    raw_write_packet,
691
    .flags= AVFMT_NOTIMESTAMPS,
692
};
693
#endif //CONFIG_MUXERS
694

    
695
AVInputFormat h264_demuxer = {
696
    "h264",
697
    "raw H264 video format",
698
    0,
699
    NULL /*mpegvideo_probe*/,
700
    video_read_header,
701
    raw_read_partial_packet,
702
    raw_read_close,
703
    .flags= AVFMT_GENERIC_INDEX,
704
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
705
    .value = CODEC_ID_H264,
706
};
707

    
708
#ifdef CONFIG_MUXERS
709
AVOutputFormat h264_muxer = {
710
    "h264",
711
    "raw H264 video format",
712
    NULL,
713
    "h264",
714
    0,
715
    CODEC_ID_NONE,
716
    CODEC_ID_H264,
717
    NULL,
718
    raw_write_packet,
719
    .flags= AVFMT_NOTIMESTAMPS,
720
};
721
#endif //CONFIG_MUXERS
722

    
723
AVInputFormat mpegvideo_demuxer = {
724
    "mpegvideo",
725
    "MPEG video",
726
    0,
727
    mpegvideo_probe,
728
    video_read_header,
729
    raw_read_partial_packet,
730
    raw_read_close,
731
    .flags= AVFMT_GENERIC_INDEX,
732
    .value = CODEC_ID_MPEG1VIDEO,
733
};
734

    
735
#ifdef CONFIG_MUXERS
736
AVOutputFormat mpeg1video_muxer = {
737
    "mpeg1video",
738
    "MPEG video",
739
    "video/x-mpeg",
740
    "mpg,mpeg,m1v",
741
    0,
742
    CODEC_ID_NONE,
743
    CODEC_ID_MPEG1VIDEO,
744
    NULL,
745
    raw_write_packet,
746
    .flags= AVFMT_NOTIMESTAMPS,
747
};
748
#endif //CONFIG_MUXERS
749

    
750
#ifdef CONFIG_MUXERS
751
AVOutputFormat mpeg2video_muxer = {
752
    "mpeg2video",
753
    "MPEG2 video",
754
    NULL,
755
    "m2v",
756
    0,
757
    CODEC_ID_NONE,
758
    CODEC_ID_MPEG2VIDEO,
759
    NULL,
760
    raw_write_packet,
761
    .flags= AVFMT_NOTIMESTAMPS,
762
};
763
#endif //CONFIG_MUXERS
764

    
765
AVInputFormat mjpeg_demuxer = {
766
    "mjpeg",
767
    "MJPEG video",
768
    0,
769
    NULL,
770
    video_read_header,
771
    raw_read_partial_packet,
772
    raw_read_close,
773
    .flags= AVFMT_GENERIC_INDEX,
774
    .extensions = "mjpg,mjpeg",
775
    .value = CODEC_ID_MJPEG,
776
};
777

    
778
AVInputFormat ingenient_demuxer = {
779
    "ingenient",
780
    "Ingenient MJPEG",
781
    0,
782
    NULL,
783
    video_read_header,
784
    ingenient_read_packet,
785
    raw_read_close,
786
    .flags= AVFMT_GENERIC_INDEX,
787
    .extensions = "cgi", // FIXME
788
    .value = CODEC_ID_MJPEG,
789
};
790

    
791
#ifdef CONFIG_MUXERS
792
AVOutputFormat mjpeg_muxer = {
793
    "mjpeg",
794
    "MJPEG video",
795
    "video/x-mjpeg",
796
    "mjpg,mjpeg",
797
    0,
798
    CODEC_ID_NONE,
799
    CODEC_ID_MJPEG,
800
    NULL,
801
    raw_write_packet,
802
    .flags= AVFMT_NOTIMESTAMPS,
803
};
804
#endif //CONFIG_MUXERS
805

    
806
AVInputFormat vc1_demuxer = {
807
    "vc1",
808
    "raw vc1",
809
    0,
810
    NULL /* vc1_probe */,
811
    video_read_header,
812
    raw_read_partial_packet,
813
    raw_read_close,
814
    .extensions = "vc1",
815
    .value = CODEC_ID_VC1,
816
};
817

    
818
/* pcm formats */
819

    
820
#define PCMINPUTDEF(name, long_name, ext, codec) \
821
AVInputFormat pcm_ ## name ## _demuxer = {\
822
    #name,\
823
    long_name,\
824
    0,\
825
    NULL,\
826
    raw_read_header,\
827
    raw_read_packet,\
828
    raw_read_close,\
829
    pcm_read_seek,\
830
    .flags= AVFMT_GENERIC_INDEX,\
831
    .extensions = ext,\
832
    .value = codec,\
833
};
834

    
835
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
836
AVOutputFormat pcm_ ## name ## _muxer = {\
837
    #name,\
838
    long_name,\
839
    NULL,\
840
    ext,\
841
    0,\
842
    codec,\
843
    CODEC_ID_NONE,\
844
    NULL,\
845
    raw_write_packet,\
846
    .flags= AVFMT_NOTIMESTAMPS,\
847
};
848

    
849

    
850
#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
851
#define PCMDEF(name, long_name, ext, codec) \
852
        PCMINPUTDEF(name, long_name, ext, codec)
853
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
854
#define PCMDEF(name, long_name, ext, codec) \
855
        PCMOUTPUTDEF(name, long_name, ext, codec)
856
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
857
#define PCMDEF(name, long_name, ext, codec) \
858
        PCMINPUTDEF(name, long_name, ext, codec)\
859
        PCMOUTPUTDEF(name, long_name, ext, codec)
860
#else
861
#define PCMDEF(name, long_name, ext, codec)
862
#endif
863

    
864
#ifdef WORDS_BIGENDIAN
865
#define BE_DEF(s) s
866
#define LE_DEF(s) NULL
867
#else
868
#define BE_DEF(s) NULL
869
#define LE_DEF(s) s
870
#endif
871

    
872

    
873
PCMDEF(s16le, "pcm signed 16 bit little endian format",
874
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
875

    
876
PCMDEF(s16be, "pcm signed 16 bit big endian format",
877
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
878

    
879
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
880
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
881

    
882
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
883
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
884

    
885
PCMDEF(s8, "pcm signed 8 bit format",
886
       "sb", CODEC_ID_PCM_S8)
887

    
888
PCMDEF(u8, "pcm unsigned 8 bit format",
889
       "ub", CODEC_ID_PCM_U8)
890

    
891
PCMDEF(mulaw, "pcm mu law format",
892
       "ul", CODEC_ID_PCM_MULAW)
893

    
894
PCMDEF(alaw, "pcm A law format",
895
       "al", CODEC_ID_PCM_ALAW)
896

    
897
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
898
{
899
    int packet_size, ret, width, height;
900
    AVStream *st = s->streams[0];
901

    
902
    width = st->codec->width;
903
    height = st->codec->height;
904

    
905
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
906
    if (packet_size < 0)
907
        return -1;
908

    
909
    ret= av_get_packet(s->pb, pkt, packet_size);
910
    pkt->pts=
911
    pkt->dts= pkt->pos / packet_size;
912

    
913
    pkt->stream_index = 0;
914
    if (ret != packet_size) {
915
        return AVERROR(EIO);
916
    } else {
917
        return 0;
918
    }
919
}
920

    
921
AVInputFormat rawvideo_demuxer = {
922
    "rawvideo",
923
    "raw video format",
924
    0,
925
    NULL,
926
    raw_read_header,
927
    rawvideo_read_packet,
928
    raw_read_close,
929
    .flags= AVFMT_GENERIC_INDEX,
930
    .extensions = "yuv,cif,qcif,rgb",
931
    .value = CODEC_ID_RAWVIDEO,
932
};
933

    
934
#ifdef CONFIG_MUXERS
935
AVOutputFormat rawvideo_muxer = {
936
    "rawvideo",
937
    "raw video format",
938
    NULL,
939
    "yuv,rgb",
940
    0,
941
    CODEC_ID_NONE,
942
    CODEC_ID_RAWVIDEO,
943
    NULL,
944
    raw_write_packet,
945
    .flags= AVFMT_NOTIMESTAMPS,
946
};
947
#endif //CONFIG_MUXERS
948

    
949
#ifdef CONFIG_MUXERS
950
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
951
{
952
    return 0;
953
}
954

    
955
AVOutputFormat null_muxer = {
956
    "null",
957
    "null video format",
958
    NULL,
959
    NULL,
960
    0,
961
#ifdef WORDS_BIGENDIAN
962
    CODEC_ID_PCM_S16BE,
963
#else
964
    CODEC_ID_PCM_S16LE,
965
#endif
966
    CODEC_ID_RAWVIDEO,
967
    NULL,
968
    null_write_packet,
969
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
970
};
971
#endif //CONFIG_MUXERS