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; } }