Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 7e1720de

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
#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
            av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
89
            st->codec->width = ap->width;
90
            st->codec->height = ap->height;
91
            st->codec->pix_fmt = ap->pix_fmt;
92
            if(st->codec->pix_fmt == PIX_FMT_NONE)
93
                st->codec->pix_fmt= PIX_FMT_YUV420P;
94
            break;
95
        default:
96
            return -1;
97
        }
98
    return 0;
99
}
100

    
101
#define RAW_PACKET_SIZE 1024
102

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

    
108
    size= RAW_PACKET_SIZE;
109

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

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

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

    
126
    size = RAW_PACKET_SIZE;
127

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

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

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

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

    
150
    size = get_le32(s->pb);
151

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
319
    return 0;
320
}
321

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

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

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

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

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

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

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

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

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

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

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

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

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

    
413
    max_frames = 0;
414
    buf = p->buf;
415
    end = buf + p->buf_size;
416

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
755
/* pcm formats */
756

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

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

    
786

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

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

    
809

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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