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;
90 int raw_read_packet(AVFormatContext *s,
93 int packet_size, n, ret;
98 packet_size = url_get_packet_size(&s->pb);
99 n = MIN_SIZE / packet_size;
102 if (av_new_packet(pkt, n * packet_size) < 0)
105 pkt->stream_index = 0;
106 ret = get_buffer(&s->pb, pkt->data, pkt->size);
112 int raw_read_close(AVFormatContext *s)
118 static int mp3_read_header(AVFormatContext *s,
119 AVFormatParameters *ap)
123 st = malloc(sizeof(AVStream));
131 st->codec.codec_type = CODEC_TYPE_AUDIO;
132 st->codec.codec_id = CODEC_ID_MP2;
133 /* XXX: read the first frame and extract rate and channels */
134 st->codec.sample_rate = 44100;
135 st->codec.channels = 2;
139 /* mpeg1/h263 input */
140 static int video_read_header(AVFormatContext *s,
141 AVFormatParameters *ap)
145 st = av_mallocz(sizeof(AVStream));
151 st->codec.codec_type = CODEC_TYPE_VIDEO;
152 st->codec.codec_id = s->format->video_codec;
156 AVFormat mp2_format = {
172 AVFormat ac3_format = {
184 AVFormat h263_format = {
199 AVFormat mpeg1video_format = {
214 AVFormat pcm_format = {
230 int rawvideo_read_packet(AVFormatContext *s,
233 int packet_size, ret, width, height;
234 AVStream *st = s->streams[0];
236 width = st->codec.width;
237 height = st->codec.height;
239 switch(st->codec.pix_fmt) {
240 case PIX_FMT_YUV420P:
241 packet_size = (width * height * 3) / 2;
244 packet_size = (width * height * 2);
248 packet_size = (width * height * 3);
255 if (av_new_packet(pkt, packet_size) < 0)
258 pkt->stream_index = 0;
259 /* bypass buffered I/O */
260 ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size);
261 if (ret != pkt->size) {
269 AVFormat rawvideo_format = {
281 rawvideo_read_packet,