Skip to main content

gstspotify/spotifyaudiosrc/
mod.rs

1// Copyright (C) 2021 Guillaume Desmottes <guillaume@desmottes.be>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
4// If a copy of the MPL was not distributed with this file, You can obtain one at
5// <https://mozilla.org/MPL/2.0/>.
6//
7// SPDX-License-Identifier: MPL-2.0
8
9use gst::glib;
10use gst::prelude::*;
11
12mod imp;
13
14#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, Default, glib::Enum)]
15#[repr(u32)]
16#[enum_type(name = "GstRsSpotifyBitrate")]
17enum Bitrate {
18    #[enum_value(name = "96 kbit/s", nick = "96")]
19    B96,
20    #[default]
21    #[enum_value(name = "160 kbit/s", nick = "160")]
22    B160,
23    #[enum_value(name = "320 kbit/s", nick = "320")]
24    B320,
25}
26
27impl From<Bitrate> for librespot_playback::config::Bitrate {
28    fn from(value: Bitrate) -> Self {
29        match value {
30            Bitrate::B96 => Self::Bitrate96,
31            Bitrate::B160 => Self::Bitrate160,
32            Bitrate::B320 => Self::Bitrate320,
33        }
34    }
35}
36
37glib::wrapper! {
38    pub struct SpotifyAudioSrc(ObjectSubclass<imp::SpotifyAudioSrc>) @extends gst_base::PushSrc, gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler;
39}
40
41pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
42    #[cfg(feature = "doc")]
43    Bitrate::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
44
45    gst::Element::register(
46        Some(plugin),
47        "spotifyaudiosrc",
48        gst::Rank::PRIMARY,
49        SpotifyAudioSrc::static_type(),
50    )
51}