Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 20b02bc6

History | View | Annotate | Download (16 KB)

1 de6d9b64 Fabrice Bellard
/* 
2
 * RAW encoder and decoder
3 19720f15 Fabrice Bellard
 * Copyright (c) 2001 Fabrice Bellard.
4 de6d9b64 Fabrice Bellard
 *
5 19720f15 Fabrice Bellard
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9 de6d9b64 Fabrice Bellard
 *
10 19720f15 Fabrice Bellard
 * This library is distributed in the hope that it will be useful,
11 de6d9b64 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 19720f15 Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14 de6d9b64 Fabrice Bellard
 *
15 19720f15 Fabrice Bellard
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 de6d9b64 Fabrice Bellard
 */
19
#include "avformat.h"
20
21 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
22 de6d9b64 Fabrice Bellard
/* simple formats */
23 5c91a675 Zdenek Kabelac
static int raw_write_header(struct AVFormatContext *s)
24 de6d9b64 Fabrice Bellard
{
25
    return 0;
26
}
27
28 e928649b Michael Niedermayer
static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
29 de6d9b64 Fabrice Bellard
{
30 e928649b Michael Niedermayer
    put_buffer(&s->pb, pkt->data, pkt->size);
31 de6d9b64 Fabrice Bellard
    put_flush_packet(&s->pb);
32
    return 0;
33
}
34
35 5c91a675 Zdenek Kabelac
static int raw_write_trailer(struct AVFormatContext *s)
36 de6d9b64 Fabrice Bellard
{
37
    return 0;
38
}
39 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
40 de6d9b64 Fabrice Bellard
41
/* raw input */
42 0c1a9eda Zdenek Kabelac
static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
43 de6d9b64 Fabrice Bellard
{
44
    AVStream *st;
45 c9a65ca8 Fabrice Bellard
    int id;
46 de6d9b64 Fabrice Bellard
47 c9a65ca8 Fabrice Bellard
    st = av_new_stream(s, 0);
48 de6d9b64 Fabrice Bellard
    if (!st)
49 c9a65ca8 Fabrice Bellard
        return AVERROR_NOMEM;
50 de6d9b64 Fabrice Bellard
    if (ap) {
51 c9a65ca8 Fabrice Bellard
        id = s->iformat->value;
52
        if (id == CODEC_ID_RAWVIDEO) {
53 de6d9b64 Fabrice Bellard
            st->codec.codec_type = CODEC_TYPE_VIDEO;
54
        } else {
55 c9a65ca8 Fabrice Bellard
            st->codec.codec_type = CODEC_TYPE_AUDIO;
56 de6d9b64 Fabrice Bellard
        }
57 c9a65ca8 Fabrice Bellard
        st->codec.codec_id = id;
58
59 de6d9b64 Fabrice Bellard
        switch(st->codec.codec_type) {
60
        case CODEC_TYPE_AUDIO:
61
            st->codec.sample_rate = ap->sample_rate;
62
            st->codec.channels = ap->channels;
63 595bf4ef Michael Niedermayer
            av_set_pts_info(st, 64, 1, st->codec.sample_rate);
64 de6d9b64 Fabrice Bellard
            break;
65
        case CODEC_TYPE_VIDEO:
66 14bea432 Michael Niedermayer
            st->codec.frame_rate      = ap->frame_rate;
67
            st->codec.frame_rate_base = ap->frame_rate_base;
68 de6d9b64 Fabrice Bellard
            st->codec.width = ap->width;
69
            st->codec.height = ap->height;
70 63167088 Roman Shaposhnik
            st->codec.pix_fmt = ap->pix_fmt;
71 de6d9b64 Fabrice Bellard
            break;
72
        default:
73 27e084bd Fabrice Bellard
            return -1;
74 de6d9b64 Fabrice Bellard
        }
75
    } else {
76 27e084bd Fabrice Bellard
        return -1;
77 de6d9b64 Fabrice Bellard
    }
78
    return 0;
79
}
80
81 2e93e3aa Fabrice Bellard
#define RAW_PACKET_SIZE 1024
82 de6d9b64 Fabrice Bellard
83 5c91a675 Zdenek Kabelac
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
84 de6d9b64 Fabrice Bellard
{
85 7866eeff Michael Niedermayer
    int ret, size;
86 2a6874fd Fabrice Bellard
    //    AVStream *st = s->streams[0];
87 7866eeff Michael Niedermayer
    
88 231dd3f3 Fabrice Bellard
    size= RAW_PACKET_SIZE;
89 de6d9b64 Fabrice Bellard
90 7866eeff Michael Niedermayer
    if (av_new_packet(pkt, size) < 0)
91 0bd586c5 Mike Melanson
        return AVERROR_IO;
92 de6d9b64 Fabrice Bellard
93
    pkt->stream_index = 0;
94 7866eeff Michael Niedermayer
    ret = get_buffer(&s->pb, pkt->data, size);
95 2e93e3aa Fabrice Bellard
    if (ret <= 0) {
96 de6d9b64 Fabrice Bellard
        av_free_packet(pkt);
97 0bd586c5 Mike Melanson
        return AVERROR_IO;
98 2e93e3aa Fabrice Bellard
    }
99
    /* note: we need to modify the packet size here to handle the last
100
       packet */
101
    pkt->size = ret;
102 de6d9b64 Fabrice Bellard
    return ret;
103
}
104
105 e15dec10 Leon van Stuivenberg
static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
106
{
107
    int ret, size;
108
109
    size = RAW_PACKET_SIZE;
110
111
    if (av_new_packet(pkt, size) < 0)
112 0bd586c5 Mike Melanson
        return AVERROR_IO;
113 e15dec10 Leon van Stuivenberg
114
    pkt->stream_index = 0;
115
    ret = get_partial_buffer(&s->pb, pkt->data, size);
116
    if (ret <= 0) {
117
        av_free_packet(pkt);
118 0bd586c5 Mike Melanson
        return AVERROR_IO;
119 e15dec10 Leon van Stuivenberg
    }
120
    pkt->size = ret;
121
    return ret;
122
}
123
124 5c91a675 Zdenek Kabelac
static int raw_read_close(AVFormatContext *s)
125 de6d9b64 Fabrice Bellard
{
126
    return 0;
127
}
128
129 4986a429 Fabrice Bellard
int pcm_read_seek(AVFormatContext *s, 
130 7b3c1382 Michael Niedermayer
                  int stream_index, int64_t timestamp, int flags)
131 4986a429 Fabrice Bellard
{
132
    AVStream *st;
133
    int block_align, byte_rate;
134
    int64_t pos;
135
136
    st = s->streams[0];
137
    switch(st->codec.codec_id) {
138
    case CODEC_ID_PCM_S16LE:
139
    case CODEC_ID_PCM_S16BE:
140
    case CODEC_ID_PCM_U16LE:
141
    case CODEC_ID_PCM_U16BE:
142
        block_align = 2 * st->codec.channels;
143
        byte_rate = block_align * st->codec.sample_rate;
144
        break;
145
    case CODEC_ID_PCM_S8:
146
    case CODEC_ID_PCM_U8:
147
    case CODEC_ID_PCM_MULAW:
148
    case CODEC_ID_PCM_ALAW:
149
        block_align = st->codec.channels;
150
        byte_rate = block_align * st->codec.sample_rate;
151
        break;
152
    default:
153
        block_align = st->codec.block_align;
154
        byte_rate = st->codec.bit_rate / 8;
155
        break;
156
    }
157
    
158
    if (block_align <= 0 || byte_rate <= 0)
159
        return -1;
160
161
    /* compute the position by aligning it to block_align */
162 7b3c1382 Michael Niedermayer
    pos = av_rescale_rnd(timestamp * byte_rate, 
163
                         st->time_base.num, 
164
                         st->time_base.den * (int64_t)block_align,
165
                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
166
    pos *= block_align;
167 4986a429 Fabrice Bellard
168
    /* recompute exact position */
169 77405fc8 Michael Niedermayer
    st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
170 4986a429 Fabrice Bellard
    url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
171
    return 0;
172
}
173
174 cd66005d Fabrice Bellard
/* ac3 read */
175
static int ac3_read_header(AVFormatContext *s,
176
                           AVFormatParameters *ap)
177
{
178
    AVStream *st;
179
180
    st = av_new_stream(s, 0);
181
    if (!st)
182
        return AVERROR_NOMEM;
183
184
    st->codec.codec_type = CODEC_TYPE_AUDIO;
185
    st->codec.codec_id = CODEC_ID_AC3;
186 4986a429 Fabrice Bellard
    st->need_parsing = 1;
187 cd66005d Fabrice Bellard
    /* the parameters will be extracted from the compressed bitstream */
188
    return 0;
189
}
190
191 23c99253 Michael Niedermayer
/* dts read */
192
static int dts_read_header(AVFormatContext *s,
193
                           AVFormatParameters *ap)
194
{
195
    AVStream *st;
196
197
    st = av_new_stream(s, 0);
198
    if (!st)
199
        return AVERROR_NOMEM;
200
201
    st->codec.codec_type = CODEC_TYPE_AUDIO;
202
    st->codec.codec_id = CODEC_ID_DTS;
203
    st->need_parsing = 1;
204
    /* the parameters will be extracted from the compressed bitstream */
205
    return 0;
206
}
207
208 de6d9b64 Fabrice Bellard
/* mpeg1/h263 input */
209
static int video_read_header(AVFormatContext *s,
210
                             AVFormatParameters *ap)
211
{
212
    AVStream *st;
213
214 c9a65ca8 Fabrice Bellard
    st = av_new_stream(s, 0);
215 de6d9b64 Fabrice Bellard
    if (!st)
216 c9a65ca8 Fabrice Bellard
        return AVERROR_NOMEM;
217 de6d9b64 Fabrice Bellard
218
    st->codec.codec_type = CODEC_TYPE_VIDEO;
219 c9a65ca8 Fabrice Bellard
    st->codec.codec_id = s->iformat->value;
220 4986a429 Fabrice Bellard
    st->need_parsing = 1;
221
222 27e084bd Fabrice Bellard
    /* for mjpeg, specify frame rate */
223 7866eeff Michael Niedermayer
    /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
224 4986a429 Fabrice Bellard
    if (st->codec.codec_id == CODEC_ID_MJPEG || 
225
        st->codec.codec_id == CODEC_ID_MPEG4) {
226
        if (ap && ap->frame_rate) {
227 14bea432 Michael Niedermayer
            st->codec.frame_rate      = ap->frame_rate;
228
            st->codec.frame_rate_base = ap->frame_rate_base;
229 27e084bd Fabrice Bellard
        } else {
230 14bea432 Michael Niedermayer
            st->codec.frame_rate      = 25;
231
            st->codec.frame_rate_base = 1;
232 27e084bd Fabrice Bellard
        }
233
    }
234 de6d9b64 Fabrice Bellard
    return 0;
235
}
236
237 c9a65ca8 Fabrice Bellard
#define SEQ_START_CODE                0x000001b3
238
#define GOP_START_CODE                0x000001b8
239
#define PICTURE_START_CODE        0x00000100
240
241
/* XXX: improve that by looking at several start codes */
242
static int mpegvideo_probe(AVProbeData *p)
243
{
244 fa777321 Fabrice Bellard
    int code;
245
    const uint8_t *d;
246 c9a65ca8 Fabrice Bellard
247
    /* we search the first start code. If it is a sequence, gop or
248
       picture start code then we decide it is an mpeg video
249
       stream. We do not send highest value to give a chance to mpegts */
250 fa777321 Fabrice Bellard
    /* NOTE: the search range was restricted to avoid too many false
251
       detections */
252
253
    if (p->buf_size < 6)
254
        return 0;
255
    d = p->buf;
256
    code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]);
257
    if ((code & 0xffffff00) == 0x100) {
258
        if (code == SEQ_START_CODE ||
259
            code == GOP_START_CODE ||
260
            code == PICTURE_START_CODE)
261
            return 50 - 1;
262
        else
263
            return 0;
264 c9a65ca8 Fabrice Bellard
    }
265
    return 0;
266
}
267
268 d07f9043 Michael Niedermayer
static int h263_probe(AVProbeData *p)
269
{
270
    int code;
271
    const uint8_t *d;
272
273
    if (p->buf_size < 6)
274
        return 0;
275
    d = p->buf;
276
    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
277
    if (code == 0x20) {
278
        return 50;
279
    }
280
    return 0;
281
}
282
283 c6148de2 Michael Niedermayer
static int h261_probe(AVProbeData *p)
284
{
285
    int code;
286
    const uint8_t *d;
287
288
    if (p->buf_size < 6)
289
        return 0;
290
    d = p->buf;
291
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
292
    if (code == 0x10) {
293
        return 50;
294
    }
295
    return 0;
296
}
297
298 c9a65ca8 Fabrice Bellard
AVInputFormat ac3_iformat = {
299
    "ac3",
300
    "raw ac3",
301
    0,
302
    NULL,
303 cd66005d Fabrice Bellard
    ac3_read_header,
304 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
305 de6d9b64 Fabrice Bellard
    raw_read_close,
306 bb76a117 Måns Rullgård
    .extensions = "ac3",
307 de6d9b64 Fabrice Bellard
};
308
309 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
310 c9a65ca8 Fabrice Bellard
AVOutputFormat ac3_oformat = {
311 de6d9b64 Fabrice Bellard
    "ac3",
312
    "raw ac3",
313
    "audio/x-ac3", 
314
    "ac3",
315 c9a65ca8 Fabrice Bellard
    0,
316 de6d9b64 Fabrice Bellard
    CODEC_ID_AC3,
317
    0,
318
    raw_write_header,
319
    raw_write_packet,
320
    raw_write_trailer,
321
};
322 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
323 de6d9b64 Fabrice Bellard
324 23c99253 Michael Niedermayer
AVInputFormat dts_iformat = {
325
    "dts",
326
    "raw dts",
327
    0,
328
    NULL,
329
    dts_read_header,
330
    raw_read_partial_packet,
331
    raw_read_close,
332
    .extensions = "dts",
333
};
334
335 c6148de2 Michael Niedermayer
AVInputFormat h261_iformat = {
336
    "h261",
337
    "raw h261",
338
    0,
339
    h261_probe,
340
    video_read_header,
341
    raw_read_partial_packet,
342
    raw_read_close,
343
    .extensions = "h261",
344
    .value = CODEC_ID_H261,
345
};
346
347 1c3990db Michael Niedermayer
#ifdef CONFIG_ENCODERS
348
AVOutputFormat h261_oformat = {
349
    "h261",
350
    "raw h261",
351
    "video/x-h261",
352
    "h261",
353
    0,
354
    0,
355
    CODEC_ID_H261,
356
    raw_write_header,
357
    raw_write_packet,
358
    raw_write_trailer,
359
};
360
#endif //CONFIG_ENCODERS
361
362 d07f9043 Michael Niedermayer
AVInputFormat h263_iformat = {
363
    "h263",
364
    "raw h263",
365
    0,
366
    h263_probe,
367
    video_read_header,
368 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
369 d07f9043 Michael Niedermayer
    raw_read_close,
370
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
371
    .value = CODEC_ID_H263,
372
};
373
374 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
375 c9a65ca8 Fabrice Bellard
AVOutputFormat h263_oformat = {
376 de6d9b64 Fabrice Bellard
    "h263",
377
    "raw h263",
378
    "video/x-h263",
379
    "h263",
380
    0,
381 c9a65ca8 Fabrice Bellard
    0,
382 de6d9b64 Fabrice Bellard
    CODEC_ID_H263,
383
    raw_write_header,
384
    raw_write_packet,
385
    raw_write_trailer,
386 c9a65ca8 Fabrice Bellard
};
387 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
388 c9a65ca8 Fabrice Bellard
389 7866eeff Michael Niedermayer
AVInputFormat m4v_iformat = {
390
    "m4v",
391
    "raw MPEG4 video format",
392
    0,
393 2f0f5b20 Michael Niedermayer
    NULL /*mpegvideo_probe*/,
394 7866eeff Michael Niedermayer
    video_read_header,
395 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
396 7866eeff Michael Niedermayer
    raw_read_close,
397 bb76a117 Måns Rullgård
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
398
    .value = CODEC_ID_MPEG4,
399 7866eeff Michael Niedermayer
};
400
401 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
402 89b3d7c9 Max Krasnyansky
AVOutputFormat m4v_oformat = {
403
    "m4v",
404
    "raw MPEG4 video format",
405
    NULL,
406
    "m4v",
407
    0,
408
    CODEC_ID_NONE,
409
    CODEC_ID_MPEG4,
410
    raw_write_header,
411
    raw_write_packet,
412
    raw_write_trailer,
413
};
414 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
415 89b3d7c9 Max Krasnyansky
416 0da71265 Michael Niedermayer
AVInputFormat h264_iformat = {
417
    "h264",
418
    "raw H264 video format",
419
    0,
420
    NULL /*mpegvideo_probe*/,
421
    video_read_header,
422 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
423 0da71265 Michael Niedermayer
    raw_read_close,
424
    .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe
425
    .value = CODEC_ID_H264,
426
};
427
428 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
429 0da71265 Michael Niedermayer
AVOutputFormat h264_oformat = {
430
    "h264",
431
    "raw H264 video format",
432
    NULL,
433
    "h264",
434
    0,
435
    CODEC_ID_NONE,
436
    CODEC_ID_H264,
437
    raw_write_header,
438
    raw_write_packet,
439
    raw_write_trailer,
440
};
441 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
442 0da71265 Michael Niedermayer
443 c9a65ca8 Fabrice Bellard
AVInputFormat mpegvideo_iformat = {
444
    "mpegvideo",
445
    "MPEG video",
446
    0,
447
    mpegvideo_probe,
448 de6d9b64 Fabrice Bellard
    video_read_header,
449 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
450 de6d9b64 Fabrice Bellard
    raw_read_close,
451 bb76a117 Måns Rullgård
    .value = CODEC_ID_MPEG1VIDEO,
452 de6d9b64 Fabrice Bellard
};
453
454 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
455 c9a65ca8 Fabrice Bellard
AVOutputFormat mpeg1video_oformat = {
456
    "mpeg1video",
457 de6d9b64 Fabrice Bellard
    "MPEG video",
458
    "video/x-mpeg",
459
    "mpg,mpeg",
460
    0,
461 c9a65ca8 Fabrice Bellard
    0,
462 de6d9b64 Fabrice Bellard
    CODEC_ID_MPEG1VIDEO,
463
    raw_write_header,
464
    raw_write_packet,
465
    raw_write_trailer,
466
};
467 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
468 de6d9b64 Fabrice Bellard
469 c9a65ca8 Fabrice Bellard
AVInputFormat mjpeg_iformat = {
470 27e084bd Fabrice Bellard
    "mjpeg",
471
    "MJPEG video",
472
    0,
473 c9a65ca8 Fabrice Bellard
    NULL,
474 27e084bd Fabrice Bellard
    video_read_header,
475 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
476 27e084bd Fabrice Bellard
    raw_read_close,
477 bb76a117 Måns Rullgård
    .extensions = "mjpg,mjpeg",
478
    .value = CODEC_ID_MJPEG,
479 27e084bd Fabrice Bellard
};
480
481 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
482 c9a65ca8 Fabrice Bellard
AVOutputFormat mjpeg_oformat = {
483
    "mjpeg",
484
    "MJPEG video",
485
    "video/x-mjpeg",
486
    "mjpg,mjpeg",
487 5ed8fafc Fabrice Bellard
    0,
488
    0,
489 c9a65ca8 Fabrice Bellard
    CODEC_ID_MJPEG,
490 5ed8fafc Fabrice Bellard
    raw_write_header,
491
    raw_write_packet,
492
    raw_write_trailer,
493
};
494 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
495 5ed8fafc Fabrice Bellard
496 c9a65ca8 Fabrice Bellard
/* pcm formats */
497 764ef400 Mike Melanson
498 4986a429 Fabrice Bellard
#define PCMINPUTDEF(name, long_name, ext, codec) \
499 764ef400 Mike Melanson
AVInputFormat pcm_ ## name ## _iformat = {\
500
    #name,\
501
    long_name,\
502
    0,\
503
    NULL,\
504
    raw_read_header,\
505
    raw_read_packet,\
506
    raw_read_close,\
507 4986a429 Fabrice Bellard
    pcm_read_seek,\
508 764ef400 Mike Melanson
    .extensions = ext,\
509
    .value = codec,\
510
};
511
512 4986a429 Fabrice Bellard
#if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS)
513
514
#define PCMDEF(name, long_name, ext, codec) \
515
    PCMINPUTDEF(name, long_name, ext, codec)
516
517 764ef400 Mike Melanson
#else
518 5ed8fafc Fabrice Bellard
519 c9a65ca8 Fabrice Bellard
#define PCMDEF(name, long_name, ext, codec) \
520 4986a429 Fabrice Bellard
    PCMINPUTDEF(name, long_name, ext, codec)\
521 c9a65ca8 Fabrice Bellard
\
522
AVOutputFormat pcm_ ## name ## _oformat = {\
523
    #name,\
524
    long_name,\
525
    NULL,\
526
    ext,\
527
    0,\
528
    codec,\
529
    0,\
530
    raw_write_header,\
531
    raw_write_packet,\
532
    raw_write_trailer,\
533 5ed8fafc Fabrice Bellard
};
534 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
535 5ed8fafc Fabrice Bellard
536
#ifdef WORDS_BIGENDIAN
537 c9a65ca8 Fabrice Bellard
#define BE_DEF(s) s
538
#define LE_DEF(s) NULL
539 5ed8fafc Fabrice Bellard
#else
540 c9a65ca8 Fabrice Bellard
#define BE_DEF(s) NULL
541
#define LE_DEF(s) s
542 5ed8fafc Fabrice Bellard
#endif
543
544
545 c9a65ca8 Fabrice Bellard
PCMDEF(s16le, "pcm signed 16 bit little endian format", 
546
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
547 5ed8fafc Fabrice Bellard
548 c9a65ca8 Fabrice Bellard
PCMDEF(s16be, "pcm signed 16 bit big endian format", 
549
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
550 5ed8fafc Fabrice Bellard
551 c9a65ca8 Fabrice Bellard
PCMDEF(u16le, "pcm unsigned 16 bit little endian format", 
552
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
553 5ed8fafc Fabrice Bellard
554 c9a65ca8 Fabrice Bellard
PCMDEF(u16be, "pcm unsigned 16 bit big endian format", 
555
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
556 5ed8fafc Fabrice Bellard
557 c9a65ca8 Fabrice Bellard
PCMDEF(s8, "pcm signed 8 bit format", 
558
       "sb", CODEC_ID_PCM_S8)
559 5ed8fafc Fabrice Bellard
560 c9a65ca8 Fabrice Bellard
PCMDEF(u8, "pcm unsigned 8 bit format", 
561
       "ub", CODEC_ID_PCM_U8)
562 5ed8fafc Fabrice Bellard
563 c9a65ca8 Fabrice Bellard
PCMDEF(mulaw, "pcm mu law format", 
564
       "ul", CODEC_ID_PCM_MULAW)
565 de6d9b64 Fabrice Bellard
566 c9a65ca8 Fabrice Bellard
PCMDEF(alaw, "pcm A law format", 
567
       "al", CODEC_ID_PCM_ALAW)
568 de6d9b64 Fabrice Bellard
569 5c91a675 Zdenek Kabelac
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
570 de6d9b64 Fabrice Bellard
{
571
    int packet_size, ret, width, height;
572
    AVStream *st = s->streams[0];
573
574
    width = st->codec.width;
575
    height = st->codec.height;
576
577 63167088 Roman Shaposhnik
    packet_size = avpicture_get_size(st->codec.pix_fmt, width, height);
578
    if (packet_size < 0)
579 71c32f19 Michael Niedermayer
        return -1;
580 de6d9b64 Fabrice Bellard
581
    if (av_new_packet(pkt, packet_size) < 0)
582 0bd586c5 Mike Melanson
        return AVERROR_IO;
583 de6d9b64 Fabrice Bellard
584
    pkt->stream_index = 0;
585 c2c2cd2d Michael Niedermayer
#if 0
586 de6d9b64 Fabrice Bellard
    /* bypass buffered I/O */
587
    ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size);
588 c2c2cd2d Michael Niedermayer
#else
589
    ret = get_buffer(&s->pb, pkt->data, pkt->size);
590
#endif
591 de6d9b64 Fabrice Bellard
    if (ret != pkt->size) {
592
        av_free_packet(pkt);
593 0bd586c5 Mike Melanson
        return AVERROR_IO;
594 de6d9b64 Fabrice Bellard
    } else {
595
        return 0;
596
    }
597
}
598
599 c9a65ca8 Fabrice Bellard
AVInputFormat rawvideo_iformat = {
600
    "rawvideo",
601
    "raw video format",
602
    0,
603
    NULL,
604
    raw_read_header,
605
    rawvideo_read_packet,
606
    raw_read_close,
607 bb76a117 Måns Rullgård
    .extensions = "yuv",
608
    .value = CODEC_ID_RAWVIDEO,
609 c9a65ca8 Fabrice Bellard
};
610
611 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
612 c9a65ca8 Fabrice Bellard
AVOutputFormat rawvideo_oformat = {
613 de6d9b64 Fabrice Bellard
    "rawvideo",
614
    "raw video format",
615
    NULL,
616
    "yuv",
617 c9a65ca8 Fabrice Bellard
    0,
618 de6d9b64 Fabrice Bellard
    CODEC_ID_NONE,
619
    CODEC_ID_RAWVIDEO,
620
    raw_write_header,
621
    raw_write_packet,
622
    raw_write_trailer,
623
};
624 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
625 c9a65ca8 Fabrice Bellard
626 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
627 e928649b Michael Niedermayer
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
628 87bdd3e5 Fabrice Bellard
{
629
    return 0;
630
}
631
632
AVOutputFormat null_oformat = {
633
    "null",
634
    "null video format",
635
    NULL,
636
    NULL,
637
    0,
638
#ifdef WORDS_BIGENDIAN
639
    CODEC_ID_PCM_S16BE,
640
#else
641
    CODEC_ID_PCM_S16LE,
642
#endif
643
    CODEC_ID_RAWVIDEO,
644
    raw_write_header,
645
    null_write_packet,
646
    raw_write_trailer,
647 b1d89f82 Måns Rullgård
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE,
648 87bdd3e5 Fabrice Bellard
};
649 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS
650
651
#ifndef CONFIG_ENCODERS
652
#define av_register_output_format(format)
653
#endif
654
#ifndef CONFIG_DECODERS
655
#define av_register_input_format(format)
656
#endif
657 87bdd3e5 Fabrice Bellard
658 c9a65ca8 Fabrice Bellard
int raw_init(void)
659
{
660
    av_register_input_format(&ac3_iformat);
661
    av_register_output_format(&ac3_oformat);
662
663 23c99253 Michael Niedermayer
    av_register_input_format(&dts_iformat);
664
665 c6148de2 Michael Niedermayer
    av_register_input_format(&h261_iformat);
666 1c3990db Michael Niedermayer
    av_register_output_format(&h261_oformat);
667 c6148de2 Michael Niedermayer
668 d07f9043 Michael Niedermayer
    av_register_input_format(&h263_iformat);
669 c9a65ca8 Fabrice Bellard
    av_register_output_format(&h263_oformat);
670 89b3d7c9 Max Krasnyansky
    
671 7866eeff Michael Niedermayer
    av_register_input_format(&m4v_iformat);
672 89b3d7c9 Max Krasnyansky
    av_register_output_format(&m4v_oformat);
673 0da71265 Michael Niedermayer
    
674
    av_register_input_format(&h264_iformat);
675
    av_register_output_format(&h264_oformat);
676 c9a65ca8 Fabrice Bellard
677
    av_register_input_format(&mpegvideo_iformat);
678
    av_register_output_format(&mpeg1video_oformat);
679
680
    av_register_input_format(&mjpeg_iformat);
681
    av_register_output_format(&mjpeg_oformat);
682
683
    av_register_input_format(&pcm_s16le_iformat);
684
    av_register_output_format(&pcm_s16le_oformat);
685
    av_register_input_format(&pcm_s16be_iformat);
686
    av_register_output_format(&pcm_s16be_oformat);
687
    av_register_input_format(&pcm_u16le_iformat);
688
    av_register_output_format(&pcm_u16le_oformat);
689
    av_register_input_format(&pcm_u16be_iformat);
690
    av_register_output_format(&pcm_u16be_oformat);
691
    av_register_input_format(&pcm_s8_iformat);
692
    av_register_output_format(&pcm_s8_oformat);
693
    av_register_input_format(&pcm_u8_iformat);
694
    av_register_output_format(&pcm_u8_oformat);
695
    av_register_input_format(&pcm_mulaw_iformat);
696
    av_register_output_format(&pcm_mulaw_oformat);
697
    av_register_input_format(&pcm_alaw_iformat);
698
    av_register_output_format(&pcm_alaw_oformat);
699
700
    av_register_input_format(&rawvideo_iformat);
701
    av_register_output_format(&rawvideo_oformat);
702 87bdd3e5 Fabrice Bellard
703
    av_register_output_format(&null_oformat);
704 c9a65ca8 Fabrice Bellard
    return 0;
705
}