From b8be2af11d9c631227193b3969cf3961e002ff8b Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Sat, 9 Apr 2022 15:58:19 +0200 Subject: [PATCH] replaygain: in Gst backend, pass paths instead of items around This is a preparation for moving the Gst calculation to multiprocessing worker threads. Passing only the file paths to the worker threads instead of synchronizing the entire `Item`s (i.e. minimizing the data that is shared between the processes) hopefully helps to prevent any issues with this approach. --- beetsplug/replaygain.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 6e5f145dd..750d78bf7 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -730,13 +730,13 @@ class GStreamerBackend(Backend): self.GLib = GLib self.Gst = Gst - def compute(self, files, target_level, album): - self._error = None - self._files = list(files) - - if len(self._files) == 0: + def compute(self, items, target_level, album): + if len(items) == 0: return + self._error = None + self._files = [i.path for i in items] + self._file_tags = collections.defaultdict(dict) self._rg.set_property("reference-level", target_level) @@ -759,8 +759,8 @@ class GStreamerBackend(Backend): ret = [] for item in task.items: - ret.append(Gain(self._file_tags[item]["TRACK_GAIN"], - self._file_tags[item]["TRACK_PEAK"])) + ret.append(Gain(self._file_tags[item.path]["TRACK_GAIN"], + self._file_tags[item.path]["TRACK_PEAK"])) task.track_gains = ret return task @@ -778,14 +778,14 @@ class GStreamerBackend(Backend): track_gains = [] for item in items: try: - gain = self._file_tags[item]["TRACK_GAIN"] - peak = self._file_tags[item]["TRACK_PEAK"] + gain = self._file_tags[item.path]["TRACK_GAIN"] + peak = self._file_tags[item.path]["TRACK_PEAK"] except KeyError: raise ReplayGainError("results missing for track") track_gains.append(Gain(gain, peak)) # Get album gain information from the last track. - last_tags = self._file_tags[items[-1]] + last_tags = self._file_tags[items[-1].path] try: gain = last_tags["ALBUM_GAIN"] peak = last_tags["ALBUM_PEAK"] @@ -849,7 +849,7 @@ class GStreamerBackend(Backend): self._file = self._files.pop(0) self._pipe.set_state(self.Gst.State.NULL) - self._src.set_property("location", py3_path(syspath(self._file.path))) + self._src.set_property("location", py3_path(syspath(self._file))) self._pipe.set_state(self.Gst.State.PLAYING) return True @@ -880,7 +880,7 @@ class GStreamerBackend(Backend): # Set a new file on the filesrc element, can only be done in the # READY state self._src.set_state(self.Gst.State.READY) - self._src.set_property("location", py3_path(syspath(self._file.path))) + self._src.set_property("location", py3_path(syspath(self._file))) self._decbin.link(self._conv) self._pipe.set_state(self.Gst.State.READY)