Skip to content

Commit 5c9366f

Browse files
authored
Merge pull request #2308 from jodal/playbin-play-flags
refactor: Give the play flags an enum of their own
2 parents fafb16a + af43331 commit 5c9366f

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎src/mopidy/audio/_gst/pipeline.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
GstEndOfStream,
1414
GstError,
1515
GstMissingPlugin,
16+
GstPlayFlags,
1617
GstState,
1718
GstStateChanged,
1819
GstStreamStart,
@@ -38,9 +39,6 @@
3839
# set_state() on a pipeline.
3940
gst_logger = logging.getLogger("mopidy.audio.gst")
4041

41-
GST_PLAY_FLAGS_AUDIO = 0x02
42-
GST_PLAY_FLAGS_DOWNLOAD = 0x80
43-
4442

4543
class GstOutputBin(Gst.Bin):
4644
"""A bin that sends its input to one or more audio outputs."""
@@ -154,7 +152,7 @@ def _make_playbin(
154152
if playbin is None:
155153
msg = "Failed to create GStreamer playbin."
156154
raise exceptions.AudioException(msg)
157-
playbin.set_property("flags", GST_PLAY_FLAGS_AUDIO)
155+
playbin.set_property("flags", GstPlayFlags.AUDIO)
158156

159157
# TODO: turn into config values...
160158
playbin.set_property("buffer-size", 5 << 20) # 5MB
@@ -314,9 +312,9 @@ def _decode_segment(segment: Gst.Segment) -> DurationMs:
314312

315313
def set_uri(self, uri: str, *, download: bool = False) -> None:
316314
"""Set the URI to play, and the buffering flags to use for it."""
317-
flags = GST_PLAY_FLAGS_AUDIO
315+
flags = GstPlayFlags.AUDIO
318316
if download:
319-
flags |= GST_PLAY_FLAGS_DOWNLOAD
317+
flags |= GstPlayFlags.DOWNLOAD
320318

321319
logger.debug(f"Flags: {flags}")
322320
self.playbin.set_property("flags", flags)

‎src/mopidy/audio/_gst/types.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
from mopidy._lib.gi import GLib
1212

1313

14+
class GstPlayFlags(enum.IntFlag):
15+
"""The parts of a stream the playbin renders, and how it buffers them.
16+
17+
GStreamer's own `GstPlayFlags` has no Python class, because the type is
18+
defined inside the playbin plugin and not in a library with GIR data.
19+
These are the values Mopidy uses from its table.
20+
"""
21+
22+
AUDIO = 0x02
23+
DOWNLOAD = 0x80
24+
25+
1426
class GstState(enum.Enum):
1527
"""The states a GStreamer element can be in.
1628

‎tests/audio/_gst/test_pipeline.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from mopidy._lib.gi import GLib, Gst
77
from mopidy.audio._gst import types
88
from mopidy.audio._gst.pipeline import (
9-
GST_PLAY_FLAGS_AUDIO,
10-
GST_PLAY_FLAGS_DOWNLOAD,
119
GstOutputBin,
1210
GstPipeline,
1311
make_output_bin,
@@ -34,11 +32,15 @@ def pipeline():
3432
pipeline.teardown()
3533

3634

35+
def test_playbin_plays_audio_only(pipeline):
36+
assert pipeline.playbin.get_property("flags") == types.GstPlayFlags.AUDIO
37+
38+
3739
def test_download_flag_is_passed_to_playbin_if_download_buffering_is_enabled(pipeline):
3840
pipeline.set_uri("some:uri", download=True)
3941

4042
flags = pipeline.playbin.get_property("flags")
41-
assert flags == GST_PLAY_FLAGS_AUDIO | GST_PLAY_FLAGS_DOWNLOAD
43+
assert flags == types.GstPlayFlags.AUDIO | types.GstPlayFlags.DOWNLOAD
4244

4345

4446
def test_download_flag_is_not_passed_to_playbin_if_download_buffering_is_disabled(
@@ -47,7 +49,7 @@ def test_download_flag_is_not_passed_to_playbin_if_download_buffering_is_disable
4749
pipeline.set_uri("some:uri", download=False)
4850

4951
flags = pipeline.playbin.get_property("flags")
50-
assert flags == GST_PLAY_FLAGS_AUDIO
52+
assert flags == types.GstPlayFlags.AUDIO
5153

5254

5355
def test_set_uri_sets_the_uri_on_the_playbin(pipeline):

0 commit comments

Comments
 (0)