From patchwork Fri Sep 27 20:26:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 15341 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 6CA12449BC8 for ; Fri, 27 Sep 2019 23:27:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 500D3689D5C; Fri, 27 Sep 2019 23:27:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C2CC689245 for ; Fri, 27 Sep 2019 23:27:02 +0300 (EEST) Received: by mail-oi1-f173.google.com with SMTP id i185so6267600oif.9 for ; Fri, 27 Sep 2019 13:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=o/LWfwjLkEYD0mMIF81WCy4Ion+/MuKzmbFXnvraFnk=; b=EO+PL6xBetIv7kPq348khAc130vLNWyXfdyuZ7IDQfAV1583KrdWz00KFpUj30/Ckb WZCCiQLKL2E5zOy1w7NFtoNpMvJCh5Eikfk0eXC8QXFDLGyif1s9mB+awPLI+i+G6xmc sx+EHmOrkqPeNUacIyqlhxv4eTBk3r3xQVZI2JroA3Fov/CfoIRFqein68iotZRv2FyJ DjZqrh2e0y7gwIUBt2GiwrUUJ+UbUbePAB6C8vjpzyRfm1AxtI1vnwixm9k1jz0vJjWy U5AqBbwhLrxjG4pbslgX6w89/MLm8Z2TR8epG2q1BVi8KAJ0azM9BIbWi3GPNKXzbq1q Xuhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=o/LWfwjLkEYD0mMIF81WCy4Ion+/MuKzmbFXnvraFnk=; b=VTQqIDmAD4WQbpN0knQCUfAYtHXKXZyRNbb5fLRYPYMLsranAw9G/cj/QVSlvhnbpR bNElhjif9j3VWKemVhkC2VL7pg7r7A5G0dG8wF9DVU1W1I2fI5JeQKz99tKrqkaYUMel yfmgv+eYeejFTmpDHtYyslNAQpjB1eNRrkMNdhIX7cv6VqFUwz4kYhH1POcf3SXvhnzO HRbv23k6Rhlx/A5pMm4+yQTQtCRk6AA2cbJecw7kDYOUt93rGVKad6z94DTYJ5ueTa2Y Dt+PGxw7EYbNqtDbQ5mxFi8oO3SD7HbKEDro4eEMgBNaZCpBS+9qzIm9k/Mk/H8ydxJ7 62Dg== X-Gm-Message-State: APjAAAWsJMtxSz/lwynx8w3t0NNghOZsmXVW/YgkyUiaK0SVPt8XW8XP gsTQSNedexGW9GboX9FPbCBj4npQ X-Google-Smtp-Source: APXvYqzp9nzxGGwUqYZSeove+UdTCkS8Nge1LIRFcaPG+Q597wCC1XIR1Vp4IhB7/pvJRQRLQSjR3A== X-Received: by 2002:aca:919:: with SMTP id 25mr8052346oij.150.1569616020831; Fri, 27 Sep 2019 13:27:00 -0700 (PDT) Received: from manj.guest.slb.com (bjcacd-22-48.slb.com. [192.23.22.48]) by smtp.gmail.com with ESMTPSA id c19sm1941133oib.21.2019.09.27.13.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 13:27:00 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Sep 2019 16:26:43 -0400 Message-Id: <20190927202643.12582-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat: Add max_probe_packets option 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 Cc: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman This allows the user to set a maximum number of buffered packets when probing a codec. It was a hard-coded parameter before this commit. --- doc/formats.texi | 4 ++++ libavformat/avformat.h | 7 +++++++ libavformat/internal.h | 2 -- libavformat/options_table.h | 1 + libavformat/utils.c | 7 ++++--- libavformat/version.h | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/formats.texi b/doc/formats.texi index d689fbadfa..fc80ce1d2b 100644 --- a/doc/formats.texi +++ b/doc/formats.texi @@ -27,6 +27,10 @@ stream information. A higher value will enable detecting more information in case it is dispersed into the stream, but will increase latency. Must be an integer not lesser than 32. It is 5000000 by default. +@item max_probe_packets @var{integer} (@emph{input}) +Set the maximum number of buffered packets when probing a codec. +Default is 2500 packets. + @item packetsize @var{integer} (@emph{output}) Set packet size. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 6eb329f13f..d4d9a3b06e 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1951,6 +1951,13 @@ typedef struct AVFormatContext { * - decoding: set by user */ int skip_estimate_duration_from_pts; + + /** + * Maximum number of packets that can be probed + * - encoding: unused + * - decoding: set by user + */ + int max_probe_packets; } AVFormatContext; #if FF_API_FORMAT_GET_SET diff --git a/libavformat/internal.h b/libavformat/internal.h index 67c35cc3e1..ec9a29907a 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -33,8 +33,6 @@ #define PROBE_BUF_MIN 2048 #define PROBE_BUF_MAX (1 << 20) -#define MAX_PROBE_PACKETS 2500 - #ifdef DEBUG # define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size) #else diff --git a/libavformat/options_table.h b/libavformat/options_table.h index f2f077b34f..618726512b 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -111,6 +111,7 @@ static const AVOption avformat_options[] = { {"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D }, {"max_streams", "maximum number of streams", OFFSET(max_streams), AV_OPT_TYPE_INT, { .i64 = 1000 }, 0, INT_MAX, D }, {"skip_estimate_duration_from_pts", "skip duration calculation in estimate_timings_from_pts", OFFSET(skip_estimate_duration_from_pts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D}, +{"max_probe_packets", "Maximum number of packets to probe a codec", OFFSET(max_probe_packets), AV_OPT_TYPE_INT, {.i64 = 2500 }, 0, INT_MAX, D }, {NULL}, }; diff --git a/libavformat/utils.c b/libavformat/utils.c index 9f8a5bfb63..23b5379030 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -363,7 +363,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, MAX_PROBE_PACKETS - st->probe_packets, + pd->buf_size, s->max_probe_packets - st->probe_packets, fmt->name, score); for (i = 0; fmt_id_type[i].name; i++) { if (!strcmp(fmt->name, fmt_id_type[i].name)) { @@ -835,6 +835,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, i, err; AVStream *st; + for (;;) { AVPacketList *pktl = s->internal->raw_packet_buffer; const AVPacket *pkt1; @@ -1954,7 +1955,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 = MAX_PROBE_PACKETS; + st->probe_packets = s->max_probe_packets; for (j = 0; j < MAX_REORDER_DELAY + 1; j++) st->pts_buffer[j] = AV_NOPTS_VALUE; @@ -4552,7 +4553,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 = MAX_PROBE_PACKETS; + st->probe_packets = s->max_probe_packets; st->pts_wrap_reference = AV_NOPTS_VALUE; st->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; diff --git a/libavformat/version.h b/libavformat/version.h index bcd0408d28..dce5a124c7 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 33 +#define LIBAVFORMAT_VERSION_MINOR 34 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \