+ initial import

This commit is contained in:
nicobo 2020-11-18 22:01:32 +01:00
parent a62a487a3f
commit 00796bc682
No known key found for this signature in database
GPG key ID: 2581E71C5FA5285F
8 changed files with 333 additions and 0 deletions

View file

@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View file

@ -0,0 +1,95 @@
Role Name
=========
**⚠ NOT RELEASED YET - VERY INCOMPLETE & NOT TESTED ⚠**
This role makes the system sound available as an audio stream through DLNA.
That means that you will be able to listen to the sound playing on the targeted machine from any DLNA renderer.
This is used for instance to listen to the music played by a Raspberry Pi with Kodi on your Hi-Fi DLNA speakers.
Under the hood it :
- installs Rygel and GstLaunch (including PulseAudio and gstreamer, as required dependencies)
- creates a PulseAudio sink that appears as an audio stream on DLNA renderers
By default FLAC and MPEG streams are available ; you may customize / change this by updating the "Configure Rygel" step in `tasks/main.yml`.
FLAC is recommended to reduce audio delay if you have a decent network speed.
See https://wiki.gnome.org/Projects/Rygel/Pulseaudio#gst-launch.
Requirements
------------
It is aimed at [Raspberry Pi](https://www.raspberrypi.org/) and not tested on other platforms.
Role Variables
--------------
Please look at the self-documented `defaults/main.yml` to see what variables you need to set.
Dependencies
------------
None.
Example Playbook
----------------
- hosts: servers
roles:
- role: nicolabs.dlna_audiostream
vars:
pulseaudio_users:
- pi
- me
dlna_audiostream_expose_system_audio: no
A note on PulseAudio configuration for DLNA
-------------------------------------------
[All sources I've found](https://wiki.gnome.org/Projects/Rygel/Pulseaudio) give the graphic way to configure the DLNA server : by checking two boxes in the **paprefs** utility.
However this didn't allow for automatic configuration so this role implements it by adding the corresponding lines in `/etc/pulse/default.pa`.
I relied on https://gitlab.freedesktop.org/pulseaudio/paprefs/-/tree/master/src to understand how to replicate the _paprefs_ behaviour.
The effect is the same but, as stated in `default.pa`, please note that changes in this file will not be seen in _paprefs_ and playing with both might generate conflicts (well I guess one will just override the other...).
TODO
----
- redirect the default system sound to this sink (may be ignored if you just want to plug a given application into the sink)
- start Rygel at boot
- create more / allow customizing audio stream (e.g. a compressed one when the network is not reliable enough)
References
----------
- [PulseAudio main documentation](https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/)
- [github.com/BaReinhard/Super-Simple-Raspberry-Pi-Audio-Receiver-Install](https://github.com/BaReinhard/Super-Simple-Raspberry-Pi-Audio-Receiver-Install/blob/master/init.d/pulseaudio)
License
-------
MIT
Author Information
------------------
https//nicolabs.net

View file

@ -0,0 +1,19 @@
---
# Name of the users who will get access to pulseaudio.
# This is required for users who wish to play sound into the DLNA stream.
# An empty list will make no change.
#pulseaudio_users: [ pi', 'me' ]
pulseaudio_users: []
# Change this to /home/<user>/.config/rygel.conf if you want to configure it for a given user.
# By default it configures Rygel system-wide (/etc/rygel.conf).
rygel_conf_path: /etc/rygel.conf
# Name/template name of the default device and streams created by this role, as seen on the DLNA renderer.
# See http://rygel-project.org/doc/latest/rygel.conf.html for available variables to customize them.
dlna_audiostream_device_title: "Live audio streams on @HOSTNAME@"
dlna_audiostream_flac_title: "FLAC audio stream"
dlna_audiostream_mpeg_title: "MPEG audio stream"
# Whether or not to redirect all system audio to the created DLNA streams
dlna_audiostream_expose_system_audio: yes

View file

@ -0,0 +1,26 @@
galaxy_info:
author: nicobo
description: creator
company: nicolabs <https://nicolabs.net>
license: MIT
min_ansible_version: 2.9
platforms:
- name: Debian
versions:
- 10
galaxy_tags:
- audio
- dlna
- gstlaunch
- gstreamer
- pulseaudio
- raspberry
- raspberrypi
- raspbian
- rygel
dependencies: []

View file

@ -0,0 +1,147 @@
---
- name: Install packages
apt:
name:
########################
# PulseAudio
- pulseaudio
# Graphical tools ; not required for this role but might be of some interest to debug
#- paprefs
#- pavucontrol
# should be installed by default
# - pulseaudio-module-gsettings
# - pulseaudio-module-zeroconf
# Useful tools : paplay, ...
- pulseaudio-utils
# Allows applications using ALSA (which is teh default on debian now) to be routed to PulseAudio natively
# FIXME Not available on raspbian ? Maybe an alternative : https://raspberrypi.stackexchange.com/a/1544
# - pulseaudio-alsa
########################
########################
# Rygel part - https://gavv.github.io/articles/pulseaudio-under-the-hood/#dlna-and-chromecast
- rygel
# Recommended but not required ?
- gupnp-tools
########################
########################
# GstLaunch part - https://wiki.gnome.org/Projects/Rygel/Pulseaudio
- rygel-gst-launch
# This package is required or you will get the error `(rygel:21053): RygelServer-WARNING **: 24:08:14.471: rygel-http-request.vala:103: Could not create GstElement for URI gst-launch://pulsesrc%20device%3Dupnp%2Emonitor%20%21%20flacenc`
# See https://mail.gnome.org/archives/rygel-list/2014-March/msg00008.html
- gstreamer1.0-pulseaudio
# This one also seems to be required but appears to be already installed by the previous commands
#- gstreamer1.0-plugins-ugly
########################
state: present
- debug:
var: pulseaudio_users
# https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/PerfectSetup/
- name: Adds users to the 'audio' group so that they get access to pa
loop: "{{ pulseaudio_users }}"
user:
name: "{{ item }}"
append: yes
groups: audio
# Note that as [pa in system mode cannot work with rygel](https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/)
# it must be [started in user mode](https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Running/)
# From my tests it should start on-demand out of the box after installation.
# Below is the daemon that spawn dedicated instances when required.
- name: Make sure pulseaudio daemon is started
service:
name: pulseaudio
state: started
enabled: yes
- name: Configure pulseaudio
lineinfile:
path: "/etc/pulse/default.pa"
line: "{{ item }}"
state: present
backup: yes
loop:
- load-module module-http-protocol-tcp
# GstLaunch configuration : this is the same as checking 'Make local sound devices available as DLNA/_UPnP Media Server' in paprefs
# See https://gitlab.freedesktop.org/pulseaudio/paprefs/-/blob/54c99e5206dad7dcc76e40a4e17d2e3a452590a0/src/paprefs.cc
- load-module module-rygel-media-server
# GstLaunch configuration : this is the same as checking 'Create separate audio device for DLNA/UPnP media streaming' in paprefs
# See https://gitlab.freedesktop.org/pulseaudio/paprefs/-/blob/54c99e5206dad7dcc76e40a4e17d2e3a452590a0/src/paprefs.cc
- load-module module-null-sink sink_name=upnp format=s16be channels=2 rate=44100 sink_properties="device.description='DLNA/UPnP Streaming' device.bus='network' device.icon_name='network-server'"
register: module_http
- name: Restart pulseaudio daemon if config changed
command: systemctl --user restart pulseaudio.service
when: module_http.changed
# https://wiki.gnome.org/Projects/Rygel/Pulseaudio
- name: Configure Rygel
ini_file:
path: "{{ rygel_conf_path }}"
section: "{{ item.section }}"
option: "{{ item.option }}"
value: "{{ item.value }}"
no_extra_spaces: yes
backup: yes
loop:
# Still required ?
- section: External
option: enabled
value: "true"
# Still required ?
- section: org.gnome.UPnP.MediaServer2.PulseAudio
option: enabled
value: "true"
# GstLaunch part - feel free to customize / add more streams - see https://wiki.gnome.org/Projects/Rygel/Pulseaudio#gst-launch
- section: GstLaunch
option: enabled
value: "true"
- section: GstLaunch
option: title
value: "{{ dlna_audiostream_device_title }}"
- section: GstLaunch
option: launch-items
# If you add new streams don't forget to add them to this line
value: "myaudioflac;myaudiompeg"
# GstLaunch part : flac-encoded stream - feel free to customize
- section: GstLaunch
option: myaudioflac-title
value: "{{ dlna_audiostream_flac_title }}"
- section: GstLaunch
option: myaudioflac-mime
value: "audio/flac"
- section: GstLaunch
option: myaudioflac-launch
value: "pulsesrc device=upnp.monitor ! flacenc"
# GstLaunch part : mpeg-encoded stream - feel free to customize
- section: GstLaunch
option: myaudiompeg-title
value: "{{ dlna_audiostream_mpeg_title }}"
- section: GstLaunch
option: myaudiompeg-mime
value: "audio/mpeg"
- section: GstLaunch
option: myaudiompeg-launch
value: "pulsesrc device=upnp.monitor ! audio/x-raw,channels=2 ! lamemp3enc target=quality quality=6"
# TODO Allow preventing Rygel from exporting all media by default
# TODO Start Rygel at boot
# TODO Redirect system sound to the upnp sink
# # https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/PerfectSetup/#alsaapplications
# - name: Configure alsa to use pulse by default
# template:
# src: templates/etc/asound.conf
# dest: /etc/asound.conf

View file

@ -0,0 +1,10 @@
pcm.pulse {
type pulse
}
ctl.pulse {
type pulse
}
pcm.default pulse
ctl.default pulse

View file

@ -0,0 +1,2 @@
localhost

View file

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- dlna-audiostream