9f12e551d8fc910928b583bdde4dab841e99e0e3
[libav.git] / libavformat / raw.c
1 /*
2 * RAW muxer and demuxer
3 * Copyright (c) 2001 Fabrice Bellard.
4 * Copyright (c) 2005 Alex Beregszaszi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include "avformat.h"
23 #include "ac3_parser.h"
24
25 #ifdef CONFIG_MUXERS
26 /* simple formats */
27 static int raw_write_header(struct AVFormatContext *s)
28 {
29 return 0;
30 }
31
32 static int flac_write_header(struct AVFormatContext *s)
33 {
34 static const uint8_t header[8] = {
35 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
36 };
37 uint8_t *streaminfo = s->streams[0]->codec->extradata;
38 int len = s->streams[0]->codec->extradata_size;
39 if(streaminfo != NULL && len > 0) {
40 put_buffer(&s->pb, header, 8);
41 put_buffer(&s->pb, streaminfo, len);
42 }
43 return 0;
44 }
45
46 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
47 {
48 put_buffer(&s->pb, pkt->data, pkt->size);
49 put_flush_packet(&s->pb);
50 return 0;
51 }
52
53 static int raw_write_trailer(struct AVFormatContext *s)
54 {
55 return 0;
56 }
57 #endif //CONFIG_MUXERS
58
59 /* raw input */
60 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
61 {
62 AVStream *st;
63 int id;
64
65 st = av_new_stream(s, 0);
66 if (!st)
67 return AVERROR_NOMEM;
68
69 id = s->iformat->value;
70 if (id == CODEC_ID_RAWVIDEO) {
71 st->codec->codec_type = CODEC_TYPE_VIDEO;
72 } else {
73 st->codec->codec_type = CODEC_TYPE_AUDIO;
74 }
75 st->codec->codec_id = id;
76
77 switch(st->codec->codec_type) {
78 case CODEC_TYPE_AUDIO:
79 st->codec->sample_rate = ap->sample_rate;
80 st->codec->channels = ap->channels;
81 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
82 break;
83 case CODEC_TYPE_VIDEO:
84 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
85 st->codec->width = ap->width;
86 st->codec->height = ap->height;
87 st->codec->pix_fmt = ap->pix_fmt;
88 if(st->codec->pix_fmt == PIX_FMT_NONE)
89 st->codec->pix_fmt= PIX_FMT_YUV420P;
90 break;
91 default:
92 return -1;
93 }
94 return 0;
95 }
96
97 #define RAW_PACKET_SIZE 1024
98
99 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
100 {
101 int ret, size;
102 // AVStream *st = s->streams[0];
103
104 size= RAW_PACKET_SIZE;
105
106 ret= av_get_packet(&s->pb, pkt, size);
107
108 pkt->stream_index = 0;
109 if (ret <= 0) {
110 return AVERROR_IO;
111 }
112 /* note: we need to modify the packet size here to handle the last
113 packet */
114 pkt->size = ret;
115 return ret;
116 }
117
118 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
119 {
120 int ret, size;
121
122 size = RAW_PACKET_SIZE;
123
124 if (av_new_packet(pkt, size) < 0)
125 return AVERROR_IO;
126
127 pkt->pos= url_ftell(&s->pb);
128 pkt->stream_index = 0;
129 ret = get_partial_buffer(&s->pb, pkt->data, size);
130 if (ret <= 0) {
131 av_free_packet(pkt);
132 return AVERROR_IO;
133 }
134 pkt->size = ret;
135 return ret;
136 }
137
138 // http://www.artificis.hu/files/texts/ingenient.txt
139 static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
140 {
141 int ret, size, w, h, unk1, unk2;
142
143 if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
144 return AVERROR_IO; // FIXME
145
146 size = get_le32(&s->pb);
147
148 w = get_le16(&s->pb);
149 h = get_le16(&s->pb);
150
151 url_fskip(&s->pb, 8); // zero + size (padded?)
152 url_fskip(&s->pb, 2);
153 unk1 = get_le16(&s->pb);
154 unk2 = get_le16(&s->pb);
155 url_fskip(&s->pb, 22); // ascii timestamp
156
157 av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
158 size, w, h, unk1, unk2);
159
160 if (av_new_packet(pkt, size) < 0)
161 return AVERROR_IO;
162
163 pkt->pos = url_ftell(&s->pb);
164 pkt->stream_index = 0;
165 ret = get_buffer(&s->pb, pkt->data, size);
166 if (ret <= 0) {
167 av_free_packet(pkt);
168 return AVERROR_IO;
169 }
170 pkt->size = ret;
171 return ret;
172 }
173
174 static int raw_read_close(AVFormatContext *s)
175 {
176 return 0;
177 }
178
179 int pcm_read_seek(AVFormatContext *s,
180 int stream_index, int64_t timestamp, int flags)
181 {
182 AVStream *st;
183 int block_align, byte_rate;
184 int64_t pos;
185
186 st = s->streams[0];
187
188 block_align = st->codec->block_align ? st->codec->block_align :
189 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
190 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
191 block_align * st->codec->sample_rate;
192
193 if (block_align <= 0 || byte_rate <= 0)
194 return -1;
195
196 /* compute the position by aligning it to block_align */
197 pos = av_rescale_rnd(timestamp * byte_rate,
198 st->time_base.num,
199 st->time_base.den * (int64_t)block_align,
200 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
201 pos *= block_align;
202
203 /* recompute exact position */
204 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
205 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
206 return 0;
207 }
208
209 /* ac3 read */
210 static int ac3_read_header(AVFormatContext *s,
211 AVFormatParameters *ap)
212 {
213 AVStream *st;
214
215 st = av_new_stream(s, 0);
216 if (!st)
217 return AVERROR_NOMEM;
218
219 st->codec->codec_type = CODEC_TYPE_AUDIO;
220 st->codec->codec_id = CODEC_ID_AC3;
221 st->need_parsing = AVSTREAM_PARSE_FULL;
222 /* the parameters will be extracted from the compressed bitstream */
223 return 0;
224 }
225
226 static int shorten_read_header(AVFormatContext *s,
227 AVFormatParameters *ap)
228 {
229 AVStream *st;
230
231 st = av_new_stream(s, 0);
232 if (!st)
233 return AVERROR_NOMEM;
234 st->codec->codec_type = CODEC_TYPE_AUDIO;
235 st->codec->codec_id = CODEC_ID_SHORTEN;
236 st->need_parsing = AVSTREAM_PARSE_FULL;
237 /* the parameters will be extracted from the compressed bitstream */
238 return 0;
239 }
240
241 /* flac read */
242 static int flac_read_header(AVFormatContext *s,
243 AVFormatParameters *ap)
244 {
245 AVStream *st;
246
247 st = av_new_stream(s, 0);
248 if (!st)
249 return AVERROR_NOMEM;
250 st->codec->codec_type = CODEC_TYPE_AUDIO;
251 st->codec->codec_id = CODEC_ID_FLAC;
252 st->need_parsing = AVSTREAM_PARSE_FULL;
253 /* the parameters will be extracted from the compressed bitstream */
254 return 0;
255 }
256
257 /* dts read */
258 static int dts_read_header(AVFormatContext *s,
259 AVFormatParameters *ap)
260 {
261 AVStream *st;
262
263 st = av_new_stream(s, 0);
264 if (!st)
265 return AVERROR_NOMEM;
266
267 st->codec->codec_type = CODEC_TYPE_AUDIO;
268 st->codec->codec_id = CODEC_ID_DTS;
269 st->need_parsing = AVSTREAM_PARSE_FULL;
270 /* the parameters will be extracted from the compressed bitstream */
271 return 0;
272 }
273
274 /* aac read */
275 static int aac_read_header(AVFormatContext *s,
276 AVFormatParameters *ap)
277 {
278 AVStream *st;
279
280 st = av_new_stream(s, 0);
281 if (!st)
282 return AVERROR_NOMEM;
283
284 st->codec->codec_type = CODEC_TYPE_AUDIO;
285 st->codec->codec_id = CODEC_ID_AAC;
286 st->need_parsing = AVSTREAM_PARSE_FULL;
287 /* the parameters will be extracted from the compressed bitstream */
288 return 0;
289 }
290
291 /* mpeg1/h263 input */
292 static int video_read_header(AVFormatContext *s,
293 AVFormatParameters *ap)
294 {
295 AVStream *st;
296
297 st = av_new_stream(s, 0);
298 if (!st)
299 return AVERROR_NOMEM;
300
301 st->codec->codec_type = CODEC_TYPE_VIDEO;
302 st->codec->codec_id = s->iformat->value;
303 st->need_parsing = AVSTREAM_PARSE_FULL;
304
305 /* for mjpeg, specify frame rate */
306 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
307 if (ap->time_base.num) {
308 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
309 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
310 st->codec->codec_id == CODEC_ID_MPEG4 ||
311 st->codec->codec_id == CODEC_ID_H264) {
312 av_set_pts_info(st, 64, 1, 25);
313 }
314
315 return 0;
316 }
317
318 #define SEQ_START_CODE 0x000001b3
319 #define GOP_START_CODE 0x000001b8
320 #define PICTURE_START_CODE 0x00000100
321 #define SLICE_START_CODE 0x00000101
322 #define PACK_START_CODE 0x000001ba
323 #define VIDEO_ID 0x000001e0
324 #define AUDIO_ID 0x000001c0
325
326 static int mpegvideo_probe(AVProbeData *p)
327 {
328 uint32_t code= -1;
329 int pic=0, seq=0, slice=0, pspack=0, pes=0;
330 int i;
331
332 for(i=0; i<p->buf_size; i++){
333 code = (code<<8) + p->buf[i];
334 if ((code & 0xffffff00) == 0x100) {
335 switch(code){
336 case SEQ_START_CODE: seq++; break;
337 case PICTURE_START_CODE: pic++; break;
338 case SLICE_START_CODE: slice++; break;
339 case PACK_START_CODE: pspack++; break;
340 }
341 if ((code & 0x1f0) == VIDEO_ID) pes++;
342 else if((code & 0x1e0) == AUDIO_ID) pes++;
343 }
344 }
345 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
346 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
347 return 0;
348 }
349
350 #define VISUAL_OBJECT_START_CODE 0x000001b5
351 #define VOP_START_CODE 0x000001b6
352
353 static int mpeg4video_probe(AVProbeData *probe_packet)
354 {
355 uint32_t temp_buffer= -1;
356 int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
357 int i;
358
359 for(i=0; i<probe_packet->buf_size; i++){
360 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
361 if ((temp_buffer & 0xffffff00) == 0x100) {
362 switch(temp_buffer){
363 case VOP_START_CODE: VOP++; break;
364 case VISUAL_OBJECT_START_CODE: VISO++; break;
365 case 0x100 ... 0x11F: VO++; break;
366 case 0x120 ... 0x12F: VOL++; break;
367 case 0x130 ... 0x1AF:
368 case 0x1B7 ... 0x1B9:
369 case 0x1C4 ... 0x1FF: res++; break;
370 }
371 }
372 }
373
374 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
375 return AVPROBE_SCORE_MAX/2;
376 return 0;
377 }
378
379 static int h263_probe(AVProbeData *p)
380 {
381 int code;
382 const uint8_t *d;
383
384 d = p->buf;
385 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
386 if (code == 0x20) {
387 return 50;
388 }
389 return 0;
390 }
391
392 static int h261_probe(AVProbeData *p)
393 {
394 int code;
395 const uint8_t *d;
396
397 d = p->buf;
398 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
399 if (code == 0x10) {
400 return 50;
401 }
402 return 0;
403 }
404
405 static int ac3_probe(AVProbeData *p)
406 {
407 int max_frames, first_frames, frames;
408 uint8_t *buf, *buf2, *end;
409 AC3HeaderInfo hdr;
410
411 if(p->buf_size < 7)
412 return 0;
413
414 max_frames = 0;
415 buf = p->buf;
416 end = buf + FFMIN(4096, p->buf_size - 7);
417
418 for(; buf < end; buf++) {
419 buf2 = buf;
420
421 for(frames = 0; buf2 < end; frames++) {
422 if(ff_ac3_parse_header(buf2, &hdr) < 0)
423 break;
424 buf2 += hdr.frame_size;
425 }
426 max_frames = FFMAX(max_frames, frames);
427 if(buf == p->buf)
428 first_frames = frames;
429 }
430 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
431 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
432 else if(max_frames>=1) return 1;
433 else return 0;
434 }
435
436 AVInputFormat shorten_demuxer = {
437 "shn",
438 "raw shorten",
439 0,
440 NULL,
441 shorten_read_header,
442 raw_read_partial_packet,
443 raw_read_close,
444 .flags= AVFMT_GENERIC_INDEX,
445 .extensions = "shn",
446 };
447
448 AVInputFormat flac_demuxer = {
449 "flac",
450 "raw flac",
451 0,
452 NULL,
453 flac_read_header,
454 raw_read_partial_packet,
455 raw_read_close,
456 .flags= AVFMT_GENERIC_INDEX,
457 .extensions = "flac",
458 };
459
460 #ifdef CONFIG_MUXERS
461 AVOutputFormat flac_muxer = {
462 "flac",
463 "raw flac",
464 "audio/x-flac",
465 "flac",
466 0,
467 CODEC_ID_FLAC,
468 0,
469 flac_write_header,
470 raw_write_packet,
471 raw_write_trailer,
472 .flags= AVFMT_NOTIMESTAMPS,
473 };
474 #endif //CONFIG_MUXERS
475
476 #ifdef CONFIG_AC3_DEMUXER
477 AVInputFormat ac3_demuxer = {
478 "ac3",
479 "raw ac3",
480 0,
481 ac3_probe,
482 ac3_read_header,
483 raw_read_partial_packet,
484 raw_read_close,
485 .flags= AVFMT_GENERIC_INDEX,
486 .extensions = "ac3",
487 };
488 #endif
489
490 #ifdef CONFIG_MUXERS
491 AVOutputFormat ac3_muxer = {
492 "ac3",
493 "raw ac3",
494 "audio/x-ac3",
495 "ac3",
496 0,
497 CODEC_ID_AC3,
498 0,
499 raw_write_header,
500 raw_write_packet,
501 raw_write_trailer,
502 .flags= AVFMT_NOTIMESTAMPS,
503 };
504 #endif //CONFIG_MUXERS
505
506 AVInputFormat dts_demuxer = {
507 "dts",
508 "raw dts",
509 0,
510 NULL,
511 dts_read_header,
512 raw_read_partial_packet,
513 raw_read_close,
514 .flags= AVFMT_GENERIC_INDEX,
515 .extensions = "dts",
516 };
517
518 AVInputFormat aac_demuxer = {
519 "aac",
520 "ADTS AAC",
521 0,
522 NULL,
523 aac_read_header,
524 raw_read_partial_packet,
525 raw_read_close,
526 .flags= AVFMT_GENERIC_INDEX,
527 .extensions = "aac",
528 };
529
530 AVInputFormat h261_demuxer = {
531 "h261",
532 "raw h261",
533 0,
534 h261_probe,
535 video_read_header,
536 raw_read_partial_packet,
537 raw_read_close,
538 .flags= AVFMT_GENERIC_INDEX,
539 .extensions = "h261",
540 .value = CODEC_ID_H261,
541 };
542
543 #ifdef CONFIG_MUXERS
544 AVOutputFormat h261_muxer = {
545 "h261",
546 "raw h261",
547 "video/x-h261",
548 "h261",
549 0,
550 0,
551 CODEC_ID_H261,
552 raw_write_header,
553 raw_write_packet,
554 raw_write_trailer,
555 .flags= AVFMT_NOTIMESTAMPS,
556 };
557 #endif //CONFIG_MUXERS
558
559 AVInputFormat h263_demuxer = {
560 "h263",
561 "raw h263",
562 0,
563 h263_probe,
564 video_read_header,
565 raw_read_partial_packet,
566 raw_read_close,
567 .flags= AVFMT_GENERIC_INDEX,
568 // .extensions = "h263", //FIXME remove after writing mpeg4_probe
569 .value = CODEC_ID_H263,
570 };
571
572 #ifdef CONFIG_MUXERS
573 AVOutputFormat h263_muxer = {
574 "h263",
575 "raw h263",
576 "video/x-h263",
577 "h263",
578 0,
579 0,
580 CODEC_ID_H263,
581 raw_write_header,
582 raw_write_packet,
583 raw_write_trailer,
584 .flags= AVFMT_NOTIMESTAMPS,
585 };
586 #endif //CONFIG_MUXERS
587
588 AVInputFormat m4v_demuxer = {
589 "m4v",
590 "raw MPEG4 video format",
591 0,
592 mpeg4video_probe, /** probing for mpeg4 data */
593 video_read_header,
594 raw_read_partial_packet,
595 raw_read_close,
596 .flags= AVFMT_GENERIC_INDEX,
597 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
598 .value = CODEC_ID_MPEG4,
599 };
600
601 #ifdef CONFIG_MUXERS
602 AVOutputFormat m4v_muxer = {
603 "m4v",
604 "raw MPEG4 video format",
605 NULL,
606 "m4v",
607 0,
608 CODEC_ID_NONE,
609 CODEC_ID_MPEG4,
610 raw_write_header,
611 raw_write_packet,
612 raw_write_trailer,
613 .flags= AVFMT_NOTIMESTAMPS,
614 };
615 #endif //CONFIG_MUXERS
616
617 AVInputFormat h264_demuxer = {
618 "h264",
619 "raw H264 video format",
620 0,
621 NULL /*mpegvideo_probe*/,
622 video_read_header,
623 raw_read_partial_packet,
624 raw_read_close,
625 .flags= AVFMT_GENERIC_INDEX,
626 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
627 .value = CODEC_ID_H264,
628 };
629
630 #ifdef CONFIG_MUXERS
631 AVOutputFormat h264_muxer = {
632 "h264",
633 "raw H264 video format",
634 NULL,
635 "h264",
636 0,
637 CODEC_ID_NONE,
638 CODEC_ID_H264,
639 raw_write_header,
640 raw_write_packet,
641 raw_write_trailer,
642 .flags= AVFMT_NOTIMESTAMPS,
643 };
644 #endif //CONFIG_MUXERS
645
646 AVInputFormat mpegvideo_demuxer = {
647 "mpegvideo",
648 "MPEG video",
649 0,
650 mpegvideo_probe,
651 video_read_header,
652 raw_read_partial_packet,
653 raw_read_close,
654 .flags= AVFMT_GENERIC_INDEX,
655 .value = CODEC_ID_MPEG1VIDEO,
656 };
657
658 #ifdef CONFIG_MUXERS
659 AVOutputFormat mpeg1video_muxer = {
660 "mpeg1video",
661 "MPEG video",
662 "video/x-mpeg",
663 "mpg,mpeg,m1v",
664 0,
665 0,
666 CODEC_ID_MPEG1VIDEO,
667 raw_write_header,
668 raw_write_packet,
669 raw_write_trailer,
670 .flags= AVFMT_NOTIMESTAMPS,
671 };
672 #endif //CONFIG_MUXERS
673
674 #ifdef CONFIG_MUXERS
675 AVOutputFormat mpeg2video_muxer = {
676 "mpeg2video",
677 "MPEG2 video",
678 NULL,
679 "m2v",
680 0,
681 0,
682 CODEC_ID_MPEG2VIDEO,
683 raw_write_header,
684 raw_write_packet,
685 raw_write_trailer,
686 .flags= AVFMT_NOTIMESTAMPS,
687 };
688 #endif //CONFIG_MUXERS
689
690 AVInputFormat mjpeg_demuxer = {
691 "mjpeg",
692 "MJPEG video",
693 0,
694 NULL,
695 video_read_header,
696 raw_read_partial_packet,
697 raw_read_close,
698 .flags= AVFMT_GENERIC_INDEX,
699 .extensions = "mjpg,mjpeg",
700 .value = CODEC_ID_MJPEG,
701 };
702
703 AVInputFormat ingenient_demuxer = {
704 "ingenient",
705 "Ingenient MJPEG",
706 0,
707 NULL,
708 video_read_header,
709 ingenient_read_packet,
710 raw_read_close,
711 .flags= AVFMT_GENERIC_INDEX,
712 .extensions = "cgi", // FIXME
713 .value = CODEC_ID_MJPEG,
714 };
715
716 #ifdef CONFIG_MUXERS
717 AVOutputFormat mjpeg_muxer = {
718 "mjpeg",
719 "MJPEG video",
720 "video/x-mjpeg",
721 "mjpg,mjpeg",
722 0,
723 0,
724 CODEC_ID_MJPEG,
725 raw_write_header,
726 raw_write_packet,
727 raw_write_trailer,
728 .flags= AVFMT_NOTIMESTAMPS,
729 };
730 #endif //CONFIG_MUXERS
731
732 AVInputFormat vc1_demuxer = {
733 "vc1",
734 "raw vc1",
735 0,
736 NULL /* vc1_probe */,
737 video_read_header,
738 raw_read_partial_packet,
739 raw_read_close,
740 .extensions = "vc1",
741 .value = CODEC_ID_VC1,
742 };
743
744 /* pcm formats */
745
746 #define PCMINPUTDEF(name, long_name, ext, codec) \
747 AVInputFormat pcm_ ## name ## _demuxer = {\
748 #name,\
749 long_name,\
750 0,\
751 NULL,\
752 raw_read_header,\
753 raw_read_packet,\
754 raw_read_close,\
755 pcm_read_seek,\
756 .flags= AVFMT_GENERIC_INDEX,\
757 .extensions = ext,\
758 .value = codec,\
759 };
760
761 #define PCMOUTPUTDEF(name, long_name, ext, codec) \
762 AVOutputFormat pcm_ ## name ## _muxer = {\
763 #name,\
764 long_name,\
765 NULL,\
766 ext,\
767 0,\
768 codec,\
769 0,\
770 raw_write_header,\
771 raw_write_packet,\
772 raw_write_trailer,\
773 .flags= AVFMT_NOTIMESTAMPS,\
774 };
775
776
777 #if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
778 #define PCMDEF(name, long_name, ext, codec) \
779 PCMINPUTDEF(name, long_name, ext, codec)
780 #elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
781 #define PCMDEF(name, long_name, ext, codec) \
782 PCMOUTPUTDEF(name, long_name, ext, codec)
783 #elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
784 #define PCMDEF(name, long_name, ext, codec) \
785 PCMINPUTDEF(name, long_name, ext, codec)\
786 PCMOUTPUTDEF(name, long_name, ext, codec)
787 #else
788 #define PCMDEF(name, long_name, ext, codec)
789 #endif
790
791 #ifdef WORDS_BIGENDIAN
792 #define BE_DEF(s) s
793 #define LE_DEF(s) NULL
794 #else
795 #define BE_DEF(s) NULL
796 #define LE_DEF(s) s
797 #endif
798
799
800 PCMDEF(s16le, "pcm signed 16 bit little endian format",
801 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
802
803 PCMDEF(s16be, "pcm signed 16 bit big endian format",
804 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
805
806 PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
807 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
808
809 PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
810 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
811
812 PCMDEF(s8, "pcm signed 8 bit format",
813 "sb", CODEC_ID_PCM_S8)
814
815 PCMDEF(u8, "pcm unsigned 8 bit format",
816 "ub", CODEC_ID_PCM_U8)
817
818 PCMDEF(mulaw, "pcm mu law format",
819 "ul", CODEC_ID_PCM_MULAW)
820
821 PCMDEF(alaw, "pcm A law format",
822 "al", CODEC_ID_PCM_ALAW)
823
824 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
825 {
826 int packet_size, ret, width, height;
827 AVStream *st = s->streams[0];
828
829 width = st->codec->width;
830 height = st->codec->height;
831
832 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
833 if (packet_size < 0)
834 return -1;
835
836 ret= av_get_packet(&s->pb, pkt, packet_size);
837
838 pkt->stream_index = 0;
839 if (ret != packet_size) {
840 return AVERROR_IO;
841 } else {
842 return 0;
843 }
844 }
845
846 AVInputFormat rawvideo_demuxer = {
847 "rawvideo",
848 "raw video format",
849 0,
850 NULL,
851 raw_read_header,
852 rawvideo_read_packet,
853 raw_read_close,
854 .flags= AVFMT_GENERIC_INDEX,
855 .extensions = "yuv,cif,qcif",
856 .value = CODEC_ID_RAWVIDEO,
857 };
858
859 #ifdef CONFIG_MUXERS
860 AVOutputFormat rawvideo_muxer = {
861 "rawvideo",
862 "raw video format",
863 NULL,
864 "yuv,rgb",
865 0,
866 CODEC_ID_NONE,
867 CODEC_ID_RAWVIDEO,
868 raw_write_header,
869 raw_write_packet,
870 raw_write_trailer,
871 .flags= AVFMT_NOTIMESTAMPS,
872 };
873 #endif //CONFIG_MUXERS
874
875 #ifdef CONFIG_MUXERS
876 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
877 {
878 return 0;
879 }
880
881 AVOutputFormat null_muxer = {
882 "null",
883 "null video format",
884 NULL,
885 NULL,
886 0,
887 #ifdef WORDS_BIGENDIAN
888 CODEC_ID_PCM_S16BE,
889 #else
890 CODEC_ID_PCM_S16LE,
891 #endif
892 CODEC_ID_RAWVIDEO,
893 raw_write_header,
894 null_write_packet,
895 raw_write_trailer,
896 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
897 };
898 #endif //CONFIG_MUXERS