From patchwork Fri Oct 9 13:04:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22794 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B83EE44AB2F for ; Fri, 9 Oct 2020 16:09:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5426968BA11; Fri, 9 Oct 2020 16:06:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C692E68B9D5 for ; Fri, 9 Oct 2020 16:06:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 40674296254 for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Aa1Mf0JfGMyn for ; Fri, 9 Oct 2020 15:06:33 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 3699B2961F9 for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 3135A20E00BE; Fri, 9 Oct 2020 15:06:25 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:13 +0200 Message-Id: <20201009130430.602-1-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/18] lavf: move AVStream.info to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This struct is for internal use of avformat_find_stream_info(), so it should not be exposed in public headers. Keep a stub pointer in its place to avoid changing AVStream layout, since e.g. ffmpeg.c accesses some fields located after it (even though they are marked as private). --- libavformat/avformat.h | 36 +------ libavformat/internal.h | 33 ++++++ libavformat/utils.c | 228 ++++++++++++++++++++--------------------- 3 files changed, 151 insertions(+), 146 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index c8c0b6c08d..8eff5b8eaa 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1023,38 +1023,10 @@ typedef struct AVStream { ***************************************************************** */ -#define MAX_STD_TIMEBASES (30*12+30+3+6) - /** - * Stream information used internally by avformat_find_stream_info() - */ - struct { - int64_t last_dts; - int64_t duration_gcd; - int duration_count; - int64_t rfps_duration_sum; - double (*duration_error)[2][MAX_STD_TIMEBASES]; - int64_t codec_info_duration; - int64_t codec_info_duration_fields; - int frame_delay_evidence; - - /** - * 0 -> decoder has not been searched for yet. - * >0 -> decoder found - * <0 -> decoder with codec_id == -found_decoder has not been found - */ - int found_decoder; - - int64_t last_duration; - - /** - * Those are used for average framerate estimation. - */ - int64_t fps_first_dts; - int fps_first_dts_idx; - int64_t fps_last_dts; - int fps_last_dts_idx; - - } *info; +#if LIBAVFORMAT_VERSION_MAJOR < 59 + // kept for ABI compatibility only, do not access in any way + void *unused; +#endif int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ diff --git a/libavformat/internal.h b/libavformat/internal.h index f4174628e0..30b4df9181 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -191,6 +191,39 @@ struct AVStreamInternal { int is_intra_only; FFFrac *priv_pts; + +#define MAX_STD_TIMEBASES (30*12+30+3+6) + /** + * Stream information used internally by avformat_find_stream_info() + */ + struct { + int64_t last_dts; + int64_t duration_gcd; + int duration_count; + int64_t rfps_duration_sum; + double (*duration_error)[2][MAX_STD_TIMEBASES]; + int64_t codec_info_duration; + int64_t codec_info_duration_fields; + int frame_delay_evidence; + + /** + * 0 -> decoder has not been searched for yet. + * >0 -> decoder found + * <0 -> decoder with codec_id == -found_decoder has not been found + */ + int found_decoder; + + int64_t last_duration; + + /** + * Those are used for average framerate estimation. + */ + int64_t fps_first_dts; + int fps_first_dts_idx; + int64_t fps_last_dts; + int fps_last_dts_idx; + + } *info; }; #ifdef __GNUC__ diff --git a/libavformat/utils.c b/libavformat/utils.c index a2e701ea1a..a13f31dccf 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -992,7 +992,7 @@ int ff_is_intra_only(enum AVCodecID id) static int has_decode_delay_been_guessed(AVStream *st) { if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; - if (!st->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy + if (!st->internal->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy return 1; #if CONFIG_H264_DECODER if (st->internal->avctx->has_b_frames && @@ -1539,7 +1539,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (avcodec_is_open(st->internal->avctx)) { av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); avcodec_close(st->internal->avctx); - st->info->found_decoder = 0; + st->internal->info->found_decoder = 0; } /* close parser, because it depends on the codec */ @@ -2812,10 +2812,10 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) else duration -= st->first_dts; if (duration > 0) { - if (st->duration == AV_NOPTS_VALUE || st->info->last_duration<= 0 || - (st->duration < duration && FFABS(duration - st->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) + if (st->duration == AV_NOPTS_VALUE || st->internal->info->last_duration<= 0 || + (st->duration < duration && FFABS(duration - st->internal->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) st->duration = duration; - st->info->last_duration = duration; + st->internal->info->last_duration = duration; } } av_packet_unref(pkt); @@ -2952,20 +2952,20 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) case AVMEDIA_TYPE_AUDIO: if (!avctx->frame_size && determinable_frame_size(avctx)) FAIL("unspecified frame size"); - if (st->info->found_decoder >= 0 && + if (st->internal->info->found_decoder >= 0 && avctx->sample_fmt == AV_SAMPLE_FMT_NONE) FAIL("unspecified sample format"); if (!avctx->sample_rate) FAIL("unspecified sample rate"); if (!avctx->channels) FAIL("unspecified number of channels"); - if (st->info->found_decoder >= 0 && !st->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) + if (st->internal->info->found_decoder >= 0 && !st->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) FAIL("no decodable DTS frames"); break; case AVMEDIA_TYPE_VIDEO: if (!avctx->width) FAIL("unspecified size"); - if (st->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) + if (st->internal->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) FAIL("unspecified pixel format"); if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !st->codec_info_nb_frames) @@ -2999,14 +2999,14 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, return AVERROR(ENOMEM); if (!avcodec_is_open(avctx) && - st->info->found_decoder <= 0 && - (st->codecpar->codec_id != -st->info->found_decoder || !st->codecpar->codec_id)) { + st->internal->info->found_decoder <= 0 && + (st->codecpar->codec_id != -st->internal->info->found_decoder || !st->codecpar->codec_id)) { AVDictionary *thread_opt = NULL; codec = find_probe_decoder(s, st, st->codecpar->codec_id); if (!codec) { - st->info->found_decoder = -st->codecpar->codec_id; + st->internal->info->found_decoder = -st->codecpar->codec_id; ret = -1; goto fail; } @@ -3020,14 +3020,14 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, if (!options) av_dict_free(&thread_opt); if (ret < 0) { - st->info->found_decoder = -avctx->codec_id; + st->internal->info->found_decoder = -avctx->codec_id; goto fail; } - st->info->found_decoder = 1; - } else if (!st->info->found_decoder) - st->info->found_decoder = 1; + st->internal->info->found_decoder = 1; + } else if (!st->internal->info->found_decoder) + st->internal->info->found_decoder = 1; - if (st->info->found_decoder < 0) { + if (st->internal->info->found_decoder < 0) { ret = -1; goto fail; } @@ -3293,59 +3293,59 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) { int i, j; - int64_t last = st->info->last_dts; + int64_t last = st->internal->info->last_dts; if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last && ts - (uint64_t)last < INT64_MAX) { double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); int64_t duration = ts - last; - if (!st->info->duration_error) - st->info->duration_error = av_mallocz(sizeof(st->info->duration_error[0])*2); - if (!st->info->duration_error) + if (!st->internal->info->duration_error) + st->internal->info->duration_error = av_mallocz(sizeof(st->internal->info->duration_error[0])*2); + if (!st->internal->info->duration_error) return AVERROR(ENOMEM); // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); for (i = 0; iinfo->duration_error[0][1][i] < 1e10) { + if (st->internal->info->duration_error[0][1][i] < 1e10) { int framerate = get_std_framerate(i); double sdts = dts*framerate/(1001*12); for (j= 0; j<2; j++) { int64_t ticks = llrint(sdts+j*0.5); double error= sdts - ticks + j*0.5; - st->info->duration_error[j][0][i] += error; - st->info->duration_error[j][1][i] += error*error; + st->internal->info->duration_error[j][0][i] += error; + st->internal->info->duration_error[j][1][i] += error*error; } } } - if (st->info->rfps_duration_sum <= INT64_MAX - duration) { - st->info->duration_count++; - st->info->rfps_duration_sum += duration; + if (st->internal->info->rfps_duration_sum <= INT64_MAX - duration) { + st->internal->info->duration_count++; + st->internal->info->rfps_duration_sum += duration; } - if (st->info->duration_count % 10 == 0) { - int n = st->info->duration_count; + if (st->internal->info->duration_count % 10 == 0) { + int n = st->internal->info->duration_count; for (i = 0; iinfo->duration_error[0][1][i] < 1e10) { - double a0 = st->info->duration_error[0][0][i] / n; - double error0 = st->info->duration_error[0][1][i] / n - a0*a0; - double a1 = st->info->duration_error[1][0][i] / n; - double error1 = st->info->duration_error[1][1][i] / n - a1*a1; + if (st->internal->info->duration_error[0][1][i] < 1e10) { + double a0 = st->internal->info->duration_error[0][0][i] / n; + double error0 = st->internal->info->duration_error[0][1][i] / n - a0*a0; + double a1 = st->internal->info->duration_error[1][0][i] / n; + double error1 = st->internal->info->duration_error[1][1][i] / n - a1*a1; if (error0 > 0.04 && error1 > 0.04) { - st->info->duration_error[0][1][i] = 2e10; - st->info->duration_error[1][1][i] = 2e10; + st->internal->info->duration_error[0][1][i] = 2e10; + st->internal->info->duration_error[1][1][i] = 2e10; } } } } // ignore the first 4 values, they might have some random jitter - if (st->info->duration_count > 3 && is_relative(ts) == is_relative(last)) - st->info->duration_gcd = av_gcd(st->info->duration_gcd, duration); + if (st->internal->info->duration_count > 3 && is_relative(ts) == is_relative(last)) + st->internal->info->duration_gcd = av_gcd(st->internal->info->duration_gcd, duration); } if (ts != AV_NOPTS_VALUE) - st->info->last_dts = ts; + st->internal->info->last_dts = ts; return 0; } @@ -3362,9 +3362,9 @@ void ff_rfps_calculate(AVFormatContext *ic) // the check for tb_unreliable() is not completely correct, since this is not about handling // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. // ipmovie.c produces. - if (tb_unreliable(st->internal->avctx) && 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>1 && !st->r_frame_rate.num + if (tb_unreliable(st->internal->avctx) && st->internal->info->duration_count > 15 && st->internal->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->internal->info->duration_gcd, INT_MAX); + if (st->internal->info->duration_count>1 && !st->r_frame_rate.num && tb_unreliable(st->internal->avctx)) { int num = 0; double best_error= 0.01; @@ -3373,19 +3373,19 @@ void ff_rfps_calculate(AVFormatContext *ic) for (j= 0; jinfo->codec_info_duration && - st->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) + if (st->internal->info->codec_info_duration && + st->internal->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) continue; - if (!st->info->codec_info_duration && get_std_framerate(j) < 1001*12) + if (!st->internal->info->codec_info_duration && get_std_framerate(j) < 1001*12) continue; - if (av_q2d(st->time_base) * st->info->rfps_duration_sum / st->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) + if (av_q2d(st->time_base) * st->internal->info->rfps_duration_sum / st->internal->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) continue; for (k= 0; k<2; k++) { - int n = st->info->duration_count; - double a= st->info->duration_error[k][0][j] / n; - double error= st->info->duration_error[k][1][j]/n - a*a; + int n = st->internal->info->duration_count; + double a= st->internal->info->duration_error[k][0][j] / n; + double error= st->internal->info->duration_error[k][1][j]/n - a*a; if (error < best_error && best_error> 0.000000001) { best_error= error; @@ -3400,19 +3400,19 @@ void ff_rfps_calculate(AVFormatContext *ic) av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); } if ( !st->avg_frame_rate.num - && st->r_frame_rate.num && st->info->rfps_duration_sum - && st->info->codec_info_duration <= 0 - && st->info->duration_count > 2 - && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - st->info->rfps_duration_sum / (double)st->info->duration_count) <= 1.0 + && st->r_frame_rate.num && st->internal->info->rfps_duration_sum + && st->internal->info->codec_info_duration <= 0 + && st->internal->info->duration_count > 2 + && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - st->internal->info->rfps_duration_sum / (double)st->internal->info->duration_count) <= 1.0 ) { av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); st->avg_frame_rate = st->r_frame_rate; } - av_freep(&st->info->duration_error); - st->info->last_dts = AV_NOPTS_VALUE; - st->info->duration_count = 0; - st->info->rfps_duration_sum = 0; + av_freep(&st->internal->info->duration_error); + st->internal->info->last_dts = AV_NOPTS_VALUE; + st->internal->info->duration_count = 0; + st->internal->info->rfps_duration_sum = 0; } } @@ -3660,10 +3660,10 @@ FF_ENABLE_DEPRECATION_WARNINGS for (i = 0; i < ic->nb_streams; i++) { #if FF_API_R_FRAME_RATE - ic->streams[i]->info->last_dts = AV_NOPTS_VALUE; + ic->streams[i]->internal->info->last_dts = AV_NOPTS_VALUE; #endif - ic->streams[i]->info->fps_first_dts = AV_NOPTS_VALUE; - ic->streams[i]->info->fps_last_dts = AV_NOPTS_VALUE; + ic->streams[i]->internal->info->fps_first_dts = AV_NOPTS_VALUE; + ic->streams[i]->internal->info->fps_last_dts = AV_NOPTS_VALUE; } read_size = 0; @@ -3697,8 +3697,8 @@ FF_ENABLE_DEPRECATION_WARNINGS fps_analyze_framecount = 0; /* variable fps and no guess at the real fps */ count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? - st->info->codec_info_duration_fields/2 : - st->info->duration_count; + st->internal->info->codec_info_duration_fields/2 : + st->internal->info->duration_count; if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (count < fps_analyze_framecount) @@ -3706,7 +3706,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } // Look at the first 3 frames if there is evidence of frame delay // but the decoder delay is not set. - if (st->info->frame_delay_evidence && count < 2 && st->internal->avctx->has_b_frames == 0) + if (st->internal->info->frame_delay_evidence && count < 2 && st->internal->avctx->has_b_frames == 0) break; if (!st->internal->avctx->extradata && (!st->internal->extract_extradata.inited || @@ -3741,7 +3741,7 @@ FF_ENABLE_DEPRECATION_WARNINGS "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); for (i = 0; i < ic->nb_streams; i++) if (!ic->streams[i]->r_frame_rate.num && - ic->streams[i]->info->duration_count <= 1 && + ic->streams[i]->internal->info->duration_count <= 1 && ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && strcmp(ic->iformat->name, "image2")) av_log(ic, AV_LOG_WARNING, @@ -3788,57 +3788,57 @@ FF_ENABLE_DEPRECATION_WARNINGS if (pkt->dts != AV_NOPTS_VALUE && st->codec_info_nb_frames > 1) { /* check for non-increasing dts */ - if (st->info->fps_last_dts != AV_NOPTS_VALUE && - st->info->fps_last_dts >= pkt->dts) { + if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && + st->internal->info->fps_last_dts >= pkt->dts) { av_log(ic, AV_LOG_DEBUG, "Non-increasing DTS in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, st->info->fps_last_dts_idx, - st->info->fps_last_dts, st->codec_info_nb_frames, + st->index, st->internal->info->fps_last_dts_idx, + st->internal->info->fps_last_dts, st->codec_info_nb_frames, pkt->dts); - st->info->fps_first_dts = - st->info->fps_last_dts = AV_NOPTS_VALUE; + st->internal->info->fps_first_dts = + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; } /* Check for a discontinuity in dts. If the difference in dts * is more than 1000 times the average packet duration in the * sequence, we treat it as a discontinuity. */ - if (st->info->fps_last_dts != AV_NOPTS_VALUE && - st->info->fps_last_dts_idx > st->info->fps_first_dts_idx && - (pkt->dts - (uint64_t)st->info->fps_last_dts) / 1000 > - (st->info->fps_last_dts - (uint64_t)st->info->fps_first_dts) / - (st->info->fps_last_dts_idx - st->info->fps_first_dts_idx)) { + if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && + st->internal->info->fps_last_dts_idx > st->internal->info->fps_first_dts_idx && + (pkt->dts - (uint64_t)st->internal->info->fps_last_dts) / 1000 > + (st->internal->info->fps_last_dts - (uint64_t)st->internal->info->fps_first_dts) / + (st->internal->info->fps_last_dts_idx - st->internal->info->fps_first_dts_idx)) { av_log(ic, AV_LOG_WARNING, "DTS discontinuity in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", - st->index, st->info->fps_last_dts_idx, - st->info->fps_last_dts, st->codec_info_nb_frames, + st->index, st->internal->info->fps_last_dts_idx, + st->internal->info->fps_last_dts, st->codec_info_nb_frames, pkt->dts); - st->info->fps_first_dts = - st->info->fps_last_dts = AV_NOPTS_VALUE; + st->internal->info->fps_first_dts = + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; } /* update stored dts values */ - if (st->info->fps_first_dts == AV_NOPTS_VALUE) { - st->info->fps_first_dts = pkt->dts; - st->info->fps_first_dts_idx = st->codec_info_nb_frames; + if (st->internal->info->fps_first_dts == AV_NOPTS_VALUE) { + st->internal->info->fps_first_dts = pkt->dts; + st->internal->info->fps_first_dts_idx = st->codec_info_nb_frames; } - st->info->fps_last_dts = pkt->dts; - st->info->fps_last_dts_idx = st->codec_info_nb_frames; + st->internal->info->fps_last_dts = pkt->dts; + st->internal->info->fps_last_dts_idx = st->codec_info_nb_frames; } if (st->codec_info_nb_frames>1) { int64_t t = 0; int64_t limit; if (st->time_base.den > 0) - t = av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); + t = av_rescale_q(st->internal->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); if (st->avg_frame_rate.num > 0) t = FFMAX(t, av_rescale_q(st->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); if ( t == 0 && st->codec_info_nb_frames>30 - && st->info->fps_first_dts != AV_NOPTS_VALUE - && st->info->fps_last_dts != AV_NOPTS_VALUE) - t = FFMAX(t, av_rescale_q(st->info->fps_last_dts - st->info->fps_first_dts, st->time_base, AV_TIME_BASE_Q)); + && st->internal->info->fps_first_dts != AV_NOPTS_VALUE + && st->internal->info->fps_last_dts != AV_NOPTS_VALUE) + t = FFMAX(t, av_rescale_q(st->internal->info->fps_last_dts - st->internal->info->fps_first_dts, st->time_base, AV_TIME_BASE_Q)); if (analyzed_all_streams) limit = max_analyze_duration; else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; @@ -3854,10 +3854,10 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (pkt->duration) { if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time) { - st->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->info->codec_info_duration + pkt->duration); + st->internal->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->internal->info->codec_info_duration + pkt->duration); } else - st->info->codec_info_duration += pkt->duration; - st->info->codec_info_duration_fields += st->parser && st->need_parsing && avctx->ticks_per_frame ==2 ? st->parser->repeat_pict + 1 : 2; + st->internal->info->codec_info_duration += pkt->duration; + st->internal->info->codec_info_duration_fields += st->parser && st->need_parsing && avctx->ticks_per_frame ==2 ? st->parser->repeat_pict + 1 : 2; } } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -3865,7 +3865,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ff_rfps_add_frame(ic, st, pkt->dts); #endif if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) - st->info->frame_delay_evidence = 1; + st->internal->info->frame_delay_evidence = 1; } if (!st->internal->avctx->extradata) { ret = extract_extradata(st, pkt); @@ -3928,7 +3928,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st = ic->streams[i]; /* flush the decoders */ - if (st->info->found_decoder == 1) { + if (st->internal->info->found_decoder == 1) { do { err = try_decode_frame(ic, st, &empty_pkt, (options && i < orig_nb_streams) @@ -3956,20 +3956,20 @@ FF_ENABLE_DEPRECATION_WARNINGS } /* estimate average framerate if not set by demuxer */ - if (st->info->codec_info_duration_fields && + if (st->internal->info->codec_info_duration_fields && !st->avg_frame_rate.num && - st->info->codec_info_duration) { + st->internal->info->codec_info_duration) { int best_fps = 0; double best_error = 0.01; AVRational codec_frame_rate = avctx->framerate; - if (st->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| - st->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || - st->info->codec_info_duration < 0) + if (st->internal->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| + st->internal->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || + st->internal->info->codec_info_duration < 0) continue; av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, - st->info->codec_info_duration_fields * (int64_t) st->time_base.den, - st->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); + st->internal->info->codec_info_duration_fields * (int64_t) st->time_base.den, + st->internal->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); /* Round guessed framerate to a "standard" framerate if it's * within 1% of the original estimate. */ @@ -4138,10 +4138,10 @@ FF_ENABLE_DEPRECATION_WARNINGS find_stream_info_err: for (i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; - if (st->info) - av_freep(&st->info->duration_error); + if (st->internal->info) + av_freep(&st->internal->info->duration_error); avcodec_close(ic->streams[i]->internal->avctx); - av_freep(&ic->streams[i]->info); + av_freep(&ic->streams[i]->internal->info); av_bsf_free(&ic->streams[i]->internal->extract_extradata.bsf); av_packet_free(&ic->streams[i]->internal->extract_extradata.pkt); } @@ -4343,6 +4343,10 @@ static void free_stream(AVStream **pst) av_freep(&st->internal->priv_pts); av_bsf_free(&st->internal->extract_extradata.bsf); av_packet_free(&st->internal->extract_extradata.pkt); + + if (st->internal->info) + av_freep(&st->internal->info->duration_error); + av_freep(&st->internal->info); } av_freep(&st->internal); @@ -4356,9 +4360,6 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif av_freep(&st->priv_data); - if (st->info) - av_freep(&st->info->duration_error); - av_freep(&st->info); #if FF_API_LAVF_FFSERVER FF_DISABLE_DEPRECATION_WARNINGS av_freep(&st->recommended_encoder_configuration); @@ -4466,17 +4467,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) st = av_mallocz(sizeof(AVStream)); if (!st) return NULL; - if (!(st->info = av_mallocz(sizeof(*st->info)))) { - av_free(st); - return NULL; - } - st->info->last_dts = AV_NOPTS_VALUE; #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS st->codec = avcodec_alloc_context3(c); if (!st->codec) { - av_free(st->info); av_free(st); return NULL; } @@ -4487,6 +4482,11 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!st->internal) goto fail; + st->internal->info = av_mallocz(sizeof(*st->internal->info)); + if (!st->internal->info) + goto fail; + st->internal->info->last_dts = AV_NOPTS_VALUE; + st->codecpar = avcodec_parameters_alloc(); if (!st->codecpar) goto fail; @@ -4530,10 +4530,10 @@ FF_ENABLE_DEPRECATION_WARNINGS st->sample_aspect_ratio = (AVRational) { 0, 1 }; #if FF_API_R_FRAME_RATE - st->info->last_dts = AV_NOPTS_VALUE; + st->internal->info->last_dts = AV_NOPTS_VALUE; #endif - st->info->fps_first_dts = AV_NOPTS_VALUE; - st->info->fps_last_dts = AV_NOPTS_VALUE; + st->internal->info->fps_first_dts = AV_NOPTS_VALUE; + st->internal->info->fps_last_dts = AV_NOPTS_VALUE; st->inject_global_side_data = s->internal->inject_global_side_data; From patchwork Fri Oct 9 13:04:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22785 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A92FC44A971 for ; Fri, 9 Oct 2020 16:06:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8CC4C68B9D2; Fri, 9 Oct 2020 16:06:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B273568B9A9 for ; Fri, 9 Oct 2020 16:06:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id CD0D029625C for ; Fri, 9 Oct 2020 15:06:35 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id SLYUX9rqYnLM for ; Fri, 9 Oct 2020 15:06:35 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 8495629625A for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id F3E5720E0231; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:14 +0200 Message-Id: <20201009130430.602-2-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/18] lavf: move AVStream.{inject_global_side_data, display_aspect_ratio} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 12 ------------ libavformat/internal.h | 12 ++++++++++++ libavformat/mov.c | 4 ++-- libavformat/mxfdec.c | 2 +- libavformat/utils.c | 14 +++++++------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 8eff5b8eaa..c93f9d65a6 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1175,18 +1175,6 @@ typedef struct AVStream { uint8_t dts_ordered; uint8_t dts_misordered; - /** - * Internal data to inject global side data - */ - int inject_global_side_data; - - /** - * display aspect ratio (0 if unknown) - * - encoding: unused - * - decoding: Set by libavformat to calculate sample_aspect_ratio internally - */ - AVRational display_aspect_ratio; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index 30b4df9181..09bab4796d 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -224,6 +224,18 @@ struct AVStreamInternal { int fps_last_dts_idx; } *info; + + /** + * Internal data to inject global side data + */ + int inject_global_side_data; + + /** + * display aspect ratio (0 if unknown) + * - encoding: unused + * - decoding: Set by libavformat to calculate sample_aspect_ratio internally + */ + AVRational display_aspect_ratio; }; #ifdef __GNUC__ diff --git a/libavformat/mov.c b/libavformat/mov.c index 4f64e96bc0..82fd1d74f6 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1767,8 +1767,8 @@ static int mov_read_ares(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; den *= 2; case 1: - c->fc->streams[c->fc->nb_streams-1]->display_aspect_ratio.num = num; - c->fc->streams[c->fc->nb_streams-1]->display_aspect_ratio.den = den; + c->fc->streams[c->fc->nb_streams-1]->internal->display_aspect_ratio.num = num; + c->fc->streams[c->fc->nb_streams-1]->internal->display_aspect_ratio.den = den; default: return 0; } diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index d16a7af0df..1f79f3d3cd 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -2586,7 +2586,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) av_dict_set_int(&st->metadata, "source_track_origin", source_track->sequence->origin, 0); } if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) - st->display_aspect_ratio = descriptor->aspect_ratio; + st->internal->display_aspect_ratio = descriptor->aspect_ratio; st->codecpar->color_range = mxf_get_color_range(mxf, descriptor); st->codecpar->color_primaries = mxf_get_codec_ul(ff_mxf_color_primaries_uls, &descriptor->color_primaries_ul)->id; st->codecpar->color_trc = mxf_get_codec_ul(ff_mxf_color_trc_uls, &descriptor->color_trc_ul)->id; diff --git a/libavformat/utils.c b/libavformat/utils.c index a13f31dccf..625d8d69f3 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -153,7 +153,7 @@ void av_format_inject_global_side_data(AVFormatContext *s) s->internal->inject_global_side_data = 1; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - st->inject_global_side_data = 1; + st->internal->inject_global_side_data = 1; } } @@ -1659,7 +1659,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->skip_samples = 0; } - if (st->inject_global_side_data) { + if (st->internal->inject_global_side_data) { for (i = 0; i < st->nb_side_data; i++) { AVPacketSideData *src_sd = &st->side_data[i]; uint8_t *dst_data; @@ -1675,7 +1675,7 @@ FF_ENABLE_DEPRECATION_WARNINGS memcpy(dst_data, src_sd->data, src_sd->size); } - st->inject_global_side_data = 0; + st->internal->inject_global_side_data = 0; } } @@ -1888,7 +1888,7 @@ void ff_read_frame_flush(AVFormatContext *s) st->pts_buffer[j] = AV_NOPTS_VALUE; if (s->internal->inject_global_side_data) - st->inject_global_side_data = 1; + st->internal->inject_global_side_data = 1; st->skip_samples = 0; } @@ -4007,9 +4007,9 @@ FF_ENABLE_DEPRECATION_WARNINGS st->r_frame_rate.den = st->time_base.num; } } - if (st->display_aspect_ratio.num && st->display_aspect_ratio.den) { + if (st->internal->display_aspect_ratio.num && st->internal->display_aspect_ratio.den) { AVRational hw_ratio = { avctx->height, avctx->width }; - st->sample_aspect_ratio = av_mul_q(st->display_aspect_ratio, + st->sample_aspect_ratio = av_mul_q(st->internal->display_aspect_ratio, hw_ratio); } } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { @@ -4535,7 +4535,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->internal->info->fps_first_dts = AV_NOPTS_VALUE; st->internal->info->fps_last_dts = AV_NOPTS_VALUE; - st->inject_global_side_data = s->internal->inject_global_side_data; + st->internal->inject_global_side_data = s->internal->inject_global_side_data; st->internal->need_context_update = 1; From patchwork Fri Oct 9 13:04:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22783 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6DB1244A971 for ; Fri, 9 Oct 2020 16:06:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5458568B9CD; Fri, 9 Oct 2020 16:06:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D36568B9B5 for ; Fri, 9 Oct 2020 16:06:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id D08FF296256 for ; Fri, 9 Oct 2020 15:06:33 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id T4lOWGiElEw4 for ; Fri, 9 Oct 2020 15:06:33 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 3799E296253 for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id B030F20E00BF; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:15 +0200 Message-Id: <20201009130430.602-3-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/18] lavf: move AVStream.{last_dts_for_order_check, dts_[mis]ordered} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 7 ------- libavformat/internal.h | 7 +++++++ libavformat/utils.c | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index c93f9d65a6..7da67d961d 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1168,13 +1168,6 @@ typedef struct AVStream { int64_t pts_reorder_error[MAX_REORDER_DELAY+1]; uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]; - /** - * Internal data to analyze DTS and detect faulty mpeg streams - */ - int64_t last_dts_for_order_check; - uint8_t dts_ordered; - uint8_t dts_misordered; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index 09bab4796d..c9eca1babb 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,13 @@ struct AVStreamInternal { } *info; + /** + * Internal data to analyze DTS and detect faulty mpeg streams + */ + int64_t last_dts_for_order_check; + uint8_t dts_ordered; + uint8_t dts_misordered; + /** * Internal data to inject global side data */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 625d8d69f3..04f2b24b72 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1210,24 +1210,24 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, return; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { - if (pkt->dts == pkt->pts && st->last_dts_for_order_check != AV_NOPTS_VALUE) { - if (st->last_dts_for_order_check <= pkt->dts) { - st->dts_ordered++; + if (pkt->dts == pkt->pts && st->internal->last_dts_for_order_check != AV_NOPTS_VALUE) { + if (st->internal->last_dts_for_order_check <= pkt->dts) { + st->internal->dts_ordered++; } else { - av_log(s, st->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, + av_log(s, st->internal->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, "DTS %"PRIi64" < %"PRIi64" out of order\n", pkt->dts, - st->last_dts_for_order_check); - st->dts_misordered++; + st->internal->last_dts_for_order_check); + st->internal->dts_misordered++; } - if (st->dts_ordered + st->dts_misordered > 250) { - st->dts_ordered >>= 1; - st->dts_misordered >>= 1; + if (st->internal->dts_ordered + st->internal->dts_misordered > 250) { + st->internal->dts_ordered >>= 1; + st->internal->dts_misordered >>= 1; } } - st->last_dts_for_order_check = pkt->dts; - if (st->dts_ordered < 8*st->dts_misordered && pkt->dts == pkt->pts) + st->internal->last_dts_for_order_check = pkt->dts; + if (st->internal->dts_ordered < 8*st->internal->dts_misordered && pkt->dts == pkt->pts) pkt->dts = AV_NOPTS_VALUE; } @@ -1875,7 +1875,7 @@ void ff_read_frame_flush(AVFormatContext *s) st->parser = NULL; } st->last_IP_pts = AV_NOPTS_VALUE; - st->last_dts_for_order_check = AV_NOPTS_VALUE; + st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; if (st->first_dts == AV_NOPTS_VALUE) st->cur_dts = RELATIVE_TS_BASE; else @@ -2864,7 +2864,7 @@ skip_duration_calc: st = ic->streams[i]; st->cur_dts = st->first_dts; st->last_IP_pts = AV_NOPTS_VALUE; - st->last_dts_for_order_check = AV_NOPTS_VALUE; + st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) st->pts_buffer[j] = AV_NOPTS_VALUE; } @@ -4523,7 +4523,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; st->last_IP_pts = AV_NOPTS_VALUE; - st->last_dts_for_order_check = AV_NOPTS_VALUE; + st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (i = 0; i < MAX_REORDER_DELAY + 1; i++) st->pts_buffer[i] = AV_NOPTS_VALUE; From patchwork Fri Oct 9 13:04:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22780 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5444D44A971 for ; Fri, 9 Oct 2020 16:06:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B47968B9B2; Fri, 9 Oct 2020 16:06:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6340B68B683 for ; Fri, 9 Oct 2020 16:06:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id D9989296258 for ; Fri, 9 Oct 2020 15:06:32 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id fGKcBkeKbwLg for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 61C36296256 for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 88CE020E00C0; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:16 +0200 Message-Id: <20201009130430.602-4-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/18] lavf: move AVStream.pts_reorder_error[_count] to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 6 ------ libavformat/internal.h | 6 ++++++ libavformat/utils.c | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7da67d961d..3d7fe4aadf 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1162,12 +1162,6 @@ typedef struct AVStream { */ int update_initial_durations_done; - /** - * Internal data to generate dts from pts - */ - int64_t pts_reorder_error[MAX_REORDER_DELAY+1]; - uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index c9eca1babb..95cb5b5d60 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,12 @@ struct AVStreamInternal { } *info; + /** + * Internal data to generate dts from pts + */ + int64_t pts_reorder_error[MAX_REORDER_DELAY+1]; + uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]; + /** * Internal data to analyze DTS and detect faulty mpeg streams */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 04f2b24b72..3c4d13e1c1 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1027,8 +1027,8 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t if (dts == AV_NOPTS_VALUE) { int64_t best_score = INT64_MAX; for (i = 0; ipts_reorder_error_count[i]) { - int64_t score = st->pts_reorder_error[i] / st->pts_reorder_error_count[i]; + if (st->internal->pts_reorder_error_count[i]) { + int64_t score = st->internal->pts_reorder_error[i] / st->internal->pts_reorder_error_count[i]; if (score < best_score) { best_score = score; dts = pts_buffer[i]; @@ -1039,13 +1039,13 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t for (i = 0; ipts_reorder_error[i]; - diff = FFMAX(diff, st->pts_reorder_error[i]); - st->pts_reorder_error[i] = diff; - st->pts_reorder_error_count[i]++; - if (st->pts_reorder_error_count[i] > 250) { - st->pts_reorder_error[i] >>= 1; - st->pts_reorder_error_count[i] >>= 1; + + (uint64_t)st->internal->pts_reorder_error[i]; + diff = FFMAX(diff, st->internal->pts_reorder_error[i]); + st->internal->pts_reorder_error[i] = diff; + st->internal->pts_reorder_error_count[i]++; + if (st->internal->pts_reorder_error_count[i] > 250) { + st->internal->pts_reorder_error[i] >>= 1; + st->internal->pts_reorder_error_count[i] >>= 1; } } } From patchwork Fri Oct 9 13:04:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22782 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6B17944A971 for ; Fri, 9 Oct 2020 16:06:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5535168B9C6; Fri, 9 Oct 2020 16:06:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CB09868B683 for ; Fri, 9 Oct 2020 16:06:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 64D57296255 for ; Fri, 9 Oct 2020 15:06:33 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id nefSZQsoWl7z for ; Fri, 9 Oct 2020 15:06:33 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 3898D296254 for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 6A3CA20E0039; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:17 +0200 Message-Id: <20201009130430.602-5-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/18] lavf: move AVStream.{pts_wrap_*, update_initial_durations_done} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 22 ---------------------- libavformat/internal.h | 22 ++++++++++++++++++++++ libavformat/mpegts.c | 4 ++-- libavformat/utils.c | 38 +++++++++++++++++++------------------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 3d7fe4aadf..7383d0b6e5 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1140,28 +1140,6 @@ typedef struct AVStream { */ int64_t mux_ts_offset; - /** - * Internal data to check for wrapping of the time stamp - */ - int64_t pts_wrap_reference; - - /** - * Options for behavior, when a wrap is detected. - * - * Defined by AV_PTS_WRAP_ values. - * - * If correction is enabled, there are two possibilities: - * If the first time stamp is near the wrap point, the wrap offset - * will be subtracted, which will create negative time stamps. - * Otherwise the offset will be added. - */ - int pts_wrap_behavior; - - /** - * Internal data to prevent doing update_initial_durations() twice - */ - int update_initial_durations_done; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index 95cb5b5d60..efa5a8b238 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,28 @@ struct AVStreamInternal { } *info; + /** + * Internal data to check for wrapping of the time stamp + */ + int64_t pts_wrap_reference; + + /** + * Options for behavior, when a wrap is detected. + * + * Defined by AV_PTS_WRAP_ values. + * + * If correction is enabled, there are two possibilities: + * If the first time stamp is near the wrap point, the wrap offset + * will be subtracted, which will create negative time stamps. + * Otherwise the offset will be added. + */ + int pts_wrap_behavior; + + /** + * Internal data to prevent doing update_initial_durations() twice + */ + int update_initial_durations_done; + /** * Internal data to generate dts from pts */ diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 50d4d5e9bc..b1b65d3887 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1325,8 +1325,8 @@ skip: int64_t pcr = f->last_pcr / 300; pcr_found = 1; if (st) { - pes->st->pts_wrap_reference = st->pts_wrap_reference; - pes->st->pts_wrap_behavior = st->pts_wrap_behavior; + pes->st->internal->pts_wrap_reference = st->internal->pts_wrap_reference; + pes->st->internal->pts_wrap_behavior = st->internal->pts_wrap_behavior; } if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) { pes->pts = pes->dts = pcr; diff --git a/libavformat/utils.c b/libavformat/utils.c index 3c4d13e1c1..e3f909a252 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -101,13 +101,13 @@ static int is_relative(int64_t ts) { */ static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) { - if (st->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && - st->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { - if (st->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && - timestamp < st->pts_wrap_reference) + if (st->internal->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && + st->internal->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { + if (st->internal->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && + timestamp < st->internal->pts_wrap_reference) return timestamp + (1ULL << st->pts_wrap_bits); - else if (st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && - timestamp >= st->pts_wrap_reference) + else if (st->internal->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && + timestamp >= st->internal->pts_wrap_reference) return timestamp - (1ULL << st->pts_wrap_bits); } return timestamp; @@ -732,7 +732,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (ref == AV_NOPTS_VALUE) ref = pkt->pts; - if (st->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) + if (st->internal->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) return 0; ref &= (1LL << st->pts_wrap_bits)-1; @@ -747,17 +747,17 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (!first_program) { int default_stream_index = av_find_default_stream_index(s); - if (s->streams[default_stream_index]->pts_wrap_reference == AV_NOPTS_VALUE) { + if (s->streams[default_stream_index]->internal->pts_wrap_reference == AV_NOPTS_VALUE) { for (i = 0; i < s->nb_streams; i++) { if (av_find_program_from_stream(s, NULL, i)) continue; - s->streams[i]->pts_wrap_reference = pts_wrap_reference; - s->streams[i]->pts_wrap_behavior = pts_wrap_behavior; + s->streams[i]->internal->pts_wrap_reference = pts_wrap_reference; + s->streams[i]->internal->pts_wrap_behavior = pts_wrap_behavior; } } else { - st->pts_wrap_reference = s->streams[default_stream_index]->pts_wrap_reference; - st->pts_wrap_behavior = s->streams[default_stream_index]->pts_wrap_behavior; + st->internal->pts_wrap_reference = s->streams[default_stream_index]->internal->pts_wrap_reference; + st->internal->pts_wrap_behavior = s->streams[default_stream_index]->internal->pts_wrap_behavior; } } else { @@ -776,8 +776,8 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in while (program) { if (program->pts_wrap_reference != pts_wrap_reference) { for (i = 0; inb_stream_indexes; i++) { - s->streams[program->stream_index[i]]->pts_wrap_reference = pts_wrap_reference; - s->streams[program->stream_index[i]]->pts_wrap_behavior = pts_wrap_behavior; + s->streams[program->stream_index[i]]->internal->pts_wrap_reference = pts_wrap_reference; + s->streams[program->stream_index[i]]->internal->pts_wrap_behavior = pts_wrap_behavior; } program->pts_wrap_reference = pts_wrap_reference; @@ -859,7 +859,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) st = s->streams[pkt->stream_index]; - if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { + if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->internal->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { // correct first time stamps to negative values if (!is_relative(st->first_dts)) st->first_dts = wrap_timestamp(st, st->first_dts); @@ -1147,9 +1147,9 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, int64_t cur_dts = RELATIVE_TS_BASE; if (st->first_dts != AV_NOPTS_VALUE) { - if (st->update_initial_durations_done) + if (st->internal->update_initial_durations_done) return; - st->update_initial_durations_done = 1; + st->internal->update_initial_durations_done = 1; cur_dts = st->first_dts; for (; pktl; pktl = get_next_pkt(s, st, pktl)) { if (pktl->pkt.stream_index == stream_index) { @@ -4519,8 +4519,8 @@ FF_ENABLE_DEPRECATION_WARNINGS st->duration = AV_NOPTS_VALUE; st->first_dts = AV_NOPTS_VALUE; st->probe_packets = s->max_probe_packets; - st->pts_wrap_reference = AV_NOPTS_VALUE; - st->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; + st->internal->pts_wrap_reference = AV_NOPTS_VALUE; + st->internal->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; st->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; From patchwork Fri Oct 9 13:04:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22781 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7C2C044A971 for ; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6653F68B9C0; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 696DE68B9A6 for ; Fri, 9 Oct 2020 16:06:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id D7ED6296257 for ; Fri, 9 Oct 2020 15:06:32 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id DcymTBgnJt3b for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 39A2F296255 for ; Fri, 9 Oct 2020 15:06:30 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id D290320E00BD; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:18 +0200 Message-Id: <20201009130430.602-6-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/18] lavf: move AVStream.{nb_decoded_frames, mux_ts_offset} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 11 ----------- libavformat/internal.h | 11 +++++++++++ libavformat/mux.c | 6 +++--- libavformat/utils.c | 10 +++++----- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7383d0b6e5..977680ec83 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1129,17 +1129,6 @@ typedef struct AVStream { */ int64_t last_discard_sample; - /** - * Number of internally decoded frames, used internally in libavformat, do not access - * its lifetime differs from info which is why it is not in that structure. - */ - int nb_decoded_frames; - - /** - * Timestamp offset added to timestamps before muxing - */ - int64_t mux_ts_offset; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index efa5a8b238..b1112fe463 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,17 @@ struct AVStreamInternal { } *info; + /** + * Number of internally decoded frames, used internally in libavformat, do not access + * its lifetime differs from info which is why it is not in that structure. + */ + int nb_decoded_frames; + + /** + * Timestamp offset added to timestamps before muxing + */ + int64_t mux_ts_offset; + /** * Internal data to check for wrapping of the time stamp */ diff --git a/libavformat/mux.c b/libavformat/mux.c index 44d5e5d1c0..8a2d6370f6 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -678,7 +678,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (s->avoid_negative_ts > 0) { AVStream *st = s->streams[pkt->stream_index]; - int64_t offset = st->mux_ts_offset; + int64_t offset = st->internal->mux_ts_offset; int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && @@ -688,7 +688,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (s->internal->offset != AV_NOPTS_VALUE && !offset) { - offset = st->mux_ts_offset = + offset = st->internal->mux_ts_offset = av_rescale_q_rnd(s->internal->offset, s->internal->offset_timebase, st->time_base, @@ -1038,7 +1038,7 @@ int ff_interleaved_peek(AVFormatContext *s, int stream, *pkt = pktl->pkt; if (add_offset) { AVStream *st = s->streams[pkt->stream_index]; - int64_t offset = st->mux_ts_offset; + int64_t offset = st->internal->mux_ts_offset; if (s->output_ts_offset) offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); diff --git a/libavformat/utils.c b/libavformat/utils.c index e3f909a252..ae7e91171e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1000,11 +1000,11 @@ static int has_decode_delay_been_guessed(AVStream *st) return 1; #endif if (st->internal->avctx->has_b_frames<3) - return st->nb_decoded_frames >= 7; + return st->internal->nb_decoded_frames >= 7; else if (st->internal->avctx->has_b_frames<4) - return st->nb_decoded_frames >= 18; + return st->internal->nb_decoded_frames >= 18; else - return st->nb_decoded_frames >= 20; + return st->internal->nb_decoded_frames >= 20; } static AVPacketList *get_next_pkt(AVFormatContext *s, AVStream *st, AVPacketList *pktl) @@ -2959,7 +2959,7 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) FAIL("unspecified sample rate"); if (!avctx->channels) FAIL("unspecified number of channels"); - if (st->internal->info->found_decoder >= 0 && !st->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) + if (st->internal->info->found_decoder >= 0 && !st->internal->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) FAIL("no decodable DTS frames"); break; case AVMEDIA_TYPE_VIDEO: @@ -3066,7 +3066,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, } if (ret >= 0) { if (got_picture) - st->nb_decoded_frames++; + st->internal->nb_decoded_frames++; ret = got_picture; } } From patchwork Fri Oct 9 13:04:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22793 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 967B744AB2F for ; Fri, 9 Oct 2020 16:09:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F4A168BA0D; Fri, 9 Oct 2020 16:06:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2CC768B9D9 for ; Fri, 9 Oct 2020 16:06:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id BA9B829625D for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rankwlRenf_v for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 8648929625B for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 37EA720E0235; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:19 +0200 Message-Id: <20201009130430.602-7-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/18] lavf: move AVStream.{*skip_samples.*_discard_sample} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 29 ----------------------------- libavformat/internal.h | 29 +++++++++++++++++++++++++++++ libavformat/mov.c | 12 ++++++------ libavformat/mp3dec.c | 8 ++++---- libavformat/swfdec.c | 2 +- libavformat/utils.c | 26 +++++++++++++------------- 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 977680ec83..8028b1b558 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1100,35 +1100,6 @@ typedef struct AVStream { */ int skip_to_keyframe; - /** - * Number of samples to skip at the start of the frame decoded from the next packet. - */ - int skip_samples; - - /** - * If not 0, the number of samples that should be skipped from the start of - * the stream (the samples are removed from packets with pts==0, which also - * assumes negative timestamps do not happen). - * Intended for use with formats such as mp3 with ad-hoc gapless audio - * support. - */ - int64_t start_skip_samples; - - /** - * If not 0, the first audio sample that should be discarded from the stream. - * This is broken by design (needs global sample count), but can't be - * avoided for broken by design formats such as mp3 with ad-hoc gapless - * audio support. - */ - int64_t first_discard_sample; - - /** - * The sample after last sample that is intended to be discarded after - * first_discard_sample. Works on frame boundaries only. Used to prevent - * early EOF if the gapless info is broken (considered concatenated mp3s). - */ - int64_t last_discard_sample; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index b1112fe463..12105aa7d0 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,35 @@ struct AVStreamInternal { } *info; + /** + * Number of samples to skip at the start of the frame decoded from the next packet. + */ + int skip_samples; + + /** + * If not 0, the number of samples that should be skipped from the start of + * the stream (the samples are removed from packets with pts==0, which also + * assumes negative timestamps do not happen). + * Intended for use with formats such as mp3 with ad-hoc gapless audio + * support. + */ + int64_t start_skip_samples; + + /** + * If not 0, the first audio sample that should be discarded from the stream. + * This is broken by design (needs global sample count), but can't be + * avoided for broken by design formats such as mp3 with ad-hoc gapless + * audio support. + */ + int64_t first_discard_sample; + + /** + * The sample after last sample that is intended to be discarded after + * first_discard_sample. Works on frame boundaries only. Used to prevent + * early EOF if the gapless info is broken (considered concatenated mp3s). + */ + int64_t last_discard_sample; + /** * Number of internally decoded frames, used internally in libavformat, do not access * its lifetime differs from info which is why it is not in that structure. diff --git a/libavformat/mov.c b/libavformat/mov.c index 82fd1d74f6..6103678cdb 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3550,7 +3550,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } if (first_non_zero_audio_edit > 0) - st->skip_samples = msc->start_pad = 0; + st->internal->skip_samples = msc->start_pad = 0; } // While reordering frame index according to edit list we must handle properly @@ -3625,7 +3625,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) curr_cts < edit_list_media_time && curr_cts + frame_duration > edit_list_media_time && first_non_zero_audio_edit > 0) { packet_skip_samples = edit_list_media_time - curr_cts; - st->skip_samples += packet_skip_samples; + st->internal->skip_samples += packet_skip_samples; // Shift the index entry timestamp by packet_skip_samples to be correct. edit_list_dts_counter -= packet_skip_samples; @@ -3658,7 +3658,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Increment skip_samples for the first non-zero audio edit list if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && first_non_zero_audio_edit > 0 && st->codecpar->codec_id != AV_CODEC_ID_VORBIS) { - st->skip_samples += frame_duration; + st->internal->skip_samples += frame_duration; } } } @@ -3744,7 +3744,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Update av stream length, if it ends up shorter than the track's media duration st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts); - msc->start_pad = st->skip_samples; + msc->start_pad = st->internal->skip_samples; // Free the old index and the old CTTS structures av_free(e_old); @@ -7615,7 +7615,7 @@ static int mov_read_header(AVFormatContext *s) fix_timescale(mov, sc); if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id == AV_CODEC_ID_AAC) { - st->skip_samples = sc->start_pad; + st->internal->skip_samples = sc->start_pad; } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sc->nb_frames_for_fps > 0 && sc->duration_for_fps > 0) av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, @@ -8104,7 +8104,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti int64_t timestamp; MOVStreamContext *sc = s->streams[i]->priv_data; st = s->streams[i]; - st->skip_samples = (sample_time <= 0) ? sc->start_pad : 0; + st->internal->skip_samples = (sample_time <= 0) ? sc->start_pad : 0; if (stream_index == i) continue; diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index b044679c02..5e7f273c6a 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -255,13 +255,13 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; - st->start_skip_samples = mp3->start_pad + 528 + 1; + st->internal->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { - st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; - st->last_discard_sample = mp3->frames * (int64_t)spf; + st->internal->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; + st->internal->last_discard_sample = mp3->frames * (int64_t)spf; } if (!st->start_time) - st->start_time = av_rescale_q(st->start_skip_samples, + st->start_time = av_rescale_q(st->internal->start_skip_samples, (AVRational){1, c->sample_rate}, st->time_base); av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3-> end_pad); diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index 2769a768de..fa11c050cd 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -292,7 +292,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(ENOMEM); ast->duration = avio_rl32(pb); // number of samples if (((v>>4) & 15) == 2) { // MP3 sound data record - ast->skip_samples = avio_rl16(pb); + ast->internal->skip_samples = avio_rl16(pb); len -= 2; } len -= 7; diff --git a/libavformat/utils.c b/libavformat/utils.c index ae7e91171e..9fd79ee540 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1123,7 +1123,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { st->start_time = pktl_it->pkt.pts; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->internal->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); } } @@ -1136,7 +1136,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, st->start_time = pts; } if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) - st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); + st->start_time = av_sat_add64(st->start_time, av_rescale_q(st->internal->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); } } @@ -1638,25 +1638,25 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; int discard_padding = 0; - if (st->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { + if (st->internal->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); int64_t sample = ts_to_samples(st, pts); int duration = ts_to_samples(st, pkt->duration); int64_t end_sample = sample + duration; - if (duration > 0 && end_sample >= st->first_discard_sample && - sample < st->last_discard_sample) - discard_padding = FFMIN(end_sample - st->first_discard_sample, duration); + if (duration > 0 && end_sample >= st->internal->first_discard_sample && + sample < st->internal->last_discard_sample) + discard_padding = FFMIN(end_sample - st->internal->first_discard_sample, duration); } - if (st->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) - st->skip_samples = st->start_skip_samples; - if (st->skip_samples || discard_padding) { + if (st->internal->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) + st->internal->skip_samples = st->internal->start_skip_samples; + if (st->internal->skip_samples || discard_padding) { uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if (p) { - AV_WL32(p, st->skip_samples); + AV_WL32(p, st->internal->skip_samples); AV_WL32(p + 4, discard_padding); - av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", st->skip_samples, discard_padding); + av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d / discard %d\n", st->internal->skip_samples, discard_padding); } - st->skip_samples = 0; + st->internal->skip_samples = 0; } if (st->internal->inject_global_side_data) { @@ -1890,7 +1890,7 @@ void ff_read_frame_flush(AVFormatContext *s) if (s->internal->inject_global_side_data) st->internal->inject_global_side_data = 1; - st->skip_samples = 0; + st->internal->skip_samples = 0; } } From patchwork Fri Oct 9 13:04:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22796 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 14997449017 for ; Fri, 9 Oct 2020 16:10:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D03C68B9E0; Fri, 9 Oct 2020 16:06:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 466AC68B9B6 for ; Fri, 9 Oct 2020 16:06:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 730EC29625F for ; Fri, 9 Oct 2020 15:06:35 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pl1cfOqoDQQY for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 86C1D29625C for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 5398120E0232; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:20 +0200 Message-Id: <20201009130430.602-8-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/18] lavf: move AVStream.{request_probe, skip_to_keyframe} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/asfdec_f.c | 2 +- libavformat/avformat.h | 13 ------------- libavformat/avidec.c | 2 +- libavformat/internal.h | 13 +++++++++++++ libavformat/matroskadec.c | 8 ++++---- libavformat/mpeg.c | 2 +- libavformat/mpegts.c | 26 +++++++++++++------------- libavformat/utils.c | 24 ++++++++++++------------ libavformat/wavdec.c | 2 +- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index 103155e9e7..b92434db9e 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -479,7 +479,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) if (is_dvr_ms_audio) { // codec_id and codec_tag are unreliable in dvr_ms // files. Set them later by probing stream. - st->request_probe = 1; + st->internal->request_probe = 1; st->codecpar->codec_tag = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_AAC) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 8028b1b558..ed0ed0d3e1 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1087,19 +1087,6 @@ typedef struct AVStream { int64_t interleaver_chunk_size; int64_t interleaver_chunk_duration; - /** - * stream probing state - * -1 -> probing finished - * 0 -> no probing requested - * rest -> perform probing with request_probe being the minimum score to accept. - */ - int request_probe; - /** - * Indicates that everything up to the next keyframe - * should be discarded. - */ - int skip_to_keyframe; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 9765e5e7b2..89a9443821 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -901,7 +901,7 @@ static int avi_read_header(AVFormatContext *s) break; case AVMEDIA_TYPE_SUBTITLE: st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->request_probe= 1; + st->internal->request_probe= 1; avio_skip(pb, size); break; default: diff --git a/libavformat/internal.h b/libavformat/internal.h index 12105aa7d0..d8ceebb26e 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,19 @@ struct AVStreamInternal { } *info; + /** + * stream probing state + * -1 -> probing finished + * 0 -> no probing requested + * rest -> perform probing with request_probe being the minimum score to accept. + */ + int request_probe; + /** + * Indicates that everything up to the next keyframe + * should be discarded. + */ + int skip_to_keyframe; + /** * Number of samples to skip at the start of the frame decoded from the next packet. */ diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 545559423c..a183026359 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3597,7 +3597,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf return res; if (is_keyframe) matroska->skip_to_keyframe = 0; - else if (!st->skip_to_keyframe) { + else if (!st->internal->skip_to_keyframe) { av_log(matroska->ctx, AV_LOG_ERROR, "File is broken, keyframes not correctly marked!\n"); matroska->skip_to_keyframe = 0; } @@ -3794,10 +3794,10 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, /* We seek to a level 1 element, so set the appropriate status. */ matroska_reset_status(matroska, 0, st->index_entries[index].pos); if (flags & AVSEEK_FLAG_ANY) { - st->skip_to_keyframe = 0; + st->internal->skip_to_keyframe = 0; matroska->skip_to_timecode = timestamp; } else { - st->skip_to_keyframe = 1; + st->internal->skip_to_keyframe = 1; matroska->skip_to_timecode = st->index_entries[index].timestamp; } matroska->skip_to_keyframe = 1; @@ -3810,7 +3810,7 @@ err: matroska_reset_status(matroska, 0, -1); matroska->resync_pos = -1; matroska_clear_queue(matroska); - st->skip_to_keyframe = + st->internal->skip_to_keyframe = matroska->skip_to_keyframe = 0; matroska->done = 0; return -1; diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index a5e17925ce..20d1e10168 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -622,7 +622,7 @@ skip: st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; st->codecpar->sample_rate = 8000; } - st->request_probe = request_probe; + st->internal->request_probe = request_probe; st->need_parsing = AVSTREAM_PARSE_FULL; found: diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b1b65d3887..7cf14a1d13 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -882,7 +882,7 @@ static void mpegts_find_stream_type(AVStream *st, st->codecpar->codec_id = types->codec_id; st->internal->need_context_update = 1; } - st->request_probe = 0; + st->internal->request_probe = 0; return; } } @@ -915,7 +915,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, mpegts_find_stream_type(st, pes->stream_type, ISO_types); if (pes->stream_type == 4 || pes->stream_type == 0x0f) - st->request_probe = 50; + st->internal->request_probe = 50; if ((prog_reg_desc == AV_RL32("HDMV") || prog_reg_desc == AV_RL32("HDPR")) && st->codecpar->codec_id == AV_CODEC_ID_NONE) { @@ -952,12 +952,12 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, st->codecpar->codec_type = old_codec_type; } if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || - (st->request_probe > 0 && st->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && + (st->internal->request_probe > 0 && st->internal->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && st->probe_packets > 0 && stream_type == STREAM_TYPE_PRIVATE_DATA) { st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; - st->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; + st->internal->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; } /* queue a context update if properties changed */ @@ -1198,12 +1198,12 @@ static int mpegts_push_data(MpegTSFilter *filter, code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ pes->state = MPEGTS_PESHEADER; - if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) { + if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes->st->internal->request_probe) { av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_type=%x probing\n", pes->pid, pes->stream_type); - pes->st->request_probe = 1; + pes->st->internal->request_probe = 1; } } else { pes->pes_header_size = 6; @@ -1799,7 +1799,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type av_log(fc, AV_LOG_TRACE, "tag: 0x%02x len=%d\n", desc_tag, desc_len); - if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) && + if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || st->internal->request_probe > 0) && stream_type == STREAM_TYPE_PRIVATE_DATA) mpegts_find_stream_type(st, desc_tag, DESC_types); @@ -1837,8 +1837,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type break; if (mp4_descr_count > 0 && (st->codecpar->codec_id == AV_CODEC_ID_AAC_LATM || - (st->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || - st->request_probe > 0) && + (st->internal->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || + st->internal->request_probe > 0) && mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) { AVIOContext pb; ffio_init_context(&pb, mp4_descr->dec_config_descr, @@ -1847,7 +1847,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type ff_mp4_read_dec_config_descr(fc, st, &pb); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { - st->request_probe = st->need_parsing = 0; + st->internal->request_probe = st->need_parsing = 0; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->internal->need_context_update = 1; } @@ -1987,10 +1987,10 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type case 0x05: /* registration descriptor */ st->codecpar->codec_tag = bytestream_get_le32(pp); av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codecpar->codec_tag); - if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->internal->request_probe > 0) { mpegts_find_stream_type(st, st->codecpar->codec_tag, REGD_types); if (st->codecpar->codec_tag == MKTAG('B', 'S', 'S', 'D')) - st->request_probe = 50; + st->internal->request_probe = 50; } break; case 0x52: /* stream identifier descriptor */ @@ -2143,7 +2143,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_ARIB_CAPTION; st->codecpar->profile = picked_profile; - st->request_probe = 0; + st->internal->request_probe = 0; } break; case 0xb0: /* DOVI video stream descriptor */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 9fd79ee540..acb9bd1cee 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -365,7 +365,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) continue; - if (st->request_probe > score && + if (st->internal->request_probe > score && st->codecpar->codec_id != fmt_id_type[i].id) continue; st->codecpar->codec_id = fmt_id_type[i].id; @@ -675,7 +675,7 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { - if (st->request_probe>0) { + if (st->internal->request_probe>0) { AVProbeData *pd = &st->probe_data; int end; av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets); @@ -711,7 +711,7 @@ no_packet: || end) { pd->buf_size = 0; av_freep(&pd->buf); - st->request_probe = -1; + st->internal->request_probe = -1; if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); } else @@ -807,7 +807,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (s->internal->raw_packet_buffer_remaining_size <= 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; - if (st->request_probe <= 0) { + if (st->internal->request_probe <= 0) { avpriv_packet_list_get(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, pkt); s->internal->raw_packet_buffer_remaining_size += pkt->size; @@ -828,10 +828,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->probe_packets || st->request_probe > 0) + if (st->probe_packets || st->internal->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; - av_assert0(st->request_probe <= 0); + av_assert0(st->internal->request_probe <= 0); } continue; } @@ -878,7 +878,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (s->use_wallclock_as_timestamps) pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); - if (!pktl && st->request_probe <= 0) + if (!pktl && st->internal->request_probe <= 0) return ret; err = avpriv_packet_list_put(&s->internal->raw_packet_buffer, @@ -1625,8 +1625,8 @@ FF_ENABLE_DEPRECATION_WARNINGS av_packet_unref(pkt); } if (pkt->flags & AV_PKT_FLAG_KEY) - st->skip_to_keyframe = 0; - if (st->skip_to_keyframe) { + st->internal->skip_to_keyframe = 0; + if (st->internal->skip_to_keyframe) { av_packet_unref(pkt); got_packet = 0; } @@ -3606,7 +3606,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif // only for the split stuff - if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->request_probe <= 0) { + if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->internal->request_probe <= 0) { st->parser = av_parser_init(st->codecpar->codec_id); if (st->parser) { if (st->need_parsing == AVSTREAM_PARSE_HEADERS) { @@ -3627,7 +3627,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ret = avcodec_parameters_to_context(avctx, st->codecpar); if (ret < 0) goto find_stream_info_err; - if (st->request_probe <= 0) + if (st->internal->request_probe <= 0) st->internal->avctx_inited = 1; codec = find_probe_decoder(ic, st, st->codecpar->codec_id); @@ -3648,7 +3648,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } // Try to just open decoders, in case this is enough to get parameters. - if (!has_codec_parameters(st, NULL) && st->request_probe <= 0) { + if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0) { if (codec && !avctx->codec) if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) av_log(ic, AV_LOG_WARNING, diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index d6ab0dde35..bca186a66f 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -154,7 +154,7 @@ static int wav_probe(const AVProbeData *p) static void handle_stream_probing(AVStream *st) { if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { - st->request_probe = AVPROBE_SCORE_EXTENSION; + st->internal->request_probe = AVPROBE_SCORE_EXTENSION; st->probe_packets = FFMIN(st->probe_packets, 32); } } From patchwork Fri Oct 9 13:04:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22784 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9B73144A971 for ; Fri, 9 Oct 2020 16:06:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 851FC68B9D3; Fri, 9 Oct 2020 16:06:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA67968B9B7 for ; Fri, 9 Oct 2020 16:06:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 47528296253 for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id G78wBNpN0sVS for ; Fri, 9 Oct 2020 15:06:33 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 9756F29625F for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 8220120E0236; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:21 +0200 Message-Id: <20201009130430.602-9-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/18] lavf: move AVStream.interleaver_chunk_* to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 3 --- libavformat/internal.h | 3 +++ libavformat/mux.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index ed0ed0d3e1..1253021452 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1084,9 +1084,6 @@ typedef struct AVStream { int pmt_version; int pmt_stream_idx; - int64_t interleaver_chunk_size; - int64_t interleaver_chunk_duration; - /** * An opaque field for libavformat internal usage. * Must not be accessed in any way by callers. diff --git a/libavformat/internal.h b/libavformat/internal.h index d8ceebb26e..87d62c51b2 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,9 @@ struct AVStreamInternal { } *info; + int64_t interleaver_chunk_size; + int64_t interleaver_chunk_duration; + /** * stream probing state * -1 -> probing finished diff --git a/libavformat/mux.c b/libavformat/mux.c index 8a2d6370f6..8a53f0feeb 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -839,19 +839,19 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (chunked) { uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP); - st->interleaver_chunk_size += pkt->size; - st->interleaver_chunk_duration += pkt->duration; - if ( (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size) - || (max && st->interleaver_chunk_duration > max)) { - st->interleaver_chunk_size = 0; + st->internal->interleaver_chunk_size += pkt->size; + st->internal->interleaver_chunk_duration += pkt->duration; + if ( (s->max_chunk_size && st->internal->interleaver_chunk_size > s->max_chunk_size) + || (max && st->internal->interleaver_chunk_duration > max)) { + st->internal->interleaver_chunk_size = 0; pkt->flags |= CHUNK_START; - if (max && st->interleaver_chunk_duration > max) { + if (max && st->internal->interleaver_chunk_duration > max) { int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2; int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset; - st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; + st->internal->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; } else - st->interleaver_chunk_duration = 0; + st->internal->interleaver_chunk_duration = 0; } } if (*next_point) { From patchwork Fri Oct 9 13:04:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22791 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EDED244A971 for ; Fri, 9 Oct 2020 16:06:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D599468B9FF; Fri, 9 Oct 2020 16:06:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36B6468B9C2 for ; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id E3D42296260 for ; Fri, 9 Oct 2020 15:06:36 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id JaZj8g60cPAE for ; Fri, 9 Oct 2020 15:06:35 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 810BA296259 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 1CD7320E00B1; Fri, 9 Oct 2020 15:06:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:22 +0200 Message-Id: <20201009130430.602-10-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/18] lavf: move AVStream.*index_entries* to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. Since there are some (semi-)public fields located after these, even though this section is supposed to be private, keep some dummy padding there until the next major bump to preserve ABI compatibility. --- libavformat/ape.c | 2 +- libavformat/asfdec_f.c | 4 +- libavformat/asfdec_o.c | 6 +- libavformat/avformat.h | 10 +- libavformat/avidec.c | 100 ++++++++++---------- libavformat/bink.c | 10 +- libavformat/cafdec.c | 22 ++--- libavformat/cinedec.c | 2 +- libavformat/dhav.c | 4 +- libavformat/flacdec.c | 8 +- libavformat/flic.c | 6 +- libavformat/flvdec.c | 10 +- libavformat/gxf.c | 6 +- libavformat/ifv.c | 8 +- libavformat/img2dec.c | 2 +- libavformat/internal.h | 5 + libavformat/jvdec.c | 28 +++--- libavformat/matroskadec.c | 40 ++++---- libavformat/mlvdec.c | 20 ++-- libavformat/mov.c | 190 +++++++++++++++++++------------------- libavformat/mp3dec.c | 6 +- libavformat/mpc.c | 4 +- libavformat/mpc8.c | 4 +- libavformat/mux.c | 2 +- libavformat/mvdec.c | 4 +- libavformat/nsvdec.c | 4 +- libavformat/nutdec.c | 6 +- libavformat/nutenc.c | 12 +-- libavformat/rl2.c | 8 +- libavformat/rpl.c | 4 +- libavformat/segafilm.c | 2 +- libavformat/tta.c | 8 +- libavformat/utils.c | 46 ++++----- libavformat/vocdec.c | 8 +- 34 files changed, 304 insertions(+), 297 deletions(-) diff --git a/libavformat/ape.c b/libavformat/ape.c index d92cb2867d..33b7237fb0 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -469,7 +469,7 @@ static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if (index < 0) return -1; - if ((ret = avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET)) < 0) + if ((ret = avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET)) < 0) return ret; ape->currentframe = index; return 0; diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index b92434db9e..deb7c266ed 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -1678,11 +1678,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, asf->index_read = -1; } - if (asf->index_read > 0 && st->index_entries) { + if (asf->index_read > 0 && st->internal->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index >= 0) { /* find the position */ - uint64_t pos = st->index_entries[index].pos; + uint64_t pos = st->internal->index_entries[index].pos; /* do the seek */ av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c index 1b10e47907..b142f83541 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -1640,11 +1640,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, ASFContext *asf = s->priv_data; int idx, ret; - if (s->streams[stream_index]->nb_index_entries && asf->is_simple_index) { + if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) { idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags); - if (idx < 0 || idx >= s->streams[stream_index]->nb_index_entries) + if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries) return AVERROR_INVALIDDATA; - avio_seek(s->pb, s->streams[stream_index]->index_entries[idx].pos, SEEK_SET); + avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET); } else { if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0) return ret; diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 1253021452..dbef1b21dd 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1065,10 +1065,12 @@ typedef struct AVStream { #define MAX_REORDER_DELAY 16 int64_t pts_buffer[MAX_REORDER_DELAY+1]; - AVIndexEntry *index_entries; /**< Only used if the format does not - support seeking natively. */ - int nb_index_entries; - unsigned int index_entries_allocated_size; +#if LIBAVFORMAT_VERSION_MAJOR < 59 + // kept for ABI compatibility only, do not access in any way + void *unused2; + int unused3; + unsigned int unused4; +#endif /** * Stream Identifier diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 89a9443821..80e5563bc6 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -272,7 +272,7 @@ static void clean_index(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AVIStream *ast = st->priv_data; - int n = st->nb_index_entries; + int n = st->internal->nb_index_entries; int max = ast->sample_size; int64_t pos, size, ts; @@ -282,9 +282,9 @@ static void clean_index(AVFormatContext *s) while (max < 1024) max += max; - pos = st->index_entries[0].pos; - size = st->index_entries[0].size; - ts = st->index_entries[0].timestamp; + pos = st->internal->index_entries[0].pos; + size = st->internal->index_entries[0].size; + ts = st->internal->index_entries[0].timestamp; for (j = 0; j < size; j += max) av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0, @@ -432,12 +432,12 @@ static int calculate_bitrate(AVFormatContext *s) int64_t len = 0; AVStream *st = s->streams[i]; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) continue; - for (j = 0; j < st->nb_index_entries; j++) - len += st->index_entries[j].size; - maxpos = FFMAX(maxpos, st->index_entries[j-1].pos); + for (j = 0; j < st->internal->nb_index_entries; j++) + len += st->internal->index_entries[j].size; + maxpos = FFMAX(maxpos, st->internal->index_entries[j-1].pos); lensum += len; } if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file @@ -451,12 +451,12 @@ static int calculate_bitrate(AVFormatContext *s) int64_t duration; int64_t bitrate; - for (j = 0; j < st->nb_index_entries; j++) - len += st->index_entries[j].size; + for (j = 0; j < st->internal->nb_index_entries; j++) + len += st->internal->index_entries[j].size; - if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0) + if (st->internal->nb_index_entries < 2 || st->codecpar->bit_rate > 0) continue; - duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp; + duration = st->internal->index_entries[j-1].timestamp - st->internal->index_entries[0].timestamp; bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num); if (bitrate > 0) { st->codecpar->bit_rate = bitrate; @@ -1034,7 +1034,7 @@ end_of_header: for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->nb_index_entries) + if (st->internal->nb_index_entries) break; } // DV-in-AVI cannot be non-interleaved, if set this must be @@ -1316,8 +1316,8 @@ start_sync: if (size) { uint64_t pos = avio_tell(pb) - 8; - if (!st->index_entries || !st->nb_index_entries || - st->index_entries[st->nb_index_entries - 1].pos < pos) { + if (!st->internal->index_entries || !st->internal->nb_index_entries || + st->internal->index_entries[st->internal->nb_index_entries - 1].pos < pos) { av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); } @@ -1347,10 +1347,10 @@ static int ni_prepare_read(AVFormatContext *s) int64_t ts = ast->frame_offset; int64_t last_ts; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) continue; - last_ts = st->index_entries[st->nb_index_entries - 1].timestamp; + last_ts = st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp; if (!ast->remaining && ts > last_ts) continue; @@ -1379,11 +1379,11 @@ static int ni_prepare_read(AVFormatContext *s) } else { i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY); if (i >= 0) - best_ast->frame_offset = best_st->index_entries[i].timestamp; + best_ast->frame_offset = best_st->internal->index_entries[i].timestamp; } if (i >= 0) { - int64_t pos = best_st->index_entries[i].pos; + int64_t pos = best_st->internal->index_entries[i].pos; pos += best_ast->packet_size - best_ast->remaining; if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0) return AVERROR_EOF; @@ -1393,7 +1393,7 @@ static int ni_prepare_read(AVFormatContext *s) avi->stream_index = best_stream_index; if (!best_ast->remaining) best_ast->packet_size = - best_ast->remaining = best_st->index_entries[i].size; + best_ast->remaining = best_st->internal->index_entries[i].size; } else return AVERROR_EOF; @@ -1483,15 +1483,15 @@ resync: pkt->dts /= ast->sample_size; pkt->stream_index = avi->stream_index; - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->index_entries) { AVIndexEntry *e; int index; index = av_index_search_timestamp(st, ast->frame_offset, AVSEEK_FLAG_ANY); - e = &st->index_entries[index]; + e = &st->internal->index_entries[index]; if (index >= 0 && e->timestamp == ast->frame_offset) { - if (index == st->nb_index_entries-1) { + if (index == st->internal->nb_index_entries-1) { int key=1; uint32_t state=-1; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { @@ -1527,7 +1527,7 @@ resync: } ast->seek_pos= 0; - if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) { + if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) { int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q); if (avi->dts_max < dts) { @@ -1627,8 +1627,8 @@ static int avi_read_idx1(AVFormatContext *s, int size) if (!anykey) { for (index = 0; index < s->nb_streams; index++) { st = s->streams[index]; - if (st->nb_index_entries) - st->index_entries[0].flags |= AVINDEX_KEYFRAME; + if (st->internal->nb_index_entries) + st->internal->index_entries[0].flags |= AVINDEX_KEYFRAME; } } return 0; @@ -1653,16 +1653,16 @@ static int check_stream_max_drift(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AVIStream *ast = st->priv_data; - int n = st->nb_index_entries; - while (idx[i] < n && st->index_entries[idx[i]].pos < pos) + int n = st->internal->nb_index_entries; + while (idx[i] < n && st->internal->index_entries[idx[i]].pos < pos) idx[i]++; if (idx[i] < n) { int64_t dts; - dts = av_rescale_q(st->index_entries[idx[i]].timestamp / + dts = av_rescale_q(st->internal->index_entries[idx[i]].timestamp / FFMAX(ast->sample_size, 1), st->time_base, AV_TIME_BASE_Q); min_dts = FFMIN(min_dts, dts); - min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos); + min_pos = FFMIN(min_pos, st->internal->index_entries[idx[i]].pos); } } for (i = 0; i < s->nb_streams; i++) { @@ -1671,7 +1671,7 @@ static int check_stream_max_drift(AVFormatContext *s) if (idx[i] && min_dts != INT64_MAX / 2) { int64_t dts; - dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp / + dts = av_rescale_q(st->internal->index_entries[idx[i] - 1].timestamp / FFMAX(ast->sample_size, 1), st->time_base, AV_TIME_BASE_Q); max_dts = FFMAX(max_dts, dts); @@ -1700,30 +1700,30 @@ static int guess_ni_flag(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - int n = st->nb_index_entries; + int n = st->internal->nb_index_entries; unsigned int size; if (n <= 0) continue; if (n >= 2) { - int64_t pos = st->index_entries[0].pos; + int64_t pos = st->internal->index_entries[0].pos; unsigned tag[2]; avio_seek(s->pb, pos, SEEK_SET); tag[0] = avio_r8(s->pb); tag[1] = avio_r8(s->pb); avio_rl16(s->pb); size = avio_rl32(s->pb); - if (get_stream_idx(tag) == i && pos + size > st->index_entries[1].pos) + if (get_stream_idx(tag) == i && pos + size > st->internal->index_entries[1].pos) last_start = INT64_MAX; - if (get_stream_idx(tag) == i && size == st->index_entries[0].size + 8) + if (get_stream_idx(tag) == i && size == st->internal->index_entries[0].size + 8) last_start = INT64_MAX; } - if (st->index_entries[0].pos > last_start) - last_start = st->index_entries[0].pos; - if (st->index_entries[n - 1].pos < first_end) - first_end = st->index_entries[n - 1].pos; + if (st->internal->index_entries[0].pos > last_start) + last_start = st->internal->index_entries[0].pos; + if (st->internal->index_entries[n - 1].pos < first_end) + first_end = st->internal->index_entries[n - 1].pos; } avio_seek(s->pb, oldpos, SEEK_SET); @@ -1811,20 +1811,20 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, timestamp * FFMAX(ast->sample_size, 1), flags); if (index < 0) { - if (st->nb_index_entries > 0) + if (st->internal->nb_index_entries > 0) av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n", timestamp * FFMAX(ast->sample_size, 1), - st->index_entries[0].timestamp, - st->index_entries[st->nb_index_entries - 1].timestamp); + st->internal->index_entries[0].timestamp, + st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp); return AVERROR_INVALIDDATA; } /* find the position */ - pos = st->index_entries[index].pos; - timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); + pos = st->internal->index_entries[index].pos; + timestamp = st->internal->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n", - timestamp, index, st->index_entries[index].timestamp); + timestamp, index, st->internal->index_entries[index].timestamp); if (CONFIG_DV_DEMUXER && avi->dv_demux) { /* One and only one real stream for DV in AVI, and it has video */ @@ -1855,7 +1855,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, continue; } - if (st2->nb_index_entries <= 0) + if (st2->internal->nb_index_entries <= 0) continue; // av_assert1(st2->codecpar->block_align); @@ -1869,14 +1869,14 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; - ast2->seek_pos = st2->index_entries[index].pos; + ast2->seek_pos = st2->internal->index_entries[index].pos; pos_min = FFMIN(pos_min,ast2->seek_pos); } for (i = 0; i < s->nb_streams; i++) { AVStream *st2 = s->streams[i]; AVIStream *ast2 = st2->priv_data; - if (ast2->sub_ctx || st2->nb_index_entries <= 0) + if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0) continue; index = av_index_search_timestamp( @@ -1885,9 +1885,9 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; - while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min) + while (!avi->non_interleaved && index>0 && st2->internal->index_entries[index-1].pos >= pos_min) index--; - ast2->frame_offset = st2->index_entries[index].timestamp; + ast2->frame_offset = st2->internal->index_entries[index].timestamp; } /* do the seek */ diff --git a/libavformat/bink.c b/libavformat/bink.c index 08125ba8f1..99bbd27ef3 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -225,8 +225,8 @@ static int read_header(AVFormatContext *s) return ret; } - if (vst->index_entries) - avio_seek(pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET); + if (vst->internal->index_entries) + avio_seek(pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET); else avio_skip(pb, 4); @@ -256,8 +256,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } - bink->remain_packet_size = st->index_entries[index_entry].size; - bink->flags = st->index_entries[index_entry].flags; + bink->remain_packet_size = st->internal->index_entries[index_entry].size; + bink->flags = st->internal->index_entries[index_entry].flags; bink->current_track = 0; } @@ -313,7 +313,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in return -1; /* seek to the first frame */ - ret = avio_seek(s->pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET); + ret = avio_seek(s->pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET); if (ret < 0) return ret; diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index d0f942f3e4..3bf1fa64bc 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -329,7 +329,7 @@ found_data: if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) { if (caf->data_size > 0) st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet; - } else if (st->nb_index_entries && st->duration > 0) { + } else if (st->internal->nb_index_entries && st->duration > 0) { if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n", st->codecpar->sample_rate, caf->data_size / st->duration); @@ -382,13 +382,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size; pkt_size = FFMIN(pkt_size, left); pkt_frames = pkt_size / caf->bytes_per_packet; - } else if (st->nb_index_entries) { - if (caf->packet_cnt < st->nb_index_entries - 1) { - pkt_size = st->index_entries[caf->packet_cnt + 1].pos - st->index_entries[caf->packet_cnt].pos; - pkt_frames = st->index_entries[caf->packet_cnt + 1].timestamp - st->index_entries[caf->packet_cnt].timestamp; - } else if (caf->packet_cnt == st->nb_index_entries - 1) { - pkt_size = caf->num_bytes - st->index_entries[caf->packet_cnt].pos; - pkt_frames = st->duration - st->index_entries[caf->packet_cnt].timestamp; + } else if (st->internal->nb_index_entries) { + if (caf->packet_cnt < st->internal->nb_index_entries - 1) { + pkt_size = st->internal->index_entries[caf->packet_cnt + 1].pos - st->internal->index_entries[caf->packet_cnt].pos; + pkt_frames = st->internal->index_entries[caf->packet_cnt + 1].timestamp - st->internal->index_entries[caf->packet_cnt].timestamp; + } else if (caf->packet_cnt == st->internal->nb_index_entries - 1) { + pkt_size = caf->num_bytes - st->internal->index_entries[caf->packet_cnt].pos; + pkt_frames = st->duration - st->internal->index_entries[caf->packet_cnt].timestamp; } else { return AVERROR(EIO); } @@ -427,10 +427,10 @@ static int read_seek(AVFormatContext *s, int stream_index, pos = FFMIN(pos, caf->data_size); packet_cnt = pos / caf->bytes_per_packet; frame_cnt = caf->frames_per_packet * packet_cnt; - } else if (st->nb_index_entries) { + } else if (st->internal->nb_index_entries) { packet_cnt = av_index_search_timestamp(st, timestamp, flags); - frame_cnt = st->index_entries[packet_cnt].timestamp; - pos = st->index_entries[packet_cnt].pos; + frame_cnt = st->internal->index_entries[packet_cnt].timestamp; + pos = st->internal->index_entries[packet_cnt].pos; } else { return -1; } diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c index 0f2453cdf5..c6c0d927ee 100644 --- a/libavformat/cinedec.c +++ b/libavformat/cinedec.c @@ -291,7 +291,7 @@ static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt) if (cine->pts >= st->duration) return AVERROR_EOF; - avio_seek(pb, st->index_entries[cine->pts].pos, SEEK_SET); + avio_seek(pb, st->internal->index_entries[cine->pts].pos, SEEK_SET); n = avio_rl32(pb); if (n < 8) return AVERROR_INVALIDDATA; diff --git a/libavformat/dhav.c b/libavformat/dhav.c index 5e9abdb611..3e64faf767 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -441,10 +441,10 @@ static int dhav_read_seek(AVFormatContext *s, int stream_index, if (index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - pts = st->index_entries[index].timestamp; + pts = st->internal->index_entries[index].timestamp; for (int n = 0; n < s->nb_streams; n++) { AVStream *st = s->streams[n]; diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 79c05f14bf..6aca4755a1 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -40,8 +40,8 @@ static void reset_index_position(int64_t metadata_head_size, AVStream *st) { /* the real seek index offset should be the size of metadata blocks with the offset in the frame blocks */ int i; - for(i=0; inb_index_entries; i++) { - st->index_entries[i].pos += metadata_head_size; + for(i=0; iinternal->nb_index_entries; i++) { + st->internal->index_entries[i].pos += metadata_head_size; } } @@ -319,10 +319,10 @@ static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in } index = av_index_search_timestamp(s->streams[0], timestamp, flags); - if(index<0 || index >= s->streams[0]->nb_index_entries) + if(index<0 || index >= s->streams[0]->internal->nb_index_entries) return -1; - e = s->streams[0]->index_entries[index]; + e = s->streams[0]->internal->index_entries[index]; pos = avio_seek(s->pb, e.pos, SEEK_SET); if (pos >= 0) { return 0; diff --git a/libavformat/flic.c b/libavformat/flic.c index 4552bff69c..9a7b8081ed 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -268,7 +268,7 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, int64_t pos, ts; int index; - if (!st->index_entries || stream_index != flic->video_stream_index) + if (!st->internal->index_entries || stream_index != flic->video_stream_index) return -1; index = av_index_search_timestamp(st, pts, flags); @@ -278,8 +278,8 @@ static int flic_read_seek(AVFormatContext *s, int stream_index, if (index < 0) return -1; - pos = st->index_entries[index].pos; - ts = st->index_entries[index].timestamp; + pos = st->internal->index_entries[index].pos; + ts = st->internal->index_entries[index].timestamp; flic->frame_number = ts; avio_seek(s->pb, pos, SEEK_SET); return 0; diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index d480d0bc67..6bddcbb556 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -140,7 +140,7 @@ static void add_keyframes_index(AVFormatContext *s) av_assert0(flv->last_keyframe_stream_index <= s->nb_streams); stream = s->streams[flv->last_keyframe_stream_index]; - if (stream->nb_index_entries == 0) { + if (stream->internal->nb_index_entries == 0) { for (i = 0; i < flv->keyframe_count; i++) { av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n", flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000); @@ -828,10 +828,10 @@ static void clear_index_entries(AVFormatContext *s, int64_t pos) AVStream *st = s->streams[i]; /* Remove all index entries that point to >= pos */ out = 0; - for (j = 0; j < st->nb_index_entries; j++) - if (st->index_entries[j].pos < pos) - st->index_entries[out++] = st->index_entries[j]; - st->nb_index_entries = out; + for (j = 0; j < st->internal->nb_index_entries; j++) + if (st->internal->index_entries[j].pos < pos) + st->internal->index_entries[out++] = st->internal->index_entries[j]; + st->internal->nb_index_entries = out; } } diff --git a/libavformat/gxf.c b/libavformat/gxf.c index 49364b7205..96b7035386 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -572,9 +572,9 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); if (idx < 0) return -1; - pos = st->index_entries[idx].pos; - if (idx < st->nb_index_entries - 2) - maxlen = st->index_entries[idx + 2].pos - pos; + pos = st->internal->index_entries[idx].pos; + if (idx < st->internal->nb_index_entries - 2) + maxlen = st->internal->index_entries[idx + 2].pos - pos; maxlen = FFMAX(maxlen, 200 * 1024); res = avio_seek(s->pb, pos, SEEK_SET); if (res < 0) diff --git a/libavformat/ifv.c b/libavformat/ifv.c index f95e9b0e52..e21628f180 100644 --- a/libavformat/ifv.c +++ b/libavformat/ifv.c @@ -195,15 +195,15 @@ static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt) if (ifv->next_video_index < ifv->total_vframes) { st = s->streams[ifv->video_stream_index]; - if (ifv->next_video_index < st->nb_index_entries) - e_next = ev = &st->index_entries[ifv->next_video_index]; + if (ifv->next_video_index < st->internal->nb_index_entries) + e_next = ev = &st->internal->index_entries[ifv->next_video_index]; } if (ifv->is_audio_present && ifv->next_audio_index < ifv->total_aframes) { st = s->streams[ifv->audio_stream_index]; - if (ifv->next_audio_index < st->nb_index_entries) { - ea = &st->index_entries[ifv->next_audio_index]; + if (ifv->next_audio_index < st->internal->nb_index_entries) { + ea = &st->internal->index_entries[ifv->next_audio_index]; if (!ev || ea->timestamp < ev->timestamp) e_next = ea; } diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 9a3c9fad02..3f217d5916 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -587,7 +587,7 @@ static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if(index < 0) return -1; - s1->img_number = st->index_entries[index].pos; + s1->img_number = st->internal->index_entries[index].pos; return 0; } diff --git a/libavformat/internal.h b/libavformat/internal.h index 87d62c51b2..ce79da8000 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,6 +225,11 @@ struct AVStreamInternal { } *info; + AVIndexEntry *index_entries; /**< Only used if the format does not + support seeking natively. */ + int nb_index_entries; + unsigned int index_entries_allocated_size; + int64_t interleaver_chunk_size; int64_t interleaver_chunk_duration; diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c index 551f8069e6..47d18e2beb 100644 --- a/libavformat/jvdec.c +++ b/libavformat/jvdec.c @@ -92,7 +92,7 @@ static int read_header(AVFormatContext *s) vst->codecpar->height = avio_rl16(pb); vst->duration = vst->nb_frames = - ast->nb_index_entries = avio_rl16(pb); + ast->internal->nb_index_entries = avio_rl16(pb); avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000); avio_skip(pb, 4); @@ -107,19 +107,19 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 10); - ast->index_entries = av_malloc(ast->nb_index_entries * - sizeof(*ast->index_entries)); - if (!ast->index_entries) + ast->internal->index_entries = av_malloc(ast->internal->nb_index_entries * + sizeof(*ast->internal->index_entries)); + if (!ast->internal->index_entries) return AVERROR(ENOMEM); - jv->frames = av_malloc(ast->nb_index_entries * sizeof(JVFrame)); + jv->frames = av_malloc(ast->internal->nb_index_entries * sizeof(JVFrame)); if (!jv->frames) { - av_freep(&ast->index_entries); + av_freep(&ast->internal->index_entries); return AVERROR(ENOMEM); } - offset = 0x68 + ast->nb_index_entries * 16; - for (i = 0; i < ast->nb_index_entries; i++) { - AVIndexEntry *e = ast->index_entries + i; + offset = 0x68 + ast->internal->nb_index_entries * 16; + for (i = 0; i < ast->internal->nb_index_entries; i++) { + AVIndexEntry *e = ast->internal->index_entries + i; JVFrame *jvf = jv->frames + i; /* total frame size including audio, video, palette data and padding */ @@ -139,7 +139,7 @@ static int read_header(AVFormatContext *s) if (s->error_recognition & AV_EF_EXPLODE) { read_close(s); av_freep(&jv->frames); - av_freep(&ast->index_entries); + av_freep(&ast->internal->index_entries); return AVERROR_INVALIDDATA; } jvf->audio_size = @@ -170,8 +170,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *ast = s->streams[0]; int ret; - while (!avio_feof(s->pb) && jv->pts < ast->nb_index_entries) { - const AVIndexEntry *e = ast->index_entries + jv->pts; + while (!avio_feof(s->pb) && jv->pts < ast->internal->nb_index_entries) { + const AVIndexEntry *e = ast->internal->index_entries + jv->pts; const JVFrame *jvf = jv->frames + jv->pts; switch (jv->state) { @@ -244,9 +244,9 @@ static int read_seek(AVFormatContext *s, int stream_index, return 0; } - if (i < 0 || i >= ast->nb_index_entries) + if (i < 0 || i >= ast->internal->nb_index_entries) return 0; - if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, ast->internal->index_entries[i].pos, SEEK_SET) < 0) return -1; jv->state = JV_AUDIO; diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index a183026359..981e044263 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3766,13 +3766,13 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, matroska_parse_cues(matroska); } - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) goto err; - timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); + timestamp = FFMAX(timestamp, st->internal->index_entries[0].timestamp); - if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) { - matroska_reset_status(matroska, 0, st->index_entries[st->nb_index_entries - 1].pos); - while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) { + if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) { + matroska_reset_status(matroska, 0, st->internal->index_entries[st->internal->nb_index_entries - 1].pos); + while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) { matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break; @@ -3780,7 +3780,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } matroska_clear_queue(matroska); - if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1)) + if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->internal->nb_index_entries - 1)) goto err; tracks = matroska->tracks.elem; @@ -3792,17 +3792,17 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, } /* We seek to a level 1 element, so set the appropriate status. */ - matroska_reset_status(matroska, 0, st->index_entries[index].pos); + matroska_reset_status(matroska, 0, st->internal->index_entries[index].pos); if (flags & AVSEEK_FLAG_ANY) { st->internal->skip_to_keyframe = 0; matroska->skip_to_timecode = timestamp; } else { st->internal->skip_to_keyframe = 1; - matroska->skip_to_timecode = st->index_entries[index].timestamp; + matroska->skip_to_timecode = st->internal->index_entries[index].timestamp; } matroska->skip_to_keyframe = 1; matroska->done = 0; - ff_update_cur_dts(s, st, st->index_entries[index].timestamp); + ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp); return 0; err: // slightly hackish but allows proper fallback to @@ -3847,8 +3847,8 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) MatroskaDemuxContext *matroska = s->priv_data; CueDesc cue_desc; int i; - int nb_index_entries = s->streams[0]->nb_index_entries; - AVIndexEntry *index_entries = s->streams[0]->index_entries; + int nb_index_entries = s->streams[0]->internal->nb_index_entries; + AVIndexEntry *index_entries = s->streams[0]->internal->index_entries; if (ts >= matroska->duration * matroska->time_scale) return (CueDesc) {-1, -1, -1, -1}; for (i = 1; i < nb_index_entries; i++) { if (index_entries[i - 1].timestamp * matroska->time_scale <= ts && @@ -3878,11 +3878,11 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) uint32_t id = matroska->current_id; int64_t cluster_pos, before_pos; int index, rv = 1; - if (s->streams[0]->nb_index_entries <= 0) return 0; + if (s->streams[0]->internal->nb_index_entries <= 0) return 0; // seek to the first cluster using cues. index = av_index_search_timestamp(s->streams[0], 0, 0); if (index < 0) return 0; - cluster_pos = s->streams[0]->index_entries[index].pos; + cluster_pos = s->streams[0]->internal->index_entries[index].pos; before_pos = avio_tell(s->pb); while (1) { uint64_t cluster_id, cluster_length; @@ -4006,9 +4006,9 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t double bandwidth = 0.0; int i; - for (i = 0; i < st->nb_index_entries; i++) { + for (i = 0; i < st->internal->nb_index_entries; i++) { int64_t prebuffer_ns = 1000000000; - int64_t time_ns = st->index_entries[i].timestamp * matroska->time_scale; + int64_t time_ns = st->internal->index_entries[i].timestamp * matroska->time_scale; double nano_seconds_per_second = 1000000000.0; int64_t prebuffered_ns = time_ns + prebuffer_ns; double prebuffer_bytes = 0.0; @@ -4146,14 +4146,14 @@ static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range) // store cue point timestamps as a comma separated list for checking subsegment alignment in // the muxer. assumes that each timestamp cannot be more than 20 characters long. - buf = av_malloc_array(s->streams[0]->nb_index_entries, 20); + buf = av_malloc_array(s->streams[0]->internal->nb_index_entries, 20); if (!buf) return -1; strcpy(buf, ""); - for (i = 0; i < s->streams[0]->nb_index_entries; i++) { + for (i = 0; i < s->streams[0]->internal->nb_index_entries; i++) { int ret = snprintf(buf + end, 20, - "%" PRId64"%s", s->streams[0]->index_entries[i].timestamp, - i != s->streams[0]->nb_index_entries - 1 ? "," : ""); - if (ret <= 0 || (ret == 20 && i == s->streams[0]->nb_index_entries - 1)) { + "%" PRId64"%s", s->streams[0]->internal->index_entries[i].timestamp, + i != s->streams[0]->internal->nb_index_entries - 1 ? "," : ""); + if (ret <= 0 || (ret == 20 && i == s->streams[0]->internal->nb_index_entries - 1)) { av_log(s, AV_LOG_ERROR, "timestamp too long.\n"); av_free(buf); return AVERROR_INVALIDDATA; diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c index f08aabf4e0..1ddef3461e 100644 --- a/libavformat/mlvdec.c +++ b/libavformat/mlvdec.c @@ -191,12 +191,12 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f } } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) { uint64_t pts = avio_rl32(pb); - ff_add_index_entry(&vst->index_entries, &vst->nb_index_entries, &vst->index_entries_allocated_size, + ff_add_index_entry(&vst->internal->index_entries, &vst->internal->nb_index_entries, &vst->internal->index_entries_allocated_size, avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME); size -= 4; } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) { uint64_t pts = avio_rl32(pb); - ff_add_index_entry(&ast->index_entries, &ast->nb_index_entries, &ast->index_entries_allocated_size, + ff_add_index_entry(&ast->internal->index_entries, &ast->internal->nb_index_entries, &ast->internal->index_entries_allocated_size, avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME); size -= 4; } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) { @@ -374,22 +374,22 @@ static int read_header(AVFormatContext *avctx) } if (vst) - vst->duration = vst->nb_index_entries; + vst->duration = vst->internal->nb_index_entries; if (ast) - ast->duration = ast->nb_index_entries; + ast->duration = ast->internal->nb_index_entries; - if ((vst && !vst->nb_index_entries) || (ast && !ast->nb_index_entries)) { + if ((vst && !vst->internal->nb_index_entries) || (ast && !ast->internal->nb_index_entries)) { av_log(avctx, AV_LOG_ERROR, "no index entries found\n"); read_close(avctx); return AVERROR_INVALIDDATA; } if (vst && ast) - avio_seek(pb, FFMIN(vst->index_entries[0].pos, ast->index_entries[0].pos), SEEK_SET); + avio_seek(pb, FFMIN(vst->internal->index_entries[0].pos, ast->internal->index_entries[0].pos), SEEK_SET); else if (vst) - avio_seek(pb, vst->index_entries[0].pos, SEEK_SET); + avio_seek(pb, vst->internal->index_entries[0].pos, SEEK_SET); else if (ast) - avio_seek(pb, ast->index_entries[0].pos, SEEK_SET); + avio_seek(pb, ast->internal->index_entries[0].pos, SEEK_SET); return 0; } @@ -415,12 +415,12 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR(EIO); } - pb = mlv->pb[st->index_entries[index].size]; + pb = mlv->pb[st->internal->index_entries[index].size]; if (!pb) { ret = FFERROR_REDO; goto next_packet; } - avio_seek(pb, st->index_entries[index].pos, SEEK_SET); + avio_seek(pb, st->internal->index_entries[index].pos, SEEK_SET); avio_skip(pb, 4); // blockType size = avio_rl32(pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index 6103678cdb..57ac212146 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3179,8 +3179,8 @@ static int find_prev_closest_index(AVStream *st, int64_t* ctts_sample) { MOVStreamContext *msc = st->priv_data; - AVIndexEntry *e_keep = st->index_entries; - int nb_keep = st->nb_index_entries; + AVIndexEntry *e_keep = st->internal->index_entries; + int nb_keep = st->internal->nb_index_entries; int64_t i = 0; int64_t index_ctts_count; @@ -3193,8 +3193,8 @@ static int find_prev_closest_index(AVStream *st, timestamp_pts -= msc->dts_shift; } - st->index_entries = e_old; - st->nb_index_entries = nb_old; + st->internal->index_entries = e_old; + st->internal->nb_index_entries = nb_old; *index = av_index_search_timestamp(st, timestamp_pts, flag | AVSEEK_FLAG_BACKWARD); // Keep going backwards in the index entries until the timestamp is the same. @@ -3247,14 +3247,14 @@ static int find_prev_closest_index(AVStream *st, } /* restore AVStream state*/ - st->index_entries = e_keep; - st->nb_index_entries = nb_keep; + st->internal->index_entries = e_keep; + st->internal->nb_index_entries = nb_keep; return *index >= 0 ? 0 : -1; } /** - * Add index entry with the given values, to the end of st->index_entries. - * Returns the new size st->index_entries if successful, else returns -1. + * Add index entry with the given values, to the end of st->internal->index_entries. + * Returns the new size st->internal->index_entries if successful, else returns -1. * * This function is similar to ff_add_index_entry in libavformat/utils.c * except that here we are always unconditionally adding an index entry to @@ -3268,27 +3268,27 @@ static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, { AVIndexEntry *entries, *ie; int64_t index = -1; - const size_t min_size_needed = (st->nb_index_entries + 1) * sizeof(AVIndexEntry); + const size_t min_size_needed = (st->internal->nb_index_entries + 1) * sizeof(AVIndexEntry); // Double the allocation each time, to lower memory fragmentation. // Another difference from ff_add_index_entry function. const size_t requested_size = - min_size_needed > st->index_entries_allocated_size ? - FFMAX(min_size_needed, 2 * st->index_entries_allocated_size) : + min_size_needed > st->internal->index_entries_allocated_size ? + FFMAX(min_size_needed, 2 * st->internal->index_entries_allocated_size) : min_size_needed; - if (st->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) + if (st->internal->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry)) return -1; - entries = av_fast_realloc(st->index_entries, - &st->index_entries_allocated_size, + entries = av_fast_realloc(st->internal->index_entries, + &st->internal->index_entries_allocated_size, requested_size); if (!entries) return -1; - st->index_entries= entries; + st->internal->index_entries= entries; - index= st->nb_index_entries++; + index= st->internal->nb_index_entries++; ie= &entries[index]; ie->pos = pos; @@ -3307,10 +3307,10 @@ static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_ int64_t* frame_duration_buffer, int frame_duration_buffer_size) { int i = 0; - av_assert0(end_index >= 0 && end_index <= st->nb_index_entries); + av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries); for (i = 0; i < frame_duration_buffer_size; i++) { end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i]; - st->index_entries[end_index - 1 - i].timestamp = end_ts; + st->internal->index_entries[end_index - 1 - i].timestamp = end_ts; } } @@ -3362,14 +3362,14 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) if (st->codecpar->video_delay <= 0 && msc->ctts_data && st->codecpar->codec_id == AV_CODEC_ID_H264) { st->codecpar->video_delay = 0; - for (ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) { + for (ind = 0; ind < st->internal->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) { // Point j to the last elem of the buffer and insert the current pts there. j = buf_start; buf_start = (buf_start + 1); if (buf_start == MAX_REORDER_DELAY + 1) buf_start = 0; - pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; + pts_buf[j] = st->internal->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration; // The timestamps that are already in the sorted buffer, and are greater than the // current pts, are exactly the timestamps that need to be buffered to output PTS @@ -3449,7 +3449,7 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample) } /** - * Fix st->index_entries, so that it contains only the entries (and the entries + * Fix st->internal->index_entries, so that it contains only the entries (and the entries * which are needed to decode them) that fall in the edit list time ranges. * Also fixes the timestamps of the index entries to match the timeline * specified the edit lists. @@ -3457,8 +3457,8 @@ static void mov_current_sample_set(MOVStreamContext *sc, int current_sample) static void mov_fix_index(MOVContext *mov, AVStream *st) { MOVStreamContext *msc = st->priv_data; - AVIndexEntry *e_old = st->index_entries; - int nb_old = st->nb_index_entries; + AVIndexEntry *e_old = st->internal->index_entries; + int nb_old = st->internal->nb_index_entries; const AVIndexEntry *e_old_end = e_old + nb_old; const AVIndexEntry *current = NULL; MOVStts *ctts_data_old = msc->ctts_data; @@ -3503,9 +3503,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) current_index_range = msc->index_ranges - 1; // Clean AVStream from traces of old index - st->index_entries = NULL; - st->index_entries_allocated_size = 0; - st->nb_index_entries = 0; + st->internal->index_entries = NULL; + st->internal->index_entries_allocated_size = 0; + st->internal->nb_index_entries = 0; // Clean ctts fields of MOVStreamContext msc->ctts_data = NULL; @@ -3634,7 +3634,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for // discarded packets. if (frame_duration_buffer) { - fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter, + fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3673,7 +3673,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Make timestamps strictly monotonically increasing by rewriting timestamps for // discarded packets. if (frame_duration_buffer) { - fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter, + fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter, frame_duration_buffer, num_discarded_begin); av_freep(&frame_duration_buffer); } @@ -3734,8 +3734,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (msc->min_corrected_pts > 0) { av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts); - for (i = 0; i < st->nb_index_entries; ++i) { - st->index_entries[i].timestamp -= msc->min_corrected_pts; + for (i = 0; i < st->internal->nb_index_entries; ++i) { + st->internal->index_entries[i].timestamp -= msc->min_corrected_pts; } } } @@ -3828,17 +3828,17 @@ static void mov_build_index(MOVContext *mov, AVStream *st) current_dts -= sc->dts_shift; last_dts = current_dts; - if (!sc->sample_count || st->nb_index_entries) + if (!sc->sample_count || st->internal->nb_index_entries) return; - if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries) + if (sc->sample_count >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries) return; - if (av_reallocp_array(&st->index_entries, - st->nb_index_entries + sc->sample_count, - sizeof(*st->index_entries)) < 0) { - st->nb_index_entries = 0; + if (av_reallocp_array(&st->internal->index_entries, + st->internal->nb_index_entries + sc->sample_count, + sizeof(*st->internal->index_entries)) < 0) { + st->internal->nb_index_entries = 0; return; } - st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries); + st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + sc->sample_count) * sizeof(*st->internal->index_entries); if (ctts_data_old) { // Expand ctts entries such that we have a 1-1 mapping with samples @@ -3921,7 +3921,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", sample_size); return; } - e = &st->index_entries[st->nb_index_entries++]; + e = &st->internal->index_entries[st->internal->nb_index_entries++]; e->pos = current_offset; e->timestamp = current_dts; e->size = sample_size; @@ -3930,7 +3930,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", " "size %u, distance %u, keyframe %d\n", st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries < 100) ff_rfps_add_frame(mov->fc, st, current_dts); } @@ -4002,15 +4002,15 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } av_log(mov->fc, AV_LOG_TRACE, "chunk count %u\n", total); - if (total >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries) + if (total >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries) return; - if (av_reallocp_array(&st->index_entries, - st->nb_index_entries + total, - sizeof(*st->index_entries)) < 0) { - st->nb_index_entries = 0; + if (av_reallocp_array(&st->internal->index_entries, + st->internal->nb_index_entries + total, + sizeof(*st->internal->index_entries)) < 0) { + st->internal->nb_index_entries = 0; return; } - st->index_entries_allocated_size = (st->nb_index_entries + total) * sizeof(*st->index_entries); + st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + total) * sizeof(*st->internal->index_entries); // populate index for (i = 0; i < sc->chunk_count; i++) { @@ -4045,7 +4045,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } - if (st->nb_index_entries >= total) { + if (st->internal->nb_index_entries >= total) { av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %u\n", total); return; } @@ -4053,7 +4053,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", size); return; } - e = &st->index_entries[st->nb_index_entries++]; + e = &st->internal->index_entries[st->internal->nb_index_entries++]; e->pos = current_offset; e->timestamp = current_dts; e->size = size; @@ -4076,8 +4076,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } // Update start time of the stream. - if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) { - st->start_time = st->index_entries[0].timestamp + sc->dts_shift; + if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries > 0) { + st->start_time = st->internal->index_entries[0].timestamp + sc->dts_shift; if (sc->ctts_data) { st->start_time += sc->ctts_data[0].duration; } @@ -4775,7 +4775,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // A valid index_entry means the trun for the fragment was read // and it's samples are in index_entries at the given position. // New index entries will be inserted before the index_entry found. - index_entry_pos = st->nb_index_entries; + index_entry_pos = st->internal->nb_index_entries; for (i = c->frag_index.current + 1; i < c->frag_index.nb_items; i++) { frag_stream_info = get_frag_stream_info(&c->frag_index, i, frag->track_id); if (frag_stream_info && frag_stream_info->index_entry >= 0) { @@ -4784,7 +4784,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) break; } } - av_assert0(index_entry_pos <= st->nb_index_entries); + av_assert0(index_entry_pos <= st->internal->nb_index_entries); avio_r8(pb); /* version */ flags = avio_rb24(pb); @@ -4835,22 +4835,22 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "first sample flags 0x%x\n", first_sample_flags); // realloc space for new index entries - if((uint64_t)st->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) { - entries = UINT_MAX / sizeof(AVIndexEntry) - st->nb_index_entries; + if((uint64_t)st->internal->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) { + entries = UINT_MAX / sizeof(AVIndexEntry) - st->internal->nb_index_entries; av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n"); } if (entries == 0) return 0; - requested_size = (st->nb_index_entries + entries) * sizeof(AVIndexEntry); - new_entries = av_fast_realloc(st->index_entries, - &st->index_entries_allocated_size, + requested_size = (st->internal->nb_index_entries + entries) * sizeof(AVIndexEntry); + new_entries = av_fast_realloc(st->internal->index_entries, + &st->internal->index_entries_allocated_size, requested_size); if (!new_entries) return AVERROR(ENOMEM); - st->index_entries= new_entries; + st->internal->index_entries= new_entries; - requested_size = (st->nb_index_entries + entries) * sizeof(*sc->ctts_data); + requested_size = (st->internal->nb_index_entries + entries) * sizeof(*sc->ctts_data); old_ctts_allocated_size = sc->ctts_allocated_size; ctts_data = av_fast_realloc(sc->ctts_data, &sc->ctts_allocated_size, requested_size); @@ -4864,12 +4864,12 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) memset((uint8_t*)(sc->ctts_data) + old_ctts_allocated_size, 0, sc->ctts_allocated_size - old_ctts_allocated_size); - if (index_entry_pos < st->nb_index_entries) { + if (index_entry_pos < st->internal->nb_index_entries) { // Make hole in index_entries and ctts_data for new samples - memmove(st->index_entries + index_entry_pos + entries, - st->index_entries + index_entry_pos, - sizeof(*st->index_entries) * - (st->nb_index_entries - index_entry_pos)); + memmove(st->internal->index_entries + index_entry_pos + entries, + st->internal->index_entries + index_entry_pos, + sizeof(*st->internal->index_entries) * + (st->internal->nb_index_entries - index_entry_pos)); memmove(sc->ctts_data + index_entry_pos + entries, sc->ctts_data + index_entry_pos, sizeof(*sc->ctts_data) * (sc->ctts_count - index_entry_pos)); @@ -4878,15 +4878,15 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) } } - st->nb_index_entries += entries; - sc->ctts_count = st->nb_index_entries; + st->internal->nb_index_entries += entries; + sc->ctts_count = st->internal->nb_index_entries; // Record the index_entry position in frag_index of this fragment if (frag_stream_info) frag_stream_info->index_entry = index_entry_pos; if (index_entry_pos > 0) - prev_dts = st->index_entries[index_entry_pos-1].timestamp; + prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp; for (i = 0; i < entries && !pb->eof_reached; i++) { unsigned sample_size = frag->size; @@ -4935,11 +4935,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (prev_dts >= dts) index_entry_flags |= AVINDEX_DISCARD_FRAME; - st->index_entries[index_entry_pos].pos = offset; - st->index_entries[index_entry_pos].timestamp = dts; - st->index_entries[index_entry_pos].size= sample_size; - st->index_entries[index_entry_pos].min_distance= distance; - st->index_entries[index_entry_pos].flags = index_entry_flags; + st->internal->index_entries[index_entry_pos].pos = offset; + st->internal->index_entries[index_entry_pos].timestamp = dts; + st->internal->index_entries[index_entry_pos].size= sample_size; + st->internal->index_entries[index_entry_pos].min_distance= distance; + st->internal->index_entries[index_entry_pos].flags = index_entry_flags; sc->ctts_data[index_entry_pos].count = 1; sc->ctts_data[index_entry_pos].duration = ctts_duration; @@ -4966,16 +4966,16 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // EOF found before reading all entries. Fix the hole this would // leave in index_entries and ctts_data int gap = entries - i; - memmove(st->index_entries + index_entry_pos, - st->index_entries + index_entry_pos + gap, - sizeof(*st->index_entries) * - (st->nb_index_entries - (index_entry_pos + gap))); + memmove(st->internal->index_entries + index_entry_pos, + st->internal->index_entries + index_entry_pos + gap, + sizeof(*st->internal->index_entries) * + (st->internal->nb_index_entries - (index_entry_pos + gap))); memmove(sc->ctts_data + index_entry_pos, sc->ctts_data + index_entry_pos + gap, sizeof(*sc->ctts_data) * (sc->ctts_count - (index_entry_pos + gap))); - st->nb_index_entries -= gap; + st->internal->nb_index_entries -= gap; sc->ctts_count -= gap; if (index_entry_pos < sc->current_sample) { sc->current_sample -= gap; @@ -4988,11 +4988,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) // fragment that overlap with AVINDEX_DISCARD_FRAME prev_dts = AV_NOPTS_VALUE; if (index_entry_pos > 0) - prev_dts = st->index_entries[index_entry_pos-1].timestamp; - for (i = index_entry_pos; i < st->nb_index_entries; i++) { - if (prev_dts < st->index_entries[i].timestamp) + prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp; + for (i = index_entry_pos; i < st->internal->nb_index_entries; i++) { + if (prev_dts < st->internal->index_entries[i].timestamp) break; - st->index_entries[i].flags |= AVINDEX_DISCARD_FRAME; + st->internal->index_entries[i].flags |= AVINDEX_DISCARD_FRAME; } // If a hole was created to insert the new index_entries into, @@ -7172,9 +7172,9 @@ static void mov_read_chapters(AVFormatContext *s) if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS; - if (st->nb_index_entries) { + if (st->internal->nb_index_entries) { // Retrieve the first frame, if possible - AVIndexEntry *sample = &st->index_entries[0]; + AVIndexEntry *sample = &st->internal->index_entries[0]; if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { av_log(s, AV_LOG_ERROR, "Failed to retrieve first frame\n"); goto finish; @@ -7190,9 +7190,9 @@ static void mov_read_chapters(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; st->discard = AVDISCARD_ALL; - for (i = 0; i < st->nb_index_entries; i++) { - AVIndexEntry *sample = &st->index_entries[i]; - int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration; + for (i = 0; i < st->internal->nb_index_entries; i++) { + AVIndexEntry *sample = &st->internal->index_entries[i]; + int64_t end = i+1 < st->internal->nb_index_entries ? st->internal->index_entries[i+1].timestamp : st->duration; uint8_t *title; uint16_t ch; int len, title_len; @@ -7265,10 +7265,10 @@ static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st) int64_t cur_pos = avio_tell(sc->pb); int hh, mm, ss, ff, drop; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) return -1; - avio_seek(sc->pb, st->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); avio_skip(s->pb, 13); hh = avio_r8(s->pb); mm = avio_r8(s->pb); @@ -7290,10 +7290,10 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) int64_t cur_pos = avio_tell(sc->pb); uint32_t value; - if (!st->nb_index_entries) + if (!st->internal->nb_index_entries) return -1; - avio_seek(sc->pb, st->index_entries->pos, SEEK_SET); + avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET); value = avio_rb32(s->pb); if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME; @@ -7757,8 +7757,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; MOVStreamContext *msc = avst->priv_data; - if (msc->pb && msc->current_sample < avst->nb_index_entries) { - AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample]; + if (msc->pb && msc->current_sample < avst->internal->nb_index_entries) { + AVIndexEntry *current_sample = &avst->internal->index_entries[msc->current_sample]; int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) || @@ -7961,8 +7961,8 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) sc->ctts_sample = 0; } } else { - int64_t next_dts = (sc->current_sample < st->nb_index_entries) ? - st->index_entries[sc->current_sample].timestamp : st->duration; + int64_t next_dts = (sc->current_sample < st->internal->nb_index_entries) ? + st->internal->index_entries[sc->current_sample].timestamp : st->duration; if (next_dts >= pkt->dts) pkt->duration = next_dts - pkt->dts; @@ -8043,7 +8043,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); - if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) + if (sample < 0 && st->internal->nb_index_entries && timestamp < st->internal->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; @@ -8098,7 +8098,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti if (mc->seek_individually) { /* adjust seek timestamp to found sample timestamp */ - int64_t seek_timestamp = st->index_entries[sample].timestamp; + int64_t seek_timestamp = st->internal->index_entries[sample].timestamp; for (i = 0; i < s->nb_streams; i++) { int64_t timestamp; diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 5e7f273c6a..53f803ef55 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -431,8 +431,8 @@ static int mp3_read_header(AVFormatContext *s) } // the seek index is relative to the end of the xing vbr headers - for (i = 0; i < st->nb_index_entries; i++) - st->index_entries[i].pos += avio_tell(s->pb); + for (i = 0; i < st->internal->nb_index_entries; i++) + st->internal->index_entries[i].pos += avio_tell(s->pb); /* the parameters will be extracted from the compressed bitstream */ return 0; @@ -567,7 +567,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, if (ret < 0) return ret; - ie = &st->index_entries[ret]; + ie = &st->internal->index_entries[ret]; } else if (fast_seek && st->duration > 0 && filesize > 0) { if (!mp3->is_cbr) av_log(s, AV_LOG_WARNING, "Using scaling to seek VBR MP3; may be imprecise.\n"); diff --git a/libavformat/mpc.c b/libavformat/mpc.c index 6a94b5d1d0..31a2072406 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -194,8 +194,8 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp uint32_t lastframe; /* if found, seek there */ - if (index >= 0 && st->index_entries[st->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){ - c->curframe = st->index_entries[index].pos; + if (index >= 0 && st->internal->index_entries[st->internal->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){ + c->curframe = st->internal->index_entries[index].pos; return 0; } /* if timestamp is out of bounds, return error */ diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index dd13bbd0a4..0002e2a9dd 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -310,9 +310,9 @@ static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestam int index = av_index_search_timestamp(st, timestamp, flags); if(index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - ff_update_cur_dts(s, st, st->index_entries[index].timestamp); + ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp); return 0; } diff --git a/libavformat/mux.c b/libavformat/mux.c index 8a53f0feeb..1cf885fbea 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1285,7 +1285,7 @@ int av_write_trailer(AVFormatContext *s) ret = s->pb ? s->pb->error : 0; for (i = 0; i < s->nb_streams; i++) { av_freep(&s->streams[i]->priv_data); - av_freep(&s->streams[i]->index_entries); + av_freep(&s->streams[i]->internal->index_entries); } if (s->oformat->priv_class) av_opt_free(s->priv_data); diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c index d5b400213d..d8f121bea5 100644 --- a/libavformat/mvdec.c +++ b/libavformat/mvdec.c @@ -431,8 +431,8 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt) int64_t ret; uint64_t pos; - if (frame < st->nb_index_entries) { - index = &st->index_entries[frame]; + if (frame < st->internal->nb_index_entries) { + index = &st->internal->index_entries[frame]; pos = avio_tell(pb); if (index->pos > pos) avio_skip(pb, index->pos - pos); diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index eb26b29450..4fab52ed36 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -682,10 +682,10 @@ static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp if(index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; - nst->frame_offset = st->index_entries[index].timestamp; + nst->frame_offset = st->internal->index_entries[index].timestamp; nsv->state = NSV_UNSYNC; return 0; } diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 3779dce2a8..53a052503e 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -1235,15 +1235,15 @@ static int read_seek(AVFormatContext *s, int stream_index, return AVERROR(ENOSYS); } - if (st->index_entries) { + if (st->internal->index_entries) { int index = av_index_search_timestamp(st, pts, flags); if (index < 0) index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD); if (index < 0) return -1; - pos2 = st->index_entries[index].pos; - ts = st->index_entries[index].timestamp; + pos2 = st->internal->index_entries[index].pos; + ts = st->internal->index_entries[index].timestamp; } else { av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, (void **) next_node); diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 6d3bf6c21e..1dcb2be1b1 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -1013,12 +1013,12 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) int index = av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD); if (index >= 0) { - sp_pos = FFMIN(sp_pos, st->index_entries[index].pos); - if (!nut->write_index && 2*index > st->nb_index_entries) { - memmove(st->index_entries, - st->index_entries + index, - sizeof(*st->index_entries) * (st->nb_index_entries - index)); - st->nb_index_entries -= index; + sp_pos = FFMIN(sp_pos, st->internal->index_entries[index].pos); + if (!nut->write_index && 2*index > st->internal->nb_index_entries) { + memmove(st->internal->index_entries, + st->internal->index_entries + index, + sizeof(*st->internal->index_entries) * (st->internal->nb_index_entries - index)); + st->internal->nb_index_entries -= index; } } } diff --git a/libavformat/rl2.c b/libavformat/rl2.c index cfde23a945..fa1b38b133 100644 --- a/libavformat/rl2.c +++ b/libavformat/rl2.c @@ -237,9 +237,9 @@ static int rl2_read_packet(AVFormatContext *s, /** check if there is a valid video or audio entry that can be used */ for(i=0; inb_streams; i++){ - if(rl2->index_pos[i] < s->streams[i]->nb_index_entries - && s->streams[i]->index_entries[ rl2->index_pos[i] ].pos < pos){ - sample = &s->streams[i]->index_entries[ rl2->index_pos[i] ]; + if(rl2->index_pos[i] < s->streams[i]->internal->nb_index_entries + && s->streams[i]->internal->index_entries[ rl2->index_pos[i] ].pos < pos){ + sample = &s->streams[i]->internal->index_entries[ rl2->index_pos[i] ]; pos= sample->pos; stream_id= i; } @@ -283,7 +283,7 @@ static int rl2_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp return -1; rl2->index_pos[stream_index] = index; - timestamp = st->index_entries[index].timestamp; + timestamp = st->internal->index_entries[index].timestamp; for(i=0; i < s->nb_streams; i++){ AVStream *st2 = s->streams[i]; diff --git a/libavformat/rpl.c b/libavformat/rpl.c index 208c50f00c..c79419d558 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -314,10 +314,10 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) stream = s->streams[rpl->chunk_part]; - if (rpl->chunk_number >= stream->nb_index_entries) + if (rpl->chunk_number >= stream->internal->nb_index_entries) return AVERROR_EOF; - index_entry = &stream->index_entries[rpl->chunk_number]; + index_entry = &stream->internal->index_entries[rpl->chunk_number]; if (rpl->frame_in_part == 0) if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0) diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c index 4d14b81d16..ce65ac6db0 100644 --- a/libavformat/segafilm.c +++ b/libavformat/segafilm.c @@ -321,7 +321,7 @@ static int film_read_seek(AVFormatContext *s, int stream_index, int64_t timestam if (ret < 0) return ret; - pos = avio_seek(s->pb, st->index_entries[ret].pos, SEEK_SET); + pos = avio_seek(s->pb, st->internal->index_entries[ret].pos, SEEK_SET); if (pos < 0) return pos; diff --git a/libavformat/tta.c b/libavformat/tta.c index 467c24455c..70e98b2937 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -155,15 +155,15 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) if (c->currentframe >= c->totalframes) return AVERROR_EOF; - if (st->nb_index_entries < c->totalframes) { + if (st->internal->nb_index_entries < c->totalframes) { av_log(s, AV_LOG_ERROR, "Index entry disappeared\n"); return AVERROR_INVALIDDATA; } - size = st->index_entries[c->currentframe].size; + size = st->internal->index_entries[c->currentframe].size; ret = av_get_packet(s->pb, pkt, size); - pkt->dts = st->index_entries[c->currentframe++].timestamp; + pkt->dts = st->internal->index_entries[c->currentframe++].timestamp; pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size : c->frame_size; return ret; @@ -176,7 +176,7 @@ static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if (index < 0) return -1; - if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) + if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0) return -1; c->currentframe = index; diff --git a/libavformat/utils.c b/libavformat/utils.c index acb9bd1cee..1e53cae103 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1913,11 +1913,11 @@ void ff_reduce_index(AVFormatContext *s, int stream_index) AVStream *st = s->streams[stream_index]; unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry); - if ((unsigned) st->nb_index_entries >= max_entries) { + if ((unsigned) st->internal->nb_index_entries >= max_entries) { int i; - for (i = 0; 2 * i < st->nb_index_entries; i++) - st->index_entries[i] = st->index_entries[2 * i]; - st->nb_index_entries = i; + for (i = 0; 2 * i < st->internal->nb_index_entries; i++) + st->internal->index_entries[i] = st->internal->index_entries[2 * i]; + st->internal->nb_index_entries = i; } } @@ -1984,8 +1984,8 @@ int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { timestamp = wrap_timestamp(st, timestamp); - return ff_add_index_entry(&st->index_entries, &st->nb_index_entries, - &st->index_entries_allocated_size, pos, + return ff_add_index_entry(&st->internal->index_entries, &st->internal->nb_index_entries, + &st->internal->index_entries_allocated_size, pos, timestamp, size, distance, flags); } @@ -2061,13 +2061,13 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) if (ist1 == ist2) continue; - for (i1 = i2 = 0; i1 < st1->nb_index_entries; i1++) { - AVIndexEntry *e1 = &st1->index_entries[i1]; + for (i1 = i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { + AVIndexEntry *e1 = &st1->internal->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); skip = FFMAX(skip, e1->size); - for (; i2 < st2->nb_index_entries; i2++) { - AVIndexEntry *e2 = &st2->index_entries[i2]; + for (; i2 < st2->internal->nb_index_entries; i2++) { + AVIndexEntry *e2 = &st2->internal->index_entries[i2]; int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q); if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance) continue; @@ -2099,7 +2099,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { - return ff_index_search_timestamp(st->index_entries, st->nb_index_entries, + return ff_index_search_timestamp(st->internal->index_entries, st->internal->nb_index_entries, wanted_timestamp, flags); } @@ -2132,7 +2132,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, pos_limit = -1; // GCC falsely says it may be uninitialized. st = s->streams[stream_index]; - if (st->index_entries) { + if (st->internal->index_entries) { AVIndexEntry *e; /* FIXME: Whole function must be checked for non-keyframe entries in @@ -2140,7 +2140,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); index = FFMAX(index, 0); - e = &st->index_entries[index]; + e = &st->internal->index_entries[index]; if (e->timestamp <= target_ts || e->pos == e->min_distance) { pos_min = e->pos; @@ -2153,9 +2153,9 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD); - av_assert0(index < st->nb_index_entries); + av_assert0(index < st->internal->nb_index_entries); if (index >= 0) { - e = &st->index_entries[index]; + e = &st->internal->index_entries[index]; av_assert1(e->timestamp >= target_ts); pos_max = e->pos; ts_max = e->timestamp; @@ -2356,17 +2356,17 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, index = av_index_search_timestamp(st, timestamp, flags); - if (index < 0 && st->nb_index_entries && - timestamp < st->index_entries[0].timestamp) + if (index < 0 && st->internal->nb_index_entries && + timestamp < st->internal->index_entries[0].timestamp) return -1; - if (index < 0 || index == st->nb_index_entries - 1) { + if (index < 0 || index == st->internal->nb_index_entries - 1) { AVPacket pkt; int nonkey = 0; - if (st->nb_index_entries) { - av_assert0(st->index_entries); - ie = &st->index_entries[st->nb_index_entries - 1]; + if (st->internal->nb_index_entries) { + av_assert0(st->internal->index_entries); + ie = &st->internal->index_entries[st->internal->nb_index_entries - 1]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; ff_update_cur_dts(s, st, ie->timestamp); @@ -2403,7 +2403,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, if (s->iformat->read_seek) if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) return 0; - ie = &st->index_entries[index]; + ie = &st->internal->index_entries[index]; if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) return ret; ff_update_cur_dts(s, st, ie->timestamp); @@ -4341,6 +4341,7 @@ static void free_stream(AVStream **pst) avcodec_free_context(&st->internal->avctx); av_bsf_free(&st->internal->bsfc); av_freep(&st->internal->priv_pts); + av_freep(&st->internal->index_entries); av_bsf_free(&st->internal->extract_extradata.bsf); av_packet_free(&st->internal->extract_extradata.pkt); @@ -4353,7 +4354,6 @@ static void free_stream(AVStream **pst) av_dict_free(&st->metadata); avcodec_parameters_free(&st->codecpar); av_freep(&st->probe_data.buf); - av_freep(&st->index_entries); #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS avcodec_free_context(&st->codec); diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c index fd1ca20c9b..d388fce92e 100644 --- a/libavformat/vocdec.c +++ b/libavformat/vocdec.c @@ -83,14 +83,14 @@ static int voc_read_seek(AVFormatContext *s, int stream_index, st = s->streams[stream_index]; index = av_index_search_timestamp(st, timestamp, flags); - if (index >= 0 && index < st->nb_index_entries - 1) { - AVIndexEntry *e = &st->index_entries[index]; + if (index >= 0 && index < st->internal->nb_index_entries - 1) { + AVIndexEntry *e = &st->internal->index_entries[index]; avio_seek(s->pb, e->pos, SEEK_SET); voc->pts = e->timestamp; voc->remaining_size = e->size; return 0; - } else if (st->nb_index_entries && st->index_entries[0].timestamp <= timestamp) { - AVIndexEntry *e = &st->index_entries[st->nb_index_entries - 1]; + } else if (st->internal->nb_index_entries && st->internal->index_entries[0].timestamp <= timestamp) { + AVIndexEntry *e = &st->internal->index_entries[st->internal->nb_index_entries - 1]; // prepare context for seek_frame_generic() voc->pts = e->timestamp; voc->remaining_size = e->size; From patchwork Fri Oct 9 13:04:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22792 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B6B0B44A971 for ; Fri, 9 Oct 2020 16:06:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A438A68BA06; Fri, 9 Oct 2020 16:06:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA6F768B9D8 for ; Fri, 9 Oct 2020 16:06:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 951492961F9 for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id fRUvh7CS3w0E for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 87BD429625D for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 6696920E0233; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:23 +0200 Message-Id: <20201009130430.602-11-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/18] lavf: move AVStream.pts_buffer to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 3 +-- libavformat/internal.h | 4 ++++ libavformat/mux.c | 12 ++++++------ libavformat/utils.c | 14 +++++++------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index dbef1b21dd..ef6d673699 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1062,11 +1062,10 @@ typedef struct AVStream { */ struct AVPacketList *last_in_packet_buffer; AVProbeData probe_data; -#define MAX_REORDER_DELAY 16 - int64_t pts_buffer[MAX_REORDER_DELAY+1]; #if LIBAVFORMAT_VERSION_MAJOR < 59 // kept for ABI compatibility only, do not access in any way + int64_t unused5[16+1]; void *unused2; int unused3; unsigned int unused4; diff --git a/libavformat/internal.h b/libavformat/internal.h index ce79da8000..23c2ce0dc3 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -308,12 +308,16 @@ struct AVStreamInternal { */ int update_initial_durations_done; +#define MAX_REORDER_DELAY 16 + /** * Internal data to generate dts from pts */ int64_t pts_reorder_error[MAX_REORDER_DELAY+1]; uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]; + int64_t pts_buffer[MAX_REORDER_DELAY+1]; + /** * Internal data to analyze DTS and detect faulty mpeg streams */ diff --git a/libavformat/mux.c b/libavformat/mux.c index 1cf885fbea..1a34ee7e96 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -595,13 +595,13 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * //calculate dts from pts if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - st->pts_buffer[0] = pkt->pts; - for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++) - st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; - for (i = 0; ipts_buffer[i] > st->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]); + st->internal->pts_buffer[0] = pkt->pts; + for (i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) + st->internal->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; + for (i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); - pkt->dts = st->pts_buffer[0]; + pkt->dts = st->internal->pts_buffer[0]; } if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && diff --git a/libavformat/utils.c b/libavformat/utils.c index 1e53cae103..6cba0cce8f 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1358,12 +1358,12 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { - st->pts_buffer[0] = pkt->pts; - for (i = 0; ipts_buffer[i] > st->pts_buffer[i + 1]; i++) - FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]); + st->internal->pts_buffer[0] = pkt->pts; + for (i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) + FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); if(has_decode_delay_been_guessed(st)) - pkt->dts = select_from_pts_buffer(st, st->pts_buffer, pkt->dts); + pkt->dts = select_from_pts_buffer(st, st->internal->pts_buffer, pkt->dts); } // We skipped it above so we try here. if (!onein_oneout) @@ -1885,7 +1885,7 @@ void ff_read_frame_flush(AVFormatContext *s) st->probe_packets = s->max_probe_packets; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) - st->pts_buffer[j] = AV_NOPTS_VALUE; + st->internal->pts_buffer[j] = AV_NOPTS_VALUE; if (s->internal->inject_global_side_data) st->internal->inject_global_side_data = 1; @@ -2866,7 +2866,7 @@ skip_duration_calc: st->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) - st->pts_buffer[j] = AV_NOPTS_VALUE; + st->internal->pts_buffer[j] = AV_NOPTS_VALUE; } } @@ -4525,7 +4525,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (i = 0; i < MAX_REORDER_DELAY + 1; i++) - st->pts_buffer[i] = AV_NOPTS_VALUE; + st->internal->pts_buffer[i] = AV_NOPTS_VALUE; st->sample_aspect_ratio = (AVRational) { 0, 1 }; From patchwork Fri Oct 9 13:04:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22795 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9AEF4449017 for ; Fri, 9 Oct 2020 16:10:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4521D68BA18; Fri, 9 Oct 2020 16:06:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E02BD68B9DA for ; Fri, 9 Oct 2020 16:06:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id E7C3429625B for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Tk6cE-1d46Xo for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 8BEC229625E for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 965C920E0234; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:24 +0200 Message-Id: <20201009130430.602-12-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/18] lavf: move AVStream.probe_data to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 2 +- libavformat/internal.h | 2 ++ libavformat/utils.c | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index ef6d673699..c99449e121 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1061,10 +1061,10 @@ typedef struct AVStream { * last packet in packet_buffer for this stream when muxing. */ struct AVPacketList *last_in_packet_buffer; - AVProbeData probe_data; #if LIBAVFORMAT_VERSION_MAJOR < 59 // kept for ABI compatibility only, do not access in any way + AVProbeData unused6; int64_t unused5[16+1]; void *unused2; int unused3; diff --git a/libavformat/internal.h b/libavformat/internal.h index 23c2ce0dc3..b8e662b96e 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -336,6 +336,8 @@ struct AVStreamInternal { * - decoding: Set by libavformat to calculate sample_aspect_ratio internally */ AVRational display_aspect_ratio; + + AVProbeData probe_data; }; #ifdef __GNUC__ diff --git a/libavformat/utils.c b/libavformat/utils.c index 6cba0cce8f..27b7b62b1a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -676,7 +676,7 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { if (st->internal->request_probe>0) { - AVProbeData *pd = &st->probe_data; + AVProbeData *pd = &st->internal->probe_data; int end; av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets); --st->probe_packets; @@ -4342,6 +4342,8 @@ static void free_stream(AVStream **pst) av_bsf_free(&st->internal->bsfc); av_freep(&st->internal->priv_pts); av_freep(&st->internal->index_entries); + av_freep(&st->internal->probe_data.buf); + av_bsf_free(&st->internal->extract_extradata.bsf); av_packet_free(&st->internal->extract_extradata.pkt); @@ -4353,7 +4355,6 @@ static void free_stream(AVStream **pst) av_dict_free(&st->metadata); avcodec_parameters_free(&st->codecpar); - av_freep(&st->probe_data.buf); #if FF_API_LAVF_AVCTX FF_DISABLE_DEPRECATION_WARNINGS avcodec_free_context(&st->codec); From patchwork Fri Oct 9 13:04:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22786 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8498744A971 for ; Fri, 9 Oct 2020 16:06:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6D95468B9F3; Fri, 9 Oct 2020 16:06:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BBAD768B9B1 for ; Fri, 9 Oct 2020 16:06:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 4C26529625A for ; Fri, 9 Oct 2020 15:06:36 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QPywWEJxwSCw for ; Fri, 9 Oct 2020 15:06:35 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id F1342296261 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id E486520E0261; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:25 +0200 Message-Id: <20201009130430.602-13-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/18] lavf: move AVStream.last_in_packet_buffer to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 6 +----- libavformat/internal.h | 5 +++++ libavformat/mux.c | 18 +++++++++--------- libavformat/mxfenc.c | 10 +++++----- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index c99449e121..9c0b25d37b 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1057,13 +1057,9 @@ typedef struct AVStream { enum AVStreamParseType need_parsing; struct AVCodecParserContext *parser; - /** - * last packet in packet_buffer for this stream when muxing. - */ - struct AVPacketList *last_in_packet_buffer; - #if LIBAVFORMAT_VERSION_MAJOR < 59 // kept for ABI compatibility only, do not access in any way + void *unused7; AVProbeData unused6; int64_t unused5[16+1]; void *unused2; diff --git a/libavformat/internal.h b/libavformat/internal.h index b8e662b96e..49e82bfbca 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -338,6 +338,11 @@ struct AVStreamInternal { AVRational display_aspect_ratio; AVProbeData probe_data; + + /** + * last packet in packet_buffer for this stream when muxing. + */ + struct AVPacketList *last_in_packet_buffer; }; #ifdef __GNUC__ diff --git a/libavformat/mux.c b/libavformat/mux.c index 1a34ee7e96..d2a56d216b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -831,8 +831,8 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, av_packet_move_ref(&this_pktl->pkt, pkt); pkt = &this_pktl->pkt; - if (st->last_in_packet_buffer) { - next_point = &(st->last_in_packet_buffer->next); + if (st->internal->last_in_packet_buffer) { + next_point = &(st->internal->last_in_packet_buffer->next); } else { next_point = &s->internal->packet_buffer; } @@ -876,7 +876,7 @@ next_non_null: this_pktl->next = *next_point; - st->last_in_packet_buffer = *next_point = this_pktl; + st->internal->last_in_packet_buffer = *next_point = this_pktl; return 0; } @@ -926,7 +926,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } for (i = 0; i < s->nb_streams; i++) { - if (s->streams[i]->last_in_packet_buffer) { + if (s->streams[i]->internal->last_in_packet_buffer) { ++stream_count; } else if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && s->streams[i]->codecpar->codec_id != AV_CODEC_ID_VP8 && @@ -951,7 +951,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, for (i = 0; i < s->nb_streams; i++) { int64_t last_dts; - const AVPacketList *last = s->streams[i]->last_in_packet_buffer; + const AVPacketList *last = s->streams[i]->internal->last_in_packet_buffer; if (!last) continue; @@ -1000,8 +1000,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->last_in_packet_buffer == pktl) - st->last_in_packet_buffer = NULL; + if (st->internal->last_in_packet_buffer == pktl) + st->internal->last_in_packet_buffer = NULL; av_packet_unref(&pktl->pkt); av_freep(&pktl); @@ -1019,8 +1019,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->last_in_packet_buffer == pktl) - st->last_in_packet_buffer = NULL; + if (st->internal->last_in_packet_buffer == pktl) + st->internal->last_in_packet_buffer = NULL; av_freep(&pktl); return 1; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index cbb0fc5a6a..d8678c9d25 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3050,7 +3050,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket int i, stream_count = 0; for (i = 0; i < s->nb_streams; i++) - stream_count += !!s->streams[i]->last_in_packet_buffer; + stream_count += !!s->streams[i]->internal->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { AVPacketList *pktl = s->internal->packet_buffer; @@ -3061,8 +3061,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (!stream_count || pktl->pkt.stream_index == 0) break; // update last packet in packet buffer - if (s->streams[pktl->pkt.stream_index]->last_in_packet_buffer != pktl) - s->streams[pktl->pkt.stream_index]->last_in_packet_buffer = pktl; + if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != pktl) + s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = pktl; last = pktl; pktl = pktl->next; stream_count--; @@ -3087,8 +3087,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); s->internal->packet_buffer = pktl->next; - if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl) - s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL; + if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) + s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; if(!s->internal->packet_buffer) s->internal->packet_buffer_end= NULL; av_freep(&pktl); From patchwork Fri Oct 9 13:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22789 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id F1E8044A971 for ; Fri, 9 Oct 2020 16:06:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD07068B9DD; Fri, 9 Oct 2020 16:06:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3665068B9C1 for ; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 8641E296261 for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id C5Un9oxiONE3 for ; Fri, 9 Oct 2020 15:06:36 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id F3578296265 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id D6F8820E0262; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:26 +0200 Message-Id: <20201009130430.602-14-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/18] lavf: move AVStream.{need_parsing, parser} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavdevice/v4l2.c | 2 +- libavformat/aacdec.c | 2 +- libavformat/aadec.c | 6 +- libavformat/acm.c | 2 +- libavformat/asfdec_f.c | 10 ++-- libavformat/av1dec.c | 2 +- libavformat/avformat.h | 6 +- libavformat/avidec.c | 16 ++--- libavformat/dtshddec.c | 2 +- libavformat/electronicarts.c | 2 +- libavformat/flacdec.c | 2 +- libavformat/flvdec.c | 4 +- libavformat/gxf.c | 6 +- libavformat/img2dec.c | 4 +- libavformat/internal.h | 4 ++ libavformat/ipudec.c | 2 +- libavformat/iv8.c | 2 +- libavformat/ivfdec.c | 2 +- libavformat/lmlm4.c | 4 +- libavformat/loasdec.c | 2 +- libavformat/lxfdec.c | 2 +- libavformat/matroskadec.c | 6 +- libavformat/mgsts.c | 2 +- libavformat/mov.c | 18 +++--- libavformat/mp3dec.c | 2 +- libavformat/mpeg.c | 2 +- libavformat/mpegts.c | 14 ++--- libavformat/msf.c | 2 +- libavformat/mtv.c | 2 +- libavformat/mxfdec.c | 8 +-- libavformat/ncdec.c | 2 +- libavformat/nsvdec.c | 4 +- libavformat/nuv.c | 2 +- libavformat/oggparseflac.c | 2 +- libavformat/oggparseogm.c | 4 +- libavformat/oggparsetheora.c | 2 +- libavformat/oggparsevp8.c | 2 +- libavformat/omadec.c | 2 +- libavformat/pva.c | 4 +- libavformat/rawdec.c | 4 +- libavformat/rmdec.c | 8 +-- libavformat/rtpdec_asf.c | 4 +- libavformat/rtsp.c | 2 +- libavformat/sdr2.c | 2 +- libavformat/segafilm.c | 2 +- libavformat/swfdec.c | 2 +- libavformat/takdec.c | 2 +- libavformat/ty.c | 4 +- libavformat/utils.c | 112 +++++++++++++++++------------------ libavformat/wavdec.c | 6 +- libavformat/wtvdec.c | 2 +- libavformat/xvag.c | 2 +- libavformat/xwma.c | 2 +- 53 files changed, 160 insertions(+), 158 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 365bacd771..960929aec3 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -961,7 +961,7 @@ static int v4l2_read_header(AVFormatContext *ctx) st->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag(st->codecpar->format); else if (codec_id == AV_CODEC_ID_H264) { - st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE; } if (desired_format == V4L2_PIX_FMT_YVU420) st->codecpar->codec_tag = MKTAG('Y', 'V', '1', '2'); diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index a0aa112a8a..70427e222b 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -112,7 +112,7 @@ static int adts_aac_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; ff_id3v1_read(s); if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && diff --git a/libavformat/aadec.c b/libavformat/aadec.c index 63f8176a57..7ada6ab07a 100644 --- a/libavformat/aadec.c +++ b/libavformat/aadec.c @@ -182,7 +182,7 @@ static int aa_read_header(AVFormatContext *s) if (!strcmp(codec_name, "mp332")) { st->codecpar->codec_id = AV_CODEC_ID_MP3; st->codecpar->sample_rate = 22050; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 8, 32000 * TIMEPREC); // encoded audio frame is MP3_FRAME_SIZE bytes (+1 with padding, unlikely) } else if (!strcmp(codec_name, "acelp85")) { @@ -191,7 +191,7 @@ static int aa_read_header(AVFormatContext *s) st->codecpar->channels = 1; st->codecpar->sample_rate = 8500; st->codecpar->bit_rate = 8500; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 8, 8500 * TIMEPREC); } else if (!strcmp(codec_name, "acelp16")) { st->codecpar->codec_id = AV_CODEC_ID_SIPR; @@ -199,7 +199,7 @@ static int aa_read_header(AVFormatContext *s) st->codecpar->channels = 1; st->codecpar->sample_rate = 16000; st->codecpar->bit_rate = 16000; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 8, 16000 * TIMEPREC); } diff --git a/libavformat/acm.c b/libavformat/acm.c index 5e03cf8bff..91f14e43aa 100644 --- a/libavformat/acm.c +++ b/libavformat/acm.c @@ -54,7 +54,7 @@ static int acm_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; st->start_time = 0; st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->channels; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index deb7c266ed..402ccaac78 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -483,9 +483,9 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) st->codecpar->codec_tag = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_AAC) - st->need_parsing = AVSTREAM_PARSE_NONE; + st->internal->need_parsing = AVSTREAM_PARSE_NONE; else - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; /* We have to init the frame size at some point .... */ pos2 = avio_tell(pb); if (size >= (pos2 + 8 - pos1 + 24)) { @@ -542,7 +542,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) st->codecpar->codec_tag = tag1; st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); if (tag1 == MKTAG('D', 'V', 'R', ' ')) { - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; /* issue658 contains wrong w/h and MS even puts a fake seq header * with wrong w/h in extradata while a correct one is in the stream. * maximum lameness */ @@ -552,9 +552,9 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) st->codecpar->extradata_size = 0; } if (st->codecpar->codec_id == AV_CODEC_ID_H264) - st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) - st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE; } pos2 = avio_tell(pb); avio_skip(pb, size - (pos2 - pos1 + 24)); diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c index 10c4560968..ad2837c831 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -66,7 +66,7 @@ static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFCon st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_AV1; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; st->internal->avctx->framerate = *framerate; // taken from rawvideo demuxers diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 9c0b25d37b..b1aab0c8ea 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1053,12 +1053,10 @@ typedef struct AVStream { */ int codec_info_nb_frames; - /* av_read_frame() support */ - enum AVStreamParseType need_parsing; - struct AVCodecParserContext *parser; - #if LIBAVFORMAT_VERSION_MAJOR < 59 // kept for ABI compatibility only, do not access in any way + int unused8; + void *unused9; void *unused7; AVProbeData unused6; int64_t unused5[16+1]; diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 80e5563bc6..bcea7f865e 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -815,19 +815,19 @@ static int avi_read_header(AVFormatContext *s) /* This is needed to get the pict type which is necessary * for generating correct pts. */ - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 && ast->handler == MKTAG('X', 'V', 'I', 'D')) st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D'); if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H')) - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; if (st->codecpar->codec_id == AV_CODEC_ID_RV40) - st->need_parsing = AVSTREAM_PARSE_NONE; + st->internal->need_parsing = AVSTREAM_PARSE_NONE; if (st->codecpar->codec_id == AV_CODEC_ID_HEVC && st->codecpar->codec_tag == MKTAG('H', '2', '6', '5')) - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 && st->codecpar->extradata_size < 1U << 30) { @@ -865,16 +865,16 @@ static int avi_read_header(AVFormatContext *s) 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->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; /* ADTS header is in extradata, AAC without header must be * stored as exact frames. Parser not needed and it will * fail. */ if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size) - st->need_parsing = AVSTREAM_PARSE_NONE; + st->internal->need_parsing = AVSTREAM_PARSE_NONE; // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) - st->need_parsing = AVSTREAM_PARSE_NONE; + st->internal->need_parsing = AVSTREAM_PARSE_NONE; /* AVI files with Xan DPCM audio (wrongly) declare PCM * audio in the header but have Axan as stream_code_tag. */ if (ast->handler == AV_RL32("Axan")) { @@ -1029,7 +1029,7 @@ end_of_header: AVStream *st = s->streams[i]; if ( st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO || st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } for (i = 0; i < s->nb_streams; i++) { diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c index b1eb7ffb2c..deb341cde9 100644 --- a/libavformat/dtshddec.c +++ b/libavformat/dtshddec.c @@ -65,7 +65,7 @@ static int dtshd_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_DTS; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; for (;;) { chunk_type = avio_rb64(pb); diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index d0f483aaf9..dcfd972f49 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -503,7 +503,7 @@ static int init_video_stream(AVFormatContext *s, VideoProperties *video) st->codecpar->codec_id = video->codec; // parsing is necessary to make FFmpeg generate correct timestamps if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; st->codecpar->codec_tag = 0; /* no fourcc */ st->codecpar->width = video->width; st->codecpar->height = video->height; diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 6aca4755a1..e7a418a3b3 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -56,7 +56,7 @@ static int flac_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_FLAC; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; /* the parameters will be extracted from the compressed bitstream */ /* if fLaC marker is not found, assume there is no header */ diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 6bddcbb556..30dd9cdcec 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -269,7 +269,7 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, break; case FLV_CODECID_MP3: apar->codec_id = AV_CODEC_ID_MP3; - astream->need_parsing = AVSTREAM_PARSE_FULL; + astream->internal->need_parsing = AVSTREAM_PARSE_FULL; break; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: // in case metadata does not otherwise declare samplerate @@ -360,7 +360,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, break; case FLV_CODECID_H264: par->codec_id = AV_CODEC_ID_H264; - vstream->need_parsing = AVSTREAM_PARSE_HEADERS; + vstream->internal->need_parsing = AVSTREAM_PARSE_HEADERS; ret = 3; // not 4, reading packet type will consume one byte break; case FLV_CODECID_MPEG4: diff --git a/libavformat/gxf.c b/libavformat/gxf.c index 96b7035386..1409895d3a 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -130,13 +130,13 @@ static int get_sindex(AVFormatContext *s, int id, int format) { case 20: st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; - st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 22: case 23: st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG1VIDEO; - st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; @@ -169,7 +169,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) { case 29: /* AVCHD */ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_H264; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; break; // timecode tracks: case 7: diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 3f217d5916..9dc0414efe 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -209,7 +209,7 @@ int ff_img_read_header(AVFormatContext *s1) s->is_pipe = 0; else { s->is_pipe = 1; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } if (s->ts_from_file == 2) { @@ -479,7 +479,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) return AVERROR_EOF; if (s->frame_size > 0) { size[0] = s->frame_size; - } else if (!s1->streams[0]->parser) { + } else if (!s1->streams[0]->internal->parser) { size[0] = avio_size(s1->pb); } else { size[0] = 4096; diff --git a/libavformat/internal.h b/libavformat/internal.h index 49e82bfbca..496bd46ef0 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -343,6 +343,10 @@ struct AVStreamInternal { * last packet in packet_buffer for this stream when muxing. */ struct AVPacketList *last_in_packet_buffer; + + /* av_read_frame() support */ + enum AVStreamParseType need_parsing; + struct AVCodecParserContext *parser; }; #ifdef __GNUC__ diff --git a/libavformat/ipudec.c b/libavformat/ipudec.c index df53df00d9..281ec66340 100644 --- a/libavformat/ipudec.c +++ b/libavformat/ipudec.c @@ -62,7 +62,7 @@ static int ipu_read_header(AVFormatContext *s) st->start_time = 0; st->duration = st->nb_frames = avio_rl32(pb); - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, 25); return 0; diff --git a/libavformat/iv8.c b/libavformat/iv8.c index e25f24eeb9..03cfe9baaa 100644 --- a/libavformat/iv8.c +++ b/libavformat/iv8.c @@ -47,7 +47,7 @@ static int read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG4; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 90000); return 0; diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c index 4a802573e7..8f089f9c42 100644 --- a/libavformat/ivfdec.c +++ b/libavformat/ivfdec.c @@ -56,7 +56,7 @@ static int read_header(AVFormatContext *s) st->duration = avio_rl32(s->pb); avio_skip(s->pb, 4); // unused - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; if (!time_base.den || !time_base.num) { av_log(s, AV_LOG_ERROR, "Invalid frame rate\n"); diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c index 79d703a8fc..c2490c94ec 100644 --- a/libavformat/lmlm4.c +++ b/libavformat/lmlm4.c @@ -67,14 +67,14 @@ static int lmlm4_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG4; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; avpriv_set_pts_info(st, 64, 1001, 30000); if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP2; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; /* the parameters will be extracted from the compressed bitstream */ return 0; diff --git a/libavformat/loasdec.c b/libavformat/loasdec.c index e166a5928a..b39dbb8a44 100644 --- a/libavformat/loasdec.c +++ b/libavformat/loasdec.c @@ -75,7 +75,7 @@ static int loas_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; //LCM of all possible AAC sample rates avpriv_set_pts_info(st, 64, 1, 28224000); diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c index fa84ceea78..526d652f43 100644 --- a/libavformat/lxfdec.c +++ b/libavformat/lxfdec.c @@ -260,7 +260,7 @@ static int lxf_read_header(AVFormatContext *s) st->codecpar->bit_rate = 1000000 * ((video_params >> 14) & 0xFF); st->codecpar->codec_tag = video_params & 0xF; st->codecpar->codec_id = ff_codec_get_id(lxf_tags, st->codecpar->codec_tag); - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; av_log(s, AV_LOG_DEBUG, "record: %x = %i-%02i-%02i\n", record_date, 1900 + (record_date & 0x7F), (record_date >> 7) & 0xF, diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 981e044263..98214e1222 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2734,7 +2734,7 @@ static int matroska_parse_tracks(AVFormatContext *s) 255); } if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->default_duration) { av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, @@ -2792,9 +2792,9 @@ static int matroska_parse_tracks(AVFormatContext *s) if (st->codecpar->codec_id == AV_CODEC_ID_MP3 || st->codecpar->codec_id == AV_CODEC_ID_MLP || st->codecpar->codec_id == AV_CODEC_ID_TRUEHD) - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; else if (st->codecpar->codec_id != AV_CODEC_ID_AAC) - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->codec_delay > 0) { st->codecpar->initial_padding = av_rescale_q(track->codec_delay, (AVRational){1, 1000000000}, diff --git a/libavformat/mgsts.c b/libavformat/mgsts.c index 415e052725..6b0a748b77 100644 --- a/libavformat/mgsts.c +++ b/libavformat/mgsts.c @@ -50,7 +50,7 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; st->start_time = 0; st->nb_frames = st->duration = avio_rb32(pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index 57ac212146..a41c358a2a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2165,7 +2165,7 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, switch (st->codecpar->codec_id) { case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; break; } } @@ -2421,10 +2421,10 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, case AV_CODEC_ID_VC1: case AV_CODEC_ID_VP8: case AV_CODEC_ID_VP9: - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_AV1: - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; break; default: break; @@ -2768,8 +2768,8 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!entries) { sc->keyframe_absent = 1; - if (!st->need_parsing && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) - st->need_parsing = AVSTREAM_PARSE_HEADERS; + if (!st->internal->need_parsing && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; return 0; } if (sc->keyframes) @@ -4312,7 +4312,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) && sc->stts_count > 3 && sc->stts_count*10 > st->nb_frames && sc->time_scale == st->codecpar->sample_rate) { - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } /* Do not need those anymore. */ av_freep(&sc->chunk_offsets); @@ -7634,7 +7634,7 @@ static int mov_read_header(AVFormatContext *s) mov->handbrake_version <= 1000000*0 + 1000*10 + 2 && // 0.10.2 st->codecpar->codec_id == AV_CODEC_ID_MP3) { av_log(s, AV_LOG_VERBOSE, "Forcing full parsing for mp3 stream\n"); - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } } @@ -7940,9 +7940,9 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) sc->has_palette = 0; } } - if (st->codecpar->codec_id == AV_CODEC_ID_MP3 && !st->need_parsing && pkt->size > 4) { + if (st->codecpar->codec_id == AV_CODEC_ID_MP3 && !st->internal->need_parsing && pkt->size > 4) { if (ff_mpa_check_header(AV_RB32(pkt->data)) < 0) - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } } diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 53f803ef55..fe12cd4fc7 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -374,7 +374,7 @@ static int mp3_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP3; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; // lcm of all mp3 sample rates diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 20d1e10168..c25d76fc60 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -623,7 +623,7 @@ skip: st->codecpar->sample_rate = 8000; } st->internal->request_probe = request_probe; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; found: if (st->discard >= AVDISCARD_ALL) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 7cf14a1d13..6135d05477 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -903,7 +903,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, st->priv_data = pes; st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_NONE; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; pes->stream_type = stream_type; @@ -941,7 +941,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, sub_st->priv_data = sub_pes; sub_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; sub_st->codecpar->codec_id = AV_CODEC_ID_AC3; - sub_st->need_parsing = AVSTREAM_PARSE_FULL; + sub_st->internal->need_parsing = AVSTREAM_PARSE_FULL; sub_pes->sub_st = pes->sub_st = sub_st; } } @@ -1716,10 +1716,10 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, ff_mp4_read_dec_config_descr(s, st, &pb); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) - st->need_parsing = 0; + st->internal->need_parsing = 0; if (st->codecpar->codec_id == AV_CODEC_ID_H264 && st->codecpar->extradata_size > 0) - st->need_parsing = 0; + st->internal->need_parsing = 0; st->codecpar->codec_type = avcodec_get_type(st->codecpar->codec_id); st->internal->need_context_update = 1; @@ -1825,7 +1825,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type ff_mp4_read_dec_config_descr(fc, st, &pb); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { - st->need_parsing = 0; + st->internal->need_parsing = 0; st->internal->need_context_update = 1; } if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4SYSTEMS) @@ -1847,7 +1847,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type ff_mp4_read_dec_config_descr(fc, st, &pb); if (st->codecpar->codec_id == AV_CODEC_ID_AAC && st->codecpar->extradata_size > 0) { - st->internal->request_probe = st->need_parsing = 0; + st->internal->request_probe = st->internal->need_parsing = 0; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->internal->need_context_update = 1; } @@ -2032,7 +2032,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type } else { avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); } - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; st->internal->need_context_update = 1; } } diff --git a/libavformat/msf.c b/libavformat/msf.c index 155f488e44..0927af43ff 100644 --- a/libavformat/msf.c +++ b/libavformat/msf.c @@ -80,7 +80,7 @@ static int msf_read_header(AVFormatContext *s) AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0); /* joint stereo (repeat?) */ AV_WL16(st->codecpar->extradata+10, 1); st->codecpar->codec_id = AV_CODEC_ID_ATRAC3; break; - case 7: st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + case 7: st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->codecpar->codec_id = AV_CODEC_ID_MP3; break; default: avpriv_request_sample(s, "Codec %d", codec); diff --git a/libavformat/mtv.c b/libavformat/mtv.c index e731d91077..6526caded2 100644 --- a/libavformat/mtv.c +++ b/libavformat/mtv.c @@ -185,7 +185,7 @@ static int mtv_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP3; st->codecpar->bit_rate = mtv->audio_br; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; // Jump over header diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 1f79f3d3cd..f9097a01a0 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -2578,7 +2578,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } } - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; if (material_track->sequence->origin) { av_dict_set_int(&st->metadata, "material_track_origin", material_track->sequence->origin, 0); } @@ -2643,7 +2643,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) else if (descriptor->bits_per_sample == 32) st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id); } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { @@ -2677,7 +2677,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } if (st->codecpar->codec_type != AVMEDIA_TYPE_DATA && source_track->wrapping != FrameWrapped) { /* TODO: decode timestamps */ - st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; + st->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; } } @@ -3612,7 +3612,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) if (next_ofs <= 0) { // If we have no way to packetize the data, then return it in chunks... if (klv.next_klv - klv.length == pos && max_data_size > MXF_MAX_CHUNK_SIZE) { - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; avpriv_request_sample(s, "Huge KLV without proper index in non-frame wrapped essence"); } size = FFMIN(max_data_size, MXF_MAX_CHUNK_SIZE); diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c index f2066b485a..b2d033bc6e 100644 --- a/libavformat/ncdec.c +++ b/libavformat/ncdec.c @@ -53,7 +53,7 @@ static int nc_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG4; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 100); diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 4fab52ed36..376ed76534 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -462,7 +462,7 @@ static int nsv_parse_NSVs_header(AVFormatContext *s) st->codecpar->codec_tag = atag; st->codecpar->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); - st->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ + st->internal->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ /* set timebase to common denominator of ms and framerate */ avpriv_set_pts_info(st, 64, 1, framerate.num*1000); @@ -615,7 +615,7 @@ null_chunk_retry: asize-=4; av_log(s, AV_LOG_TRACE, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate); if (fill_header) { - st[NSV_ST_AUDIO]->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */ + st[NSV_ST_AUDIO]->internal->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */ if (bps != 16) { av_log(s, AV_LOG_TRACE, "NSV AUDIO bit/sample != 16 (%d)!!!\n", bps); } diff --git a/libavformat/nuv.c b/libavformat/nuv.c index d99770d41d..8ebcdddce4 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -128,7 +128,7 @@ static int get_codec_data(AVFormatContext *s, AVIOContext *pb, AVStream *vst, } ast->codecpar->codec_id = id; - ast->need_parsing = AVSTREAM_PARSE_FULL; + ast->internal->need_parsing = AVSTREAM_PARSE_FULL; } else avio_skip(pb, 4 * 4); diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index 4e85b05c67..15eeca56aa 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -59,7 +59,7 @@ flac_header (AVFormatContext * s, int idx) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_FLAC; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; if ((ret = ff_alloc_extradata(st->codecpar, FLAC_STREAMINFO_SIZE)) < 0) return ret; diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index 469b229995..a8319b9dfa 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -60,7 +60,7 @@ ogm_header(AVFormatContext *s, int idx) st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); st->codecpar->codec_tag = tag; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (bytestream2_peek_byte(&p) == 't') { st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_TEXT; @@ -76,7 +76,7 @@ ogm_header(AVFormatContext *s, int idx) st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); // our parser completely breaks AAC in Ogg if (st->codecpar->codec_id != AV_CODEC_ID_AAC) - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } size = bytestream2_get_le32(&p); diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c index d1064e4328..28684f6ea9 100644 --- a/libavformat/oggparsetheora.c +++ b/libavformat/oggparsetheora.c @@ -112,7 +112,7 @@ static int theora_header(AVFormatContext *s, int idx) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_THEORA; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; } break; case 0x81: diff --git a/libavformat/oggparsevp8.c b/libavformat/oggparsevp8.c index b76ac71cc5..85b3627c9c 100644 --- a/libavformat/oggparsevp8.c +++ b/libavformat/oggparsevp8.c @@ -61,7 +61,7 @@ static int vp8_header(AVFormatContext *s, int idx) avpriv_set_pts_info(st, 64, framerate.den, framerate.num); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_VP8; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; break; case 0x02: if (p[6] != 0x20) diff --git a/libavformat/omadec.c b/libavformat/omadec.c index 5675d86e75..c4799e9fdc 100644 --- a/libavformat/omadec.c +++ b/libavformat/omadec.c @@ -506,7 +506,7 @@ static int oma_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, 1, samplerate); break; case OMA_CODECID_MP3: - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; framesize = 1024; break; case OMA_CODECID_LPCM: diff --git a/libavformat/pva.c b/libavformat/pva.c index 58ec78750c..4d348417c8 100644 --- a/libavformat/pva.c +++ b/libavformat/pva.c @@ -61,7 +61,7 @@ static int pva_read_header(AVFormatContext *s) { return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 32, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); @@ -69,7 +69,7 @@ static int pva_read_header(AVFormatContext *s) { return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_MP2; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 33, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 10c37c5cb9..aa5ac23cdc 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -60,7 +60,7 @@ int ff_raw_audio_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; /* the parameters will be extracted from the compressed bitstream */ @@ -83,7 +83,7 @@ int ff_raw_video_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = s->iformat->raw_codec_id; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->internal->avctx->framerate = s1->framerate; avpriv_set_pts_info(st, 64, 1, 1200000); diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 72b8dba741..bafd1a2000 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -200,7 +200,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, switch (st->codecpar->codec_id) { case AV_CODEC_ID_AC3: - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_RA_288: st->codecpar->extradata_size= 0; @@ -209,7 +209,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, st->codecpar->block_align = coded_framesize; break; case AV_CODEC_ID_COOK: - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; case AV_CODEC_ID_ATRAC3: case AV_CODEC_ID_SIPR: if (read_all) { @@ -233,7 +233,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, return -1; } st->codecpar->block_align = ff_sipr_subpk_size[flavor]; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; } else { if(sub_packet_size <= 0){ av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n"); @@ -386,7 +386,7 @@ int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb, avio_skip(pb, 2); // looks like bits per sample avio_skip(pb, 4); // always zero? st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; + st->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; fps = avio_rb32(pb); if ((ret = rm_read_extradata(s, pb, st->codecpar, codec_data_size - (avio_tell(pb) - codec_pos))) < 0) diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index e58f0260f3..3b8d16ec46 100644 --- a/libavformat/rtpdec_asf.c +++ b/libavformat/rtpdec_asf.c @@ -167,8 +167,8 @@ static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, if (s->streams[stream_index]->id == rt->asf_ctx->streams[i]->id) { avcodec_parameters_copy(s->streams[stream_index]->codecpar, rt->asf_ctx->streams[i]->codecpar); - s->streams[stream_index]->need_parsing = - rt->asf_ctx->streams[i]->need_parsing; + s->streams[stream_index]->internal->need_parsing = + rt->asf_ctx->streams[i]->internal->need_parsing; avpriv_set_pts_info(s->streams[stream_index], 32, 1, 1000); } } diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 2ce09477ed..5d01b91b1e 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -226,7 +226,7 @@ static void init_rtp_handler(const RTPDynamicProtocolHandler *handler, par->codec_id = handler->codec_id; rtsp_st->dynamic_handler = handler; if (st) - st->need_parsing = handler->need_parsing; + st->internal->need_parsing = handler->need_parsing; if (handler->priv_data_size) { rtsp_st->dynamic_protocol_context = av_mallocz(handler->priv_data_size); if (!rtsp_st->dynamic_protocol_context) diff --git a/libavformat/sdr2.c b/libavformat/sdr2.c index 3743d59e58..496870bb3b 100644 --- a/libavformat/sdr2.c +++ b/libavformat/sdr2.c @@ -51,7 +51,7 @@ static int sdr2_read_header(AVFormatContext *s) st->codecpar->width = avio_rl32(s->pb); st->codecpar->height = avio_rl32(s->pb); st->codecpar->codec_id = AV_CODEC_ID_H264; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ast->codecpar->channels = 1; diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c index ce65ac6db0..22362c4561 100644 --- a/libavformat/segafilm.c +++ b/libavformat/segafilm.c @@ -180,7 +180,7 @@ static int film_read_header(AVFormatContext *s) if (film->audio_type == AV_CODEC_ID_ADPCM_ADX) { st->codecpar->bits_per_coded_sample = 18 * 8 / 32; st->codecpar->block_align = st->codecpar->channels * 18; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; } else { st->codecpar->bits_per_coded_sample = film->audio_bits; st->codecpar->block_align = st->codecpar->channels * diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index fa11c050cd..8f9b1ab7ce 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -203,7 +203,7 @@ static AVStream *create_new_audio_stream(AVFormatContext *s, int id, int info) } ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ast->codecpar->codec_id = ff_codec_get_id(swf_audio_codec_tags, info>>4 & 15); - ast->need_parsing = AVSTREAM_PARSE_FULL; + ast->internal->need_parsing = AVSTREAM_PARSE_FULL; sample_rate_code = info>>2 & 3; sample_size_code = info>>1 & 1; if (!sample_size_code && ast->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) diff --git a/libavformat/takdec.c b/libavformat/takdec.c index 6d18b6af21..8929be8f24 100644 --- a/libavformat/takdec.c +++ b/libavformat/takdec.c @@ -65,7 +65,7 @@ static int tak_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_TAK; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; tc->mlast_frame = 0; if (avio_rl32(pb) != MKTAG('t', 'B', 'a', 'K')) { diff --git a/libavformat/ty.c b/libavformat/ty.c index c8e1067c0e..96af6952e6 100644 --- a/libavformat/ty.c +++ b/libavformat/ty.c @@ -308,7 +308,7 @@ static int ty_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(st, 64, 1, 90000); ast = avformat_new_stream(s, NULL); @@ -318,7 +318,7 @@ static int ty_read_header(AVFormatContext *s) if (ty->audio_type == TIVO_AUDIO_MPEG) { ast->codecpar->codec_id = AV_CODEC_ID_MP2; - ast->need_parsing = AVSTREAM_PARSE_FULL_RAW; + ast->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; } else { ast->codecpar->codec_id = AV_CODEC_ID_AC3; } diff --git a/libavformat/utils.c b/libavformat/utils.c index 27b7b62b1a..4d281a9ce8 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -144,7 +144,7 @@ int64_t av_stream_get_end_pts(const AVStream *st) struct AVCodecParserContext *av_stream_get_parser(const AVStream *st) { - return st->parser; + return st->internal->parser; } void av_format_inject_global_side_data(AVFormatContext *s) @@ -472,9 +472,9 @@ static int update_stream_avctx(AVFormatContext *s) continue; /* close parser, because it depends on the codec */ - if (st->parser && st->internal->avctx->codec_id != st->codecpar->codec_id) { - av_parser_close(st->parser); - st->parser = NULL; + if (st->internal->parser && st->internal->avctx->codec_id != st->codecpar->codec_id) { + av_parser_close(st->internal->parser); + st->internal->parser = NULL; } /* update internal codec context, for the parser */ @@ -1287,7 +1287,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* Correct timestamps with byte offset if demuxers only have timestamps * on packet boundaries */ - if (pc && st->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { + if (pc && st->internal->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { /* this will estimate bitrate based on this frame's duration and size */ offset = av_rescale(pc->offset, pkt->duration, pkt->size); if (pkt->pts != AV_NOPTS_VALUE) @@ -1404,9 +1404,9 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, if (size || flush) { av_init_packet(&out_pkt); - } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { + } else if (st->internal->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { // preserve 0-size sync packets - compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); + compute_pkt_fields(s, st, st->internal->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); } while (size > 0 || (flush && got_output)) { @@ -1414,7 +1414,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int64_t next_pts = pkt->pts; int64_t next_dts = pkt->dts; - len = av_parser_parse2(st->parser, st->internal->avctx, + len = av_parser_parse2(st->internal->parser, st->internal->avctx, &out_pkt.data, &out_pkt.size, data, size, pkt->pts, pkt->dts, pkt->pos); @@ -1432,7 +1432,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, if (pkt->buf && out_pkt.data == pkt->data) { /* reference pkt->buf only when out_pkt.data is guaranteed to point * to data in it and not in the parser's internal buffer. */ - /* XXX: Ensure this is the case with all parsers when st->parser->flags + /* XXX: Ensure this is the case with all parsers when st->internal->parser->flags * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ out_pkt.buf = av_buffer_ref(pkt->buf); if (!out_pkt.buf) { @@ -1453,11 +1453,11 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, } /* set the duration */ - out_pkt.duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; + out_pkt.duration = (st->internal->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->internal->avctx->sample_rate > 0) { out_pkt.duration = - av_rescale_q_rnd(st->parser->duration, + av_rescale_q_rnd(st->internal->parser->duration, (AVRational) { 1, st->internal->avctx->sample_rate }, st->time_base, AV_ROUND_DOWN); @@ -1465,23 +1465,23 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, } out_pkt.stream_index = st->index; - out_pkt.pts = st->parser->pts; - out_pkt.dts = st->parser->dts; - out_pkt.pos = st->parser->pos; + out_pkt.pts = st->internal->parser->pts; + out_pkt.dts = st->internal->parser->dts; + out_pkt.pos = st->internal->parser->pos; out_pkt.flags |= pkt->flags & AV_PKT_FLAG_DISCARD; - if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW) - out_pkt.pos = st->parser->frame_offset; + if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_RAW) + out_pkt.pos = st->internal->parser->frame_offset; - if (st->parser->key_frame == 1 || - (st->parser->key_frame == -1 && - st->parser->pict_type == AV_PICTURE_TYPE_I)) + if (st->internal->parser->key_frame == 1 || + (st->internal->parser->key_frame == -1 && + st->internal->parser->pict_type == AV_PICTURE_TYPE_I)) out_pkt.flags |= AV_PKT_FLAG_KEY; - if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) + if (st->internal->parser->key_frame == -1 && st->internal->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) out_pkt.flags |= AV_PKT_FLAG_KEY; - compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts); + compute_pkt_fields(s, st, st->internal->parser, &out_pkt, next_dts, next_pts); ret = avpriv_packet_list_put(&s->internal->parse_queue, &s->internal->parse_queue_end, @@ -1494,8 +1494,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, /* end of the stream => close and free the parser */ if (flush) { - av_parser_close(st->parser); - st->parser = NULL; + av_parser_close(st->internal->parser); + st->internal->parser = NULL; } fail: @@ -1524,7 +1524,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) /* flush the parsers */ for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->parser && st->need_parsing) + if (st->internal->parser && st->internal->need_parsing) parse_packet(s, pkt, st->index, 1); } /* all remaining packets are now in parse_queue => @@ -1543,9 +1543,9 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } /* close parser, because it depends on the codec */ - if (st->parser && st->internal->avctx->codec_id != st->codecpar->codec_id) { - av_parser_close(st->parser); - st->parser = NULL; + if (st->internal->parser && st->internal->avctx->codec_id != st->codecpar->codec_id) { + av_parser_close(st->internal->parser); + st->internal->parser = NULL; } ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar); @@ -1586,23 +1586,23 @@ FF_ENABLE_DEPRECATION_WARNINGS av_ts2str(pkt->dts), pkt->size, pkt->duration, pkt->flags); - if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { - st->parser = av_parser_init(st->codecpar->codec_id); - if (!st->parser) { + if (st->internal->need_parsing && !st->internal->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { + st->internal->parser = av_parser_init(st->codecpar->codec_id); + if (!st->internal->parser) { av_log(s, AV_LOG_VERBOSE, "parser not found for codec " "%s, packets or times may be invalid.\n", avcodec_get_name(st->codecpar->codec_id)); /* no parser available: just output the raw packets */ - st->need_parsing = AVSTREAM_PARSE_NONE; - } else if (st->need_parsing == AVSTREAM_PARSE_HEADERS) - st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; - else if (st->need_parsing == AVSTREAM_PARSE_FULL_ONCE) - st->parser->flags |= PARSER_FLAG_ONCE; - else if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW) - st->parser->flags |= PARSER_FLAG_USE_CODEC_TS; + st->internal->need_parsing = AVSTREAM_PARSE_NONE; + } else if (st->internal->need_parsing == AVSTREAM_PARSE_HEADERS) + st->internal->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + else if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_ONCE) + st->internal->parser->flags |= PARSER_FLAG_ONCE; + else if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_RAW) + st->internal->parser->flags |= PARSER_FLAG_USE_CODEC_TS; } - if (!st->need_parsing || !st->parser) { + if (!st->internal->need_parsing || !st->internal->parser) { /* no parsing needed: we just output the packet as is */ compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && @@ -1870,9 +1870,9 @@ void ff_read_frame_flush(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->parser) { - av_parser_close(st->parser); - st->parser = NULL; + if (st->internal->parser) { + av_parser_close(st->internal->parser); + st->internal->parser = NULL; } st->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; @@ -2759,9 +2759,9 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) av_log(ic, AV_LOG_WARNING, "start time for stream %d is not set in estimate_timings_from_pts\n", i); - if (st->parser) { - av_parser_close(st->parser); - st->parser = NULL; + if (st->internal->parser) { + av_parser_close(st->internal->parser); + st->internal->parser = NULL; } } @@ -2797,7 +2797,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) (st->start_time != AV_NOPTS_VALUE || st->first_dts != AV_NOPTS_VALUE)) { if (pkt->duration == 0) { - ff_compute_frame_duration(ic, &num, &den, st, st->parser, pkt); + ff_compute_frame_duration(ic, &num, &den, st, st->internal->parser, pkt); if (den && num) { pkt->duration = av_rescale_rnd(1, num * (int64_t) st->time_base.den, @@ -3606,15 +3606,15 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif // only for the split stuff - if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->internal->request_probe <= 0) { - st->parser = av_parser_init(st->codecpar->codec_id); - if (st->parser) { - if (st->need_parsing == AVSTREAM_PARSE_HEADERS) { - st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; - } else if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW) { - st->parser->flags |= PARSER_FLAG_USE_CODEC_TS; + if (!st->internal->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->internal->request_probe <= 0) { + st->internal->parser = av_parser_init(st->codecpar->codec_id); + if (st->internal->parser) { + if (st->internal->need_parsing == AVSTREAM_PARSE_HEADERS) { + st->internal->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + } else if (st->internal->need_parsing == AVSTREAM_PARSE_FULL_RAW) { + st->internal->parser->flags |= PARSER_FLAG_USE_CODEC_TS; } - } else if (st->need_parsing) { + } else if (st->internal->need_parsing) { av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " "%s, packets or times may be invalid.\n", avcodec_get_name(st->codecpar->codec_id)); @@ -3857,7 +3857,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->internal->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->internal->info->codec_info_duration + pkt->duration); } else st->internal->info->codec_info_duration += pkt->duration; - st->internal->info->codec_info_duration_fields += st->parser && st->need_parsing && avctx->ticks_per_frame ==2 ? st->parser->repeat_pict + 1 : 2; + st->internal->info->codec_info_duration_fields += st->internal->parser && st->internal->need_parsing && avctx->ticks_per_frame ==2 ? st->internal->parser->repeat_pict + 1 : 2; } } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -4331,8 +4331,8 @@ static void free_stream(AVStream **pst) av_freep(&st->side_data[i].data); av_freep(&st->side_data); - if (st->parser) - av_parser_close(st->parser); + if (st->internal->parser) + av_parser_close(st->internal->parser); if (st->attached_pic.data) av_packet_unref(&st->attached_pic); diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index bca186a66f..9b93cfce8e 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -175,7 +175,7 @@ static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st) return ret; handle_stream_probing(*st); - (*st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; + (*st)->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avpriv_set_pts_info(*st, 64, 1, (*st)->codecpar->sample_rate); @@ -196,7 +196,7 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t size, AVStream **st) (*st)->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; (*st)->codecpar->codec_id = AV_CODEC_ID_XMA2; - (*st)->need_parsing = AVSTREAM_PARSE_FULL_RAW; + (*st)->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; version = avio_r8(pb); if (version != 3 && version != 4) @@ -943,7 +943,7 @@ static int w64_read_header(AVFormatContext *s) ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); handle_stream_probing(st); - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; avio_seek(pb, data_ofs, SEEK_SET); diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index 83f510b92f..fe665af10c 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -621,7 +621,7 @@ static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int code st->priv_data = wst; } st->codecpar->codec_type = codec_type; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 10000000); return st; } diff --git a/libavformat/xvag.c b/libavformat/xvag.c index e95d84aa3f..b79c89f09e 100644 --- a/libavformat/xvag.c +++ b/libavformat/xvag.c @@ -87,7 +87,7 @@ static int xvag_read_header(AVFormatContext *s) if (avio_rb16(s->pb) == 0xFFFB) { st->codecpar->codec_id = AV_CODEC_ID_MP3; st->codecpar->block_align = 0x1000; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW; } avio_skip(s->pb, -2); diff --git a/libavformat/xwma.c b/libavformat/xwma.c index 5a57caa841..c5e9db1e72 100644 --- a/libavformat/xwma.c +++ b/libavformat/xwma.c @@ -78,7 +78,7 @@ static int xwma_read_header(AVFormatContext *s) ret = ff_get_wav_header(s, pb, st->codecpar, size, 0); if (ret < 0) return ret; - st->need_parsing = AVSTREAM_PARSE_NONE; + st->internal->need_parsing = AVSTREAM_PARSE_NONE; /* XWMA encoder only allows a few channel/sample rate/bitrate combinations, * but some create identical files with fake bitrate (1ch 22050hz at From patchwork Fri Oct 9 13:04:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22788 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2933344A971 for ; Fri, 9 Oct 2020 16:06:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 13B2868B9D9; Fri, 9 Oct 2020 16:06:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D94768B9B6 for ; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id DF58B296264 for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 7JLYW4_L4Waj for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id F2158296262 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id C82D420E0263; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:27 +0200 Message-Id: <20201009130430.602-15-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/18] ffmpeg: stop using non-public AVStream fields X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This effectively reverts ae2cb9290ac and 52c5521877a. --- fftools/ffmpeg_opt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 19f719e3ff..a5c92bf461 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2215,7 +2215,7 @@ static int open_output_file(OptionsContext *o, const char *filename) for (i = 0; i < nb_input_streams; i++) { int new_area; ist = input_streams[i]; - new_area = ist->st->codecpar->width * ist->st->codecpar->height + 100000000*!!ist->st->codec_info_nb_frames + new_area = ist->st->codecpar->width * ist->st->codecpar->height + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); if (ist->user_set_discard == AVDISCARD_ALL) continue; @@ -2239,7 +2239,7 @@ static int open_output_file(OptionsContext *o, const char *filename) for (i = 0; i < nb_input_streams; i++) { int score; ist = input_streams[i]; - score = ist->st->codecpar->channels + 100000000*!!ist->st->codec_info_nb_frames + score = ist->st->codecpar->channels + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); if (ist->user_set_discard == AVDISCARD_ALL) continue; From patchwork Fri Oct 9 13:04:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22797 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8AFF4449017 for ; Fri, 9 Oct 2020 16:10:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 332A368BA27; Fri, 9 Oct 2020 16:06:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 472E468B9D2 for ; Fri, 9 Oct 2020 16:06:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 47F3D29625E for ; Fri, 9 Oct 2020 15:06:35 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0R0vRJgrZaTm for ; Fri, 9 Oct 2020 15:06:34 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 98679296260 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id ADCA020E025F; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:28 +0200 Message-Id: <20201009130430.602-16-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/18] lavf: move AVStream.{probe_packets, codec_info_nb_frames} to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 12 ++------- libavformat/dump.c | 3 ++- libavformat/internal.h | 10 +++++++ libavformat/mpegts.c | 2 +- libavformat/sbgdec.c | 2 +- libavformat/tedcaptionsdec.c | 2 +- libavformat/utils.c | 46 ++++++++++++++++---------------- libavformat/wavdec.c | 2 +- tests/api/api-codec-param-test.c | 5 ++-- 9 files changed, 44 insertions(+), 40 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index b1aab0c8ea..6168062ce1 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1043,18 +1043,10 @@ typedef struct AVStream { int64_t last_IP_pts; int last_IP_duration; - /** - * Number of packets to buffer for codec probing - */ - int probe_packets; - - /** - * Number of frames that have been demuxed during avformat_find_stream_info() - */ - int codec_info_nb_frames; - #if LIBAVFORMAT_VERSION_MAJOR < 59 // kept for ABI compatibility only, do not access in any way + int unused10; + int unused11; int unused8; void *unused9; void *unused7; diff --git a/libavformat/dump.c b/libavformat/dump.c index fe628010d3..0554bf667d 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -37,6 +37,7 @@ #include "libavutil/timecode.h" #include "avformat.h" +#include "internal.h" #define HEXDUMP_PRINT(...) \ do { \ @@ -551,7 +552,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); if (lang) av_log(NULL, AV_LOG_INFO, "(%s)", lang->value); - av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames, + av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->internal->codec_info_nb_frames, st->time_base.num, st->time_base.den); av_log(NULL, AV_LOG_INFO, ": %s", buf); diff --git a/libavformat/internal.h b/libavformat/internal.h index 496bd46ef0..edc8bbae80 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -347,6 +347,16 @@ struct AVStreamInternal { /* av_read_frame() support */ enum AVStreamParseType need_parsing; struct AVCodecParserContext *parser; + + /** + * Number of packets to buffer for codec probing + */ + int probe_packets; + + /** + * Number of frames that have been demuxed during avformat_find_stream_info() + */ + int codec_info_nb_frames; }; #ifdef __GNUC__ diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 6135d05477..86f943375a 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -953,7 +953,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, } if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->internal->request_probe > 0 && st->internal->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && - st->probe_packets > 0 && + st->internal->probe_packets > 0 && stream_type == STREAM_TYPE_PRIVATE_DATA) { st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c index c11244ef3d..d8efb9d9fb 100644 --- a/libavformat/sbgdec.c +++ b/libavformat/sbgdec.c @@ -1423,7 +1423,7 @@ static av_cold int sbg_read_header(AVFormatContext *avf) st->codecpar->sample_rate = sbg->sample_rate; st->codecpar->frame_size = sbg->frame_size; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); - st->probe_packets = 0; + st->internal->probe_packets = 0; st->start_time = av_rescale(script.start_ts, sbg->sample_rate, AV_TIME_BASE); st->duration = script.end_ts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : diff --git a/libavformat/tedcaptionsdec.c b/libavformat/tedcaptionsdec.c index 6c25d602d6..9ccb1f886d 100644 --- a/libavformat/tedcaptionsdec.c +++ b/libavformat/tedcaptionsdec.c @@ -297,7 +297,7 @@ static av_cold int tedcaptions_read_header(AVFormatContext *avf) st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_TEXT; avpriv_set_pts_info(st, 64, 1, 1000); - st->probe_packets = 0; + st->internal->probe_packets = 0; st->start_time = 0; st->duration = last->pts + last->duration; st->cur_dts = 0; diff --git a/libavformat/utils.c b/libavformat/utils.c index 4d281a9ce8..c0ba07d288 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -358,7 +358,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, int i; av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", - pd->buf_size, s->max_probe_packets - st->probe_packets, + pd->buf_size, s->max_probe_packets - st->internal->probe_packets, fmt->name, score); for (i = 0; fmt_id_type[i].name; i++) { if (!strcmp(fmt->name, fmt_id_type[i].name)) { @@ -678,8 +678,8 @@ static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) if (st->internal->request_probe>0) { AVProbeData *pd = &st->internal->probe_data; int end; - av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets); - --st->probe_packets; + av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->internal->probe_packets); + --st->internal->probe_packets; if (pkt) { uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); @@ -695,7 +695,7 @@ static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); } else { no_packet: - st->probe_packets = 0; + st->internal->probe_packets = 0; if (!pd->buf_size) { av_log(s, AV_LOG_WARNING, "nothing to probe for stream %d\n", st->index); @@ -703,7 +703,7 @@ no_packet: } end= s->internal->raw_packet_buffer_remaining_size <= 0 - || st->probe_packets<= 0; + || st->internal->probe_packets<= 0; if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { int score = set_codec_from_probe_data(s, st, pd); @@ -828,7 +828,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->probe_packets || st->internal->request_probe > 0) + if (st->internal->probe_packets || st->internal->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; av_assert0(st->internal->request_probe <= 0); @@ -1844,7 +1844,7 @@ int av_find_default_stream_index(AVFormatContext *s) if (st->codecpar->sample_rate) score += 50; } - if (st->codec_info_nb_frames) + if (st->internal->codec_info_nb_frames) score += 12; if (st->discard != AVDISCARD_ALL) @@ -1882,7 +1882,7 @@ void ff_read_frame_flush(AVFormatContext *s) /* We set the current DTS to an unspecified origin. */ st->cur_dts = AV_NOPTS_VALUE; - st->probe_packets = s->max_probe_packets; + st->internal->probe_packets = s->max_probe_packets; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; @@ -2700,7 +2700,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) break; } bit_rate += st->codecpar->bit_rate; - } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codec_info_nb_frames > 1) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->codec_info_nb_frames > 1) { // If we have a videostream with packets but without a bitrate // then consider the sum not known bit_rate = 0; @@ -2968,7 +2968,7 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) if (st->internal->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) FAIL("unspecified pixel format"); if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) - if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !st->codec_info_nb_frames) + if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !st->internal->codec_info_nb_frames) FAIL("no frame in rv30/40 and no sar"); break; case AVMEDIA_TYPE_SUBTITLE: @@ -3041,7 +3041,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, while ((pkt.size > 0 || (!pkt.data && got_picture)) && ret >= 0 && (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || - (!st->codec_info_nb_frames && + (!st->internal->codec_info_nb_frames && (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { got_picture = 0; if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || @@ -3715,7 +3715,7 @@ FF_ENABLE_DEPRECATION_WARNINGS break; if (st->first_dts == AV_NOPTS_VALUE && !(ic->iformat->flags & AVFMT_NOTIMESTAMPS) && - st->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && + st->internal->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) break; @@ -3786,7 +3786,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->internal->avctx_inited = 1; } - if (pkt->dts != AV_NOPTS_VALUE && st->codec_info_nb_frames > 1) { + if (pkt->dts != AV_NOPTS_VALUE && st->internal->codec_info_nb_frames > 1) { /* check for non-increasing dts */ if (st->internal->info->fps_last_dts != AV_NOPTS_VALUE && st->internal->info->fps_last_dts >= pkt->dts) { @@ -3794,7 +3794,7 @@ FF_ENABLE_DEPRECATION_WARNINGS "Non-increasing DTS in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", st->index, st->internal->info->fps_last_dts_idx, - st->internal->info->fps_last_dts, st->codec_info_nb_frames, + st->internal->info->fps_last_dts, st->internal->codec_info_nb_frames, pkt->dts); st->internal->info->fps_first_dts = st->internal->info->fps_last_dts = AV_NOPTS_VALUE; @@ -3811,7 +3811,7 @@ FF_ENABLE_DEPRECATION_WARNINGS "DTS discontinuity in stream %d: packet %d with DTS " "%"PRId64", packet %d with DTS %"PRId64"\n", st->index, st->internal->info->fps_last_dts_idx, - st->internal->info->fps_last_dts, st->codec_info_nb_frames, + st->internal->info->fps_last_dts, st->internal->codec_info_nb_frames, pkt->dts); st->internal->info->fps_first_dts = st->internal->info->fps_last_dts = AV_NOPTS_VALUE; @@ -3820,22 +3820,22 @@ FF_ENABLE_DEPRECATION_WARNINGS /* update stored dts values */ if (st->internal->info->fps_first_dts == AV_NOPTS_VALUE) { st->internal->info->fps_first_dts = pkt->dts; - st->internal->info->fps_first_dts_idx = st->codec_info_nb_frames; + st->internal->info->fps_first_dts_idx = st->internal->codec_info_nb_frames; } st->internal->info->fps_last_dts = pkt->dts; - st->internal->info->fps_last_dts_idx = st->codec_info_nb_frames; + st->internal->info->fps_last_dts_idx = st->internal->codec_info_nb_frames; } - if (st->codec_info_nb_frames>1) { + if (st->internal->codec_info_nb_frames>1) { int64_t t = 0; int64_t limit; if (st->time_base.den > 0) t = av_rescale_q(st->internal->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); if (st->avg_frame_rate.num > 0) - t = FFMAX(t, av_rescale_q(st->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); + t = FFMAX(t, av_rescale_q(st->internal->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); if ( t == 0 - && st->codec_info_nb_frames>30 + && st->internal->codec_info_nb_frames>30 && st->internal->info->fps_first_dts != AV_NOPTS_VALUE && st->internal->info->fps_last_dts != AV_NOPTS_VALUE) t = FFMAX(t, av_rescale_q(st->internal->info->fps_last_dts - st->internal->info->fps_first_dts, st->time_base, AV_TIME_BASE_Q)); @@ -3888,7 +3888,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ic->flags & AVFMT_FLAG_NOBUFFER) av_packet_unref(&pkt1); - st->codec_info_nb_frames++; + st->internal->codec_info_nb_frames++; count++; } @@ -4212,7 +4212,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, } disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED)) + !! (st->disposition & AV_DISPOSITION_DEFAULT); - count = st->codec_info_nb_frames; + count = st->internal->codec_info_nb_frames; bitrate = par->bit_rate; multiframe = FFMIN(5, count); if ((best_disposition > disposition) || @@ -4519,7 +4519,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->start_time = AV_NOPTS_VALUE; st->duration = AV_NOPTS_VALUE; st->first_dts = AV_NOPTS_VALUE; - st->probe_packets = s->max_probe_packets; + st->internal->probe_packets = s->max_probe_packets; st->internal->pts_wrap_reference = AV_NOPTS_VALUE; st->internal->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 9b93cfce8e..e896b86a56 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -155,7 +155,7 @@ static void handle_stream_probing(AVStream *st) { if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { st->internal->request_probe = AVPROBE_SCORE_EXTENSION; - st->probe_packets = FFMIN(st->probe_packets, 32); + st->internal->probe_packets = FFMIN(st->internal->probe_packets, 32); } } diff --git a/tests/api/api-codec-param-test.c b/tests/api/api-codec-param-test.c index 0868322cb4..af3f70d373 100644 --- a/tests/api/api-codec-param-test.c +++ b/tests/api/api-codec-param-test.c @@ -22,6 +22,7 @@ #include #include "libavformat/avformat.h" +#include "libavformat/internal.h" #include "libavutil/pixdesc.h" #include "libavcodec/internal.h" #include "libavutil/avassert.h" @@ -100,7 +101,7 @@ static int find_video_stream_info(AVFormatContext *fmt_ctx, int decode) * which writes to this field. * */ if (codec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || - st->codec_info_nb_frames++ > 0) { + st->internal->codec_info_nb_frames++ > 0) { av_packet_unref(&pkt); continue; } @@ -122,7 +123,7 @@ static int find_video_stream_info(AVFormatContext *fmt_ctx, int decode) if (codec_ctx->codec_type != AVMEDIA_TYPE_VIDEO) continue; - done &= st->codec_info_nb_frames > 0; + done &= st->internal->codec_info_nb_frames > 0; } } From patchwork Fri Oct 9 13:04:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22787 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5131144A971 for ; Fri, 9 Oct 2020 16:06:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4110768B9EF; Fri, 9 Oct 2020 16:06:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3646C68B9C0 for ; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 67669296259 for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 2Ja0Hzf1K5OL for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id F2B0A296263 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 0A7CA20E0265; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:29 +0200 Message-Id: <20201009130430.602-17-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/18] lavf: move AVStream.last_IP_* to AVStreamInternal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Those are private fields, no reason to have them exposed in a public header. --- libavformat/avformat.h | 4 ++-- libavformat/internal.h | 3 +++ libavformat/nutdec.c | 2 +- libavformat/utils.c | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 6168062ce1..a01912d654 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1040,10 +1040,10 @@ typedef struct AVStream { */ int64_t first_dts; int64_t cur_dts; - int64_t last_IP_pts; - int last_IP_duration; #if LIBAVFORMAT_VERSION_MAJOR < 59 + int64_t unused12; + int unused13; // kept for ABI compatibility only, do not access in any way int unused10; int unused11; diff --git a/libavformat/internal.h b/libavformat/internal.h index edc8bbae80..a8c8a10d4b 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -357,6 +357,9 @@ struct AVStreamInternal { * Number of frames that have been demuxed during avformat_find_stream_info() */ int codec_info_nb_frames; + + int64_t last_IP_pts; + int last_IP_duration; }; #ifdef __GNUC__ diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 53a052503e..f8c11d270f 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -1086,7 +1086,7 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code) stc->skip_until_key_frame = 0; discard = s->streams[stream_id]->discard; - last_IP_pts = s->streams[stream_id]->last_IP_pts; + last_IP_pts = s->streams[stream_id]->internal->last_IP_pts; if ((discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) || (discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts) || diff --git a/libavformat/utils.c b/libavformat/utils.c index c0ba07d288..8be6400f11 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1316,28 +1316,28 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* DTS = decompression timestamp */ /* PTS = presentation timestamp */ if (pkt->dts == AV_NOPTS_VALUE) - pkt->dts = st->last_IP_pts; + pkt->dts = st->internal->last_IP_pts; update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); if (pkt->dts == AV_NOPTS_VALUE) pkt->dts = st->cur_dts; /* This is tricky: the dts must be incremented by the duration * of the frame we are displaying, i.e. the last I- or P-frame. */ - if (st->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) - st->last_IP_duration = pkt->duration; + if (st->internal->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) + st->internal->last_IP_duration = pkt->duration; if (pkt->dts != AV_NOPTS_VALUE) - st->cur_dts = av_sat_add64(pkt->dts, st->last_IP_duration); + st->cur_dts = av_sat_add64(pkt->dts, st->internal->last_IP_duration); if (pkt->dts != AV_NOPTS_VALUE && pkt->pts == AV_NOPTS_VALUE && - st->last_IP_duration > 0 && + st->internal->last_IP_duration > 0 && ((uint64_t)st->cur_dts - (uint64_t)next_dts + 1) <= 2 && next_dts != next_pts && next_pts != AV_NOPTS_VALUE) pkt->pts = next_dts; if ((uint64_t)pkt->duration <= INT32_MAX) - st->last_IP_duration = pkt->duration; - st->last_IP_pts = pkt->pts; + st->internal->last_IP_duration = pkt->duration; + st->internal->last_IP_pts = pkt->pts; /* Cannot compute PTS if not present (we can compute it only * by knowing the future. */ } else if (pkt->pts != AV_NOPTS_VALUE || @@ -1874,7 +1874,7 @@ void ff_read_frame_flush(AVFormatContext *s) av_parser_close(st->internal->parser); st->internal->parser = NULL; } - st->last_IP_pts = AV_NOPTS_VALUE; + st->internal->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; if (st->first_dts == AV_NOPTS_VALUE) st->cur_dts = RELATIVE_TS_BASE; @@ -2863,7 +2863,7 @@ skip_duration_calc: st = ic->streams[i]; st->cur_dts = st->first_dts; - st->last_IP_pts = AV_NOPTS_VALUE; + st->internal->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; @@ -4523,7 +4523,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st->internal->pts_wrap_reference = AV_NOPTS_VALUE; st->internal->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; - st->last_IP_pts = AV_NOPTS_VALUE; + st->internal->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; for (i = 0; i < MAX_REORDER_DELAY + 1; i++) st->internal->pts_buffer[i] = AV_NOPTS_VALUE; From patchwork Fri Oct 9 13:04:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22790 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3C1E444A971 for ; Fri, 9 Oct 2020 16:06:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 231F668B9E6; Fri, 9 Oct 2020 16:06:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6156D68B9B7 for ; Fri, 9 Oct 2020 16:06:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id CA523296263 for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id zxmWTU2DnTFp for ; Fri, 9 Oct 2020 15:06:37 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id F2BE3296264 for ; Fri, 9 Oct 2020 15:06:31 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id F24DB20E0260; Fri, 9 Oct 2020 15:06:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Oct 2020 15:04:30 +0200 Message-Id: <20201009130430.602-18-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201009130430.602-1-anton@khirnov.net> References: <20201009130430.602-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/18] lavf: document some AVStream fields as private X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Specifically: pts_wrap_bits, first_dts, cur_dts. They are supposed to be private and are located in the private section of AVStream, but ffmpeg.c currently accesses them regardless. They should be moved to AVStreamInternal once that bug is fixed. Remove the marker for the private AVStream section, as there are no other accessible fields left there. It has proven highly confusing and people kept adding supposedly-public fields into the private section. New private per-stream fields should be added to AVStreamInternal. --- libavformat/avformat.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index a01912d654..612791a2eb 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1013,22 +1013,16 @@ typedef struct AVStream { */ AVCodecParameters *codecpar; - /***************************************************************** - * All fields below this line are not part of the public API. They - * may not be used outside of libavformat and can be changed and - * removed at will. - * Internal note: be aware that physically removing these fields - * will break ABI. Replace removed fields with dummy fields, and - * add new fields to AVStreamInternal. - ***************************************************************** - */ - #if LIBAVFORMAT_VERSION_MAJOR < 59 // kept for ABI compatibility only, do not access in any way void *unused; #endif - int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ + /** + * number of bits in pts (used for wrapping control) + * private, do not access from outside libavformat. + */ + int pts_wrap_bits; // Timestamp generation support: /** @@ -1037,8 +1031,12 @@ typedef struct AVStream { * Initialized when AVCodecParserContext.dts_sync_point >= 0 and * a DTS is received from the underlying container. Otherwise set to * AV_NOPTS_VALUE by default. + * private, do not access from outside libavformat. */ int64_t first_dts; + /** + * private, do not access from outside libavformat. + */ int64_t cur_dts; #if LIBAVFORMAT_VERSION_MAJOR < 59