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; | |
de6d9b64 FB |
63 | break; |
64 | case CODEC_TYPE_VIDEO: | |
14bea432 MN |
65 | st->codec.frame_rate = ap->frame_rate; |
66 | st->codec.frame_rate_base = ap->frame_rate_base; | |
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 FB |
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 */ | |
cdd5034f | 161 | pos = av_rescale(timestamp * byte_rate, st->time_base.num, st->time_base.den); |
4986a429 FB |
162 | pos = (pos / block_align) * block_align; |
163 | ||
164 | /* recompute exact position */ | |
77405fc8 | 165 | st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); |
4986a429 FB |
166 | url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); |
167 | return 0; | |
168 | } | |
169 | ||
cd66005d FB |
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; | |
4986a429 | 182 | st->need_parsing = 1; |
cd66005d FB |
183 | /* the parameters will be extracted from the compressed bitstream */ |
184 | return 0; | |
185 | } | |
186 | ||
23c99253 MN |
187 | /* dts read */ |
188 | static int dts_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_AUDIO; | |
198 | st->codec.codec_id = CODEC_ID_DTS; | |
199 | st->need_parsing = 1; | |
200 | /* the parameters will be extracted from the compressed bitstream */ | |
201 | return 0; | |
202 | } | |
203 | ||
de6d9b64 FB |
204 | /* mpeg1/h263 input */ |
205 | static int video_read_header(AVFormatContext *s, | |
206 | AVFormatParameters *ap) | |
207 | { | |
208 | AVStream *st; | |
209 | ||
c9a65ca8 | 210 | st = av_new_stream(s, 0); |
de6d9b64 | 211 | if (!st) |
c9a65ca8 | 212 | return AVERROR_NOMEM; |
de6d9b64 FB |
213 | |
214 | st->codec.codec_type = CODEC_TYPE_VIDEO; | |
c9a65ca8 | 215 | st->codec.codec_id = s->iformat->value; |
4986a429 FB |
216 | st->need_parsing = 1; |
217 | ||
27e084bd | 218 | /* for mjpeg, specify frame rate */ |
7866eeff | 219 | /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ |
4986a429 FB |
220 | if (st->codec.codec_id == CODEC_ID_MJPEG || |
221 | st->codec.codec_id == CODEC_ID_MPEG4) { | |
222 | if (ap && ap->frame_rate) { | |
14bea432 MN |
223 | st->codec.frame_rate = ap->frame_rate; |
224 | st->codec.frame_rate_base = ap->frame_rate_base; | |
27e084bd | 225 | } else { |
14bea432 MN |
226 | st->codec.frame_rate = 25; |
227 | st->codec.frame_rate_base = 1; | |
27e084bd FB |
228 | } |
229 | } | |
de6d9b64 FB |
230 | return 0; |
231 | } | |
232 | ||
c9a65ca8 FB |
233 | #define SEQ_START_CODE 0x000001b3 |
234 | #define GOP_START_CODE 0x000001b8 | |
235 | #define PICTURE_START_CODE 0x00000100 | |
236 | ||
237 | /* XXX: improve that by looking at several start codes */ | |
238 | static int mpegvideo_probe(AVProbeData *p) | |
239 | { | |
fa777321 FB |
240 | int code; |
241 | const uint8_t *d; | |
c9a65ca8 FB |
242 | |
243 | /* we search the first start code. If it is a sequence, gop or | |
244 | picture start code then we decide it is an mpeg video | |
245 | stream. We do not send highest value to give a chance to mpegts */ | |
fa777321 FB |
246 | /* NOTE: the search range was restricted to avoid too many false |
247 | detections */ | |
248 | ||
249 | if (p->buf_size < 6) | |
250 | return 0; | |
251 | d = p->buf; | |
252 | code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]); | |
253 | if ((code & 0xffffff00) == 0x100) { | |
254 | if (code == SEQ_START_CODE || | |
255 | code == GOP_START_CODE || | |
256 | code == PICTURE_START_CODE) | |
257 | return 50 - 1; | |
258 | else | |
259 | return 0; | |
c9a65ca8 FB |
260 | } |
261 | return 0; | |
262 | } | |
263 | ||
d07f9043 MN |
264 | static int h263_probe(AVProbeData *p) |
265 | { | |
266 | int code; | |
267 | const uint8_t *d; | |
268 | ||
269 | if (p->buf_size < 6) | |
270 | return 0; | |
271 | d = p->buf; | |
272 | code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); | |
273 | if (code == 0x20) { | |
274 | return 50; | |
275 | } | |
276 | return 0; | |
277 | } | |
278 | ||
c6148de2 MN |
279 | static int h261_probe(AVProbeData *p) |
280 | { | |
281 | int code; | |
282 | const uint8_t *d; | |
283 | ||
284 | if (p->buf_size < 6) | |
285 | return 0; | |
286 | d = p->buf; | |
287 | code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4); | |
288 | if (code == 0x10) { | |
289 | return 50; | |
290 | } | |
291 | return 0; | |
292 | } | |
293 | ||
c9a65ca8 FB |
294 | AVInputFormat ac3_iformat = { |
295 | "ac3", | |
296 | "raw ac3", | |
297 | 0, | |
298 | NULL, | |
cd66005d | 299 | ac3_read_header, |
e15dec10 | 300 | raw_read_partial_packet, |
de6d9b64 | 301 | raw_read_close, |
bb76a117 | 302 | .extensions = "ac3", |
de6d9b64 FB |
303 | }; |
304 | ||
764ef400 | 305 | #ifdef CONFIG_ENCODERS |
c9a65ca8 | 306 | AVOutputFormat ac3_oformat = { |
de6d9b64 FB |
307 | "ac3", |
308 | "raw ac3", | |
309 | "audio/x-ac3", | |
310 | "ac3", | |
c9a65ca8 | 311 | 0, |
de6d9b64 FB |
312 | CODEC_ID_AC3, |
313 | 0, | |
314 | raw_write_header, | |
315 | raw_write_packet, | |
316 | raw_write_trailer, | |
317 | }; | |
764ef400 | 318 | #endif //CONFIG_ENCODERS |
de6d9b64 | 319 | |
23c99253 MN |
320 | AVInputFormat dts_iformat = { |
321 | "dts", | |
322 | "raw dts", | |
323 | 0, | |
324 | NULL, | |
325 | dts_read_header, | |
326 | raw_read_partial_packet, | |
327 | raw_read_close, | |
328 | .extensions = "dts", | |
329 | }; | |
330 | ||
c6148de2 MN |
331 | AVInputFormat h261_iformat = { |
332 | "h261", | |
333 | "raw h261", | |
334 | 0, | |
335 | h261_probe, | |
336 | video_read_header, | |
337 | raw_read_partial_packet, | |
338 | raw_read_close, | |
339 | .extensions = "h261", | |
340 | .value = CODEC_ID_H261, | |
341 | }; | |
342 | ||
d07f9043 MN |
343 | AVInputFormat h263_iformat = { |
344 | "h263", | |
345 | "raw h263", | |
346 | 0, | |
347 | h263_probe, | |
348 | video_read_header, | |
e15dec10 | 349 | raw_read_partial_packet, |
d07f9043 MN |
350 | raw_read_close, |
351 | // .extensions = "h263", //FIXME remove after writing mpeg4_probe | |
352 | .value = CODEC_ID_H263, | |
353 | }; | |
354 | ||
764ef400 | 355 | #ifdef CONFIG_ENCODERS |
c9a65ca8 | 356 | AVOutputFormat h263_oformat = { |
de6d9b64 FB |
357 | "h263", |
358 | "raw h263", | |
359 | "video/x-h263", | |
360 | "h263", | |
361 | 0, | |
c9a65ca8 | 362 | 0, |
de6d9b64 FB |
363 | CODEC_ID_H263, |
364 | raw_write_header, | |
365 | raw_write_packet, | |
366 | raw_write_trailer, | |
c9a65ca8 | 367 | }; |
764ef400 | 368 | #endif //CONFIG_ENCODERS |
c9a65ca8 | 369 | |
7866eeff MN |
370 | AVInputFormat m4v_iformat = { |
371 | "m4v", | |
372 | "raw MPEG4 video format", | |
373 | 0, | |
2f0f5b20 | 374 | NULL /*mpegvideo_probe*/, |
7866eeff | 375 | video_read_header, |
e15dec10 | 376 | raw_read_partial_packet, |
7866eeff | 377 | raw_read_close, |
bb76a117 MR |
378 | .extensions = "m4v", //FIXME remove after writing mpeg4_probe |
379 | .value = CODEC_ID_MPEG4, | |
7866eeff MN |
380 | }; |
381 | ||
764ef400 | 382 | #ifdef CONFIG_ENCODERS |
89b3d7c9 MK |
383 | AVOutputFormat m4v_oformat = { |
384 | "m4v", | |
385 | "raw MPEG4 video format", | |
386 | NULL, | |
387 | "m4v", | |
388 | 0, | |
389 | CODEC_ID_NONE, | |
390 | CODEC_ID_MPEG4, | |
391 | raw_write_header, | |
392 | raw_write_packet, | |
393 | raw_write_trailer, | |
394 | }; | |
764ef400 | 395 | #endif //CONFIG_ENCODERS |
89b3d7c9 | 396 | |
0da71265 MN |
397 | AVInputFormat h264_iformat = { |
398 | "h264", | |
399 | "raw H264 video format", | |
400 | 0, | |
401 | NULL /*mpegvideo_probe*/, | |
402 | video_read_header, | |
e15dec10 | 403 | raw_read_partial_packet, |
0da71265 MN |
404 | raw_read_close, |
405 | .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe | |
406 | .value = CODEC_ID_H264, | |
407 | }; | |
408 | ||
764ef400 | 409 | #ifdef CONFIG_ENCODERS |
0da71265 MN |
410 | AVOutputFormat h264_oformat = { |
411 | "h264", | |
412 | "raw H264 video format", | |
413 | NULL, | |
414 | "h264", | |
415 | 0, | |
416 | CODEC_ID_NONE, | |
417 | CODEC_ID_H264, | |
418 | raw_write_header, | |
419 | raw_write_packet, | |
420 | raw_write_trailer, | |
421 | }; | |
764ef400 | 422 | #endif //CONFIG_ENCODERS |
0da71265 | 423 | |
c9a65ca8 FB |
424 | AVInputFormat mpegvideo_iformat = { |
425 | "mpegvideo", | |
426 | "MPEG video", | |
427 | 0, | |
428 | mpegvideo_probe, | |
de6d9b64 | 429 | video_read_header, |
e15dec10 | 430 | raw_read_partial_packet, |
de6d9b64 | 431 | raw_read_close, |
bb76a117 | 432 | .value = CODEC_ID_MPEG1VIDEO, |
de6d9b64 FB |
433 | }; |
434 | ||
764ef400 | 435 | #ifdef CONFIG_ENCODERS |
c9a65ca8 FB |
436 | AVOutputFormat mpeg1video_oformat = { |
437 | "mpeg1video", | |
de6d9b64 FB |
438 | "MPEG video", |
439 | "video/x-mpeg", | |
440 | "mpg,mpeg", | |
441 | 0, | |
c9a65ca8 | 442 | 0, |
de6d9b64 FB |
443 | CODEC_ID_MPEG1VIDEO, |
444 | raw_write_header, | |
445 | raw_write_packet, | |
446 | raw_write_trailer, | |
de6d9b64 | 447 | }; |
764ef400 | 448 | #endif //CONFIG_ENCODERS |
de6d9b64 | 449 | |
c9a65ca8 | 450 | AVInputFormat mjpeg_iformat = { |
27e084bd FB |
451 | "mjpeg", |
452 | "MJPEG video", | |
27e084bd | 453 | 0, |
c9a65ca8 | 454 | NULL, |
27e084bd | 455 | video_read_header, |
e15dec10 | 456 | raw_read_partial_packet, |
27e084bd | 457 | raw_read_close, |
bb76a117 MR |
458 | .extensions = "mjpg,mjpeg", |
459 | .value = CODEC_ID_MJPEG, | |
27e084bd FB |
460 | }; |
461 | ||
764ef400 | 462 | #ifdef CONFIG_ENCODERS |
c9a65ca8 FB |
463 | AVOutputFormat mjpeg_oformat = { |
464 | "mjpeg", | |
465 | "MJPEG video", | |
466 | "video/x-mjpeg", | |
467 | "mjpg,mjpeg", | |
5ed8fafc | 468 | 0, |
5ed8fafc | 469 | 0, |
c9a65ca8 | 470 | CODEC_ID_MJPEG, |
5ed8fafc FB |
471 | raw_write_header, |
472 | raw_write_packet, | |
473 | raw_write_trailer, | |
5ed8fafc | 474 | }; |
764ef400 | 475 | #endif //CONFIG_ENCODERS |
5ed8fafc | 476 | |
c9a65ca8 | 477 | /* pcm formats */ |
764ef400 | 478 | |
4986a429 | 479 | #define PCMINPUTDEF(name, long_name, ext, codec) \ |
764ef400 MM |
480 | AVInputFormat pcm_ ## name ## _iformat = {\ |
481 | #name,\ | |
482 | long_name,\ | |
483 | 0,\ | |
484 | NULL,\ | |
485 | raw_read_header,\ | |
486 | raw_read_packet,\ | |
487 | raw_read_close,\ | |
4986a429 | 488 | pcm_read_seek,\ |
764ef400 MM |
489 | .extensions = ext,\ |
490 | .value = codec,\ | |
491 | }; | |
492 | ||
4986a429 FB |
493 | #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) |
494 | ||
495 | #define PCMDEF(name, long_name, ext, codec) \ | |
496 | PCMINPUTDEF(name, long_name, ext, codec) | |
497 | ||
764ef400 | 498 | #else |
5ed8fafc | 499 | |
c9a65ca8 | 500 | #define PCMDEF(name, long_name, ext, codec) \ |
4986a429 | 501 | PCMINPUTDEF(name, long_name, ext, codec)\ |
c9a65ca8 FB |
502 | \ |
503 | AVOutputFormat pcm_ ## name ## _oformat = {\ | |
504 | #name,\ | |
505 | long_name,\ | |
506 | NULL,\ | |
507 | ext,\ | |
508 | 0,\ | |
509 | codec,\ | |
510 | 0,\ | |
511 | raw_write_header,\ | |
512 | raw_write_packet,\ | |
513 | raw_write_trailer,\ | |
5ed8fafc | 514 | }; |
764ef400 | 515 | #endif //CONFIG_ENCODERS |
5ed8fafc | 516 | |
5ed8fafc | 517 | #ifdef WORDS_BIGENDIAN |
c9a65ca8 FB |
518 | #define BE_DEF(s) s |
519 | #define LE_DEF(s) NULL | |
5ed8fafc | 520 | #else |
c9a65ca8 FB |
521 | #define BE_DEF(s) NULL |
522 | #define LE_DEF(s) s | |
5ed8fafc | 523 | #endif |
5ed8fafc | 524 | |
5ed8fafc | 525 | |
c9a65ca8 FB |
526 | PCMDEF(s16le, "pcm signed 16 bit little endian format", |
527 | LE_DEF("sw"), CODEC_ID_PCM_S16LE) | |
5ed8fafc | 528 | |
c9a65ca8 FB |
529 | PCMDEF(s16be, "pcm signed 16 bit big endian format", |
530 | BE_DEF("sw"), CODEC_ID_PCM_S16BE) | |
5ed8fafc | 531 | |
c9a65ca8 FB |
532 | PCMDEF(u16le, "pcm unsigned 16 bit little endian format", |
533 | LE_DEF("uw"), CODEC_ID_PCM_U16LE) | |
5ed8fafc | 534 | |
c9a65ca8 FB |
535 | PCMDEF(u16be, "pcm unsigned 16 bit big endian format", |
536 | BE_DEF("uw"), CODEC_ID_PCM_U16BE) | |
5ed8fafc | 537 | |
c9a65ca8 FB |
538 | PCMDEF(s8, "pcm signed 8 bit format", |
539 | "sb", CODEC_ID_PCM_S8) | |
5ed8fafc | 540 | |
c9a65ca8 FB |
541 | PCMDEF(u8, "pcm unsigned 8 bit format", |
542 | "ub", CODEC_ID_PCM_U8) | |
5ed8fafc | 543 | |
c9a65ca8 FB |
544 | PCMDEF(mulaw, "pcm mu law format", |
545 | "ul", CODEC_ID_PCM_MULAW) | |
de6d9b64 | 546 | |
c9a65ca8 FB |
547 | PCMDEF(alaw, "pcm A law format", |
548 | "al", CODEC_ID_PCM_ALAW) | |
de6d9b64 | 549 | |
5c91a675 | 550 | static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) |
de6d9b64 FB |
551 | { |
552 | int packet_size, ret, width, height; | |
553 | AVStream *st = s->streams[0]; | |
554 | ||
555 | width = st->codec.width; | |
556 | height = st->codec.height; | |
557 | ||
63167088 RS |
558 | packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); |
559 | if (packet_size < 0) | |
71c32f19 | 560 | return -1; |
de6d9b64 FB |
561 | |
562 | if (av_new_packet(pkt, packet_size) < 0) | |
0bd586c5 | 563 | return AVERROR_IO; |
de6d9b64 FB |
564 | |
565 | pkt->stream_index = 0; | |
c2c2cd2d | 566 | #if 0 |
de6d9b64 FB |
567 | /* bypass buffered I/O */ |
568 | ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size); | |
c2c2cd2d MN |
569 | #else |
570 | ret = get_buffer(&s->pb, pkt->data, pkt->size); | |
571 | #endif | |
de6d9b64 FB |
572 | if (ret != pkt->size) { |
573 | av_free_packet(pkt); | |
0bd586c5 | 574 | return AVERROR_IO; |
de6d9b64 FB |
575 | } else { |
576 | return 0; | |
577 | } | |
578 | } | |
579 | ||
c9a65ca8 FB |
580 | AVInputFormat rawvideo_iformat = { |
581 | "rawvideo", | |
582 | "raw video format", | |
583 | 0, | |
584 | NULL, | |
585 | raw_read_header, | |
586 | rawvideo_read_packet, | |
587 | raw_read_close, | |
bb76a117 MR |
588 | .extensions = "yuv", |
589 | .value = CODEC_ID_RAWVIDEO, | |
c9a65ca8 FB |
590 | }; |
591 | ||
764ef400 | 592 | #ifdef CONFIG_ENCODERS |
c9a65ca8 | 593 | AVOutputFormat rawvideo_oformat = { |
de6d9b64 FB |
594 | "rawvideo", |
595 | "raw video format", | |
596 | NULL, | |
597 | "yuv", | |
c9a65ca8 | 598 | 0, |
de6d9b64 FB |
599 | CODEC_ID_NONE, |
600 | CODEC_ID_RAWVIDEO, | |
601 | raw_write_header, | |
602 | raw_write_packet, | |
603 | raw_write_trailer, | |
de6d9b64 | 604 | }; |
764ef400 | 605 | #endif //CONFIG_ENCODERS |
c9a65ca8 | 606 | |
764ef400 | 607 | #ifdef CONFIG_ENCODERS |
e928649b | 608 | static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
87bdd3e5 FB |
609 | { |
610 | return 0; | |
611 | } | |
612 | ||
613 | AVOutputFormat null_oformat = { | |
614 | "null", | |
615 | "null video format", | |
616 | NULL, | |
617 | NULL, | |
618 | 0, | |
619 | #ifdef WORDS_BIGENDIAN | |
620 | CODEC_ID_PCM_S16BE, | |
621 | #else | |
622 | CODEC_ID_PCM_S16LE, | |
623 | #endif | |
624 | CODEC_ID_RAWVIDEO, | |
625 | raw_write_header, | |
626 | null_write_packet, | |
627 | raw_write_trailer, | |
b1d89f82 | 628 | .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE, |
87bdd3e5 | 629 | }; |
764ef400 MM |
630 | #endif //CONFIG_ENCODERS |
631 | ||
632 | #ifndef CONFIG_ENCODERS | |
633 | #define av_register_output_format(format) | |
634 | #endif | |
635 | #ifndef CONFIG_DECODERS | |
636 | #define av_register_input_format(format) | |
637 | #endif | |
87bdd3e5 | 638 | |
c9a65ca8 FB |
639 | int raw_init(void) |
640 | { | |
c9a65ca8 FB |
641 | av_register_input_format(&ac3_iformat); |
642 | av_register_output_format(&ac3_oformat); | |
643 | ||
23c99253 MN |
644 | av_register_input_format(&dts_iformat); |
645 | ||
c6148de2 MN |
646 | av_register_input_format(&h261_iformat); |
647 | ||
d07f9043 | 648 | av_register_input_format(&h263_iformat); |
c9a65ca8 | 649 | av_register_output_format(&h263_oformat); |
89b3d7c9 | 650 | |
7866eeff | 651 | av_register_input_format(&m4v_iformat); |
89b3d7c9 | 652 | av_register_output_format(&m4v_oformat); |
0da71265 MN |
653 | |
654 | av_register_input_format(&h264_iformat); | |
655 | av_register_output_format(&h264_oformat); | |
c9a65ca8 FB |
656 | |
657 | av_register_input_format(&mpegvideo_iformat); | |
658 | av_register_output_format(&mpeg1video_oformat); | |
659 | ||
660 | av_register_input_format(&mjpeg_iformat); | |
661 | av_register_output_format(&mjpeg_oformat); | |
662 | ||
663 | av_register_input_format(&pcm_s16le_iformat); | |
664 | av_register_output_format(&pcm_s16le_oformat); | |
665 | av_register_input_format(&pcm_s16be_iformat); | |
666 | av_register_output_format(&pcm_s16be_oformat); | |
667 | av_register_input_format(&pcm_u16le_iformat); | |
668 | av_register_output_format(&pcm_u16le_oformat); | |
669 | av_register_input_format(&pcm_u16be_iformat); | |
670 | av_register_output_format(&pcm_u16be_oformat); | |
671 | av_register_input_format(&pcm_s8_iformat); | |
672 | av_register_output_format(&pcm_s8_oformat); | |
673 | av_register_input_format(&pcm_u8_iformat); | |
674 | av_register_output_format(&pcm_u8_oformat); | |
675 | av_register_input_format(&pcm_mulaw_iformat); | |
676 | av_register_output_format(&pcm_mulaw_oformat); | |
677 | av_register_input_format(&pcm_alaw_iformat); | |
678 | av_register_output_format(&pcm_alaw_oformat); | |
679 | ||
680 | av_register_input_format(&rawvideo_iformat); | |
681 | av_register_output_format(&rawvideo_oformat); | |
87bdd3e5 FB |
682 | |
683 | av_register_output_format(&null_oformat); | |
c9a65ca8 FB |
684 | return 0; |
685 | } |