diff options
Diffstat (limited to 'libavformat')
71 files changed, 175 insertions, 142 deletions
diff --git a/libavformat/4xm.c b/libavformat/4xm.c index ee4f54244e..699277248d 100644 --- a/libavformat/4xm.c +++ b/libavformat/4xm.c @@ -259,7 +259,7 @@ static int fourxm_read_packet(AVFormatContext *s, return ret; fourcc_tag = AV_RL32(&header[0]); size = AV_RL32(&header[4]); - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); switch (fourcc_tag) { diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 2cec376e14..c43ee32adc 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -51,7 +51,7 @@ static int get_tag(AVIOContext *pb, uint32_t * tag) { int size; - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); *tag = avio_rl32(pb); diff --git a/libavformat/amr.c b/libavformat/amr.c index e7a6758986..0459632b10 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -122,7 +122,7 @@ static int amr_read_packet(AVFormatContext *s, AVCodecContext *enc = s->streams[0]->codec; int read, size = 0, toc, mode; - if (s->pb->eof_reached) + if (url_feof(s->pb)) { return AVERROR(EIO); } diff --git a/libavformat/anm.c b/libavformat/anm.c index 1f19b50d08..269e325e42 100644 --- a/libavformat/anm.c +++ b/libavformat/anm.c @@ -181,7 +181,7 @@ static int read_packet(AVFormatContext *s, Page *p; int tmp, record_size; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); if (anm->page < 0) diff --git a/libavformat/ape.c b/libavformat/ape.c index d9c988753b..456407cb46 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -341,7 +341,7 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) APEContext *ape = s->priv_data; uint32_t extra_size = 8; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); if (ape->currentframe > ape->totalframes) return AVERROR(EIO); diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c index d6f7db36e1..324494ad74 100644 --- a/libavformat/applehttp.c +++ b/libavformat/applehttp.c @@ -173,7 +173,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url, if (var) free_segment_list(var); c->finished = 0; - while (!in->eof_reached) { + while (!url_feof(in)) { read_chomp_line(in, line, sizeof(line)); if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) { struct variant_info info = {{0}}; @@ -406,7 +406,7 @@ start: if (var->pb && !var->pkt.data) { ret = av_read_frame(var->ctx, &var->pkt); if (ret < 0) { - if (!var->pb->eof_reached) + if (!url_feof(var->pb)) return ret; reset_packet(&var->pkt); } diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c index c287c6c614..630d02d3d6 100644 --- a/libavformat/applehttpproto.c +++ b/libavformat/applehttpproto.c @@ -123,7 +123,7 @@ static int parse_playlist(URLContext *h, const char *url) free_segment_list(s); s->finished = 0; - while (!in->eof_reached) { + while (!url_feof(in)) { read_chomp_line(in, line, sizeof(line)); if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) { struct variant_info info = {{0}}; diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index e27c29b193..7d08e6ebcf 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -178,8 +178,7 @@ static void get_tag(AVFormatContext *s, const char *key, int type, int len) av_log(s, AV_LOG_DEBUG, "Unsupported value type %d in tag %s.\n", type, key); goto finish; } - if (*value) - av_metadata_set2(&s->metadata, key, value, 0); + av_metadata_set2(&s->metadata, key, value, 0); finish: av_freep(&value); avio_seek(s->pb, off + len, SEEK_SET); @@ -639,7 +638,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) continue; } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) { asf_read_marker(s, gsize); - } else if (pb->eof_reached) { + } else if (url_feof(pb)) { return -1; } else { if (!s->keylen) { @@ -660,7 +659,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) avio_rl64(pb); avio_r8(pb); avio_r8(pb); - if (pb->eof_reached) + if (url_feof(pb)) return -1; asf->data_offset = avio_tell(pb); asf->packet_size_left = 0; @@ -745,12 +744,12 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb) */ if (pb->error == AVERROR(EAGAIN)) return AVERROR(EAGAIN); - if (!pb->eof_reached) + if (!url_feof(pb)) av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb)); } if ((c & 0x8f) == 0x82) { if (d || e) { - if (!pb->eof_reached) + if (!url_feof(pb)) av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n"); return -1; } @@ -886,7 +885,7 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk ASFStream *asf_st = 0; for (;;) { int ret; - if(pb->eof_reached) + if(url_feof(pb)) return AVERROR_EOF; if (asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1) { @@ -1195,7 +1194,7 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) skip them until the simple index object is reached */ while (ff_guidcmp(&g, &index_guid)) { int64_t gsize= avio_rl64(s->pb); - if (gsize < 24 || s->pb->eof_reached) { + if (gsize < 24 || url_feof(s->pb)) { avio_seek(s->pb, current_pos, SEEK_SET); return; } diff --git a/libavformat/assdec.c b/libavformat/assdec.c index abaf942f45..e04d92ae65 100644 --- a/libavformat/assdec.c +++ b/libavformat/assdec.c @@ -92,7 +92,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap) header_remaining= INT_MAX; dst[0] = &st->codec->extradata; dst[1] = &ass->event_buffer; - while(!pb->eof_reached){ + while(!url_feof(pb)){ uint8_t line[MAX_LINESIZE]; len = ff_get_line(pb, line, sizeof(line)); diff --git a/libavformat/avformat.h b/libavformat/avformat.h index ce50053f49..7990ce7bbe 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -118,7 +118,7 @@ typedef struct { }AVMetadataTag; typedef struct AVMetadata AVMetadata; -#if FF_API_OLD_METADATA +#if FF_API_OLD_METADATA2 typedef struct AVMetadataConv AVMetadataConv; #endif @@ -159,7 +159,7 @@ attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const */ int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags); -#if FF_API_OLD_METADATA +#if FF_API_OLD_METADATA2 /** * This function is provided for compatibility reason and currently does nothing. */ diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 83b476144e..9ba1f5725e 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -178,7 +178,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ #ifdef DEBUG_SEEK av_log(s, AV_LOG_ERROR, "pos:%"PRId64", len:%X\n", pos, len); #endif - if(pb->eof_reached) + if(url_feof(pb)) return -1; if(last_pos == pos || pos == base - 8) @@ -195,7 +195,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ avio_rl32(pb); /* size */ duration = avio_rl32(pb); - if(pb->eof_reached) + if(url_feof(pb)) return -1; pos = avio_tell(pb); @@ -360,7 +360,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) codec_type = -1; frame_period = 0; for(;;) { - if (pb->eof_reached) + if (url_feof(pb)) goto fail; tag = avio_rl32(pb); size = avio_rl32(pb); @@ -989,7 +989,7 @@ resync: } memset(d, -1, sizeof(int)*8); - for(i=sync=avio_tell(pb); !pb->eof_reached; i++) { + for(i=sync=avio_tell(pb); !url_feof(pb); i++) { int j; for(j=0; j<7; j++) @@ -1145,7 +1145,7 @@ static int avi_read_idx1(AVFormatContext *s, int size) #if defined(DEBUG_SEEK) av_log(s, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\n", len, ast->cum_len); #endif - if(pb->eof_reached) + if(url_feof(pb)) return -1; if(last_pos == pos) @@ -1203,7 +1203,7 @@ static int avi_load_index(AVFormatContext *s) printf("movi_end=0x%"PRIx64"\n", avi->movi_end); #endif for(;;) { - if (pb->eof_reached) + if (url_feof(pb)) break; tag = avio_rl32(pb); size = avio_rl32(pb); diff --git a/libavformat/avio.h b/libavformat/avio.h index a8e98cb529..2d2afc7112 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -440,10 +440,6 @@ attribute_deprecated void put_flush_packet(AVIOContext *s); * @} */ -/** - * @deprecated use AVIOContext.eof_reached - */ -attribute_deprecated int url_feof(AVIOContext *s); attribute_deprecated int url_ferror(AVIOContext *s); #endif @@ -493,10 +489,7 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence); * Skip given number of bytes forward * @return new position or AVERROR. */ -static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset) -{ - return avio_seek(s, offset, SEEK_CUR); -} +int64_t avio_skip(AVIOContext *s, int64_t offset); /** * ftell() equivalent for AVIOContext. @@ -513,6 +506,12 @@ static av_always_inline int64_t avio_tell(AVIOContext *s) */ int64_t avio_size(AVIOContext *s); +/** + * feof() equivalent for AVIOContext. + * @return non zero if and only if end of file + */ +int url_feof(AVIOContext *s); + int av_url_read_fpause(AVIOContext *h, int pause); int64_t av_url_read_fseek(AVIOContext *h, int stream_index, int64_t timestamp, int flags); diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index a0cb9a8921..b8cfb9286a 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -233,6 +233,11 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence) return offset; } +int64_t avio_skip(AVIOContext *s, int64_t offset) +{ + return avio_seek(s, offset, SEEK_CUR); +} + #if FF_API_OLD_AVIO int url_fskip(AVIOContext *s, int64_t offset) { @@ -265,14 +270,18 @@ int64_t avio_size(AVIOContext *s) return size; } -#if FF_API_OLD_AVIO int url_feof(AVIOContext *s) { if(!s) return 0; + if(s->eof_reached){ + s->eof_reached=0; + fill_buffer(s); + } return s->eof_reached; } +#if FF_API_OLD_AVIO int url_ferror(AVIOContext *s) { if(!s) @@ -619,8 +628,8 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) } } if (size1 == size) { - if (s->error) return s->error; - if (s->eof_reached) return AVERROR_EOF; + if (s->error) return s->error; + if (url_feof(s)) return AVERROR_EOF; } return size1 - size; } @@ -642,8 +651,8 @@ int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size) memcpy(buf, s->buf_ptr, len); s->buf_ptr += len; if (!len) { - if (s->error) return s->error; - if (s->eof_reached) return AVERROR_EOF; + if (s->error) return s->error; + if (url_feof(s)) return AVERROR_EOF; } return len; } @@ -948,11 +957,11 @@ char *url_fgets(AVIOContext *s, char *buf, int buf_size) char *q; c = avio_r8(s); - if (s->eof_reached) + if (url_feof(s)) return NULL; q = buf; for(;;) { - if (s->eof_reached || c == '\n') + if (url_feof(s) || c == '\n') break; if ((q - buf) < buf_size - 1) *q++ = c; diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c index e371a2a80c..399d627121 100644 --- a/libavformat/bethsoftvid.c +++ b/libavformat/bethsoftvid.c @@ -179,7 +179,7 @@ static int vid_read_packet(AVFormatContext *s, int audio_length; int ret_value; - if(vid->is_finished || pb->eof_reached) + if(vid->is_finished || url_feof(pb)) return AVERROR(EIO); block_type = avio_r8(pb); diff --git a/libavformat/bfi.c b/libavformat/bfi.c index 5b72322320..843ba9972e 100644 --- a/libavformat/bfi.c +++ b/libavformat/bfi.c @@ -109,7 +109,7 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt) BFIContext *bfi = s->priv_data; AVIOContext *pb = s->pb; int ret, audio_offset, video_offset, chunk_size, audio_size = 0; - if (bfi->nframes == 0 || pb->eof_reached) { + if (bfi->nframes == 0 || url_feof(pb)) { return AVERROR(EIO); } @@ -117,7 +117,7 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt) if (!bfi->avflag) { uint32_t state = 0; while(state != MKTAG('S','A','V','I')){ - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); state = 256*state + avio_r8(pb); } diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 82db4efef4..217f4db633 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -185,8 +185,8 @@ static void read_info_chunk(AVFormatContext *s, int64_t size) for (i = 0; i < nb_entries; i++) { char key[32]; char value[1024]; - avio_get_str(pb, INT_MAX, key, sizeof(key)); - avio_get_str(pb, INT_MAX, value, sizeof(value)); + get_strz(pb, key, sizeof(key)); + get_strz(pb, value, sizeof(value)); av_metadata_set2(&s->metadata, key, value, 0); } } @@ -219,7 +219,7 @@ static int read_header(AVFormatContext *s, /* parse each chunk */ found_data = 0; - while (!pb->eof_reached) { + while (!url_feof(pb)) { /* stop at data chunk if seeking is not supported or data chunk size is unknown */ @@ -228,7 +228,7 @@ static int read_header(AVFormatContext *s, tag = avio_rb32(pb); size = avio_rb64(pb); - if (pb->eof_reached) + if (url_feof(pb)) break; switch (tag) { @@ -307,7 +307,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) int res, pkt_size = 0, pkt_frames = 0; int64_t left = CAF_MAX_PKT_SIZE; - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); /* don't read past end of data chunk */ diff --git a/libavformat/daud.c b/libavformat/daud.c index 77cae8a855..7aa1b6dad2 100644 --- a/libavformat/daud.c +++ b/libavformat/daud.c @@ -38,7 +38,7 @@ static int daud_header(AVFormatContext *s, AVFormatParameters *ap) { static int daud_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; int ret, size; - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); size = avio_rb16(pb); avio_rb16(pb); // unknown diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c index 023441be73..22233731c5 100644 --- a/libavformat/dsicin.c +++ b/libavformat/dsicin.c @@ -147,7 +147,7 @@ static int cin_read_frame_header(CinDemuxContext *cin, AVIOContext *pb) { hdr->video_frame_size = avio_rl32(pb); hdr->audio_frame_size = avio_rl32(pb); - if (pb->eof_reached || pb->error) + if (url_feof(pb) || pb->error) return AVERROR(EIO); if (avio_rl32(pb) != 0xAA55AA55) diff --git a/libavformat/dv.c b/libavformat/dv.c index 9e67e710b5..1e32125c23 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -412,7 +412,7 @@ static int dv_read_header(AVFormatContext *s, state = avio_rb32(s->pb); while ((state & 0xffffff7f) != 0x1f07003f) { - if (s->pb->eof_reached) { + if (url_feof(s->pb)) { av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n"); return -1; } diff --git a/libavformat/dxa.c b/libavformat/dxa.c index 6b9a55221a..cf93df70d4 100644 --- a/libavformat/dxa.c +++ b/libavformat/dxa.c @@ -104,7 +104,7 @@ static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap) return -1; ff_get_wav_header(pb, ast->codec, fsize); // find 'data' chunk - while(avio_tell(pb) < c->vidpos && !pb->eof_reached){ + while(avio_tell(pb) < c->vidpos && !url_feof(pb)){ tag = avio_rl32(pb); fsize = avio_rl32(pb); if(tag == MKTAG('d', 'a', 't', 'a')) break; @@ -162,7 +162,7 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt) return 0; } avio_seek(s->pb, c->vidpos, SEEK_SET); - while(!s->pb->eof_reached && c->frames){ + while(!url_feof(s->pb) && c->frames){ avio_read(s->pb, buf, 4); switch(AV_RL32(buf)){ case MKTAG('N', 'U', 'L', 'L'): diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index d4d0d553ba..6585bbea2d 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -109,7 +109,7 @@ static int process_audio_header_elements(AVFormatContext *s) ea->sample_rate = -1; ea->num_channels = 1; - while (!pb->eof_reached && inHeader) { + while (!url_feof(pb) && inHeader) { int inSubheader; uint8_t byte; byte = avio_r8(pb); @@ -118,7 +118,7 @@ static int process_audio_header_elements(AVFormatContext *s) case 0xFD: av_log (s, AV_LOG_DEBUG, "entered audio subheader\n"); inSubheader = 1; - while (!pb->eof_reached && inSubheader) { + while (!url_feof(pb) && inSubheader) { uint8_t subbyte; subbyte = avio_r8(pb); diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c index 591a83525f..a54bee059d 100644 --- a/libavformat/ffmdec.c +++ b/libavformat/ffmdec.c @@ -91,7 +91,7 @@ static int ffm_resync(AVFormatContext *s, int state) { av_log(s, AV_LOG_ERROR, "resyncing\n"); while (state != PACKET_ID) { - if (s->pb->eof_reached) { + if (url_feof(s->pb)) { av_log(s, AV_LOG_ERROR, "cannot find FFM syncword\n"); return -1; } @@ -325,8 +325,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) codec->qcompress = avio_rb16(pb) / 10000.0; codec->qblur = avio_rb16(pb) / 10000.0; codec->bit_rate_tolerance = avio_rb32(pb); - avio_get_str(pb, INT_MAX, rc_eq_buf, sizeof(rc_eq_buf)); - codec->rc_eq = av_strdup(rc_eq_buf); + codec->rc_eq = av_strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf))); codec->rc_max_rate = avio_rb32(pb); codec->rc_min_rate = avio_rb32(pb); codec->rc_buffer_size = avio_rb32(pb); diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c index ed65624520..cc7e1da48f 100644 --- a/libavformat/ffmetadec.c +++ b/libavformat/ffmetadec.c @@ -48,7 +48,7 @@ static void get_line(AVIOContext *s, uint8_t *buf, int size) buf[i++] = c; } buf[i] = 0; - } while (!s->eof_reached && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0)); + } while (!url_feof(s) && (buf[0] == ';' || buf[0] == '#' || buf[0] == 0)); } static AVChapter *read_chapter(AVFormatContext *s) @@ -126,7 +126,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap) AVMetadata **m = &s->metadata; uint8_t line[1024]; - while(!s->pb->eof_reached) { + while(!url_feof(s->pb)) { get_line(s->pb, line, sizeof(line)); if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) { diff --git a/libavformat/filmstripdec.c b/libavformat/filmstripdec.c index 107f9e3622..46d0635e9d 100644 --- a/libavformat/filmstripdec.c +++ b/libavformat/filmstripdec.c @@ -80,7 +80,7 @@ static int read_packet(AVFormatContext *s, FilmstripDemuxContext *film = s->priv_data; AVStream *st = s->streams[0]; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); pkt->dts = avio_tell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4); pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4); diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 8ab4d9a80c..3dd3e1f70f 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -46,7 +46,7 @@ static int flac_read_header(AVFormatContext *s, } /* process metadata blocks */ - while (!s->pb->eof_reached && !metadata_last) { + while (!url_feof(s->pb) && !metadata_last) { avio_read(s->pb, header, 4); ff_flac_parse_block_header(header, &metadata_last, &metadata_type, &metadata_size); diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 65d77fcc7d..d84051c7a8 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -311,7 +311,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) dts = avio_rb24(s->pb); dts |= avio_r8(s->pb) << 24; // av_log(s, AV_LOG_DEBUG, "type:%d, size:%d, dts:%d\n", type, size, dts); - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR_EOF; avio_skip(s->pb, 3); /* stream id, always 0 */ flags = 0; diff --git a/libavformat/gxf.c b/libavformat/gxf.c index e959bf9dc4..e278b9b846 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -368,7 +368,7 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) { #define READ_ONE() \ { \ - if (!max_interval-- || pb->eof_reached) \ + if (!max_interval-- || url_feof(pb)) \ goto out; \ tmp = tmp << 8 | avio_r8(pb); \ } @@ -422,13 +422,13 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; GXFPktType pkt_type; int pkt_len; - while (!pb->eof_reached) { + while (!url_feof(pb)) { AVStream *st; int track_type, track_id, ret; int field_nr, field_info, skip = 0; int stream_index; if (!parse_packet_header(pb, &pkt_type, &pkt_len)) { - if (!pb->eof_reached) + if (!url_feof(pb)) av_log(s, AV_LOG_ERROR, "sync lost\n"); return -1; } diff --git a/libavformat/id3v1.c b/libavformat/id3v1.c index 0152e39654..4f9b5840ec 100644 --- a/libavformat/id3v1.c +++ b/libavformat/id3v1.c @@ -225,8 +225,9 @@ static int parse_tag(AVFormatContext *s, const uint8_t *buf) void ff_id3v1_read(AVFormatContext *s) { - int ret, filesize; + int ret; uint8_t buf[ID3v1_TAG_SIZE]; + int64_t filesize, position = url_ftell(s->pb); if (!url_is_streamed(s->pb)) { /* XXX: change that */ @@ -237,7 +238,7 @@ void ff_id3v1_read(AVFormatContext *s) if (ret == ID3v1_TAG_SIZE) { parse_tag(s, buf); } - avio_seek(s->pb, 0, SEEK_SET); + avio_seek(s->pb, position, SEEK_SET); } } } diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index b288ec6eec..027b8d717c 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -184,7 +184,8 @@ finish: static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) { - int isv34, tlen, unsync; + int isv34, unsync; + unsigned tlen; char tag[5]; int64_t next; int taghdrlen; @@ -237,6 +238,8 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t tag[3] = 0; tlen = avio_rb24(s->pb); } + if (tlen > (1<<28)) + break; len -= taghdrlen + tlen; if (len < 0) diff --git a/libavformat/idcin.c b/libavformat/idcin.c index 5c1d48df4c..fb07788655 100644 --- a/libavformat/idcin.c +++ b/libavformat/idcin.c @@ -227,7 +227,7 @@ static int idcin_read_packet(AVFormatContext *s, unsigned char r, g, b; unsigned char palette_buffer[768]; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); if (idcin->next_chunk_is_video) { diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 92c48d42fe..cbf3b3ed8d 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -111,7 +111,7 @@ static int roq_read_packet(AVFormatContext *s, while (!packet_read) { - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); /* get the next chunk preamble */ diff --git a/libavformat/iff.c b/libavformat/iff.c index 900d823d2b..24942122ad 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -138,7 +138,7 @@ static int iff_read_header(AVFormatContext *s, // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content st->codec->codec_tag = avio_rl32(pb); - while(!pb->eof_reached) { + while(!url_feof(pb)) { uint64_t orig_pos; int res; const char *metadata_tag = NULL; diff --git a/libavformat/img2.c b/libavformat/img2.c index d7e014f132..f9c71b97f2 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -287,7 +287,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt) infer_size(&codec->width, &codec->height, size[0]); } else { f[0] = s1->pb; - if (f[0]->eof_reached) + if (url_feof(f[0])) return AVERROR(EIO); size[0]= 4096; } diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index 97f225618d..8ea59a3b08 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -225,7 +225,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, return chunk_type; /* read the next chunk, wherever the file happens to be pointing */ - if (pb->eof_reached) + if (url_feof(pb)) return CHUNK_EOF; if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) != CHUNK_PREAMBLE_SIZE) @@ -271,7 +271,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) { /* read the next chunk, wherever the file happens to be pointing */ - if (pb->eof_reached) { + if (url_feof(pb)) { chunk_type = CHUNK_EOF; break; } @@ -532,7 +532,7 @@ static int ipmovie_read_header(AVFormatContext *s, while (memcmp(signature_buffer, signature, sizeof(signature))) { memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1); signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb); - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR_EOF; } /* initialize private context members */ diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c index c4aea3d44f..20978c674e 100644 --- a/libavformat/lxfdec.c +++ b/libavformat/lxfdec.c @@ -90,7 +90,7 @@ static int sync(AVFormatContext *s, uint8_t *header) return ret < 0 ? ret : AVERROR_EOF; while (memcmp(buf, LXF_IDENT, LXF_IDENT_LENGTH)) { - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR_EOF; memmove(buf, &buf[1], LXF_IDENT_LENGTH-1); diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index dff97b2cc8..d99b6ed487 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -127,6 +127,7 @@ typedef struct { int sub_packet_size; int sub_packet_cnt; int pkt_cnt; + uint64_t buf_timecode; uint8_t *buf; } MatroskaTrackAudio; @@ -485,7 +486,7 @@ static EbmlSyntax matroska_segments[] = { static EbmlSyntax matroska_blockgroup[] = { { MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) }, { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) }, - { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration), {.u=AV_NOPTS_VALUE} }, + { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration) }, { MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) }, { 1, EBML_UINT, 0, offsetof(MatroskaBlock,non_simple), {.u=1} }, { 0 } @@ -548,7 +549,7 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, * use it safely here to catch EOS. */ if (!(total = avio_r8(pb))) { /* we might encounter EOS here */ - if (!pb->eof_reached) { + if (!url_feof(pb)) { int64_t pos = avio_tell(pb); av_log(matroska->ctx, AV_LOG_ERROR, "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", @@ -1621,7 +1622,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, st = track->stream; if (st->discard >= AVDISCARD_ALL) return res; - if (duration == AV_NOPTS_VALUE) + if (!duration) duration = track->default_duration / matroska->time_scale; block_time = AV_RB16(data); @@ -1740,6 +1741,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int x; if (!track->audio.pkt_cnt) { + if (track->audio.sub_packet_cnt == 0) + track->audio.buf_timecode = timecode; if (st->codec->codec_id == CODEC_ID_RA_288) for (x=0; x<h/2; x++) memcpy(track->audio.buf+x*2*w+y*cfs, @@ -1762,6 +1765,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, av_new_packet(pkt, a); memcpy(pkt->data, track->audio.buf + a * (h*w / a - track->audio.pkt_cnt--), a); + pkt->pts = track->audio.buf_timecode; + track->audio.buf_timecode = AV_NOPTS_VALUE; pkt->pos = pos; pkt->stream_index = st->index; dynarray_add(&matroska->packets,&matroska->num_packets,pkt); @@ -1903,6 +1908,9 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, index_min = index; for (i=0; i < matroska->tracks.nb_elem; i++) { + tracks[i].audio.pkt_cnt = 0; + tracks[i].audio.sub_packet_cnt = 0; + tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; tracks[i].end_timecode = 0; if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE && !tracks[i].stream->discard != AVDISCARD_ALL) { diff --git a/libavformat/metadata.c b/libavformat/metadata.c index 7d9a8645df..68d42fd257 100644 --- a/libavformat/metadata.c +++ b/libavformat/metadata.c @@ -91,7 +91,9 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value) { return av_metadata_set2(pm, key, value, 0); } +#endif +#if FF_API_OLD_METADATA2 void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv) { diff --git a/libavformat/metadata.h b/libavformat/metadata.h index 9e866503b5..dd9b69005c 100644 --- a/libavformat/metadata.h +++ b/libavformat/metadata.h @@ -39,7 +39,7 @@ struct AVMetadataConv{ const char *native; const char *generic; }; -#if !FF_API_OLD_METADATA +#if !FF_API_OLD_METADATA2 typedef struct AVMetadataConv AVMetadataConv; #endif diff --git a/libavformat/mmf.c b/libavformat/mmf.c index 72dc954132..4605bf7fbd 100644 --- a/libavformat/mmf.c +++ b/libavformat/mmf.c @@ -266,7 +266,7 @@ static int mmf_read_packet(AVFormatContext *s, AVStream *st; int ret, size; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); st = s->streams[0]; diff --git a/libavformat/mov.c b/libavformat/mov.c index 746939d781..23ba1d47f0 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -259,7 +259,7 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (atom.size < 0) atom.size = INT64_MAX; - while (total_size + 8 < atom.size && !pb->eof_reached) { + while (total_size + 8 < atom.size && !url_feof(pb)) { int (*parse)(MOVContext*, AVIOContext*, MOVAtom) = NULL; a.size = atom.size; a.type=0; @@ -2331,7 +2331,7 @@ static void mov_read_chapters(AVFormatContext *s) avio_get_str16le(sc->pb, len, title, title_len); else { AV_WB16(title, ch); - avio_get_str(sc->pb, len - 2, title + 2, title_len - 2); + get_strz(sc->pb, title + 2, len - 1); } ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title); @@ -2411,7 +2411,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) mov->found_mdat = 0; if (!url_is_streamed(s->pb) || mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 || - s->pb->eof_reached) + url_feof(s->pb)) return AVERROR_EOF; av_dlog(s, "read fragments, offset 0x%llx\n", avio_tell(s->pb)); goto retry; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 774cd3a3b5..cd93f45449 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -91,6 +91,7 @@ static int mov_write_stsz_tag(AVIOContext *pb, MOVTrack *track) } if (equalChunks) { int sSize = track->cluster[0].size/track->cluster[0].entries; + sSize = FFMAX(1, sSize); // adpcm mono case could make sSize == 0 avio_wb32(pb, sSize); // sample size avio_wb32(pb, entries); // sample count } diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index 8b2d395621..b18726c6db 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -201,7 +201,7 @@ static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap) return -1; } - while(!pb->eof_reached){ + while(!url_feof(pb)){ pos = avio_tell(pb); mpc8_get_chunk_header(pb, &tag, &size); if(tag == TAG_STREAMHDR) @@ -248,7 +248,7 @@ static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt) int tag; int64_t pos, size; - while(!s->pb->eof_reached){ + while(!url_feof(s->pb)){ pos = avio_tell(s->pb); mpc8_get_chunk_header(s->pb, &tag, &size); if (size < 0) diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 821cd6c763..3903949d5d 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -143,7 +143,7 @@ static int find_next_start_code(AVIOContext *pb, int *size_ptr, state = *header_state; n = *size_ptr; while (n > 0) { - if (pb->eof_reached) + if (url_feof(pb)) break; v = avio_r8(pb); n--; @@ -253,7 +253,7 @@ static int mpegps_read_pes_header(AVFormatContext *s, last_sync = avio_tell(s->pb); //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, avio_tell(s->pb)); if (startcode < 0){ - if(s->pb->eof_reached) + if(url_feof(s->pb)) return AVERROR_EOF; //FIXME we should remember header_state return AVERROR(EAGAIN); diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 2ef80c088c..af0cadbb5a 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -809,7 +809,7 @@ static int mpegts_push_data(MpegTSFilter *filter, * a couple of seconds to milliseconds for properly muxed files. * total_size is the number of bytes following pes_packet_length * in the pes header, i.e. not counting the first 6 bytes */ - if (pes->total_size < MAX_PES_PAYLOAD && + if (!ts->stop_parse && pes->total_size < MAX_PES_PAYLOAD && pes->pes_header_size + pes->data_index == pes->total_size + 6) { ts->stop_parse = 1; new_pes_packet(pes, ts->pkt); @@ -1329,7 +1329,7 @@ static int mpegts_resync(AVFormatContext *s) for(i = 0;i < MAX_RESYNC_SIZE; i++) { c = avio_r8(pb); - if (pb->eof_reached) + if (url_feof(pb)) return -1; if (c == 0x47) { avio_seek(pb, -1, SEEK_CUR); diff --git a/libavformat/msnwc_tcp.c b/libavformat/msnwc_tcp.c index a5dab2013f..252ce34f6b 100644 --- a/libavformat/msnwc_tcp.c +++ b/libavformat/msnwc_tcp.c @@ -88,9 +88,9 @@ static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap) /* Some files start with "connected\r\n\r\n". * So skip until we find the first byte of struct size */ - while(avio_r8(pb) != HEADER_SIZE && !pb->eof_reached); + while(avio_r8(pb) != HEADER_SIZE && !url_feof(pb)); - if(pb->eof_reached) { + if(url_feof(pb)) { av_log(ctx, AV_LOG_ERROR, "Could not find valid start."); return -1; } diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index fa0b734853..6b44b8f3e3 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -179,7 +179,7 @@ static int64_t klv_decode_ber_length(AVIOContext *pb) static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size) { int i, b; - for (i = 0; i < size && !pb->eof_reached; i++) { + for (i = 0; i < size && !url_feof(pb); i++) { b = avio_r8(pb); if (b == key[0]) i = 0; @@ -305,7 +305,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) { KLVPacket klv; - while (!s->pb->eof_reached) { + while (!url_feof(s->pb)) { if (klv_read_packet(&klv, s->pb) < 0) return -1; PRINT_KEY(s, "read packet", klv.key); @@ -914,7 +914,7 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) } avio_seek(s->pb, -14, SEEK_CUR); mxf->fc = s; - while (!s->pb->eof_reached) { + while (!url_feof(s->pb)) { const MXFMetadataReadTableEntry *metadata; if (klv_read_packet(&klv, s->pb) < 0) diff --git a/libavformat/mxg.c b/libavformat/mxg.c index 7d342f1766..e884311bad 100644 --- a/libavformat/mxg.c +++ b/libavformat/mxg.c @@ -132,7 +132,7 @@ static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt) uint8_t *startmarker_ptr, *end, *search_end, marker; MXGContext *mxg = s->priv_data; - while (!s->pb->eof_reached && !s->pb->error){ + while (!url_feof(s->pb) && !s->pb->error){ if (mxg->cache_size <= OVERREAD_SIZE) { /* update internal buffer */ ret = mxg_update_cache(s, DEFAULT_PACKET_SIZE + OVERREAD_SIZE); diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c index 142fd37ad1..c95b4bde9d 100644 --- a/libavformat/ncdec.c +++ b/libavformat/ncdec.c @@ -66,7 +66,7 @@ static int nc_read_packet(AVFormatContext *s, AVPacket *pkt) uint32_t state=-1; while (state != NC_VIDEO_FLAG) { - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); state = (state<<8) + avio_r8(s->pb); } diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 06565cdb43..4b294d3591 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -230,7 +230,7 @@ static int nsv_resync(AVFormatContext *s) //nsv->state = NSV_UNSYNC; for (i = 0; i < NSV_MAX_RESYNC; i++) { - if (pb->eof_reached) { + if (url_feof(pb)) { av_dlog(s, "NSV EOF\n"); nsv->state = NSV_UNSYNC; return -1; @@ -296,7 +296,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) table_entries_used = avio_rl32(pb); av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", strings_size, table_entries, table_entries_used); - if (pb->eof_reached) + if (url_feof(pb)) return -1; av_dlog(s, "NSV got header; filepos %"PRId64"\n", avio_tell(pb)); @@ -331,7 +331,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) } av_free(strings); } - if (pb->eof_reached) + if (url_feof(pb)) return -1; av_dlog(s, "NSV got infos; filepos %"PRId64"\n", avio_tell(pb)); @@ -378,7 +378,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) avio_seek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */ - if (pb->eof_reached) + if (url_feof(pb)) return -1; nsv->state = NSV_HAS_READ_NSVF; return 0; @@ -554,7 +554,7 @@ static int nsv_read_chunk(AVFormatContext *s, int fill_header) return 0; //-1; /* hey! eat what you've in your plate first! */ null_chunk_retry: - if (pb->eof_reached) + if (url_feof(pb)) return -1; for (i = 0; i < NSV_MAX_RESYNC_TRIES && nsv->state < NSV_FOUND_NSVS && !err; i++) @@ -588,7 +588,7 @@ null_chunk_retry: vsize -= auxsize + sizeof(uint16_t) + sizeof(uint32_t); /* that's becoming braindead */ } - if (pb->eof_reached) + if (url_feof(pb)) return -1; if (!vsize && !asize) { nsv->state = NSV_UNSYNC; diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index d9bb76904f..b957644f12 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -122,7 +122,7 @@ static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos){ if(pos >= 0) avio_seek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we currently are - while(!bc->eof_reached){ + while(!url_feof(bc)){ state= (state<<8) | avio_r8(bc); if((state>>56) != 'N') continue; @@ -791,7 +791,7 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) pos-=8; }else{ frame_code = avio_r8(bc); - if(bc->eof_reached) + if(url_feof(bc)) return -1; if(frame_code == 'N'){ tmp= frame_code; diff --git a/libavformat/nuv.c b/libavformat/nuv.c index 5d63291868..db31689753 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -60,7 +60,7 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst, nuv_frametype frametype; if (!vst && !myth) return 1; // no codec data needed - while (!pb->eof_reached) { + while (!url_feof(pb)) { int size, subtype; frametype = avio_r8(pb); switch (frametype) { @@ -195,7 +195,7 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { uint8_t hdr[HDRSIZE]; nuv_frametype frametype; int ret, size; - while (!pb->eof_reached) { + while (!url_feof(pb)) { int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0; uint64_t pos = avio_tell(pb); ret = avio_read(pb, hdr, HDRSIZE); diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 76ef19ada3..379de7eac1 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -219,7 +219,7 @@ ogg_read_page (AVFormatContext * s, int *str) break; c = avio_r8(bc); - if (bc->eof_reached) + if (url_feof(bc)) return -1; sync[sp++ & 3] = c; }while (i++ < MAX_PAGE_SIZE); diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c index 3b0780b6ea..744ae94459 100644 --- a/libavformat/psxstr.c +++ b/libavformat/psxstr.c @@ -241,7 +241,7 @@ static int str_read_packet(AVFormatContext *s, break; } - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); } } diff --git a/libavformat/qcp.c b/libavformat/qcp.c index 46eb0a9685..b4f559ee11 100644 --- a/libavformat/qcp.c +++ b/libavformat/qcp.c @@ -140,7 +140,7 @@ static int qcp_read_packet(AVFormatContext *s, AVPacket *pkt) QCPContext *c = s->priv_data; unsigned int chunk_size, tag; - while(!pb->eof_reached) { + while(!url_feof(pb)) { if (c->data_size) { int pkt_size, ret, mode = avio_r8(pb); diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index c29905db58..1ffeae56ee 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -409,7 +409,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) avio_rb32(pb); /* number of headers */ for(;;) { - if (pb->eof_reached) + if (url_feof(pb)) return -1; tag = avio_rl32(pb); tag_size = avio_rb32(pb); @@ -515,7 +515,7 @@ static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_ AVStream *st; uint32_t state=0xFFFFFFFF; - while(!pb->eof_reached){ + while(!url_feof(pb)){ int len, num, i; *pos= avio_tell(pb) - 3; if(rm->remaining_len > 0){ @@ -848,7 +848,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) st = s->streams[i]; } - if(len<0 || s->pb->eof_reached) + if(len<0 || url_feof(s->pb)) return AVERROR(EIO); res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt, diff --git a/libavformat/smacker.c b/libavformat/smacker.c index 5fc6e58e59..2603a4d71c 100644 --- a/libavformat/smacker.c +++ b/libavformat/smacker.c @@ -235,7 +235,7 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) int palchange = 0; int pos; - if (s->pb->eof_reached || smk->cur_frame >= smk->frames) + if (url_feof(s->pb) || smk->cur_frame >= smk->frames) return AVERROR_EOF; /* if we demuxed all streams, pass another frame */ diff --git a/libavformat/sol.c b/libavformat/sol.c index 2a3b40c02b..7ad894e304 100644 --- a/libavformat/sol.c +++ b/libavformat/sol.c @@ -130,7 +130,7 @@ static int sol_read_packet(AVFormatContext *s, { int ret; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); ret= av_get_packet(s->pb, pkt, MAX_SIZE); pkt->stream_index = 0; diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c index 4f0984dde4..5e1e220f76 100644 --- a/libavformat/soxdec.c +++ b/libavformat/soxdec.c @@ -127,7 +127,7 @@ static int sox_read_packet(AVFormatContext *s, { int ret, size; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR_EOF; size = SOX_SAMPLES*s->streams[0]->codec->block_align; diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c index 1d198ca2c4..dd29a5fecc 100644 --- a/libavformat/spdifdec.c +++ b/libavformat/spdifdec.c @@ -171,7 +171,7 @@ static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt) while (state != (AV_BSWAP16C(SYNCWORD1) << 16 | AV_BSWAP16C(SYNCWORD2))) { state = (state << 8) | avio_r8(pb); - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR_EOF; } diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c index 3572add0dd..0a94a7f518 100644 --- a/libavformat/srtdec.c +++ b/libavformat/srtdec.c @@ -81,7 +81,7 @@ static int srt_read_packet(AVFormatContext *s, AVPacket *pkt) do { ptr2 = ptr; ptr += ff_get_line(s->pb, ptr, sizeof(buffer)+buffer-ptr); - } while (!is_eol(*ptr2) && !s->pb->eof_reached && ptr-buffer<sizeof(buffer)-1); + } while (!is_eol(*ptr2) && !url_feof(s->pb) && ptr-buffer<sizeof(buffer)-1); if (buffer[0] && !(res = av_new_packet(pkt, ptr-buffer))) { memcpy(pkt->data, buffer, pkt->size); diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index bf70fc5250..f90564f3db 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -27,7 +27,7 @@ static int get_swf_tag(AVIOContext *pb, int *len_ptr) { int tag, len; - if (pb->eof_reached) + if (url_feof(pb)) return -1; tag = avio_rl16(pb); diff --git a/libavformat/tmv.c b/libavformat/tmv.c index 828a556720..0a16ae111a 100644 --- a/libavformat/tmv.c +++ b/libavformat/tmv.c @@ -146,7 +146,7 @@ static int tmv_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, pkt_size = tmv->stream_index ? tmv->audio_chunk_size : tmv->video_chunk_size; - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR_EOF; ret = av_get_packet(pb, pkt, pkt_size); diff --git a/libavformat/tty.c b/libavformat/tty.c index 8af245ae60..71c00e7e0a 100644 --- a/libavformat/tty.c +++ b/libavformat/tty.c @@ -106,7 +106,7 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) TtyDemuxContext *s = avctx->priv_data; int n; - if (avctx->pb->eof_reached) + if (url_feof(avctx->pb)) return AVERROR_EOF; n = s->chars_per_frame; diff --git a/libavformat/txd.c b/libavformat/txd.c index dd95366795..05eb0ce6f3 100644 --- a/libavformat/txd.c +++ b/libavformat/txd.c @@ -61,7 +61,7 @@ next_chunk: chunk_size = avio_rl32(pb); marker = avio_rl32(pb); - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR_EOF; if (marker != TXD_MARKER && marker != TXD_MARKER2) { av_log(s, AV_LOG_ERROR, "marker does not match\n"); diff --git a/libavformat/utils.c b/libavformat/utils.c index d6a17009db..89eb557647 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2408,7 +2408,7 @@ int av_find_stream_info(AVFormatContext *ic) // the check for tb_unreliable() is not completely correct, since this is not about handling // a unreliable/inexact time base, but a time base that is finer than necessary, as e.g. // ipmovie.c produces. - if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > 1 && !st->r_frame_rate.num) + if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num) av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX); if (st->info->duration_count && !st->r_frame_rate.num && tb_unreliable(st->codec) /*&& @@ -2501,7 +2501,7 @@ int av_find_best_stream(AVFormatContext *ic, AVCodec **decoder_ret, int flags) { - int i, nb_streams = ic->nb_streams, stream_number = 0; + int i, nb_streams = ic->nb_streams; int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1; unsigned *program = NULL; AVCodec *decoder = NULL, *best_decoder = NULL; @@ -2514,16 +2514,17 @@ int av_find_best_stream(AVFormatContext *ic, } } for (i = 0; i < nb_streams; i++) { - AVStream *st = ic->streams[program ? program[i] : i]; + int real_stream_index = program ? program[i] : i; + AVStream *st = ic->streams[real_stream_index]; AVCodecContext *avctx = st->codec; if (avctx->codec_type != type) continue; - if (wanted_stream_nb >= 0 && stream_number++ != wanted_stream_nb) + if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb) continue; if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED)) continue; if (decoder_ret) { - decoder = avcodec_find_decoder(ic->streams[i]->codec->codec_id); + decoder = avcodec_find_decoder(st->codec->codec_id); if (!decoder) { if (ret < 0) ret = AVERROR_DECODER_NOT_FOUND; @@ -2533,7 +2534,7 @@ int av_find_best_stream(AVFormatContext *ic, if (best_count >= st->codec_info_nb_frames) continue; best_count = st->codec_info_nb_frames; - ret = program ? program[i] : i; + ret = real_stream_index; best_decoder = decoder; if (program && i == nb_streams - 1 && ret < 0) { program = NULL; @@ -2992,6 +2993,8 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) return ret; ret= s->oformat->write_packet(s, pkt); + if(!ret) + ret= url_ferror(s->pb); return ret; } @@ -3115,6 +3118,8 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ if(ret<0) return ret; + if(url_ferror(s->pb)) + return url_ferror(s->pb); } } @@ -3136,11 +3141,15 @@ int av_write_trailer(AVFormatContext *s) if(ret<0) goto fail; + if(url_ferror(s->pb)) + goto fail; } if(s->oformat->write_trailer) ret = s->oformat->write_trailer(s); fail: + if(ret == 0) + ret=url_ferror(s->pb); for(i=0;i<s->nb_streams;i++) { av_freep(&s->streams[i]->priv_data); av_freep(&s->streams[i]->index_entries); diff --git a/libavformat/vc1test.c b/libavformat/vc1test.c index 783ab88ebf..4ab9bca1af 100644 --- a/libavformat/vc1test.c +++ b/libavformat/vc1test.c @@ -92,7 +92,7 @@ static int vc1t_read_packet(AVFormatContext *s, int keyframe = 0; uint32_t pts; - if(pb->eof_reached) + if(url_feof(pb)) return AVERROR(EIO); frame_size = avio_rl24(pb); diff --git a/libavformat/version.h b/libavformat/version.h index aed8908ebe..d03fe1214f 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -47,6 +47,9 @@ #ifndef FF_API_OLD_METADATA #define FF_API_OLD_METADATA (LIBAVFORMAT_VERSION_MAJOR < 53) #endif +#ifndef FF_API_OLD_METADATA2 +#define FF_API_OLD_METADATA2 (LIBAVFORMAT_VERSION_MAJOR < 54) +#endif #ifndef FF_API_URL_CLASS #define FF_API_URL_CLASS (LIBAVFORMAT_VERSION_MAJOR >= 53) #endif @@ -87,7 +90,7 @@ #define FF_API_SYMVER (LIBAVFORMAT_VERSION_MAJOR < 53) #endif #ifndef FF_API_OLD_AVIO -#define FF_API_OLD_AVIO (LIBAVFORMAT_VERSION_MAJOR < 53) +#define FF_API_OLD_AVIO (LIBAVFORMAT_VERSION_MAJOR < 54) #endif #ifndef FF_API_INDEX_BUILT #define FF_API_INDEX_BUILT (LIBAVFORMAT_VERSION_MAJOR < 53) diff --git a/libavformat/wav.c b/libavformat/wav.c index 28ebe140b6..876defb51d 100644 --- a/libavformat/wav.c +++ b/libavformat/wav.c @@ -155,7 +155,7 @@ static int64_t find_tag(AVIOContext *pb, uint32_t tag1) int64_t size; for (;;) { - if (pb->eof_reached) + if (url_feof(pb)) return -1; size = next_tag(pb, &tag); if (tag == tag1) @@ -234,7 +234,7 @@ static int wav_read_header(AVFormatContext *s, av_set_pts_info(st, 64, 1, st->codec->sample_rate); for (;;) { - if (pb->eof_reached) + if (url_feof(pb)) return -1; size = next_tag(pb, &tag); if (tag == MKTAG('d', 'a', 't', 'a')){ @@ -269,7 +269,7 @@ static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16]) uint8_t guid[16]; int64_t size; - while (!pb->eof_reached) { + while (!url_feof(pb)) { avio_read(pb, guid, 16); size = avio_rl64(pb); if (size <= 24) diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c index 01bed4f714..0f2e077859 100644 --- a/libavformat/wc3movie.c +++ b/libavformat/wc3movie.c @@ -157,7 +157,7 @@ static int wc3_read_header(AVFormatContext *s, fourcc_tag = avio_rl32(pb); /* chunk sizes are 16-bit aligned */ size = (avio_rb32(pb) + 1) & (~1); - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); } while (fourcc_tag != BRCH_TAG); @@ -208,7 +208,7 @@ static int wc3_read_packet(AVFormatContext *s, fourcc_tag = avio_rl32(pb); /* chunk sizes are 16-bit aligned */ size = (avio_rb32(pb) + 1) & (~1); - if (pb->eof_reached) + if (url_feof(pb)) return AVERROR(EIO); switch (fourcc_tag) { diff --git a/libavformat/wtv.c b/libavformat/wtv.c index 6337502209..35d987c061 100644 --- a/libavformat/wtv.c +++ b/libavformat/wtv.c @@ -79,7 +79,7 @@ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size) if (wf->error || pb->error) return -1; - if (wf->position >= wf->length || pb->eof_reached) + if (wf->position >= wf->length || url_feof(pb)) return 0; buf_size = FFMIN(buf_size, wf->length - wf->position); @@ -554,7 +554,7 @@ static void parse_legacy_attrib(AVFormatContext *s, AVIOContext *pb) { ff_asf_guid guid; int length, type; - while(!pb->eof_reached) { + while(!url_feof(pb)) { char key[1024]; ff_get_guid(pb, &guid); type = avio_rl32(pb); @@ -770,7 +770,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p { WtvContext *wtv = s->priv_data; AVIOContext *pb = wtv->pb; - while (!pb->eof_reached) { + while (!url_feof(pb)) { ff_asf_guid g; int len, sid, consumed; @@ -997,7 +997,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap) while(1) { uint64_t timestamp = avio_rl64(pb); uint64_t frame_nb = avio_rl64(pb); - if (pb->eof_reached) + if (url_feof(pb)) break; ff_add_index_entry(&wtv->index_entries, &wtv->nb_index_entries, &wtv->index_entries_allocated_size, 0, timestamp, frame_nb, 0, AVINDEX_KEYFRAME); @@ -1011,7 +1011,7 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap) while (1) { uint64_t frame_nb = avio_rl64(pb); uint64_t position = avio_rl64(pb); - if (pb->eof_reached) + if (url_feof(pb)) break; for (i = wtv->nb_index_entries - 1; i >= 0; i--) { AVIndexEntry *e = wtv->index_entries + i; diff --git a/libavformat/wv.c b/libavformat/wv.c index 9a8f857968..600de9317b 100644 --- a/libavformat/wv.c +++ b/libavformat/wv.c @@ -241,7 +241,7 @@ static int wv_read_packet(AVFormatContext *s, int ret; int size, ver, off; - if (s->pb->eof_reached) + if (url_feof(s->pb)) return AVERROR(EIO); if(wc->block_parsed){ if(wv_read_block_header(s, s->pb, 0) < 0) |