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