Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 55736cfb

History | View | Annotate | Download (21.6 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
#include "avformat.h"
23
#include "ac3_parser.h"
24
#include "raw.h"
25
#include "crc.h"
26
#include "bitstream.h"
27

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

    
44

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

    
51
    put_buffer(s->pb, header, 8);
52
    put_flush_packet(s->pb);
53

    
54
    return 0;
55
}
56

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

    
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
            st->codec->channels = ap->channels;
87
            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
88
            break;
89
        case CODEC_TYPE_VIDEO:
90
            if(ap->time_base.num)
91
                av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
92
            else
93
                av_set_pts_info(st, 64, 1, 25);
94
            st->codec->width = ap->width;
95
            st->codec->height = ap->height;
96
            st->codec->pix_fmt = ap->pix_fmt;
97
            if(st->codec->pix_fmt == PIX_FMT_NONE)
98
                st->codec->pix_fmt= PIX_FMT_YUV420P;
99
            break;
100
        default:
101
            return -1;
102
        }
103
    return 0;
104
}
105

    
106
#define RAW_PACKET_SIZE 1024
107

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

    
113
    size= RAW_PACKET_SIZE;
114

    
115
    ret= av_get_packet(s->pb, pkt, size);
116

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

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

    
130
    return ret;
131
}
132

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

    
137
    size = RAW_PACKET_SIZE;
138

    
139
    if (av_new_packet(pkt, size) < 0)
140
        return AVERROR(EIO);
141

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

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

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

    
161
    size = get_le32(s->pb);
162

    
163
    w = get_le16(s->pb);
164
    h = get_le16(s->pb);
165

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

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

    
175
    if (av_new_packet(pkt, size) < 0)
176
        return AVERROR(EIO);
177

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

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

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

    
201
    st = s->streams[0];
202

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

    
208
    if (block_align <= 0 || byte_rate <= 0)
209
        return -1;
210

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

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

    
224
/* ac3 read */
225
static int ac3_read_header(AVFormatContext *s,
226
                           AVFormatParameters *ap)
227
{
228
    AVStream *st;
229

    
230
    st = av_new_stream(s, 0);
231
    if (!st)
232
        return AVERROR(ENOMEM);
233

    
234
    st->codec->codec_type = CODEC_TYPE_AUDIO;
235
    st->codec->codec_id = CODEC_ID_AC3;
236
    st->need_parsing = AVSTREAM_PARSE_FULL;
237
    /* the parameters will be extracted from the compressed bitstream */
238
    return 0;
239
}
240

    
241
static int shorten_read_header(AVFormatContext *s,
242
                               AVFormatParameters *ap)
243
{
244
    AVStream *st;
245

    
246
    st = av_new_stream(s, 0);
247
    if (!st)
248
        return AVERROR(ENOMEM);
249
    st->codec->codec_type = CODEC_TYPE_AUDIO;
250
    st->codec->codec_id = CODEC_ID_SHORTEN;
251
    st->need_parsing = AVSTREAM_PARSE_FULL;
252
    /* the parameters will be extracted from the compressed bitstream */
253
    return 0;
254
}
255

    
256
/* flac read */
257
static int flac_read_header(AVFormatContext *s,
258
                            AVFormatParameters *ap)
259
{
260
    AVStream *st;
261

    
262
    st = av_new_stream(s, 0);
263
    if (!st)
264
        return AVERROR(ENOMEM);
265
    st->codec->codec_type = CODEC_TYPE_AUDIO;
266
    st->codec->codec_id = CODEC_ID_FLAC;
267
    st->need_parsing = AVSTREAM_PARSE_FULL;
268
    /* the parameters will be extracted from the compressed bitstream */
269
    return 0;
270
}
271

    
272
/* dts read */
273
static int dts_read_header(AVFormatContext *s,
274
                           AVFormatParameters *ap)
275
{
276
    AVStream *st;
277

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

    
282
    st->codec->codec_type = CODEC_TYPE_AUDIO;
283
    st->codec->codec_id = CODEC_ID_DTS;
284
    st->need_parsing = AVSTREAM_PARSE_FULL;
285
    /* the parameters will be extracted from the compressed bitstream */
286
    return 0;
287
}
288

    
289
/* aac read */
290
static int aac_read_header(AVFormatContext *s,
291
                           AVFormatParameters *ap)
292
{
293
    AVStream *st;
294

    
295
    st = av_new_stream(s, 0);
296
    if (!st)
297
        return AVERROR(ENOMEM);
298

    
299
    st->codec->codec_type = CODEC_TYPE_AUDIO;
300
    st->codec->codec_id = CODEC_ID_AAC;
301
    st->need_parsing = AVSTREAM_PARSE_FULL;
302
    /* the parameters will be extracted from the compressed bitstream */
303
    return 0;
304
}
305

    
306
/* mpeg1/h263 input */
307
static int video_read_header(AVFormatContext *s,
308
                             AVFormatParameters *ap)
309
{
310
    AVStream *st;
311

    
312
    st = av_new_stream(s, 0);
313
    if (!st)
314
        return AVERROR(ENOMEM);
315

    
316
    st->codec->codec_type = CODEC_TYPE_VIDEO;
317
    st->codec->codec_id = s->iformat->value;
318
    st->need_parsing = AVSTREAM_PARSE_FULL;
319

    
320
    /* for mjpeg, specify frame rate */
321
    /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
322
    if (ap->time_base.num) {
323
        av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
324
    } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
325
                st->codec->codec_id == CODEC_ID_MPEG4 ||
326
                st->codec->codec_id == CODEC_ID_H264) {
327
        av_set_pts_info(st, 64, 1, 25);
328
    }
329

    
330
    return 0;
331
}
332

    
333
#define SEQ_START_CODE          0x000001b3
334
#define GOP_START_CODE          0x000001b8
335
#define PICTURE_START_CODE      0x00000100
336
#define SLICE_START_CODE        0x00000101
337
#define PACK_START_CODE         0x000001ba
338
#define VIDEO_ID                0x000001e0
339
#define AUDIO_ID                0x000001c0
340

    
341
static int mpegvideo_probe(AVProbeData *p)
342
{
343
    uint32_t code= -1;
344
    int pic=0, seq=0, slice=0, pspack=0, pes=0;
345
    int i;
346

    
347
    for(i=0; i<p->buf_size; i++){
348
        code = (code<<8) + p->buf[i];
349
        if ((code & 0xffffff00) == 0x100) {
350
            switch(code){
351
            case     SEQ_START_CODE:   seq++; break;
352
            case PICTURE_START_CODE:   pic++; break;
353
            case   SLICE_START_CODE: slice++; break;
354
            case    PACK_START_CODE: pspack++; break;
355
            }
356
            if     ((code & 0x1f0) == VIDEO_ID)   pes++;
357
            else if((code & 0x1e0) == AUDIO_ID)   pes++;
358
        }
359
    }
360
    if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
361
        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
362
    return 0;
363
}
364

    
365
#define VISUAL_OBJECT_START_CODE       0x000001b5
366
#define VOP_START_CODE                 0x000001b6
367

    
368
static int mpeg4video_probe(AVProbeData *probe_packet)
369
{
370
    uint32_t temp_buffer= -1;
371
    int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
372
    int i;
373

    
374
    for(i=0; i<probe_packet->buf_size; i++){
375
        temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
376
        if ((temp_buffer & 0xffffff00) != 0x100)
377
            continue;
378

    
379
        if (temp_buffer == VOP_START_CODE)                         VOP++;
380
        else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
381
        else if (temp_buffer < 0x120)                              VO++;
382
        else if (temp_buffer < 0x130)                              VOL++;
383
        else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
384
                 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
385
    }
386

    
387
    if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
388
        return AVPROBE_SCORE_MAX/2;
389
    return 0;
390
}
391

    
392
static int h263_probe(AVProbeData *p)
393
{
394
    int code;
395
    const uint8_t *d;
396

    
397
    d = p->buf;
398
    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
399
    if (code == 0x20) {
400
        return 50;
401
    }
402
    return 0;
403
}
404

    
405
static int h261_probe(AVProbeData *p)
406
{
407
    int code;
408
    const uint8_t *d;
409

    
410
    d = p->buf;
411
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
412
    if (code == 0x10) {
413
        return 50;
414
    }
415
    return 0;
416
}
417

    
418
static int ac3_probe(AVProbeData *p)
419
{
420
    int max_frames, first_frames = 0, frames;
421
    uint8_t *buf, *buf2, *end;
422
    AC3HeaderInfo hdr;
423
    GetBitContext gbc;
424

    
425
    max_frames = 0;
426
    buf = p->buf;
427
    end = buf + p->buf_size;
428

    
429
    for(; buf < end; buf++) {
430
        buf2 = buf;
431

    
432
        for(frames = 0; buf2 < end; frames++) {
433
            init_get_bits(&gbc, buf2, 54);
434
            if(ff_ac3_parse_header(&gbc, &hdr) < 0)
435
                break;
436
            if(buf2 + hdr.frame_size > end ||
437
               av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
438
                break;
439
            buf2 += hdr.frame_size;
440
        }
441
        max_frames = FFMAX(max_frames, frames);
442
        if(buf == p->buf)
443
            first_frames = frames;
444
    }
445
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
446
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
447
    else if(max_frames>=1) return 1;
448
    else                   return 0;
449
}
450

    
451
static int flac_probe(AVProbeData *p)
452
{
453
    if(memcmp(p->buf, "fLaC", 4)) return 0;
454
    else                          return AVPROBE_SCORE_MAX / 2;
455
}
456

    
457
AVInputFormat shorten_demuxer = {
458
    "shn",
459
    "raw shorten",
460
    0,
461
    NULL,
462
    shorten_read_header,
463
    raw_read_partial_packet,
464
    raw_read_close,
465
    .flags= AVFMT_GENERIC_INDEX,
466
    .extensions = "shn",
467
};
468

    
469
AVInputFormat flac_demuxer = {
470
    "flac",
471
    "raw flac",
472
    0,
473
    flac_probe,
474
    flac_read_header,
475
    raw_read_partial_packet,
476
    raw_read_close,
477
    .flags= AVFMT_GENERIC_INDEX,
478
    .extensions = "flac",
479
};
480

    
481
#ifdef CONFIG_MUXERS
482
AVOutputFormat flac_muxer = {
483
    "flac",
484
    "raw flac",
485
    "audio/x-flac",
486
    "flac",
487
    0,
488
    CODEC_ID_FLAC,
489
    0,
490
    flac_write_header,
491
    raw_write_packet,
492
    .flags= AVFMT_NOTIMESTAMPS,
493
};
494
#endif //CONFIG_MUXERS
495

    
496
#ifdef CONFIG_AC3_DEMUXER
497
AVInputFormat ac3_demuxer = {
498
    "ac3",
499
    "raw ac3",
500
    0,
501
    ac3_probe,
502
    ac3_read_header,
503
    raw_read_partial_packet,
504
    raw_read_close,
505
    .flags= AVFMT_GENERIC_INDEX,
506
    .extensions = "ac3",
507
};
508
#endif
509

    
510
#ifdef CONFIG_MUXERS
511
AVOutputFormat ac3_muxer = {
512
    "ac3",
513
    "raw ac3",
514
    "audio/x-ac3",
515
    "ac3",
516
    0,
517
    CODEC_ID_AC3,
518
    0,
519
    NULL,
520
    raw_write_packet,
521
    .flags= AVFMT_NOTIMESTAMPS,
522
};
523

    
524
AVOutputFormat dts_muxer = {
525
    "dts",
526
    "raw dts",
527
    "audio/x-dca",
528
    "dts",
529
    0,
530
    CODEC_ID_DTS,
531
    0,
532
    NULL,
533
    raw_write_packet,
534
    .flags= AVFMT_NOTIMESTAMPS,
535
};
536

    
537
#endif //CONFIG_MUXERS
538

    
539
AVInputFormat dts_demuxer = {
540
    "dts",
541
    "raw dts",
542
    0,
543
    NULL,
544
    dts_read_header,
545
    raw_read_partial_packet,
546
    raw_read_close,
547
    .flags= AVFMT_GENERIC_INDEX,
548
    .extensions = "dts",
549
};
550

    
551
AVInputFormat aac_demuxer = {
552
    "aac",
553
    "ADTS AAC",
554
    0,
555
    NULL,
556
    aac_read_header,
557
    raw_read_partial_packet,
558
    raw_read_close,
559
    .flags= AVFMT_GENERIC_INDEX,
560
    .extensions = "aac",
561
};
562

    
563
#ifdef CONFIG_ROQ_MUXER
564
AVOutputFormat roq_muxer =
565
{
566
    "RoQ",
567
    "Id RoQ format",
568
    NULL,
569
    "roq",
570
    0,
571
    CODEC_ID_ROQ_DPCM,
572
    CODEC_ID_ROQ,
573
    roq_write_header,
574
    raw_write_packet,
575
};
576
#endif //CONFIG_ROQ_MUXER
577

    
578
AVInputFormat h261_demuxer = {
579
    "h261",
580
    "raw h261",
581
    0,
582
    h261_probe,
583
    video_read_header,
584
    raw_read_partial_packet,
585
    raw_read_close,
586
    .flags= AVFMT_GENERIC_INDEX,
587
    .extensions = "h261",
588
    .value = CODEC_ID_H261,
589
};
590

    
591
#ifdef CONFIG_MUXERS
592
AVOutputFormat h261_muxer = {
593
    "h261",
594
    "raw h261",
595
    "video/x-h261",
596
    "h261",
597
    0,
598
    0,
599
    CODEC_ID_H261,
600
    NULL,
601
    raw_write_packet,
602
    .flags= AVFMT_NOTIMESTAMPS,
603
};
604
#endif //CONFIG_MUXERS
605

    
606
AVInputFormat h263_demuxer = {
607
    "h263",
608
    "raw h263",
609
    0,
610
    h263_probe,
611
    video_read_header,
612
    raw_read_partial_packet,
613
    raw_read_close,
614
    .flags= AVFMT_GENERIC_INDEX,
615
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
616
    .value = CODEC_ID_H263,
617
};
618

    
619
#ifdef CONFIG_MUXERS
620
AVOutputFormat h263_muxer = {
621
    "h263",
622
    "raw h263",
623
    "video/x-h263",
624
    "h263",
625
    0,
626
    0,
627
    CODEC_ID_H263,
628
    NULL,
629
    raw_write_packet,
630
    .flags= AVFMT_NOTIMESTAMPS,
631
};
632
#endif //CONFIG_MUXERS
633

    
634
AVInputFormat m4v_demuxer = {
635
    "m4v",
636
    "raw MPEG4 video format",
637
    0,
638
    mpeg4video_probe, /** probing for mpeg4 data */
639
    video_read_header,
640
    raw_read_partial_packet,
641
    raw_read_close,
642
    .flags= AVFMT_GENERIC_INDEX,
643
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
644
    .value = CODEC_ID_MPEG4,
645
};
646

    
647
#ifdef CONFIG_MUXERS
648
AVOutputFormat m4v_muxer = {
649
    "m4v",
650
    "raw MPEG4 video format",
651
    NULL,
652
    "m4v",
653
    0,
654
    CODEC_ID_NONE,
655
    CODEC_ID_MPEG4,
656
    NULL,
657
    raw_write_packet,
658
    .flags= AVFMT_NOTIMESTAMPS,
659
};
660
#endif //CONFIG_MUXERS
661

    
662
AVInputFormat h264_demuxer = {
663
    "h264",
664
    "raw H264 video format",
665
    0,
666
    NULL /*mpegvideo_probe*/,
667
    video_read_header,
668
    raw_read_partial_packet,
669
    raw_read_close,
670
    .flags= AVFMT_GENERIC_INDEX,
671
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
672
    .value = CODEC_ID_H264,
673
};
674

    
675
#ifdef CONFIG_MUXERS
676
AVOutputFormat h264_muxer = {
677
    "h264",
678
    "raw H264 video format",
679
    NULL,
680
    "h264",
681
    0,
682
    CODEC_ID_NONE,
683
    CODEC_ID_H264,
684
    NULL,
685
    raw_write_packet,
686
    .flags= AVFMT_NOTIMESTAMPS,
687
};
688
#endif //CONFIG_MUXERS
689

    
690
AVInputFormat mpegvideo_demuxer = {
691
    "mpegvideo",
692
    "MPEG video",
693
    0,
694
    mpegvideo_probe,
695
    video_read_header,
696
    raw_read_partial_packet,
697
    raw_read_close,
698
    .flags= AVFMT_GENERIC_INDEX,
699
    .value = CODEC_ID_MPEG1VIDEO,
700
};
701

    
702
#ifdef CONFIG_MUXERS
703
AVOutputFormat mpeg1video_muxer = {
704
    "mpeg1video",
705
    "MPEG video",
706
    "video/x-mpeg",
707
    "mpg,mpeg,m1v",
708
    0,
709
    0,
710
    CODEC_ID_MPEG1VIDEO,
711
    NULL,
712
    raw_write_packet,
713
    .flags= AVFMT_NOTIMESTAMPS,
714
};
715
#endif //CONFIG_MUXERS
716

    
717
#ifdef CONFIG_MUXERS
718
AVOutputFormat mpeg2video_muxer = {
719
    "mpeg2video",
720
    "MPEG2 video",
721
    NULL,
722
    "m2v",
723
    0,
724
    0,
725
    CODEC_ID_MPEG2VIDEO,
726
    NULL,
727
    raw_write_packet,
728
    .flags= AVFMT_NOTIMESTAMPS,
729
};
730
#endif //CONFIG_MUXERS
731

    
732
AVInputFormat mjpeg_demuxer = {
733
    "mjpeg",
734
    "MJPEG video",
735
    0,
736
    NULL,
737
    video_read_header,
738
    raw_read_partial_packet,
739
    raw_read_close,
740
    .flags= AVFMT_GENERIC_INDEX,
741
    .extensions = "mjpg,mjpeg",
742
    .value = CODEC_ID_MJPEG,
743
};
744

    
745
AVInputFormat ingenient_demuxer = {
746
    "ingenient",
747
    "Ingenient MJPEG",
748
    0,
749
    NULL,
750
    video_read_header,
751
    ingenient_read_packet,
752
    raw_read_close,
753
    .flags= AVFMT_GENERIC_INDEX,
754
    .extensions = "cgi", // FIXME
755
    .value = CODEC_ID_MJPEG,
756
};
757

    
758
#ifdef CONFIG_MUXERS
759
AVOutputFormat mjpeg_muxer = {
760
    "mjpeg",
761
    "MJPEG video",
762
    "video/x-mjpeg",
763
    "mjpg,mjpeg",
764
    0,
765
    0,
766
    CODEC_ID_MJPEG,
767
    NULL,
768
    raw_write_packet,
769
    .flags= AVFMT_NOTIMESTAMPS,
770
};
771
#endif //CONFIG_MUXERS
772

    
773
AVInputFormat vc1_demuxer = {
774
    "vc1",
775
    "raw vc1",
776
    0,
777
    NULL /* vc1_probe */,
778
    video_read_header,
779
    raw_read_partial_packet,
780
    raw_read_close,
781
    .extensions = "vc1",
782
    .value = CODEC_ID_VC1,
783
};
784

    
785
/* pcm formats */
786

    
787
#define PCMINPUTDEF(name, long_name, ext, codec) \
788
AVInputFormat pcm_ ## name ## _demuxer = {\
789
    #name,\
790
    long_name,\
791
    0,\
792
    NULL,\
793
    raw_read_header,\
794
    raw_read_packet,\
795
    raw_read_close,\
796
    pcm_read_seek,\
797
    .flags= AVFMT_GENERIC_INDEX,\
798
    .extensions = ext,\
799
    .value = codec,\
800
};
801

    
802
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
803
AVOutputFormat pcm_ ## name ## _muxer = {\
804
    #name,\
805
    long_name,\
806
    NULL,\
807
    ext,\
808
    0,\
809
    codec,\
810
    0,\
811
    NULL,\
812
    raw_write_packet,\
813
    .flags= AVFMT_NOTIMESTAMPS,\
814
};
815

    
816

    
817
#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
818
#define PCMDEF(name, long_name, ext, codec) \
819
        PCMINPUTDEF(name, long_name, ext, codec)
820
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
821
#define PCMDEF(name, long_name, ext, codec) \
822
        PCMOUTPUTDEF(name, long_name, ext, codec)
823
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
824
#define PCMDEF(name, long_name, ext, codec) \
825
        PCMINPUTDEF(name, long_name, ext, codec)\
826
        PCMOUTPUTDEF(name, long_name, ext, codec)
827
#else
828
#define PCMDEF(name, long_name, ext, codec)
829
#endif
830

    
831
#ifdef WORDS_BIGENDIAN
832
#define BE_DEF(s) s
833
#define LE_DEF(s) NULL
834
#else
835
#define BE_DEF(s) NULL
836
#define LE_DEF(s) s
837
#endif
838

    
839

    
840
PCMDEF(s16le, "pcm signed 16 bit little endian format",
841
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
842

    
843
PCMDEF(s16be, "pcm signed 16 bit big endian format",
844
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
845

    
846
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
847
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
848

    
849
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
850
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
851

    
852
PCMDEF(s8, "pcm signed 8 bit format",
853
       "sb", CODEC_ID_PCM_S8)
854

    
855
PCMDEF(u8, "pcm unsigned 8 bit format",
856
       "ub", CODEC_ID_PCM_U8)
857

    
858
PCMDEF(mulaw, "pcm mu law format",
859
       "ul", CODEC_ID_PCM_MULAW)
860

    
861
PCMDEF(alaw, "pcm A law format",
862
       "al", CODEC_ID_PCM_ALAW)
863

    
864
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
865
{
866
    int packet_size, ret, width, height;
867
    AVStream *st = s->streams[0];
868

    
869
    width = st->codec->width;
870
    height = st->codec->height;
871

    
872
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
873
    if (packet_size < 0)
874
        return -1;
875

    
876
    ret= av_get_packet(s->pb, pkt, packet_size);
877
    pkt->pts=
878
    pkt->dts= pkt->pos / packet_size;
879

    
880
    pkt->stream_index = 0;
881
    if (ret != packet_size) {
882
        return AVERROR(EIO);
883
    } else {
884
        return 0;
885
    }
886
}
887

    
888
AVInputFormat rawvideo_demuxer = {
889
    "rawvideo",
890
    "raw video format",
891
    0,
892
    NULL,
893
    raw_read_header,
894
    rawvideo_read_packet,
895
    raw_read_close,
896
    .flags= AVFMT_GENERIC_INDEX,
897
    .extensions = "yuv,cif,qcif,rgb",
898
    .value = CODEC_ID_RAWVIDEO,
899
};
900

    
901
#ifdef CONFIG_MUXERS
902
AVOutputFormat rawvideo_muxer = {
903
    "rawvideo",
904
    "raw video format",
905
    NULL,
906
    "yuv,rgb",
907
    0,
908
    CODEC_ID_NONE,
909
    CODEC_ID_RAWVIDEO,
910
    NULL,
911
    raw_write_packet,
912
    .flags= AVFMT_NOTIMESTAMPS,
913
};
914
#endif //CONFIG_MUXERS
915

    
916
#ifdef CONFIG_MUXERS
917
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
918
{
919
    return 0;
920
}
921

    
922
AVOutputFormat null_muxer = {
923
    "null",
924
    "null video format",
925
    NULL,
926
    NULL,
927
    0,
928
#ifdef WORDS_BIGENDIAN
929
    CODEC_ID_PCM_S16BE,
930
#else
931
    CODEC_ID_PCM_S16LE,
932
#endif
933
    CODEC_ID_RAWVIDEO,
934
    NULL,
935
    null_write_packet,
936
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
937
};
938
#endif //CONFIG_MUXERS