Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ a23c9c4a

History | View | Annotate | Download (21.2 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

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

    
42

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

    
49
    put_buffer(s->pb, header, 8);
50
    put_flush_packet(s->pb);
51

    
52
    return 0;
53
}
54

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

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

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

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

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

    
104
#define RAW_PACKET_SIZE 1024
105

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

    
111
    size= RAW_PACKET_SIZE;
112

    
113
    ret= av_get_packet(s->pb, pkt, size);
114

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

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

    
128
    return ret;
129
}
130

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

    
135
    size = RAW_PACKET_SIZE;
136

    
137
    if (av_new_packet(pkt, size) < 0)
138
        return AVERROR(EIO);
139

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

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

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

    
159
    size = get_le32(s->pb);
160

    
161
    w = get_le16(s->pb);
162
    h = get_le16(s->pb);
163

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

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

    
173
    if (av_new_packet(pkt, size) < 0)
174
        return AVERROR(EIO);
175

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

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

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

    
199
    st = s->streams[0];
200

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

    
206
    if (block_align <= 0 || byte_rate <= 0)
207
        return -1;
208

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

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

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

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

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

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

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

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

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

    
270
/* dts read */
271
static int dts_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_AUDIO;
281
    st->codec->codec_id = CODEC_ID_DTS;
282
    st->need_parsing = AVSTREAM_PARSE_FULL;
283
    /* the parameters will be extracted from the compressed bitstream */
284
    return 0;
285
}
286

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

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

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

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

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

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

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

    
328
    return 0;
329
}
330

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

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

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

    
363
#define VISUAL_OBJECT_START_CODE       0x000001b5
364
#define VOP_START_CODE                 0x000001b6
365

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

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

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

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

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

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

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

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

    
416
static int ac3_probe(AVProbeData *p)
417
{
418
    int max_frames, first_frames = 0, frames;
419
    uint8_t *buf, *buf2, *end;
420
    AC3HeaderInfo hdr;
421

    
422
    max_frames = 0;
423
    buf = p->buf;
424
    end = buf + p->buf_size;
425

    
426
    for(; buf < end; buf++) {
427
        buf2 = buf;
428

    
429
        for(frames = 0; buf2 < end; frames++) {
430
            if(ff_ac3_parse_header(buf2, &hdr) < 0)
431
                break;
432
            buf2 += hdr.frame_size;
433
        }
434
        max_frames = FFMAX(max_frames, frames);
435
        if(buf == p->buf)
436
            first_frames = frames;
437
    }
438
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
439
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
440
    else if(max_frames>=1) return 1;
441
    else                   return 0;
442
}
443

    
444
static int flac_probe(AVProbeData *p)
445
{
446
    if(memcmp(p->buf, "fLaC", 4)) return 0;
447
    else                          return AVPROBE_SCORE_MAX / 2;
448
}
449

    
450
AVInputFormat shorten_demuxer = {
451
    "shn",
452
    "raw shorten",
453
    0,
454
    NULL,
455
    shorten_read_header,
456
    raw_read_partial_packet,
457
    raw_read_close,
458
    .flags= AVFMT_GENERIC_INDEX,
459
    .extensions = "shn",
460
};
461

    
462
AVInputFormat flac_demuxer = {
463
    "flac",
464
    "raw flac",
465
    0,
466
    flac_probe,
467
    flac_read_header,
468
    raw_read_partial_packet,
469
    raw_read_close,
470
    .flags= AVFMT_GENERIC_INDEX,
471
    .extensions = "flac",
472
};
473

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

    
489
#ifdef CONFIG_AC3_DEMUXER
490
AVInputFormat ac3_demuxer = {
491
    "ac3",
492
    "raw ac3",
493
    0,
494
    ac3_probe,
495
    ac3_read_header,
496
    raw_read_partial_packet,
497
    raw_read_close,
498
    .flags= AVFMT_GENERIC_INDEX,
499
    .extensions = "ac3",
500
};
501
#endif
502

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

    
518
AVInputFormat dts_demuxer = {
519
    "dts",
520
    "raw dts",
521
    0,
522
    NULL,
523
    dts_read_header,
524
    raw_read_partial_packet,
525
    raw_read_close,
526
    .flags= AVFMT_GENERIC_INDEX,
527
    .extensions = "dts",
528
};
529

    
530
AVInputFormat aac_demuxer = {
531
    "aac",
532
    "ADTS AAC",
533
    0,
534
    NULL,
535
    aac_read_header,
536
    raw_read_partial_packet,
537
    raw_read_close,
538
    .flags= AVFMT_GENERIC_INDEX,
539
    .extensions = "aac",
540
};
541

    
542
#ifdef CONFIG_ROQ_MUXER
543
AVOutputFormat roq_muxer =
544
{
545
    "RoQ",
546
    "Id RoQ format",
547
    NULL,
548
    "roq",
549
    0,
550
    CODEC_ID_ROQ_DPCM,
551
    CODEC_ID_ROQ,
552
    roq_write_header,
553
    raw_write_packet,
554
};
555
#endif //CONFIG_ROQ_MUXER
556

    
557
AVInputFormat h261_demuxer = {
558
    "h261",
559
    "raw h261",
560
    0,
561
    h261_probe,
562
    video_read_header,
563
    raw_read_partial_packet,
564
    raw_read_close,
565
    .flags= AVFMT_GENERIC_INDEX,
566
    .extensions = "h261",
567
    .value = CODEC_ID_H261,
568
};
569

    
570
#ifdef CONFIG_MUXERS
571
AVOutputFormat h261_muxer = {
572
    "h261",
573
    "raw h261",
574
    "video/x-h261",
575
    "h261",
576
    0,
577
    0,
578
    CODEC_ID_H261,
579
    NULL,
580
    raw_write_packet,
581
    .flags= AVFMT_NOTIMESTAMPS,
582
};
583
#endif //CONFIG_MUXERS
584

    
585
AVInputFormat h263_demuxer = {
586
    "h263",
587
    "raw h263",
588
    0,
589
    h263_probe,
590
    video_read_header,
591
    raw_read_partial_packet,
592
    raw_read_close,
593
    .flags= AVFMT_GENERIC_INDEX,
594
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
595
    .value = CODEC_ID_H263,
596
};
597

    
598
#ifdef CONFIG_MUXERS
599
AVOutputFormat h263_muxer = {
600
    "h263",
601
    "raw h263",
602
    "video/x-h263",
603
    "h263",
604
    0,
605
    0,
606
    CODEC_ID_H263,
607
    NULL,
608
    raw_write_packet,
609
    .flags= AVFMT_NOTIMESTAMPS,
610
};
611
#endif //CONFIG_MUXERS
612

    
613
AVInputFormat m4v_demuxer = {
614
    "m4v",
615
    "raw MPEG4 video format",
616
    0,
617
    mpeg4video_probe, /** probing for mpeg4 data */
618
    video_read_header,
619
    raw_read_partial_packet,
620
    raw_read_close,
621
    .flags= AVFMT_GENERIC_INDEX,
622
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
623
    .value = CODEC_ID_MPEG4,
624
};
625

    
626
#ifdef CONFIG_MUXERS
627
AVOutputFormat m4v_muxer = {
628
    "m4v",
629
    "raw MPEG4 video format",
630
    NULL,
631
    "m4v",
632
    0,
633
    CODEC_ID_NONE,
634
    CODEC_ID_MPEG4,
635
    NULL,
636
    raw_write_packet,
637
    .flags= AVFMT_NOTIMESTAMPS,
638
};
639
#endif //CONFIG_MUXERS
640

    
641
AVInputFormat h264_demuxer = {
642
    "h264",
643
    "raw H264 video format",
644
    0,
645
    NULL /*mpegvideo_probe*/,
646
    video_read_header,
647
    raw_read_partial_packet,
648
    raw_read_close,
649
    .flags= AVFMT_GENERIC_INDEX,
650
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
651
    .value = CODEC_ID_H264,
652
};
653

    
654
#ifdef CONFIG_MUXERS
655
AVOutputFormat h264_muxer = {
656
    "h264",
657
    "raw H264 video format",
658
    NULL,
659
    "h264",
660
    0,
661
    CODEC_ID_NONE,
662
    CODEC_ID_H264,
663
    NULL,
664
    raw_write_packet,
665
    .flags= AVFMT_NOTIMESTAMPS,
666
};
667
#endif //CONFIG_MUXERS
668

    
669
AVInputFormat mpegvideo_demuxer = {
670
    "mpegvideo",
671
    "MPEG video",
672
    0,
673
    mpegvideo_probe,
674
    video_read_header,
675
    raw_read_partial_packet,
676
    raw_read_close,
677
    .flags= AVFMT_GENERIC_INDEX,
678
    .value = CODEC_ID_MPEG1VIDEO,
679
};
680

    
681
#ifdef CONFIG_MUXERS
682
AVOutputFormat mpeg1video_muxer = {
683
    "mpeg1video",
684
    "MPEG video",
685
    "video/x-mpeg",
686
    "mpg,mpeg,m1v",
687
    0,
688
    0,
689
    CODEC_ID_MPEG1VIDEO,
690
    NULL,
691
    raw_write_packet,
692
    .flags= AVFMT_NOTIMESTAMPS,
693
};
694
#endif //CONFIG_MUXERS
695

    
696
#ifdef CONFIG_MUXERS
697
AVOutputFormat mpeg2video_muxer = {
698
    "mpeg2video",
699
    "MPEG2 video",
700
    NULL,
701
    "m2v",
702
    0,
703
    0,
704
    CODEC_ID_MPEG2VIDEO,
705
    NULL,
706
    raw_write_packet,
707
    .flags= AVFMT_NOTIMESTAMPS,
708
};
709
#endif //CONFIG_MUXERS
710

    
711
AVInputFormat mjpeg_demuxer = {
712
    "mjpeg",
713
    "MJPEG video",
714
    0,
715
    NULL,
716
    video_read_header,
717
    raw_read_partial_packet,
718
    raw_read_close,
719
    .flags= AVFMT_GENERIC_INDEX,
720
    .extensions = "mjpg,mjpeg",
721
    .value = CODEC_ID_MJPEG,
722
};
723

    
724
AVInputFormat ingenient_demuxer = {
725
    "ingenient",
726
    "Ingenient MJPEG",
727
    0,
728
    NULL,
729
    video_read_header,
730
    ingenient_read_packet,
731
    raw_read_close,
732
    .flags= AVFMT_GENERIC_INDEX,
733
    .extensions = "cgi", // FIXME
734
    .value = CODEC_ID_MJPEG,
735
};
736

    
737
#ifdef CONFIG_MUXERS
738
AVOutputFormat mjpeg_muxer = {
739
    "mjpeg",
740
    "MJPEG video",
741
    "video/x-mjpeg",
742
    "mjpg,mjpeg",
743
    0,
744
    0,
745
    CODEC_ID_MJPEG,
746
    NULL,
747
    raw_write_packet,
748
    .flags= AVFMT_NOTIMESTAMPS,
749
};
750
#endif //CONFIG_MUXERS
751

    
752
AVInputFormat vc1_demuxer = {
753
    "vc1",
754
    "raw vc1",
755
    0,
756
    NULL /* vc1_probe */,
757
    video_read_header,
758
    raw_read_partial_packet,
759
    raw_read_close,
760
    .extensions = "vc1",
761
    .value = CODEC_ID_VC1,
762
};
763

    
764
/* pcm formats */
765

    
766
#define PCMINPUTDEF(name, long_name, ext, codec) \
767
AVInputFormat pcm_ ## name ## _demuxer = {\
768
    #name,\
769
    long_name,\
770
    0,\
771
    NULL,\
772
    raw_read_header,\
773
    raw_read_packet,\
774
    raw_read_close,\
775
    pcm_read_seek,\
776
    .flags= AVFMT_GENERIC_INDEX,\
777
    .extensions = ext,\
778
    .value = codec,\
779
};
780

    
781
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
782
AVOutputFormat pcm_ ## name ## _muxer = {\
783
    #name,\
784
    long_name,\
785
    NULL,\
786
    ext,\
787
    0,\
788
    codec,\
789
    0,\
790
    NULL,\
791
    raw_write_packet,\
792
    .flags= AVFMT_NOTIMESTAMPS,\
793
};
794

    
795

    
796
#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
797
#define PCMDEF(name, long_name, ext, codec) \
798
        PCMINPUTDEF(name, long_name, ext, codec)
799
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
800
#define PCMDEF(name, long_name, ext, codec) \
801
        PCMOUTPUTDEF(name, long_name, ext, codec)
802
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
803
#define PCMDEF(name, long_name, ext, codec) \
804
        PCMINPUTDEF(name, long_name, ext, codec)\
805
        PCMOUTPUTDEF(name, long_name, ext, codec)
806
#else
807
#define PCMDEF(name, long_name, ext, codec)
808
#endif
809

    
810
#ifdef WORDS_BIGENDIAN
811
#define BE_DEF(s) s
812
#define LE_DEF(s) NULL
813
#else
814
#define BE_DEF(s) NULL
815
#define LE_DEF(s) s
816
#endif
817

    
818

    
819
PCMDEF(s16le, "pcm signed 16 bit little endian format",
820
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
821

    
822
PCMDEF(s16be, "pcm signed 16 bit big endian format",
823
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
824

    
825
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
826
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
827

    
828
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
829
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
830

    
831
PCMDEF(s8, "pcm signed 8 bit format",
832
       "sb", CODEC_ID_PCM_S8)
833

    
834
PCMDEF(u8, "pcm unsigned 8 bit format",
835
       "ub", CODEC_ID_PCM_U8)
836

    
837
PCMDEF(mulaw, "pcm mu law format",
838
       "ul", CODEC_ID_PCM_MULAW)
839

    
840
PCMDEF(alaw, "pcm A law format",
841
       "al", CODEC_ID_PCM_ALAW)
842

    
843
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
844
{
845
    int packet_size, ret, width, height;
846
    AVStream *st = s->streams[0];
847

    
848
    width = st->codec->width;
849
    height = st->codec->height;
850

    
851
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
852
    if (packet_size < 0)
853
        return -1;
854

    
855
    ret= av_get_packet(s->pb, pkt, packet_size);
856
    pkt->pts=
857
    pkt->dts= pkt->pos / packet_size;
858

    
859
    pkt->stream_index = 0;
860
    if (ret != packet_size) {
861
        return AVERROR(EIO);
862
    } else {
863
        return 0;
864
    }
865
}
866

    
867
AVInputFormat rawvideo_demuxer = {
868
    "rawvideo",
869
    "raw video format",
870
    0,
871
    NULL,
872
    raw_read_header,
873
    rawvideo_read_packet,
874
    raw_read_close,
875
    .flags= AVFMT_GENERIC_INDEX,
876
    .extensions = "yuv,cif,qcif,rgb",
877
    .value = CODEC_ID_RAWVIDEO,
878
};
879

    
880
#ifdef CONFIG_MUXERS
881
AVOutputFormat rawvideo_muxer = {
882
    "rawvideo",
883
    "raw video format",
884
    NULL,
885
    "yuv,rgb",
886
    0,
887
    CODEC_ID_NONE,
888
    CODEC_ID_RAWVIDEO,
889
    NULL,
890
    raw_write_packet,
891
    .flags= AVFMT_NOTIMESTAMPS,
892
};
893
#endif //CONFIG_MUXERS
894

    
895
#ifdef CONFIG_MUXERS
896
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
897
{
898
    return 0;
899
}
900

    
901
AVOutputFormat null_muxer = {
902
    "null",
903
    "null video format",
904
    NULL,
905
    NULL,
906
    0,
907
#ifdef WORDS_BIGENDIAN
908
    CODEC_ID_PCM_S16BE,
909
#else
910
    CODEC_ID_PCM_S16LE,
911
#endif
912
    CODEC_ID_RAWVIDEO,
913
    NULL,
914
    null_write_packet,
915
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
916
};
917
#endif //CONFIG_MUXERS