2
* RAW encoder and decoder
3
* Copyright (c) 2001 Gerard Lantau.
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
int raw_write_header(struct AVFormatContext *s)
27
int raw_write_packet(struct AVFormatContext *s,
29
unsigned char *buf, int size)
31
put_buffer(&s->pb, buf, size);
32
put_flush_packet(&s->pb);
36
int raw_write_trailer(struct AVFormatContext *s)
42
static int raw_read_header(AVFormatContext *s,
43
AVFormatParameters *ap)
47
st = malloc(sizeof(AVStream));
56
if (s->format->audio_codec != CODEC_ID_NONE) {
57
st->codec.codec_type = CODEC_TYPE_AUDIO;
58
st->codec.codec_id = s->format->audio_codec;
59
} else if (s->format->video_codec != CODEC_ID_NONE) {
60
st->codec.codec_type = CODEC_TYPE_VIDEO;
61
st->codec.codec_id = s->format->video_codec;
67
switch(st->codec.codec_type) {
68
case CODEC_TYPE_AUDIO:
69
st->codec.sample_rate = ap->sample_rate;
70
st->codec.channels = ap->channels;
73
case CODEC_TYPE_VIDEO:
74
st->codec.frame_rate = ap->frame_rate;
75
st->codec.width = ap->width;
76
st->codec.height = ap->height;
89
int raw_read_packet(AVFormatContext *s,
92
int packet_size, n, ret;
97
packet_size = url_get_packet_size(&s->pb);
98
n = MIN_SIZE / packet_size;
101
if (av_new_packet(pkt, n * packet_size) < 0)
104
pkt->stream_index = 0;
105
ret = get_buffer(&s->pb, pkt->data, pkt->size);
111
int raw_read_close(AVFormatContext *s)
117
static int mp3_read_header(AVFormatContext *s,
118
AVFormatParameters *ap)
122
st = malloc(sizeof(AVStream));
130
st->codec.codec_type = CODEC_TYPE_AUDIO;
131
st->codec.codec_id = CODEC_ID_MP2;
132
/* the parameters will be extracted from the compressed bitstream */
136
/* mpeg1/h263 input */
137
static int video_read_header(AVFormatContext *s,
138
AVFormatParameters *ap)
142
st = av_mallocz(sizeof(AVStream));
148
st->codec.codec_type = CODEC_TYPE_VIDEO;
149
st->codec.codec_id = s->format->video_codec;
150
/* for mjpeg, specify frame rate */
151
if (st->codec.codec_id == CODEC_ID_MJPEG) {
153
st->codec.frame_rate = ap->frame_rate;
155
st->codec.frame_rate = 25 * FRAME_RATE_BASE;
161
AVFormat mp2_format = {
177
AVFormat ac3_format = {
189
AVFormat h263_format = {
204
AVFormat mpeg1video_format = {
219
AVFormat mjpeg_format = {
234
AVFormat pcm_format = {
250
int rawvideo_read_packet(AVFormatContext *s,
253
int packet_size, ret, width, height;
254
AVStream *st = s->streams[0];
256
width = st->codec.width;
257
height = st->codec.height;
259
switch(st->codec.pix_fmt) {
260
case PIX_FMT_YUV420P:
261
packet_size = (width * height * 3) / 2;
264
packet_size = (width * height * 2);
268
packet_size = (width * height * 3);
275
if (av_new_packet(pkt, packet_size) < 0)
278
pkt->stream_index = 0;
279
/* bypass buffered I/O */
280
ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size);
281
if (ret != pkt->size) {
289
AVFormat rawvideo_format = {
301
rawvideo_read_packet,