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