Mercurial > libavformat.hg
comparison smacker.c @ 2771:d52c718e83f9 libavformat
Use dynamically allocated ByteIOContext in AVFormatContext
patch by: Bj«Órn Axelsson, bjorn d axelsson a intinor d se
thread: [PATCH] Remove static ByteIOContexts, 06 nov 2007
author | andoma |
---|---|
date | Wed, 21 Nov 2007 07:41:00 +0000 |
parents | 2ca025105808 |
children | 6f61c3b36632 |
comparison
equal
deleted
inserted
replaced
2770:a7e42cf4b364 | 2771:d52c718e83f9 |
---|---|
96 return 0; | 96 return 0; |
97 } | 97 } |
98 | 98 |
99 static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) | 99 static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) |
100 { | 100 { |
101 ByteIOContext *pb = &s->pb; | 101 ByteIOContext *pb = s->pb; |
102 SmackerContext *smk = s->priv_data; | 102 SmackerContext *smk = s->priv_data; |
103 AVStream *st, *ast[7]; | 103 AVStream *st, *ast[7]; |
104 int i, ret; | 104 int i, ret; |
105 int tbase; | 105 int tbase; |
106 | 106 |
224 int i; | 224 int i; |
225 int frame_size = 0; | 225 int frame_size = 0; |
226 int palchange = 0; | 226 int palchange = 0; |
227 int pos; | 227 int pos; |
228 | 228 |
229 if (url_feof(&s->pb) || smk->cur_frame >= smk->frames) | 229 if (url_feof(s->pb) || smk->cur_frame >= smk->frames) |
230 return AVERROR(EIO); | 230 return AVERROR(EIO); |
231 | 231 |
232 /* if we demuxed all streams, pass another frame */ | 232 /* if we demuxed all streams, pass another frame */ |
233 if(smk->curstream < 0) { | 233 if(smk->curstream < 0) { |
234 url_fseek(&s->pb, smk->nextpos, 0); | 234 url_fseek(s->pb, smk->nextpos, 0); |
235 frame_size = smk->frm_size[smk->cur_frame] & (~3); | 235 frame_size = smk->frm_size[smk->cur_frame] & (~3); |
236 flags = smk->frm_flags[smk->cur_frame]; | 236 flags = smk->frm_flags[smk->cur_frame]; |
237 /* handle palette change event */ | 237 /* handle palette change event */ |
238 pos = url_ftell(&s->pb); | 238 pos = url_ftell(s->pb); |
239 if(flags & SMACKER_PAL){ | 239 if(flags & SMACKER_PAL){ |
240 int size, sz, t, off, j, pos; | 240 int size, sz, t, off, j, pos; |
241 uint8_t *pal = smk->pal; | 241 uint8_t *pal = smk->pal; |
242 uint8_t oldpal[768]; | 242 uint8_t oldpal[768]; |
243 | 243 |
244 memcpy(oldpal, pal, 768); | 244 memcpy(oldpal, pal, 768); |
245 size = get_byte(&s->pb); | 245 size = get_byte(s->pb); |
246 size = size * 4 - 1; | 246 size = size * 4 - 1; |
247 frame_size -= size; | 247 frame_size -= size; |
248 frame_size--; | 248 frame_size--; |
249 sz = 0; | 249 sz = 0; |
250 pos = url_ftell(&s->pb) + size; | 250 pos = url_ftell(s->pb) + size; |
251 while(sz < 256){ | 251 while(sz < 256){ |
252 t = get_byte(&s->pb); | 252 t = get_byte(s->pb); |
253 if(t & 0x80){ /* skip palette entries */ | 253 if(t & 0x80){ /* skip palette entries */ |
254 sz += (t & 0x7F) + 1; | 254 sz += (t & 0x7F) + 1; |
255 pal += ((t & 0x7F) + 1) * 3; | 255 pal += ((t & 0x7F) + 1) * 3; |
256 } else if(t & 0x40){ /* copy with offset */ | 256 } else if(t & 0x40){ /* copy with offset */ |
257 off = get_byte(&s->pb) * 3; | 257 off = get_byte(s->pb) * 3; |
258 j = (t & 0x3F) + 1; | 258 j = (t & 0x3F) + 1; |
259 while(j-- && sz < 256) { | 259 while(j-- && sz < 256) { |
260 *pal++ = oldpal[off + 0]; | 260 *pal++ = oldpal[off + 0]; |
261 *pal++ = oldpal[off + 1]; | 261 *pal++ = oldpal[off + 1]; |
262 *pal++ = oldpal[off + 2]; | 262 *pal++ = oldpal[off + 2]; |
263 sz++; | 263 sz++; |
264 off += 3; | 264 off += 3; |
265 } | 265 } |
266 } else { /* new entries */ | 266 } else { /* new entries */ |
267 *pal++ = smk_pal[t]; | 267 *pal++ = smk_pal[t]; |
268 *pal++ = smk_pal[get_byte(&s->pb) & 0x3F]; | 268 *pal++ = smk_pal[get_byte(s->pb) & 0x3F]; |
269 *pal++ = smk_pal[get_byte(&s->pb) & 0x3F]; | 269 *pal++ = smk_pal[get_byte(s->pb) & 0x3F]; |
270 sz++; | 270 sz++; |
271 } | 271 } |
272 } | 272 } |
273 url_fseek(&s->pb, pos, 0); | 273 url_fseek(s->pb, pos, 0); |
274 palchange |= 1; | 274 palchange |= 1; |
275 } | 275 } |
276 flags >>= 1; | 276 flags >>= 1; |
277 smk->curstream = -1; | 277 smk->curstream = -1; |
278 /* if audio chunks are present, put them to stack and retrieve later */ | 278 /* if audio chunks are present, put them to stack and retrieve later */ |
279 for(i = 0; i < 7; i++) { | 279 for(i = 0; i < 7; i++) { |
280 if(flags & 1) { | 280 if(flags & 1) { |
281 int size; | 281 int size; |
282 size = get_le32(&s->pb) - 4; | 282 size = get_le32(s->pb) - 4; |
283 frame_size -= size; | 283 frame_size -= size; |
284 frame_size -= 4; | 284 frame_size -= 4; |
285 smk->curstream++; | 285 smk->curstream++; |
286 smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size); | 286 smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size); |
287 smk->buf_sizes[smk->curstream] = size; | 287 smk->buf_sizes[smk->curstream] = size; |
288 ret = get_buffer(&s->pb, smk->bufs[smk->curstream], size); | 288 ret = get_buffer(s->pb, smk->bufs[smk->curstream], size); |
289 if(ret != size) | 289 if(ret != size) |
290 return AVERROR(EIO); | 290 return AVERROR(EIO); |
291 smk->stream_id[smk->curstream] = smk->indexes[i]; | 291 smk->stream_id[smk->curstream] = smk->indexes[i]; |
292 } | 292 } |
293 flags >>= 1; | 293 flags >>= 1; |
296 return AVERROR(ENOMEM); | 296 return AVERROR(ENOMEM); |
297 if(smk->frm_size[smk->cur_frame] & 1) | 297 if(smk->frm_size[smk->cur_frame] & 1) |
298 palchange |= 2; | 298 palchange |= 2; |
299 pkt->data[0] = palchange; | 299 pkt->data[0] = palchange; |
300 memcpy(pkt->data + 1, smk->pal, 768); | 300 memcpy(pkt->data + 1, smk->pal, 768); |
301 ret = get_buffer(&s->pb, pkt->data + 769, frame_size); | 301 ret = get_buffer(s->pb, pkt->data + 769, frame_size); |
302 if(ret != frame_size) | 302 if(ret != frame_size) |
303 return AVERROR(EIO); | 303 return AVERROR(EIO); |
304 pkt->stream_index = smk->videoindex; | 304 pkt->stream_index = smk->videoindex; |
305 pkt->size = ret + 769; | 305 pkt->size = ret + 769; |
306 smk->cur_frame++; | 306 smk->cur_frame++; |
307 smk->nextpos = url_ftell(&s->pb); | 307 smk->nextpos = url_ftell(s->pb); |
308 } else { | 308 } else { |
309 if (av_new_packet(pkt, smk->buf_sizes[smk->curstream])) | 309 if (av_new_packet(pkt, smk->buf_sizes[smk->curstream])) |
310 return AVERROR(ENOMEM); | 310 return AVERROR(ENOMEM); |
311 memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]); | 311 memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]); |
312 pkt->size = smk->buf_sizes[smk->curstream]; | 312 pkt->size = smk->buf_sizes[smk->curstream]; |