From patchwork Sat Jan 6 10:07:08 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: 7156 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp386343jaa; Sat, 6 Jan 2018 02:07:52 -0800 (PST) X-Google-Smtp-Source: ACJfBovrqJBMxLcGiPnWsV07rhEnTYQrcPQGu1Mi8OkT0SctKRUbXeqmu99MpCeIxrP13Gw9A9xN X-Received: by 10.223.155.218 with SMTP id e26mr3640675wrc.128.1515233271970; Sat, 06 Jan 2018 02:07:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515233271; cv=none; d=google.com; s=arc-20160816; b=RJrzYjOyMazGXxvPw3s3wlcSdvrTwHYW4dAkegYIAtZ71DumdyhsLAdYPjo/bO1CJj nSUWrQr5porQ+GhXWs5XsiAYIvRyhXPFggdU9Z/pRhm3VD3nSHGcOVZdypmK+qjcIviX Gp5Ch4CwT3pnUeku350Ey4irI7ErN6PYue0nzsmTW8+N8gKQKHM0ypjT8pGvmUKxekcc MnS/qoJ2TNorFynxWuu2H1aAruG9FHAZoUUjv8Y89VxNaqPlWRikjpvb2lFwTmfzoGow byqXnjZgxhqWSCyvi2TU0IoPLUrmDqxoWLBE9huI8/z4YHv15tGXHh0rzUgTdfWj8u3z jSHA== 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=MCUndyP5dvZDmnbne8wTloHoaPd9B4HmOwdTRNLuKr0=; b=DLjUrqJvVF0q6HKpkJVmE3qD6EU7heJIvwPpfsqaGcGJWMji+Sq9ZmZJy5wqnhjgri UcZrguHpAp/9iV1kZYzYsLM/JItfu4qqtLu+Mluo7YOjQW56iJKMFTjF9RYmqRiUSjJZ UXfqcrKcy6UI0zrGZmJhU6a2fHL3CowG4WzcmUNXmejxWB+TjhHKBPwcKDiZmXdpWSA4 QCA7L3njUCzPKgspylcR5nV+noeaDRG+Yb46Psu73alTyspCuu5zxmlKxh09F2nCf/Qq s458dr1r4GLKt73f0agEyEtHuuRVC5vbZQwb4vg2xUSUkJ/lOfeA7suA907OHOEmdOoU nSPQ== 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 a9si4809971wmh.4.2018.01.06.02.07.51; Sat, 06 Jan 2018 02:07:51 -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 2D7EF689C87; Sat, 6 Jan 2018 12:07:43 +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 296DC689951 for ; Sat, 6 Jan 2018 12:07:37 +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 1eXlNf-00081P-5V; Sat, 06 Jan 2018 11:07:11 +0100 From: =?UTF-8?q?J=C3=B6rn=20Heusipp?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 6 Jan 2018 11:07:08 +0100 Message-Id: <1515233228-16796-4-git-send-email-osmanx@problemloesungsmaschine.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1515233228-16796-1-git-send-email-osmanx@problemloesungsmaschine.de> References: <1515233228-16796-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 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'. As expected, I did not see any measurable performance difference caused by libopenmpt file header probing when compared to the previous pure file extension based format probing (using the following synthetic test program (which tries to do nothing but exercise file probing) on the complete FATE suite). // find ../fate/ -type f | xargs --no-run-if-empty ./probetest #include #include "libavformat/avformat.h" #define BUFSIZE 2048 static char buf[BUFSIZE + AVPROBE_PADDING_SIZE]; int main(int argc, const char * * argv) { av_log_set_level(AV_LOG_WARNING); av_register_all(); for (int i = 1; i < argc; ++i) { AVProbeData pd; FILE * f; size_t size; memset(&pd, 0, sizeof(AVProbeData)); pd.filename = argv[i]; memset(buf, 0, sizeof(buf)); f = fopen(pd.filename, "rb"); size = fread(buf, 1, BUFSIZE, f); fclose(f); pd.buf_size = size; av_probe_input_format(&pd, 1); } return 0; } Signed-off-by: Jörn Heusipp --- libavformat/libopenmpt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c index 5efbdc4..a663b2e 100644 --- a/libavformat/libopenmpt.c +++ b/libavformat/libopenmpt.c @@ -218,6 +218,64 @@ static int read_seek_openmpt(AVFormatContext *s, int stream_idx, int64_t ts, int return 0; } +static int read_probe_openmpt(AVProbeData * p) +{ + const int score_data = AVPROBE_SCORE_MIME + 1; /* 76 */ + const int score_ext = AVPROBE_SCORE_EXTENSION; /* 50 */ + const int score_ext_retry = AVPROBE_SCORE_RETRY; /* 25 */ + const int score_retry = AVPROBE_SCORE_RETRY / 2; /* 12 */ + const int score_fail = 0; /* 0 */ + + const char *ext; + int probe_result; + int score = score_fail; + + if (p->filename) { + ext = strrchr(p->filename, '.'); + if (ext && strlen(ext + 1) > 0) { + ext++; /* skip '.' */ + if (openmpt_is_extension_supported(ext) == 1) + score = FFMAX(score, score_ext); + } + } + +#if OPENMPT_API_VERSION_AT_LEAST(0,3,0) + 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_FAILURE) { + score = score_fail; + } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS) { + score = FFMAX(score, score_data); + } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) { + if (score > score_fail) { + /* known file extension */ + score = FFMAX(score, score_ext_retry); + } else { + /* unknown file extension */ + 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. + */ + score = FFMAX(score, score_retry); + } 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. + */ + score = score_fail; + } + } + } + } +#endif + + return score; +} + static const AVClass class_openmpt = { .class_name = "libopenmpt", .item_name = av_default_item_name, @@ -229,6 +287,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,