From patchwork Wed Jan 10 11:18:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=C3=B6rn_Heusipp?= X-Patchwork-Id: 7250 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp5053219jaa; Wed, 10 Jan 2018 03:19:32 -0800 (PST) X-Google-Smtp-Source: ACJfBosj2EQi2XSvdSZOqupZX9x2KYBNdj2b95OO8OSBvp132H0DHsEvy4RBWS9z3xlB2a+uGRY8 X-Received: by 10.28.140.1 with SMTP id o1mr16030461wmd.27.1515583172880; Wed, 10 Jan 2018 03:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515583172; cv=none; d=google.com; s=arc-20160816; b=I2H4WbfspbgrtEJ9er4CdcniIgWByHwqArI77dv6RDCdJ4yo9C79pv4kVDCTi2i88z VnD/bS6D/EXCUEBC+tmDkG5p2QWpynBj0G9/je8kPyJqiQ2Xz4xRNwNr/zkfW/FEa+8H J2r3ZDuWzqOF2wbg0mvSoTO4Z7Wf0YGU81tT2lbuzu2Wzyhy30homl7KO9NQ6Du/ZFgG Sga4SrIo3uNWbN7XRrPRaOpS1rxVA+nrArj736ekkK5xtltAXQjjQJ/B0XKI5mXY3den s1qXluByPydl19llbZuyxsyAwzU35xglpOtJO6cClr0JX1eJKZvWihvjF9xrnTO4o93w neuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to:arc-authentication-results; bh=YobNFgvW7MO2jTk+5PNT0XWXmPSOt4ckvzb76uS1WRg=; b=0YfFUkqXTkxcUaH+Z6QZjmuzReTyb+ng8+fhbKANwWOuyZWghQT3Ts22IIpNnab+7F o0bCDR8glYBfOEob52lbn7i/Uc7yPKNI6AIYBV/4HIy2a7PeAXOeVr00bc7w1zSrdPvG 3Q5PIz6Xybj0Rs1Pn7Xm4eXwIyyimcKecDY1gOPoTE5tdRTZYU4VoRPPGpggMvoCBHh1 6BoK/DzRu+9V59EB+5QayhkLj3L+QW+eXHqXcJATDhqeRgGWDwjFqLeoHULOHvayVE+M qbs9r2u0eQPp34Vd6UImPm0YGP0NiKm9utx2O+Jt6UZHOUOrmn0QOoUyD1+IvI1kuy+3 SrKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 137si11026485wmk.148.2018.01.10.03.19.32; Wed, 10 Jan 2018 03:19:32 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8829468A156; Wed, 10 Jan 2018 13:19:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from datengang.de (datengang.de [138.201.179.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18BCA689D01 for ; Wed, 10 Jan 2018 13:19:10 +0200 (EET) Received: from p5b3e6755.dip0.t-ipconnect.de ([91.62.103.85] helo=idefix.fritz.box) by datengang.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.89) (envelope-from ) id 1eZEOV-0001nt-0d; Wed, 10 Jan 2018 12:18:07 +0100 From: =?UTF-8?q?J=C3=B6rn=20Heusipp?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Jan 2018 12:18:04 +0100 Message-Id: <1515583084-6466-5-git-send-email-osmanx@problemloesungsmaschine.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1515583084-6466-1-git-send-email-osmanx@problemloesungsmaschine.de> References: <1515233228-16796-1-git-send-email-osmanx@problemloesungsmaschine.de> <1515583084-6466-1-git-send-email-osmanx@problemloesungsmaschine.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 91.62.103.85 X-SA-Exim-Mail-From: osmanx@problemloesungsmaschine.de X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on datengang.de X-Spam-Level: X-Spam-Status: No, score=-2.9 required=8.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on datengang.de) Subject: [FFmpeg-devel] [PATCH v2 4/4] avformat/libopenmpt: Probe file format from file data if possible 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" When building with libopenmpt 0.3, use the libopenmpt file header probing functions for probing. libopenmpt probing functions are allocation-free and designed to be as fast as possible. For libopenmpt 0.2, or when libopenmpt 0.3 file header probing cannot probe successfully due to too small probe buffer, test the filename against the file extensions supported by the libopenmpt library that is actually linked, instead of relying on a hard-coded file extension list. File extension testing is also allocation-free and designed to be fast in libopenmpt. Avoiding a hard-coded file extension list is useful because later libopenmpt versions will likely add support for more module file formats. libopenmpt file header probing is tested regularly against the FATE suite and other diverse file collections by libopenmpt upstream in order to avoid false positives. FATE passes with './configure --enable-libopenmpt' as well as with './configure --enable-libopenmpt --enable-libmodplug'. libopenmpt probing adds about 5%..10% cpu time (depending on precise usage pattern and host CPU and compiler version used for libopenmpt) compared to all current internal FFmpeg probing functions combined in tools/probetest for all of its module formats combined (currently 41 modules formats in libopenmpt 0.3.4 and 234 file formats in FFmpeg). Signed-off-by: Jörn Heusipp --- libavformat/libopenmpt.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c index 5efbdc4..42b78fb 100644 --- a/libavformat/libopenmpt.c +++ b/libavformat/libopenmpt.c @@ -218,6 +218,62 @@ static int read_seek_openmpt(AVFormatContext *s, int stream_idx, int64_t ts, int return 0; } +static int probe_openmpt_extension(AVProbeData *p) +{ + const char *ext; + if (p->filename) { + ext = strrchr(p->filename, '.'); + if (ext && strlen(ext + 1) > 0) { + ext++; /* skip '.' */ + if (openmpt_is_extension_supported(ext) == 1) + return AVPROBE_SCORE_EXTENSION; + } + } + return 0; +} + +static int read_probe_openmpt(AVProbeData *p) +{ +#if OPENMPT_API_VERSION_AT_LEAST(0,3,0) + int probe_result; + if (p->buf && p->buf_size > 0) { + probe_result = openmpt_probe_file_header_without_filesize( + OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT, + p->buf, p->buf_size, + &openmpt_logfunc, NULL, NULL, NULL, NULL, NULL); + if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS) { + /* As probing here relies on code external to FFmpeg, do not return + * AVPROBE_SCORE_MAX in order to reduce the impact in the rare + * cases of false positives. + */ + return AVPROBE_SCORE_MIME + 1; + } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) { + if (probe_openmpt_extension(p) > 0) { + return AVPROBE_SCORE_EXTENSION; + } else { + if (p->buf_size >= openmpt_probe_file_header_get_recommended_size()) { + /* We have already received the recommended amount of data + * and still cannot decide. Return a rather low score. + */ + return AVPROBE_SCORE_RETRY / 2; + } else { + /* The file extension is unknown and we have very few data + * bytes available. libopenmpt cannot decide anything here, + * and returning any score > 0 would result in successfull + * probing of random data. + */ + return 0; + } + } + } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE) { + return 0; + } + } +#endif + /* for older libopenmpt, fall back to file extension probing */ + return probe_openmpt_extension(p); +} + static const AVClass class_openmpt = { .class_name = "libopenmpt", .item_name = av_default_item_name, @@ -229,6 +285,7 @@ AVInputFormat ff_libopenmpt_demuxer = { .name = "libopenmpt", .long_name = NULL_IF_CONFIG_SMALL("Tracker formats (libopenmpt)"), .priv_data_size = sizeof(OpenMPTContext), + .read_probe = read_probe_openmpt, .read_header = read_header_openmpt, .read_packet = read_packet_openmpt, .read_close = read_close_openmpt,