mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-22 11:30:59 +00:00
spotifyaudiosrc: Support configurable bitrate
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1073>
This commit is contained in:
parent
0f383a6545
commit
3c31c98d95
3 changed files with 87 additions and 3 deletions
|
@ -31,6 +31,8 @@ use librespot::playback::{
|
||||||
player::{Player, PlayerEvent},
|
player::{Player, PlayerEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::Bitrate;
|
||||||
|
|
||||||
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
||||||
gst::DebugCategory::new(
|
gst::DebugCategory::new(
|
||||||
"spotifyaudiosrc",
|
"spotifyaudiosrc",
|
||||||
|
@ -71,6 +73,7 @@ struct Settings {
|
||||||
cache_files: String,
|
cache_files: String,
|
||||||
cache_max_size: u64,
|
cache_max_size: u64,
|
||||||
track: String,
|
track: String,
|
||||||
|
bitrate: Bitrate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -132,6 +135,11 @@ impl ObjectImpl for SpotifyAudioSrc {
|
||||||
.default_value(Some(""))
|
.default_value(Some(""))
|
||||||
.mutable_ready()
|
.mutable_ready()
|
||||||
.build(),
|
.build(),
|
||||||
|
glib::ParamSpecEnum::builder::<Bitrate>("bitrate")
|
||||||
|
.nick("Spotify bitrate")
|
||||||
|
.blurb("Spotify audio bitrate in kbit/s")
|
||||||
|
.mutable_ready()
|
||||||
|
.build()
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -164,6 +172,10 @@ impl ObjectImpl for SpotifyAudioSrc {
|
||||||
let mut settings = self.settings.lock().unwrap();
|
let mut settings = self.settings.lock().unwrap();
|
||||||
settings.track = value.get().expect("type checked upstream");
|
settings.track = value.get().expect("type checked upstream");
|
||||||
}
|
}
|
||||||
|
"bitrate" => {
|
||||||
|
let mut settings = self.settings.lock().unwrap();
|
||||||
|
settings.bitrate = value.get().expect("type checked upstream");
|
||||||
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +206,10 @@ impl ObjectImpl for SpotifyAudioSrc {
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
settings.track.to_value()
|
settings.track.to_value()
|
||||||
}
|
}
|
||||||
|
"bitrate" => {
|
||||||
|
let settings = self.settings.lock().unwrap();
|
||||||
|
settings.bitrate.to_value()
|
||||||
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,7 +450,7 @@ impl SpotifyAudioSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (credentials, cache, track) = {
|
let (credentials, cache, track, bitrate) = {
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
|
|
||||||
let credentials_cache = if settings.cache_credentials.is_empty() {
|
let credentials_cache = if settings.cache_credentials.is_empty() {
|
||||||
|
@ -482,7 +498,10 @@ impl SpotifyAudioSrc {
|
||||||
bail!("track is not set")
|
bail!("track is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
(credentials, cache, settings.track.clone())
|
let bitrate = settings.bitrate.into();
|
||||||
|
gst::debug!(CAT, imp: self, "Requesting bitrate {:?}", bitrate);
|
||||||
|
|
||||||
|
(credentials, cache, settings.track.clone(), bitrate)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (session, _credentials) =
|
let (session, _credentials) =
|
||||||
|
@ -490,6 +509,7 @@ impl SpotifyAudioSrc {
|
||||||
|
|
||||||
let player_config = PlayerConfig {
|
let player_config = PlayerConfig {
|
||||||
passthrough: true,
|
passthrough: true,
|
||||||
|
bitrate,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,42 @@ use gst::prelude::*;
|
||||||
|
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
|
||||||
|
#[repr(u32)]
|
||||||
|
#[enum_type(name = "GstRsSpotifyBitrate")]
|
||||||
|
enum Bitrate {
|
||||||
|
#[enum_value(name = "96 kbit/s", nick = "96")]
|
||||||
|
B96,
|
||||||
|
#[enum_value(name = "160 kbit/s", nick = "160")]
|
||||||
|
B160,
|
||||||
|
#[enum_value(name = "320 kbit/s", nick = "320")]
|
||||||
|
B320,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Bitrate {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::B160
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Bitrate> for librespot::playback::config::Bitrate {
|
||||||
|
fn from(value: Bitrate) -> Self {
|
||||||
|
match value {
|
||||||
|
Bitrate::B96 => Self::Bitrate96,
|
||||||
|
Bitrate::B160 => Self::Bitrate160,
|
||||||
|
Bitrate::B320 => Self::Bitrate320,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct SpotifyAudioSrc(ObjectSubclass<imp::SpotifyAudioSrc>) @extends gst_base::PushSrc, gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler;
|
pub struct SpotifyAudioSrc(ObjectSubclass<imp::SpotifyAudioSrc>) @extends gst_base::PushSrc, gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
||||||
|
#[cfg(feature = "doc")]
|
||||||
|
Bitrate::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
|
||||||
|
|
||||||
gst::Element::register(
|
gst::Element::register(
|
||||||
Some(plugin),
|
Some(plugin),
|
||||||
"spotifyaudiosrc",
|
"spotifyaudiosrc",
|
||||||
|
|
|
@ -6311,6 +6311,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"bitrate": {
|
||||||
|
"blurb": "Spotify audio bitrate in kbit/s",
|
||||||
|
"conditionally-available": false,
|
||||||
|
"construct": false,
|
||||||
|
"construct-only": false,
|
||||||
|
"controllable": false,
|
||||||
|
"default": "160 (1)",
|
||||||
|
"mutable": "ready",
|
||||||
|
"readable": true,
|
||||||
|
"type": "GstRsSpotifyBitrate",
|
||||||
|
"writable": true
|
||||||
|
},
|
||||||
"cache-credentials": {
|
"cache-credentials": {
|
||||||
"blurb": "Directory where to cache Spotify credentials",
|
"blurb": "Directory where to cache Spotify credentials",
|
||||||
"conditionally-available": false,
|
"conditionally-available": false,
|
||||||
|
@ -6391,7 +6403,28 @@
|
||||||
},
|
},
|
||||||
"filename": "gstspotify",
|
"filename": "gstspotify",
|
||||||
"license": "MPL",
|
"license": "MPL",
|
||||||
"other-types": {},
|
"other-types": {
|
||||||
|
"GstRsSpotifyBitrate": {
|
||||||
|
"kind": "enum",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"desc": "96 kbit/s",
|
||||||
|
"name": "96",
|
||||||
|
"value": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"desc": "160 kbit/s",
|
||||||
|
"name": "160",
|
||||||
|
"value": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"desc": "320 kbit/s",
|
||||||
|
"name": "320",
|
||||||
|
"value": "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"package": "gst-plugin-spotify",
|
"package": "gst-plugin-spotify",
|
||||||
"source": "gst-plugin-spotify",
|
"source": "gst-plugin-spotify",
|
||||||
"tracers": {},
|
"tracers": {},
|
||||||
|
|
Loading…
Reference in a new issue