Prześlij pliki do "audio"
This commit is contained in:
1 parent
93a68999dc
commit
b720c824c6
1 file changed
+123
@@ -0,0 +1,123 @@
|
|||||||
|
# audio/sources.py
|
||||||
|
import logging
|
||||||
|
from gi.repository import Gst
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# Abstrakcyjna klasa bazowa
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
class AudioSource:
|
||||||
|
"""Bazowa klasa źródła audio – implementuje jedynie interfejs."""
|
||||||
|
|
||||||
|
def __init__(self, name: str):
|
||||||
|
self.name = name
|
||||||
|
self.pipeline_src = None # GStreamer element (np. uridecodebin)
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
"""Zwraca gotowy element GStreamer, który można podłączyć do AudioEngine."""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
"""Przygotowanie (np. połączenie z DBus, Bluetooth itp.)."""
|
||||||
|
log.debug("%s – activate()", self.name)
|
||||||
|
|
||||||
|
def deactivate(self):
|
||||||
|
"""Czyszczenie zasobów."""
|
||||||
|
log.debug("%s – deactivate()", self.name)
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# Radio – odtwarzanie strumienia HTTP (np. Icecast)
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
class RadioSource(AudioSource):
|
||||||
|
def __init__(self, station_url: str, station_name: str = "radio"):
|
||||||
|
super().__init__(station_name)
|
||||||
|
self.url = station_url
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
src = Gst.ElementFactory.make("souphttpsrc", None)
|
||||||
|
src.set_property("location", self.url)
|
||||||
|
decode = Gst.ElementFactory.make("decodebin", None)
|
||||||
|
bin_ = Gst.Bin.new("radio_bin")
|
||||||
|
bin_.add(src)
|
||||||
|
bin_.add(decode)
|
||||||
|
src.link(decode)
|
||||||
|
self.pipeline_src = bin_
|
||||||
|
return bin_
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# Bluetooth – używamy pulse‑audio source (simplified)
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
class BluetoothSource(AudioSource):
|
||||||
|
def __init__(self, name: str = "bluetooth"):
|
||||||
|
super().__init__(name)
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
# Zakładamy, że Bluetooth jest już połączony z PulseAudio jako "bluez_source"
|
||||||
|
src = Gst.ElementFactory.make("pulsesrc", None)
|
||||||
|
src.set_property("device", "bluez_source")
|
||||||
|
self.pipeline_src = src
|
||||||
|
return src
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# Analog – Phono / Line1 / Line2 (przez ALSA)
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
class AnalogSource(AudioSource):
|
||||||
|
def __init__(self, device: str, name: str):
|
||||||
|
"""
|
||||||
|
`device` – nazwa ALSA (np. "hw:1,0").
|
||||||
|
`name` – przyjazna nazwa (phono, line1, line2)
|
||||||
|
"""
|
||||||
|
super().__init__(name)
|
||||||
|
self.device = device
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
src = Gst.ElementFactory.make("alsasrc", None)
|
||||||
|
src.set_property("device", self.device)
|
||||||
|
self.pipeline_src = src
|
||||||
|
return src
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# SPDIF (digital) – także ALSA, ale inny adres
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
class SpdifSource(AudioSource):
|
||||||
|
def __init__(self, device: str = "hw:1,0", name: str = "spdif"):
|
||||||
|
super().__init__(name)
|
||||||
|
self.device = device
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
src = Gst.ElementFactory.make("alsasrc", None)
|
||||||
|
src.set_property("device", self.device)
|
||||||
|
self.pipeline_src = src
|
||||||
|
return src
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
# CD / USB – tylko szkielet (można rozbudować później)
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
class CdSource(AudioSource):
|
||||||
|
def __init__(self, device: str = "/dev/cdrom", name: str = "cd"):
|
||||||
|
super().__init__(name)
|
||||||
|
self.device = device
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
src = Gst.ElementFactory.make("cdparanoiasrc", None)
|
||||||
|
src.set_property("device", self.device)
|
||||||
|
self.pipeline_src = src
|
||||||
|
return src
|
||||||
|
|
||||||
|
|
||||||
|
class UsbSource(AudioSource):
|
||||||
|
def __init__(self, device: str = "/dev/sr0", name: str = "usb"):
|
||||||
|
super().__init__(name)
|
||||||
|
self.device = device
|
||||||
|
|
||||||
|
def build_source(self):
|
||||||
|
src = Gst.ElementFactory.make("alsasrc", None)
|
||||||
|
src.set_property("device", self.device)
|
||||||
|
self.pipeline_src = src
|
||||||
|
return src
|
||||||
Reference in new issue
Block a user