Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 0a5790d1

History | View | Annotate | Download (20.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
#include "avformat.h"
23
#include "ac3_parser.h"
24

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

    
41

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

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

    
51
    return 0;
52
}
53

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

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

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

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

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

    
100
#define RAW_PACKET_SIZE 1024
101

    
102
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
103
{
104
    int ret, size;
105
    //    AVStream *st = s->streams[0];
106

    
107
    size= RAW_PACKET_SIZE;
108

    
109
    ret= av_get_packet(&s->pb, pkt, size);
110

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

    
121
static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
122
{
123
    int ret, size;
124

    
125
    size = RAW_PACKET_SIZE;
126

    
127
    if (av_new_packet(pkt, size) < 0)
128
        return AVERROR(EIO);
129

    
130
    pkt->pos= url_ftell(&s->pb);
131
    pkt->stream_index = 0;
132
    ret = get_partial_buffer(&s->pb, pkt->data, size);
133
    if (ret <= 0) {
134
        av_free_packet(pkt);
135
        return AVERROR(EIO);
136
    }
137
    pkt->size = ret;
138
    return ret;
139
}
140

    
141
// http://www.artificis.hu/files/texts/ingenient.txt
142
static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
143
{
144
    int ret, size, w, h, unk1, unk2;
145

    
146
    if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
147
        return AVERROR(EIO); // FIXME
148

    
149
    size = get_le32(&s->pb);
150

    
151
    w = get_le16(&s->pb);
152
    h = get_le16(&s->pb);
153

    
154
    url_fskip(&s->pb, 8); // zero + size (padded?)
155
    url_fskip(&s->pb, 2);
156
    unk1 = get_le16(&s->pb);
157
    unk2 = get_le16(&s->pb);
158
    url_fskip(&s->pb, 22); // ascii timestamp
159

    
160
    av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
161
        size, w, h, unk1, unk2);
162

    
163
    if (av_new_packet(pkt, size) < 0)
164
        return AVERROR(EIO);
165

    
166
    pkt->pos = url_ftell(&s->pb);
167
    pkt->stream_index = 0;
168
    ret = get_buffer(&s->pb, pkt->data, size);
169
    if (ret <= 0) {
170
        av_free_packet(pkt);
171
        return AVERROR(EIO);
172
    }
173
    pkt->size = ret;
174
    return ret;
175
}
176

    
177
static int raw_read_close(AVFormatContext *s)
178
{
179
    return 0;
180
}
181

    
182
int pcm_read_seek(AVFormatContext *s,
183
                  int stream_index, int64_t timestamp, int flags)
184
{
185
    AVStream *st;
186
    int block_align, byte_rate;
187
    int64_t pos;
188

    
189
    st = s->streams[0];
190

    
191
    block_align = st->codec->block_align ? st->codec->block_align :
192
        (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
193
    byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
194
        block_align * st->codec->sample_rate;
195

    
196
    if (block_align <= 0 || byte_rate <= 0)
197
        return -1;
198

    
199
    /* compute the position by aligning it to block_align */
200
    pos = av_rescale_rnd(timestamp * byte_rate,
201
                         st->time_base.num,
202
                         st->time_base.den * (int64_t)block_align,
203
                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
204
    pos *= block_align;
205

    
206
    /* recompute exact position */
207
    st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
208
    url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
209
    return 0;
210
}
211

    
212
/* ac3 read */
213
static int ac3_read_header(AVFormatContext *s,
214
                           AVFormatParameters *ap)
215
{
216
    AVStream *st;
217

    
218
    st = av_new_stream(s, 0);
219
    if (!st)
220
        return AVERROR(ENOMEM);
221

    
222
    st->codec->codec_type = CODEC_TYPE_AUDIO;
223
    st->codec->codec_id = CODEC_ID_AC3;
224
    st->need_parsing = AVSTREAM_PARSE_FULL;
225
    /* the parameters will be extracted from the compressed bitstream */
226
    return 0;
227
}
228

    
229
static int shorten_read_header(AVFormatContext *s,
230
                               AVFormatParameters *ap)
231
{
232
    AVStream *st;
233

    
234
    st = av_new_stream(s, 0);
235
    if (!st)
236
        return AVERROR(ENOMEM);
237
    st->codec->codec_type = CODEC_TYPE_AUDIO;
238
    st->codec->codec_id = CODEC_ID_SHORTEN;
239
    st->need_parsing = AVSTREAM_PARSE_FULL;
240
    /* the parameters will be extracted from the compressed bitstream */
241
    return 0;
242
}
243

    
244
/* flac read */
245
static int flac_read_header(AVFormatContext *s,
246
                            AVFormatParameters *ap)
247
{
248
    AVStream *st;
249

    
250
    st = av_new_stream(s, 0);
251
    if (!st)
252
        return AVERROR(ENOMEM);
253
    st->codec->codec_type = CODEC_TYPE_AUDIO;
254
    st->codec->codec_id = CODEC_ID_FLAC;
255
    st->need_parsing = AVSTREAM_PARSE_FULL;
256
    /* the parameters will be extracted from the compressed bitstream */
257
    return 0;
258
}
259

    
260
/* dts read */
261
static int dts_read_header(AVFormatContext *s,
262
                           AVFormatParameters *ap)
263
{
264
    AVStream *st;
265

    
266
    st = av_new_stream(s, 0);
267
    if (!st)
268
        return AVERROR(ENOMEM);
269

    
270
    st->codec->codec_type = CODEC_TYPE_AUDIO;
271
    st->codec->codec_id = CODEC_ID_DTS;
272
    st->need_parsing = AVSTREAM_PARSE_FULL;
273
    /* the parameters will be extracted from the compressed bitstream */
274
    return 0;
275
}
276

    
277
/* aac read */
278
static int aac_read_header(AVFormatContext *s,
279
                           AVFormatParameters *ap)
280
{
281
    AVStream *st;
282

    
283
    st = av_new_stream(s, 0);
284
    if (!st)
285
        return AVERROR(ENOMEM);
286

    
287
    st->codec->codec_type = CODEC_TYPE_AUDIO;
288
    st->codec->codec_id = CODEC_ID_AAC;
289
    st->need_parsing = AVSTREAM_PARSE_FULL;
290
    /* the parameters will be extracted from the compressed bitstream */
291
    return 0;
292
}
293

    
294
/* mpeg1/h263 input */
295
static int video_read_header(AVFormatContext *s,
296
                             AVFormatParameters *ap)
297
{
298
    AVStream *st;
299

    
300
    st = av_new_stream(s, 0);
301
    if (!st)
302
        return AVERROR(ENOMEM);
303

    
304
    st->codec->codec_type = CODEC_TYPE_VIDEO;
305
    st->codec->codec_id = s->iformat->value;
306
    st->need_parsing = AVSTREAM_PARSE_FULL;
307

    
308
    /* for mjpeg, specify frame rate */
309
    /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
310
    if (ap->time_base.num) {
311
        av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
312
    } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
313
                st->codec->codec_id == CODEC_ID_MPEG4 ||
314
                st->codec->codec_id == CODEC_ID_H264) {
315
        av_set_pts_info(st, 64, 1, 25);
316
    }
317

    
318
    return 0;
319
}
320

    
321
#define SEQ_START_CODE          0x000001b3
322
#define GOP_START_CODE          0x000001b8
323
#define PICTURE_START_CODE      0x00000100
324
#define SLICE_START_CODE        0x00000101
325
#define PACK_START_CODE         0x000001ba
326
#define VIDEO_ID                0x000001e0
327
#define AUDIO_ID                0x000001c0
328

    
329
static int mpegvideo_probe(AVProbeData *p)
330
{
331
    uint32_t code= -1;
332
    int pic=0, seq=0, slice=0, pspack=0, pes=0;
333
    int i;
334

    
335
    for(i=0; i<p->buf_size; i++){
336
        code = (code<<8) + p->buf[i];
337
        if ((code & 0xffffff00) == 0x100) {
338
            switch(code){
339
            case     SEQ_START_CODE:   seq++; break;
340
            case PICTURE_START_CODE:   pic++; break;
341
            case   SLICE_START_CODE: slice++; break;
342
            case    PACK_START_CODE: pspack++; break;
343
            }
344
            if     ((code & 0x1f0) == VIDEO_ID)   pes++;
345
            else if((code & 0x1e0) == AUDIO_ID)   pes++;
346
        }
347
    }
348
    if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
349
        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
350
    return 0;
351
}
352

    
353
#define VISUAL_OBJECT_START_CODE       0x000001b5
354
#define VOP_START_CODE                 0x000001b6
355

    
356
static int mpeg4video_probe(AVProbeData *probe_packet)
357
{
358
    uint32_t temp_buffer= -1;
359
    int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
360
    int i;
361

    
362
    for(i=0; i<probe_packet->buf_size; i++){
363
        temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
364
        if ((temp_buffer & 0xffffff00) != 0x100)
365
            continue;
366

    
367
        if (temp_buffer == VOP_START_CODE)                         VOP++;
368
        else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
369
        else if (temp_buffer < 0x120)                              VO++;
370
        else if (temp_buffer < 0x130)                              VOL++;
371
        else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
372
                 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
373
    }
374

    
375
    if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
376
        return AVPROBE_SCORE_MAX/2;
377
    return 0;
378
}
379

    
380
static int h263_probe(AVProbeData *p)
381
{
382
    int code;
383
    const uint8_t *d;
384

    
385
    d = p->buf;
386
    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
387
    if (code == 0x20) {
388
        return 50;
389
    }
390
    return 0;
391
}
392

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

    
398
    d = p->buf;
399
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
400
    if (code == 0x10) {
401
        return 50;
402
    }
403
    return 0;
404
}
405

    
406
static int ac3_probe(AVProbeData *p)
407
{
408
    int max_frames, first_frames = 0, frames;
409
    uint8_t *buf, *buf2, *end;
410
    AC3HeaderInfo hdr;
411

    
412
    if(p->buf_size < 7)
413
        return 0;
414

    
415
    max_frames = 0;
416
    buf = p->buf;
417
    end = buf + p->buf_size;
418

    
419
    for(; buf < end; buf++) {
420
        buf2 = buf;
421

    
422
        for(frames = 0; buf2 < end; frames++) {
423
            if(ff_ac3_parse_header(buf2, &hdr) < 0)
424
                break;
425
            buf2 += hdr.frame_size;
426
        }
427
        max_frames = FFMAX(max_frames, frames);
428
        if(buf == p->buf)
429
            first_frames = frames;
430
    }
431
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
432
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
433
    else if(max_frames>=1) return 1;
434
    else                   return 0;
435
}
436

    
437
AVInputFormat shorten_demuxer = {
438
    "shn",
439
    "raw shorten",
440
    0,
441
    NULL,
442
    shorten_read_header,
443
    raw_read_partial_packet,
444
    raw_read_close,
445
    .flags= AVFMT_GENERIC_INDEX,
446
    .extensions = "shn",
447
};
448

    
449
AVInputFormat flac_demuxer = {
450
    "flac",
451
    "raw flac",
452
    0,
453
    NULL,
454
    flac_read_header,
455
    raw_read_partial_packet,
456
    raw_read_close,
457
    .flags= AVFMT_GENERIC_INDEX,
458
    .extensions = "flac",
459
};
460

    
461
#ifdef CONFIG_MUXERS
462
AVOutputFormat flac_muxer = {
463
    "flac",
464
    "raw flac",
465
    "audio/x-flac",
466
    "flac",
467
    0,
468
    CODEC_ID_FLAC,
469
    0,
470
    flac_write_header,
471
    raw_write_packet,
472
    .flags= AVFMT_NOTIMESTAMPS,
473
};
474
#endif //CONFIG_MUXERS
475

    
476
#ifdef CONFIG_AC3_DEMUXER
477
AVInputFormat ac3_demuxer = {
478
    "ac3",
479
    "raw ac3",
480
    0,
481
    ac3_probe,
482
    ac3_read_header,
483
    raw_read_partial_packet,
484
    raw_read_close,
485
    .flags= AVFMT_GENERIC_INDEX,
486
    .extensions = "ac3",
487
};
488
#endif
489

    
490
#ifdef CONFIG_MUXERS
491
AVOutputFormat ac3_muxer = {
492
    "ac3",
493
    "raw ac3",
494
    "audio/x-ac3",
495
    "ac3",
496
    0,
497
    CODEC_ID_AC3,
498
    0,
499
    NULL,
500
    raw_write_packet,
501
    .flags= AVFMT_NOTIMESTAMPS,
502
};
503
#endif //CONFIG_MUXERS
504

    
505
AVInputFormat dts_demuxer = {
506
    "dts",
507
    "raw dts",
508
    0,
509
    NULL,
510
    dts_read_header,
511
    raw_read_partial_packet,
512
    raw_read_close,
513
    .flags= AVFMT_GENERIC_INDEX,
514
    .extensions = "dts",
515
};
516

    
517
AVInputFormat aac_demuxer = {
518
    "aac",
519
    "ADTS AAC",
520
    0,
521
    NULL,
522
    aac_read_header,
523
    raw_read_partial_packet,
524
    raw_read_close,
525
    .flags= AVFMT_GENERIC_INDEX,
526
    .extensions = "aac",
527
};
528

    
529
#ifdef CONFIG_ROQ_MUXER
530
AVOutputFormat roq_muxer =
531
{
532
    "RoQ",
533
    "Id RoQ format",
534
    NULL,
535
    "roq",
536
    0,
537
    CODEC_ID_ROQ_DPCM,
538
    CODEC_ID_ROQ,
539
    roq_write_header,
540
    raw_write_packet,
541
};
542
#endif //CONFIG_ROQ_MUXER
543

    
544
AVInputFormat h261_demuxer = {
545
    "h261",
546
    "raw h261",
547
    0,
548
    h261_probe,
549
    video_read_header,
550
    raw_read_partial_packet,
551
    raw_read_close,
552
    .flags= AVFMT_GENERIC_INDEX,
553
    .extensions = "h261",
554
    .value = CODEC_ID_H261,
555
};
556

    
557
#ifdef CONFIG_MUXERS
558
AVOutputFormat h261_muxer = {
559
    "h261",
560
    "raw h261",
561
    "video/x-h261",
562
    "h261",
563
    0,
564
    0,
565
    CODEC_ID_H261,
566
    NULL,
567
    raw_write_packet,
568
    .flags= AVFMT_NOTIMESTAMPS,
569
};
570
#endif //CONFIG_MUXERS
571

    
572
AVInputFormat h263_demuxer = {
573
    "h263",
574
    "raw h263",
575
    0,
576
    h263_probe,
577
    video_read_header,
578
    raw_read_partial_packet,
579
    raw_read_close,
580
    .flags= AVFMT_GENERIC_INDEX,
581
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
582
    .value = CODEC_ID_H263,
583
};
584

    
585
#ifdef CONFIG_MUXERS
586
AVOutputFormat h263_muxer = {
587
    "h263",
588
    "raw h263",
589
    "video/x-h263",
590
    "h263",
591
    0,
592
    0,
593
    CODEC_ID_H263,
594
    NULL,
595
    raw_write_packet,
596
    .flags= AVFMT_NOTIMESTAMPS,
597
};
598
#endif //CONFIG_MUXERS
599

    
600
AVInputFormat m4v_demuxer = {
601
    "m4v",
602
    "raw MPEG4 video format",
603
    0,
604
    mpeg4video_probe, /** probing for mpeg4 data */
605
    video_read_header,
606
    raw_read_partial_packet,
607
    raw_read_close,
608
    .flags= AVFMT_GENERIC_INDEX,
609
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
610
    .value = CODEC_ID_MPEG4,
611
};
612

    
613
#ifdef CONFIG_MUXERS
614
AVOutputFormat m4v_muxer = {
615
    "m4v",
616
    "raw MPEG4 video format",
617
    NULL,
618
    "m4v",
619
    0,
620
    CODEC_ID_NONE,
621
    CODEC_ID_MPEG4,
622
    NULL,
623
    raw_write_packet,
624
    .flags= AVFMT_NOTIMESTAMPS,
625
};
626
#endif //CONFIG_MUXERS
627

    
628
AVInputFormat h264_demuxer = {
629
    "h264",
630
    "raw H264 video format",
631
    0,
632
    NULL /*mpegvideo_probe*/,
633
    video_read_header,
634
    raw_read_partial_packet,
635
    raw_read_close,
636
    .flags= AVFMT_GENERIC_INDEX,
637
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
638
    .value = CODEC_ID_H264,
639
};
640

    
641
#ifdef CONFIG_MUXERS
642
AVOutputFormat h264_muxer = {
643
    "h264",
644
    "raw H264 video format",
645
    NULL,
646
    "h264",
647
    0,
648
    CODEC_ID_NONE,
649
    CODEC_ID_H264,
650
    NULL,
651
    raw_write_packet,
652
    .flags= AVFMT_NOTIMESTAMPS,
653
};
654
#endif //CONFIG_MUXERS
655

    
656
AVInputFormat mpegvideo_demuxer = {
657
    "mpegvideo",
658
    "MPEG video",
659
    0,
660
    mpegvideo_probe,
661
    video_read_header,
662
    raw_read_partial_packet,
663
    raw_read_close,
664
    .flags= AVFMT_GENERIC_INDEX,
665
    .value = CODEC_ID_MPEG1VIDEO,
666
};
667

    
668
#ifdef CONFIG_MUXERS
669
AVOutputFormat mpeg1video_muxer = {
670
    "mpeg1video",
671
    "MPEG video",
672
    "video/x-mpeg",
673
    "mpg,mpeg,m1v",
674
    0,
675
    0,
676
    CODEC_ID_MPEG1VIDEO,
677
    NULL,
678
    raw_write_packet,
679
    .flags= AVFMT_NOTIMESTAMPS,
680
};
681
#endif //CONFIG_MUXERS
682

    
683
#ifdef CONFIG_MUXERS
684
AVOutputFormat mpeg2video_muxer = {
685
    "mpeg2video",
686
    "MPEG2 video",
687
    NULL,
688
    "m2v",
689
    0,
690
    0,
691
    CODEC_ID_MPEG2VIDEO,
692
    NULL,
693
    raw_write_packet,
694
    .flags= AVFMT_NOTIMESTAMPS,
695
};
696
#endif //CONFIG_MUXERS
697

    
698
AVInputFormat mjpeg_demuxer = {
699
    "mjpeg",
700
    "MJPEG video",
701
    0,
702
    NULL,
703
    video_read_header,
704
    raw_read_partial_packet,
705
    raw_read_close,
706
    .flags= AVFMT_GENERIC_INDEX,
707
    .extensions = "mjpg,mjpeg",
708
    .value = CODEC_ID_MJPEG,
709
};
710

    
711
AVInputFormat ingenient_demuxer = {
712
    "ingenient",
713
    "Ingenient MJPEG",
714
    0,
715
    NULL,
716
    video_read_header,
717
    ingenient_read_packet,
718
    raw_read_close,
719
    .flags= AVFMT_GENERIC_INDEX,
720
    .extensions = "cgi", // FIXME
721
    .value = CODEC_ID_MJPEG,
722
};
723

    
724
#ifdef CONFIG_MUXERS
725
AVOutputFormat mjpeg_muxer = {
726
    "mjpeg",
727
    "MJPEG video",
728
    "video/x-mjpeg",
729
    "mjpg,mjpeg",
730
    0,
731
    0,
732
    CODEC_ID_MJPEG,
733
    NULL,
734
    raw_write_packet,
735
    .flags= AVFMT_NOTIMESTAMPS,
736
};
737
#endif //CONFIG_MUXERS
738

    
739
AVInputFormat vc1_demuxer = {
740
    "vc1",
741
    "raw vc1",
742
    0,
743
    NULL /* vc1_probe */,
744
    video_read_header,
745
    raw_read_partial_packet,
746
    raw_read_close,
747
    .extensions = "vc1",
748
    .value = CODEC_ID_VC1,
749
};
750

    
751
/* pcm formats */
752

    
753
#define PCMINPUTDEF(name, long_name, ext, codec) \
754
AVInputFormat pcm_ ## name ## _demuxer = {\
755
    #name,\
756
    long_name,\
757
    0,\
758
    NULL,\
759
    raw_read_header,\
760
    raw_read_packet,\
761
    raw_read_close,\
762
    pcm_read_seek,\
763
    .flags= AVFMT_GENERIC_INDEX,\
764
    .extensions = ext,\
765
    .value = codec,\
766
};
767

    
768
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
769
AVOutputFormat pcm_ ## name ## _muxer = {\
770
    #name,\
771
    long_name,\
772
    NULL,\
773
    ext,\
774
    0,\
775
    codec,\
776
    0,\
777
    NULL,\
778
    raw_write_packet,\
779
    .flags= AVFMT_NOTIMESTAMPS,\
780
};
781

    
782

    
783
#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
784
#define PCMDEF(name, long_name, ext, codec) \
785
        PCMINPUTDEF(name, long_name, ext, codec)
786
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
787
#define PCMDEF(name, long_name, ext, codec) \
788
        PCMOUTPUTDEF(name, long_name, ext, codec)
789
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
790
#define PCMDEF(name, long_name, ext, codec) \
791
        PCMINPUTDEF(name, long_name, ext, codec)\
792
        PCMOUTPUTDEF(name, long_name, ext, codec)
793
#else
794
#define PCMDEF(name, long_name, ext, codec)
795
#endif
796

    
797
#ifdef WORDS_BIGENDIAN
798
#define BE_DEF(s) s
799
#define LE_DEF(s) NULL
800
#else
801
#define BE_DEF(s) NULL
802
#define LE_DEF(s) s
803
#endif
804

    
805

    
806
PCMDEF(s16le, "pcm signed 16 bit little endian format",
807
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
808

    
809
PCMDEF(s16be, "pcm signed 16 bit big endian format",
810
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
811

    
812
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
813
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
814

    
815
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
816
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
817

    
818
PCMDEF(s8, "pcm signed 8 bit format",
819
       "sb", CODEC_ID_PCM_S8)
820

    
821
PCMDEF(u8, "pcm unsigned 8 bit format",
822
       "ub", CODEC_ID_PCM_U8)
823

    
824
PCMDEF(mulaw, "pcm mu law format",
825
       "ul", CODEC_ID_PCM_MULAW)
826

    
827
PCMDEF(alaw, "pcm A law format",
828
       "al", CODEC_ID_PCM_ALAW)
829

    
830
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
831
{
832
    int packet_size, ret, width, height;
833
    AVStream *st = s->streams[0];
834

    
835
    width = st->codec->width;
836
    height = st->codec->height;
837

    
838
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
839
    if (packet_size < 0)
840
        return -1;
841

    
842
    ret= av_get_packet(&s->pb, pkt, packet_size);
843

    
844
    pkt->stream_index = 0;
845
    if (ret != packet_size) {
846
        return AVERROR(EIO);
847
    } else {
848
        return 0;
849
    }
850
}
851

    
852
AVInputFormat rawvideo_demuxer = {
853
    "rawvideo",
854
    "raw video format",
855
    0,
856
    NULL,
857
    raw_read_header,
858
    rawvideo_read_packet,
859
    raw_read_close,
860
    .flags= AVFMT_GENERIC_INDEX,
861
    .extensions = "yuv,cif,qcif,rgb",
862
    .value = CODEC_ID_RAWVIDEO,
863
};
864

    
865
#ifdef CONFIG_MUXERS
866
AVOutputFormat rawvideo_muxer = {
867
    "rawvideo",
868
    "raw video format",
869
    NULL,
870
    "yuv,rgb",
871
    0,
872
    CODEC_ID_NONE,
873
    CODEC_ID_RAWVIDEO,
874
    NULL,
875
    raw_write_packet,
876
    .flags= AVFMT_NOTIMESTAMPS,
877
};
878
#endif //CONFIG_MUXERS
879

    
880
#ifdef CONFIG_MUXERS
881
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
882
{
883
    return 0;
884
}
885

    
886
AVOutputFormat null_muxer = {
887
    "null",
888
    "null video format",
889
    NULL,
890
    NULL,
891
    0,
892
#ifdef WORDS_BIGENDIAN
893
    CODEC_ID_PCM_S16BE,
894
#else
895
    CODEC_ID_PCM_S16LE,
896
#endif
897
    CODEC_ID_RAWVIDEO,
898
    NULL,
899
    null_write_packet,
900
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
901
};
902
#endif //CONFIG_MUXERS