Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPRIS Device Name #1100

Merged
merged 6 commits into from
Sep 27, 2022
Merged

MPRIS Device Name #1100

merged 6 commits into from
Sep 27, 2022

Conversation

klay2000
Copy link
Contributor

@klay2000 klay2000 commented Aug 9, 2022

Added a compilation option to append device names to the end of dbus paths, this allows multiple Spotifyd daemons to be running each with a unique dbus object for MPRIS as long as they have unique device names.

@eladyn
Copy link
Member

eladyn commented Aug 15, 2022

Hi and thanks for the contribution!

While your approach certainly works, I think that it'd be much nicer, if this setting either were the default or customizable at runtime via some configuration option. The reason for this is that most people probably download a prebuilt spotifyd binary rather than building it themselves, so they never get to choose the dbus name behaviour.

Happy to hear your thoughts on that!

@klay2000
Copy link
Contributor Author

A configuration option sounds like a good idea, I'll give that a try.

Copy link
Member

@eladyn eladyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me now, thanks! You'll need to run cargo fmt before this is ready, to keep coding style consistent.

In the docs, there's also the sample config, where this new option should be added as well, accompanied by some short explanation.

src/dbus_mpris.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
eladyn
eladyn previously approved these changes Aug 26, 2022
Copy link
Member

@eladyn eladyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment. Apart from that, I think this is ready. Thank you! Now, we'll just have to wait for the maintainers.

docs/src/config/File.md Outdated Show resolved Hide resolved
@JasonLG1979
Copy link

The spec says that apps that allow multiple instances should follow this convention.

So if the name is "spotifyd" the bus name should be:

org.mpris.MediaPlayer2.spotifyd.instance{deviceName}

Where deviceName is the sanitized device name. Bus names can only contain ASCII characters (but no -)

@JasonLG1979
Copy link

JasonLG1979 commented Sep 2, 2022

Really the easiest way is just to follow the spec and make the bus name org.mpris.MediaPlayer2.spotifyd.instance{pid} all of the time and not even use the DeviceName at all.

@eladyn
Copy link
Member

eladyn commented Sep 2, 2022

The spec says that apps that allow multiple instances should follow this convention.

Thanks for chiming in! This is indeed something that should be considered.

So if the name is "spotifyd" the bus name should be:

org.mpris.MediaPlayer2.spotifyd.instance{deviceName}

Where deviceName is the sanitized device name. Bus names can only contain ASCII characters (but no -)

If the deviceName doesn't start with a number, we could omit the instance part, but I don't think that is guaranteed. The ASCII sanitization is indeed missing (even in the current implementation).

Really the easiest way is just to follow the spec and make the bus name org.mpris.MediaPlayer2.spotifyd.instance{pid} all of the time and not even use the DeviceName at all.

I can imagine that some use cases might benefit from the explicit naming with DeviceName, since it makes the bus names reproducible between restarts and can be hard coded in a custom client that targets specifically one instance. I personally don't have a use case for this flag, so I don't know in which situations people would be using it. Might as well be that the pid version is just sufficient for those who need it. Probably something that @klay2000 can answer best.

@JasonLG1979
Copy link

JasonLG1979 commented Sep 2, 2022

I don't know in which situations people would be using it. Might as well be that the pid version is just sufficient for those who need it. Probably something that @klay2000 can answer best.

I'm not sure either? If it's just for the sake of uniqueness purely to allow for multiple instances I would follow the specs suggestion, and really that could just be the default behavior all of the time.

On the other hand if it's to let a user know what the instance is in any sort of UI you'd want to set the Identity prop to something like Spotifyd {DeviceName} Identity can be any arbitrary string, it's not bound by the bus name rules, and that's what would be displayed to a user not the bus name. You may already do this idk?

@klay2000
Copy link
Contributor Author

klay2000 commented Sep 6, 2022

Reading the spec, it actually only says that it must have a dot and a unique identifier appended to it's bus name, the instance{pid} thing is just an example so I think something like org.mpris.MediaPlayer2.spotifyd.{DeviceName} is sufficient to conform to the spec.

As far as ASCII sanitization goes I definitely forgot about that one, I'll make these changes and push it up.

@JasonLG1979
Copy link

Do you need it to be the device name for any reason in particular? If it's just for the sake of having a unique name I strongly suggest using what the example suggests as it is the convention that all other players follow. It's also useful to clients because if it's the pid it can be used for other things.

@klay2000
Copy link
Contributor Author

klay2000 commented Sep 6, 2022

I suppose either is useful but I've been debugging something that uses this feature and I've been running into issues with Spotifyd's PID not being the same as the one it has on creation when I try to kill it's process, so at the moment it seems like it's not going to be as easy to make use of.

@JasonLG1979
Copy link

Pids don't change over the course of a program's life. You're prob getting a pid of a child process/thread of Spotifyd mixed up with the main process/thread.

@JasonLG1979
Copy link

JasonLG1979 commented Sep 6, 2022

Not to mention that 2 equally valid device names could be sanitized into the same name thus breaking the uniqueness guarantee.

@klay2000
Copy link
Contributor Author

klay2000 commented Sep 6, 2022

Exactly, the parent process is dying and leaving several child processes.

@klay2000
Copy link
Contributor Author

klay2000 commented Sep 6, 2022

Alright, I'll change it to the PID.

@JasonLG1979
Copy link

My guess would be that you want the pid of the Tokio runtime.

@JasonLG1979
Copy link

If you try to grab a pid before you're in the runtime it may be wrong?

@JasonLG1979
Copy link

JasonLG1979 commented Sep 7, 2022

I suppose either is useful but I've been debugging something that uses this feature and I've been running into issues with Spotifyd's PID not being the same as the one it has on creation when I try to kill it's process, so at the moment it seems like it's not going to be as easy to make use of.

I sprinkled some println!("PID in 'whatever': {}", std::process::id()); all around the current dev version of librespot and they all printed the same PID.

My guess is that if you're using systemd (or some other way to daemonize Spotifyd) is that you're not getting the actual PID but the PID of the task that spawns Spotifyd?

@JasonLG1979
Copy link

This whole PR could be as simple as:

    let busname = format!(
        "org.mpris.MediaPlayer2.spotifyd.instance{}",
        std::process::id()
    );
    
    conn.request_name(&busname, true, true, true)
        .await
        .expect("Failed to register dbus player name");

src/dbus_mpris.rs Outdated Show resolved Hide resolved
@slondr slondr added this to the v0.4.0 milestone Sep 11, 2022
Copy link

@JasonLG1979 JasonLG1979 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need all the b = stuff, you've only got one value and format args can be positional. The only reason to assign them is if it needs to be repeated in the string.

src/dbus_mpris.rs Outdated Show resolved Hide resolved
Copy link
Member

@eladyn eladyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your work!

@eladyn eladyn requested a review from a team September 26, 2022 20:22
@robinvd robinvd merged commit e523711 into Spotifyd:master Sep 27, 2022
2opremio added a commit to 2opremio/spotifyd that referenced this pull request Aug 19, 2024
Revert "Merge pull request Spotifyd#1100 from klay2000/mpris_device_name"

This reverts commit e523711, reversing
changes made to a4316df.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants