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.
21 #include <netinet/in.h>
27 int raw_write_header(struct AVFormatContext
*s
)
32 int raw_write_packet(struct AVFormatContext
*s
,
34 unsigned char *buf
, int size
)
36 put_buffer(&s
->pb
, buf
, size
);
37 put_flush_packet(&s
->pb
);
41 int raw_write_trailer(struct AVFormatContext
*s
)
47 static int raw_read_header(AVFormatContext
*s
,
48 AVFormatParameters
*ap
)
52 st
= malloc(sizeof(AVStream
));
61 if (s
->format
->audio_codec
!= CODEC_ID_NONE
) {
62 st
->codec
.codec_type
= CODEC_TYPE_AUDIO
;
63 st
->codec
.codec_id
= s
->format
->audio_codec
;
64 } else if (s
->format
->video_codec
!= CODEC_ID_NONE
) {
65 st
->codec
.codec_type
= CODEC_TYPE_VIDEO
;
66 st
->codec
.codec_id
= s
->format
->video_codec
;
72 switch(st
->codec
.codec_type
) {
73 case CODEC_TYPE_AUDIO
:
74 st
->codec
.sample_rate
= ap
->sample_rate
;
75 st
->codec
.channels
= ap
->channels
;
78 case CODEC_TYPE_VIDEO
:
79 st
->codec
.frame_rate
= ap
->frame_rate
;
80 st
->codec
.width
= ap
->width
;
81 st
->codec
.height
= ap
->height
;
95 int raw_read_packet(AVFormatContext
*s
,
98 int packet_size
, n
, ret
;
100 if (url_feof(&s
->pb
))
103 packet_size
= url_get_packet_size(&s
->pb
);
104 n
= MIN_SIZE
/ packet_size
;
107 if (av_new_packet(pkt
, n
* packet_size
) < 0)
110 pkt
->stream_index
= 0;
111 ret
= get_buffer(&s
->pb
, pkt
->data
, pkt
->size
);
117 int raw_read_close(AVFormatContext
*s
)
123 static int mp3_read_header(AVFormatContext
*s
,
124 AVFormatParameters
*ap
)
128 st
= malloc(sizeof(AVStream
));
136 st
->codec
.codec_type
= CODEC_TYPE_AUDIO
;
137 st
->codec
.codec_id
= CODEC_ID_MP2
;
138 /* XXX: read the first frame and extract rate and channels */
139 st
->codec
.sample_rate
= 44100;
140 st
->codec
.channels
= 2;
144 /* mpeg1/h263 input */
145 static int video_read_header(AVFormatContext
*s
,
146 AVFormatParameters
*ap
)
150 st
= av_mallocz(sizeof(AVStream
));
156 st
->codec
.codec_type
= CODEC_TYPE_VIDEO
;
157 st
->codec
.codec_id
= s
->format
->video_codec
;
161 AVFormat mp2_format
= {
177 AVFormat ac3_format
= {
189 AVFormat h263_format
= {
204 AVFormat mpeg1video_format
= {
219 AVFormat pcm_format
= {
235 int rawvideo_read_packet(AVFormatContext
*s
,
238 int packet_size
, ret
, width
, height
;
239 AVStream
*st
= s
->streams
[0];
241 width
= st
->codec
.width
;
242 height
= st
->codec
.height
;
244 switch(st
->codec
.pix_fmt
) {
245 case PIX_FMT_YUV420P
:
246 packet_size
= (width
* height
* 3) / 2;
249 packet_size
= (width
* height
* 2);
253 packet_size
= (width
* height
* 3);
260 if (av_new_packet(pkt
, packet_size
) < 0)
263 pkt
->stream_index
= 0;
264 /* bypass buffered I/O */
265 ret
= url_read(url_fileno(&s
->pb
), pkt
->data
, pkt
->size
);
266 if (ret
!= pkt
->size
) {
274 AVFormat rawvideo_format
= {
286 rawvideo_read_packet
,