Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ d2062ff6

History | View | Annotate | Download (20.8 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
    max_frames = 0;
413
    buf = p->buf;
414
    end = buf + p->buf_size;
415

    
416
    for(; buf < end; buf++) {
417
        buf2 = buf;
418

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

    
434
static int flac_probe(AVProbeData *p)
435
{
436
    if(memcmp(p->buf, "fLaC", 4)) return 0;
437
    else                          return AVPROBE_SCORE_MAX / 2;
438
}
439

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

    
452
AVInputFormat flac_demuxer = {
453
    "flac",
454
    "raw flac",
455
    0,
456
    flac_probe,
457
    flac_read_header,
458
    raw_read_partial_packet,
459
    raw_read_close,
460
    .flags= AVFMT_GENERIC_INDEX,
461
    .extensions = "flac",
462
};
463

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
754
/* pcm formats */
755

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

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

    
785

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

    
800
#ifdef WORDS_BIGENDIAN
801
#define BE_DEF(s) s
802
#define LE_DEF(s) NULL
803
#else
804
#define BE_DEF(s) NULL
805
#define LE_DEF(s) s
806
#endif
807

    
808

    
809
PCMDEF(s16le, "pcm signed 16 bit little endian format",
810
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
811

    
812
PCMDEF(s16be, "pcm signed 16 bit big endian format",
813
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
814

    
815
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
816
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
817

    
818
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
819
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
820

    
821
PCMDEF(s8, "pcm signed 8 bit format",
822
       "sb", CODEC_ID_PCM_S8)
823

    
824
PCMDEF(u8, "pcm unsigned 8 bit format",
825
       "ub", CODEC_ID_PCM_U8)
826

    
827
PCMDEF(mulaw, "pcm mu law format",
828
       "ul", CODEC_ID_PCM_MULAW)
829

    
830
PCMDEF(alaw, "pcm A law format",
831
       "al", CODEC_ID_PCM_ALAW)
832

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

    
838
    width = st->codec->width;
839
    height = st->codec->height;
840

    
841
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
842
    if (packet_size < 0)
843
        return -1;
844

    
845
    ret= av_get_packet(&s->pb, pkt, packet_size);
846

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

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

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

    
883
#ifdef CONFIG_MUXERS
884
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
885
{
886
    return 0;
887
}
888

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