Mercurial > libavformat.hg
annotate raw.c @ 391:1cf22651d33b libavformat
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
this is needed for compatibility with tcp.c 1.10
author | michael |
---|---|
date | Sat, 20 Mar 2004 19:57:28 +0000 |
parents | e14fcd57ad2f |
children | 696f41bc8784 |
rev | line source |
---|---|
0 | 1 /* |
2 * RAW encoder and decoder | |
3 * Copyright (c) 2001 Fabrice Bellard. | |
4 * | |
5 * 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 * | |
10 * This library 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 GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * 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 */ | |
19 #include "avformat.h" | |
20 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
21 #ifdef CONFIG_ENCODERS |
0 | 22 /* simple formats */ |
64 | 23 static int raw_write_header(struct AVFormatContext *s) |
0 | 24 { |
25 return 0; | |
26 } | |
27 | |
64 | 28 static int raw_write_packet(struct AVFormatContext *s, int stream_index, |
241 | 29 const uint8_t *buf, int size, int64_t pts) |
0 | 30 { |
31 put_buffer(&s->pb, buf, size); | |
32 put_flush_packet(&s->pb); | |
33 return 0; | |
34 } | |
35 | |
64 | 36 static int raw_write_trailer(struct AVFormatContext *s) |
0 | 37 { |
38 return 0; | |
39 } | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
40 #endif //CONFIG_ENCODERS |
0 | 41 |
42 /* raw input */ | |
65 | 43 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) |
0 | 44 { |
45 AVStream *st; | |
46 int id; | |
47 | |
48 st = av_new_stream(s, 0); | |
49 if (!st) | |
50 return AVERROR_NOMEM; | |
51 if (ap) { | |
52 id = s->iformat->value; | |
53 if (id == CODEC_ID_RAWVIDEO) { | |
54 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
55 } else { | |
56 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
57 } | |
58 st->codec.codec_id = id; | |
59 | |
60 switch(st->codec.codec_type) { | |
61 case CODEC_TYPE_AUDIO: | |
62 st->codec.sample_rate = ap->sample_rate; | |
63 st->codec.channels = ap->channels; | |
64 break; | |
65 case CODEC_TYPE_VIDEO: | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
66 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
67 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 68 st->codec.width = ap->width; |
69 st->codec.height = ap->height; | |
128 | 70 st->codec.pix_fmt = ap->pix_fmt; |
0 | 71 break; |
72 default: | |
73 return -1; | |
74 } | |
75 } else { | |
76 return -1; | |
77 } | |
78 return 0; | |
79 } | |
80 | |
81 #define RAW_PACKET_SIZE 1024 | |
82 | |
64 | 83 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 84 { |
85 int ret, size; | |
28 | 86 // AVStream *st = s->streams[0]; |
0 | 87 |
88 size= RAW_PACKET_SIZE; | |
89 | |
90 if (av_new_packet(pkt, size) < 0) | |
91 return -EIO; | |
92 | |
93 pkt->stream_index = 0; | |
94 ret = get_buffer(&s->pb, pkt->data, size); | |
95 if (ret <= 0) { | |
96 av_free_packet(pkt); | |
97 return -EIO; | |
98 } | |
99 /* note: we need to modify the packet size here to handle the last | |
100 packet */ | |
101 pkt->size = ret; | |
102 return ret; | |
103 } | |
104 | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
105 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
106 { |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
107 int ret, size; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
108 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
109 size = RAW_PACKET_SIZE; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
110 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
111 if (av_new_packet(pkt, size) < 0) |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
112 return -EIO; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
113 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
114 pkt->stream_index = 0; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
115 ret = get_partial_buffer(&s->pb, pkt->data, size); |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
116 if (ret <= 0) { |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
117 av_free_packet(pkt); |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
118 return -EIO; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
119 } |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
120 pkt->size = ret; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
121 return ret; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
122 } |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
123 |
64 | 124 static int raw_read_close(AVFormatContext *s) |
0 | 125 { |
126 return 0; | |
127 } | |
128 | |
306 | 129 int pcm_read_seek(AVFormatContext *s, |
130 int stream_index, int64_t timestamp) | |
131 { | |
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 pos = (timestamp * byte_rate) / AV_TIME_BASE; | |
163 pos = (pos / block_align) * block_align; | |
164 | |
165 /* recompute exact position */ | |
166 st->cur_dts = (pos * AV_TIME_BASE) / byte_rate; | |
167 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); | |
168 return 0; | |
169 } | |
170 | |
63 | 171 /* ac3 read */ |
172 static int ac3_read_header(AVFormatContext *s, | |
173 AVFormatParameters *ap) | |
174 { | |
175 AVStream *st; | |
176 | |
177 st = av_new_stream(s, 0); | |
178 if (!st) | |
179 return AVERROR_NOMEM; | |
180 | |
181 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
182 st->codec.codec_id = CODEC_ID_AC3; | |
306 | 183 st->need_parsing = 1; |
63 | 184 /* the parameters will be extracted from the compressed bitstream */ |
185 return 0; | |
186 } | |
187 | |
0 | 188 /* mpeg1/h263 input */ |
189 static int video_read_header(AVFormatContext *s, | |
190 AVFormatParameters *ap) | |
191 { | |
192 AVStream *st; | |
193 | |
194 st = av_new_stream(s, 0); | |
195 if (!st) | |
196 return AVERROR_NOMEM; | |
197 | |
198 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
199 st->codec.codec_id = s->iformat->value; | |
306 | 200 st->need_parsing = 1; |
201 | |
0 | 202 /* for mjpeg, specify frame rate */ |
203 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ | |
306 | 204 if (st->codec.codec_id == CODEC_ID_MJPEG || |
205 st->codec.codec_id == CODEC_ID_MPEG4) { | |
206 if (ap && ap->frame_rate) { | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
207 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
208 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 209 } else { |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
210 st->codec.frame_rate = 25; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
211 st->codec.frame_rate_base = 1; |
0 | 212 } |
213 } | |
214 return 0; | |
215 } | |
216 | |
217 #define SEQ_START_CODE 0x000001b3 | |
218 #define GOP_START_CODE 0x000001b8 | |
219 #define PICTURE_START_CODE 0x00000100 | |
220 | |
221 /* XXX: improve that by looking at several start codes */ | |
222 static int mpegvideo_probe(AVProbeData *p) | |
223 { | |
49 | 224 int code; |
225 const uint8_t *d; | |
0 | 226 |
227 /* we search the first start code. If it is a sequence, gop or | |
228 picture start code then we decide it is an mpeg video | |
229 stream. We do not send highest value to give a chance to mpegts */ | |
49 | 230 /* NOTE: the search range was restricted to avoid too many false |
231 detections */ | |
232 | |
233 if (p->buf_size < 6) | |
234 return 0; | |
235 d = p->buf; | |
236 code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]); | |
237 if ((code & 0xffffff00) == 0x100) { | |
238 if (code == SEQ_START_CODE || | |
239 code == GOP_START_CODE || | |
240 code == PICTURE_START_CODE) | |
241 return 50 - 1; | |
242 else | |
243 return 0; | |
0 | 244 } |
245 return 0; | |
246 } | |
247 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
248 static int h263_probe(AVProbeData *p) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
249 { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
250 int code; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
251 const uint8_t *d; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
252 |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
253 if (p->buf_size < 6) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
254 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
255 d = p->buf; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
256 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
257 if (code == 0x20) { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
258 return 50; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
259 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
260 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
261 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
262 |
0 | 263 AVInputFormat ac3_iformat = { |
264 "ac3", | |
265 "raw ac3", | |
266 0, | |
267 NULL, | |
63 | 268 ac3_read_header, |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
269 raw_read_partial_packet, |
0 | 270 raw_read_close, |
271 .extensions = "ac3", | |
272 }; | |
273 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
274 #ifdef CONFIG_ENCODERS |
0 | 275 AVOutputFormat ac3_oformat = { |
276 "ac3", | |
277 "raw ac3", | |
278 "audio/x-ac3", | |
279 "ac3", | |
280 0, | |
281 CODEC_ID_AC3, | |
282 0, | |
283 raw_write_header, | |
284 raw_write_packet, | |
285 raw_write_trailer, | |
286 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
287 #endif //CONFIG_ENCODERS |
0 | 288 |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
289 AVInputFormat h263_iformat = { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
290 "h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
291 "raw h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
292 0, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
293 h263_probe, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
294 video_read_header, |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
295 raw_read_partial_packet, |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
296 raw_read_close, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
297 // .extensions = "h263", //FIXME remove after writing mpeg4_probe |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
298 .value = CODEC_ID_H263, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
299 }; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
300 |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
301 #ifdef CONFIG_ENCODERS |
0 | 302 AVOutputFormat h263_oformat = { |
303 "h263", | |
304 "raw h263", | |
305 "video/x-h263", | |
306 "h263", | |
307 0, | |
308 0, | |
309 CODEC_ID_H263, | |
310 raw_write_header, | |
311 raw_write_packet, | |
312 raw_write_trailer, | |
313 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
314 #endif //CONFIG_ENCODERS |
0 | 315 |
316 AVInputFormat m4v_iformat = { | |
317 "m4v", | |
318 "raw MPEG4 video format", | |
319 0, | |
320 NULL /*mpegvideo_probe*/, | |
321 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
322 raw_read_partial_packet, |
0 | 323 raw_read_close, |
324 .extensions = "m4v", //FIXME remove after writing mpeg4_probe | |
325 .value = CODEC_ID_MPEG4, | |
326 }; | |
327 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
328 #ifdef CONFIG_ENCODERS |
0 | 329 AVOutputFormat m4v_oformat = { |
330 "m4v", | |
331 "raw MPEG4 video format", | |
332 NULL, | |
333 "m4v", | |
334 0, | |
335 CODEC_ID_NONE, | |
336 CODEC_ID_MPEG4, | |
337 raw_write_header, | |
338 raw_write_packet, | |
339 raw_write_trailer, | |
340 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
341 #endif //CONFIG_ENCODERS |
0 | 342 |
100 | 343 AVInputFormat h264_iformat = { |
344 "h264", | |
345 "raw H264 video format", | |
346 0, | |
347 NULL /*mpegvideo_probe*/, | |
348 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
349 raw_read_partial_packet, |
100 | 350 raw_read_close, |
351 .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe | |
352 .value = CODEC_ID_H264, | |
353 }; | |
354 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
355 #ifdef CONFIG_ENCODERS |
100 | 356 AVOutputFormat h264_oformat = { |
357 "h264", | |
358 "raw H264 video format", | |
359 NULL, | |
360 "h264", | |
361 0, | |
362 CODEC_ID_NONE, | |
363 CODEC_ID_H264, | |
364 raw_write_header, | |
365 raw_write_packet, | |
366 raw_write_trailer, | |
367 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
368 #endif //CONFIG_ENCODERS |
100 | 369 |
0 | 370 AVInputFormat mpegvideo_iformat = { |
371 "mpegvideo", | |
372 "MPEG video", | |
373 0, | |
374 mpegvideo_probe, | |
375 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
376 raw_read_partial_packet, |
0 | 377 raw_read_close, |
378 .value = CODEC_ID_MPEG1VIDEO, | |
379 }; | |
380 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
381 #ifdef CONFIG_ENCODERS |
0 | 382 AVOutputFormat mpeg1video_oformat = { |
383 "mpeg1video", | |
384 "MPEG video", | |
385 "video/x-mpeg", | |
386 "mpg,mpeg", | |
387 0, | |
388 0, | |
389 CODEC_ID_MPEG1VIDEO, | |
390 raw_write_header, | |
391 raw_write_packet, | |
392 raw_write_trailer, | |
393 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
394 #endif //CONFIG_ENCODERS |
0 | 395 |
396 AVInputFormat mjpeg_iformat = { | |
397 "mjpeg", | |
398 "MJPEG video", | |
399 0, | |
400 NULL, | |
401 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
402 raw_read_partial_packet, |
0 | 403 raw_read_close, |
404 .extensions = "mjpg,mjpeg", | |
405 .value = CODEC_ID_MJPEG, | |
406 }; | |
407 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
408 #ifdef CONFIG_ENCODERS |
0 | 409 AVOutputFormat mjpeg_oformat = { |
410 "mjpeg", | |
411 "MJPEG video", | |
412 "video/x-mjpeg", | |
413 "mjpg,mjpeg", | |
414 0, | |
415 0, | |
416 CODEC_ID_MJPEG, | |
417 raw_write_header, | |
418 raw_write_packet, | |
419 raw_write_trailer, | |
420 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
421 #endif //CONFIG_ENCODERS |
0 | 422 |
423 /* pcm formats */ | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
424 |
306 | 425 #define PCMINPUTDEF(name, long_name, ext, codec) \ |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
426 AVInputFormat pcm_ ## name ## _iformat = {\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
427 #name,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
428 long_name,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
429 0,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
430 NULL,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
431 raw_read_header,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
432 raw_read_packet,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
433 raw_read_close,\ |
306 | 434 pcm_read_seek,\ |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
435 .extensions = ext,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
436 .value = codec,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
437 }; |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
438 |
306 | 439 #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) |
440 | |
441 #define PCMDEF(name, long_name, ext, codec) \ | |
442 PCMINPUTDEF(name, long_name, ext, codec) | |
443 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
444 #else |
0 | 445 |
446 #define PCMDEF(name, long_name, ext, codec) \ | |
306 | 447 PCMINPUTDEF(name, long_name, ext, codec)\ |
0 | 448 \ |
449 AVOutputFormat pcm_ ## name ## _oformat = {\ | |
450 #name,\ | |
451 long_name,\ | |
452 NULL,\ | |
453 ext,\ | |
454 0,\ | |
455 codec,\ | |
456 0,\ | |
457 raw_write_header,\ | |
458 raw_write_packet,\ | |
459 raw_write_trailer,\ | |
460 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
461 #endif //CONFIG_ENCODERS |
0 | 462 |
463 #ifdef WORDS_BIGENDIAN | |
464 #define BE_DEF(s) s | |
465 #define LE_DEF(s) NULL | |
466 #else | |
467 #define BE_DEF(s) NULL | |
468 #define LE_DEF(s) s | |
469 #endif | |
470 | |
471 | |
472 PCMDEF(s16le, "pcm signed 16 bit little endian format", | |
473 LE_DEF("sw"), CODEC_ID_PCM_S16LE) | |
474 | |
475 PCMDEF(s16be, "pcm signed 16 bit big endian format", | |
476 BE_DEF("sw"), CODEC_ID_PCM_S16BE) | |
477 | |
478 PCMDEF(u16le, "pcm unsigned 16 bit little endian format", | |
479 LE_DEF("uw"), CODEC_ID_PCM_U16LE) | |
480 | |
481 PCMDEF(u16be, "pcm unsigned 16 bit big endian format", | |
482 BE_DEF("uw"), CODEC_ID_PCM_U16BE) | |
483 | |
484 PCMDEF(s8, "pcm signed 8 bit format", | |
485 "sb", CODEC_ID_PCM_S8) | |
486 | |
487 PCMDEF(u8, "pcm unsigned 8 bit format", | |
488 "ub", CODEC_ID_PCM_U8) | |
489 | |
490 PCMDEF(mulaw, "pcm mu law format", | |
491 "ul", CODEC_ID_PCM_MULAW) | |
492 | |
493 PCMDEF(alaw, "pcm A law format", | |
494 "al", CODEC_ID_PCM_ALAW) | |
495 | |
64 | 496 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 497 { |
498 int packet_size, ret, width, height; | |
499 AVStream *st = s->streams[0]; | |
500 | |
501 width = st->codec.width; | |
502 height = st->codec.height; | |
503 | |
128 | 504 packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); |
505 if (packet_size < 0) | |
0 | 506 av_abort(); |
507 | |
508 if (av_new_packet(pkt, packet_size) < 0) | |
509 return -EIO; | |
510 | |
511 pkt->stream_index = 0; | |
512 #if 0 | |
513 /* bypass buffered I/O */ | |
514 ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size); | |
515 #else | |
516 ret = get_buffer(&s->pb, pkt->data, pkt->size); | |
517 #endif | |
518 if (ret != pkt->size) { | |
519 av_free_packet(pkt); | |
520 return -EIO; | |
521 } else { | |
522 return 0; | |
523 } | |
524 } | |
525 | |
526 AVInputFormat rawvideo_iformat = { | |
527 "rawvideo", | |
528 "raw video format", | |
529 0, | |
530 NULL, | |
531 raw_read_header, | |
532 rawvideo_read_packet, | |
533 raw_read_close, | |
534 .extensions = "yuv", | |
535 .value = CODEC_ID_RAWVIDEO, | |
536 }; | |
537 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
538 #ifdef CONFIG_ENCODERS |
0 | 539 AVOutputFormat rawvideo_oformat = { |
540 "rawvideo", | |
541 "raw video format", | |
542 NULL, | |
543 "yuv", | |
544 0, | |
545 CODEC_ID_NONE, | |
546 CODEC_ID_RAWVIDEO, | |
547 raw_write_header, | |
548 raw_write_packet, | |
549 raw_write_trailer, | |
550 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
551 #endif //CONFIG_ENCODERS |
0 | 552 |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
553 #ifdef CONFIG_ENCODERS |
0 | 554 static int null_write_packet(struct AVFormatContext *s, |
555 int stream_index, | |
241 | 556 const uint8_t *buf, int size, int64_t pts) |
0 | 557 { |
558 return 0; | |
559 } | |
560 | |
561 AVOutputFormat null_oformat = { | |
562 "null", | |
563 "null video format", | |
564 NULL, | |
565 NULL, | |
566 0, | |
567 #ifdef WORDS_BIGENDIAN | |
568 CODEC_ID_PCM_S16BE, | |
569 #else | |
570 CODEC_ID_PCM_S16LE, | |
571 #endif | |
572 CODEC_ID_RAWVIDEO, | |
573 raw_write_header, | |
574 null_write_packet, | |
575 raw_write_trailer, | |
576 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE, | |
577 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
578 #endif //CONFIG_ENCODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
579 |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
580 #ifndef CONFIG_ENCODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
581 #define av_register_output_format(format) |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
582 #endif |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
583 #ifndef CONFIG_DECODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
584 #define av_register_input_format(format) |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
585 #endif |
0 | 586 |
587 int raw_init(void) | |
588 { | |
589 av_register_input_format(&ac3_iformat); | |
590 av_register_output_format(&ac3_oformat); | |
591 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
592 av_register_input_format(&h263_iformat); |
0 | 593 av_register_output_format(&h263_oformat); |
594 | |
595 av_register_input_format(&m4v_iformat); | |
596 av_register_output_format(&m4v_oformat); | |
100 | 597 |
598 av_register_input_format(&h264_iformat); | |
599 av_register_output_format(&h264_oformat); | |
0 | 600 |
601 av_register_input_format(&mpegvideo_iformat); | |
602 av_register_output_format(&mpeg1video_oformat); | |
603 | |
604 av_register_input_format(&mjpeg_iformat); | |
605 av_register_output_format(&mjpeg_oformat); | |
606 | |
607 av_register_input_format(&pcm_s16le_iformat); | |
608 av_register_output_format(&pcm_s16le_oformat); | |
609 av_register_input_format(&pcm_s16be_iformat); | |
610 av_register_output_format(&pcm_s16be_oformat); | |
611 av_register_input_format(&pcm_u16le_iformat); | |
612 av_register_output_format(&pcm_u16le_oformat); | |
613 av_register_input_format(&pcm_u16be_iformat); | |
614 av_register_output_format(&pcm_u16be_oformat); | |
615 av_register_input_format(&pcm_s8_iformat); | |
616 av_register_output_format(&pcm_s8_oformat); | |
617 av_register_input_format(&pcm_u8_iformat); | |
618 av_register_output_format(&pcm_u8_oformat); | |
619 av_register_input_format(&pcm_mulaw_iformat); | |
620 av_register_output_format(&pcm_mulaw_oformat); | |
621 av_register_input_format(&pcm_alaw_iformat); | |
622 av_register_output_format(&pcm_alaw_oformat); | |
623 | |
624 av_register_input_format(&rawvideo_iformat); | |
625 av_register_output_format(&rawvideo_oformat); | |
626 | |
627 av_register_output_format(&null_oformat); | |
628 return 0; | |
629 } |