Commit | Line | Data |
---|---|---|
de6d9b64 FB |
1 | /* |
2 | * RAW encoder and decoder | |
19720f15 | 3 | * Copyright (c) 2001 Fabrice Bellard. |
de6d9b64 | 4 | * |
19720f15 FB |
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. | |
de6d9b64 | 9 | * |
19720f15 | 10 | * This library is distributed in the hope that it will be useful, |
de6d9b64 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19720f15 FB |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. | |
de6d9b64 | 14 | * |
19720f15 FB |
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 | |
de6d9b64 | 18 | */ |
de6d9b64 FB |
19 | #include "avformat.h" |
20 | ||
764ef400 | 21 | #ifdef CONFIG_ENCODERS |
de6d9b64 | 22 | /* simple formats */ |
5c91a675 | 23 | static int raw_write_header(struct AVFormatContext *s) |
de6d9b64 FB |
24 | { |
25 | return 0; | |
26 | } | |
27 | ||
e928649b | 28 | static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
de6d9b64 | 29 | { |
e928649b | 30 | put_buffer(&s->pb, pkt->data, pkt->size); |
de6d9b64 FB |
31 | put_flush_packet(&s->pb); |
32 | return 0; | |
33 | } | |
34 | ||
5c91a675 | 35 | static int raw_write_trailer(struct AVFormatContext *s) |
de6d9b64 FB |
36 | { |
37 | return 0; | |
38 | } | |
764ef400 | 39 | #endif //CONFIG_ENCODERS |
de6d9b64 FB |
40 | |
41 | /* raw input */ | |
0c1a9eda | 42 | static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) |
de6d9b64 FB |
43 | { |
44 | AVStream *st; | |
c9a65ca8 | 45 | int id; |
de6d9b64 | 46 | |
c9a65ca8 | 47 | st = av_new_stream(s, 0); |
de6d9b64 | 48 | if (!st) |
c9a65ca8 | 49 | return AVERROR_NOMEM; |
de6d9b64 | 50 | if (ap) { |
c9a65ca8 FB |
51 | id = s->iformat->value; |
52 | if (id == CODEC_ID_RAWVIDEO) { | |
de6d9b64 | 53 | st->codec.codec_type = CODEC_TYPE_VIDEO; |
de6d9b64 | 54 | } else { |
c9a65ca8 | 55 | st->codec.codec_type = CODEC_TYPE_AUDIO; |
de6d9b64 | 56 | } |
c9a65ca8 FB |
57 | st->codec.codec_id = id; |
58 | ||
de6d9b64 FB |
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; | |
595bf4ef | 63 | av_set_pts_info(st, 64, 1, st->codec.sample_rate); |
de6d9b64 FB |
64 | break; |
65 | case CODEC_TYPE_VIDEO: | |
c0df9d75 | 66 | av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); |
de6d9b64 FB |
67 | st->codec.width = ap->width; |
68 | st->codec.height = ap->height; | |
63167088 | 69 | st->codec.pix_fmt = ap->pix_fmt; |
de6d9b64 FB |
70 | break; |
71 | default: | |
27e084bd | 72 | return -1; |
de6d9b64 FB |
73 | } |
74 | } else { | |
27e084bd | 75 | return -1; |
de6d9b64 FB |
76 | } |
77 | return 0; | |
78 | } | |
79 | ||
2e93e3aa | 80 | #define RAW_PACKET_SIZE 1024 |
de6d9b64 | 81 | |
5c91a675 | 82 | static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) |
de6d9b64 | 83 | { |
7866eeff | 84 | int ret, size; |
2a6874fd | 85 | // AVStream *st = s->streams[0]; |
7866eeff | 86 | |
231dd3f3 | 87 | size= RAW_PACKET_SIZE; |
de6d9b64 | 88 | |
7866eeff | 89 | if (av_new_packet(pkt, size) < 0) |
0bd586c5 | 90 | return AVERROR_IO; |
de6d9b64 FB |
91 | |
92 | pkt->stream_index = 0; | |
7866eeff | 93 | ret = get_buffer(&s->pb, pkt->data, size); |
2e93e3aa | 94 | if (ret <= 0) { |
de6d9b64 | 95 | av_free_packet(pkt); |
0bd586c5 | 96 | return AVERROR_IO; |
2e93e3aa FB |
97 | } |
98 | /* note: we need to modify the packet size here to handle the last | |
99 | packet */ | |
100 | pkt->size = ret; | |
de6d9b64 FB |
101 | return ret; |
102 | } | |
103 | ||
e15dec10 LS |
104 | static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) |
105 | { | |
106 | int ret, size; | |
107 | ||
108 | size = RAW_PACKET_SIZE; | |
109 | ||
110 | if (av_new_packet(pkt, size) < 0) | |
0bd586c5 | 111 | return AVERROR_IO; |
e15dec10 LS |
112 | |
113 | pkt->stream_index = 0; | |
114 | ret = get_partial_buffer(&s->pb, pkt->data, size); | |
115 | if (ret <= 0) { | |
116 | av_free_packet(pkt); | |
0bd586c5 | 117 | return AVERROR_IO; |
e15dec10 LS |
118 | } |
119 | pkt->size = ret; | |
120 | return ret; | |
121 | } | |
122 | ||
5c91a675 | 123 | static int raw_read_close(AVFormatContext *s) |
de6d9b64 FB |
124 | { |
125 | return 0; | |
126 | } | |
127 | ||
4986a429 | 128 | int pcm_read_seek(AVFormatContext *s, |
7b3c1382 | 129 | int stream_index, int64_t timestamp, int flags) |
4986a429 FB |
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 */ | |
7b3c1382 MN |
161 | pos = av_rescale_rnd(timestamp * byte_rate, |
162 | st->time_base.num, | |
163 | st->time_base.den * (int64_t)block_align, | |
164 | (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP); | |
165 | pos *= block_align; | |
4986a429 FB |
166 | |
167 | /* recompute exact position */ | |
77405fc8 | 168 | st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); |
4986a429 FB |
169 | url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); |
170 | return 0; | |
171 | } | |
172 | ||
cd66005d FB |
173 | /* ac3 read */ |
174 | static int ac3_read_header(AVFormatContext *s, | |
175 | AVFormatParameters *ap) | |
176 | { | |
177 | AVStream *st; | |
178 | ||
179 | st = av_new_stream(s, 0); | |
180 | if (!st) | |
181 | return AVERROR_NOMEM; | |
182 | ||
183 | st->codec.codec_type = CODEC_TYPE_AUDIO; | |
184 | st->codec.codec_id = CODEC_ID_AC3; | |
4986a429 | 185 | st->need_parsing = 1; |
cd66005d FB |
186 | /* the parameters will be extracted from the compressed bitstream */ |
187 | return 0; | |
188 | } | |
189 | ||
85ad5695 MN |
190 | static int shorten_read_header(AVFormatContext *s, |
191 | AVFormatParameters *ap) | |
192 | { | |
193 | AVStream *st; | |
194 | ||
195 | st = av_new_stream(s, 0); | |
196 | if (!st) | |
197 | return AVERROR_NOMEM; | |
198 | st->codec.codec_type = CODEC_TYPE_AUDIO; | |
199 | st->codec.codec_id = CODEC_ID_SHORTEN; | |
200 | st->need_parsing = 1; | |
201 | /* the parameters will be extracted from the compressed bitstream */ | |
202 | return 0; | |
203 | } | |
204 | ||
23c99253 MN |
205 | /* dts read */ |
206 | static int dts_read_header(AVFormatContext *s, | |
207 | AVFormatParameters *ap) | |
208 | { | |
209 | AVStream *st; | |
210 | ||
211 | st = av_new_stream(s, 0); | |
212 | if (!st) | |
213 | return AVERROR_NOMEM; | |
214 | ||
215 | st->codec.codec_type = CODEC_TYPE_AUDIO; | |
216 | st->codec.codec_id = CODEC_ID_DTS; | |
217 | st->need_parsing = 1; | |
218 | /* the parameters will be extracted from the compressed bitstream */ | |
219 | return 0; | |
220 | } | |
221 | ||
de6d9b64 FB |
222 | /* mpeg1/h263 input */ |
223 | static int video_read_header(AVFormatContext *s, | |
224 | AVFormatParameters *ap) | |
225 | { | |
226 | AVStream *st; | |
227 | ||
c9a65ca8 | 228 | st = av_new_stream(s, 0); |
de6d9b64 | 229 | if (!st) |
c9a65ca8 | 230 | return AVERROR_NOMEM; |
de6d9b64 FB |
231 | |
232 | st->codec.codec_type = CODEC_TYPE_VIDEO; | |
c9a65ca8 | 233 | st->codec.codec_id = s->iformat->value; |
4986a429 FB |
234 | st->need_parsing = 1; |
235 | ||
27e084bd | 236 | /* for mjpeg, specify frame rate */ |
7866eeff | 237 | /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ |
4986a429 FB |
238 | if (st->codec.codec_id == CODEC_ID_MJPEG || |
239 | st->codec.codec_id == CODEC_ID_MPEG4) { | |
c0df9d75 MN |
240 | if (ap && ap->time_base.num) { |
241 | av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); | |
27e084bd | 242 | } else { |
c0df9d75 | 243 | av_set_pts_info(st, 64, 1, 25); |
27e084bd FB |
244 | } |
245 | } | |
de6d9b64 FB |
246 | return 0; |
247 | } | |
248 | ||
c9a65ca8 FB |
249 | #define SEQ_START_CODE 0x000001b3 |
250 | #define GOP_START_CODE 0x000001b8 | |
251 | #define PICTURE_START_CODE 0x00000100 | |
252 | ||
253 | /* XXX: improve that by looking at several start codes */ | |
254 | static int mpegvideo_probe(AVProbeData *p) | |
255 | { | |
fa777321 FB |
256 | int code; |
257 | const uint8_t *d; | |
c9a65ca8 FB |
258 | |
259 | /* we search the first start code. If it is a sequence, gop or | |
260 | picture start code then we decide it is an mpeg video | |
261 | stream. We do not send highest value to give a chance to mpegts */ | |
fa777321 FB |
262 | /* NOTE: the search range was restricted to avoid too many false |
263 | detections */ | |
264 | ||
265 | if (p->buf_size < 6) | |
266 | return 0; | |
267 | d = p->buf; | |
268 | code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]); | |
269 | if ((code & 0xffffff00) == 0x100) { | |
270 | if (code == SEQ_START_CODE || | |
271 | code == GOP_START_CODE || | |
272 | code == PICTURE_START_CODE) | |
273 | return 50 - 1; | |
274 | else | |
275 | return 0; | |
c9a65ca8 FB |
276 | } |
277 | return 0; | |
278 | } | |
279 | ||
d07f9043 MN |
280 | static int h263_probe(AVProbeData *p) |
281 | { | |
282 | int code; | |
283 | const uint8_t *d; | |
284 | ||
285 | if (p->buf_size < 6) | |
286 | return 0; | |
287 | d = p->buf; | |
288 | code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); | |
289 | if (code == 0x20) { | |
290 | return 50; | |
291 | } | |
292 | return 0; | |
293 | } | |
294 | ||
c6148de2 MN |
295 | static int h261_probe(AVProbeData *p) |
296 | { | |
297 | int code; | |
298 | const uint8_t *d; | |
299 | ||
300 | if (p->buf_size < 6) | |
301 | return 0; | |
302 | d = p->buf; | |
303 | code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4); | |
304 | if (code == 0x10) { | |
305 | return 50; | |
306 | } | |
307 | return 0; | |
308 | } | |
309 | ||
85ad5695 MN |
310 | AVInputFormat shorten_iformat = { |
311 | "shn", | |
312 | "raw shn", | |
313 | 0, | |
314 | NULL, | |
315 | shorten_read_header, | |
316 | raw_read_partial_packet, | |
317 | raw_read_close, | |
318 | .extensions = "shn", | |
319 | }; | |
320 | ||
c9a65ca8 FB |
321 | AVInputFormat ac3_iformat = { |
322 | "ac3", | |
323 | "raw ac3", | |
324 | 0, | |
325 | NULL, | |
cd66005d | 326 | ac3_read_header, |
e15dec10 | 327 | raw_read_partial_packet, |
de6d9b64 | 328 | raw_read_close, |
bb76a117 | 329 | .extensions = "ac3", |
de6d9b64 FB |
330 | }; |
331 | ||
764ef400 | 332 | #ifdef CONFIG_ENCODERS |
c9a65ca8 | 333 | AVOutputFormat ac3_oformat = { |
de6d9b64 FB |
334 | "ac3", |
335 | "raw ac3", | |
336 | "audio/x-ac3", | |
337 | "ac3", | |
c9a65ca8 | 338 | 0, |
de6d9b64 FB |
339 | CODEC_ID_AC3, |
340 | 0, | |
341 | raw_write_header, | |
342 | raw_write_packet, | |
343 | raw_write_trailer, | |
344 | }; | |
764ef400 | 345 | #endif //CONFIG_ENCODERS |
de6d9b64 | 346 | |
23c99253 MN |
347 | AVInputFormat dts_iformat = { |
348 | "dts", | |
349 | "raw dts", | |
350 | 0, | |
351 | NULL, | |
352 | dts_read_header, | |
353 | raw_read_partial_packet, | |
354 | raw_read_close, | |
355 | .extensions = "dts", | |
356 | }; | |
357 | ||
c6148de2 MN |
358 | AVInputFormat h261_iformat = { |
359 | "h261", | |
360 | "raw h261", | |
361 | 0, | |
362 | h261_probe, | |
363 | video_read_header, | |
364 | raw_read_partial_packet, | |
365 | raw_read_close, | |
366 | .extensions = "h261", | |
367 | .value = CODEC_ID_H261, | |
368 | }; | |
369 | ||
1c3990db MN |
370 | #ifdef CONFIG_ENCODERS |
371 | AVOutputFormat h261_oformat = { | |
372 | "h261", | |
373 | "raw h261", | |
374 | "video/x-h261", | |
375 | "h261", | |
376 | 0, | |
377 | 0, | |
378 | CODEC_ID_H261, | |
379 | raw_write_header, | |
380 | raw_write_packet, | |
381 | raw_write_trailer, | |
382 | }; | |
383 | #endif //CONFIG_ENCODERS | |
384 | ||
d07f9043 MN |
385 | AVInputFormat h263_iformat = { |
386 | "h263", | |
387 | "raw h263", | |
388 | 0, | |
389 | h263_probe, | |
390 | video_read_header, | |
e15dec10 | 391 | raw_read_partial_packet, |
d07f9043 MN |
392 | raw_read_close, |
393 | // .extensions = "h263", //FIXME remove after writing mpeg4_probe | |
394 | .value = CODEC_ID_H263, | |
395 | }; | |
396 | ||
764ef400 | 397 | #ifdef CONFIG_ENCODERS |
c9a65ca8 | 398 | AVOutputFormat h263_oformat = { |
de6d9b64 FB |
399 | "h263", |
400 | "raw h263", | |
401 | "video/x-h263", | |
402 | "h263", | |
403 | 0, | |
c9a65ca8 | 404 | 0, |
de6d9b64 FB |
405 | CODEC_ID_H263, |
406 | raw_write_header, | |
407 | raw_write_packet, | |
408 | raw_write_trailer, | |
c9a65ca8 | 409 | }; |
764ef400 | 410 | #endif //CONFIG_ENCODERS |
c9a65ca8 | 411 | |
7866eeff MN |
412 | AVInputFormat m4v_iformat = { |
413 | "m4v", | |
414 | "raw MPEG4 video format", | |
415 | 0, | |
2f0f5b20 | 416 | NULL /*mpegvideo_probe*/, |
7866eeff | 417 | video_read_header, |
e15dec10 | 418 | raw_read_partial_packet, |
7866eeff | 419 | raw_read_close, |
bb76a117 MR |
420 | .extensions = "m4v", //FIXME remove after writing mpeg4_probe |
421 | .value = CODEC_ID_MPEG4, | |
7866eeff MN |
422 | }; |
423 | ||
764ef400 | 424 | #ifdef CONFIG_ENCODERS |
89b3d7c9 MK |
425 | AVOutputFormat m4v_oformat = { |
426 | "m4v", | |
427 | "raw MPEG4 video format", | |
428 | NULL, | |
429 | "m4v", | |
430 | 0, | |
431 | CODEC_ID_NONE, | |
432 | CODEC_ID_MPEG4, | |
433 | raw_write_header, | |
434 | raw_write_packet, | |
435 | raw_write_trailer, | |
436 | }; | |
764ef400 | 437 | #endif //CONFIG_ENCODERS |
89b3d7c9 | 438 | |
0da71265 MN |
439 | AVInputFormat h264_iformat = { |
440 | "h264", | |
441 | "raw H264 video format", | |
442 | 0, | |
443 | NULL /*mpegvideo_probe*/, | |
444 | video_read_header, | |
e15dec10 | 445 | raw_read_partial_packet, |
0da71265 MN |
446 | raw_read_close, |
447 | .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe | |
448 | .value = CODEC_ID_H264, | |
449 | }; | |
450 | ||
764ef400 | 451 | #ifdef CONFIG_ENCODERS |
0da71265 MN |
452 | AVOutputFormat h264_oformat = { |
453 | "h264", | |
454 | "raw H264 video format", | |
455 | NULL, | |
456 | "h264", | |
457 | 0, | |
458 | CODEC_ID_NONE, | |
459 | CODEC_ID_H264, | |
460 | raw_write_header, | |
461 | raw_write_packet, | |
462 | raw_write_trailer, | |
463 | }; | |
764ef400 | 464 | #endif //CONFIG_ENCODERS |
0da71265 | 465 | |
c9a65ca8 FB |
466 | AVInputFormat mpegvideo_iformat = { |
467 | "mpegvideo", | |
468 | "MPEG video", | |
469 | 0, | |
470 | mpegvideo_probe, | |
de6d9b64 | 471 | video_read_header, |
e15dec10 | 472 | raw_read_partial_packet, |
de6d9b64 | 473 | raw_read_close, |
bb76a117 | 474 | .value = CODEC_ID_MPEG1VIDEO, |
de6d9b64 FB |
475 | }; |
476 | ||
764ef400 | 477 | #ifdef CONFIG_ENCODERS |
c9a65ca8 FB |
478 | AVOutputFormat mpeg1video_oformat = { |
479 | "mpeg1video", | |
de6d9b64 FB |
480 | "MPEG video", |
481 | "video/x-mpeg", | |
482 | "mpg,mpeg", | |
483 | 0, | |
c9a65ca8 | 484 | 0, |
de6d9b64 FB |
485 | CODEC_ID_MPEG1VIDEO, |
486 | raw_write_header, | |
487 | raw_write_packet, | |
488 | raw_write_trailer, | |
de6d9b64 | 489 | }; |
764ef400 | 490 | #endif //CONFIG_ENCODERS |
de6d9b64 | 491 | |
6ec864da MN |
492 | #ifdef CONFIG_ENCODERS |
493 | AVOutputFormat mpeg2video_oformat = { | |
494 | "mpeg2video", | |
495 | "MPEG2 video", | |
496 | NULL, | |
497 | "m2v", | |
498 | 0, | |
499 | 0, | |
500 | CODEC_ID_MPEG2VIDEO, | |
501 | raw_write_header, | |
502 | raw_write_packet, | |
503 | raw_write_trailer, | |
504 | }; | |
505 | #endif //CONFIG_ENCODERS | |
506 | ||
c9a65ca8 | 507 | AVInputFormat mjpeg_iformat = { |
27e084bd FB |
508 | "mjpeg", |
509 | "MJPEG video", | |
27e084bd | 510 | 0, |
c9a65ca8 | 511 | NULL, |
27e084bd | 512 | video_read_header, |
e15dec10 | 513 | raw_read_partial_packet, |
27e084bd | 514 | raw_read_close, |
bb76a117 MR |
515 | .extensions = "mjpg,mjpeg", |
516 | .value = CODEC_ID_MJPEG, | |
27e084bd FB |
517 | }; |
518 | ||
764ef400 | 519 | #ifdef CONFIG_ENCODERS |
c9a65ca8 FB |
520 | AVOutputFormat mjpeg_oformat = { |
521 | "mjpeg", | |
522 | "MJPEG video", | |
523 | "video/x-mjpeg", | |
524 | "mjpg,mjpeg", | |
5ed8fafc | 525 | 0, |
5ed8fafc | 526 | 0, |
c9a65ca8 | 527 | CODEC_ID_MJPEG, |
5ed8fafc FB |
528 | raw_write_header, |
529 | raw_write_packet, | |
530 | raw_write_trailer, | |
5ed8fafc | 531 | }; |
764ef400 | 532 | #endif //CONFIG_ENCODERS |
5ed8fafc | 533 | |
c9a65ca8 | 534 | /* pcm formats */ |
764ef400 | 535 | |
4986a429 | 536 | #define PCMINPUTDEF(name, long_name, ext, codec) \ |
764ef400 MM |
537 | AVInputFormat pcm_ ## name ## _iformat = {\ |
538 | #name,\ | |
539 | long_name,\ | |
540 | 0,\ | |
541 | NULL,\ | |
542 | raw_read_header,\ | |
543 | raw_read_packet,\ | |
544 | raw_read_close,\ | |
4986a429 | 545 | pcm_read_seek,\ |
764ef400 MM |
546 | .extensions = ext,\ |
547 | .value = codec,\ | |
548 | }; | |
549 | ||
4986a429 FB |
550 | #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) |
551 | ||
552 | #define PCMDEF(name, long_name, ext, codec) \ | |
553 | PCMINPUTDEF(name, long_name, ext, codec) | |
554 | ||
764ef400 | 555 | #else |
5ed8fafc | 556 | |
c9a65ca8 | 557 | #define PCMDEF(name, long_name, ext, codec) \ |
4986a429 | 558 | PCMINPUTDEF(name, long_name, ext, codec)\ |
c9a65ca8 FB |
559 | \ |
560 | AVOutputFormat pcm_ ## name ## _oformat = {\ | |
561 | #name,\ | |
562 | long_name,\ | |
563 | NULL,\ | |
564 | ext,\ | |
565 | 0,\ | |
566 | codec,\ | |
567 | 0,\ | |
568 | raw_write_header,\ | |
569 | raw_write_packet,\ | |
570 | raw_write_trailer,\ | |
5ed8fafc | 571 | }; |
764ef400 | 572 | #endif //CONFIG_ENCODERS |
5ed8fafc | 573 | |
5ed8fafc | 574 | #ifdef WORDS_BIGENDIAN |
c9a65ca8 FB |
575 | #define BE_DEF(s) s |
576 | #define LE_DEF(s) NULL | |
5ed8fafc | 577 | #else |
c9a65ca8 FB |
578 | #define BE_DEF(s) NULL |
579 | #define LE_DEF(s) s | |
5ed8fafc | 580 | #endif |
5ed8fafc | 581 | |
5ed8fafc | 582 | |
c9a65ca8 FB |
583 | PCMDEF(s16le, "pcm signed 16 bit little endian format", |
584 | LE_DEF("sw"), CODEC_ID_PCM_S16LE) | |
5ed8fafc | 585 | |
c9a65ca8 FB |
586 | PCMDEF(s16be, "pcm signed 16 bit big endian format", |
587 | BE_DEF("sw"), CODEC_ID_PCM_S16BE) | |
5ed8fafc | 588 | |
c9a65ca8 FB |
589 | PCMDEF(u16le, "pcm unsigned 16 bit little endian format", |
590 | LE_DEF("uw"), CODEC_ID_PCM_U16LE) | |
5ed8fafc | 591 | |
c9a65ca8 FB |
592 | PCMDEF(u16be, "pcm unsigned 16 bit big endian format", |
593 | BE_DEF("uw"), CODEC_ID_PCM_U16BE) | |
5ed8fafc | 594 | |
c9a65ca8 FB |
595 | PCMDEF(s8, "pcm signed 8 bit format", |
596 | "sb", CODEC_ID_PCM_S8) | |
5ed8fafc | 597 | |
c9a65ca8 FB |
598 | PCMDEF(u8, "pcm unsigned 8 bit format", |
599 | "ub", CODEC_ID_PCM_U8) | |
5ed8fafc | 600 | |
c9a65ca8 FB |
601 | PCMDEF(mulaw, "pcm mu law format", |
602 | "ul", CODEC_ID_PCM_MULAW) | |
de6d9b64 | 603 | |
c9a65ca8 FB |
604 | PCMDEF(alaw, "pcm A law format", |
605 | "al", CODEC_ID_PCM_ALAW) | |
de6d9b64 | 606 | |
5c91a675 | 607 | static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) |
de6d9b64 FB |
608 | { |
609 | int packet_size, ret, width, height; | |
610 | AVStream *st = s->streams[0]; | |
611 | ||
612 | width = st->codec.width; | |
613 | height = st->codec.height; | |
614 | ||
63167088 RS |
615 | packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); |
616 | if (packet_size < 0) | |
71c32f19 | 617 | return -1; |
de6d9b64 FB |
618 | |
619 | if (av_new_packet(pkt, packet_size) < 0) | |
0bd586c5 | 620 | return AVERROR_IO; |
de6d9b64 FB |
621 | |
622 | pkt->stream_index = 0; | |
c2c2cd2d | 623 | #if 0 |
de6d9b64 FB |
624 | /* bypass buffered I/O */ |
625 | ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size); | |
c2c2cd2d MN |
626 | #else |
627 | ret = get_buffer(&s->pb, pkt->data, pkt->size); | |
628 | #endif | |
de6d9b64 FB |
629 | if (ret != pkt->size) { |
630 | av_free_packet(pkt); | |
0bd586c5 | 631 | return AVERROR_IO; |
de6d9b64 FB |
632 | } else { |
633 | return 0; | |
634 | } | |
635 | } | |
636 | ||
c9a65ca8 FB |
637 | AVInputFormat rawvideo_iformat = { |
638 | "rawvideo", | |
639 | "raw video format", | |
640 | 0, | |
641 | NULL, | |
642 | raw_read_header, | |
643 | rawvideo_read_packet, | |
644 | raw_read_close, | |
bb76a117 MR |
645 | .extensions = "yuv", |
646 | .value = CODEC_ID_RAWVIDEO, | |
c9a65ca8 FB |
647 | }; |
648 | ||
764ef400 | 649 | #ifdef CONFIG_ENCODERS |
c9a65ca8 | 650 | AVOutputFormat rawvideo_oformat = { |
de6d9b64 FB |
651 | "rawvideo", |
652 | "raw video format", | |
653 | NULL, | |
654 | "yuv", | |
c9a65ca8 | 655 | 0, |
de6d9b64 FB |
656 | CODEC_ID_NONE, |
657 | CODEC_ID_RAWVIDEO, | |
658 | raw_write_header, | |
659 | raw_write_packet, | |
660 | raw_write_trailer, | |
de6d9b64 | 661 | }; |
764ef400 | 662 | #endif //CONFIG_ENCODERS |
c9a65ca8 | 663 | |
764ef400 | 664 | #ifdef CONFIG_ENCODERS |
e928649b | 665 | static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
87bdd3e5 FB |
666 | { |
667 | return 0; | |
668 | } | |
669 | ||
670 | AVOutputFormat null_oformat = { | |
671 | "null", | |
672 | "null video format", | |
673 | NULL, | |
674 | NULL, | |
675 | 0, | |
676 | #ifdef WORDS_BIGENDIAN | |
677 | CODEC_ID_PCM_S16BE, | |
678 | #else | |
679 | CODEC_ID_PCM_S16LE, | |
680 | #endif | |
681 | CODEC_ID_RAWVIDEO, | |
682 | raw_write_header, | |
683 | null_write_packet, | |
684 | raw_write_trailer, | |
b1d89f82 | 685 | .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE, |
87bdd3e5 | 686 | }; |
764ef400 MM |
687 | #endif //CONFIG_ENCODERS |
688 | ||
689 | #ifndef CONFIG_ENCODERS | |
690 | #define av_register_output_format(format) | |
691 | #endif | |
692 | #ifndef CONFIG_DECODERS | |
693 | #define av_register_input_format(format) | |
694 | #endif | |
87bdd3e5 | 695 | |
c9a65ca8 FB |
696 | int raw_init(void) |
697 | { | |
85ad5695 MN |
698 | |
699 | av_register_input_format(&shorten_iformat); | |
700 | ||
c9a65ca8 FB |
701 | av_register_input_format(&ac3_iformat); |
702 | av_register_output_format(&ac3_oformat); | |
703 | ||
23c99253 MN |
704 | av_register_input_format(&dts_iformat); |
705 | ||
c6148de2 | 706 | av_register_input_format(&h261_iformat); |
1c3990db | 707 | av_register_output_format(&h261_oformat); |
c6148de2 | 708 | |
d07f9043 | 709 | av_register_input_format(&h263_iformat); |
c9a65ca8 | 710 | av_register_output_format(&h263_oformat); |
89b3d7c9 | 711 | |
7866eeff | 712 | av_register_input_format(&m4v_iformat); |
89b3d7c9 | 713 | av_register_output_format(&m4v_oformat); |
0da71265 MN |
714 | |
715 | av_register_input_format(&h264_iformat); | |
716 | av_register_output_format(&h264_oformat); | |
c9a65ca8 FB |
717 | |
718 | av_register_input_format(&mpegvideo_iformat); | |
719 | av_register_output_format(&mpeg1video_oformat); | |
720 | ||
6ec864da MN |
721 | av_register_output_format(&mpeg2video_oformat); |
722 | ||
c9a65ca8 FB |
723 | av_register_input_format(&mjpeg_iformat); |
724 | av_register_output_format(&mjpeg_oformat); | |
725 | ||
726 | av_register_input_format(&pcm_s16le_iformat); | |
727 | av_register_output_format(&pcm_s16le_oformat); | |
728 | av_register_input_format(&pcm_s16be_iformat); | |
729 | av_register_output_format(&pcm_s16be_oformat); | |
730 | av_register_input_format(&pcm_u16le_iformat); | |
731 | av_register_output_format(&pcm_u16le_oformat); | |
732 | av_register_input_format(&pcm_u16be_iformat); | |
733 | av_register_output_format(&pcm_u16be_oformat); | |
734 | av_register_input_format(&pcm_s8_iformat); | |
735 | av_register_output_format(&pcm_s8_oformat); | |
736 | av_register_input_format(&pcm_u8_iformat); | |
737 | av_register_output_format(&pcm_u8_oformat); | |
738 | av_register_input_format(&pcm_mulaw_iformat); | |
739 | av_register_output_format(&pcm_mulaw_oformat); | |
740 | av_register_input_format(&pcm_alaw_iformat); | |
741 | av_register_output_format(&pcm_alaw_oformat); | |
742 | ||
743 | av_register_input_format(&rawvideo_iformat); | |
744 | av_register_output_format(&rawvideo_oformat); | |
87bdd3e5 FB |
745 | |
746 | av_register_output_format(&null_oformat); | |
c9a65ca8 FB |
747 | return 0; |
748 | } |