annotate rsoenc.c @ 6435:67433b0c29d5 libavformat

move h264 demuxer to its own file
author aurel
date Sun, 29 Aug 2010 21:28:51 +0000
parents ab5b82b7b8e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6288
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
1 /*
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
2 * RSO muxer
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard (original AU code)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
4 * Copyright (c) 2010 Rafael Carre
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
5 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
6 * This file is part of FFmpeg.
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
7 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
12 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
16 * Lesser General Public License for more details.
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
17 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
21 */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
22
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
23 #include "avformat.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
24 #include "internal.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
25 #include "riff.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
26 #include "rso.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
27
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
28 static int rso_write_header(AVFormatContext *s)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
29 {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
30 ByteIOContext *pb = s->pb;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
31 AVCodecContext *enc = s->streams[0]->codec;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
32
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
33 if (!enc->codec_tag)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
34 return AVERROR_INVALIDDATA;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
35
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
36 if (enc->channels != 1) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
37 av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
38 return AVERROR_INVALIDDATA;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
39 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
40
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
41 if (url_is_streamed(s->pb)) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
42 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
43 return AVERROR_INVALIDDATA;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
44 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
45
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
46 /* XXX: find legal sample rates (if any) */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
47 if (enc->sample_rate >= 1u<<16) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
48 av_log(s, AV_LOG_ERROR, "Sample rate must be < 65536\n");
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
49 return AVERROR_INVALIDDATA;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
50 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
51
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
52 if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
53 av_log(s, AV_LOG_ERROR, "ADPCM in RSO not implemented\n");
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
54 return AVERROR_PATCHWELCOME;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
55 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
56
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
57 /* format header */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
58 put_be16(pb, enc->codec_tag); /* codec ID */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
59 put_be16(pb, 0); /* data size, will be written at EOF */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
60 put_be16(pb, enc->sample_rate);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
61 put_be16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
62
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
63 put_flush_packet(pb);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
64
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
65 return 0;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
66 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
67
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
68 static int rso_write_packet(AVFormatContext *s, AVPacket *pkt)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
69 {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
70 put_buffer(s->pb, pkt->data, pkt->size);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
71 return 0;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
72 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
73
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
74 static int rso_write_trailer(AVFormatContext *s)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
75 {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
76 ByteIOContext *pb = s->pb;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
77 int64_t file_size;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
78 uint16_t coded_file_size;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
79
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
80 file_size = url_ftell(pb);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
81
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
82 if (file_size < 0)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
83 return file_size;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
84
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
85 if (file_size > 0xffff + RSO_HEADER_SIZE) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
86 av_log(s, AV_LOG_WARNING,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
87 "Output file is too big (%"PRId64" bytes >= 64kB)\n", file_size);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
88 coded_file_size = 0xffff;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
89 } else {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
90 coded_file_size = file_size - RSO_HEADER_SIZE;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
91 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
92
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
93 /* update file size */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
94 url_fseek(pb, 2, SEEK_SET);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
95 put_be16(pb, coded_file_size);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
96 url_fseek(pb, file_size, SEEK_SET);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
97
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
98 put_flush_packet(pb);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
99
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
100 return 0;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
101 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
102
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
103 AVOutputFormat rso_muxer = {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
104 .name = "rso",
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
105 .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO format"),
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
106 .extensions = "rso",
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
107 .priv_data_size = 0,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
108 .audio_codec = CODEC_ID_PCM_U8,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
109 .video_codec = CODEC_ID_NONE,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
110 .write_header = rso_write_header,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
111 .write_packet = rso_write_packet,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
112 .write_trailer = rso_write_trailer,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
113 .codec_tag = (const AVCodecTag* const []){ff_codec_rso_tags, 0},
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
114 };