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, glib::Enum)]
15#[repr(u32)]
16#[enum_type(name = "GstRsSpotifyBitrate")]
17enum Bitrate {
18    #[enum_value(name = "96 kbit/s", nick = "96")]
19    B96,
20    #[enum_value(name = "160 kbit/s", nick = "160")]
21    B160,
22    #[enum_value(name = "320 kbit/s", nick = "320")]
23    B320,
24}
25
26impl Default for Bitrate {
27    fn default() -> Self {
28        Self::B160
29    }
30}
31
32impl From<Bitrate> for librespot_playback::config::Bitrate {
33    fn from(value: Bitrate) -> Self {
34        match value {
35            Bitrate::B96 => Self::Bitrate96,
36            Bitrate::B160 => Self::Bitrate160,
37            Bitrate::B320 => Self::Bitrate320,
38        }
39    }
40}
41
42glib::wrapper! {
43    pub struct SpotifyAudioSrc(ObjectSubclass<imp::SpotifyAudioSrc>) @extends gst_base::PushSrc, gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler;
44}
45
46pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
47    #[cfg(feature = "doc")]
48    Bitrate::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
49
50    gst::Element::register(
51        Some(plugin),
52        "spotifyaudiosrc",
53        gst::Rank::PRIMARY,
54        SpotifyAudioSrc::static_type(),
55    )
56}