Skip to content

Commit

Permalink
replaygain: in Gst backend, pass paths instead of items around
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wisp3rwind committed Jul 16, 2023
1 parent 50f342b commit 9742f11
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions beetsplug/replaygain.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,13 @@ def _import_gst(self):
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)
Expand All @@ -759,8 +759,8 @@ def compute_track_gain(self, task):

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
Expand All @@ -778,14 +778,14 @@ def compute_album_gain(self, task):
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"]
Expand Down Expand Up @@ -849,7 +849,7 @@ def _set_first_file(self):

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

Expand Down Expand Up @@ -880,7 +880,7 @@ def _set_file(self):
# 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)
Expand Down

0 comments on commit 9742f11

Please sign in to comment.