* AVI demuxer
* Copyright (c) 2001 Fabrice Bellard
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef DEBUG_SEEK
av_log(s, AV_LOG_ERROR, "pos:%"PRId64", len:%X\n", pos, len);
#endif
- if(url_feof(pb))
+ if(pb->eof_reached)
return -1;
if(last_pos == pos || pos == base - 8)
avio_rl32(pb); /* size */
duration = avio_rl32(pb);
- if(url_feof(pb))
+ if(pb->eof_reached)
return -1;
pos = avio_tell(pb);
}
if (name)
av_metadata_set2(&s->metadata, name, buffer, 0);
- avio_seek(s->pb, size, SEEK_CUR);
+ avio_skip(s->pb, size);
}
break;
}
default:
- avio_seek(s->pb, size, SEEK_CUR);
+ avio_skip(s->pb, size);
break;
}
}
int avih_width=0, avih_height=0;
int amv_file_format=0;
uint64_t list_end = 0;
+ int ret;
avi->stream_index= -1;
codec_type = -1;
frame_period = 0;
for(;;) {
- if (url_feof(pb))
+ if (pb->eof_reached)
goto fail;
tag = avio_rl32(pb);
size = avio_rl32(pb);
unsigned char date[64] = {0};
size += (size & 1);
size -= avio_read(pb, date, FFMIN(size, sizeof(date)-1));
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
avi_metadata_creation_time(&s->metadata, date);
break;
}
case MKTAG('d', 'm', 'l', 'h'):
avi->is_odml = 1;
- avio_seek(pb, size + (size & 1), SEEK_CUR);
+ avio_skip(pb, size + (size & 1));
break;
case MKTAG('a', 'm', 'v', 'h'):
amv_file_format=1;
avio_rl32(pb);
avi->non_interleaved |= avio_rl32(pb) & AVIF_MUSTUSEINDEX;
- avio_seek(pb, 2 * 4, SEEK_CUR);
+ avio_skip(pb, 2 * 4);
avio_rl32(pb);
avio_rl32(pb);
avih_width=avio_rl32(pb);
avih_height=avio_rl32(pb);
- avio_seek(pb, size - 10 * 4, SEEK_CUR);
+ avio_skip(pb, size - 10 * 4);
break;
case MKTAG('s', 't', 'r', 'h'):
/* stream header */
handler = avio_rl32(pb); /* codec tag */
if(tag1 == MKTAG('p', 'a', 'd', 's')){
- avio_seek(pb, size - 8, SEEK_CUR);
+ avio_skip(pb, size - 8);
break;
}else{
stream_index++;
goto fail;
}
s->streams[0]->priv_data = ast;
- avio_seek(pb, 3 * 4, SEEK_CUR);
+ avio_skip(pb, 3 * 4);
ast->scale = avio_rl32(pb);
ast->rate = avio_rl32(pb);
- avio_seek(pb, 4, SEEK_CUR); /* start time */
+ avio_skip(pb, 4); /* start time */
dv_dur = avio_rl32(pb);
if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {
*/
stream_index = s->nb_streams - 1;
- avio_seek(pb, size - 9*4, SEEK_CUR);
+ avio_skip(pb, size - 9*4);
break;
}
if(ast->sample_size == 0)
st->duration = st->nb_frames;
ast->frame_offset= ast->cum_len;
- avio_seek(pb, size - 12 * 4, SEEK_CUR);
+ avio_skip(pb, size - 12 * 4);
break;
case MKTAG('s', 't', 'r', 'f'):
/* stream header */
if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
} else {
uint64_t cur_pos = avio_tell(pb);
if (cur_pos < list_end)
st->codec->height=avih_height;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_AMV;
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
break;
}
tag1 = ff_get_bmp_header(pb, st);
/* Extract palette from extradata if bpp <= 8. */
/* This code assumes that extradata contains only palette. */
- /* This is true for all paletted codecs implemented in FFmpeg. */
+ /* This is true for all paletted codecs implemented in Libav. */
if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
- st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
+ int pal_size = (1 << st->codec->bits_per_coded_sample) << 2;
+ const uint8_t *pal_src;
+
+ pal_size = FFMIN(pal_size, st->codec->extradata_size);
+ pal_src = st->codec->extradata + st->codec->extradata_size - pal_size;
#if HAVE_BIGENDIAN
- for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
- st->codec->palctrl->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]);
+ for (i = 0; i < pal_size/4; i++)
+ ast->pal[i] = av_bswap32(((uint32_t*)pal_src)[i]);
#else
- memcpy(st->codec->palctrl->palette, st->codec->extradata,
- FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
+ memcpy(ast->pal, pal_src, pal_size);
#endif
- st->codec->palctrl->palette_changed = 1;
+ ast->has_pal = 1;
}
print_tag("video", tag1, 0);
}
st->codec->height= FFABS(st->codec->height);
-// avio_seek(pb, size - 5 * 4, SEEK_CUR);
+// avio_skip(pb, size - 5 * 4);
break;
case AVMEDIA_TYPE_AUDIO:
- ff_get_wav_header(pb, st->codec, size);
+ ret = ff_get_wav_header(pb, st->codec, size);
+ if (ret < 0)
+ return ret;
ast->dshow_block_align= st->codec->block_align;
if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){
av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align);
ast->sample_size= st->codec->block_align;
}
if (size&1) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
- avio_seek(pb, 1, SEEK_CUR);
+ avio_skip(pb, 1);
/* Force parsing as several audio frames can be in
* one packet and timestamps refer to packet start. */
st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;
st->codec->codec_type = AVMEDIA_TYPE_DATA;
st->codec->codec_id= CODEC_ID_NONE;
st->codec->codec_tag= 0;
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
break;
}
}
break;
case MKTAG('i', 'n', 'd', 'x'):
i= avio_tell(pb);
- if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){
+ if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX)){
read_braindead_odml_indx(s, 0);
}
avio_seek(pb, i+size, SEEK_SET);
}
size -= 9*4;
}
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
break;
case MKTAG('s', 't', 'r', 'n'):
if(s->nb_streams){
}
/* skip tag */
size += (size & 1);
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
break;
}
}
return -1;
}
- if(!avi->index_loaded && !url_is_streamed(pb))
+ if(!avi->index_loaded && pb->seekable)
avi_load_index(s);
avi->index_loaded = 1;
avi->non_interleaved |= guess_ni_flag(s);
goto error;
ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc));
- avio_seek(pb, desc_len - ret, SEEK_CUR);
+ avio_skip(pb, desc_len - ret);
if (*desc)
av_metadata_set2(&st->metadata, "title", desc, 0);
return err;
if(ast->has_pal && pkt->data && pkt->size<(unsigned)INT_MAX/2){
- void *ptr= av_realloc(pkt->data, pkt->size + 4*256 + FF_INPUT_BUFFER_PADDING_SIZE);
- if(ptr){
- ast->has_pal=0;
- pkt->size += 4*256;
- pkt->data= ptr;
- memcpy(pkt->data + pkt->size - 4*256, ast->pal, 4*256);
- }else
- av_log(s, AV_LOG_ERROR, "Failed to append palette\n");
+ uint8_t *pal;
+ pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
+ if(!pal){
+ av_log(s, AV_LOG_ERROR, "Failed to allocate data for palette\n");
+ }else{
+ memcpy(pal, ast->pal, AVPALETTE_SIZE);
+ ast->has_pal = 0;
+ }
}
if (CONFIG_DV_DEMUXER && avi->dv_demux) {
}
memset(d, -1, sizeof(int)*8);
- for(i=sync=avio_tell(pb); !url_feof(pb); i++) {
+ for(i=sync=avio_tell(pb); !pb->eof_reached; i++) {
int j;
for(j=0; j<7; j++)
//parse JUNK
||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')
||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
//av_log(s, AV_LOG_DEBUG, "SKIP\n");
goto resync;
}
//parse stray LIST
if(d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T'){
- avio_seek(pb, 4, SEEK_CUR);
+ avio_skip(pb, 4);
goto resync;
}
//detect ##ix chunk and skip
if(d[2] == 'i' && d[3] == 'x' && n < s->nb_streams){
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
goto resync;
}
/*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering
|| st->discard >= AVDISCARD_ALL){
ast->frame_offset += get_duration(ast, size);
- avio_seek(pb, size, SEEK_CUR);
+ avio_skip(pb, size);
goto resync;
}
#if defined(DEBUG_SEEK)
av_log(s, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
#endif
- if(url_feof(pb))
+ if(pb->eof_reached)
return -1;
if(last_pos == pos)
printf("movi_end=0x%"PRIx64"\n", avi->movi_end);
#endif
for(;;) {
- if (url_feof(pb))
+ if (pb->eof_reached)
break;
tag = avio_rl32(pb);
size = avio_rl32(pb);
default:
skip:
size += (size & 1);
- if (avio_seek(pb, size, SEEK_CUR) < 0)
+ if (avio_skip(pb, size) < 0)
goto the_end; // something is wrong here
break;
}
for(i=0;i<s->nb_streams;i++) {
AVStream *st = s->streams[i];
AVIStream *ast = st->priv_data;
- av_free(st->codec->palctrl);
if (ast) {
if (ast->sub_ctx) {
av_freep(&ast->sub_ctx->pb);