From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 595511F55F for ; Mon, 4 Sep 2023 06:22:16 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=80x24.org header.i=@80x24.org header.a=rsa-sha256 header.s=selector1 header.b=JM6MWh2D; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qd2yU-0007Of-Kc; Mon, 04 Sep 2023 02:22:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd2yP-0007Ng-A9 for dtas-all@nongnu.org; Mon, 04 Sep 2023 02:22:10 -0400 Received: from dcvr.yhbt.net ([173.255.242.215]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd2yN-0008AJ-6Z for dtas-all@nongnu.org; Mon, 04 Sep 2023 02:22:09 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 42CCF1F560 for ; Mon, 4 Sep 2023 06:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1693808513; bh=2yWPxvsbhl/CYtm890tia4NKZOCRAOmxOTdxmUKQ8Zw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JM6MWh2D26hsN5tuZC+tI52HY5zHMLnKMxFUeSEcZxcS32FEyDuWmqSa/+GW6fk6O fS10r3yETR7IYPlez+8daqi2ZMQnl3Zr4Z/DySfKYjEkIC8VB5oNKGOsZRrTZBy+xQ y1w9YIKP/cwxkrgr68+/gySc78JygCC8LK58JbPg= From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH 2/2] av_ff_common: use mcache Date: Mon, 4 Sep 2023 06:21:52 +0000 Message-ID: <20230904062152.2054504-2-e@80x24.org> In-Reply-To: <20230904062152.2054504-1-e@80x24.org> References: <20230904062152.2054504-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=173.255.242.215; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: dtas-all-bounces+e=80x24.org@nongnu.org As with soxi(1), waiting for ffprobe(1) or avprobe(1) is still an expensive operation despite Process.spawn being optimized to use vfork(2). --- lib/dtas/source/av.rb | 1 + lib/dtas/source/av_ff_common.rb | 19 ++++++++++++++++--- lib/dtas/source/ff.rb | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/dtas/source/av.rb b/lib/dtas/source/av.rb index 39cad6c..823b29f 100644 --- a/lib/dtas/source/av.rb +++ b/lib/dtas/source/av.rb @@ -20,6 +20,7 @@ class DTAS::Source::Av # :nodoc: def initialize command_init(AV_DEFAULTS) + @mcache = nil @av_ff_probe = "avprobe" end diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb index 332a0bb..0c84b2f 100644 --- a/lib/dtas/source/av_ff_common.rb +++ b/lib/dtas/source/av_ff_common.rb @@ -21,10 +21,23 @@ module DTAS::Source::AvFfCommon # :nodoc: attr_reader :format attr_reader :duration + CACHE_KEYS = [ :@duration, :@probe_harder, :@comments, :@astreams, + :@format ].freeze + + def mcache_lookup(infile) + (@mcache ||= DTAS::Mcache.new).lookup(infile) do |input, dst| + tmp = source_file_dup(infile, nil, nil) + tmp.av_ff_ok? or return nil + CACHE_KEYS.each { |k| dst[k] = tmp.instance_variable_get(k) } + dst + end + end + def try(infile, offset = nil, trim = nil) - rv = source_file_dup(infile, offset, trim) - rv.av_ff_ok? or return - rv + ent = mcache_lookup(infile) or return + ret = source_file_dup(infile, offset, trim) + CACHE_KEYS.each { |k| ret.instance_variable_set(k, ent[k]) } + ret end def __parse_astream(cmd, stream) diff --git a/lib/dtas/source/ff.rb b/lib/dtas/source/ff.rb index 687cd18..491e580 100644 --- a/lib/dtas/source/ff.rb +++ b/lib/dtas/source/ff.rb @@ -21,6 +21,7 @@ class DTAS::Source::Ff # :nodoc: def initialize command_init(FF_DEFAULTS) + @mcache = nil @av_ff_probe = "ffprobe" end