Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ e9b78eeb

History | View | Annotate | Download (19.6 KB)

1
/*
2
 * RAW muxer and demuxer
3
 * Copyright (c) 2001 Fabrice Bellard.
4
 * Copyright (c) 2005 Alex Beregszaszi
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22
#include "avformat.h"
23

    
24
#ifdef CONFIG_MUXERS
25
/* simple formats */
26
static int raw_write_header(struct AVFormatContext *s)
27
{
28
    return 0;
29
}
30

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

    
45
static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
46
{
47
    put_buffer(&s->pb, pkt->data, pkt->size);
48
    put_flush_packet(&s->pb);
49
    return 0;
50
}
51

    
52
static int raw_write_trailer(struct AVFormatContext *s)
53
{
54
    return 0;
55
}
56
#endif //CONFIG_MUXERS
57

    
58
/* raw input */
59
static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
60
{
61
    AVStream *st;
62
    int id;
63

    
64
    st = av_new_stream(s, 0);
65
    if (!st)
66
        return AVERROR_NOMEM;
67

    
68
        id = s->iformat->value;
69
        if (id == CODEC_ID_RAWVIDEO) {
70
            st->codec->codec_type = CODEC_TYPE_VIDEO;
71
        } else {
72
            st->codec->codec_type = CODEC_TYPE_AUDIO;
73
        }
74
        st->codec->codec_id = id;
75

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

    
96
#define RAW_PACKET_SIZE 1024
97

    
98
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
99
{
100
    int ret, size;
101
    //    AVStream *st = s->streams[0];
102

    
103
    size= RAW_PACKET_SIZE;
104

    
105
    ret= av_get_packet(&s->pb, pkt, size);
106

    
107
    pkt->stream_index = 0;
108
    if (ret <= 0) {
109
        return AVERROR_IO;
110
    }
111
    /* note: we need to modify the packet size here to handle the last
112
       packet */
113
    pkt->size = ret;
114
    return ret;
115
}
116

    
117
static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
118
{
119
    int ret, size;
120

    
121
    size = RAW_PACKET_SIZE;
122

    
123
    if (av_new_packet(pkt, size) < 0)
124
        return AVERROR_IO;
125

    
126
    pkt->pos= url_ftell(&s->pb);
127
    pkt->stream_index = 0;
128
    ret = get_partial_buffer(&s->pb, pkt->data, size);
129
    if (ret <= 0) {
130
        av_free_packet(pkt);
131
        return AVERROR_IO;
132
    }
133
    pkt->size = ret;
134
    return ret;
135
}
136

    
137
// http://www.artificis.hu/files/texts/ingenient.txt
138
static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
139
{
140
    int ret, size, w, h, unk1, unk2;
141

    
142
    if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
143
        return AVERROR_IO; // FIXME
144

    
145
    size = get_le32(&s->pb);
146

    
147
    w = get_le16(&s->pb);
148
    h = get_le16(&s->pb);
149

    
150
    url_fskip(&s->pb, 8); // zero + size (padded?)
151
    url_fskip(&s->pb, 2);
152
    unk1 = get_le16(&s->pb);
153
    unk2 = get_le16(&s->pb);
154
    url_fskip(&s->pb, 22); // ascii timestamp
155

    
156
    av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
157
        size, w, h, unk1, unk2);
158

    
159
    if (av_new_packet(pkt, size) < 0)
160
        return AVERROR_IO;
161

    
162
    pkt->pos = url_ftell(&s->pb);
163
    pkt->stream_index = 0;
164
    ret = get_buffer(&s->pb, pkt->data, size);
165
    if (ret <= 0) {
166
        av_free_packet(pkt);
167
        return AVERROR_IO;
168
    }
169
    pkt->size = ret;
170
    return ret;
171
}
172

    
173
static int raw_read_close(AVFormatContext *s)
174
{
175
    return 0;
176
}
177

    
178
int pcm_read_seek(AVFormatContext *s,
179
                  int stream_index, int64_t timestamp, int flags)
180
{
181
    AVStream *st;
182
    int block_align, byte_rate;
183
    int64_t pos;
184

    
185
    st = s->streams[0];
186

    
187
    block_align = st->codec->block_align ? st->codec->block_align :
188
        (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
189
    byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
190
        block_align * st->codec->sample_rate;
191

    
192
    if (block_align <= 0 || byte_rate <= 0)
193
        return -1;
194

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

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

    
208
/* ac3 read */
209
static int ac3_read_header(AVFormatContext *s,
210
                           AVFormatParameters *ap)
211
{
212
    AVStream *st;
213

    
214
    st = av_new_stream(s, 0);
215
    if (!st)
216
        return AVERROR_NOMEM;
217

    
218
    st->codec->codec_type = CODEC_TYPE_AUDIO;
219
    st->codec->codec_id = CODEC_ID_AC3;
220
    st->need_parsing = 1;
221
    /* the parameters will be extracted from the compressed bitstream */
222
    return 0;
223
}
224

    
225
static int shorten_read_header(AVFormatContext *s,
226
                               AVFormatParameters *ap)
227
{
228
    AVStream *st;
229

    
230
    st = av_new_stream(s, 0);
231
    if (!st)
232
        return AVERROR_NOMEM;
233
    st->codec->codec_type = CODEC_TYPE_AUDIO;
234
    st->codec->codec_id = CODEC_ID_SHORTEN;
235
    st->need_parsing = 1;
236
    /* the parameters will be extracted from the compressed bitstream */
237
    return 0;
238
}
239

    
240
/* flac read */
241
static int flac_read_header(AVFormatContext *s,
242
                            AVFormatParameters *ap)
243
{
244
    AVStream *st;
245

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

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

    
262
    st = av_new_stream(s, 0);
263
    if (!st)
264
        return AVERROR_NOMEM;
265

    
266
    st->codec->codec_type = CODEC_TYPE_AUDIO;
267
    st->codec->codec_id = CODEC_ID_DTS;
268
    st->need_parsing = 1;
269
    /* the parameters will be extracted from the compressed bitstream */
270
    return 0;
271
}
272

    
273
/* aac read */
274
static int aac_read_header(AVFormatContext *s,
275
                           AVFormatParameters *ap)
276
{
277
    AVStream *st;
278

    
279
    st = av_new_stream(s, 0);
280
    if (!st)
281
        return AVERROR_NOMEM;
282

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

    
290
/* mpeg1/h263 input */
291
static int video_read_header(AVFormatContext *s,
292
                             AVFormatParameters *ap)
293
{
294
    AVStream *st;
295

    
296
    st = av_new_stream(s, 0);
297
    if (!st)
298
        return AVERROR_NOMEM;
299

    
300
    st->codec->codec_type = CODEC_TYPE_VIDEO;
301
    st->codec->codec_id = s->iformat->value;
302
    st->need_parsing = 1;
303

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

    
314
    return 0;
315
}
316

    
317
#define SEQ_START_CODE          0x000001b3
318
#define GOP_START_CODE          0x000001b8
319
#define PICTURE_START_CODE      0x00000100
320
#define SLICE_START_CODE        0x00000101
321
#define PACK_START_CODE         0x000001ba
322
#define VIDEO_ID                0x000001e0
323
#define AUDIO_ID                0x000001c0
324

    
325
static int mpegvideo_probe(AVProbeData *p)
326
{
327
    uint32_t code= -1;
328
    int pic=0, seq=0, slice=0, pspack=0, pes=0;
329
    int i;
330

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

    
349
#define VIDEO_OBJECT_START_CODE        0x00000100
350
#define VIDEO_OBJECT_LAYER_START_CODE  0x00000120
351
#define VISUAL_OBJECT_START_CODE       0x000001b5
352
#define VOP_START_CODE                 0x000001b6
353

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

    
360
    for(i=0; i<probe_packet->buf_size; i++){
361
        temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
362
        if ((temp_buffer & 0xffffff00) == 0x100) {
363
            switch(temp_buffer){
364
            case VOP_START_CODE:             VOP++; break;
365
            case VISUAL_OBJECT_START_CODE:  VISO++; break;
366
            }
367
            switch(temp_buffer & 0xfffffff0){
368
            case VIDEO_OBJECT_START_CODE:            VO++; break;
369
            case VIDEO_OBJECT_LAYER_START_CODE:     VOL++; break;
370
            }
371
        }
372
    }
373

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

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

    
384
    if (p->buf_size < 6)
385
        return 0;
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
    if (p->buf_size < 6)
400
        return 0;
401
    d = p->buf;
402
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
403
    if (code == 0x10) {
404
        return 50;
405
    }
406
    return 0;
407
}
408

    
409
AVInputFormat shorten_demuxer = {
410
    "shn",
411
    "raw shorten",
412
    0,
413
    NULL,
414
    shorten_read_header,
415
    raw_read_partial_packet,
416
    raw_read_close,
417
    .flags= AVFMT_GENERIC_INDEX,
418
    .extensions = "shn",
419
};
420

    
421
AVInputFormat flac_demuxer = {
422
    "flac",
423
    "raw flac",
424
    0,
425
    NULL,
426
    flac_read_header,
427
    raw_read_partial_packet,
428
    raw_read_close,
429
    .flags= AVFMT_GENERIC_INDEX,
430
    .extensions = "flac",
431
};
432

    
433
#ifdef CONFIG_MUXERS
434
AVOutputFormat flac_muxer = {
435
    "flac",
436
    "raw flac",
437
    "audio/x-flac",
438
    "flac",
439
    0,
440
    CODEC_ID_FLAC,
441
    0,
442
    flac_write_header,
443
    raw_write_packet,
444
    raw_write_trailer,
445
    .flags= AVFMT_NOTIMESTAMPS,
446
};
447
#endif //CONFIG_MUXERS
448

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

    
461
#ifdef CONFIG_MUXERS
462
AVOutputFormat ac3_muxer = {
463
    "ac3",
464
    "raw ac3",
465
    "audio/x-ac3",
466
    "ac3",
467
    0,
468
    CODEC_ID_AC3,
469
    0,
470
    raw_write_header,
471
    raw_write_packet,
472
    raw_write_trailer,
473
    .flags= AVFMT_NOTIMESTAMPS,
474
};
475
#endif //CONFIG_MUXERS
476

    
477
AVInputFormat dts_demuxer = {
478
    "dts",
479
    "raw dts",
480
    0,
481
    NULL,
482
    dts_read_header,
483
    raw_read_partial_packet,
484
    raw_read_close,
485
    .flags= AVFMT_GENERIC_INDEX,
486
    .extensions = "dts",
487
};
488

    
489
AVInputFormat aac_demuxer = {
490
    "aac",
491
    "ADTS AAC",
492
    0,
493
    NULL,
494
    aac_read_header,
495
    raw_read_partial_packet,
496
    raw_read_close,
497
    .flags= AVFMT_GENERIC_INDEX,
498
    .extensions = "aac",
499
};
500

    
501
AVInputFormat h261_demuxer = {
502
    "h261",
503
    "raw h261",
504
    0,
505
    h261_probe,
506
    video_read_header,
507
    raw_read_partial_packet,
508
    raw_read_close,
509
    .flags= AVFMT_GENERIC_INDEX,
510
    .extensions = "h261",
511
    .value = CODEC_ID_H261,
512
};
513

    
514
#ifdef CONFIG_MUXERS
515
AVOutputFormat h261_muxer = {
516
    "h261",
517
    "raw h261",
518
    "video/x-h261",
519
    "h261",
520
    0,
521
    0,
522
    CODEC_ID_H261,
523
    raw_write_header,
524
    raw_write_packet,
525
    raw_write_trailer,
526
    .flags= AVFMT_NOTIMESTAMPS,
527
};
528
#endif //CONFIG_MUXERS
529

    
530
AVInputFormat h263_demuxer = {
531
    "h263",
532
    "raw h263",
533
    0,
534
    h263_probe,
535
    video_read_header,
536
    raw_read_partial_packet,
537
    raw_read_close,
538
    .flags= AVFMT_GENERIC_INDEX,
539
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
540
    .value = CODEC_ID_H263,
541
};
542

    
543
#ifdef CONFIG_MUXERS
544
AVOutputFormat h263_muxer = {
545
    "h263",
546
    "raw h263",
547
    "video/x-h263",
548
    "h263",
549
    0,
550
    0,
551
    CODEC_ID_H263,
552
    raw_write_header,
553
    raw_write_packet,
554
    raw_write_trailer,
555
    .flags= AVFMT_NOTIMESTAMPS,
556
};
557
#endif //CONFIG_MUXERS
558

    
559
AVInputFormat m4v_demuxer = {
560
    "m4v",
561
    "raw MPEG4 video format",
562
    0,
563
    mpeg4video_probe, /** probing for mpeg4 data */
564
    video_read_header,
565
    raw_read_partial_packet,
566
    raw_read_close,
567
    .flags= AVFMT_GENERIC_INDEX,
568
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
569
    .value = CODEC_ID_MPEG4,
570
};
571

    
572
#ifdef CONFIG_MUXERS
573
AVOutputFormat m4v_muxer = {
574
    "m4v",
575
    "raw MPEG4 video format",
576
    NULL,
577
    "m4v",
578
    0,
579
    CODEC_ID_NONE,
580
    CODEC_ID_MPEG4,
581
    raw_write_header,
582
    raw_write_packet,
583
    raw_write_trailer,
584
    .flags= AVFMT_NOTIMESTAMPS,
585
};
586
#endif //CONFIG_MUXERS
587

    
588
AVInputFormat h264_demuxer = {
589
    "h264",
590
    "raw H264 video format",
591
    0,
592
    NULL /*mpegvideo_probe*/,
593
    video_read_header,
594
    raw_read_partial_packet,
595
    raw_read_close,
596
    .flags= AVFMT_GENERIC_INDEX,
597
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
598
    .value = CODEC_ID_H264,
599
};
600

    
601
#ifdef CONFIG_MUXERS
602
AVOutputFormat h264_muxer = {
603
    "h264",
604
    "raw H264 video format",
605
    NULL,
606
    "h264",
607
    0,
608
    CODEC_ID_NONE,
609
    CODEC_ID_H264,
610
    raw_write_header,
611
    raw_write_packet,
612
    raw_write_trailer,
613
    .flags= AVFMT_NOTIMESTAMPS,
614
};
615
#endif //CONFIG_MUXERS
616

    
617
AVInputFormat mpegvideo_demuxer = {
618
    "mpegvideo",
619
    "MPEG video",
620
    0,
621
    mpegvideo_probe,
622
    video_read_header,
623
    raw_read_partial_packet,
624
    raw_read_close,
625
    .flags= AVFMT_GENERIC_INDEX,
626
    .value = CODEC_ID_MPEG1VIDEO,
627
};
628

    
629
#ifdef CONFIG_MUXERS
630
AVOutputFormat mpeg1video_muxer = {
631
    "mpeg1video",
632
    "MPEG video",
633
    "video/x-mpeg",
634
    "mpg,mpeg,m1v",
635
    0,
636
    0,
637
    CODEC_ID_MPEG1VIDEO,
638
    raw_write_header,
639
    raw_write_packet,
640
    raw_write_trailer,
641
    .flags= AVFMT_NOTIMESTAMPS,
642
};
643
#endif //CONFIG_MUXERS
644

    
645
#ifdef CONFIG_MUXERS
646
AVOutputFormat mpeg2video_muxer = {
647
    "mpeg2video",
648
    "MPEG2 video",
649
    NULL,
650
    "m2v",
651
    0,
652
    0,
653
    CODEC_ID_MPEG2VIDEO,
654
    raw_write_header,
655
    raw_write_packet,
656
    raw_write_trailer,
657
    .flags= AVFMT_NOTIMESTAMPS,
658
};
659
#endif //CONFIG_MUXERS
660

    
661
AVInputFormat mjpeg_demuxer = {
662
    "mjpeg",
663
    "MJPEG video",
664
    0,
665
    NULL,
666
    video_read_header,
667
    raw_read_partial_packet,
668
    raw_read_close,
669
    .flags= AVFMT_GENERIC_INDEX,
670
    .extensions = "mjpg,mjpeg",
671
    .value = CODEC_ID_MJPEG,
672
};
673

    
674
AVInputFormat ingenient_demuxer = {
675
    "ingenient",
676
    "Ingenient MJPEG",
677
    0,
678
    NULL,
679
    video_read_header,
680
    ingenient_read_packet,
681
    raw_read_close,
682
    .flags= AVFMT_GENERIC_INDEX,
683
    .extensions = "cgi", // FIXME
684
    .value = CODEC_ID_MJPEG,
685
};
686

    
687
#ifdef CONFIG_MUXERS
688
AVOutputFormat mjpeg_muxer = {
689
    "mjpeg",
690
    "MJPEG video",
691
    "video/x-mjpeg",
692
    "mjpg,mjpeg",
693
    0,
694
    0,
695
    CODEC_ID_MJPEG,
696
    raw_write_header,
697
    raw_write_packet,
698
    raw_write_trailer,
699
    .flags= AVFMT_NOTIMESTAMPS,
700
};
701
#endif //CONFIG_MUXERS
702

    
703
/* pcm formats */
704

    
705
#define PCMINPUTDEF(name, long_name, ext, codec) \
706
AVInputFormat pcm_ ## name ## _demuxer = {\
707
    #name,\
708
    long_name,\
709
    0,\
710
    NULL,\
711
    raw_read_header,\
712
    raw_read_packet,\
713
    raw_read_close,\
714
    pcm_read_seek,\
715
    .flags= AVFMT_GENERIC_INDEX,\
716
    .extensions = ext,\
717
    .value = codec,\
718
};
719

    
720
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
721
AVOutputFormat pcm_ ## name ## _muxer = {\
722
    #name,\
723
    long_name,\
724
    NULL,\
725
    ext,\
726
    0,\
727
    codec,\
728
    0,\
729
    raw_write_header,\
730
    raw_write_packet,\
731
    raw_write_trailer,\
732
    .flags= AVFMT_NOTIMESTAMPS,\
733
};
734

    
735

    
736
#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
737
#define PCMDEF(name, long_name, ext, codec) \
738
        PCMINPUTDEF(name, long_name, ext, codec)
739
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
740
#define PCMDEF(name, long_name, ext, codec) \
741
        PCMOUTPUTDEF(name, long_name, ext, codec)
742
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
743
#define PCMDEF(name, long_name, ext, codec) \
744
        PCMINPUTDEF(name, long_name, ext, codec)\
745
        PCMOUTPUTDEF(name, long_name, ext, codec)
746
#else
747
#define PCMDEF(name, long_name, ext, codec)
748
#endif
749

    
750
#ifdef WORDS_BIGENDIAN
751
#define BE_DEF(s) s
752
#define LE_DEF(s) NULL
753
#else
754
#define BE_DEF(s) NULL
755
#define LE_DEF(s) s
756
#endif
757

    
758

    
759
PCMDEF(s16le, "pcm signed 16 bit little endian format",
760
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
761

    
762
PCMDEF(s16be, "pcm signed 16 bit big endian format",
763
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
764

    
765
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
766
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
767

    
768
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
769
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
770

    
771
PCMDEF(s8, "pcm signed 8 bit format",
772
       "sb", CODEC_ID_PCM_S8)
773

    
774
PCMDEF(u8, "pcm unsigned 8 bit format",
775
       "ub", CODEC_ID_PCM_U8)
776

    
777
PCMDEF(mulaw, "pcm mu law format",
778
       "ul", CODEC_ID_PCM_MULAW)
779

    
780
PCMDEF(alaw, "pcm A law format",
781
       "al", CODEC_ID_PCM_ALAW)
782

    
783
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
784
{
785
    int packet_size, ret, width, height;
786
    AVStream *st = s->streams[0];
787

    
788
    width = st->codec->width;
789
    height = st->codec->height;
790

    
791
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
792
    if (packet_size < 0)
793
        return -1;
794

    
795
    ret= av_get_packet(&s->pb, pkt, packet_size);
796

    
797
    pkt->stream_index = 0;
798
    if (ret != packet_size) {
799
        return AVERROR_IO;
800
    } else {
801
        return 0;
802
    }
803
}
804

    
805
AVInputFormat rawvideo_demuxer = {
806
    "rawvideo",
807
    "raw video format",
808
    0,
809
    NULL,
810
    raw_read_header,
811
    rawvideo_read_packet,
812
    raw_read_close,
813
    .flags= AVFMT_GENERIC_INDEX,
814
    .extensions = "yuv,cif,qcif",
815
    .value = CODEC_ID_RAWVIDEO,
816
};
817

    
818
#ifdef CONFIG_MUXERS
819
AVOutputFormat rawvideo_muxer = {
820
    "rawvideo",
821
    "raw video format",
822
    NULL,
823
    "yuv",
824
    0,
825
    CODEC_ID_NONE,
826
    CODEC_ID_RAWVIDEO,
827
    raw_write_header,
828
    raw_write_packet,
829
    raw_write_trailer,
830
    .flags= AVFMT_NOTIMESTAMPS,
831
};
832
#endif //CONFIG_MUXERS
833

    
834
#ifdef CONFIG_MUXERS
835
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
836
{
837
    return 0;
838
}
839

    
840
AVOutputFormat null_muxer = {
841
    "null",
842
    "null video format",
843
    NULL,
844
    NULL,
845
    0,
846
#ifdef WORDS_BIGENDIAN
847
    CODEC_ID_PCM_S16BE,
848
#else
849
    CODEC_ID_PCM_S16LE,
850
#endif
851
    CODEC_ID_RAWVIDEO,
852
    raw_write_header,
853
    null_write_packet,
854
    raw_write_trailer,
855
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
856
};
857
#endif //CONFIG_MUXERS