Bug 492316 - Set playback stream type to "Audio"?
Summary: Set playback stream type to "Audio"?
Status: RESOLVED FIXED
Alias: None
Product: Elisa
Classification: Applications
Component: general (show other bugs)
Version: 24.08.0
Platform: Arch Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Matthieu Gallien
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-28 12:33 UTC by Daniel Schulte
Modified: 2024-11-14 22:48 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Schulte 2024-08-28 12:33:29 UTC
I've noticed that Elisa creates a new stream for each file played. My issue is that I'd like to play music via my speakers but movies via my headphones. If I change the output device for Elisa to be the speakers, start playback and they open a movie (with mpv) it also plays on the speakers. If I then move the mpv stream back to my headphones, the next time Elisa opens a new stream it also gets played on the headphones again.

Currently when playing audio with Elisa (using the libvlc backend) the PipeWire/PulseAudio streams introspection output looks like this:

```
trilader@eldingar ~ % wpctl inspect 422
id 422, type PipeWire:Interface:Node
    adapt.follower.spa-node = ""
    application.icon-name = "elisa"
    application.id = "org.kde.elisa"
    application.language = "en_US.UTF-8"
  * application.name = "Elisa"
    application.process.binary = "elisa"
    application.process.host = "eldingar"
    application.process.id = "7415"
    application.process.machine-id = "51231c1673024639abcd3cce5e316627"
    application.process.session-id = "2"
    application.process.user = "trilader"
    application.version = "24.05.2"
  * client.api = "pipewire-pulse"
  * client.id = "388"
    clock.quantum-limit = "8192"
  * factory.id = "7"
    library.name = "audioconvert/libspa-audioconvert"
  * media.class = "Stream/Output/Audio"
    media.name = "audio stream"
  * media.role = "Movie"
    node.autoconnect = "true"
    node.latency = "1764/44100"
    node.loop.name = "data-loop.0"
  * node.name = "Elisa"
    node.rate = "1/44100"
    node.want-driver = "true"
    object.register = "false"
  * object.serial = "81288"
    port.group = "stream.0"
    pulse.attr.maxlength = "4194304"
    pulse.attr.minreq = "14112"
    pulse.attr.prebuf = "0"
    pulse.attr.tlength = "42336"
    pulse.server.type = "unix"
    stream.is-live = "true"
    window.x11.display = ":1"
```

Note that media.role is set to "Movie" instead of "Audio" which would be more appropriate (and might resolve the device assignment issue described above).

With the libvlc backend this is easily possible by calling `libvlc_media_player_set_role(d->mPlayer, libvlc_role_Music);` in the AudioWrapper ctor in audiowrapper_libvlc.cpp.

With the Qt Multimedia backend it's likely not possible to implement at the moment as the stream type support got removed from Qt (QMediaPlayer::setAudioRole() got removed about 3 years ago in https://github.com/qt/qtmultimedia/commit/634894a8a83b021386da8c2672628b0b26185ef3 .)
Comment 1 Bug Janitor Service 2024-11-11 17:18:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/multimedia/elisa/-/merge_requests/640
Comment 2 Jack Hill 2024-11-14 22:47:29 UTC
Git commit 1e3fd23902f3d39c62aef79dd6971fb617ad87ad by Jack Hill, on behalf of Daniel Schulte.
Committed on 14/11/2024 at 22:47.
Pushed by jackh into branch 'master'.

libvlc: Set media player role to "Music"

PipeWire/WirePlumber stream restore function often uses the streams
`media.role` property to restore stream volume and output device when
a new stream is stated. By default libvlc doesn't have a value set for
the relevant property, resulting in `media.role = "Movie"` being the
default. This is annoying (to me) as I'd like to use a different device
(speakers) for music playback than for video playback (my headphones).

Test-plan:

I inspected the audio stream generated by Elisa with this patch applied.
I first get the stream ID using `wpctl status` and then inspecting the
correct stream using `wpctl inspect xxx`. It now (correctly) reports
`media.role = "Music"` instead of `media.role = "Movie"` like before.

Stream restore is also working correctly with this patch applied:

1. Play a video using e.g. mpv. Note which output device and playback
   volume are used for it. Quit mpv.
2. Start Elisa and play a song and pause it after a bit.
3. Either while still playing or when paused, change the volume and/or
   stream output device to something else.
4. Pause the stream.
5. Start playing a video (again) using e.g. mpv.
   Without the patch applied it should be using the same device/volume
   that Elisa is set to.    With it applied it should be using whatever
   was used previously.
6. Switch mpv to another audio device and/or change the playback volume.
7. Start playing a new track in Elisa, either by clicking "Next track"
   or clicking one (even the same, already paused file works) in the
   playlist.
8. Elisa starts a new stream.
   With the patch applied the stream should go to the device set in
   step 3 with the same volume it had before. Without the patch the
   stream uses the same properties as mpv in step 6.

With the Qt Multimedia backend it's likely not possible to implement at
the moment as the stream type support got removed from Qt 3 years ago here:
https://github.com/qt/qtmultimedia/commit/634894a8a83b021386da8c2672628b0b26185ef3

M  +2    -0    src/audiowrapper_libvlc.cpp

https://invent.kde.org/multimedia/elisa/-/commit/1e3fd23902f3d39c62aef79dd6971fb617ad87ad
Comment 3 Jack Hill 2024-11-14 22:48:09 UTC
Git commit 25af9be945684b72dbbab221f1b423db33dd1ae3 by Jack Hill.
Committed on 14/11/2024 at 22:48.
Pushed by jackh into branch 'release/24.12'.

libvlc: Set media player role to "Music"

PipeWire/WirePlumber stream restore function often uses the streams
`media.role` property to restore stream volume and output device when
a new stream is stated. By default libvlc doesn't have a value set for
the relevant property, resulting in `media.role = "Movie"` being the
default. This is annoying (to me) as I'd like to use a different device
(speakers) for music playback than for video playback (my headphones).

Test-plan:

I inspected the audio stream generated by Elisa with this patch applied.
I first get the stream ID using `wpctl status` and then inspecting the
correct stream using `wpctl inspect xxx`. It now (correctly) reports
`media.role = "Music"` instead of `media.role = "Movie"` like before.

Stream restore is also working correctly with this patch applied:

1. Play a video using e.g. mpv. Note which output device and playback
   volume are used for it. Quit mpv.
2. Start Elisa and play a song and pause it after a bit.
3. Either while still playing or when paused, change the volume and/or
   stream output device to something else.
4. Pause the stream.
5. Start playing a video (again) using e.g. mpv.
   Without the patch applied it should be using the same device/volume
   that Elisa is set to.    With it applied it should be using whatever
   was used previously.
6. Switch mpv to another audio device and/or change the playback volume.
7. Start playing a new track in Elisa, either by clicking "Next track"
   or clicking one (even the same, already paused file works) in the
   playlist.
8. Elisa starts a new stream.
   With the patch applied the stream should go to the device set in
   step 3 with the same volume it had before. Without the patch the
   stream uses the same properties as mpv in step 6.

With the Qt Multimedia backend it's likely not possible to implement at
the moment as the stream type support got removed from Qt 3 years ago here:
https://github.com/qt/qtmultimedia/commit/634894a8a83b021386da8c2672628b0b26185ef3


(cherry picked from commit 1e3fd23902f3d39c62aef79dd6971fb617ad87ad)

b11ea27f libvlc: Set media player role to "Music"

Co-authored-by: Daniel Schulte <trilader+kde@schroedingers-bit.net>

M  +2    -0    src/audiowrapper_libvlc.cpp

https://invent.kde.org/multimedia/elisa/-/commit/25af9be945684b72dbbab221f1b423db33dd1ae3