Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 373 lines (341 sloc) 12.571 kB
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
1 /*
7fbde34 @aurelj replace coder/decoder file description in libavformat by muxer/demuxer
aurelj authored
2 * Smacker demuxer
406792e @DonDiego cosmetics: Remove pointless period after copyright statement non-sent…
DonDiego authored
3 * Copyright (c) 2006 Konstantin Shishkov
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
4 *
b78e719 @DonDiego Change license headers to say 'FFmpeg' instead of 'this program/this …
DonDiego authored
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
b78e719 @DonDiego Change license headers to say 'FFmpeg' instead of 'this program/this …
DonDiego authored
10 * version 2.1 of the License, or (at your option) any later version.
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
11 *
b78e719 @DonDiego Change license headers to say 'FFmpeg' instead of 'this program/this …
DonDiego authored
12 * FFmpeg is distributed in the hope that it will be useful,
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
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
b78e719 @DonDiego Change license headers to say 'FFmpeg' instead of 'this program/this …
DonDiego authored
18 * License along with FFmpeg; if not, write to the Free Software
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 * Based on http://wiki.multimedia.cx/index.php?title=Smacker
24 */
25
245976d @DonDiego Use full path for #includes from another directory.
DonDiego authored
26 #include "libavutil/bswap.h"
6a5d31a @DonDiego Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
DonDiego authored
27 #include "libavutil/intreadwrite.h"
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
28 #include "avformat.h"
c3f9ebf @elenril lavf: make av_set_pts_info private.
elenril authored
29 #include "internal.h"
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
30
31 #define SMACKER_PAL 0x01
2b71ddd Take ring frame into account when demuxing.
Kostya Shishkov authored
32 #define SMACKER_FLAG_RING_FRAME 0x01
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
33
34 enum SAudFlags {
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
35 SMK_AUD_PACKED = 0x80,
36 SMK_AUD_16BITS = 0x20,
37 SMK_AUD_STEREO = 0x10,
38 SMK_AUD_BINKAUD = 0x08,
39 SMK_AUD_USEDCT = 0x04
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
40 };
41
42 typedef struct SmackerContext {
43 /* Smacker file header */
44 uint32_t magic;
45 uint32_t width, height;
46 uint32_t frames;
47 int pts_inc;
48 uint32_t flags;
49 uint32_t audio[7];
50 uint32_t treesize;
51 uint32_t mmap_size, mclr_size, full_size, type_size;
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
52 uint8_t aflags[7];
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
53 uint32_t rates[7];
54 uint32_t pad;
55 /* frame info */
56 uint32_t *frm_size;
57 uint8_t *frm_flags;
58 /* internal variables */
59 int cur_frame;
60 int is_ver4;
61 int64_t cur_pts;
62 /* current frame for demuxing */
63 uint8_t pal[768];
64 int indexes[7];
65 int videoindex;
66 uint8_t *bufs[7];
67 int buf_sizes[7];
68 int stream_id[7];
69 int curstream;
bc5c918 @DonDiego Remove offset_t typedef and use int64_t directly instead.
DonDiego authored
70 int64_t nextpos;
386b9b5 Proper PTS generation for Smacker audio
Kostya Shishkov authored
71 int64_t aud_pts[7];
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
72 } SmackerContext;
73
74 typedef struct SmackerFrame {
75 int64_t pts;
76 int stream;
77 } SmackerFrame;
78
79 /* palette used in Smacker */
80 static const uint8_t smk_pal[64] = {
81 0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x18, 0x1C,
82 0x20, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C,
83 0x41, 0x45, 0x49, 0x4D, 0x51, 0x55, 0x59, 0x5D,
84 0x61, 0x65, 0x69, 0x6D, 0x71, 0x75, 0x79, 0x7D,
85 0x82, 0x86, 0x8A, 0x8E, 0x92, 0x96, 0x9A, 0x9E,
86 0xA2, 0xA6, 0xAA, 0xAE, 0xB2, 0xB6, 0xBA, 0xBE,
87 0xC3, 0xC7, 0xCB, 0xCF, 0xD3, 0xD7, 0xDB, 0xDF,
88 0xE3, 0xE7, 0xEB, 0xEF, 0xF3, 0xF7, 0xFB, 0xFF
89 };
90
91
92 static int smacker_probe(AVProbeData *p)
93 {
94 if(p->buf[0] == 'S' && p->buf[1] == 'M' && p->buf[2] == 'K'
95 && (p->buf[3] == '2' || p->buf[3] == '4'))
96 return AVPROBE_SCORE_MAX;
97 else
98 return 0;
99 }
100
6e9651d @elenril lavf: remove AVFormatParameters from AVFormatContext.read_header sign…
elenril authored
101 static int smacker_read_header(AVFormatContext *s)
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
102 {
471fe57 @elenril avio: rename ByteIOContext to AVIOContext.
elenril authored
103 AVIOContext *pb = s->pb;
e414143 Get rid of unnecessary pointer casts.
Nicholas Tung authored
104 SmackerContext *smk = s->priv_data;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
105 AVStream *st, *ast[7];
106 int i, ret;
107 int tbase;
108
109 /* read and check header */
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
110 smk->magic = avio_rl32(pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
111 if (smk->magic != MKTAG('S', 'M', 'K', '2') && smk->magic != MKTAG('S', 'M', 'K', '4'))
112 return -1;
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
113 smk->width = avio_rl32(pb);
114 smk->height = avio_rl32(pb);
115 smk->frames = avio_rl32(pb);
116 smk->pts_inc = (int32_t)avio_rl32(pb);
117 smk->flags = avio_rl32(pb);
2b71ddd Take ring frame into account when demuxing.
Kostya Shishkov authored
118 if(smk->flags & SMACKER_FLAG_RING_FRAME)
119 smk->frames++;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
120 for(i = 0; i < 7; i++)
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
121 smk->audio[i] = avio_rl32(pb);
122 smk->treesize = avio_rl32(pb);
a443a25 @michaelni sanity checks some might have been exploitable
michaelni authored
123
124 if(smk->treesize >= UINT_MAX/4){ // smk->treesize + 16 must not overflow (this check is probably redundant)
125 av_log(s, AV_LOG_ERROR, "treesize too large\n");
126 return -1;
127 }
128
129 //FIXME remove extradata "rebuilding"
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
130 smk->mmap_size = avio_rl32(pb);
131 smk->mclr_size = avio_rl32(pb);
132 smk->full_size = avio_rl32(pb);
133 smk->type_size = avio_rl32(pb);
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
134 for(i = 0; i < 7; i++) {
135 smk->rates[i] = avio_rl24(pb);
136 smk->aflags[i] = avio_r8(pb);
137 }
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
138 smk->pad = avio_rl32(pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
139 /* setup data */
140 if(smk->frames > 0xFFFFFF) {
141 av_log(s, AV_LOG_ERROR, "Too many frames: %i\n", smk->frames);
142 return -1;
143 }
144 smk->frm_size = av_malloc(smk->frames * 4);
145 smk->frm_flags = av_malloc(smk->frames);
146
147 smk->is_ver4 = (smk->magic != MKTAG('S', 'M', 'K', '2'));
148
149 /* read frame info */
150 for(i = 0; i < smk->frames; i++) {
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
151 smk->frm_size[i] = avio_rl32(pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
152 }
153 for(i = 0; i < smk->frames; i++) {
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
154 smk->frm_flags[i] = avio_r8(pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
155 }
156
157 /* init video codec */
3b3bbdd @elenril lavf,lavd: replace av_new_stream->avformat_new_stream part I.
elenril authored
158 st = avformat_new_stream(s, NULL);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
159 if (!st)
160 return -1;
161 smk->videoindex = st->index;
162 st->codec->width = smk->width;
163 st->codec->height = smk->height;
164 st->codec->pix_fmt = PIX_FMT_PAL8;
72415b2 Define AVMediaType enum, and use it instead of enum CodecType, which
Stefano Sabatini authored
165 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
166 st->codec->codec_id = CODEC_ID_SMACKVIDEO;
103eee5 Now MPlayer should understand Smacker audio and video codecs.
Kostya Shishkov authored
167 st->codec->codec_tag = smk->magic;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
168 /* Smacker uses 100000 as internal timebase */
169 if(smk->pts_inc < 0)
170 smk->pts_inc = -smk->pts_inc;
171 else
172 smk->pts_inc *= 100;
173 tbase = 100000;
174 av_reduce(&tbase, &smk->pts_inc, tbase, smk->pts_inc, (1UL<<31)-1);
c3f9ebf @elenril lavf: make av_set_pts_info private.
elenril authored
175 avpriv_set_pts_info(st, 33, smk->pts_inc, tbase);
2a33c67 @danielverkamp Set duration in Smacker demuxer
danielverkamp authored
176 st->duration = smk->frames;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
177 /* handle possible audio streams */
178 for(i = 0; i < 7; i++) {
179 smk->indexes[i] = -1;
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
180 if (smk->rates[i]) {
3b3bbdd @elenril lavf,lavd: replace av_new_stream->avformat_new_stream part I.
elenril authored
181 ast[i] = avformat_new_stream(s, NULL);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
182 smk->indexes[i] = ast[i]->index;
72415b2 Define AVMediaType enum, and use it instead of enum CodecType, which
Stefano Sabatini authored
183 ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
184 if (smk->aflags[i] & SMK_AUD_BINKAUD) {
895ab74 @danielverkamp Demux Bink audio in Smacker files
danielverkamp authored
185 ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_RDFT;
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
186 } else if (smk->aflags[i] & SMK_AUD_USEDCT) {
895ab74 @danielverkamp Demux Bink audio in Smacker files
danielverkamp authored
187 ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_DCT;
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
188 } else if (smk->aflags[i] & SMK_AUD_PACKED){
895ab74 @danielverkamp Demux Bink audio in Smacker files
danielverkamp authored
189 ast[i]->codec->codec_id = CODEC_ID_SMACKAUDIO;
190 ast[i]->codec->codec_tag = MKTAG('S', 'M', 'K', 'A');
191 } else {
192 ast[i]->codec->codec_id = CODEC_ID_PCM_U8;
193 }
a7984a6 @justinruggles smacker: Separate audio flags from sample rates in smacker demuxer.
justinruggles authored
194 ast[i]->codec->channels = (smk->aflags[i] & SMK_AUD_STEREO) ? 2 : 1;
195 ast[i]->codec->sample_rate = smk->rates[i];
196 ast[i]->codec->bits_per_coded_sample = (smk->aflags[i] & SMK_AUD_16BITS) ? 16 : 8;
dd1c8f3 Bump Major version, this commit is almost just renaming bits_per_samp…
Luca Abeni authored
197 if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8)
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
198 ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
c3f9ebf @elenril lavf: make av_set_pts_info private.
elenril authored
199 avpriv_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
dd1c8f3 Bump Major version, this commit is almost just renaming bits_per_samp…
Luca Abeni authored
200 * ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
201 }
202 }
203
204
205 /* load trees to extradata, they will be unpacked by decoder */
2a59abf @michaelni smackerdemux: Allocate padding for extradata
michaelni authored
206 st->codec->extradata = av_malloc(smk->treesize + 16 + FF_INPUT_BUFFER_PADDING_SIZE);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
207 st->codec->extradata_size = smk->treesize + 16;
208 if(!st->codec->extradata){
209 av_log(s, AV_LOG_ERROR, "Cannot allocate %i bytes of extradata\n", smk->treesize + 16);
210 av_free(smk->frm_size);
211 av_free(smk->frm_flags);
212 return -1;
213 }
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
214 ret = avio_read(pb, st->codec->extradata + 16, st->codec->extradata_size - 16);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
215 if(ret != st->codec->extradata_size - 16){
216 av_free(smk->frm_size);
217 av_free(smk->frm_flags);
6f3e0b2 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
Panagiotis Issaris authored
218 return AVERROR(EIO);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
219 }
8fc0162 @mansr Add av_ prefix to bswap macros
mansr authored
220 ((int32_t*)st->codec->extradata)[0] = av_le2ne32(smk->mmap_size);
221 ((int32_t*)st->codec->extradata)[1] = av_le2ne32(smk->mclr_size);
222 ((int32_t*)st->codec->extradata)[2] = av_le2ne32(smk->full_size);
223 ((int32_t*)st->codec->extradata)[3] = av_le2ne32(smk->type_size);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
224
225 smk->curstream = -1;
384c9c2 @elenril avio: add avio_tell macro as a replacement for url_ftell
elenril authored
226 smk->nextpos = avio_tell(pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
227
228 return 0;
229 }
230
231
232 static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
233 {
e414143 Get rid of unnecessary pointer casts.
Nicholas Tung authored
234 SmackerContext *smk = s->priv_data;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
235 int flags;
236 int ret;
237 int i;
238 int frame_size = 0;
239 int palchange = 0;
240
899681c @bjornax Use dynamically allocated ByteIOContext in AVFormatContext
bjornax authored
241 if (url_feof(s->pb) || smk->cur_frame >= smk->frames)
3bb96f9 @asvitkine Correctly return EOF for smacker videos
asvitkine authored
242 return AVERROR_EOF;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
243
244 /* if we demuxed all streams, pass another frame */
245 if(smk->curstream < 0) {
f59d8ff @elenril avio: avio_ prefix for url_fseek
elenril authored
246 avio_seek(s->pb, smk->nextpos, 0);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
247 frame_size = smk->frm_size[smk->cur_frame] & (~3);
248 flags = smk->frm_flags[smk->cur_frame];
249 /* handle palette change event */
250 if(flags & SMACKER_PAL){
251 int size, sz, t, off, j, pos;
252 uint8_t *pal = smk->pal;
253 uint8_t oldpal[768];
254
255 memcpy(oldpal, pal, 768);
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
256 size = avio_r8(s->pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
257 size = size * 4 - 1;
c402c1c @michaelni smackerdemuxer: check some values before instead of just after malloc()
michaelni authored
258 if(size + 1 > frame_size)
259 return AVERROR_INVALIDDATA;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
260 frame_size -= size;
261 frame_size--;
262 sz = 0;
384c9c2 @elenril avio: add avio_tell macro as a replacement for url_ftell
elenril authored
263 pos = avio_tell(s->pb) + size;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
264 while(sz < 256){
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
265 t = avio_r8(s->pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
266 if(t & 0x80){ /* skip palette entries */
267 sz += (t & 0x7F) + 1;
268 pal += ((t & 0x7F) + 1) * 3;
269 } else if(t & 0x40){ /* copy with offset */
a93b572 @rbultje smacker: error out if palette copy-with-offset overruns palette size.
rbultje authored
270 off = avio_r8(s->pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
271 j = (t & 0x3F) + 1;
a93b572 @rbultje smacker: error out if palette copy-with-offset overruns palette size.
rbultje authored
272 if (off + j > 0xff) {
273 av_log(s, AV_LOG_ERROR,
274 "Invalid palette update, offset=%d length=%d extends beyond palette size\n",
275 off, j);
276 return AVERROR_INVALIDDATA;
277 }
278 off *= 3;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
279 while(j-- && sz < 256) {
280 *pal++ = oldpal[off + 0];
281 *pal++ = oldpal[off + 1];
282 *pal++ = oldpal[off + 2];
283 sz++;
284 off += 3;
285 }
286 } else { /* new entries */
287 *pal++ = smk_pal[t];
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
288 *pal++ = smk_pal[avio_r8(s->pb) & 0x3F];
289 *pal++ = smk_pal[avio_r8(s->pb) & 0x3F];
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
290 sz++;
291 }
292 }
f59d8ff @elenril avio: avio_ prefix for url_fseek
elenril authored
293 avio_seek(s->pb, pos, 0);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
294 palchange |= 1;
295 }
296 flags >>= 1;
297 smk->curstream = -1;
298 /* if audio chunks are present, put them to stack and retrieve later */
299 for(i = 0; i < 7; i++) {
300 if(flags & 1) {
c402c1c @michaelni smackerdemuxer: check some values before instead of just after malloc()
michaelni authored
301 unsigned int size;
47a8589 smacker demuxer: handle possible av_realloc() failure.
Kostya Shishkov authored
302 uint8_t *tmpbuf;
303
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
304 size = avio_rl32(s->pb) - 4;
c402c1c @michaelni smackerdemuxer: check some values before instead of just after malloc()
michaelni authored
305 if(size + 4L > frame_size)
306 return AVERROR_INVALIDDATA;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
307 frame_size -= size;
308 frame_size -= 4;
309 smk->curstream++;
47a8589 smacker demuxer: handle possible av_realloc() failure.
Kostya Shishkov authored
310 tmpbuf = av_realloc(smk->bufs[smk->curstream], size);
311 if (!tmpbuf)
d0121e8 Fixed segfault on corrupted smacker streams in the demuxer.
Laurent Aimar authored
312 return AVERROR(ENOMEM);
47a8589 smacker demuxer: handle possible av_realloc() failure.
Kostya Shishkov authored
313 smk->bufs[smk->curstream] = tmpbuf;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
314 smk->buf_sizes[smk->curstream] = size;
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
315 ret = avio_read(s->pb, smk->bufs[smk->curstream], size);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
316 if(ret != size)
6f3e0b2 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
Panagiotis Issaris authored
317 return AVERROR(EIO);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
318 smk->stream_id[smk->curstream] = smk->indexes[i];
319 }
320 flags >>= 1;
321 }
d0121e8 Fixed segfault on corrupted smacker streams in the demuxer.
Laurent Aimar authored
322 if (frame_size < 0)
323 return AVERROR_INVALIDDATA;
324 if (av_new_packet(pkt, frame_size + 769))
769e10f Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
Panagiotis Issaris authored
325 return AVERROR(ENOMEM);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
326 if(smk->frm_size[smk->cur_frame] & 1)
327 palchange |= 2;
328 pkt->data[0] = palchange;
329 memcpy(pkt->data + 1, smk->pal, 768);
e63a362 @elenril avio: avio_ prefixes for get_* functions
elenril authored
330 ret = avio_read(s->pb, pkt->data + 769, frame_size);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
331 if(ret != frame_size)
6f3e0b2 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
Panagiotis Issaris authored
332 return AVERROR(EIO);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
333 pkt->stream_index = smk->videoindex;
334 pkt->size = ret + 769;
335 smk->cur_frame++;
384c9c2 @elenril avio: add avio_tell macro as a replacement for url_ftell
elenril authored
336 smk->nextpos = avio_tell(s->pb);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
337 } else {
338 if (av_new_packet(pkt, smk->buf_sizes[smk->curstream]))
769e10f Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
Panagiotis Issaris authored
339 return AVERROR(ENOMEM);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
340 memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]);
341 pkt->size = smk->buf_sizes[smk->curstream];
342 pkt->stream_index = smk->stream_id[smk->curstream];
386b9b5 Proper PTS generation for Smacker audio
Kostya Shishkov authored
343 pkt->pts = smk->aud_pts[smk->curstream];
fead30d @axic rename BE/LE_8/16/32 to AV_RL/B_8/16/32
axic authored
344 smk->aud_pts[smk->curstream] += AV_RL32(pkt->data);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
345 smk->curstream--;
346 }
347
348 return 0;
349 }
350
351 static int smacker_read_close(AVFormatContext *s)
352 {
e414143 Get rid of unnecessary pointer casts.
Nicholas Tung authored
353 SmackerContext *smk = s->priv_data;
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
354 int i;
355
356 for(i = 0; i < 7; i++)
e31a744 @ubitux Remove a few if (p) av_free(p) forms
ubitux authored
357 av_free(smk->bufs[i]);
358 av_free(smk->frm_size);
359 av_free(smk->frm_flags);
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
360
361 return 0;
362 }
363
66355be @Flameeyes Prefix all _demuxer, _muxer, _protocol from libavformat and libavdevice.
Flameeyes authored
364 AVInputFormat ff_smacker_demuxer = {
dfc2c4d @elenril lavf: use designated initialisers for all (de)muxers.
elenril authored
365 .name = "smk",
366 .long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
367 .priv_data_size = sizeof(SmackerContext),
368 .read_probe = smacker_probe,
369 .read_header = smacker_read_header,
370 .read_packet = smacker_read_packet,
371 .read_close = smacker_read_close,
348efc1 Smacker demuxer and decoder.
Kostya Shishkov authored
372 };
Something went wrong with that request. Please try again.