Mercurial > libavformat.hg
annotate c93.c @ 6340:3ef72a19674e libavformat
100l: av_freep() needs the address of the pointer
author | aurel |
---|---|
date | Fri, 30 Jul 2010 23:41:12 +0000 |
parents | 11bb10c37225 |
children |
rev | line source |
---|---|
1987 | 1 /* |
2 * Interplay C93 demuxer | |
3 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> | |
4 * | |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
2217 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1987 | 20 */ |
21 | |
22 #include "avformat.h" | |
23 #include "voc.h" | |
5181
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
24 #include "libavutil/intreadwrite.h" |
1987 | 25 |
26 typedef struct { | |
27 uint16_t index; | |
28 uint8_t length; | |
29 uint8_t frames; | |
30 } C93BlockRecord; | |
31 | |
32 typedef struct { | |
4081 | 33 VocDecContext voc; |
1987 | 34 |
35 C93BlockRecord block_records[512]; | |
36 int current_block; | |
37 | |
38 uint32_t frame_offsets[32]; | |
39 int current_frame; | |
40 int next_pkt_is_audio; | |
41 | |
42 AVStream *audio; | |
43 } C93DemuxContext; | |
44 | |
2000
ce51095f383b
also remove c93_ prefix for static function in the c93 demuxer
michael
parents:
1987
diff
changeset
|
45 static int probe(AVProbeData *p) |
1987 | 46 { |
5181
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
47 int i; |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
48 int index = 1; |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
49 if (p->buf_size < 16) |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
50 return 0; |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
51 for (i = 0; i < 16; i += 4) { |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
52 if (AV_RL16(p->buf + i) != index || !p->buf[i + 2] || !p->buf[i + 3]) |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
53 return 0; |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
54 index += p->buf[i + 2]; |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
55 } |
c900e8690782
Check the index validity more thoroughly for the c93 probe function.
reimar
parents:
4081
diff
changeset
|
56 return AVPROBE_SCORE_MAX; |
1987 | 57 } |
58 | |
2000
ce51095f383b
also remove c93_ prefix for static function in the c93 demuxer
michael
parents:
1987
diff
changeset
|
59 static int read_header(AVFormatContext *s, |
1987 | 60 AVFormatParameters *ap) |
61 { | |
62 AVStream *video; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
63 ByteIOContext *pb = s->pb; |
1987 | 64 C93DemuxContext *c93 = s->priv_data; |
65 int i; | |
66 int framecount = 0; | |
67 | |
68 for (i = 0; i < 512; i++) { | |
69 c93->block_records[i].index = get_le16(pb); | |
70 c93->block_records[i].length = get_byte(pb); | |
71 c93->block_records[i].frames = get_byte(pb); | |
72 if (c93->block_records[i].frames > 32) { | |
73 av_log(s, AV_LOG_ERROR, "too many frames in block\n"); | |
74 return AVERROR_INVALIDDATA; | |
75 } | |
76 framecount += c93->block_records[i].frames; | |
77 } | |
78 | |
79 /* Audio streams are added if audio packets are found */ | |
80 s->ctx_flags |= AVFMTCTX_NOHEADER; | |
81 | |
82 video = av_new_stream(s, 0); | |
83 if (!video) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2217
diff
changeset
|
84 return AVERROR(ENOMEM); |
1987 | 85 |
5910
536e5527c1e0
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
5181
diff
changeset
|
86 video->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
1987 | 87 video->codec->codec_id = CODEC_ID_C93; |
88 video->codec->width = 320; | |
89 video->codec->height = 192; | |
90 /* 4:3 320x200 with 8 empty lines */ | |
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3424
diff
changeset
|
91 video->sample_aspect_ratio = (AVRational) { 5, 6 }; |
1987 | 92 video->time_base = (AVRational) { 2, 25 }; |
93 video->nb_frames = framecount; | |
94 video->duration = framecount; | |
95 video->start_time = 0; | |
96 | |
97 c93->current_block = 0; | |
98 c93->current_frame = 0; | |
99 c93->next_pkt_is_audio = 0; | |
100 return 0; | |
101 } | |
102 | |
103 #define C93_HAS_PALETTE 0x01 | |
104 #define C93_FIRST_FRAME 0x02 | |
105 | |
2000
ce51095f383b
also remove c93_ prefix for static function in the c93 demuxer
michael
parents:
1987
diff
changeset
|
106 static int read_packet(AVFormatContext *s, AVPacket *pkt) |
1987 | 107 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
108 ByteIOContext *pb = s->pb; |
1987 | 109 C93DemuxContext *c93 = s->priv_data; |
110 C93BlockRecord *br = &c93->block_records[c93->current_block]; | |
111 int datasize; | |
112 int ret, i; | |
113 | |
114 if (c93->next_pkt_is_audio) { | |
115 c93->current_frame++; | |
116 c93->next_pkt_is_audio = 0; | |
117 datasize = get_le16(pb); | |
118 if (datasize > 42) { | |
119 if (!c93->audio) { | |
120 c93->audio = av_new_stream(s, 1); | |
121 if (!c93->audio) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2217
diff
changeset
|
122 return AVERROR(ENOMEM); |
5910
536e5527c1e0
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
5181
diff
changeset
|
123 c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; |
1987 | 124 } |
125 url_fskip(pb, 26); /* VOC header */ | |
126 ret = voc_get_packet(s, pkt, c93->audio, datasize - 26); | |
127 if (ret > 0) { | |
128 pkt->stream_index = 1; | |
5913
11bb10c37225
Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents:
5910
diff
changeset
|
129 pkt->flags |= AV_PKT_FLAG_KEY; |
1987 | 130 return ret; |
131 } | |
132 } | |
133 } | |
134 if (c93->current_frame >= br->frames) { | |
135 if (c93->current_block >= 511 || !br[1].length) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
136 return AVERROR(EIO); |
1987 | 137 br++; |
138 c93->current_block++; | |
139 c93->current_frame = 0; | |
140 } | |
141 | |
142 if (c93->current_frame == 0) { | |
143 url_fseek(pb, br->index * 2048, SEEK_SET); | |
144 for (i = 0; i < 32; i++) { | |
145 c93->frame_offsets[i] = get_le32(pb); | |
146 } | |
147 } | |
148 | |
149 url_fseek(pb,br->index * 2048 + | |
150 c93->frame_offsets[c93->current_frame], SEEK_SET); | |
151 datasize = get_le16(pb); /* video frame size */ | |
152 | |
153 ret = av_new_packet(pkt, datasize + 768 + 1); | |
154 if (ret < 0) | |
155 return ret; | |
156 pkt->data[0] = 0; | |
157 pkt->size = datasize + 1; | |
158 | |
159 ret = get_buffer(pb, pkt->data + 1, datasize); | |
160 if (ret < datasize) { | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
161 ret = AVERROR(EIO); |
1987 | 162 goto fail; |
163 } | |
164 | |
165 datasize = get_le16(pb); /* palette size */ | |
166 if (datasize) { | |
167 if (datasize != 768) { | |
168 av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); | |
169 ret = AVERROR_INVALIDDATA; | |
170 goto fail; | |
171 } | |
172 pkt->data[0] |= C93_HAS_PALETTE; | |
173 ret = get_buffer(pb, pkt->data + pkt->size, datasize); | |
174 if (ret < datasize) { | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
175 ret = AVERROR(EIO); |
1987 | 176 goto fail; |
177 } | |
178 pkt->size += 768; | |
179 } | |
180 pkt->stream_index = 0; | |
181 c93->next_pkt_is_audio = 1; | |
182 | |
183 /* only the first frame is guaranteed to not reference previous frames */ | |
184 if (c93->current_block == 0 && c93->current_frame == 0) { | |
5913
11bb10c37225
Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents:
5910
diff
changeset
|
185 pkt->flags |= AV_PKT_FLAG_KEY; |
1987 | 186 pkt->data[0] |= C93_FIRST_FRAME; |
187 } | |
188 return 0; | |
189 | |
190 fail: | |
191 av_free_packet(pkt); | |
192 return ret; | |
193 } | |
194 | |
195 AVInputFormat c93_demuxer = { | |
196 "c93", | |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
2771
diff
changeset
|
197 NULL_IF_CONFIG_SMALL("Interplay C93"), |
1987 | 198 sizeof(C93DemuxContext), |
2000
ce51095f383b
also remove c93_ prefix for static function in the c93 demuxer
michael
parents:
1987
diff
changeset
|
199 probe, |
ce51095f383b
also remove c93_ prefix for static function in the c93 demuxer
michael
parents:
1987
diff
changeset
|
200 read_header, |
ce51095f383b
also remove c93_ prefix for static function in the c93 demuxer
michael
parents:
1987
diff
changeset
|
201 read_packet, |
1987 | 202 }; |