Commit c10731e7 authored by Anton Khirnov's avatar Anton Khirnov

lavf: deprecate AVFormatContext.file_size

It's too unreliable to be useful. avio_size() should be called instead.
parent f0556353
...@@ -268,9 +268,6 @@ static int aiff_read_header(AVFormatContext *s, ...@@ -268,9 +268,6 @@ static int aiff_read_header(AVFormatContext *s,
got_sound: got_sound:
/* Now positioned, get the sound data start and end */ /* Now positioned, get the sound data start and end */
if (st->nb_frames)
s->file_size = st->nb_frames * st->codec->block_align;
av_set_pts_info(st, 64, 1, st->codec->sample_rate); av_set_pts_info(st, 64, 1, st->codec->sample_rate);
st->start_time = 0; st->start_time = 0;
st->duration = st->codec->frame_size ? st->duration = st->codec->frame_size ?
......
...@@ -716,10 +716,12 @@ typedef struct AVFormatContext { ...@@ -716,10 +716,12 @@ typedef struct AVFormatContext {
*/ */
int64_t duration; int64_t duration;
#if FF_API_FILESIZE
/** /**
* decoding: total file size, 0 if unknown * decoding: total file size, 0 if unknown
*/ */
int64_t file_size; attribute_deprecated int64_t file_size;
#endif
/** /**
* Decoding: total stream bitrate in bit/s, 0 if not * Decoding: total stream bitrate in bit/s, 0 if not
......
...@@ -286,8 +286,6 @@ static int read_header(AVFormatContext *s, ...@@ -286,8 +286,6 @@ static int read_header(AVFormatContext *s,
"block size or frame size are variable.\n"); "block size or frame size are variable.\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
s->file_size = avio_size(pb);
s->file_size = FFMAX(0, s->file_size);
av_set_pts_info(st, 64, 1, st->codec->sample_rate); av_set_pts_info(st, 64, 1, st->codec->sample_rate);
st->start_time = 0; st->start_time = 0;
......
...@@ -92,8 +92,7 @@ static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -92,8 +92,7 @@ static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
avio_rb32(pb); // "RIFF" avio_rb32(pb); // "RIFF"
s->file_size = avio_rl32(pb) + 8; avio_skip(pb, 4 + 8 + 4 + 1 + 1); // filesize + "QLCMfmt " + chunk-size + major-version + minor-version
avio_skip(pb, 8 + 4 + 1 + 1); // "QLCMfmt " + chunk-size + major-version + minor-version
st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->channels = 1; st->codec->channels = 1;
......
...@@ -1837,7 +1837,7 @@ static int has_duration(AVFormatContext *ic) ...@@ -1837,7 +1837,7 @@ static int has_duration(AVFormatContext *ic)
static void update_stream_timings(AVFormatContext *ic) static void update_stream_timings(AVFormatContext *ic)
{ {
int64_t start_time, start_time1, end_time, end_time1; int64_t start_time, start_time1, end_time, end_time1;
int64_t duration, duration1; int64_t duration, duration1, filesize;
int i; int i;
AVStream *st; AVStream *st;
...@@ -1872,9 +1872,9 @@ static void update_stream_timings(AVFormatContext *ic) ...@@ -1872,9 +1872,9 @@ static void update_stream_timings(AVFormatContext *ic)
} }
if (duration != INT64_MIN) { if (duration != INT64_MIN) {
ic->duration = duration; ic->duration = duration;
if (ic->file_size > 0) { if (ic->pb && (filesize = avio_size(ic->pb)) > 0) {
/* compute the bitrate */ /* compute the bitrate */
ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / ic->bit_rate = (double)filesize * 8.0 * AV_TIME_BASE /
(double)ic->duration; (double)ic->duration;
} }
} }
...@@ -1916,9 +1916,8 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) ...@@ -1916,9 +1916,8 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)
/* if duration is already set, we believe it */ /* if duration is already set, we believe it */
if (ic->duration == AV_NOPTS_VALUE && if (ic->duration == AV_NOPTS_VALUE &&
ic->bit_rate != 0 && ic->bit_rate != 0) {
ic->file_size != 0) { filesize = ic->pb ? avio_size(ic->pb) : 0;
filesize = ic->file_size;
if (filesize > 0) { if (filesize > 0) {
for(i = 0; i < ic->nb_streams; i++) { for(i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i]; st = ic->streams[i];
...@@ -1962,7 +1961,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) ...@@ -1962,7 +1961,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
/* estimate the end time (duration) */ /* estimate the end time (duration) */
/* XXX: may need to support wrapping */ /* XXX: may need to support wrapping */
filesize = ic->file_size; filesize = ic->pb ? avio_size(ic->pb) : 0;
end_time = AV_NOPTS_VALUE; end_time = AV_NOPTS_VALUE;
do{ do{
offset = filesize - (DURATION_MAX_READ_SIZE<<retry); offset = filesize - (DURATION_MAX_READ_SIZE<<retry);
...@@ -2026,7 +2025,6 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) ...@@ -2026,7 +2025,6 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
if (file_size < 0) if (file_size < 0)
file_size = 0; file_size = 0;
} }
ic->file_size = file_size;
if ((!strcmp(ic->iformat->name, "mpeg") || if ((!strcmp(ic->iformat->name, "mpeg") ||
!strcmp(ic->iformat->name, "mpegts")) && !strcmp(ic->iformat->name, "mpegts")) &&
......
...@@ -86,5 +86,8 @@ ...@@ -86,5 +86,8 @@
#ifndef FF_API_TIMESTAMP #ifndef FF_API_TIMESTAMP
#define FF_API_TIMESTAMP (LIBAVFORMAT_VERSION_MAJOR < 54) #define FF_API_TIMESTAMP (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif #endif
#ifndef FF_API_FILESIZE
#define FF_API_FILESIZE (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
#endif /* AVFORMAT_VERSION_H */ #endif /* AVFORMAT_VERSION_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment