Enhancements
Enable the AirPlay 2 build to operate an optional classic-AirPlay-only service or to gracefully degrade to classic AirPlay, as follows:
1. Add a new command-line option '-—service-type=<type>' and an equivalent configuration entry 'service_type = "<type>"' in the 'general' section of the configuration file,
where <type> can be "auto", "classic" or "airplay2":
1. "auto" (default) means that the service will be AirPlay 2 if NQPTP is running. If NQPTP is not running, classic AirPlay service will be provided instead, and in that case,
"(Classic)" will be appended to the default AirPlay service name visible to AirPlay clients like Apple Music, for example "RaspberryPi3B (Classic)".
2. "classic" means the service will be classic AirPlay (aka AirPlay 1).
3. "airplay2" means the service will be the modern AirPlay 2. In this case, as distinct from "auto", if NQPTP is not running, Shairport Sync will log an error and terminate.
2. In the systemd service file, NQPTP is now a "Want" rather than a "Require". If it's present, then it will be launched before Shairport Sync. If it's absent, Shairport Sync will launch anyway.
3. Improve the delivery of input format changes and emit 'sdsc' metadata when changes occur.
4. Emit new format information in the log if statistics is enabled.
Docker Changes
1. Support for linux/arm/v6 has been dropped, as Docker is no longer supported.
2. NQPTP is not started in the AirPlay 2 Docker image if '--service-type=classic' or '--service-type=airplay1' is in the command line options at the end of the docker run command.
The purpose is to ensure that ports 319 and 320 are left alone when the AirPlay 2 image is set to provide Classic service only.
Note that setting the configuration file 'service_type' to 'classic' will not prevent NQPTP from starting up -- you must use the command line option.
3. A new "dev" target has been added. It is a large image containing the custom-built FFmpeg library, NQPTP, Avahi and D-Bus along with the Shairport Sync source and
all necessary development tools. When started, Avahi, D-Bus and NQPTP are all installed and running. The bash shell has also been added and is entered.
Stability Improvements
Reorganise session preemption to fully terminate the existing session before starting a new one.
Don't delay closing the event port to wait for it to be closed at the client end.
Add a safe_socket_close() function to ensure sockets are fully closed. Use -1 to designate closed rather than 0, to prevent attempts to reclose sockets, causing mayhem.
Re-order FFmpeg decommissioning during teardown.
This commit is contained in:
@@ -23,7 +23,7 @@ jobs:
|
|||||||
outputs:
|
outputs:
|
||||||
nqptp_branch: ${{ env.NQPTP_BRANCH }}
|
nqptp_branch: ${{ env.NQPTP_BRANCH }}
|
||||||
push_docker_image: ${{ env.PUSH_DOCKER_IMAGE }}
|
push_docker_image: ${{ env.PUSH_DOCKER_IMAGE }}
|
||||||
docker_platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
|
docker_platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
|
||||||
steps:
|
steps:
|
||||||
- name: Push docker image if this is a tag.
|
- name: Push docker image if this is a tag.
|
||||||
if: github.ref_type == 'tag'
|
if: github.ref_type == 'tag'
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
# Working with PulseAudio or PipeWire
|
# Working with PulseAudio or PipeWire
|
||||||
Many Linux systems, especially desktop Linuxes with a GUI, have [PipeWire](https://pipewire.org) or [PulseAudio](https://www.freedesktop.org/wiki/Software/PulseAudio/) installed as [sound servers](https://en.wikipedia.org/wiki/Sound_server).
|
Many Linux systems, especially desktop Linuxes with a GUI, have [PipeWire](https://pipewire.org) or [PulseAudio](https://www.freedesktop.org/wiki/Software/PulseAudio/) installed as [sound servers](https://en.wikipedia.org/wiki/Sound_server).
|
||||||
PipeWire and PulseAudio are widely used and have the great advantage of being easily able to mix audio from multiple sources. The slight downside is that audio may be further processed (e.g. transcoded) on its way to the output device.
|
PipeWire and PulseAudio are widely used and have the great advantage of being easily able to mix audio from multiple sources.
|
||||||
|
|
||||||
|
However, the main thing to remember about PipeWire and PulseAudio sound servers is they only become available when a user logs in -- that is, they are set up as _user services_.
|
||||||
|
Shairport Sync relies on them and therefore it must also be set up as a user service. Shairport Sync can not be set up as a system service because the PipeWire or PulseAudio services are not available when system services are launched just after system startup.
|
||||||
|
|
||||||
To use PipeWire or PulseAudio-based systems, Shairport Sync must be set up as a user service.
|
To use PipeWire or PulseAudio-based systems, Shairport Sync must be set up as a user service.
|
||||||
|
|
||||||
@@ -10,26 +13,5 @@ To use PipeWire or PulseAudio-based systems, Shairport Sync must be set up as a
|
|||||||
3. To check if PipeWire support is built into Shairport Sync, check that the string `PipeWire` is included in the version string. (Enter `$ shairport-sync -V` to get the version string.) Similarly, the version string will include `PulseAudio` if the PulseAudio backend is built in.
|
3. To check if PipeWire support is built into Shairport Sync, check that the string `PipeWire` is included in the version string. (Enter `$ shairport-sync -V` to get the version string.) Similarly, the version string will include `PulseAudio` if the PulseAudio backend is built in.
|
||||||
4. Remember to specify which backend Shairport Sync should use in the configuration file or on the command line.
|
4. Remember to specify which backend Shairport Sync should use in the configuration file or on the command line.
|
||||||
|
|
||||||
## Automatic Startup of Shairport Sync
|
## Starting Shairport Sync as a User Service
|
||||||
|
Please refer to [this](https://github.com/mikebrady/shairport-sync/blob/development/BUILD.md#5-enable-and-start-service) section to discover how to start Shairport Sync as a user service.
|
||||||
The main thing to remember about PipeWire and PulseAudio sound servers is that the services they offer only become available when a user logs in -- that is, they are set up as _user services_.
|
|
||||||
Shairport Sync relies on them, so it must also be set up as a user service; it can not be set up as a system service because the PipeWire or PulseAudio services needed by Shairport Sync are not available when system services are launched just after system startup.
|
|
||||||
|
|
||||||
### Starting Shairport Sync as a User Service
|
|
||||||
To make Shairport Sync start as a user service, (assuming you built and installed Shairport Sync using the BUILD.md guide), ensure you are logged in as the appropriate user and enter:
|
|
||||||
```
|
|
||||||
$ systemctl --user enable shairport-sync
|
|
||||||
```
|
|
||||||
Make sure it is _not enabled_ as a system service:
|
|
||||||
```
|
|
||||||
# systemctl disable shairport-sync
|
|
||||||
```
|
|
||||||
and then reboot.
|
|
||||||
|
|
||||||
#### Problems with User Service
|
|
||||||
Shairport Sync will function perfectly well as a user service, but there are a number of things to bear in mind:
|
|
||||||
|
|
||||||
1. The AirPlay service will only be available when the user is logged in. When the user logs out, Shairport Sync will terminate and the AirPlay service will disappear.
|
|
||||||
2. If the Linux system is a desktop Linux with a GUI, audio will be sent to the default output only when the user is logged in through the GUI.
|
|
||||||
|
|
||||||
Automatic user login may help address these problems.
|
|
||||||
|
|||||||
Executable → Regular
+63
-195
@@ -25,7 +25,6 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
#if defined(AUDIOFFT_APPLE_ACCELERATE)
|
#if defined(AUDIOFFT_APPLE_ACCELERATE)
|
||||||
#define AUDIOFFT_APPLE_ACCELERATE_USED
|
#define AUDIOFFT_APPLE_ACCELERATE_USED
|
||||||
#include <Accelerate/Accelerate.h>
|
#include <Accelerate/Accelerate.h>
|
||||||
@@ -41,15 +40,11 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace audiofft {
|
||||||
|
|
||||||
namespace audiofft
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
namespace detail
|
class AudioFFTImpl {
|
||||||
{
|
|
||||||
|
|
||||||
class AudioFFTImpl
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
AudioFFTImpl() = default;
|
AudioFFTImpl() = default;
|
||||||
AudioFFTImpl(const AudioFFTImpl &) = delete;
|
AudioFFTImpl(const AudioFFTImpl &) = delete;
|
||||||
@@ -60,38 +55,26 @@ namespace audiofft
|
|||||||
virtual void ifft(float *data, const float *re, const float *im) = 0;
|
virtual void ifft(float *data, const float *re, const float *im) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool IsPowerOf2(size_t val) { return (val == 1 || (val & (val - 1)) == 0); }
|
||||||
constexpr bool IsPowerOf2(size_t val)
|
|
||||||
{
|
|
||||||
return (val == 1 || (val & (val-1)) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename TypeDest, typename TypeSrc>
|
template <typename TypeDest, typename TypeSrc>
|
||||||
void ConvertBuffer(TypeDest* dest, const TypeSrc* src, size_t len)
|
void ConvertBuffer(TypeDest *dest, const TypeSrc *src, size_t len) {
|
||||||
{
|
for (size_t i = 0; i < len; ++i) {
|
||||||
for (size_t i=0; i<len; ++i)
|
|
||||||
{
|
|
||||||
dest[i] = static_cast<TypeDest>(src[i]);
|
dest[i] = static_cast<TypeDest>(src[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename TypeDest, typename TypeSrc, typename TypeFactor>
|
template <typename TypeDest, typename TypeSrc, typename TypeFactor>
|
||||||
void ScaleBuffer(TypeDest* dest, const TypeSrc* src, const TypeFactor factor, size_t len)
|
void ScaleBuffer(TypeDest *dest, const TypeSrc *src, const TypeFactor factor, size_t len) {
|
||||||
{
|
for (size_t i = 0; i < len; ++i) {
|
||||||
for (size_t i=0; i<len; ++i)
|
|
||||||
{
|
|
||||||
dest[i] = static_cast<TypeDest>(static_cast<TypeFactor>(src[i]) * factor);
|
dest[i] = static_cast<TypeDest>(static_cast<TypeFactor>(src[i]) * factor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End of namespace detail
|
} // End of namespace detail
|
||||||
|
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
||||||
|
|
||||||
#ifdef AUDIOFFT_OOURA_USED
|
#ifdef AUDIOFFT_OOURA_USED
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,25 +82,15 @@ namespace audiofft
|
|||||||
* @class OouraFFT
|
* @class OouraFFT
|
||||||
* @brief FFT implementation based on the great radix-4 routines by Takuya Ooura
|
* @brief FFT implementation based on the great radix-4 routines by Takuya Ooura
|
||||||
*/
|
*/
|
||||||
class OouraFFT : public detail::AudioFFTImpl
|
class OouraFFT : public detail::AudioFFTImpl {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
OouraFFT() :
|
OouraFFT() : detail::AudioFFTImpl(), _size(0), _ip(), _w(), _buffer() {}
|
||||||
detail::AudioFFTImpl(),
|
|
||||||
_size(0),
|
|
||||||
_ip(),
|
|
||||||
_w(),
|
|
||||||
_buffer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
OouraFFT(const OouraFFT &) = delete;
|
OouraFFT(const OouraFFT &) = delete;
|
||||||
OouraFFT &operator=(const OouraFFT &) = delete;
|
OouraFFT &operator=(const OouraFFT &) = delete;
|
||||||
|
|
||||||
virtual void init(size_t size) override
|
virtual void init(size_t size) override {
|
||||||
{
|
if (_size != size) {
|
||||||
if (_size != size)
|
|
||||||
{
|
|
||||||
_ip.resize(2 + static_cast<int>(std::sqrt(static_cast<double>(size))));
|
_ip.resize(2 + static_cast<int>(std::sqrt(static_cast<double>(size))));
|
||||||
_w.resize(size / 2);
|
_w.resize(size / 2);
|
||||||
_buffer.resize(size);
|
_buffer.resize(size);
|
||||||
@@ -129,8 +102,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void fft(const float* data, float* re, float* im) override
|
virtual void fft(const float *data, float *re, float *im) override {
|
||||||
{
|
|
||||||
// Convert into the format as required by the Ooura FFT
|
// Convert into the format as required by the Ooura FFT
|
||||||
detail::ConvertBuffer(_buffer.data(), data, _size);
|
detail::ConvertBuffer(_buffer.data(), data, _size);
|
||||||
|
|
||||||
@@ -142,8 +114,7 @@ namespace audiofft
|
|||||||
double *bEnd = b + _size;
|
double *bEnd = b + _size;
|
||||||
float *r = re;
|
float *r = re;
|
||||||
float *i = im;
|
float *i = im;
|
||||||
while (b != bEnd)
|
while (b != bEnd) {
|
||||||
{
|
|
||||||
*(r++) = static_cast<float>(*(b++));
|
*(r++) = static_cast<float>(*(b++));
|
||||||
*(i++) = static_cast<float>(-(*(b++)));
|
*(i++) = static_cast<float>(-(*(b++)));
|
||||||
}
|
}
|
||||||
@@ -154,16 +125,14 @@ namespace audiofft
|
|||||||
im[size2] = 0.0;
|
im[size2] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ifft(float* data, const float* re, const float* im) override
|
virtual void ifft(float *data, const float *re, const float *im) override {
|
||||||
{
|
|
||||||
// Convert into the format as required by the Ooura FFT
|
// Convert into the format as required by the Ooura FFT
|
||||||
{
|
{
|
||||||
double *b = _buffer.data();
|
double *b = _buffer.data();
|
||||||
double *bEnd = b + _size;
|
double *bEnd = b + _size;
|
||||||
const float *r = re;
|
const float *r = re;
|
||||||
const float *i = im;
|
const float *i = im;
|
||||||
while (b != bEnd)
|
while (b != bEnd) {
|
||||||
{
|
|
||||||
*(b++) = static_cast<double>(*(r++));
|
*(b++) = static_cast<double>(*(r++));
|
||||||
*(b++) = -static_cast<double>(*(i++));
|
*(b++) = -static_cast<double>(*(i++));
|
||||||
}
|
}
|
||||||
@@ -182,49 +151,37 @@ namespace audiofft
|
|||||||
std::vector<double> _w;
|
std::vector<double> _w;
|
||||||
std::vector<double> _buffer;
|
std::vector<double> _buffer;
|
||||||
|
|
||||||
void rdft(int n, int isgn, double *a, int *ip, double *w)
|
void rdft(int n, int isgn, double *a, int *ip, double *w) {
|
||||||
{
|
|
||||||
int nw = ip[0];
|
int nw = ip[0];
|
||||||
int nc = ip[1];
|
int nc = ip[1];
|
||||||
|
|
||||||
if (isgn >= 0)
|
if (isgn >= 0) {
|
||||||
{
|
if (n > 4) {
|
||||||
if (n > 4)
|
|
||||||
{
|
|
||||||
bitrv2(n, ip + 2, a);
|
bitrv2(n, ip + 2, a);
|
||||||
cftfsub(n, a, w);
|
cftfsub(n, a, w);
|
||||||
rftfsub(n, a, nc, w + nw);
|
rftfsub(n, a, nc, w + nw);
|
||||||
}
|
} else if (n == 4) {
|
||||||
else if (n == 4)
|
|
||||||
{
|
|
||||||
cftfsub(n, a, w);
|
cftfsub(n, a, w);
|
||||||
}
|
}
|
||||||
double xi = a[0] - a[1];
|
double xi = a[0] - a[1];
|
||||||
a[0] += a[1];
|
a[0] += a[1];
|
||||||
a[1] = xi;
|
a[1] = xi;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
a[1] = 0.5 * (a[0] - a[1]);
|
a[1] = 0.5 * (a[0] - a[1]);
|
||||||
a[0] -= a[1];
|
a[0] -= a[1];
|
||||||
if (n > 4)
|
if (n > 4) {
|
||||||
{
|
|
||||||
rftbsub(n, a, nc, w + nw);
|
rftbsub(n, a, nc, w + nw);
|
||||||
bitrv2(n, ip + 2, a);
|
bitrv2(n, ip + 2, a);
|
||||||
cftbsub(n, a, w);
|
cftbsub(n, a, w);
|
||||||
}
|
} else if (n == 4) {
|
||||||
else if (n == 4)
|
|
||||||
{
|
|
||||||
cftfsub(n, a, w);
|
cftfsub(n, a, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------- initializing routines -------- */
|
/* -------- initializing routines -------- */
|
||||||
|
|
||||||
void makewt(int nw, int *ip, double *w)
|
void makewt(int nw, int *ip, double *w) {
|
||||||
{
|
|
||||||
int j, nwh;
|
int j, nwh;
|
||||||
double delta, x, y;
|
double delta, x, y;
|
||||||
|
|
||||||
@@ -251,9 +208,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void makect(int nc, int *ip, double *c) {
|
||||||
void makect(int nc, int *ip, double *c)
|
|
||||||
{
|
|
||||||
int j, nch;
|
int j, nch;
|
||||||
double delta;
|
double delta;
|
||||||
|
|
||||||
@@ -270,12 +225,9 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------- child routines -------- */
|
/* -------- child routines -------- */
|
||||||
|
|
||||||
|
void bitrv2(int n, int *ip, double *a) {
|
||||||
void bitrv2(int n, int *ip, double *a)
|
|
||||||
{
|
|
||||||
int j, j1, k, k1, l, m, m2;
|
int j, j1, k, k1, l, m, m2;
|
||||||
double xr, xi, yr, yi;
|
double xr, xi, yr, yi;
|
||||||
|
|
||||||
@@ -373,9 +325,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cftfsub(int n, double *a, double *w) {
|
||||||
void cftfsub(int n, double *a, double *w)
|
|
||||||
{
|
|
||||||
int j, j1, j2, j3, l;
|
int j, j1, j2, j3, l;
|
||||||
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||||
|
|
||||||
@@ -423,9 +373,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cftbsub(int n, double *a, double *w) {
|
||||||
void cftbsub(int n, double *a, double *w)
|
|
||||||
{
|
|
||||||
int j, j1, j2, j3, l;
|
int j, j1, j2, j3, l;
|
||||||
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||||
|
|
||||||
@@ -473,9 +421,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cft1st(int n, double *a, double *w) {
|
||||||
void cft1st(int n, double *a, double *w)
|
|
||||||
{
|
|
||||||
int j, k1, k2;
|
int j, k1, k2;
|
||||||
double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
|
double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
|
||||||
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||||
@@ -578,9 +524,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cftmdl(int n, int l, double *a, double *w) {
|
||||||
void cftmdl(int n, int l, double *a, double *w)
|
|
||||||
{
|
|
||||||
int j, j1, j2, j3, k, k1, k2, m, m2;
|
int j, j1, j2, j3, k, k1, k2, m, m2;
|
||||||
double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
|
double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
|
||||||
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||||
@@ -705,9 +649,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rftfsub(int n, double *a, int nc, double *c) {
|
||||||
void rftfsub(int n, double *a, int nc, double *c)
|
|
||||||
{
|
|
||||||
int j, k, kk, ks, m;
|
int j, k, kk, ks, m;
|
||||||
double wkr, wki, xr, xi, yr, yi;
|
double wkr, wki, xr, xi, yr, yi;
|
||||||
|
|
||||||
@@ -730,9 +672,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rftbsub(int n, double *a, int nc, double *c) {
|
||||||
void rftbsub(int n, double *a, int nc, double *c)
|
|
||||||
{
|
|
||||||
int j, k, kk, ks, m;
|
int j, k, kk, ks, m;
|
||||||
double wkr, wki, xr, xi, yr, yi;
|
double wkr, wki, xr, xi, yr, yi;
|
||||||
|
|
||||||
@@ -758,53 +698,35 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @brief Concrete FFT implementation
|
* @brief Concrete FFT implementation
|
||||||
*/
|
*/
|
||||||
typedef OouraFFT AudioFFTImplementation;
|
typedef OouraFFT AudioFFTImplementation;
|
||||||
|
|
||||||
|
|
||||||
#endif // AUDIOFFT_OOURA_USED
|
#endif // AUDIOFFT_OOURA_USED
|
||||||
|
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
||||||
|
|
||||||
#ifdef AUDIOFFT_APPLE_ACCELERATE_USED
|
#ifdef AUDIOFFT_APPLE_ACCELERATE_USED
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @class AppleAccelerateFFT
|
* @class AppleAccelerateFFT
|
||||||
* @brief FFT implementation using the Apple Accelerate framework internally
|
* @brief FFT implementation using the Apple Accelerate framework internally
|
||||||
*/
|
*/
|
||||||
class AppleAccelerateFFT : public detail::AudioFFTImpl
|
class AppleAccelerateFFT : public detail::AudioFFTImpl {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
AppleAccelerateFFT() :
|
AppleAccelerateFFT()
|
||||||
detail::AudioFFTImpl(),
|
: detail::AudioFFTImpl(), _size(0), _powerOf2(0), _fftSetup(0), _re(), _im() {}
|
||||||
_size(0),
|
|
||||||
_powerOf2(0),
|
|
||||||
_fftSetup(0),
|
|
||||||
_re(),
|
|
||||||
_im()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AppleAccelerateFFT(const AppleAccelerateFFT &) = delete;
|
AppleAccelerateFFT(const AppleAccelerateFFT &) = delete;
|
||||||
AppleAccelerateFFT &operator=(const AppleAccelerateFFT &) = delete;
|
AppleAccelerateFFT &operator=(const AppleAccelerateFFT &) = delete;
|
||||||
|
|
||||||
virtual ~AppleAccelerateFFT()
|
virtual ~AppleAccelerateFFT() { init(0); }
|
||||||
{
|
|
||||||
init(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void init(size_t size) override
|
virtual void init(size_t size) override {
|
||||||
{
|
if (_fftSetup) {
|
||||||
if (_fftSetup)
|
|
||||||
{
|
|
||||||
vDSP_destroy_fftsetup(_fftSetup);
|
vDSP_destroy_fftsetup(_fftSetup);
|
||||||
_size = 0;
|
_size = 0;
|
||||||
_powerOf2 = 0;
|
_powerOf2 = 0;
|
||||||
@@ -813,12 +735,10 @@ namespace audiofft
|
|||||||
_im.clear();
|
_im.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > 0)
|
if (size > 0) {
|
||||||
{
|
|
||||||
_size = size;
|
_size = size;
|
||||||
_powerOf2 = 0;
|
_powerOf2 = 0;
|
||||||
while ((1 << _powerOf2) < _size)
|
while ((1 << _powerOf2) < _size) {
|
||||||
{
|
|
||||||
++_powerOf2;
|
++_powerOf2;
|
||||||
}
|
}
|
||||||
_fftSetup = vDSP_create_fftsetup(_powerOf2, FFT_RADIX2);
|
_fftSetup = vDSP_create_fftsetup(_powerOf2, FFT_RADIX2);
|
||||||
@@ -827,8 +747,7 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void fft(const float* data, float* re, float* im) override
|
virtual void fft(const float *data, float *re, float *im) override {
|
||||||
{
|
|
||||||
const size_t size2 = _size / 2;
|
const size_t size2 = _size / 2;
|
||||||
DSPSplitComplex splitComplex;
|
DSPSplitComplex splitComplex;
|
||||||
splitComplex.realp = re;
|
splitComplex.realp = re;
|
||||||
@@ -843,8 +762,7 @@ namespace audiofft
|
|||||||
im[size2] = 0.0f;
|
im[size2] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ifft(float* data, const float* re, const float* im) override
|
virtual void ifft(float *data, const float *re, const float *im) override {
|
||||||
{
|
|
||||||
const size_t size2 = _size / 2;
|
const size_t size2 = _size / 2;
|
||||||
::memcpy(_re.data(), re, size2 * sizeof(float));
|
::memcpy(_re.data(), re, size2 * sizeof(float));
|
||||||
::memcpy(_im.data(), im, size2 * sizeof(float));
|
::memcpy(_im.data(), im, size2 * sizeof(float));
|
||||||
@@ -866,57 +784,37 @@ namespace audiofft
|
|||||||
std::vector<float> _im;
|
std::vector<float> _im;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @brief Concrete FFT implementation
|
* @brief Concrete FFT implementation
|
||||||
*/
|
*/
|
||||||
typedef AppleAccelerateFFT AudioFFTImplementation;
|
typedef AppleAccelerateFFT AudioFFTImplementation;
|
||||||
|
|
||||||
|
|
||||||
#endif // AUDIOFFT_APPLE_ACCELERATE_USED
|
#endif // AUDIOFFT_APPLE_ACCELERATE_USED
|
||||||
|
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
||||||
|
|
||||||
#ifdef AUDIOFFT_FFTW3_USED
|
#ifdef AUDIOFFT_FFTW3_USED
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @class FFTW3FFT
|
* @class FFTW3FFT
|
||||||
* @brief FFT implementation using FFTW3 internally (see fftw.org)
|
* @brief FFT implementation using FFTW3 internally (see fftw.org)
|
||||||
*/
|
*/
|
||||||
class FFTW3FFT : public detail::AudioFFTImpl
|
class FFTW3FFT : public detail::AudioFFTImpl {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
FFTW3FFT() :
|
FFTW3FFT()
|
||||||
detail::AudioFFTImpl(),
|
: detail::AudioFFTImpl(), _size(0), _complexSize(0), _planForward(0), _planBackward(0),
|
||||||
_size(0),
|
_data(0), _re(0), _im(0) {}
|
||||||
_complexSize(0),
|
|
||||||
_planForward(0),
|
|
||||||
_planBackward(0),
|
|
||||||
_data(0),
|
|
||||||
_re(0),
|
|
||||||
_im(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FFTW3FFT(const FFTW3FFT &) = delete;
|
FFTW3FFT(const FFTW3FFT &) = delete;
|
||||||
FFTW3FFT &operator=(const FFTW3FFT &) = delete;
|
FFTW3FFT &operator=(const FFTW3FFT &) = delete;
|
||||||
|
|
||||||
virtual ~FFTW3FFT()
|
virtual ~FFTW3FFT() { init(0); }
|
||||||
{
|
|
||||||
init(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void init(size_t size) override
|
virtual void init(size_t size) override {
|
||||||
{
|
if (_size != size) {
|
||||||
if (_size != size)
|
if (_size > 0) {
|
||||||
{
|
|
||||||
if (_size > 0)
|
|
||||||
{
|
|
||||||
fftwf_destroy_plan(_planForward);
|
fftwf_destroy_plan(_planForward);
|
||||||
fftwf_destroy_plan(_planBackward);
|
fftwf_destroy_plan(_planBackward);
|
||||||
_planForward = 0;
|
_planForward = 0;
|
||||||
@@ -924,27 +822,23 @@ namespace audiofft
|
|||||||
_size = 0;
|
_size = 0;
|
||||||
_complexSize = 0;
|
_complexSize = 0;
|
||||||
|
|
||||||
if (_data)
|
if (_data) {
|
||||||
{
|
|
||||||
fftwf_free(_data);
|
fftwf_free(_data);
|
||||||
_data = 0;
|
_data = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_re)
|
if (_re) {
|
||||||
{
|
|
||||||
fftwf_free(_re);
|
fftwf_free(_re);
|
||||||
_re = 0;
|
_re = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_im)
|
if (_im) {
|
||||||
{
|
|
||||||
fftwf_free(_im);
|
fftwf_free(_im);
|
||||||
_im = 0;
|
_im = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > 0)
|
if (size > 0) {
|
||||||
{
|
|
||||||
|
|
||||||
_size = size;
|
_size = size;
|
||||||
_complexSize = AudioFFT::ComplexSize(_size);
|
_complexSize = AudioFFT::ComplexSize(_size);
|
||||||
@@ -963,16 +857,14 @@ namespace audiofft
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void fft(const float* data, float* re, float* im) override
|
virtual void fft(const float *data, float *re, float *im) override {
|
||||||
{
|
|
||||||
::memcpy(_data, data, _size * sizeof(float));
|
::memcpy(_data, data, _size * sizeof(float));
|
||||||
fftwf_execute_split_dft_r2c(_planForward, _data, _re, _im);
|
fftwf_execute_split_dft_r2c(_planForward, _data, _re, _im);
|
||||||
::memcpy(re, _re, _complexSize * sizeof(float));
|
::memcpy(re, _re, _complexSize * sizeof(float));
|
||||||
::memcpy(im, _im, _complexSize * sizeof(float));
|
::memcpy(im, _im, _complexSize * sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ifft(float* data, const float* re, const float* im) override
|
virtual void ifft(float *data, const float *re, const float *im) override {
|
||||||
{
|
|
||||||
::memcpy(_re, re, _complexSize * sizeof(float));
|
::memcpy(_re, re, _complexSize * sizeof(float));
|
||||||
::memcpy(_im, im, _complexSize * sizeof(float));
|
::memcpy(_im, im, _complexSize * sizeof(float));
|
||||||
fftwf_execute_split_dft_c2r(_planBackward, _re, _im, _data);
|
fftwf_execute_split_dft_c2r(_planBackward, _re, _im, _data);
|
||||||
@@ -989,53 +881,29 @@ namespace audiofft
|
|||||||
float *_im;
|
float *_im;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @brief Concrete FFT implementation
|
* @brief Concrete FFT implementation
|
||||||
*/
|
*/
|
||||||
typedef FFTW3FFT AudioFFTImplementation;
|
typedef FFTW3FFT AudioFFTImplementation;
|
||||||
|
|
||||||
|
|
||||||
#endif // AUDIOFFT_FFTW3_USED
|
#endif // AUDIOFFT_FFTW3_USED
|
||||||
|
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|
||||||
|
AudioFFT::AudioFFT() : _impl(new AudioFFTImplementation()) {}
|
||||||
|
|
||||||
AudioFFT::AudioFFT() :
|
AudioFFT::~AudioFFT() {}
|
||||||
_impl(new AudioFFTImplementation())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void AudioFFT::init(size_t size) {
|
||||||
AudioFFT::~AudioFFT()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AudioFFT::init(size_t size)
|
|
||||||
{
|
|
||||||
assert(detail::IsPowerOf2(size));
|
assert(detail::IsPowerOf2(size));
|
||||||
_impl->init(size);
|
_impl->init(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioFFT::fft(const float *data, float *re, float *im) { _impl->fft(data, re, im); }
|
||||||
|
|
||||||
void AudioFFT::fft(const float* data, float* re, float* im)
|
void AudioFFT::ifft(float *data, const float *re, const float *im) { _impl->ifft(data, re, im); }
|
||||||
{
|
|
||||||
_impl->fft(data, re, im);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
size_t AudioFFT::ComplexSize(size_t size) { return (size / 2) + 1; }
|
||||||
|
|
||||||
void AudioFFT::ifft(float* data, const float* re, const float* im)
|
} // namespace audiofft
|
||||||
{
|
|
||||||
_impl->ifft(data, re, im);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t AudioFFT::ComplexSize(size_t size)
|
|
||||||
{
|
|
||||||
return (size / 2) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of namespace
|
|
||||||
|
|||||||
Executable → Regular
+14
-18
@@ -22,7 +22,6 @@
|
|||||||
#ifndef _AUDIOFFT_H
|
#ifndef _AUDIOFFT_H
|
||||||
#define _AUDIOFFT_H
|
#define _AUDIOFFT_H
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AudioFFT provides real-to-complex/complex-to-real FFT routines.
|
* AudioFFT provides real-to-complex/complex-to-real FFT routines.
|
||||||
*
|
*
|
||||||
@@ -30,7 +29,8 @@
|
|||||||
*
|
*
|
||||||
* - Real-complex FFT and complex-real inverse FFT for power-of-2-sized real data.
|
* - Real-complex FFT and complex-real inverse FFT for power-of-2-sized real data.
|
||||||
*
|
*
|
||||||
* - Uniform interface to different FFT implementations (currently Ooura, FFTW3 and Apple Accelerate).
|
* - Uniform interface to different FFT implementations (currently Ooura, FFTW3 and Apple
|
||||||
|
* Accelerate).
|
||||||
*
|
*
|
||||||
* - Complex data is handled in "split-complex" format, i.e. there are separate
|
* - Complex data is handled in "split-complex" format, i.e. there are separate
|
||||||
* arrays for the real and imaginary parts which can be useful for SIMD optimizations
|
* arrays for the real and imaginary parts which can be useful for SIMD optimizations
|
||||||
@@ -86,29 +86,22 @@
|
|||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace audiofft {
|
||||||
|
|
||||||
namespace audiofft
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class AudioFFTImpl;
|
class AudioFFTImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class AudioFFT
|
* @class AudioFFT
|
||||||
* @brief Performs 1D FFTs
|
* @brief Performs 1D FFTs
|
||||||
*/
|
*/
|
||||||
class AudioFFT
|
class AudioFFT {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor
|
* @brief Constructor
|
||||||
@@ -132,8 +125,10 @@ namespace audiofft
|
|||||||
/**
|
/**
|
||||||
* @brief Performs the forward FFT
|
* @brief Performs the forward FFT
|
||||||
* @param data The real input data (has to be of the length as specified in init())
|
* @param data The real input data (has to be of the length as specified in init())
|
||||||
* @param re The real part of the complex output (has to be of length as returned by ComplexSize())
|
* @param re The real part of the complex output (has to be of length as returned by
|
||||||
* @param im The imaginary part of the complex output (has to be of length as returned by ComplexSize())
|
* ComplexSize())
|
||||||
|
* @param im The imaginary part of the complex output (has to be of length as returned by
|
||||||
|
* ComplexSize())
|
||||||
*/
|
*/
|
||||||
void fft(const float *data, float *re, float *im);
|
void fft(const float *data, float *re, float *im);
|
||||||
|
|
||||||
@@ -141,7 +136,8 @@ namespace audiofft
|
|||||||
* @brief Performs the inverse FFT
|
* @brief Performs the inverse FFT
|
||||||
* @param data The real output data (has to be of the length as specified in init())
|
* @param data The real output data (has to be of the length as specified in init())
|
||||||
* @param re The real part of the complex input (has to be of length as returned by ComplexSize())
|
* @param re The real part of the complex input (has to be of length as returned by ComplexSize())
|
||||||
* @param im The imaginary part of the complex input (has to be of length as returned by ComplexSize())
|
* @param im The imaginary part of the complex input (has to be of length as returned by
|
||||||
|
* ComplexSize())
|
||||||
*/
|
*/
|
||||||
void ifft(float *data, const float *re, const float *im);
|
void ifft(float *data, const float *re, const float *im);
|
||||||
|
|
||||||
@@ -156,13 +152,13 @@ namespace audiofft
|
|||||||
std::unique_ptr<detail::AudioFFTImpl> _impl;
|
std::unique_ptr<detail::AudioFFTImpl> _impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @brief Let's keep an AudioFFTBase type around for now because it has been here already in the 1st version in order to avoid breaking existing code.
|
* @brief Let's keep an AudioFFTBase type around for now because it has been here already in the 1st
|
||||||
|
* version in order to avoid breaking existing code.
|
||||||
*/
|
*/
|
||||||
typedef AudioFFT AudioFFTBase;
|
typedef AudioFFT AudioFFTBase;
|
||||||
|
|
||||||
} // End of namespace
|
} // namespace audiofft
|
||||||
|
|
||||||
#endif // Header guard
|
#endif // Header guard
|
||||||
|
|||||||
@@ -140,7 +140,10 @@ void ConvolverThreadPool::clearState(size_t convolverId) {
|
|||||||
if (convolverId < _convolvers.size()) {
|
if (convolverId < _convolvers.size()) {
|
||||||
waitForAll();
|
waitForAll();
|
||||||
} else {
|
} else {
|
||||||
debug(1, "assert(convolverId < _convolvers.size()) failed, with convolverId: %u and _convolvers.size(): %u.", convolverId, _convolvers.size());
|
debug(1,
|
||||||
|
"assert(convolverId < _convolvers.size()) failed, with convolverId: %u and "
|
||||||
|
"_convolvers.size(): %u.",
|
||||||
|
convolverId, _convolvers.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Executable → Regular
+27
-63
@@ -24,39 +24,17 @@
|
|||||||
#include <xmmintrin.h>
|
#include <xmmintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace fftconvolver {
|
||||||
|
|
||||||
namespace fftconvolver
|
FFTConvolver::FFTConvolver()
|
||||||
{
|
: _blockSize(0), _segSize(0), _segCount(0), _fftComplexSize(0), _segments(), _segmentsIR(),
|
||||||
|
_fftBuffer(), _fft(), _preMultiplied(), _conv(), _overlap(), _current(0), _inputBuffer(),
|
||||||
|
_inputBufferFill(0) {}
|
||||||
|
|
||||||
FFTConvolver::FFTConvolver() :
|
FFTConvolver::~FFTConvolver() { reset(); }
|
||||||
_blockSize(0),
|
|
||||||
_segSize(0),
|
|
||||||
_segCount(0),
|
|
||||||
_fftComplexSize(0),
|
|
||||||
_segments(),
|
|
||||||
_segmentsIR(),
|
|
||||||
_fftBuffer(),
|
|
||||||
_fft(),
|
|
||||||
_preMultiplied(),
|
|
||||||
_conv(),
|
|
||||||
_overlap(),
|
|
||||||
_current(0),
|
|
||||||
_inputBuffer(),
|
|
||||||
_inputBufferFill(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void FFTConvolver::reset() {
|
||||||
FFTConvolver::~FFTConvolver()
|
for (size_t i = 0; i < _segCount; ++i) {
|
||||||
{
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FFTConvolver::reset()
|
|
||||||
{
|
|
||||||
for (size_t i=0; i<_segCount; ++i)
|
|
||||||
{
|
|
||||||
delete _segments[i];
|
delete _segments[i];
|
||||||
delete _segmentsIR[i];
|
delete _segmentsIR[i];
|
||||||
}
|
}
|
||||||
@@ -77,10 +55,8 @@ void FFTConvolver::reset()
|
|||||||
_inputBufferFill = 0;
|
_inputBufferFill = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFTConvolver::clearState()
|
void FFTConvolver::clearState() {
|
||||||
{
|
if (_segCount == 0) {
|
||||||
if (_segCount == 0)
|
|
||||||
{
|
|
||||||
return; // Not initialized
|
return; // Not initialized
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +64,7 @@ void FFTConvolver::clearState()
|
|||||||
_inputBufferFill = 0;
|
_inputBufferFill = 0;
|
||||||
_overlap.setZero();
|
_overlap.setZero();
|
||||||
|
|
||||||
for (size_t i = 0; i < _segCount; ++i)
|
for (size_t i = 0; i < _segCount; ++i) {
|
||||||
{
|
|
||||||
_segments[i]->setZero();
|
_segments[i]->setZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,29 +73,26 @@ void FFTConvolver::clearState()
|
|||||||
_current = 0;
|
_current = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFTConvolver::init(size_t blockSize, const Sample* ir, size_t irLen)
|
bool FFTConvolver::init(size_t blockSize, const Sample *ir, size_t irLen) {
|
||||||
{
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
if (blockSize == 0)
|
if (blockSize == 0) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore zeros at the end of the impulse response because they only waste computation time
|
// Ignore zeros at the end of the impulse response because they only waste computation time
|
||||||
while (irLen > 0 && ::fabs(ir[irLen-1]) < 0.000001f)
|
while (irLen > 0 && ::fabs(ir[irLen - 1]) < 0.000001f) {
|
||||||
{
|
|
||||||
--irLen;
|
--irLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (irLen == 0)
|
if (irLen == 0) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_blockSize = NextPowerOf2(blockSize);
|
_blockSize = NextPowerOf2(blockSize);
|
||||||
_segSize = 2 * _blockSize;
|
_segSize = 2 * _blockSize;
|
||||||
_segCount = static_cast<size_t>(::ceil(static_cast<float>(irLen) / static_cast<float>(_blockSize)));
|
_segCount =
|
||||||
|
static_cast<size_t>(::ceil(static_cast<float>(irLen) / static_cast<float>(_blockSize)));
|
||||||
_fftComplexSize = audiofft::AudioFFT::ComplexSize(_segSize);
|
_fftComplexSize = audiofft::AudioFFT::ComplexSize(_segSize);
|
||||||
|
|
||||||
// FFT
|
// FFT
|
||||||
@@ -128,14 +100,12 @@ bool FFTConvolver::init(size_t blockSize, const Sample* ir, size_t irLen)
|
|||||||
_fftBuffer.resize(_segSize);
|
_fftBuffer.resize(_segSize);
|
||||||
|
|
||||||
// Prepare segments
|
// Prepare segments
|
||||||
for (size_t i=0; i<_segCount; ++i)
|
for (size_t i = 0; i < _segCount; ++i) {
|
||||||
{
|
|
||||||
_segments.push_back(new SplitComplex(_fftComplexSize));
|
_segments.push_back(new SplitComplex(_fftComplexSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare IR
|
// Prepare IR
|
||||||
for (size_t i=0; i<_segCount; ++i)
|
for (size_t i = 0; i < _segCount; ++i) {
|
||||||
{
|
|
||||||
SplitComplex *segment = new SplitComplex(_fftComplexSize);
|
SplitComplex *segment = new SplitComplex(_fftComplexSize);
|
||||||
const size_t remaining = irLen - (i * _blockSize);
|
const size_t remaining = irLen - (i * _blockSize);
|
||||||
const size_t sizeCopy = (remaining >= _blockSize) ? _blockSize : remaining;
|
const size_t sizeCopy = (remaining >= _blockSize) ? _blockSize : remaining;
|
||||||
@@ -159,18 +129,14 @@ bool FFTConvolver::init(size_t blockSize, const Sample* ir, size_t irLen)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FFTConvolver::process(const Sample *input, Sample *output, size_t len) {
|
||||||
void FFTConvolver::process(const Sample* input, Sample* output, size_t len)
|
if (_segCount == 0) {
|
||||||
{
|
|
||||||
if (_segCount == 0)
|
|
||||||
{
|
|
||||||
::memset(output, 0, len * sizeof(Sample));
|
::memset(output, 0, len * sizeof(Sample));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t processed = 0;
|
size_t processed = 0;
|
||||||
while (processed < len)
|
while (processed < len) {
|
||||||
{
|
|
||||||
const bool inputBufferWasEmpty = (_inputBufferFill == 0);
|
const bool inputBufferWasEmpty = (_inputBufferFill == 0);
|
||||||
const size_t processing = std::min(len - processed, _blockSize - _inputBufferFill);
|
const size_t processing = std::min(len - processed, _blockSize - _inputBufferFill);
|
||||||
const size_t inputBufferPos = _inputBufferFill;
|
const size_t inputBufferPos = _inputBufferFill;
|
||||||
@@ -181,11 +147,9 @@ void FFTConvolver::process(const Sample* input, Sample* output, size_t len)
|
|||||||
_fft.fft(_fftBuffer.data(), _segments[_current]->re(), _segments[_current]->im());
|
_fft.fft(_fftBuffer.data(), _segments[_current]->re(), _segments[_current]->im());
|
||||||
|
|
||||||
// Complex multiplication
|
// Complex multiplication
|
||||||
if (inputBufferWasEmpty)
|
if (inputBufferWasEmpty) {
|
||||||
{
|
|
||||||
_preMultiplied.setZero();
|
_preMultiplied.setZero();
|
||||||
for (size_t i=1; i<_segCount; ++i)
|
for (size_t i = 1; i < _segCount; ++i) {
|
||||||
{
|
|
||||||
const size_t indexIr = i;
|
const size_t indexIr = i;
|
||||||
const size_t indexAudio = (_current + i) % _segCount;
|
const size_t indexAudio = (_current + i) % _segCount;
|
||||||
ComplexMultiplyAccumulate(_preMultiplied, *_segmentsIR[indexIr], *_segments[indexAudio]);
|
ComplexMultiplyAccumulate(_preMultiplied, *_segmentsIR[indexIr], *_segments[indexAudio]);
|
||||||
@@ -198,12 +162,12 @@ void FFTConvolver::process(const Sample* input, Sample* output, size_t len)
|
|||||||
_fft.ifft(_fftBuffer.data(), _conv.re(), _conv.im());
|
_fft.ifft(_fftBuffer.data(), _conv.re(), _conv.im());
|
||||||
|
|
||||||
// Add overlap
|
// Add overlap
|
||||||
Sum(output+processed, _fftBuffer.data()+inputBufferPos, _overlap.data()+inputBufferPos, processing);
|
Sum(output + processed, _fftBuffer.data() + inputBufferPos, _overlap.data() + inputBufferPos,
|
||||||
|
processing);
|
||||||
|
|
||||||
// Input buffer full => Next block
|
// Input buffer full => Next block
|
||||||
_inputBufferFill += processing;
|
_inputBufferFill += processing;
|
||||||
if (_inputBufferFill == _blockSize)
|
if (_inputBufferFill == _blockSize) {
|
||||||
{
|
|
||||||
// Input buffer is empty again now
|
// Input buffer is empty again now
|
||||||
_inputBuffer.setZero();
|
_inputBuffer.setZero();
|
||||||
_inputBufferFill = 0;
|
_inputBufferFill = 0;
|
||||||
|
|||||||
Executable → Regular
+2
-5
@@ -27,9 +27,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace fftconvolver {
|
||||||
namespace fftconvolver
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class FFTConvolver
|
* @class FFTConvolver
|
||||||
@@ -50,8 +48,7 @@ namespace fftconvolver
|
|||||||
* performed during processing (all necessary allocations and preparations take
|
* performed during processing (all necessary allocations and preparations take
|
||||||
* place during initialization).
|
* place during initialization).
|
||||||
*/
|
*/
|
||||||
class FFTConvolver
|
class FFTConvolver {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
FFTConvolver();
|
FFTConvolver();
|
||||||
virtual ~FFTConvolver();
|
virtual ~FFTConvolver();
|
||||||
|
|||||||
+15
-33
@@ -21,12 +21,9 @@
|
|||||||
|
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
|
|
||||||
|
namespace fftconvolver {
|
||||||
|
|
||||||
namespace fftconvolver
|
bool SSEEnabled() {
|
||||||
{
|
|
||||||
|
|
||||||
bool SSEEnabled()
|
|
||||||
{
|
|
||||||
#if defined(FFTCONVOLVER_USE_SSE)
|
#if defined(FFTCONVOLVER_USE_SSE)
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
@@ -34,47 +31,35 @@ bool SSEEnabled()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sum(Sample *FFTCONVOLVER_RESTRICT result, const Sample *FFTCONVOLVER_RESTRICT a,
|
||||||
void Sum(Sample* FFTCONVOLVER_RESTRICT result,
|
const Sample *FFTCONVOLVER_RESTRICT b, size_t len) {
|
||||||
const Sample* FFTCONVOLVER_RESTRICT a,
|
|
||||||
const Sample* FFTCONVOLVER_RESTRICT b,
|
|
||||||
size_t len)
|
|
||||||
{
|
|
||||||
const size_t end4 = 4 * (len / 4);
|
const size_t end4 = 4 * (len / 4);
|
||||||
for (size_t i=0; i<end4; i+=4)
|
for (size_t i = 0; i < end4; i += 4) {
|
||||||
{
|
|
||||||
result[i + 0] = a[i + 0] + b[i + 0];
|
result[i + 0] = a[i + 0] + b[i + 0];
|
||||||
result[i + 1] = a[i + 1] + b[i + 1];
|
result[i + 1] = a[i + 1] + b[i + 1];
|
||||||
result[i + 2] = a[i + 2] + b[i + 2];
|
result[i + 2] = a[i + 2] + b[i + 2];
|
||||||
result[i + 3] = a[i + 3] + b[i + 3];
|
result[i + 3] = a[i + 3] + b[i + 3];
|
||||||
}
|
}
|
||||||
for (size_t i=end4; i<len; ++i)
|
for (size_t i = end4; i < len; ++i) {
|
||||||
{
|
|
||||||
result[i] = a[i] + b[i];
|
result[i] = a[i] + b[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComplexMultiplyAccumulate(SplitComplex &result, const SplitComplex &a, const SplitComplex &b) {
|
||||||
void ComplexMultiplyAccumulate(SplitComplex& result, const SplitComplex& a, const SplitComplex& b)
|
|
||||||
{
|
|
||||||
assert(result.size() == a.size());
|
assert(result.size() == a.size());
|
||||||
assert(result.size() == b.size());
|
assert(result.size() == b.size());
|
||||||
ComplexMultiplyAccumulate(result.re(), result.im(), a.re(), a.im(), b.re(), b.im(), result.size());
|
ComplexMultiplyAccumulate(result.re(), result.im(), a.re(), a.im(), b.re(), b.im(),
|
||||||
|
result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComplexMultiplyAccumulate(Sample *FFTCONVOLVER_RESTRICT re, Sample *FFTCONVOLVER_RESTRICT im,
|
||||||
void ComplexMultiplyAccumulate(Sample* FFTCONVOLVER_RESTRICT re,
|
|
||||||
Sample* FFTCONVOLVER_RESTRICT im,
|
|
||||||
const Sample *FFTCONVOLVER_RESTRICT reA,
|
const Sample *FFTCONVOLVER_RESTRICT reA,
|
||||||
const Sample *FFTCONVOLVER_RESTRICT imA,
|
const Sample *FFTCONVOLVER_RESTRICT imA,
|
||||||
const Sample *FFTCONVOLVER_RESTRICT reB,
|
const Sample *FFTCONVOLVER_RESTRICT reB,
|
||||||
const Sample* FFTCONVOLVER_RESTRICT imB,
|
const Sample *FFTCONVOLVER_RESTRICT imB, const size_t len) {
|
||||||
const size_t len)
|
|
||||||
{
|
|
||||||
#if defined(FFTCONVOLVER_USE_SSE)
|
#if defined(FFTCONVOLVER_USE_SSE)
|
||||||
const size_t end4 = 4 * (len / 4);
|
const size_t end4 = 4 * (len / 4);
|
||||||
for (size_t i=0; i<end4; i+=4)
|
for (size_t i = 0; i < end4; i += 4) {
|
||||||
{
|
|
||||||
const __m128 ra = _mm_load_ps(&reA[i]);
|
const __m128 ra = _mm_load_ps(&reA[i]);
|
||||||
const __m128 rb = _mm_load_ps(&reB[i]);
|
const __m128 rb = _mm_load_ps(&reB[i]);
|
||||||
const __m128 ia = _mm_load_ps(&imA[i]);
|
const __m128 ia = _mm_load_ps(&imA[i]);
|
||||||
@@ -88,15 +73,13 @@ void ComplexMultiplyAccumulate(Sample* FFTCONVOLVER_RESTRICT re,
|
|||||||
imag = _mm_add_ps(imag, _mm_mul_ps(ia, rb));
|
imag = _mm_add_ps(imag, _mm_mul_ps(ia, rb));
|
||||||
_mm_store_ps(&im[i], imag);
|
_mm_store_ps(&im[i], imag);
|
||||||
}
|
}
|
||||||
for (size_t i=end4; i<len; ++i)
|
for (size_t i = end4; i < len; ++i) {
|
||||||
{
|
|
||||||
re[i] += reA[i] * reB[i] - imA[i] * imB[i];
|
re[i] += reA[i] * reB[i] - imA[i] * imB[i];
|
||||||
im[i] += reA[i] * imB[i] + imA[i] * reB[i];
|
im[i] += reA[i] * imB[i] + imA[i] * reB[i];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const size_t end4 = 4 * (len / 4);
|
const size_t end4 = 4 * (len / 4);
|
||||||
for (size_t i=0; i<end4; i+=4)
|
for (size_t i = 0; i < end4; i += 4) {
|
||||||
{
|
|
||||||
re[i + 0] += reA[i + 0] * reB[i + 0] - imA[i + 0] * imB[i + 0];
|
re[i + 0] += reA[i + 0] * reB[i + 0] - imA[i + 0] * imB[i + 0];
|
||||||
re[i + 1] += reA[i + 1] * reB[i + 1] - imA[i + 1] * imB[i + 1];
|
re[i + 1] += reA[i + 1] * reB[i + 1] - imA[i + 1] * imB[i + 1];
|
||||||
re[i + 2] += reA[i + 2] * reB[i + 2] - imA[i + 2] * imB[i + 2];
|
re[i + 2] += reA[i + 2] * reB[i + 2] - imA[i + 2] * imB[i + 2];
|
||||||
@@ -106,8 +89,7 @@ void ComplexMultiplyAccumulate(Sample* FFTCONVOLVER_RESTRICT re,
|
|||||||
im[i + 2] += reA[i + 2] * imB[i + 2] + imA[i + 2] * reB[i + 2];
|
im[i + 2] += reA[i + 2] * imB[i + 2] + imA[i + 2] * reB[i + 2];
|
||||||
im[i + 3] += reA[i + 3] * imB[i + 3] + imA[i + 3] * reB[i + 3];
|
im[i + 3] += reA[i + 3] * imB[i + 3] + imA[i + 3] * reB[i + 3];
|
||||||
}
|
}
|
||||||
for (size_t i=end4; i<len; ++i)
|
for (size_t i = end4; i < len; ++i) {
|
||||||
{
|
|
||||||
re[i] += reA[i] * reB[i] - imA[i] * imB[i];
|
re[i] += reA[i] * reB[i] - imA[i] * imB[i];
|
||||||
im[i] += reA[i] * imB[i] + imA[i] * reB[i];
|
im[i] += reA[i] * imB[i] + imA[i] * reB[i];
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-127
@@ -28,9 +28,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
namespace fftconvolver {
|
||||||
namespace fftconvolver
|
|
||||||
{
|
|
||||||
|
|
||||||
#if defined(__SSE__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
|
#if defined(__SSE__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
|
||||||
#if !defined(FFTCONVOLVER_USE_SSE) && !defined(FFTCONVOLVER_DONT_USE_SSE)
|
#if !defined(FFTCONVOLVER_USE_SSE) && !defined(FFTCONVOLVER_DONT_USE_SSE)
|
||||||
@@ -38,61 +36,43 @@ namespace fftconvolver
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(FFTCONVOLVER_USE_SSE)
|
#if defined(FFTCONVOLVER_USE_SSE)
|
||||||
#include <xmmintrin.h>
|
#include <xmmintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#define FFTCONVOLVER_RESTRICT __restrict__
|
#define FFTCONVOLVER_RESTRICT __restrict__
|
||||||
#else
|
#else
|
||||||
#define FFTCONVOLVER_RESTRICT
|
#define FFTCONVOLVER_RESTRICT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns whether SSE optimization for the convolver is enabled
|
* @brief Returns whether SSE optimization for the convolver is enabled
|
||||||
* @return true: Enabled - false: Disabled
|
* @return true: Enabled - false: Disabled
|
||||||
*/
|
*/
|
||||||
bool SSEEnabled();
|
bool SSEEnabled();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Buffer
|
* @class Buffer
|
||||||
* @brief Simple buffer implementation (uses 16-byte alignment if SSE optimization is enabled)
|
* @brief Simple buffer implementation (uses 16-byte alignment if SSE optimization is enabled)
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template <typename T> class Buffer {
|
||||||
class Buffer
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit Buffer(size_t initialSize = 0) :
|
explicit Buffer(size_t initialSize = 0) : _data(0), _size(0) { resize(initialSize); }
|
||||||
_data(0),
|
|
||||||
_size(0)
|
|
||||||
{
|
|
||||||
resize(initialSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~Buffer()
|
virtual ~Buffer() { clear(); }
|
||||||
{
|
|
||||||
clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear()
|
void clear() {
|
||||||
{
|
|
||||||
deallocate(_data);
|
deallocate(_data);
|
||||||
_data = 0;
|
_data = 0;
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(size_t size)
|
void resize(size_t size) {
|
||||||
{
|
if (_size != size) {
|
||||||
if (_size != size)
|
|
||||||
{
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
if (size > 0)
|
if (size > 0) {
|
||||||
{
|
|
||||||
assert(!_data && _size == 0);
|
assert(!_data && _size == 0);
|
||||||
_data = allocate(size);
|
_data = allocate(size);
|
||||||
_size = size;
|
_size = size;
|
||||||
@@ -101,61 +81,40 @@ public:
|
|||||||
setZero();
|
setZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size() const
|
size_t size() const { return _size; }
|
||||||
{
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setZero()
|
void setZero() { ::memset(_data, 0, _size * sizeof(T)); }
|
||||||
{
|
|
||||||
::memset(_data, 0, _size * sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
void copyFrom(const Buffer<T>& other)
|
void copyFrom(const Buffer<T> &other) {
|
||||||
{
|
|
||||||
assert(_size == other._size);
|
assert(_size == other._size);
|
||||||
if (this != &other)
|
if (this != &other) {
|
||||||
{
|
|
||||||
::memcpy(_data, other._data, _size * sizeof(T));
|
::memcpy(_data, other._data, _size * sizeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator[](size_t index)
|
T &operator[](size_t index) {
|
||||||
{
|
|
||||||
assert(_data && index < _size);
|
assert(_data && index < _size);
|
||||||
return _data[index];
|
return _data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator[](size_t index) const
|
const T &operator[](size_t index) const {
|
||||||
{
|
|
||||||
assert(_data && index < _size);
|
assert(_data && index < _size);
|
||||||
return _data[index];
|
return _data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool() const
|
operator bool() const { return (_data != 0 && _size > 0); }
|
||||||
{
|
|
||||||
return (_data != 0 && _size > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
T* data()
|
T *data() { return _data; }
|
||||||
{
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
const T* data() const
|
const T *data() const { return _data; }
|
||||||
{
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Swap(Buffer<T>& a, Buffer<T>& b)
|
static void Swap(Buffer<T> &a, Buffer<T> &b) {
|
||||||
{
|
|
||||||
std::swap(a._data, b._data);
|
std::swap(a._data, b._data);
|
||||||
std::swap(a._size, b._size);
|
std::swap(a._size, b._size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T* allocate(size_t size)
|
T *allocate(size_t size) {
|
||||||
{
|
|
||||||
#if defined(FFTCONVOLVER_USE_SSE)
|
#if defined(FFTCONVOLVER_USE_SSE)
|
||||||
return static_cast<T *>(_mm_malloc(size * sizeof(T), 16));
|
return static_cast<T *>(_mm_malloc(size * sizeof(T), 16));
|
||||||
#else
|
#else
|
||||||
@@ -163,8 +122,7 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate(T* ptr)
|
void deallocate(T *ptr) {
|
||||||
{
|
|
||||||
#if defined(FFTCONVOLVER_USE_SSE)
|
#if defined(FFTCONVOLVER_USE_SSE)
|
||||||
_mm_free(ptr);
|
_mm_free(ptr);
|
||||||
#else
|
#else
|
||||||
@@ -180,19 +138,16 @@ private:
|
|||||||
Buffer &operator=(const Buffer &);
|
Buffer &operator=(const Buffer &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of one sample
|
* @brief Type of one sample
|
||||||
*/
|
*/
|
||||||
typedef float Sample;
|
typedef float Sample;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Buffer for samples
|
* @brief Buffer for samples
|
||||||
*/
|
*/
|
||||||
typedef Buffer<Sample> SampleBuffer;
|
typedef Buffer<Sample> SampleBuffer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class SplitComplex
|
* @class SplitComplex
|
||||||
* @brief Buffer for split-complex representation of FFT results
|
* @brief Buffer for split-complex representation of FFT results
|
||||||
@@ -201,72 +156,43 @@ typedef Buffer<Sample> SampleBuffer;
|
|||||||
* of FFT results in two different memory buffers which is useful e.g. for
|
* of FFT results in two different memory buffers which is useful e.g. for
|
||||||
* SIMD optimizations.
|
* SIMD optimizations.
|
||||||
*/
|
*/
|
||||||
class SplitComplex
|
class SplitComplex {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit SplitComplex(size_t initialSize = 0) :
|
explicit SplitComplex(size_t initialSize = 0) : _size(0), _re(), _im() { resize(initialSize); }
|
||||||
_size(0),
|
|
||||||
_re(),
|
|
||||||
_im()
|
|
||||||
{
|
|
||||||
resize(initialSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
~SplitComplex()
|
~SplitComplex() { clear(); }
|
||||||
{
|
|
||||||
clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear()
|
void clear() {
|
||||||
{
|
|
||||||
_re.clear();
|
_re.clear();
|
||||||
_im.clear();
|
_im.clear();
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(size_t newSize)
|
void resize(size_t newSize) {
|
||||||
{
|
|
||||||
_re.resize(newSize);
|
_re.resize(newSize);
|
||||||
_im.resize(newSize);
|
_im.resize(newSize);
|
||||||
_size = newSize;
|
_size = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setZero()
|
void setZero() {
|
||||||
{
|
|
||||||
_re.setZero();
|
_re.setZero();
|
||||||
_im.setZero();
|
_im.setZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyFrom(const SplitComplex& other)
|
void copyFrom(const SplitComplex &other) {
|
||||||
{
|
|
||||||
_re.copyFrom(other._re);
|
_re.copyFrom(other._re);
|
||||||
_im.copyFrom(other._im);
|
_im.copyFrom(other._im);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sample* re()
|
Sample *re() { return _re.data(); }
|
||||||
{
|
|
||||||
return _re.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
const Sample* re() const
|
const Sample *re() const { return _re.data(); }
|
||||||
{
|
|
||||||
return _re.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sample* im()
|
Sample *im() { return _im.data(); }
|
||||||
{
|
|
||||||
return _im.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
const Sample* im() const
|
const Sample *im() const { return _im.data(); }
|
||||||
{
|
|
||||||
return _im.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size() const
|
size_t size() const { return _size; }
|
||||||
{
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t _size;
|
size_t _size;
|
||||||
@@ -278,24 +204,19 @@ private:
|
|||||||
SplitComplex &operator=(const SplitComplex &);
|
SplitComplex &operator=(const SplitComplex &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the next power of 2 of a given number
|
* @brief Returns the next power of 2 of a given number
|
||||||
* @param val The number
|
* @param val The number
|
||||||
* @return The next power of 2
|
* @return The next power of 2
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template <typename T> T NextPowerOf2(const T &val) {
|
||||||
T NextPowerOf2(const T& val)
|
|
||||||
{
|
|
||||||
T nextPowerOf2 = 1;
|
T nextPowerOf2 = 1;
|
||||||
while (nextPowerOf2 < val)
|
while (nextPowerOf2 < val) {
|
||||||
{
|
|
||||||
nextPowerOf2 *= 2;
|
nextPowerOf2 *= 2;
|
||||||
}
|
}
|
||||||
return nextPowerOf2;
|
return nextPowerOf2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sums two given sample arrays
|
* @brief Sums two given sample arrays
|
||||||
* @param result The result array
|
* @param result The result array
|
||||||
@@ -303,11 +224,8 @@ T NextPowerOf2(const T& val)
|
|||||||
* @param b The 2nd array
|
* @param b The 2nd array
|
||||||
* @param len The length of the arrays
|
* @param len The length of the arrays
|
||||||
*/
|
*/
|
||||||
void Sum(Sample* FFTCONVOLVER_RESTRICT result,
|
void Sum(Sample *FFTCONVOLVER_RESTRICT result, const Sample *FFTCONVOLVER_RESTRICT a,
|
||||||
const Sample* FFTCONVOLVER_RESTRICT a,
|
const Sample *FFTCONVOLVER_RESTRICT b, size_t len);
|
||||||
const Sample* FFTCONVOLVER_RESTRICT b,
|
|
||||||
size_t len);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copies a source array into a destination buffer and pads the destination buffer with zeros
|
* @brief Copies a source array into a destination buffer and pads the destination buffer with zeros
|
||||||
@@ -315,15 +233,12 @@ void Sum(Sample* FFTCONVOLVER_RESTRICT result,
|
|||||||
* @param src The source array
|
* @param src The source array
|
||||||
* @param srcSize The size of the source array
|
* @param srcSize The size of the source array
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template <typename T> void CopyAndPad(Buffer<T> &dest, const T *src, size_t srcSize) {
|
||||||
void CopyAndPad(Buffer<T>& dest, const T* src, size_t srcSize)
|
|
||||||
{
|
|
||||||
assert(dest.size() >= srcSize);
|
assert(dest.size() >= srcSize);
|
||||||
::memcpy(dest.data(), src, srcSize * sizeof(T));
|
::memcpy(dest.data(), src, srcSize * sizeof(T));
|
||||||
::memset(dest.data() + srcSize, 0, (dest.size() - srcSize) * sizeof(T));
|
::memset(dest.data() + srcSize, 0, (dest.size() - srcSize) * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds the complex product of two split-complex buffers to a result buffer
|
* @brief Adds the complex product of two split-complex buffers to a result buffer
|
||||||
* @param result The result buffer
|
* @param result The result buffer
|
||||||
@@ -332,7 +247,6 @@ void CopyAndPad(Buffer<T>& dest, const T* src, size_t srcSize)
|
|||||||
*/
|
*/
|
||||||
void ComplexMultiplyAccumulate(SplitComplex &result, const SplitComplex &a, const SplitComplex &b);
|
void ComplexMultiplyAccumulate(SplitComplex &result, const SplitComplex &a, const SplitComplex &b);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds the complex product of two split-complex arrays to a result array
|
* @brief Adds the complex product of two split-complex arrays to a result array
|
||||||
* @param re The real part of the result buffer
|
* @param re The real part of the result buffer
|
||||||
@@ -342,13 +256,11 @@ void ComplexMultiplyAccumulate(SplitComplex& result, const SplitComplex& a, cons
|
|||||||
* @param reB The real part of the 2nd factor of the complex product
|
* @param reB The real part of the 2nd factor of the complex product
|
||||||
* @param imB The imaginary part of the 2nd factor of the complex product
|
* @param imB The imaginary part of the 2nd factor of the complex product
|
||||||
*/
|
*/
|
||||||
void ComplexMultiplyAccumulate(Sample* FFTCONVOLVER_RESTRICT re,
|
void ComplexMultiplyAccumulate(Sample *FFTCONVOLVER_RESTRICT re, Sample *FFTCONVOLVER_RESTRICT im,
|
||||||
Sample* FFTCONVOLVER_RESTRICT im,
|
|
||||||
const Sample *FFTCONVOLVER_RESTRICT reA,
|
const Sample *FFTCONVOLVER_RESTRICT reA,
|
||||||
const Sample *FFTCONVOLVER_RESTRICT imA,
|
const Sample *FFTCONVOLVER_RESTRICT imA,
|
||||||
const Sample *FFTCONVOLVER_RESTRICT reB,
|
const Sample *FFTCONVOLVER_RESTRICT reB,
|
||||||
const Sample* FFTCONVOLVER_RESTRICT imB,
|
const Sample *FFTCONVOLVER_RESTRICT imB, const size_t len);
|
||||||
const size_t len);
|
|
||||||
|
|
||||||
} // End of namespace fftconvolver
|
} // End of namespace fftconvolver
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ void convolver_pool_init(size_t numThreads, size_t numConvolvers) {
|
|||||||
if (!pool.init(numThreads, numConvolvers)) {
|
if (!pool.init(numThreads, numConvolvers)) {
|
||||||
debug(1, "failed to initialize thread pool!");
|
debug(1, "failed to initialize thread pool!");
|
||||||
} else {
|
} else {
|
||||||
debug(1, "thread pool initialized with %u thread%s and %u convolver%s.", numThreads, numThreads == 1 ? "" : "s",
|
debug(1, "thread pool initialized with %u thread%s and %u convolver%s.", numThreads,
|
||||||
numConvolvers, numConvolvers == 1 ? "" : "s");
|
numThreads == 1 ? "" : "s", numConvolvers, numConvolvers == 1 ? "" : "s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +56,8 @@ void convolver_pool_closedown() {
|
|||||||
debug(3, "thread pool shut down");
|
debug(3, "thread pool shut down");
|
||||||
}
|
}
|
||||||
|
|
||||||
int convolver_init(const char *filename, unsigned char channel_count,
|
int convolver_init(const char *filename, unsigned char channel_count, double max_length_in_seconds,
|
||||||
double max_length_in_seconds, size_t block_size) {
|
size_t block_size) {
|
||||||
debug(3, "convolver_init");
|
debug(3, "convolver_init");
|
||||||
int success = 0;
|
int success = 0;
|
||||||
SF_INFO info = {}; // Zero everything, including format
|
SF_INFO info = {}; // Zero everything, including format
|
||||||
@@ -124,9 +124,7 @@ void convolver_process(unsigned int channel, float *data, int length) {
|
|||||||
|
|
||||||
void convolver_wait_for_all() { pool.waitForAll(); }
|
void convolver_wait_for_all() { pool.waitForAll(); }
|
||||||
|
|
||||||
void convolver_clear_state() {
|
void convolver_clear_state() { pool.clearAllStates(); }
|
||||||
pool.clearAllStates();
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned int max_channels = 8;
|
const unsigned int max_channels = 8;
|
||||||
fftconvolver::FFTConvolver convolvers[max_channels];
|
fftconvolver::FFTConvolver convolvers[max_channels];
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
// int convolver_init(const char* file, unsigned char channel_count, double max_length_in_seconds, size_t block_size);
|
// int convolver_init(const char* file, unsigned char channel_count, double max_length_in_seconds,
|
||||||
|
// size_t block_size);
|
||||||
void convolver_reset();
|
void convolver_reset();
|
||||||
// void convolver_clear_state();
|
// void convolver_clear_state();
|
||||||
// void convolver_process(unsigned int channel, float *data, int length);
|
// void convolver_process(unsigned int channel, float *data, int length);
|
||||||
@@ -16,7 +17,8 @@ void convolver_reset();
|
|||||||
|
|
||||||
void convolver_pool_init(size_t numThreads, size_t numConvolvers);
|
void convolver_pool_init(size_t numThreads, size_t numConvolvers);
|
||||||
void convolver_pool_closedown();
|
void convolver_pool_closedown();
|
||||||
int convolver_init(const char* file, unsigned char channel_count, double max_length_in_seconds, size_t block_size);
|
int convolver_init(const char *file, unsigned char channel_count, double max_length_in_seconds,
|
||||||
|
size_t block_size);
|
||||||
void convolver_process(unsigned int channel, float *data, int length);
|
void convolver_process(unsigned int channel, float *data, int length);
|
||||||
void convolver_clear_state();
|
void convolver_clear_state();
|
||||||
void convolver_wait_for_all();
|
void convolver_wait_for_all();
|
||||||
|
|||||||
+9
-5
@@ -5,11 +5,11 @@ homedir = @HOME@
|
|||||||
|
|
||||||
# Note that xmlmantohtml isn't producing correct HTML.
|
# Note that xmlmantohtml isn't producing correct HTML.
|
||||||
# Uncomment the if/else and SUBDIR lines in this stanza to make xmltoman build shairport-sync.1
|
# Uncomment the if/else and SUBDIR lines in this stanza to make xmltoman build shairport-sync.1
|
||||||
# if USE_XMLTOMAN
|
if USE_XMLTOMAN
|
||||||
# SUBDIRS = man
|
SUBDIRS = man
|
||||||
# else
|
else
|
||||||
man_MANS = $(top_srcdir)/man/shairport-sync.1
|
man_MANS = $(top_srcdir)/man/shairport-sync.1
|
||||||
# endif
|
endif
|
||||||
|
|
||||||
lib_pair_ap_a_CFLAGS = -Wall -g -DCONFIG_GCRYPT -pthread --include=utilities/debug.h
|
lib_pair_ap_a_CFLAGS = -Wall -g -DCONFIG_GCRYPT -pthread --include=utilities/debug.h
|
||||||
lib_tinyhttp_a_CFLAGS = -pthread
|
lib_tinyhttp_a_CFLAGS = -pthread
|
||||||
@@ -27,7 +27,11 @@ noinst_LIBRARIES =
|
|||||||
|
|
||||||
# See below for the flags for the test client program
|
# See below for the flags for the test client program
|
||||||
|
|
||||||
shairport_sync_SOURCES = shairport.c bonjour_strings.c rtsp.c mdns.c common.c rtp.c player.c audio.c loudness.c activity_monitor.c utilities/debug.c utilities/network_utilities.c utilities/rtsp_message_utilities.c
|
shairport_sync_SOURCES = shairport.c bonjour_strings.c mdns.c common.c rtp.c \
|
||||||
|
player.c audio.c loudness.c activity_monitor.c \
|
||||||
|
rtsp.c \
|
||||||
|
utilities/debug.c utilities/network_utilities.c utilities/rtsp_message_utilities.c \
|
||||||
|
utilities/string_utilities.c
|
||||||
|
|
||||||
if BUILD_FOR_DARWIN
|
if BUILD_FOR_DARWIN
|
||||||
AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-deprecated-declarations -pthread -DSYSCONFDIR=\"$(sysconfdir)\"
|
AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-deprecated-declarations -pthread -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ static const int host_bigendian = 0;
|
|||||||
|
|
||||||
#define _Swap32(v) \
|
#define _Swap32(v) \
|
||||||
do { \
|
do { \
|
||||||
v = (((v)&0x000000FF) << 0x18) | (((v)&0x0000FF00) << 0x08) | (((v)&0x00FF0000) >> 0x08) | \
|
v = (((v) & 0x000000FF) << 0x18) | (((v) & 0x0000FF00) << 0x08) | \
|
||||||
(((v)&0xFF000000) >> 0x18); \
|
(((v) & 0x00FF0000) >> 0x08) | (((v) & 0xFF000000) >> 0x18); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define _Swap16(v) \
|
#define _Swap16(v) \
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "rtp.h"
|
#include "rtp.h"
|
||||||
#include "utilities/buffered_read.h"
|
#include "utilities/buffered_read.h"
|
||||||
#include "utilities/mod23.h"
|
#include "utilities/mod23.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -91,10 +92,9 @@ void addADTStoPacket(uint8_t *packet, int packetLen, int rate, int channel_confi
|
|||||||
void rtp_buffered_audio_cleanup_handler(__attribute__((unused)) void *arg) {
|
void rtp_buffered_audio_cleanup_handler(__attribute__((unused)) void *arg) {
|
||||||
debug(2, "Buffered Audio Receiver Cleanup Start.");
|
debug(2, "Buffered Audio Receiver Cleanup Start.");
|
||||||
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
||||||
close(conn->buffered_audio_socket);
|
safe_socket_close(&conn->buffered_audio_socket);
|
||||||
debug(3, "Connection %d: closing TCP Buffered Audio port: %u.", conn->connection_number,
|
debug(3, "Connection %d: closing TCP Buffered Audio port: %u.", conn->connection_number,
|
||||||
conn->local_buffered_audio_port);
|
conn->local_buffered_audio_port);
|
||||||
conn->buffered_audio_socket = 0;
|
|
||||||
debug(2, "Connection %d: rtp_buffered_audio_processor exit.", conn->connection_number);
|
debug(2, "Connection %d: rtp_buffered_audio_processor exit.", conn->connection_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,14 +277,13 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
previous_ssrc = payload_ssrc;
|
previous_ssrc = payload_ssrc;
|
||||||
payload_ssrc = nctohl(&packet[8]);
|
payload_ssrc = nctohl(&packet[8]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ((payload_ssrc != previous_ssrc) && (payload_ssrc != SSRC_NONE)) {
|
if ((payload_ssrc != previous_ssrc) && (payload_ssrc != SSRC_NONE)) {
|
||||||
if (ssrc_is_recognised(payload_ssrc) == 0) {
|
if (ssrc_is_recognised(payload_ssrc) == 0) {
|
||||||
debug(2, "Unrecognised SSRC: %u.", payload_ssrc);
|
debug(2, "Unrecognised SSRC: %u.", payload_ssrc);
|
||||||
} else {
|
} else {
|
||||||
debug(2, "Connection %d: incoming audio encoding is%s \"%s\".",
|
debug(2, "Connection %d: incoming audio encoding is%s \"%s\".",
|
||||||
conn->connection_number, previous_ssrc == SSRC_NONE ? "" : " switching to", get_ssrc_name(payload_ssrc));
|
conn->connection_number, previous_ssrc == SSRC_NONE ? "" : " switching to",
|
||||||
|
get_ssrc_name(payload_ssrc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +326,8 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
finished = 1;
|
finished = 1;
|
||||||
} else if (nread < 0) {
|
} else if (nread < 0) {
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
(void) !strerror_r(errno, (char *)errorstring, sizeof(errorstring)); // (void) ! to suppress unused response warning
|
(void)!strerror_r(errno, (char *)errorstring,
|
||||||
|
sizeof(errorstring)); // (void) ! to suppress unused response warning
|
||||||
debug(1, "error in rtp_buffered_audio_processor %d: \"%s\". Could not recv a data_len .",
|
debug(1, "error in rtp_buffered_audio_processor %d: \"%s\". Could not recv a data_len .",
|
||||||
errno, errorstring);
|
errno, errorstring);
|
||||||
finished = 1;
|
finished = 1;
|
||||||
@@ -343,23 +343,32 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
debug(2, "immediate flush started at sequence number %u until sequence number of %u.",
|
debug(2, "immediate flush started at sequence number %u until sequence number of %u.",
|
||||||
seq_no, conn->ap2_immediate_flush_until_sequence_number);
|
seq_no, conn->ap2_immediate_flush_until_sequence_number);
|
||||||
}
|
}
|
||||||
if ((blocks_read != 0) && ((a_minus_b_mod23(seq_no, conn->ap2_immediate_flush_until_sequence_number) > 0))) {
|
if ((blocks_read != 0) &&
|
||||||
debug(1, "immediate flush may have escaped its endpoint! Seq_no is %u, conn->ap2_immediate_flush_until_sequence_number is %u.", seq_no, conn->ap2_immediate_flush_until_sequence_number);
|
((a_minus_b_mod23(seq_no, conn->ap2_immediate_flush_until_sequence_number) > 0))) {
|
||||||
|
debug(1,
|
||||||
|
"immediate flush may have escaped its endpoint! Seq_no is %u, "
|
||||||
|
"conn->ap2_immediate_flush_until_sequence_number is %u.",
|
||||||
|
seq_no, conn->ap2_immediate_flush_until_sequence_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((blocks_read != 0) && ((a_minus_b_mod23(seq_no, conn->ap2_immediate_flush_until_sequence_number) >= 0))) {
|
if ((blocks_read != 0) &&
|
||||||
debug(2, "immediate flush completed at seq_no: %u, conn->ap2_immediate_flush_until_sequence_number: %u.", seq_no, conn->ap2_immediate_flush_until_sequence_number);
|
((a_minus_b_mod23(seq_no, conn->ap2_immediate_flush_until_sequence_number) >= 0))) {
|
||||||
|
debug(2,
|
||||||
|
"immediate flush completed at seq_no: %u, "
|
||||||
|
"conn->ap2_immediate_flush_until_sequence_number: %u.",
|
||||||
|
seq_no, conn->ap2_immediate_flush_until_sequence_number);
|
||||||
|
|
||||||
conn->ap2_immediate_flush_requested = 0;
|
conn->ap2_immediate_flush_requested = 0;
|
||||||
ap2_immediate_flush_requested = 0;
|
ap2_immediate_flush_requested = 0;
|
||||||
|
|
||||||
|
|
||||||
// turn off all deferred requests. Not sure if this is right...
|
// turn off all deferred requests. Not sure if this is right...
|
||||||
unsigned int f = 0;
|
unsigned int f = 0;
|
||||||
for (f = 0; f < MAX_DEFERRED_FLUSH_REQUESTS; f++) {
|
for (f = 0; f < MAX_DEFERRED_FLUSH_REQUESTS; f++) {
|
||||||
if ((conn->ap2_deferred_flush_requests[f].inUse != 0) && (conn->ap2_deferred_flush_requests[f].active = 0)) {
|
if ((conn->ap2_deferred_flush_requests[f].inUse != 0) &&
|
||||||
|
(conn->ap2_deferred_flush_requests[f].active = 0)) {
|
||||||
debug(1,
|
debug(1,
|
||||||
"deferred flush cancelled by an immediate flush: flushFromTS: %12u, flushFromSeq: %12u, "
|
"deferred flush cancelled by an immediate flush: flushFromTS: %12u, "
|
||||||
|
"flushFromSeq: %12u, "
|
||||||
"flushUntilTS: %12u, flushUntilSeq: %12u, timestamp: %12u.",
|
"flushUntilTS: %12u, flushUntilSeq: %12u, timestamp: %12u.",
|
||||||
conn->ap2_deferred_flush_requests[f].flushFromTS,
|
conn->ap2_deferred_flush_requests[f].flushFromTS,
|
||||||
conn->ap2_deferred_flush_requests[f].flushFromSeq,
|
conn->ap2_deferred_flush_requests[f].flushFromSeq,
|
||||||
@@ -370,7 +379,6 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
conn->ap2_deferred_flush_requests[f].active = 0;
|
conn->ap2_deferred_flush_requests[f].active = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
debug(4, "immediate flush of block %u until block %u", seq_no,
|
debug(4, "immediate flush of block %u until block %u", seq_no,
|
||||||
conn->ap2_immediate_flush_until_sequence_number);
|
conn->ap2_immediate_flush_until_sequence_number);
|
||||||
@@ -426,11 +434,10 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
} else if (conn->ap2_deferred_flush_requests[f].active != 0) {
|
} else if (conn->ap2_deferred_flush_requests[f].active != 0) {
|
||||||
new_audio_block_needed = 1;
|
new_audio_block_needed = 1;
|
||||||
debug(4,
|
debug(4,
|
||||||
"deferred flush of block: %u, timestamp: %u, SSRC: \"%s\". flushFromTS: %12u, flushFromSeq: %12u, "
|
"deferred flush of block: %u, timestamp: %u, SSRC: \"%s\". flushFromTS: %12u, "
|
||||||
|
"flushFromSeq: %12u, "
|
||||||
"flushUntilTS: %12u, flushUntilSeq: %12u, timestamp: %12u.",
|
"flushUntilTS: %12u, flushUntilSeq: %12u, timestamp: %12u.",
|
||||||
seq_no,
|
seq_no, timestamp, get_ssrc_name(payload_ssrc),
|
||||||
timestamp,
|
|
||||||
get_ssrc_name(payload_ssrc),
|
|
||||||
conn->ap2_deferred_flush_requests[f].flushFromTS,
|
conn->ap2_deferred_flush_requests[f].flushFromTS,
|
||||||
conn->ap2_deferred_flush_requests[f].flushFromSeq,
|
conn->ap2_deferred_flush_requests[f].flushFromSeq,
|
||||||
conn->ap2_deferred_flush_requests[f].flushUntilTS,
|
conn->ap2_deferred_flush_requests[f].flushUntilTS,
|
||||||
@@ -454,9 +461,13 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
|
|
||||||
// calculate if there is room in the decoded audio buffer...
|
// calculate if there is room in the decoded audio buffer...
|
||||||
|
|
||||||
// debug(1, "frames buffered: %f seconds, desired length: %f seconds.", (1.0 * player_buffer_occupancy * conn->frames_per_packet) / conn->input_rate, config.audio_decoded_buffer_desired_length);
|
// debug(1, "frames buffered: %f seconds, desired length: %f seconds.", (1.0 *
|
||||||
|
// player_buffer_occupancy * conn->frames_per_packet) / conn->input_rate,
|
||||||
|
// config.audio_decoded_buffer_desired_length);
|
||||||
|
|
||||||
// int audio_decoded_buffer_below_desired_length = ((1.0 * player_buffer_occupancy * conn->frames_per_packet) / conn->input_rate) <= config.audio_decoded_buffer_desired_length;
|
// int audio_decoded_buffer_below_desired_length = ((1.0 * player_buffer_occupancy *
|
||||||
|
// conn->frames_per_packet) / conn->input_rate) <=
|
||||||
|
// config.audio_decoded_buffer_desired_length;
|
||||||
uint64_t buffer_should_be_time;
|
uint64_t buffer_should_be_time;
|
||||||
|
|
||||||
int have_valid_time = (frame_to_local_time(timestamp, &buffer_should_be_time, conn) == 0);
|
int have_valid_time = (frame_to_local_time(timestamp, &buffer_should_be_time, conn) == 0);
|
||||||
@@ -464,9 +475,11 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
// calculate the lead time to make sure it's not too early...
|
// calculate the lead time to make sure it's not too early...
|
||||||
int64_t lead_time = buffer_should_be_time - get_absolute_time_in_ns();
|
int64_t lead_time = buffer_should_be_time - get_absolute_time_in_ns();
|
||||||
|
|
||||||
|
// debug(1,"play_enabled: %d, have_valid_time: %d,
|
||||||
// debug(1,"play_enabled: %d, have_valid_time: %d, audio_decoded_buffer_below_desired_length: %d, lead_time * 1E-9: %f, (config.audio_decoded_buffer_desired_length + 0.1): %f, player_buffer_occupancy: %zu",
|
// audio_decoded_buffer_below_desired_length: %d, lead_time * 1E-9: %f,
|
||||||
// play_enabled, have_valid_time, audio_decoded_buffer_below_desired_length, lead_time * 1E-9, (config.audio_decoded_buffer_desired_length + 0.1), player_buffer_occupancy
|
// (config.audio_decoded_buffer_desired_length + 0.1): %f, player_buffer_occupancy: %zu",
|
||||||
|
// play_enabled, have_valid_time, audio_decoded_buffer_below_desired_length, lead_time *
|
||||||
|
// 1E-9, (config.audio_decoded_buffer_desired_length + 0.1), player_buffer_occupancy
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// A slight problem here is that counting the number of buffers may not be sufficient,
|
// A slight problem here is that counting the number of buffers may not be sufficient,
|
||||||
@@ -483,7 +496,8 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
// But it also means that Shairport Sync's buffers must be sufficient to hold all the
|
// But it also means that Shairport Sync's buffers must be sufficient to hold all the
|
||||||
// entire lead-time's amount of audio in case the device has a zero-sized buffer.
|
// entire lead-time's amount of audio in case the device has a zero-sized buffer.
|
||||||
|
|
||||||
if ((play_enabled != 0) && (have_valid_time != 0)
|
if ((play_enabled != 0) &&
|
||||||
|
(have_valid_time != 0)
|
||||||
// (audio_decoded_buffer_below_desired_length != 0) &&
|
// (audio_decoded_buffer_below_desired_length != 0) &&
|
||||||
&& (lead_time * 1E-9 < (config.audio_decoded_buffer_desired_length + 0.1))
|
&& (lead_time * 1E-9 < (config.audio_decoded_buffer_desired_length + 0.1))
|
||||||
// && (audio_decoded_buffer_below_desired_length != 0)
|
// && (audio_decoded_buffer_below_desired_length != 0)
|
||||||
@@ -661,11 +675,16 @@ void *rtp_buffered_audio_processor(void *arg) {
|
|||||||
}
|
}
|
||||||
new_audio_block_needed = 1; // the block has been used up and is no longer current
|
new_audio_block_needed = 1; // the block has been used up and is no longer current
|
||||||
} else {
|
} else {
|
||||||
if ((have_valid_time != 0) && (very_early_packets_signalled == 0) && (lead_time * 1E-9 > (config.audio_decoded_buffer_desired_length + 0.2))) {
|
if ((have_valid_time != 0) && (very_early_packets_signalled == 0) &&
|
||||||
debug(1, "incoming frame suddenly (?) has a lead time of %f seconds, with a desired decoded buffer length of %f.", 1.0 * lead_time * 1E-9, config.audio_decoded_buffer_desired_length);
|
(lead_time * 1E-9 > (config.audio_decoded_buffer_desired_length + 0.2))) {
|
||||||
|
debug(1,
|
||||||
|
"incoming frame suddenly (?) has a lead time of %f seconds, with a desired "
|
||||||
|
"decoded buffer length of %f.",
|
||||||
|
1.0 * lead_time * 1E-9, config.audio_decoded_buffer_desired_length);
|
||||||
very_early_packets_signalled = 1;
|
very_early_packets_signalled = 1;
|
||||||
}
|
}
|
||||||
usleep(((1000000 * conn->frames_per_packet) / conn->input_rate) * 2); // wait for approximately the length of two packets
|
usleep(((1000000 * conn->frames_per_packet) / conn->input_rate) *
|
||||||
|
2); // wait for approximately the length of two packets
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,8 @@
|
|||||||
#include "ap2_event_message_handler.h"
|
#include "ap2_event_message_handler.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
#include "utilities/structured_buffer.h"
|
|
||||||
#include "utilities/generate_random_uuid.h"
|
#include "utilities/generate_random_uuid.h"
|
||||||
|
#include "utilities/structured_buffer.h"
|
||||||
|
|
||||||
void decodeAndLogPlist(plist_t plist_to_log) {
|
void decodeAndLogPlist(plist_t plist_to_log) {
|
||||||
if (plist_to_log != NULL) {
|
if (plist_to_log != NULL) {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#ifndef _AP2_EVENT_COMMAND_SENDER_H
|
#ifndef _AP2_EVENT_COMMAND_SENDER_H
|
||||||
#define _AP2_EVENT_COMMAND_SENDER_H
|
#define _AP2_EVENT_COMMAND_SENDER_H
|
||||||
|
|
||||||
|
#include "player.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "player.h"
|
|
||||||
|
|
||||||
ssize_t ap2_event_send_unit_volume_notification(rtsp_conn_info *conn, double volume);
|
ssize_t ap2_event_send_unit_volume_notification(rtsp_conn_info *conn, double volume);
|
||||||
ssize_t ap2_event_send_modern_media_remote_command(rtsp_conn_info *conn, unsigned int command_number);
|
ssize_t ap2_event_send_modern_media_remote_command(rtsp_conn_info *conn,
|
||||||
|
unsigned int command_number);
|
||||||
ssize_t ap2_event_send_update_info(rtsp_conn_info *conn);
|
ssize_t ap2_event_send_update_info(rtsp_conn_info *conn);
|
||||||
|
|
||||||
ssize_t ap2_event_send_dev_mule();
|
ssize_t ap2_event_send_dev_mule();
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ void ap2_event_receiver_cleanup_handler(void *arg) {
|
|||||||
#endif
|
#endif
|
||||||
debug_mutex_lock(&conn->event_sender_mutex, 1000000, 4);
|
debug_mutex_lock(&conn->event_sender_mutex, 1000000, 4);
|
||||||
pthread_cleanup_push(mutex_unlock, &conn->event_sender_mutex);
|
pthread_cleanup_push(mutex_unlock, &conn->event_sender_mutex);
|
||||||
close(conn->event_channel_fd);
|
safe_socket_close(&conn->event_channel_fd);
|
||||||
conn->event_channel_fd = 0;
|
|
||||||
pthread_cleanup_pop(1); // unlock the mutex
|
pthread_cleanup_pop(1); // unlock the mutex
|
||||||
|
|
||||||
if (conn->airplay_gid != NULL) {
|
if (conn->airplay_gid != NULL) {
|
||||||
@@ -68,7 +67,8 @@ void *ap2_event_receiver(void *arg) {
|
|||||||
|
|
||||||
debug_mutex_lock(&conn->event_sender_mutex, 1000000, 4);
|
debug_mutex_lock(&conn->event_sender_mutex, 1000000, 4);
|
||||||
pthread_cleanup_push(mutex_unlock, &conn->event_sender_mutex);
|
pthread_cleanup_push(mutex_unlock, &conn->event_sender_mutex);
|
||||||
conn->event_channel_fd = eintr_checked_accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
|
conn->event_channel_fd =
|
||||||
|
eintr_checked_accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
|
||||||
pthread_cleanup_pop(1); // unlock the mutex
|
pthread_cleanup_pop(1); // unlock the mutex
|
||||||
if (conn->event_channel_fd > 0) {
|
if (conn->event_channel_fd > 0) {
|
||||||
debug(2,
|
debug(2,
|
||||||
@@ -79,7 +79,6 @@ void *ap2_event_receiver(void *arg) {
|
|||||||
|
|
||||||
ap2_event_send_update_info(conn);
|
ap2_event_send_update_info(conn);
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
};
|
};
|
||||||
|
|||||||
+13
-7
@@ -40,6 +40,7 @@
|
|||||||
#include "activity_monitor.h"
|
#include "activity_monitor.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "utilities/string_utilities.h"
|
||||||
|
|
||||||
enum alsa_backend_mode {
|
enum alsa_backend_mode {
|
||||||
abm_disconnected,
|
abm_disconnected,
|
||||||
@@ -951,8 +952,8 @@ static int actual_open_alsa_device() {
|
|||||||
|
|
||||||
if ((snd_pcm_hw_params_get_rate_numden(alsa_params, &uval, &uval2) == 0) && (uval2 != 0))
|
if ((snd_pcm_hw_params_get_rate_numden(alsa_params, &uval, &uval2) == 0) && (uval2 != 0))
|
||||||
// watch for a divide by zero too!
|
// watch for a divide by zero too!
|
||||||
debug(log_level, " precise (rational) rate = %.3f frames per second (i.e. %u/%u).", (1.0 * uval) / uval2, uval,
|
debug(log_level, " precise (rational) rate = %.3f frames per second (i.e. %u/%u).",
|
||||||
uval2);
|
(1.0 * uval) / uval2, uval, uval2);
|
||||||
else
|
else
|
||||||
debug(log_level, " precise (rational) rate information unavailable.");
|
debug(log_level, " precise (rational) rate information unavailable.");
|
||||||
|
|
||||||
@@ -1260,7 +1261,8 @@ static int init(int argc, char **argv) {
|
|||||||
else {
|
else {
|
||||||
warn("Invalid disable_synchronization option choice \"%s\". It should "
|
warn("Invalid disable_synchronization option choice \"%s\". It should "
|
||||||
"be \"yes\" or "
|
"be \"yes\" or "
|
||||||
"\"no\". It is set to \"no\".", str);
|
"\"no\". It is set to \"no\".",
|
||||||
|
str);
|
||||||
config.no_sync = 0;
|
config.no_sync = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1276,7 +1278,8 @@ static int init(int argc, char **argv) {
|
|||||||
else {
|
else {
|
||||||
warn("Invalid mute_using_playback_switch option choice \"%s\". It "
|
warn("Invalid mute_using_playback_switch option choice \"%s\". It "
|
||||||
"should be \"yes\" or "
|
"should be \"yes\" or "
|
||||||
"\"no\". It is set to \"no\".", str);
|
"\"no\". It is set to \"no\".",
|
||||||
|
str);
|
||||||
config.alsa_use_hardware_mute = 0;
|
config.alsa_use_hardware_mute = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1290,7 +1293,8 @@ static int init(int argc, char **argv) {
|
|||||||
else {
|
else {
|
||||||
warn("Invalid use_hardware_mute_if_available option choice \"%s\". It "
|
warn("Invalid use_hardware_mute_if_available option choice \"%s\". It "
|
||||||
"should be \"yes\" or "
|
"should be \"yes\" or "
|
||||||
"\"no\". It is set to \"no\".", str);
|
"\"no\". It is set to \"no\".",
|
||||||
|
str);
|
||||||
config.alsa_use_hardware_mute = 0;
|
config.alsa_use_hardware_mute = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1304,7 +1308,8 @@ static int init(int argc, char **argv) {
|
|||||||
else {
|
else {
|
||||||
warn("Invalid use_mmap_if_available option choice \"%s\". It should be "
|
warn("Invalid use_mmap_if_available option choice \"%s\". It should be "
|
||||||
"\"yes\" or \"no\". "
|
"\"yes\" or \"no\". "
|
||||||
"It remains set to \"yes\".", str);
|
"It remains set to \"yes\".",
|
||||||
|
str);
|
||||||
config.no_mmap = 0;
|
config.no_mmap = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1424,7 +1429,8 @@ static int init(int argc, char **argv) {
|
|||||||
else {
|
else {
|
||||||
warn("Invalid use_precision_timing option choice \"%s\". It should be "
|
warn("Invalid use_precision_timing option choice \"%s\". It should be "
|
||||||
"\"yes\", \"auto\" or \"no\". "
|
"\"yes\", \"auto\" or \"no\". "
|
||||||
"It remains set to \"%s\".", str,
|
"It remains set to \"%s\".",
|
||||||
|
str,
|
||||||
config.use_precision_timing == YNA_NO ? "no"
|
config.use_precision_timing == YNA_NO ? "no"
|
||||||
: config.use_precision_timing == YNA_AUTO ? "auto"
|
: config.use_precision_timing == YNA_AUTO ? "auto"
|
||||||
: "yes");
|
: "yes");
|
||||||
|
|||||||
+2
-1
@@ -506,7 +506,8 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char *
|
|||||||
|
|
||||||
// get the default channel mapping setting basis -- "alsa" or "pulseaudio".
|
// get the default channel mapping setting basis -- "alsa" or "pulseaudio".
|
||||||
|
|
||||||
if (config_lookup_non_empty_string(config.cfg, "pulseaudio.default_channel_layouts", &default_channel_layouts)) {
|
if (config_lookup_non_empty_string(config.cfg, "pulseaudio.default_channel_layouts",
|
||||||
|
&default_channel_layouts)) {
|
||||||
if ((strcasecmp(default_channel_layouts, "alsa") == 0) ||
|
if ((strcasecmp(default_channel_layouts, "alsa") == 0) ||
|
||||||
(strcasecmp(default_channel_layouts, "pulseaudio") == 0)) {
|
(strcasecmp(default_channel_layouts, "pulseaudio") == 0)) {
|
||||||
debug(1, "pulseaudio default_channel_layouts setting: \"%s\".", default_channel_layouts);
|
debug(1, "pulseaudio default_channel_layouts setting: \"%s\".", default_channel_layouts);
|
||||||
|
|||||||
+3
-4
@@ -39,6 +39,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
|
|
||||||
static int fd = -1;
|
static int fd = -1;
|
||||||
static int warned = 0;
|
static int warned = 0;
|
||||||
static unsigned int bytes_per_frame = 0;
|
static unsigned int bytes_per_frame = 0;
|
||||||
@@ -146,10 +148,7 @@ static int init(int argc, char **argv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deinit(void) {
|
static void deinit(void) { safe_socket_close(&fd); }
|
||||||
if (fd > 0)
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void help(void) {
|
static void help(void) {
|
||||||
printf(" Provide the pipe's pathname. The default is \"%s\".\n", default_pipe_name);
|
printf(" Provide the pipe's pathname. The default is \"%s\".\n", default_pipe_name);
|
||||||
|
|||||||
+10
-6
@@ -76,15 +76,17 @@ void build_bonjour_strings(__attribute((unused)) rtsp_conn_info *conn) {
|
|||||||
// the secondary_txt_records are for the _airplay._tcp items.
|
// the secondary_txt_records are for the _airplay._tcp items.
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
uint64_t features_hi = config.airplay_features;
|
||||||
|
features_hi = (features_hi >> 32) & 0xffffffff;
|
||||||
|
uint64_t features_lo = config.airplay_features;
|
||||||
|
features_lo = features_lo & 0xffffffff;
|
||||||
|
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
txt_records[entry_number++] = "cn=0,1";
|
txt_records[entry_number++] = "cn=0,1";
|
||||||
txt_records[entry_number++] = "da=true";
|
txt_records[entry_number++] = "da=true";
|
||||||
txt_records[entry_number++] = "et=0,1";
|
txt_records[entry_number++] = "et=0,1";
|
||||||
if (config.password != NULL)
|
if (config.password != NULL)
|
||||||
txt_records[entry_number++] = "pw=true";
|
txt_records[entry_number++] = "pw=true";
|
||||||
uint64_t features_hi = config.airplay_features;
|
|
||||||
features_hi = (features_hi >> 32) & 0xffffffff;
|
|
||||||
uint64_t features_lo = config.airplay_features;
|
|
||||||
features_lo = features_lo & 0xffffffff;
|
|
||||||
|
|
||||||
txt_records[entry_number++] =
|
txt_records[entry_number++] =
|
||||||
bnprintf(ap1_featuresString, sizeof(ap1_featuresString), "ft=0x%" PRIX64 ",0x%" PRIX64 "",
|
bnprintf(ap1_featuresString, sizeof(ap1_featuresString), "ft=0x%" PRIX64 ",0x%" PRIX64 "",
|
||||||
@@ -110,8 +112,8 @@ void build_bonjour_strings(__attribute((unused)) rtsp_conn_info *conn) {
|
|||||||
txt_records[entry_number++] =
|
txt_records[entry_number++] =
|
||||||
bnprintf(ap1OsversString, sizeof(ap1OsversString), "ov=%s", config.osvers);
|
bnprintf(ap1OsversString, sizeof(ap1OsversString), "ov=%s", config.osvers);
|
||||||
txt_records[entry_number++] = NULL;
|
txt_records[entry_number++] = NULL;
|
||||||
|
} else {
|
||||||
#else
|
#endif
|
||||||
// here, just replicate what happens in mdns.h when using those #defines
|
// here, just replicate what happens in mdns.h when using those #defines
|
||||||
txt_records[entry_number++] =
|
txt_records[entry_number++] =
|
||||||
bnprintf(ap1StatusFlagsString, sizeof(ap1StatusFlagsString), "sf=0x4");
|
bnprintf(ap1StatusFlagsString, sizeof(ap1StatusFlagsString), "sf=0x4");
|
||||||
@@ -142,6 +144,8 @@ void build_bonjour_strings(__attribute((unused)) rtsp_conn_info *conn) {
|
|||||||
else
|
else
|
||||||
txt_records[entry_number++] = "pw=true";
|
txt_records[entry_number++] = "pw=true";
|
||||||
txt_records[entry_number++] = NULL;
|
txt_records[entry_number++] = NULL;
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
|
|
||||||
#ifdef CONFIG_USE_GIT_VERSION_STRING
|
#ifdef CONFIG_USE_GIT_VERSION_STRING
|
||||||
#include "gitversion.h"
|
#include "gitversion.h"
|
||||||
@@ -51,8 +52,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
#ifdef COMPILE_FOR_LINUX
|
#ifdef COMPILE_FOR_LINUX
|
||||||
#include <netpacket/packet.h>
|
#include <netpacket/packet.h>
|
||||||
@@ -411,7 +412,7 @@ int bind_socket_and_port(int type, int ip_family, const char *self_ip_address, u
|
|||||||
#endif
|
#endif
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret = errno;
|
ret = errno;
|
||||||
close(local_socket);
|
safe_socket_close(&local_socket);
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
getErrorText((char *)errorstring, sizeof(errorstring));
|
getErrorText((char *)errorstring, sizeof(errorstring));
|
||||||
warn("error %d: \"%s\". Could not bind a port!", errno, errorstring);
|
warn("error %d: \"%s\". Could not bind a port!", errno, errorstring);
|
||||||
@@ -422,7 +423,7 @@ int bind_socket_and_port(int type, int ip_family, const char *self_ip_address, u
|
|||||||
ret = getsockname(local_socket, (struct sockaddr *)&local, &local_len);
|
ret = getsockname(local_socket, (struct sockaddr *)&local, &local_len);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret = errno;
|
ret = errno;
|
||||||
close(local_socket);
|
safe_socket_close(&local_socket);
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
getErrorText((char *)errorstring, sizeof(errorstring));
|
getErrorText((char *)errorstring, sizeof(errorstring));
|
||||||
warn("error %d: \"%s\". Could not retrieve socket's port!", errno, errorstring);
|
warn("error %d: \"%s\". Could not retrieve socket's port!", errno, errorstring);
|
||||||
@@ -494,7 +495,7 @@ uint16_t bind_UDP_port(int ip_family, const char *self_ip_address, uint32_t scop
|
|||||||
// debug(1,"UDP port chosen: %d.",desired_port);
|
// debug(1,"UDP port chosen: %d.",desired_port);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
close(local_socket);
|
safe_socket_close(&local_socket);
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
getErrorText((char *)errorstring, sizeof(errorstring));
|
getErrorText((char *)errorstring, sizeof(errorstring));
|
||||||
die("error %d: \"%s\". Could not bind a UDP port! Check the udp_port_range is large enough -- "
|
die("error %d: \"%s\". Could not bind a UDP port! Check the udp_port_range is large enough -- "
|
||||||
@@ -950,7 +951,8 @@ uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
|
|||||||
mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE);
|
mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE);
|
||||||
outbuf = malloc(trsa->MBEDTLS_PRIVATE_V3_ONLY(len));
|
outbuf = malloc(trsa->MBEDTLS_PRIVATE_V3_ONLY(len));
|
||||||
#if MBEDTLS_VERSION_MAJOR == 3
|
#if MBEDTLS_VERSION_MAJOR == 3
|
||||||
rc = mbedtls_pk_sign(&pkctx, MBEDTLS_MD_NONE, input, inlen, outbuf, mbedtls_pk_get_len(&pkctx), &olen, mbedtls_ctr_drbg_random, &ctr_drbg);
|
rc = mbedtls_pk_sign(&pkctx, MBEDTLS_MD_NONE, input, inlen, outbuf, mbedtls_pk_get_len(&pkctx),
|
||||||
|
&olen, mbedtls_ctr_drbg_random, &ctr_drbg);
|
||||||
*outlen = olen;
|
*outlen = olen;
|
||||||
#else
|
#else
|
||||||
rc = mbedtls_rsa_pkcs1_encrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
|
rc = mbedtls_rsa_pkcs1_encrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
|
||||||
@@ -1076,11 +1078,14 @@ int config_set_lookup_bool(config_t *cfg, const char *where, int *dst) {
|
|||||||
(*dst) = 1;
|
(*dst) = 1;
|
||||||
response = CONFIG_TRUE;
|
response = CONFIG_TRUE;
|
||||||
} else {
|
} else {
|
||||||
die("invalid boolean parameter \"%s\" option choice \"%s\". It should be \"yes\" or \"no\"", where, str);
|
die("invalid boolean parameter \"%s\" option choice \"%s\". It should be \"yes\" or \"no\"",
|
||||||
|
where, str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn("the \"%s\" parameter is not a string with a value of \"yes\" or \"no\", as required, and has been ignored.", where);
|
warn("the \"%s\" parameter is not a string with a value of \"yes\" or \"no\", as required, "
|
||||||
|
"and has been ignored.",
|
||||||
|
where);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
@@ -1245,6 +1250,59 @@ int check_int_or_list_setting(config_setting_t *setting, const int item) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void service_type_to_string(APST_t service_type, char *string_space) {
|
||||||
|
if (string_space != NULL) {
|
||||||
|
string_space[0] = '\0';
|
||||||
|
switch (service_type) {
|
||||||
|
case APST_auto:
|
||||||
|
strcpy(string_space, "auto");
|
||||||
|
break;
|
||||||
|
case APST_classic:
|
||||||
|
strcpy(string_space, "classic");
|
||||||
|
break;
|
||||||
|
case APST_forced_classic:
|
||||||
|
strcpy(string_space, "forced_classic");
|
||||||
|
break;
|
||||||
|
case APST_airplay2:
|
||||||
|
strcpy(string_space, "airplay2");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
APST_t string_to_service_type(const char *parameter, const char *setting_name) {
|
||||||
|
APST_t response = APST_auto;
|
||||||
|
if (parameter != NULL) {
|
||||||
|
if (strcasecmp(parameter, "auto") == 0) {
|
||||||
|
response = APST_auto;
|
||||||
|
} else if (strcasecmp(parameter, "classic") == 0) {
|
||||||
|
response = APST_classic;
|
||||||
|
} else if (strcasecmp(parameter, "airplay1") == 0) {
|
||||||
|
response = APST_classic;
|
||||||
|
} else if (strcasecmp(parameter, "airplay2") == 0) {
|
||||||
|
response = APST_airplay2;
|
||||||
|
} else {
|
||||||
|
warn("The %s \"%s\" was ignored. It must be \"auto\", \"classic\" or \"airplay2\". (You can "
|
||||||
|
"use \"airplay1\" instead of \"classic\".)",
|
||||||
|
setting_name, parameter);
|
||||||
|
}
|
||||||
|
#ifndef CONFIG_AIRPLAY_2
|
||||||
|
if (response == APST_airplay2) {
|
||||||
|
warn("This version of Shairport Sync supports does not support AirPlay 2. The %s \"%s\" "
|
||||||
|
"setting has been ignored.",
|
||||||
|
setting_name, parameter);
|
||||||
|
response = APST_auto; // reset to default
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
char service_type_string[32];
|
||||||
|
service_type_to_string(response, service_type_string);
|
||||||
|
debug(1, "config.service_type read from %s is: \"%s\".", setting_name, service_type_string);
|
||||||
|
*/
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
void command_set_volume(double volume) {
|
void command_set_volume(double volume) {
|
||||||
// this has a cancellation point if waiting is enabled
|
// this has a cancellation point if waiting is enabled
|
||||||
if (config.cmd_set_volume) {
|
if (config.cmd_set_volume) {
|
||||||
@@ -1310,11 +1368,11 @@ void command_start(void) {
|
|||||||
char **argV;
|
char **argV;
|
||||||
|
|
||||||
if (config.cmd_start_returns_output) {
|
if (config.cmd_start_returns_output) {
|
||||||
close(pipes[0]);
|
safe_socket_close(&pipes[0]);
|
||||||
if (dup2(pipes[1], 1) < 0) {
|
if (dup2(pipes[1], 1) < 0) {
|
||||||
warn("Unable to reopen pipe as stdout for popen of start command");
|
warn("Unable to reopen pipe as stdout for popen of start command");
|
||||||
debug(1, "dup2 finished with error %d", errno);
|
debug(1, "dup2 finished with error %d", errno);
|
||||||
close(pipes[1]);
|
safe_socket_close(&pipes[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1344,9 +1402,9 @@ void command_start(void) {
|
|||||||
if (config.cmd_start_returns_output) {
|
if (config.cmd_start_returns_output) {
|
||||||
static char buffer[256];
|
static char buffer[256];
|
||||||
int len;
|
int len;
|
||||||
close(pipes[1]);
|
safe_socket_close(&pipes[1]);
|
||||||
len = read(pipes[0], buffer, 255);
|
len = read(pipes[0], buffer, 255);
|
||||||
close(pipes[0]);
|
safe_socket_close(&pipes[0]);
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
if (buffer[len - 1] == '\n')
|
if (buffer[len - 1] == '\n')
|
||||||
buffer[len - 1] = '\0'; // strip trailing newlines
|
buffer[len - 1] = '\0'; // strip trailing newlines
|
||||||
@@ -1705,45 +1763,6 @@ int try_to_open_pipe_for_writing(const char *pathname) {
|
|||||||
return fdis;
|
return fdis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* from
|
|
||||||
* http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring#comment-722
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *str_replace(const char *string, const char *substr, const char *replacement) {
|
|
||||||
char *tok = NULL;
|
|
||||||
char *newstr = NULL;
|
|
||||||
char *oldstr = NULL;
|
|
||||||
char *head = NULL;
|
|
||||||
|
|
||||||
/* if either substr or replacement is NULL, duplicate string a let caller handle it */
|
|
||||||
if (substr == NULL || replacement == NULL)
|
|
||||||
return strdup(string);
|
|
||||||
newstr = strdup(string);
|
|
||||||
head = newstr;
|
|
||||||
if (head) {
|
|
||||||
while ((tok = strstr(head, substr))) {
|
|
||||||
oldstr = newstr;
|
|
||||||
newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
|
|
||||||
/*failed to alloc mem, free old string and return NULL */
|
|
||||||
if (newstr == NULL) {
|
|
||||||
free(oldstr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy(newstr, oldstr, tok - oldstr);
|
|
||||||
memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
|
|
||||||
memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
|
|
||||||
strlen(oldstr) - strlen(substr) - (tok - oldstr));
|
|
||||||
memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
|
|
||||||
/* move back head right after the last replacement */
|
|
||||||
head = newstr + (tok - oldstr) + strlen(replacement);
|
|
||||||
free(oldstr);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
die("failed to allocate memory in str_replace.");
|
|
||||||
}
|
|
||||||
return newstr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* from http://burtleburtle.net/bob/rand/smallprng.html */
|
/* from http://burtleburtle.net/bob/rand/smallprng.html */
|
||||||
|
|
||||||
// this is not thread-safe, so we need a mutex on it to use it properly.
|
// this is not thread-safe, so we need a mutex on it to use it properly.
|
||||||
@@ -1826,7 +1845,8 @@ void sps_nanosleep(const time_t sec, const long nanosec) {
|
|||||||
rem = req;
|
rem = req;
|
||||||
} while ((result == -1) && (errno == EINTR));
|
} while ((result == -1) && (errno == EINTR));
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
debug(1, "Error in sps_nanosleep of %" PRIdMAX " sec and %ld nanoseconds: %d.", (intmax_t)sec, nanosec, errno);
|
debug(1, "Error in sps_nanosleep of %" PRIdMAX " sec and %ld nanoseconds: %d.", (intmax_t)sec,
|
||||||
|
nanosec, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mac OS X doesn't have pthread_mutex_timedlock
|
// Mac OS X doesn't have pthread_mutex_timedlock
|
||||||
@@ -1938,10 +1958,9 @@ void plist_cleanup(void *arg) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void socket_cleanup(void *arg) {
|
void socket_cleanup(void *arg) {
|
||||||
intptr_t fdp = (intptr_t)arg;
|
int *p = (int *)arg;
|
||||||
int soc = fdp;
|
debug(3, "socket_cleanup called for socket: %d.", *p);
|
||||||
debug(3, "socket_cleanup called for socket: %d.", soc);
|
safe_socket_close(p);
|
||||||
close(fdp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv_cleanup(void *arg) {
|
void cv_cleanup(void *arg) {
|
||||||
@@ -2349,12 +2368,8 @@ int get_device_id(uint8_t *id, int int_length) {
|
|||||||
#ifdef AF_PACKET
|
#ifdef AF_PACKET
|
||||||
if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) {
|
if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) {
|
||||||
struct sockaddr_ll *s = (struct sockaddr_ll *)ifa->ifa_addr;
|
struct sockaddr_ll *s = (struct sockaddr_ll *)ifa->ifa_addr;
|
||||||
if (
|
if (((ifa->ifa_flags & IFF_UP) != 0) && ((ifa->ifa_flags & IFF_RUNNING) != 0) &&
|
||||||
((ifa->ifa_flags & IFF_UP) != 0) &&
|
((ifa->ifa_flags & IFF_LOOPBACK) == 0) && (ifa->ifa_addr != 0)) {
|
||||||
((ifa->ifa_flags & IFF_RUNNING) != 0) &&
|
|
||||||
((ifa->ifa_flags & IFF_LOOPBACK) == 0) &&
|
|
||||||
(ifa->ifa_addr != 0)
|
|
||||||
) {
|
|
||||||
found = 1;
|
found = 1;
|
||||||
response = 0;
|
response = 0;
|
||||||
for (i = 0; ((i < s->sll_halen) && (i < int_length)); i++) {
|
for (i = 0; ((i < s->sll_halen) && (i < int_length)); i++) {
|
||||||
@@ -2430,7 +2445,7 @@ int named_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||||||
debug(1, "error creating thread \"%s\"", actual_name);
|
debug(1, "error creating thread \"%s\"", actual_name);
|
||||||
}
|
}
|
||||||
#ifndef COMPILE_FOR_OSX
|
#ifndef COMPILE_FOR_OSX
|
||||||
else {
|
if (response == 0) {
|
||||||
pthread_setname_np(*thread, actual_name);
|
pthread_setname_np(*thread, actual_name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2481,6 +2496,7 @@ int named_pthread_create_with_priority(pthread_t *thread, int priority,
|
|||||||
}
|
}
|
||||||
// ret == 0 if creating and setting up the attributes was successful
|
// ret == 0 if creating and setting up the attributes was successful
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
|
||||||
ret = pthread_create(thread, &attr, start_routine, arg);
|
ret = pthread_create(thread, &attr, start_routine, arg);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
}
|
}
|
||||||
@@ -2489,7 +2505,7 @@ int named_pthread_create_with_priority(pthread_t *thread, int priority,
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = pthread_create(thread, NULL, start_routine, arg);
|
ret = pthread_create(thread, NULL, start_routine, arg);
|
||||||
if (failed_to_set_rt == 0) {
|
if (failed_to_set_rt == 0) {
|
||||||
inform("Can not set realtime properties of a thread.");
|
inform("Can not set realtime properties of thread \"%s\".", actual_name);
|
||||||
failed_to_set_rt = 1;
|
failed_to_set_rt = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ extern "C" {
|
|||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "mdns.h"
|
#include "mdns.h"
|
||||||
|
|
||||||
|
// service type to be offered
|
||||||
|
typedef enum {
|
||||||
|
APST_auto = 0,
|
||||||
|
APST_classic, // must be classic / airplay 1
|
||||||
|
APST_forced_classic, // must be classic / airplay 1 because no nqptp
|
||||||
|
APST_airplay2, // must be airplay 2; error if no NQPTP
|
||||||
|
} APST_t; // AirPlay Service Type
|
||||||
|
|
||||||
// struct sockaddr_in6 is bigger than struct sockaddr. derp
|
// struct sockaddr_in6 is bigger than struct sockaddr. derp
|
||||||
#ifdef AF_INET6
|
#ifdef AF_INET6
|
||||||
#define SOCKADDR struct sockaddr_storage
|
#define SOCKADDR struct sockaddr_storage
|
||||||
@@ -24,8 +32,10 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_CONVOLUTION)
|
#if defined(CONFIG_CONVOLUTION)
|
||||||
|
// impulse response filter file status
|
||||||
typedef enum { ev_unchecked, ev_okay, ev_invalid } ir_file_evaluation;
|
typedef enum { ev_unchecked, ev_okay, ev_invalid } ir_file_evaluation;
|
||||||
|
|
||||||
|
// impulse response filter file record
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int samplerate; // initialized to 0, will be filter frame rate
|
unsigned int samplerate; // initialized to 0, will be filter frame rate
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
@@ -147,12 +157,13 @@ typedef enum {
|
|||||||
#define SPS_FORMAT_SET (((1 << (SPS_FORMAT_HIGHEST_NATIVE + 1)) - 1) - (1 << SPS_FORMAT_UNKNOWN))
|
#define SPS_FORMAT_SET (((1 << (SPS_FORMAT_HIGHEST_NATIVE + 1)) - 1) - (1 << SPS_FORMAT_UNKNOWN))
|
||||||
#define SPS_RATE_SET (((1 << (SPS_RATE_HIGHEST + 1)) - 1) - (1 << SPS_RATE_UNKNOWN))
|
#define SPS_RATE_SET (((1 << (SPS_RATE_HIGHEST + 1)) - 1) - (1 << SPS_RATE_UNKNOWN))
|
||||||
|
|
||||||
// in SPS_CHANNEL_SET, bit 0 set means a channel set of no channels, bit 1 set means a channel set of 1 channel
|
// in SPS_CHANNEL_SET, bit 0 set means a channel set of no channels, bit 1 set means a channel set
|
||||||
// and so on to bit 31 meaning a channel set of 31 channels. We want to consider all possible channel sets
|
// of 1 channel and so on to bit 31 meaning a channel set of 31 channels. We want to consider all
|
||||||
// apart from channel set 0.
|
// possible channel sets apart from channel set 0.
|
||||||
#define SPS_GREATEST_CHANNEL_COUNT 31 // should be 32 to be fully in line with ALSA limits
|
#define SPS_GREATEST_CHANNEL_COUNT 31 // should be 32 to be fully in line with ALSA limits
|
||||||
#define SPS_CHANNEL_SET 0xFFFFFFFE // channel sets 31 to 1, but no channel set 0
|
#define SPS_CHANNEL_SET 0xFFFFFFFE // channel sets 31 to 1, but no channel set 0
|
||||||
// #define SPS_CHANNEL_SET (((1 << (SPS_GREATEST_CHANNEL_COUNT + 1)) - 1) - (1 << 0)) // channels 1 to 31, not 0-based!
|
// #define SPS_CHANNEL_SET (((1 << (SPS_GREATEST_CHANNEL_COUNT + 1)) - 1) - (1 << 0)) // channels 1
|
||||||
|
// to 31, not 0-based!
|
||||||
|
|
||||||
#ifndef CONFIG_AIRPLAY_2
|
#ifndef CONFIG_AIRPLAY_2
|
||||||
#define SPS_FORMAT_NON_FFMPEG_SET SPS_FORMAT_SET
|
#define SPS_FORMAT_NON_FFMPEG_SET SPS_FORMAT_SET
|
||||||
@@ -410,6 +421,9 @@ typedef struct {
|
|||||||
char *nqptp_shared_memory_interface_name; // client name for nqptp service
|
char *nqptp_shared_memory_interface_name; // client name for nqptp service
|
||||||
int enable_HK_Access_Control; // true if the device is part of an Apple Home
|
int enable_HK_Access_Control; // true if the device is part of an Apple Home
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
APST_t service_type; // APST_auto, APST_classic, APST_forced_classic, APST_airplay2
|
||||||
|
|
||||||
int unfixable_error_reported; // only report once.
|
int unfixable_error_reported; // only report once.
|
||||||
|
|
||||||
uint64_t eight_channel_layout; // non-zero means enabled and is a channel layout
|
uint64_t eight_channel_layout; // non-zero means enabled and is a channel layout
|
||||||
@@ -460,11 +474,6 @@ void set_requested_connection_state_to_output(int v);
|
|||||||
int try_to_open_pipe_for_writing(
|
int try_to_open_pipe_for_writing(
|
||||||
const char *pathname); // open it without blocking if it's not hooked up
|
const char *pathname); // open it without blocking if it's not hooked up
|
||||||
|
|
||||||
/* from
|
|
||||||
* http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring#comment-722
|
|
||||||
*/
|
|
||||||
char *str_replace(const char *string, const char *substr, const char *replacement);
|
|
||||||
|
|
||||||
// based on http://burtleburtle.net/bob/rand/smallprng.html
|
// based on http://burtleburtle.net/bob/rand/smallprng.html
|
||||||
|
|
||||||
void r64init(uint64_t seed);
|
void r64init(uint64_t seed);
|
||||||
@@ -562,6 +571,9 @@ unsigned int config_get_string_settings_as_string_array(config_setting_t *settin
|
|||||||
const char ***result);
|
const char ***result);
|
||||||
unsigned int config_get_int_settings_as_int_array(config_setting_t *setting, int **result);
|
unsigned int config_get_int_settings_as_int_array(config_setting_t *setting, int **result);
|
||||||
|
|
||||||
|
APST_t string_to_service_type(const char *parameter, const char *setting_name);
|
||||||
|
void service_type_to_string(APST_t service_type, char *string_space);
|
||||||
|
|
||||||
void command_start(void);
|
void command_start(void);
|
||||||
void command_stop(void);
|
void command_stop(void);
|
||||||
void command_execute(const char *command, const char *extra_argument, const int block);
|
void command_execute(const char *command, const char *extra_argument, const int block);
|
||||||
|
|||||||
+6
-1
@@ -469,7 +469,7 @@ if test "x$with_airplay_2" = "xyes" ; then
|
|||||||
])
|
])
|
||||||
AC_CHECK_LIB([uuid],[uuid_generate], [], [AC_MSG_ERROR([AirPlay 2 support requires the uuid library -- uuid-dev suggested])])
|
AC_CHECK_LIB([uuid],[uuid_generate], [], [AC_MSG_ERROR([AirPlay 2 support requires the uuid library -- uuid-dev suggested])])
|
||||||
systemd_after_args="${systemd_after_args}${systemd_after_args:+ }nqptp.service"
|
systemd_after_args="${systemd_after_args}${systemd_after_args:+ }nqptp.service"
|
||||||
systemd_requires_args="${systemd_requires_args}${systemd_requires_args:+ }nqptp.service"
|
systemd_wants_args="${systemd_wants_args}${systemd_wants_args:+ }nqptp.service"
|
||||||
fi
|
fi
|
||||||
AM_CONDITIONAL([USE_AIRPLAY_2], [test "x$with_airplay_2" = "xyes"])
|
AM_CONDITIONAL([USE_AIRPLAY_2], [test "x$with_airplay_2" = "xyes"])
|
||||||
|
|
||||||
@@ -586,8 +586,13 @@ if test "x${systemd_requires_args}" != x ; then
|
|||||||
systemd_requires_args="Requires=${systemd_requires_args}"
|
systemd_requires_args="Requires=${systemd_requires_args}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "x${systemd_wants_args}" != x ; then
|
||||||
|
systemd_wants_args="Wants=${systemd_wants_args}"
|
||||||
|
fi
|
||||||
|
|
||||||
AC_SUBST([SYSTEMD_AFTER_ARGS], [${systemd_after_args}])
|
AC_SUBST([SYSTEMD_AFTER_ARGS], [${systemd_after_args}])
|
||||||
AC_SUBST([SYSTEMD_REQUIRES_ARGS], [${systemd_requires_args}])
|
AC_SUBST([SYSTEMD_REQUIRES_ARGS], [${systemd_requires_args}])
|
||||||
|
AC_SUBST([SYSTEMD_WANTS_ARGS], [${systemd_wants_args}])
|
||||||
|
|
||||||
# The man directory will not be recursively made unless you set the SUBDIR in Makefile.am.
|
# The man directory will not be recursively made unless you set the SUBDIR in Makefile.am.
|
||||||
# But leave this as is to enable a distclean to be done.
|
# But leave this as is to enable a distclean to be done.
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include "metadata/hub.h"
|
#include "metadata/hub.h"
|
||||||
#include "tinyhttp/http.h"
|
#include "tinyhttp/http.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int players_connection_thread_index; // the connection thread index when a player thread is
|
int players_connection_thread_index; // the connection thread index when a player thread is
|
||||||
@@ -117,8 +118,7 @@ void response_body(void *opaque, const char *data, int size) {
|
|||||||
static void
|
static void
|
||||||
response_header(__attribute__((unused)) void *opaque, __attribute__((unused)) const char *ckey,
|
response_header(__attribute__((unused)) void *opaque, __attribute__((unused)) const char *ckey,
|
||||||
__attribute__((unused)) int nkey, __attribute__((unused)) const char *cvalue,
|
__attribute__((unused)) int nkey, __attribute__((unused)) const char *cvalue,
|
||||||
__attribute__((unused)) int nvalue) { /* example doesn't care about headers */
|
__attribute__((unused)) int nvalue) { /* example doesn't care about headers */ }
|
||||||
}
|
|
||||||
|
|
||||||
static void response_code(void *opaque, int code) {
|
static void response_code(void *opaque, int code) {
|
||||||
struct HttpResponse *response = (struct HttpResponse *)opaque;
|
struct HttpResponse *response = (struct HttpResponse *)opaque;
|
||||||
@@ -150,12 +150,6 @@ void mutex_lock_cleanup(void *arg) {
|
|||||||
debug(1, "Error releasing mutex.");
|
debug(1, "Error releasing mutex.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void connect_cleanup(void *arg) {
|
|
||||||
int *fd = (int *)arg;
|
|
||||||
// debug(2, "dacp_send_command: close socket %d.",*fd);
|
|
||||||
close(*fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void http_cleanup(void *arg) {
|
void http_cleanup(void *arg) {
|
||||||
// debug(1, "http cleanup called.");
|
// debug(1, "http cleanup called.");
|
||||||
struct http_roundtripper *rt = (struct http_roundtripper *)arg;
|
struct http_roundtripper *rt = (struct http_roundtripper *)arg;
|
||||||
@@ -234,7 +228,7 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
|
|||||||
// \"%s\".",errno,strerror(errno));
|
// \"%s\".",errno,strerror(errno));
|
||||||
response.code = 497; // Can't establish a socket to the DACP server
|
response.code = 497; // Can't establish a socket to the DACP server
|
||||||
} else {
|
} else {
|
||||||
pthread_cleanup_push(connect_cleanup, (void *)&sockfd);
|
pthread_cleanup_push(socket_cleanup, (void *)&sockfd);
|
||||||
// debug(2, "dacp_send_command: open socket %d.",sockfd);
|
// debug(2, "dacp_send_command: open socket %d.",sockfd);
|
||||||
|
|
||||||
// This is for limiting the time to be spent waiting for a response.
|
// This is for limiting the time to be spent waiting for a response.
|
||||||
@@ -350,8 +344,7 @@ int dacp_send_command(const char *command, char **body, ssize_t *bodysize) {
|
|||||||
0); // this should *not* free the malloced buffer -- just pop the malloc cleanup
|
0); // this should *not* free the malloced buffer -- just pop the malloc cleanup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_cleanup_pop(1); // this should close the socket
|
pthread_cleanup_pop(1); // this will close the socket
|
||||||
// close(sockfd);
|
|
||||||
// debug(1,"DACP socket closed.");
|
// debug(1,"DACP socket closed.");
|
||||||
}
|
}
|
||||||
pthread_cleanup_pop(1); // this should unlock the dacp_conversation_lock);
|
pthread_cleanup_pop(1); // this should unlock the dacp_conversation_lock);
|
||||||
@@ -1302,8 +1295,8 @@ int dacp_set_volume(int32_t vo) {
|
|||||||
int32_t active_speakers = 0;
|
int32_t active_speakers = 0;
|
||||||
for (i = 0; i < speaker_count; i++) {
|
for (i = 0; i < speaker_count; i++) {
|
||||||
if (speaker_info[i].speaker_number == machine_number) {
|
if (speaker_info[i].speaker_number == machine_number) {
|
||||||
debug(2, "Our speaker number found: %" PRId64 " with relative volume %" PRId32 ".", machine_number,
|
debug(2, "Our speaker number found: %" PRId64 " with relative volume %" PRId32 ".",
|
||||||
speaker_info[i].volume);
|
machine_number, speaker_info[i].volume);
|
||||||
}
|
}
|
||||||
if (speaker_info[i].active == 1) {
|
if (speaker_info[i].active == 1) {
|
||||||
active_speakers++;
|
active_speakers++;
|
||||||
|
|||||||
+21
-23
@@ -596,9 +596,9 @@ gboolean notify_convolution_enabled_callback(__attribute__((unused)) ShairportSy
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_CONVOLUTION
|
#ifdef CONFIG_CONVOLUTION
|
||||||
gboolean notify_convolution_maximum_length_in_seconds_callback(ShairportSync *skeleton,
|
gboolean
|
||||||
__attribute__((unused))
|
notify_convolution_maximum_length_in_seconds_callback(ShairportSync *skeleton,
|
||||||
gpointer user_data) {
|
__attribute__((unused)) gpointer user_data) {
|
||||||
|
|
||||||
gdouble th = shairport_sync_get_convolution_maximum_length_in_seconds(skeleton);
|
gdouble th = shairport_sync_get_convolution_maximum_length_in_seconds(skeleton);
|
||||||
if ((th >= 0.0) && (th <= 15.0)) {
|
if ((th >= 0.0) && (th <= 15.0)) {
|
||||||
@@ -612,10 +612,8 @@ gboolean notify_convolution_maximum_length_in_seconds_callback(ShairportSync *sk
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
gboolean notify_convolution_maximum_length_in_seconds_callback(__attribute__((unused))
|
gboolean notify_convolution_maximum_length_in_seconds_callback(
|
||||||
ShairportSync *skeleton,
|
__attribute__((unused)) ShairportSync *skeleton, __attribute__((unused)) gpointer user_data) {
|
||||||
__attribute__((unused))
|
|
||||||
gpointer user_data) {
|
|
||||||
warn(">> Convolution support is not built in to this build of Shairport Sync.");
|
warn(">> Convolution support is not built in to this build of Shairport Sync.");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -643,9 +641,9 @@ gboolean notify_convolution_gain_callback(__attribute__((unused)) ShairportSync
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_CONVOLUTION
|
#ifdef CONFIG_CONVOLUTION
|
||||||
gboolean notify_convolution_impulse_response_files_callback(ShairportSync *skeleton,
|
gboolean
|
||||||
__attribute__((unused))
|
notify_convolution_impulse_response_files_callback(ShairportSync *skeleton,
|
||||||
gpointer user_data) {
|
__attribute__((unused)) gpointer user_data) {
|
||||||
char *th = (char *)shairport_sync_get_convolution_impulse_response_files(skeleton);
|
char *th = (char *)shairport_sync_get_convolution_impulse_response_files(skeleton);
|
||||||
if (th != NULL) {
|
if (th != NULL) {
|
||||||
debug(1, ">> freeing current configuration impulse response filter files.");
|
debug(1, ">> freeing current configuration impulse response filter files.");
|
||||||
@@ -662,10 +660,9 @@ gboolean notify_convolution_impulse_response_files_callback(ShairportSync *skele
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
gboolean notify_convolution_impulse_response_files_callback(__attribute__((unused))
|
gboolean
|
||||||
ShairportSync *skeleton,
|
notify_convolution_impulse_response_files_callback(__attribute__((unused)) ShairportSync *skeleton,
|
||||||
__attribute__((unused))
|
__attribute__((unused)) gpointer user_data) {
|
||||||
gpointer user_data) {
|
|
||||||
__attribute__((unused)) char *th =
|
__attribute__((unused)) char *th =
|
||||||
(char *)shairport_sync_get_convolution_impulse_response_files(skeleton);
|
(char *)shairport_sync_get_convolution_impulse_response_files(skeleton);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -762,7 +759,8 @@ gboolean notify_alacdecoder_callback(ShairportSync *skeleton,
|
|||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
if (strcasecmp(th, "ffmpeg") != 0) {
|
if (strcasecmp(th, "ffmpeg") != 0) {
|
||||||
warn(" This request, to set the decoder to \"%s\", is ignored. For AirPlay 2, the FFmpeg decoder is always used.",
|
warn(" This request, to set the decoder to \"%s\", is ignored. For AirPlay 2, the FFmpeg "
|
||||||
|
"decoder is always used.",
|
||||||
th);
|
th);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -879,7 +877,8 @@ gboolean notify_shuffle_callback(ShairportSyncAdvancedRemoteControl *skeleton,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
gboolean notify_shuffle_callback(__attribute__((unused)) ShairportSyncAdvancedRemoteControl *skeleton,
|
gboolean notify_shuffle_callback(__attribute__((unused))
|
||||||
|
ShairportSyncAdvancedRemoteControl *skeleton,
|
||||||
__attribute__((unused)) gpointer user_data) {
|
__attribute__((unused)) gpointer user_data) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -924,7 +923,8 @@ gboolean notify_loop_status_callback(ShairportSyncAdvancedRemoteControl *skeleto
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
gboolean notify_loop_status_callback(__attribute__((unused)) ShairportSyncAdvancedRemoteControl *skeleton,
|
gboolean notify_loop_status_callback(__attribute__((unused))
|
||||||
|
ShairportSyncAdvancedRemoteControl *skeleton,
|
||||||
__attribute__((unused)) gpointer user_data) {
|
__attribute__((unused)) gpointer user_data) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -971,16 +971,14 @@ static gboolean on_handle_remote_command(ShairportSync *skeleton, GDBusMethodInv
|
|||||||
|
|
||||||
static gboolean on_handle_drop_session(ShairportSync *skeleton, GDBusMethodInvocation *invocation,
|
static gboolean on_handle_drop_session(ShairportSync *skeleton, GDBusMethodInvocation *invocation,
|
||||||
__attribute__((unused)) gpointer user_data) {
|
__attribute__((unused)) gpointer user_data) {
|
||||||
release_play_lock(NULL); // stop any current session and don't replace it
|
stop_play(); // stop any current session and don't replace it
|
||||||
shairport_sync_complete_drop_session(skeleton, invocation);
|
shairport_sync_complete_drop_session(skeleton, invocation);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean on_handle_set_frame_position_update_interval(ShairportSync *skeleton,
|
static gboolean on_handle_set_frame_position_update_interval(
|
||||||
GDBusMethodInvocation *invocation,
|
ShairportSync *skeleton, GDBusMethodInvocation *invocation, const gdouble seconds,
|
||||||
const gdouble seconds,
|
__attribute__((unused)) gpointer user_data) {
|
||||||
__attribute__((unused))
|
|
||||||
gpointer user_data) {
|
|
||||||
debug(1, ">> set frame position update interval to %.6f.", seconds);
|
debug(1, ">> set frame position update interval to %.6f.", seconds);
|
||||||
config.metadata_progress_interval = seconds;
|
config.metadata_progress_interval = seconds;
|
||||||
shairport_sync_complete_set_frame_position_update_interval(skeleton, invocation);
|
shairport_sync_complete_set_frame_position_update_interval(skeleton, invocation);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
// for generating our own UUIDs
|
// for generating our own UUIDs
|
||||||
#define SHAIRPORT_SYNC_DEVICE_NAMESPACE "01d7c137-6316-455d-a52f-dfb529f26adf"
|
#define SHAIRPORT_SYNC_DEVICE_NAMESPACE "01d7c137-6316-455d-a52f-dfb529f26adf"
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,33 @@ RUN DESTDIR=install make install
|
|||||||
WORKDIR /
|
WORKDIR /
|
||||||
##### SPS END #####
|
##### SPS END #####
|
||||||
|
|
||||||
|
# Shairport Sync Development Environment
|
||||||
|
# This (large) image contains the custom-built FFmpeg library and NQPTP, Avahi, D-Bus, etc., Shairport Sync source and all tools.
|
||||||
|
# When started, D-Bus, Avahi and NQPTP are set to run in the background.
|
||||||
|
# To build it, here is a sample local build instruction:
|
||||||
|
# $ docker build --build-arg SHAIRPORT_SYNC_BRANCH=development --build-arg NQPTP_BRANCH=main --target dev -t shairport-sync-dev -f docker/Dockerfile .
|
||||||
|
# Sample local use (remember to save your changes):
|
||||||
|
# $ docker run -it \
|
||||||
|
# --cap-add=SYS_NICE --net host --device /dev/snd \
|
||||||
|
# -v /etc/shairport-sync.conf:/etc/shairport-sync.conf \
|
||||||
|
# shairport-sync-dev
|
||||||
|
|
||||||
|
##### DEV #####
|
||||||
|
FROM shairport-sync AS dev
|
||||||
|
RUN apk add bash
|
||||||
|
|
||||||
|
RUN addgroup shairport-sync && \
|
||||||
|
adduser -D shairport-sync -G shairport-sync && \
|
||||||
|
addgroup -g 29 docker_audio && \
|
||||||
|
addgroup shairport-sync docker_audio && \
|
||||||
|
addgroup shairport-sync audio && \
|
||||||
|
mkdir -p /run/dbus
|
||||||
|
|
||||||
|
COPY --from=nqptp /nqptp/nqptp /usr/local/bin/nqptp
|
||||||
|
COPY --chmod=755 ./docker/devrun.sh ./devrun.sh
|
||||||
|
ENTRYPOINT ["./devrun.sh"]
|
||||||
|
##### DEV END #####
|
||||||
|
|
||||||
##### STATIC FILES #####
|
##### STATIC FILES #####
|
||||||
FROM scratch AS files
|
FROM scratch AS files
|
||||||
|
|
||||||
|
|||||||
Executable
+36
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# exit if any command returns a non-zero result
|
||||||
|
set -e
|
||||||
|
echo "Shairport Sync Dev Startup ($(date))"
|
||||||
|
if [ -z ${ENABLE_AVAHI+x} ] || [ $ENABLE_AVAHI -eq 1 ]; then
|
||||||
|
rm -rf /run/dbus/dbus.pid
|
||||||
|
rm -rf /run/avahi-daemon/pid
|
||||||
|
dbus-uuidgen --ensure
|
||||||
|
dbus-daemon --system
|
||||||
|
avahi-daemon --daemonize --no-chroot
|
||||||
|
fi
|
||||||
|
# Don't launch NQPTP if classic only
|
||||||
|
SERVICE_TYPE=""
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--service-type=classic|--service-type=airplay1)
|
||||||
|
SERVICE_TYPE="${arg#--service-type=}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [ -z "$SERVICE_TYPE" ]; then
|
||||||
|
# not looking for Classic aka AirPlay 1 so start NQPTP for AirPlay 2
|
||||||
|
echo "Starting NQPTP ($(date))"
|
||||||
|
(/usr/local/bin/nqptp > /dev/null 2>&1) &
|
||||||
|
fi
|
||||||
|
while [ ! -f /var/run/avahi-daemon/pid ]; do
|
||||||
|
echo "Warning: avahi is not running, sleeping for 5 seconds before checking again"
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
# for PipeWire
|
||||||
|
export XDG_RUNTIME_DIR=/tmp
|
||||||
|
# for PulseAudio
|
||||||
|
export PULSE_SERVER=unix:/tmp/pulseaudio.socket
|
||||||
|
export PULSE_COOKIE=/tmp/pulseaudio.cookie
|
||||||
|
echo "Finished startup tasks ($(date)), starting bash."
|
||||||
|
exec /bin/bash
|
||||||
+15
-1
@@ -15,9 +15,23 @@ if [ -z ${ENABLE_AVAHI+x} ] || [ $ENABLE_AVAHI -eq 1 ]; then
|
|||||||
avahi-daemon --daemonize --no-chroot
|
avahi-daemon --daemonize --no-chroot
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting NQPTP ($(date))"
|
# Don't launch NQPTP if it classic only
|
||||||
|
|
||||||
|
SERVICE_TYPE=""
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--service-type=classic|--service-type=airplay1)
|
||||||
|
SERVICE_TYPE="${arg#--service-type=}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$SERVICE_TYPE" ]; then
|
||||||
|
# not looking for Classic aka AirPlay 1 so start NQPTP for AirPlay 2
|
||||||
|
echo "Starting NQPTP ($(date))"
|
||||||
(/usr/local/bin/nqptp > /dev/null 2>&1) &
|
(/usr/local/bin/nqptp > /dev/null 2>&1) &
|
||||||
|
fi
|
||||||
|
|
||||||
while [ ! -f /var/run/avahi-daemon/pid ]; do
|
while [ ! -f /var/run/avahi-daemon/pid ]; do
|
||||||
echo "Warning: avahi is not running, sleeping for 5 seconds before trying to start shairport-sync"
|
echo "Warning: avahi is not running, sleeping for 5 seconds before trying to start shairport-sync"
|
||||||
|
|||||||
@@ -39,7 +39,9 @@
|
|||||||
<opt>[-a </opt><arg>service-name</arg><opt> | --name=</opt><arg>service-name</arg><opt>]</opt>
|
<opt>[-a </opt><arg>service-name</arg><opt> | --name=</opt><arg>service-name</arg><opt>]</opt>
|
||||||
<opt>[-B </opt><arg>command</arg><opt> | --onstart=</opt><arg>command</arg><opt>]</opt>
|
<opt>[-B </opt><arg>command</arg><opt> | --onstart=</opt><arg>command</arg><opt>]</opt>
|
||||||
<opt>[-c </opt><arg>configurationfile</arg><opt> | --configfile=</opt><arg>configurationfile</arg><opt>]</opt>
|
<opt>[-c </opt><arg>configurationfile</arg><opt> | --configfile=</opt><arg>configurationfile</arg><opt>]</opt>
|
||||||
|
<opt>[--classic-airplay-only]</opt>
|
||||||
<opt>[-d | --daemon]</opt>
|
<opt>[-d | --daemon]</opt>
|
||||||
|
<opt>[--dbus-default-message-bus=</opt><arg>bus</arg><opt>]</opt>
|
||||||
<opt>[-E </opt><arg>command</arg><opt> | --onstop=</opt><arg>command</arg><opt>]</opt>
|
<opt>[-E </opt><arg>command</arg><opt> | --onstop=</opt><arg>command</arg><opt>]</opt>
|
||||||
<opt>[-g | --get-cover-art]</opt>
|
<opt>[-g | --get-cover-art]</opt>
|
||||||
<opt>[-j | --justDaemoniseNoPIDFile]</opt>
|
<opt>[-j | --justDaemoniseNoPIDFile]</opt>
|
||||||
@@ -203,6 +205,15 @@
|
|||||||
</p></optdesc>
|
</p></optdesc>
|
||||||
</option>
|
</option>
|
||||||
|
|
||||||
|
<option>
|
||||||
|
<p><opt>--dbus-default-message-bus=</opt><arg>bus</arg></p>
|
||||||
|
<optdesc><p>
|
||||||
|
Use the <arg>bus</arg> specified for the native D-Bus and MPRIS interfaces.
|
||||||
|
The <arg>bus</arg> must be <opt>system</opt> or <opt>session</opt>. This option is
|
||||||
|
only available if Shairport Sync is built with the D-Bus or MPRIS interface.
|
||||||
|
</p></optdesc>
|
||||||
|
</option>
|
||||||
|
|
||||||
<option>
|
<option>
|
||||||
<p><opt>-E </opt><arg>program</arg><opt> | --on-stop=</opt><arg>program</arg></p>
|
<p><opt>-E </opt><arg>program</arg><opt> | --on-stop=</opt><arg>program</arg></p>
|
||||||
<optdesc><p>
|
<optdesc><p>
|
||||||
@@ -350,6 +361,23 @@
|
|||||||
</p></optdesc>
|
</p></optdesc>
|
||||||
</option>
|
</option>
|
||||||
|
|
||||||
|
<option>
|
||||||
|
<p><opt>--service-type</opt></p>
|
||||||
|
<optdesc><p>
|
||||||
|
On an AirPlay-2-capable Shairport Sync, if you need offer only the older
|
||||||
|
"classic" AirPlay (sometimes called AirPlay 1) service, set
|
||||||
|
<opt>--service-type=classic</opt>.
|
||||||
|
A potential use of this would be for Apple Music on Windows, which is not compatible
|
||||||
|
with the AirPlay 2 service offered by Shairport Sync,
|
||||||
|
but which is compatible with the classic-only service.
|
||||||
|
To offer AirPlay 2 service only, set <opt>--service-type=airplay2</opt> (note that this
|
||||||
|
requires NQPTP).
|
||||||
|
Set <opt>--service-type=auto</opt> to allow Shairport Sync to choose AirPlay 2
|
||||||
|
service if NQPTP is present or classic AirPlay service if not, with
|
||||||
|
"(Classic)" appended to the default service name.
|
||||||
|
</p></optdesc>
|
||||||
|
</option>
|
||||||
|
|
||||||
<option>
|
<option>
|
||||||
<p><opt>--statistics</opt></p>
|
<p><opt>--statistics</opt></p>
|
||||||
<optdesc><p>
|
<optdesc><p>
|
||||||
@@ -365,11 +393,13 @@
|
|||||||
process of adding or removing frames of audio to or from the
|
process of adding or removing frames of audio to or from the
|
||||||
stream sent to the output device in order to keep it synchronised
|
stream sent to the output device in order to keep it synchronised
|
||||||
with the player.
|
with the player.
|
||||||
The <opt>basic</opt> mode is normally almost completely inaudible.
|
The <opt>vernier</opt> mode is normally almost completely inaudible and suitable for low-powered devices.
|
||||||
The alternative mode, <opt>soxr</opt>, is even less obtrusive but
|
An alternative mode, <opt>soxr</opt>, is less obtrusive but
|
||||||
requires much more processing power. For this mode, support for
|
requires much more processing power. For this mode, support for
|
||||||
<opt>libsoxr</opt>, the SoX Resampler Library, must be selected when
|
<opt>libsoxr</opt>, the SoX Resampler Library, must be selected when
|
||||||
<opt>shairport-sync</opt> is built.
|
<opt>shairport-sync</opt> is built.
|
||||||
|
The <opt>basic</opt> mode is also suitable for low-powered device,
|
||||||
|
but <opt>vernier</opt> is better.
|
||||||
|
|
||||||
The default setting, <opt>auto</opt>, allows Shairport Sync to choose
|
The default setting, <opt>auto</opt>, allows Shairport Sync to choose
|
||||||
<opt>soxr</opt> mode if the system is powerful enough.
|
<opt>soxr</opt> mode if the system is powerful enough.
|
||||||
@@ -485,6 +515,10 @@
|
|||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section name="Note">
|
||||||
|
<p>The <opt>dacquery</opt> utility (<url href="https://github.com/mikebrady/dacquery"/>) might be useful for discovering the properties of your system's DACs.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section name="Credits">
|
<section name="Credits">
|
||||||
<p>Mike Brady (<url href="https://github.com/mikebrady"/>) developed Shairport Sync from Shairport by James Wah (<url href="https://github.com/abrasive"/>).</p>
|
<p>Mike Brady (<url href="https://github.com/mikebrady"/>) developed Shairport Sync from Shairport by James Wah (<url href="https://github.com/abrasive"/>).</p>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
+2
-3
@@ -91,8 +91,7 @@ static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIn
|
|||||||
const char *name, const char *type, const char *domain,
|
const char *name, const char *type, const char *domain,
|
||||||
__attribute__((unused)) const char *host_name,
|
__attribute__((unused)) const char *host_name,
|
||||||
#if defined(CONFIG_METADATA) || defined(CONFIG_DACP_CLIENT)
|
#if defined(CONFIG_METADATA) || defined(CONFIG_DACP_CLIENT)
|
||||||
__attribute__((unused)) const AvahiAddress *address,
|
__attribute__((unused)) const AvahiAddress *address, uint16_t lport,
|
||||||
uint16_t lport,
|
|
||||||
#else
|
#else
|
||||||
__attribute__((unused)) const AvahiAddress *address,
|
__attribute__((unused)) const AvahiAddress *address,
|
||||||
__attribute__((unused)) uint16_t lport,
|
__attribute__((unused)) uint16_t lport,
|
||||||
@@ -120,7 +119,7 @@ static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIn
|
|||||||
while (*dacpid == '0')
|
while (*dacpid == '0')
|
||||||
dacpid++; // skip any leading zeroes
|
dacpid++; // skip any leading zeroes
|
||||||
if (strcmp(dacpid, dbs->dacp_id) == 0) {
|
if (strcmp(dacpid, dbs->dacp_id) == 0) {
|
||||||
debug(1, "resolve_callback: client dacp_id \"%s\" dacp port: %u.", dbs->dacp_id, lport);
|
debug(4, "resolve_callback: client dacp_id \"%s\" dacp port: %u.", dbs->dacp_id, lport);
|
||||||
#ifdef CONFIG_DACP_CLIENT
|
#ifdef CONFIG_DACP_CLIENT
|
||||||
dacp_monitor_port_update_callback(dacpid, lport);
|
dacp_monitor_port_update_callback(dacpid, lport);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+10
-15
@@ -25,15 +25,14 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "pc_queue.h"
|
#include "pc_queue.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA_PIPE
|
#ifdef CONFIG_METADATA_PIPE
|
||||||
#include "pipe.h"
|
#include "pipe.h"
|
||||||
@@ -51,7 +50,6 @@
|
|||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Metadata is not used by shairport-sync.
|
// Metadata is not used by shairport-sync.
|
||||||
// Instead we send all metadata to a fifo pipe, so that other apps can listen to
|
// Instead we send all metadata to a fifo pipe, so that other apps can listen to
|
||||||
// the pipe and use the metadata.
|
// the pipe and use the metadata.
|
||||||
@@ -202,7 +200,6 @@ void metadata_stop(void) {
|
|||||||
#ifdef CONFIG_METADATA_PIPE
|
#ifdef CONFIG_METADATA_PIPE
|
||||||
metadata_pipe_queue_stop();
|
metadata_pipe_queue_stop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,16 +256,17 @@ int send_metadata_to_queue(pc_queue *queue, const uint32_t type, const uint32_t
|
|||||||
if (pack.carrier) {
|
if (pack.carrier) {
|
||||||
if (rc == EWOULDBLOCK)
|
if (rc == EWOULDBLOCK)
|
||||||
debug(2,
|
debug(2,
|
||||||
"metadata queue \"%s\" full, dropping message item: type %x, code %x, data %" PRIxPTR ", "
|
"metadata queue \"%s\" full, dropping message item: type %x, code %x, data %" PRIxPTR
|
||||||
|
", "
|
||||||
"length %u, message %d.",
|
"length %u, message %d.",
|
||||||
queue->name, pack.type, pack.code, (uintptr_t)pack.data, pack.length,
|
queue->name, pack.type, pack.code, (uintptr_t)pack.data, pack.length,
|
||||||
pack.carrier->index_number);
|
pack.carrier->index_number);
|
||||||
msg_free(&pack.carrier);
|
msg_free(&pack.carrier);
|
||||||
} else {
|
} else {
|
||||||
if (rc == EWOULDBLOCK)
|
if (rc == EWOULDBLOCK)
|
||||||
debug(
|
debug(2,
|
||||||
2,
|
"metadata queue \"%s\" full, dropping data item: type %x, code %x, data %" PRIxPTR
|
||||||
"metadata queue \"%s\" full, dropping data item: type %x, code %x, data %" PRIxPTR ", length %u.",
|
", length %u.",
|
||||||
queue->name, pack.type, pack.code, (uintptr_t)pack.data, pack.length);
|
queue->name, pack.type, pack.code, (uintptr_t)pack.data, pack.length);
|
||||||
if (pack.data)
|
if (pack.data)
|
||||||
free(pack.data);
|
free(pack.data);
|
||||||
@@ -287,8 +285,7 @@ int send_metadata(const uint32_t type, const uint32_t code, const char *data, co
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA_MULTICAST
|
#ifdef CONFIG_METADATA_MULTICAST
|
||||||
rc =
|
rc = send_metadata_to_multicast_queue(type, code, data, length, carrier, block);
|
||||||
send_metadata_to_multicast_queue(type, code, data, length, carrier, block);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA_HUB
|
#ifdef CONFIG_METADATA_HUB
|
||||||
@@ -298,7 +295,6 @@ int send_metadata(const uint32_t type, const uint32_t code, const char *data, co
|
|||||||
#ifdef CONFIG_MQTT
|
#ifdef CONFIG_MQTT
|
||||||
rc = send_metadata_to_mqtt_queue(type, code, data, length, carrier, block);
|
rc = send_metadata_to_mqtt_queue(type, code, data, length, carrier, block);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -307,4 +303,3 @@ int send_ssnc_metadata(const uint32_t code, const char *data, const uint32_t len
|
|||||||
const int block) {
|
const int block) {
|
||||||
return send_metadata('ssnc', code, data, length, NULL, block);
|
return send_metadata('ssnc', code, data, length, NULL, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../rtsp.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "../rtsp.h"
|
|
||||||
#include "pc_queue.h"
|
#include "pc_queue.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
@@ -21,7 +21,6 @@ void metadata_pack_cleanup_function(void *arg);
|
|||||||
void metadata_init(void);
|
void metadata_init(void);
|
||||||
void metadata_stop(void);
|
void metadata_stop(void);
|
||||||
|
|
||||||
|
|
||||||
int send_metadata_to_queue(pc_queue *queue, const uint32_t type, const uint32_t code,
|
int send_metadata_to_queue(pc_queue *queue, const uint32_t type, const uint32_t code,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const char *data, const uint32_t length, rtsp_message *carrier,
|
||||||
int block);
|
int block);
|
||||||
|
|||||||
+3
-4
@@ -43,10 +43,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "core.h"
|
||||||
#include "dacp.h"
|
#include "dacp.h"
|
||||||
#include "hub.h"
|
#include "hub.h"
|
||||||
#include "pc_queue.h"
|
#include "pc_queue.h"
|
||||||
#include "core.h"
|
|
||||||
|
|
||||||
#ifdef CONFIG_MBEDTLS
|
#ifdef CONFIG_MBEDTLS
|
||||||
#include <mbedtls/md5.h>
|
#include <mbedtls/md5.h>
|
||||||
@@ -766,8 +766,7 @@ void metadata_hub_queue_stop() {
|
|||||||
// debug(2, "metadata stop hub done.");
|
// debug(2, "metadata stop hub done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_metadata_to_hub_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_hub_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block) {
|
||||||
int block) {
|
|
||||||
return send_metadata_to_queue(&metadata_hub_queue, type, code, data, length, carrier, block);
|
return send_metadata_to_queue(&metadata_hub_queue, type, code, data, length, carrier, block);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -194,7 +194,5 @@ void _metadata_hub_read_epilog(const char *filename, const int linenumber);
|
|||||||
// metadata queue stuff
|
// metadata queue stuff
|
||||||
void metadata_hub_queue_init();
|
void metadata_hub_queue_init();
|
||||||
void metadata_hub_queue_stop();
|
void metadata_hub_queue_stop();
|
||||||
int send_metadata_to_hub_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_hub_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block);
|
||||||
int block);
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
// A special sub-protocol is used for sending large data items over UDP
|
// A special sub-protocol is used for sending large data items over UDP
|
||||||
// If the payload exceeded 4 MB, it is chunked using the following format:
|
// If the payload exceeded 4 MB, it is chunked using the following format:
|
||||||
// "ssnc", "chnk", packet_ix, packet_counts, packet_tag, packet_type, chunked_data.
|
// "ssnc", "chnk", packet_ix, packet_counts, packet_tag, packet_type, chunked_data.
|
||||||
@@ -20,10 +19,10 @@ pc_queue metadata_multicast_queue;
|
|||||||
metadata_package metadata_multicast_queue_items[metadata_multicast_queue_size];
|
metadata_package metadata_multicast_queue_items[metadata_multicast_queue_size];
|
||||||
pthread_t metadata_multicast_thread;
|
pthread_t metadata_multicast_thread;
|
||||||
|
|
||||||
int send_metadata_to_multicast_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_multicast_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block) {
|
||||||
int block) {
|
return send_metadata_to_queue(&metadata_multicast_queue, type, code, data, length, carrier,
|
||||||
return send_metadata_to_queue(&metadata_multicast_queue, type, code, data, length, carrier, block);
|
block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void metadata_create_multicast_socket(void) {
|
void metadata_create_multicast_socket(void) {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
void metadata_multicast_queue_init();
|
void metadata_multicast_queue_init();
|
||||||
void metadata_multicast_queue_stop();
|
void metadata_multicast_queue_stop();
|
||||||
int send_metadata_to_multicast_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_multicast_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block);
|
||||||
int block);
|
|
||||||
+1
-2
@@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
#include "pc_queue.h"
|
#include "pc_queue.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
void pc_queue_init(pc_queue *the_queue, char *items, size_t item_size, uint32_t number_of_items,
|
void pc_queue_init(pc_queue *the_queue, char *items, size_t item_size, uint32_t number_of_items,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
@@ -169,4 +169,3 @@ int pc_queue_get_item(pc_queue *the_queue, void *the_stuff) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -2,10 +2,10 @@
|
|||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "pc_queue.h"
|
#include "pc_queue.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
static int fd = -1; // the pipe file descriptor
|
static int fd = -1; // the pipe file descriptor
|
||||||
|
|
||||||
@@ -152,8 +152,8 @@ void metadata_pipe_queue_init() {
|
|||||||
if ((fd == -1) && (errno != ENXIO)) {
|
if ((fd == -1) && (errno != ENXIO)) {
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
|
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
|
||||||
debug(1, "metadata_init -- error %d (\"%s\") opening pipe: \"%s\".", errno,
|
debug(1, "metadata_init -- error %d (\"%s\") opening pipe: \"%s\".", errno, (char *)errorstring,
|
||||||
(char *)errorstring, path);
|
path);
|
||||||
warn("can not open metadata pipe -- error %d (\"%s\") opening pipe: \"%s\".", errno,
|
warn("can not open metadata pipe -- error %d (\"%s\") opening pipe: \"%s\".", errno,
|
||||||
(char *)errorstring, path);
|
(char *)errorstring, path);
|
||||||
}
|
}
|
||||||
@@ -179,8 +179,7 @@ void metadata_pipe_queue_stop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_metadata_to_pipe_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_pipe_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block) {
|
||||||
int block) {
|
|
||||||
return send_metadata_to_queue(&metadata_queue, type, code, data, length, carrier, block);
|
return send_metadata_to_queue(&metadata_queue, type, code, data, length, carrier, block);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
void metadata_pipe_queue_init();
|
void metadata_pipe_queue_init();
|
||||||
void metadata_pipe_queue_stop();
|
void metadata_pipe_queue_stop();
|
||||||
int send_metadata_to_pipe_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_pipe_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block);
|
||||||
int block);
|
|
||||||
@@ -8,14 +8,16 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
|
#include "utilities/string_utilities.h"
|
||||||
|
|
||||||
#include "rtp.h"
|
#include "rtp.h"
|
||||||
|
|
||||||
#ifdef CONFIG_DACP_CLIENT
|
#ifdef CONFIG_DACP_CLIENT
|
||||||
#include "dacp.h"
|
#include "dacp.h"
|
||||||
#endif
|
#endif
|
||||||
#include "metadata/hub.h"
|
|
||||||
#include "metadata/core.h"
|
#include "metadata/core.h"
|
||||||
|
#include "metadata/hub.h"
|
||||||
#include "metadata/pc_queue.h"
|
#include "metadata/pc_queue.h"
|
||||||
|
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
@@ -79,7 +81,7 @@ void on_message(__attribute__((unused)) struct mosquitto *mosq,
|
|||||||
debug(2, "[MQTT]: Received Recognized Command: %s\n", commands[it]);
|
debug(2, "[MQTT]: Received Recognized Command: %s\n", commands[it]);
|
||||||
if (strcmp(commands[it], "disconnect") == 0) {
|
if (strcmp(commands[it], "disconnect") == 0) {
|
||||||
debug(2, "[MQTT]: Disconnect Command: %s\n", commands[it]);
|
debug(2, "[MQTT]: Disconnect Command: %s\n", commands[it]);
|
||||||
release_play_lock(NULL); // stop any current session and don't replace it
|
stop_play(); // stop any current session and don't replace it
|
||||||
} else {
|
} else {
|
||||||
debug(2, "[MQTT]: DACP Command: %s\n", commands[it]);
|
debug(2, "[MQTT]: DACP Command: %s\n", commands[it]);
|
||||||
#ifdef CONFIG_DACP_CLIENT
|
#ifdef CONFIG_DACP_CLIENT
|
||||||
@@ -213,8 +215,8 @@ void send_autodiscovery_messages(struct mosquitto *mosq) {
|
|||||||
|
|
||||||
const char *entity_type = is_binary_sensor ? "binary_sensor" : "sensor";
|
const char *entity_type = is_binary_sensor ? "binary_sensor" : "sensor";
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic), "%s/%s/%s_%s/%s/config", autodiscovery_prefix,
|
snprintf(topic, sizeof(topic), "%s/%s/%s_%s/%s/config", autodiscovery_prefix, entity_type,
|
||||||
entity_type, model, device_id_no_colons, sensors[i]);
|
model, device_id_no_colons, sensors[i]);
|
||||||
|
|
||||||
snprintf(id_string, sizeof(id_string), "%s_%s_%s", model, device_name, sensors[i]);
|
snprintf(id_string, sizeof(id_string), "%s_%s_%s", model, device_name, sensors[i]);
|
||||||
|
|
||||||
@@ -268,8 +270,7 @@ void mqtt_publish(char *topic, char *data_in, uint32_t length_in) {
|
|||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
if ((rc = mosquitto_publish(global_mosq, NULL, fulltopic, length, data, 0,
|
if ((rc = mosquitto_publish(global_mosq, NULL, fulltopic, length, data, 0,
|
||||||
config.mqtt_publish_retain)) !=
|
config.mqtt_publish_retain)) != MOSQ_ERR_SUCCESS) {
|
||||||
MOSQ_ERR_SUCCESS) {
|
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case MOSQ_ERR_NO_CONN:
|
case MOSQ_ERR_NO_CONN:
|
||||||
debug(1, "[MQTT]: Publish failed: not connected to broker");
|
debug(1, "[MQTT]: Publish failed: not connected to broker");
|
||||||
@@ -509,9 +510,7 @@ void metadata_mqtt_queue_stop() {
|
|||||||
pc_queue_delete(&metadata_mqtt_queue);
|
pc_queue_delete(&metadata_mqtt_queue);
|
||||||
// debug(2, "metadata stop mqtt done.");
|
// debug(2, "metadata stop mqtt done.");
|
||||||
}
|
}
|
||||||
int send_metadata_to_mqtt_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_mqtt_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block) {
|
||||||
int block) {
|
|
||||||
return send_metadata_to_queue(&metadata_mqtt_queue, type, code, data, length, carrier, block);
|
return send_metadata_to_queue(&metadata_mqtt_queue, type, code, data, length, carrier, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ void _cb_log(struct mosquitto *mosq, void *userdata, int level, const char *str)
|
|||||||
|
|
||||||
void metadata_mqtt_queue_init();
|
void metadata_mqtt_queue_init();
|
||||||
void metadata_mqtt_queue_stop();
|
void metadata_mqtt_queue_stop();
|
||||||
int send_metadata_to_mqtt_queue(const uint32_t type, const uint32_t code,
|
int send_metadata_to_mqtt_queue(const uint32_t type, const uint32_t code, const char *data,
|
||||||
const char *data, const uint32_t length, rtsp_message *carrier,
|
const uint32_t length, rtsp_message *carrier, int block);
|
||||||
int block);
|
|
||||||
#endif /* #ifndef MQTT_H */
|
#endif /* #ifndef MQTT_H */
|
||||||
|
|||||||
@@ -705,7 +705,8 @@ int setup_software_resampler(rtsp_conn_info *conn, ssrc_t ssrc) {
|
|||||||
av_opt_set_int(swr, "in_channel_layout", input_layout, 0);
|
av_opt_set_int(swr, "in_channel_layout", input_layout, 0);
|
||||||
if (config.mixdown_enable != 0) {
|
if (config.mixdown_enable != 0) {
|
||||||
if (config.mixdown_channel_layout == 0) {
|
if (config.mixdown_channel_layout == 0) {
|
||||||
if (CHANNELS_FROM_ENCODED_FORMAT(output_configuration) < av_get_channel_layout_nb_channels(input_layout)) {
|
if ((signed)CHANNELS_FROM_ENCODED_FORMAT(output_configuration) <
|
||||||
|
(av_get_channel_layout_nb_channels(input_layout)) {
|
||||||
output_layout =
|
output_layout =
|
||||||
av_get_default_channel_layout(CHANNELS_FROM_ENCODED_FORMAT(output_configuration));
|
av_get_default_channel_layout(CHANNELS_FROM_ENCODED_FORMAT(output_configuration));
|
||||||
} // else leave output_layout as it was: the sames as the input_layout.
|
} // else leave output_layout as it was: the sames as the input_layout.
|
||||||
@@ -1035,17 +1036,26 @@ int setup_software_resampler(rtsp_conn_info *conn, ssrc_t ssrc) {
|
|||||||
return response; // 0 if everything is okay
|
return response; // 0 if everything is okay
|
||||||
}
|
}
|
||||||
void prepare_decoding_chain(rtsp_conn_info *conn, ssrc_t ssrc) {
|
void prepare_decoding_chain(rtsp_conn_info *conn, ssrc_t ssrc) {
|
||||||
if ((ssrc_is_recognised(ssrc)) && (ssrc != conn->incoming_ssrc)) {
|
if ((ssrc != SSRC_NONE) && (ssrc != conn->incoming_ssrc) && (ssrc_is_recognised(ssrc) != 0)) {
|
||||||
|
// conn->incoming_ssrc will be SSRC_NONE only before the first valid encoding is found
|
||||||
if ((config.statistics_requested != 0) && (ssrc != SSRC_NONE) &&
|
if ((config.statistics_requested) && (conn->incoming_ssrc != SSRC_NONE))
|
||||||
(conn->incoming_ssrc != SSRC_NONE)) {
|
inform("Connection %d: Incoming Audio Encoding is switching to: \"%s\".",
|
||||||
debug(2, "Connection %d: incoming audio switching to \"%s\".", conn->connection_number,
|
conn->connection_number, get_ssrc_name(ssrc));
|
||||||
get_ssrc_name(ssrc));
|
// conn->incoming_ssrc = payload_ssrc;
|
||||||
#ifdef CONFIG_METADATA
|
#ifdef CONFIG_METADATA
|
||||||
send_ssnc_metadata('sdsc', get_ssrc_name(ssrc), strlen(get_ssrc_name(ssrc)), 1);
|
send_ssnc_metadata('sdsc', get_ssrc_name(ssrc), strlen(get_ssrc_name(ssrc)), 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((ssrc_is_recognised(ssrc)) && (ssrc != conn->incoming_ssrc)) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
if ((config.statistics_requested != 0) && (ssrc != SSRC_NONE) &&
|
||||||
|
(conn->incoming_ssrc != SSRC_NONE)) {
|
||||||
|
debug(2, "Connection %d: incoming audio switching to \"%s\".", conn->connection_number,
|
||||||
|
get_ssrc_name(ssrc));
|
||||||
|
}
|
||||||
|
*/
|
||||||
// the ssrc of the incoming packet is different to the ssrc of the decoding chain
|
// the ssrc of the incoming packet is different to the ssrc of the decoding chain
|
||||||
// so the decoding chain must be rebuilt
|
// so the decoding chain must be rebuilt
|
||||||
|
|
||||||
@@ -1071,7 +1081,8 @@ void prepare_decoding_chain(rtsp_conn_info *conn, ssrc_t ssrc) {
|
|||||||
conn->codec = avcodec_find_decoder(AV_CODEC_ID_AAC);
|
conn->codec = avcodec_find_decoder(AV_CODEC_ID_AAC);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("Connection %d: can't find a suitable codec for SSRC: %s", conn->connection_number, get_ssrc_name(ssrc));
|
die("Connection %d: can't find a suitable codec for SSRC: %s", conn->connection_number,
|
||||||
|
get_ssrc_name(ssrc));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1090,7 +1101,8 @@ void prepare_decoding_chain(rtsp_conn_info *conn, ssrc_t ssrc) {
|
|||||||
alac_ffmpeg_magic_cookie *extradata =
|
alac_ffmpeg_magic_cookie *extradata =
|
||||||
malloc(sizeof(alac_ffmpeg_magic_cookie)); // might not use it
|
malloc(sizeof(alac_ffmpeg_magic_cookie)); // might not use it
|
||||||
if (extradata == NULL)
|
if (extradata == NULL)
|
||||||
die("connection %d: could not allocate memory for a magic cookie.", conn->connection_number);
|
die("connection %d: could not allocate memory for a magic cookie.",
|
||||||
|
conn->connection_number);
|
||||||
// creata a magic cookie preceded by the 12-byte "atom" (?) expected by FFMPEG (?)
|
// creata a magic cookie preceded by the 12-byte "atom" (?) expected by FFMPEG (?)
|
||||||
memset(extradata, 0, sizeof(alac_ffmpeg_magic_cookie));
|
memset(extradata, 0, sizeof(alac_ffmpeg_magic_cookie));
|
||||||
extradata->cookie_size = htonl(sizeof(alac_ffmpeg_magic_cookie));
|
extradata->cookie_size = htonl(sizeof(alac_ffmpeg_magic_cookie));
|
||||||
@@ -1126,7 +1138,8 @@ void prepare_decoding_chain(rtsp_conn_info *conn, ssrc_t ssrc) {
|
|||||||
pthread_setcancelstate(oldState, NULL);
|
pthread_setcancelstate(oldState, NULL);
|
||||||
|
|
||||||
conn->input_rate = get_ssrc_rate(ssrc);
|
conn->input_rate = get_ssrc_rate(ssrc);
|
||||||
debug(2, "Connection %d: set conn->input_rate: %u.", conn->connection_number, conn->input_rate);
|
debug(2, "Connection %d: set conn->input_rate: %u.", conn->connection_number,
|
||||||
|
conn->input_rate);
|
||||||
if ((ssrc == ALAC_48000_S24_2) || (ssrc == ALAC_44100_S16_2)) {
|
if ((ssrc == ALAC_48000_S24_2) || (ssrc == ALAC_44100_S16_2)) {
|
||||||
conn->frames_per_packet = 352;
|
conn->frames_per_packet = 352;
|
||||||
} else {
|
} else {
|
||||||
@@ -1583,7 +1596,6 @@ uint32_t player_put_packet(uint32_t ssrc, seq_t seqno, uint32_t actual_timestamp
|
|||||||
} else if (config.decoder_in_use == 1 << decoder_ffmpeg_alac) {
|
} else if (config.decoder_in_use == 1 << decoder_ffmpeg_alac) {
|
||||||
#ifdef CONFIG_FFMPEG
|
#ifdef CONFIG_FFMPEG
|
||||||
prepare_decoding_chain(conn, ALAC_44100_S16_2);
|
prepare_decoding_chain(conn, ALAC_44100_S16_2);
|
||||||
// if (len > 8) {
|
|
||||||
abuf->avframe = block_to_avframe(conn, data_to_use, len);
|
abuf->avframe = block_to_avframe(conn, data_to_use, len);
|
||||||
abuf->ssrc = ALAC_44100_S16_2;
|
abuf->ssrc = ALAC_44100_S16_2;
|
||||||
if (abuf->avframe) {
|
if (abuf->avframe) {
|
||||||
@@ -1597,14 +1609,13 @@ uint32_t player_put_packet(uint32_t ssrc, seq_t seqno, uint32_t actual_timestamp
|
|||||||
av_frame_free(&abuf->avframe);
|
av_frame_free(&abuf->avframe);
|
||||||
abuf->avframe = NULL;
|
abuf->avframe = NULL;
|
||||||
}
|
}
|
||||||
// } else {
|
|
||||||
if (len <= 8) {
|
if (len <= 8) {
|
||||||
debug(1,
|
debug(2,
|
||||||
"Using the FFMPEG ALAC_44100_S16_2 decoder, a short audio packet %u, rtptime %u, of length %zu has been decoded but not discarded. Contents follow:", seqno,
|
"Connection %d, using FFMPEG on an ALAC_44100_S16_2 stream, a short audio packet "
|
||||||
actual_timestamp, len);
|
"%u, rtptime %u, of length %zu has been decoded but not discarded. Contents "
|
||||||
debug_print_buffer(1, data, len);
|
"follow:",
|
||||||
// abuf->length = conn->frames_per_packet;
|
conn->connection_number, seqno, actual_timestamp, len);
|
||||||
// abuf->avframe = NULL;
|
debug_print_buffer(2, data, len);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
debug(1, "FFMPEG support has not been built into this version Shairport Sync!");
|
debug(1, "FFMPEG support has not been built into this version Shairport Sync!");
|
||||||
@@ -1636,7 +1647,6 @@ uint32_t player_put_packet(uint32_t ssrc, seq_t seqno, uint32_t actual_timestamp
|
|||||||
|
|
||||||
prepare_decoding_chain(conn, ssrc); // dynamically set the decoding environment
|
prepare_decoding_chain(conn, ssrc); // dynamically set the decoding environment
|
||||||
|
|
||||||
// if (len > 8) {
|
|
||||||
abuf->avframe = block_to_avframe(conn, data, len);
|
abuf->avframe = block_to_avframe(conn, data, len);
|
||||||
abuf->ssrc = ssrc; // tag the avframe with its specific SSRC
|
abuf->ssrc = ssrc; // tag the avframe with its specific SSRC
|
||||||
if (abuf->avframe) {
|
if (abuf->avframe) {
|
||||||
@@ -1649,14 +1659,13 @@ uint32_t player_put_packet(uint32_t ssrc, seq_t seqno, uint32_t actual_timestamp
|
|||||||
av_frame_free(&abuf->avframe);
|
av_frame_free(&abuf->avframe);
|
||||||
abuf->avframe = NULL;
|
abuf->avframe = NULL;
|
||||||
}
|
}
|
||||||
//} else {
|
|
||||||
if (len <= 8) {
|
if (len <= 8) {
|
||||||
debug(1,
|
debug(2,
|
||||||
"Using an FFMPEG decoder, a short audio packet %u, rtptime %u, of length %zu has been decoded but not discarded. Contents follow:", seqno,
|
"Connection %d: using FFMPEG on a %s stream, a short audio packet %u, rtptime %u, "
|
||||||
actual_timestamp, len);
|
"of length %zu has been decoded but not discarded. Contents follow:",
|
||||||
debug_print_buffer(1, data, len);
|
conn->connection_number, get_ssrc_name(ssrc), seqno, actual_timestamp, len);
|
||||||
// abuf->length = 0;
|
debug_print_buffer(2, data, len);
|
||||||
// abuf->avframe = NULL;
|
|
||||||
}
|
}
|
||||||
abuf->ready = 1;
|
abuf->ready = 1;
|
||||||
abuf->status = 0; // signifying that it was received
|
abuf->status = 0; // signifying that it was received
|
||||||
@@ -2498,11 +2507,11 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn, int resync_requested) {
|
|||||||
1000000000;
|
1000000000;
|
||||||
int64_t exact_frame_gap = gross_frame_gap - dac_delay;
|
int64_t exact_frame_gap = gross_frame_gap - dac_delay;
|
||||||
|
|
||||||
|
|
||||||
debug(4,
|
debug(4,
|
||||||
"Exact frame gap: %" PRId64
|
"Exact frame gap: %" PRId64 ". DAC delay: %ld. Total: %" PRId64
|
||||||
". DAC delay: %ld. Total: %" PRId64 ". First packet timestamp: %u. ",
|
". First packet timestamp: %u. ",
|
||||||
exact_frame_gap, dac_delay, gross_frame_gap, conn->first_packet_timestamp);
|
exact_frame_gap, dac_delay, gross_frame_gap,
|
||||||
|
conn->first_packet_timestamp);
|
||||||
// int64_t frames_needed_to_maintain_desired_buffer =
|
// int64_t frames_needed_to_maintain_desired_buffer =
|
||||||
// (int64_t)(config.audio_backend_buffer_desired_length *
|
// (int64_t)(config.audio_backend_buffer_desired_length *
|
||||||
// config.current_output_configuration->rate) -
|
// config.current_output_configuration->rate) -
|
||||||
@@ -2721,8 +2730,10 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn, int resync_requested) {
|
|||||||
if (wait) {
|
if (wait) {
|
||||||
uint64_t time_to_wait_for_wakeup_ns = 10000000; // default
|
uint64_t time_to_wait_for_wakeup_ns = 10000000; // default
|
||||||
if (conn->input_format_is_valid != 0) {
|
if (conn->input_format_is_valid != 0) {
|
||||||
time_to_wait_for_wakeup_ns = 1000000000 / conn->input_rate; // this is time period of one frame
|
time_to_wait_for_wakeup_ns =
|
||||||
time_to_wait_for_wakeup_ns *= 4 * conn->frames_per_packet; // about 4 * 7 mS for 352 frames per second
|
1000000000 / conn->input_rate; // this is time period of one frame
|
||||||
|
time_to_wait_for_wakeup_ns *=
|
||||||
|
4 * conn->frames_per_packet; // about 4 * 7 mS for 352 frames per second
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef COMPILE_FOR_LINUX_AND_FREEBSD_AND_CYGWIN_AND_OPENBSD
|
#ifdef COMPILE_FOR_LINUX_AND_FREEBSD_AND_CYGWIN_AND_OPENBSD
|
||||||
@@ -2733,7 +2744,8 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn, int resync_requested) {
|
|||||||
struct timespec time_of_wakeup;
|
struct timespec time_of_wakeup;
|
||||||
time_of_wakeup.tv_sec = sec;
|
time_of_wakeup.tv_sec = sec;
|
||||||
time_of_wakeup.tv_nsec = nsec;
|
time_of_wakeup.tv_nsec = nsec;
|
||||||
// debug(1, "wait for up to %f mS or for the next packet...", time_to_wait_for_wakeup_ns * 1E-6);
|
// debug(1, "wait for up to %f mS or for the next packet...", time_to_wait_for_wakeup_ns *
|
||||||
|
// 1E-6);
|
||||||
int rc = pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex,
|
int rc = pthread_cond_timedwait(&conn->flowcontrol, &conn->ab_mutex,
|
||||||
&time_of_wakeup); // this is a pthread cancellation point
|
&time_of_wakeup); // this is a pthread cancellation point
|
||||||
if ((rc != 0) && (rc != ETIMEDOUT))
|
if ((rc != 0) && (rc != ETIMEDOUT))
|
||||||
@@ -2789,8 +2801,8 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn, int resync_requested) {
|
|||||||
debug(2, "setting up software resampler for %s for the first time.",
|
debug(2, "setting up software resampler for %s for the first time.",
|
||||||
get_ssrc_name(curframe->ssrc));
|
get_ssrc_name(curframe->ssrc));
|
||||||
} else {
|
} else {
|
||||||
debug(1, "Connection %d: queued audio buffers switching to \"%s\".", conn->connection_number,
|
debug(2, "Connection %d: queued audio buffers switching to \"%s\".",
|
||||||
get_ssrc_name(curframe->ssrc));
|
conn->connection_number, get_ssrc_name(curframe->ssrc));
|
||||||
clear_software_resampler(conn);
|
clear_software_resampler(conn);
|
||||||
// ask the backend if it can give us its best choice for an ffmpeg configuration:
|
// ask the backend if it can give us its best choice for an ffmpeg configuration:
|
||||||
}
|
}
|
||||||
@@ -3029,8 +3041,8 @@ static int stuff_buffer_vernier(int32_t *inptr, int length, sps_format_t l_outpu
|
|||||||
debug(1,
|
debug(1,
|
||||||
"Can't see how this could ever happen, but "
|
"Can't see how this could ever happen, but "
|
||||||
"current_input_sample_floor_index %" PRId64
|
"current_input_sample_floor_index %" PRId64
|
||||||
" has just stepped outside the frame of %d samples, with stuff %d and current_input_sample_index_fp at %" PRId64 ".%05" PRId64
|
" has just stepped outside the frame of %d samples, with stuff %d and "
|
||||||
".",
|
"current_input_sample_index_fp at %" PRId64 ".%05" PRId64 ".",
|
||||||
current_input_sample_floor_index, length, stuff, current_input_sample_index_int,
|
current_input_sample_floor_index, length, stuff, current_input_sample_index_int,
|
||||||
current_input_sample_index_low);
|
current_input_sample_index_low);
|
||||||
current_input_sample_floor_index = length - 1; // hack
|
current_input_sample_floor_index = length - 1; // hack
|
||||||
@@ -3052,8 +3064,8 @@ static int stuff_buffer_vernier(int32_t *inptr, int length, sps_format_t l_outpu
|
|||||||
debug(1,
|
debug(1,
|
||||||
"Can't see how this could ever happen, but "
|
"Can't see how this could ever happen, but "
|
||||||
"current_input_sample_ceil_index %" PRId64
|
"current_input_sample_ceil_index %" PRId64
|
||||||
" has just stepped outside the frame of %d samples, with stuff %d and current_input_sample_index_fp at %" PRId64
|
" has just stepped outside the frame of %d samples, with stuff %d and "
|
||||||
".%05" PRId64 ".",
|
"current_input_sample_index_fp at %" PRId64 ".%05" PRId64 ".",
|
||||||
current_input_sample_floor_index, length, stuff, current_input_sample_index_int,
|
current_input_sample_floor_index, length, stuff, current_input_sample_index_int,
|
||||||
current_input_sample_index_low);
|
current_input_sample_index_low);
|
||||||
}
|
}
|
||||||
@@ -3314,17 +3326,10 @@ void player_thread_cleanup_handler(void *arg) {
|
|||||||
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
||||||
// debug(1, "Connection %d: player_thread_cleanup_handler start.", conn->connection_number);
|
// debug(1, "Connection %d: player_thread_cleanup_handler start.", conn->connection_number);
|
||||||
|
|
||||||
#ifdef CONFIG_FFMPEG
|
|
||||||
// debug(1, "FFmpeg clearup");
|
|
||||||
clear_software_resampler(conn);
|
|
||||||
clear_decoding_chain(conn);
|
|
||||||
// debug(1, "FFmpeg clearup done");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (config.output->stop) {
|
if (config.output->stop) {
|
||||||
#ifdef CONFIG_FFMPEG
|
#ifdef CONFIG_FFMPEG
|
||||||
if (avflush(conn) > 1)
|
if ((config.decoder_in_use == 1 << decoder_ffmpeg_alac) && (avflush(conn) > 1))
|
||||||
debug(3, "ffmpeg flush at stop!");
|
debug(1, "ffmpeg flush at stop!");
|
||||||
#endif
|
#endif
|
||||||
debug(2, "Connection %d: player: stop the output backend.", conn->connection_number);
|
debug(2, "Connection %d: player: stop the output backend.", conn->connection_number);
|
||||||
config.output->stop();
|
config.output->stop();
|
||||||
@@ -3418,6 +3423,15 @@ void player_thread_cleanup_handler(void *arg) {
|
|||||||
ptp_send_control_message_string("E");
|
ptp_send_control_message_string("E");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FFMPEG
|
||||||
|
if (config.decoder_in_use == 1 << decoder_ffmpeg_alac) {
|
||||||
|
// debug(1, "FFmpeg clearup");
|
||||||
|
clear_software_resampler(conn);
|
||||||
|
clear_decoding_chain(conn);
|
||||||
|
// debug(1, "FFmpeg clearup done");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (conn->outbuf) {
|
if (conn->outbuf) {
|
||||||
free(conn->outbuf);
|
free(conn->outbuf);
|
||||||
conn->outbuf = NULL;
|
conn->outbuf = NULL;
|
||||||
@@ -3512,11 +3526,17 @@ void *player_thread_func(void *arg) {
|
|||||||
init_alac_decoder((int32_t *)&conn->stream.fmtp,
|
init_alac_decoder((int32_t *)&conn->stream.fmtp,
|
||||||
conn); // this sets up incoming rate, bit depth, channels.
|
conn); // this sets up incoming rate, bit depth, channels.
|
||||||
// No pthread cancellation point in here
|
// No pthread cancellation point in here
|
||||||
|
#ifdef CONFIG_METADATA
|
||||||
|
send_ssnc_metadata('sdsc', "ALAC/44100/S16_LE/2", strlen("ALAC/44100/S16_LE/2"), 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_APPLE_ALAC
|
#ifdef CONFIG_APPLE_ALAC
|
||||||
if (config.decoder_in_use == 1 << decoder_apple_alac) {
|
if (config.decoder_in_use == 1 << decoder_apple_alac) {
|
||||||
apple_alac_init(conn->stream.fmtp); // no pthread cancellation point in here
|
apple_alac_init(conn->stream.fmtp); // no pthread cancellation point in here
|
||||||
|
#ifdef CONFIG_METADATA
|
||||||
|
send_ssnc_metadata('sdsc', "ALAC/44100/S16_LE/2", strlen("ALAC/44100/S16_LE/2"), 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -4145,7 +4165,7 @@ void *player_thread_func(void *arg) {
|
|||||||
send_ssnc_stream_description("Classic", get_ssrc_name(conn->incoming_ssrc));
|
send_ssnc_stream_description("Classic", get_ssrc_name(conn->incoming_ssrc));
|
||||||
#endif
|
#endif
|
||||||
if (config.statistics_requested)
|
if (config.statistics_requested)
|
||||||
inform("Connection %d: Classic AirPlay (\"AirPlay 1\") Compatible playback. "
|
inform("Connection %d: Classic AirPlay (\"AirPlay 1\") playback. "
|
||||||
"Input format: %s. Output format: %s.",
|
"Input format: %s. Output format: %s.",
|
||||||
conn->connection_number, get_ssrc_name(conn->incoming_ssrc),
|
conn->connection_number, get_ssrc_name(conn->incoming_ssrc),
|
||||||
short_description);
|
short_description);
|
||||||
@@ -4369,10 +4389,14 @@ void *player_thread_func(void *arg) {
|
|||||||
if (inframe->timestamp_gap < 0) {
|
if (inframe->timestamp_gap < 0) {
|
||||||
gap_to_fix = -inframe->timestamp_gap; // this is frames at the input rate
|
gap_to_fix = -inframe->timestamp_gap; // this is frames at the input rate
|
||||||
int64_t gap_to_fix_ns = (gap_to_fix * 1000000000) / conn->input_rate;
|
int64_t gap_to_fix_ns = (gap_to_fix * 1000000000) / conn->input_rate;
|
||||||
gap_to_fix = (gap_to_fix_ns *
|
gap_to_fix = (gap_to_fix_ns * RATE_FROM_ENCODED_FORMAT(
|
||||||
RATE_FROM_ENCODED_FORMAT(config.current_output_configuration) + 1000000000/2) /
|
config.current_output_configuration) +
|
||||||
|
1000000000 / 2) /
|
||||||
1000000000; // this is frames at the output rate
|
1000000000; // this is frames at the output rate
|
||||||
debug(4, "gap_to_fix: %u frames at input rate, %" PRId64 " frames at output rate.", -inframe->timestamp_gap, gap_to_fix);
|
debug(4,
|
||||||
|
"gap_to_fix: %u frames at input rate, %" PRId64
|
||||||
|
" frames at output rate.",
|
||||||
|
-inframe->timestamp_gap, gap_to_fix);
|
||||||
// debug(3, "due to timstamp gap of %d frames, skip %" PRId64 " output
|
// debug(3, "due to timstamp gap of %d frames, skip %" PRId64 " output
|
||||||
// frames.", inframe->timestamp_gap, gap_to_fix);
|
// frames.", inframe->timestamp_gap, gap_to_fix);
|
||||||
}
|
}
|
||||||
@@ -4794,9 +4818,8 @@ void *player_thread_func(void *arg) {
|
|||||||
frames_to_skip -= play_samples;
|
frames_to_skip -= play_samples;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
size_t bytes_to_skip =
|
||||||
|
frames_to_skip *
|
||||||
size_t bytes_to_skip = frames_to_skip *
|
|
||||||
CHANNELS_FROM_ENCODED_FORMAT(config.current_output_configuration) *
|
CHANNELS_FROM_ENCODED_FORMAT(config.current_output_configuration) *
|
||||||
sps_format_sample_size(
|
sps_format_sample_size(
|
||||||
FORMAT_FROM_ENCODED_FORMAT(config.current_output_configuration));
|
FORMAT_FROM_ENCODED_FORMAT(config.current_output_configuration));
|
||||||
|
|||||||
@@ -273,7 +273,8 @@ typedef struct {
|
|||||||
// otherwise
|
// otherwise
|
||||||
int software_mute_enabled; // if we don't have a real mute that we can use
|
int software_mute_enabled; // if we don't have a real mute that we can use
|
||||||
int fd;
|
int fd;
|
||||||
int authorized; // set if a password is required and has been supplied or not required. Also always set in AirPlay 2 mode.
|
int authorized; // set if a password is required and has been supplied or not required. Also
|
||||||
|
// always set in AirPlay 2 mode.
|
||||||
char *auth_nonce; // the session nonce, if needed
|
char *auth_nonce; // the session nonce, if needed
|
||||||
stream_cfg stream;
|
stream_cfg stream;
|
||||||
SOCKADDR remote, local;
|
SOCKADDR remote, local;
|
||||||
|
|||||||
+2
-1
@@ -42,6 +42,7 @@
|
|||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "ptp-utilities.h"
|
#include "ptp-utilities.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -253,7 +254,7 @@ void ptp_send_control_message_string(const char *msg) {
|
|||||||
die("error sending timing_peer_list to NQPTP");
|
die("error sending timing_peer_list to NQPTP");
|
||||||
}
|
}
|
||||||
/* Deallocate the socket */
|
/* Deallocate the socket */
|
||||||
close(s);
|
safe_socket_close(&s);
|
||||||
freeaddrinfo(info);
|
freeaddrinfo(info);
|
||||||
|
|
||||||
/* deallocate the message string */
|
/* deallocate the message string */
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -311,11 +312,6 @@ void *rtp_audio_receiver(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
debug(3, "Audio receiver -- Server RTP thread interrupted. terminating.");
|
|
||||||
close(conn->audio_socket);
|
|
||||||
*/
|
|
||||||
|
|
||||||
debug(1, "Audio receiver thread \"normal\" exit -- this can't happen. Hah!");
|
debug(1, "Audio receiver thread \"normal\" exit -- this can't happen. Hah!");
|
||||||
pthread_cleanup_pop(0); // don't execute anything here.
|
pthread_cleanup_pop(0); // don't execute anything here.
|
||||||
debug(2, "Audio receiver thread exit.");
|
debug(2, "Audio receiver thread exit.");
|
||||||
@@ -981,7 +977,8 @@ void *rtp_timing_receiver(void *arg) {
|
|||||||
return_time);
|
return_time);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug(1, "Timing port -- Unknown RTP packet of type 0x%02X length %zd.", packet[1], nread);
|
debug(1, "Timing port -- Unknown RTP packet of type 0x%02X length %zd.", packet[1],
|
||||||
|
nread);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug(3, "Timing Receiver Thread -- dropping incoming packet to simulate a bad network.");
|
debug(3, "Timing Receiver Thread -- dropping incoming packet to simulate a bad network.");
|
||||||
@@ -1387,9 +1384,11 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP,
|
|||||||
if ((previous_offset != 0) && (previous_clock_id == actual_clock_id) &&
|
if ((previous_offset != 0) && (previous_clock_id == actual_clock_id) &&
|
||||||
((jitter > 3000000) || (jitter < -3000000)))
|
((jitter > 3000000) || (jitter < -3000000)))
|
||||||
debug(1,
|
debug(1,
|
||||||
"Clock jitter: %.3f mS. Time since sample: %.3f mS. Time since start of mastership: %.3f "
|
"Clock jitter: %.3f mS. Time since sample: %.3f mS. Time since start of "
|
||||||
|
"mastership: %.3f "
|
||||||
"seconds.",
|
"seconds.",
|
||||||
jitter * 0.000001, time_since_sample * 0.000001, time_since_start_of_mastership * 0.000000001);
|
jitter * 0.000001, time_since_sample * 0.000001,
|
||||||
|
time_since_start_of_mastership * 0.000000001);
|
||||||
|
|
||||||
previous_offset = actual_offset;
|
previous_offset = actual_offset;
|
||||||
previous_clock_id = actual_clock_id;
|
previous_clock_id = actual_clock_id;
|
||||||
@@ -1514,7 +1513,8 @@ int frame_to_ptp_local_time(uint32_t timestamp, uint64_t *time, rtsp_conn_info *
|
|||||||
int64_t time_difference = frame_difference;
|
int64_t time_difference = frame_difference;
|
||||||
time_difference = time_difference * 1000000000;
|
time_difference = time_difference * 1000000000;
|
||||||
if (conn->input_rate == 0) {
|
if (conn->input_rate == 0) {
|
||||||
debug(1,"Connection %d: in a call to frame_to_ptp_local_time, conn->input_rate is zero!", conn->connection_number);
|
debug(1, "Connection %d: in a call to frame_to_ptp_local_time, conn->input_rate is zero!",
|
||||||
|
conn->connection_number);
|
||||||
time_difference = 0;
|
time_difference = 0;
|
||||||
} else {
|
} else {
|
||||||
time_difference = time_difference / conn->input_rate;
|
time_difference = time_difference / conn->input_rate;
|
||||||
@@ -1550,10 +1550,9 @@ int local_ptp_time_to_frame(uint64_t time, uint32_t *frame, rtsp_conn_info *conn
|
|||||||
void rtp_ap2_control_handler_cleanup_handler(void *arg) {
|
void rtp_ap2_control_handler_cleanup_handler(void *arg) {
|
||||||
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
||||||
debug(2, "Connection %d: AP2 Control Receiver Cleanup.", conn->connection_number);
|
debug(2, "Connection %d: AP2 Control Receiver Cleanup.", conn->connection_number);
|
||||||
close(conn->ap2_control_socket);
|
safe_socket_close(&conn->ap2_control_socket);
|
||||||
debug(2, "Connection %d: UDP control port %u closed.", conn->connection_number,
|
debug(2, "Connection %d: UDP control port %u closed.", conn->connection_number,
|
||||||
conn->local_ap2_control_port);
|
conn->local_ap2_control_port);
|
||||||
conn->ap2_control_socket = 0;
|
|
||||||
conn->ap2_remote_control_socket_addr_length =
|
conn->ap2_remote_control_socket_addr_length =
|
||||||
0; // indicates to the control receiver thread that the socket address need to be
|
0; // indicates to the control receiver thread that the socket address need to be
|
||||||
// recreated (needed for resend requests in the realtime mode)
|
// recreated (needed for resend requests in the realtime mode)
|
||||||
@@ -1806,9 +1805,9 @@ void *rtp_ap2_control_receiver(void *arg) {
|
|||||||
void rtp_realtime_audio_cleanup_handler(__attribute__((unused)) void *arg) {
|
void rtp_realtime_audio_cleanup_handler(__attribute__((unused)) void *arg) {
|
||||||
debug(2, "Realtime Audio Receiver Cleanup Start.");
|
debug(2, "Realtime Audio Receiver Cleanup Start.");
|
||||||
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
|
||||||
close(conn->realtime_audio_socket);
|
debug(2, "Connection %d: closing realtime audio port %u", conn->connection_number,
|
||||||
debug(2, "Connection %d: closing realtime audio port %u", conn->connection_number, conn->local_realtime_audio_port);
|
conn->local_realtime_audio_port);
|
||||||
conn->realtime_audio_socket = 0;
|
safe_socket_close(&conn->realtime_audio_socket);
|
||||||
debug(2, "Realtime Audio Receiver Cleanup Done.");
|
debug(2, "Realtime Audio Receiver Cleanup Done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
#include "activity_monitor.h"
|
#include "activity_monitor.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
#include "utilities/rtsp_message_utilities.h"
|
#include "utilities/rtsp_message_utilities.h"
|
||||||
|
|
||||||
#ifdef CONFIG_OPENSSL
|
#ifdef CONFIG_OPENSSL
|
||||||
@@ -76,8 +77,8 @@
|
|||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA
|
#ifdef CONFIG_METADATA
|
||||||
#include "metadata/pc_queue.h"
|
|
||||||
#include "metadata/core.h"
|
#include "metadata/core.h"
|
||||||
|
#include "metadata/pc_queue.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA_HUB
|
#ifdef CONFIG_METADATA_HUB
|
||||||
@@ -91,12 +92,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
#include <plist/plist.h>
|
|
||||||
#include "ap2_buffered_audio_processor.h"
|
#include "ap2_buffered_audio_processor.h"
|
||||||
#include "ap2_event_receiver.h"
|
#include "ap2_event_receiver.h"
|
||||||
#include "pair_ap/pair.h"
|
#include "pair_ap/pair.h"
|
||||||
#include "plists/get_info_response.h"
|
#include "plists/get_info_response.h"
|
||||||
#include "ptp-utilities.h"
|
#include "ptp-utilities.h"
|
||||||
|
#include <plist/plist.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBPLIST_GE_2_3_0
|
#ifdef HAVE_LIBPLIST_GE_2_3_0
|
||||||
#define plist_from_memory(plist_data, length, plist) \
|
#define plist_from_memory(plist_data, length, plist) \
|
||||||
@@ -125,8 +126,8 @@ enum rtsp_read_request_response {
|
|||||||
rtsp_read_request_response_error
|
rtsp_read_request_response_error
|
||||||
};
|
};
|
||||||
|
|
||||||
rtsp_conn_info *principal_conn;
|
rtsp_conn_info *principal_conn = NULL;
|
||||||
rtsp_conn_info **conns;
|
rtsp_conn_info **conns = NULL;
|
||||||
|
|
||||||
// always lock this when accessing the principal conn value
|
// always lock this when accessing the principal conn value
|
||||||
// use a read lock when consulting and holding it
|
// use a read lock when consulting and holding it
|
||||||
@@ -144,132 +145,6 @@ pthread_mutex_t conns_lock = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
|
|
||||||
int RTSP_connection_index = 1;
|
int RTSP_connection_index = 1;
|
||||||
|
|
||||||
// The principal_conn variable points to the connection that
|
|
||||||
// controls the mDNS status and flags and that is potentially
|
|
||||||
// in control of the playing subsystem to output audio to a backend
|
|
||||||
// the principal_conn variable may be NULL
|
|
||||||
|
|
||||||
// the principal_conn is set by an ANNOUNCE message (Classic AirPlay) or
|
|
||||||
// by the initial SETUP (of a connection, not of a play session) message (AirPlay 2) and cleared
|
|
||||||
// when a session is terminated (AirPlay 2)
|
|
||||||
|
|
||||||
// In AirPlay 2, only one PTP connection can be live at any time, and it is the principal_conn.
|
|
||||||
// This is because, in AirPlay 2, the principal_conn connection
|
|
||||||
// also has control of the mDNS interface, and thus determines the state of the player as seen by
|
|
||||||
// other devices.
|
|
||||||
|
|
||||||
void release_play_lock(rtsp_conn_info *conn) {
|
|
||||||
// no need thread cancellation points in here
|
|
||||||
pthread_rwlock_wrlock(&principal_conn_lock);
|
|
||||||
if ((principal_conn == conn) || (conn == NULL)) { // if we have the player
|
|
||||||
if (principal_conn != NULL) {
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
|
||||||
config.airplay_statusflags &= (0xffffffff - (1 << 11)); // DeviceSupportsRelay
|
|
||||||
if (principal_conn->airplay_gid) {
|
|
||||||
free(principal_conn->airplay_gid);
|
|
||||||
principal_conn->airplay_gid = NULL; // stop using the client's GID as our GID.
|
|
||||||
}
|
|
||||||
build_bonjour_strings(principal_conn);
|
|
||||||
mdns_update(NULL, secondary_txt_records);
|
|
||||||
#endif
|
|
||||||
debug(2, "Connection %d: %s released principal_conn.", conn->connection_number,
|
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
}
|
|
||||||
principal_conn = NULL; // let it go
|
|
||||||
}
|
|
||||||
pthread_rwlock_unlock(&principal_conn_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop the current principal_conn from playing if necessary and make conn the principal_conn.
|
|
||||||
|
|
||||||
play_lock_r get_play_lock(rtsp_conn_info *conn, int allow_session_interruption) {
|
|
||||||
play_lock_r response = play_lock_aquisition_failed;
|
|
||||||
if (conn != NULL) {
|
|
||||||
debug(2, "Connection %d: %s get_play_lock with allow_session_interruption of %d.",
|
|
||||||
conn->connection_number, get_category_string(conn->airplay_stream_category),
|
|
||||||
allow_session_interruption);
|
|
||||||
|
|
||||||
pthread_rwlock_wrlock(&principal_conn_lock);
|
|
||||||
pthread_cleanup_push(rwlock_unlock, (void *)&principal_conn_lock);
|
|
||||||
|
|
||||||
if (principal_conn == conn) {
|
|
||||||
debug(2, "Connection %d: %s already has principal_conn.", principal_conn->connection_number,
|
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
} else {
|
|
||||||
if (principal_conn != NULL)
|
|
||||||
debug(2, "Connection %d: %s is requested to relinquish principal_conn.",
|
|
||||||
principal_conn->connection_number,
|
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
if (conn != NULL)
|
|
||||||
debug(2, "Connection %d: %s request to acquire principal_conn.", conn->connection_number,
|
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (principal_conn == conn) {
|
|
||||||
if (conn == NULL)
|
|
||||||
response = play_lock_already_released;
|
|
||||||
else
|
|
||||||
response = play_lock_already_acquired;
|
|
||||||
} else if (principal_conn == NULL) {
|
|
||||||
// already unlocked, and principal conn not NULL
|
|
||||||
principal_conn = conn;
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
|
||||||
config.airplay_statusflags |= (1 << 11); // DeviceSupportsRelay
|
|
||||||
#endif
|
|
||||||
response = play_lock_acquired_without_breaking_in;
|
|
||||||
} else if (allow_session_interruption != 0) { // principal conn not NULL,
|
|
||||||
// important -- demote the principal conn before cancelling it
|
|
||||||
if (principal_conn->fd > 0) {
|
|
||||||
debug(2,
|
|
||||||
"Connection %d: %s is acquiring play_lock and is forcing termination of Connection "
|
|
||||||
"%d %s. Closing "
|
|
||||||
"RTSP connection socket %d: "
|
|
||||||
"from %s:%u to self at "
|
|
||||||
"%s:%u.",
|
|
||||||
conn->connection_number, get_category_string(conn->airplay_stream_category),
|
|
||||||
principal_conn->connection_number,
|
|
||||||
get_category_string(principal_conn->airplay_stream_category), principal_conn->fd,
|
|
||||||
principal_conn->client_ip_string, principal_conn->client_rtsp_port,
|
|
||||||
principal_conn->self_ip_string, principal_conn->self_rtsp_port);
|
|
||||||
close(principal_conn->fd);
|
|
||||||
principal_conn->fd = 0;
|
|
||||||
usleep(1000000);
|
|
||||||
}
|
|
||||||
rtsp_conn_info *previous_principal_conn = principal_conn;
|
|
||||||
principal_conn = conn; // make the conn the new principal_conn
|
|
||||||
pthread_cancel(previous_principal_conn->thread); // cancel the previous one...
|
|
||||||
usleep(1000000);
|
|
||||||
if (principal_conn == NULL) {
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
|
||||||
config.airplay_statusflags &= (0xffffffff - (1 << 11)); // DeviceSupportsRelay
|
|
||||||
if (conn->airplay_gid) {
|
|
||||||
free(conn->airplay_gid);
|
|
||||||
conn->airplay_gid = NULL; // stop using the client's GID as our GID.
|
|
||||||
}
|
|
||||||
build_bonjour_strings(conn);
|
|
||||||
mdns_update(NULL, secondary_txt_records);
|
|
||||||
#endif
|
|
||||||
response = play_lock_released;
|
|
||||||
} else {
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
|
||||||
config.airplay_statusflags |= (1 << 11); // DeviceSupportsRelay
|
|
||||||
#endif
|
|
||||||
response = play_lock_acquired_by_breaking_in;
|
|
||||||
}
|
|
||||||
// usleep(1000000); // don't know why this delay is needed.
|
|
||||||
}
|
|
||||||
if ((principal_conn != NULL) && (response != play_lock_already_acquired))
|
|
||||||
debug(2, "Connection %d: %s has principal_conn.", conn->connection_number,
|
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
pthread_cleanup_pop(1); // release the principal_conn lock
|
|
||||||
|
|
||||||
} else {
|
|
||||||
debug(1, "Connection %d: %s get_play_lock must have a non-NULL conn.", conn->connection_number,
|
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep track of the threads we have spawned so we can join() them
|
// keep track of the threads we have spawned so we can join() them
|
||||||
static int nconns = 0;
|
static int nconns = 0;
|
||||||
static void track_thread(rtsp_conn_info *conn) {
|
static void track_thread(rtsp_conn_info *conn) {
|
||||||
@@ -369,6 +244,191 @@ void cleanup_threads(void) {
|
|||||||
debug(4, "Airplay Volume for new connections is %.6f.", suggested_volume(NULL));
|
debug(4, "Airplay Volume for new connections is %.6f.", suggested_volume(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int terminate_conn(int connection_number) {
|
||||||
|
// this will look for a connection by number, cancel it, join it and delete it.
|
||||||
|
int found = 0;
|
||||||
|
debug_mutex_lock(&conns_lock, 1000000, 4);
|
||||||
|
// look for an empty slot first
|
||||||
|
int i = 0;
|
||||||
|
while ((i < nconns) && (found == 0)) {
|
||||||
|
if ((conns[i] != NULL) && (conns[i]->connection_number == connection_number)) {
|
||||||
|
pthread_cancel(conns[i]->thread);
|
||||||
|
pthread_join(conns[i]->thread, NULL);
|
||||||
|
conns[i] = NULL;
|
||||||
|
found = 1;
|
||||||
|
} else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
debug_mutex_unlock(&conns_lock, 4);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The principal_conn variable points to the connection that
|
||||||
|
// controls the mDNS status and flags and that is potentially
|
||||||
|
// in control of the playing subsystem to output audio to a backend
|
||||||
|
// the principal_conn variable may be NULL
|
||||||
|
|
||||||
|
// the principal_conn is set by an ANNOUNCE message (Classic AirPlay) or
|
||||||
|
// by the initial SETUP (of a connection, not of a play session) message (AirPlay 2) and cleared
|
||||||
|
// when a session is terminated (AirPlay 2)
|
||||||
|
|
||||||
|
// In AirPlay 2, only one PTP connection can be live at any time, and it is the principal_conn.
|
||||||
|
// This is because, in AirPlay 2, the principal_conn connection
|
||||||
|
// also has control of the mDNS interface, and thus determines the state of the player as seen by
|
||||||
|
// other devices.
|
||||||
|
|
||||||
|
// If a conn has play lock, kill the connection completely.
|
||||||
|
|
||||||
|
void stop_play() {
|
||||||
|
pthread_rwlock_wrlock(&principal_conn_lock);
|
||||||
|
if (principal_conn != NULL) {
|
||||||
|
debug(1, "Connection %d: stop and close this connection.", principal_conn->connection_number);
|
||||||
|
terminate_conn(principal_conn->connection_number);
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
config.airplay_statusflags &= (0xffffffff - (1 << 11)); // DeviceSupportsRelay
|
||||||
|
if (principal_conn->airplay_gid) {
|
||||||
|
free(principal_conn->airplay_gid);
|
||||||
|
principal_conn->airplay_gid = NULL; // stop using the client's GID as our GID.
|
||||||
|
}
|
||||||
|
build_bonjour_strings(principal_conn);
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
|
mdns_update(NULL, secondary_txt_records);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
principal_conn = NULL; // let it go
|
||||||
|
debug(1, "Connection successfully closed.");
|
||||||
|
}
|
||||||
|
pthread_rwlock_unlock(&principal_conn_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void release_play_lock(rtsp_conn_info *conn) {
|
||||||
|
// no need thread cancellation points in here
|
||||||
|
pthread_rwlock_wrlock(&principal_conn_lock);
|
||||||
|
if ((principal_conn == conn) || (conn == NULL)) { // if we have the player
|
||||||
|
if (principal_conn != NULL) {
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
config.airplay_statusflags &= (0xffffffff - (1 << 11)); // DeviceSupportsRelay
|
||||||
|
if (principal_conn->airplay_gid) {
|
||||||
|
free(principal_conn->airplay_gid);
|
||||||
|
principal_conn->airplay_gid = NULL; // stop using the client's GID as our GID.
|
||||||
|
}
|
||||||
|
build_bonjour_strings(principal_conn);
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
|
mdns_update(NULL, secondary_txt_records);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
debug(2, "Connection %d: %s released principal_conn.", conn->connection_number,
|
||||||
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
}
|
||||||
|
principal_conn = NULL; // let it go
|
||||||
|
}
|
||||||
|
pthread_rwlock_unlock(&principal_conn_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop the current principal_conn from playing if necessary and make conn the principal_conn.
|
||||||
|
|
||||||
|
// result of trying to acquire or release the play lock
|
||||||
|
typedef enum {
|
||||||
|
play_lock_released,
|
||||||
|
play_lock_already_released,
|
||||||
|
play_lock_already_acquired,
|
||||||
|
play_lock_acquired_without_breaking_in,
|
||||||
|
play_lock_acquired_by_breaking_in,
|
||||||
|
play_lock_aquisition_failed
|
||||||
|
} play_lock_r;
|
||||||
|
|
||||||
|
play_lock_r get_play_lock(rtsp_conn_info *conn, int allow_session_interruption) {
|
||||||
|
play_lock_r response = play_lock_aquisition_failed;
|
||||||
|
if (conn != NULL) {
|
||||||
|
debug(2, "Connection %d: %s get_play_lock with allow_session_interruption of %d.",
|
||||||
|
conn->connection_number, get_category_string(conn->airplay_stream_category),
|
||||||
|
allow_session_interruption);
|
||||||
|
|
||||||
|
pthread_rwlock_wrlock(&principal_conn_lock);
|
||||||
|
pthread_cleanup_push(rwlock_unlock, (void *)&principal_conn_lock);
|
||||||
|
|
||||||
|
if (principal_conn == conn) {
|
||||||
|
debug(2, "Connection %d: %s already has principal_conn.", principal_conn->connection_number,
|
||||||
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
} else {
|
||||||
|
if (principal_conn != NULL)
|
||||||
|
debug(2, "Connection %d: %s is requested to relinquish principal_conn.",
|
||||||
|
principal_conn->connection_number,
|
||||||
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
if (conn != NULL)
|
||||||
|
debug(2, "Connection %d: %s request to acquire principal_conn.", conn->connection_number,
|
||||||
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (principal_conn == conn) {
|
||||||
|
if (conn == NULL)
|
||||||
|
response = play_lock_already_released;
|
||||||
|
else
|
||||||
|
response = play_lock_already_acquired;
|
||||||
|
} else if (principal_conn == NULL) {
|
||||||
|
// already unlocked, and principal conn not NULL
|
||||||
|
principal_conn = conn;
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
config.airplay_statusflags |= (1 << 11); // DeviceSupportsRelay
|
||||||
|
#endif
|
||||||
|
response = play_lock_acquired_without_breaking_in;
|
||||||
|
} else if (allow_session_interruption != 0) { // principal conn not NULL,
|
||||||
|
// important -- demote the principal conn before cancelling it
|
||||||
|
/*
|
||||||
|
if (principal_conn->fd > 0) {
|
||||||
|
debug(2,
|
||||||
|
"Connection %d: %s is acquiring play_lock and is forcing termination of Connection "
|
||||||
|
"%d %s. Closing "
|
||||||
|
"RTSP connection socket %d: "
|
||||||
|
"from %s:%u to self at "
|
||||||
|
"%s:%u.",
|
||||||
|
conn->connection_number, get_category_string(conn->airplay_stream_category),
|
||||||
|
principal_conn->connection_number,
|
||||||
|
get_category_string(principal_conn->airplay_stream_category), principal_conn->fd,
|
||||||
|
principal_conn->client_ip_string, principal_conn->client_rtsp_port,
|
||||||
|
principal_conn->self_ip_string, principal_conn->self_rtsp_port);
|
||||||
|
safe_socket_close(&principal_conn->fd);
|
||||||
|
usleep(1000000);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
debug(4, "Connection %d: about to be terminated.", principal_conn->connection_number);
|
||||||
|
rtsp_conn_info *previous_principal_conn = principal_conn;
|
||||||
|
principal_conn = conn; // make the conn the new principal_conn
|
||||||
|
terminate_conn(previous_principal_conn->connection_number);
|
||||||
|
debug(4, "Connection successfully terminated.");
|
||||||
|
if (principal_conn == NULL) {
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
config.airplay_statusflags &= (0xffffffff - (1 << 11)); // DeviceSupportsRelay
|
||||||
|
if (conn->airplay_gid) {
|
||||||
|
free(conn->airplay_gid);
|
||||||
|
conn->airplay_gid = NULL; // stop using the client's GID as our GID.
|
||||||
|
}
|
||||||
|
build_bonjour_strings(conn);
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
|
mdns_update(NULL, secondary_txt_records);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
response = play_lock_released;
|
||||||
|
} else {
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
config.airplay_statusflags |= (1 << 11); // DeviceSupportsRelay
|
||||||
|
#endif
|
||||||
|
response = play_lock_acquired_by_breaking_in;
|
||||||
|
}
|
||||||
|
// usleep(1000000); // don't know why this delay is needed.
|
||||||
|
}
|
||||||
|
if ((principal_conn != NULL) && (response != play_lock_already_acquired))
|
||||||
|
debug(2, "Connection %d: %s has principal_conn.", conn->connection_number,
|
||||||
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
pthread_cleanup_pop(1); // release the principal_conn lock
|
||||||
|
|
||||||
|
} else {
|
||||||
|
debug(1, "Connection %d: %s get_play_lock must have a non-NULL conn.", conn->connection_number,
|
||||||
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
// park a null at the line ending, and return the next line pointer
|
// park a null at the line ending, and return the next line pointer
|
||||||
// accept \r, \n, or \r\n
|
// accept \r, \n, or \r\n
|
||||||
static char *nextline(char *in, int inbuf) {
|
static char *nextline(char *in, int inbuf) {
|
||||||
@@ -578,8 +638,7 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
|
|||||||
debug(2, "Connection %d RTSP port closed by client with error %d: \"%s\".",
|
debug(2, "Connection %d RTSP port closed by client with error %d: \"%s\".",
|
||||||
conn->connection_number, errno, (char *)errorstring);
|
conn->connection_number, errno, (char *)errorstring);
|
||||||
}
|
}
|
||||||
close(conn->fd); // close it from our end too...
|
safe_socket_close(&conn->fd); // close it from our end too...
|
||||||
conn->fd = 0;
|
|
||||||
reply = rtsp_read_request_response_channel_closed;
|
reply = rtsp_read_request_response_channel_closed;
|
||||||
} else {
|
} else {
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
@@ -959,13 +1018,11 @@ void generateTxtDataValueInfo(rtsp_conn_info *conn, void **response, size_t *res
|
|||||||
features_lo = features_lo & 0xffffffff;
|
features_lo = features_lo & 0xffffffff;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
uint64_t features_hi = config.airplay_features;
|
uint64_t features_hi = config.airplay_features;
|
||||||
features_hi = (features_hi >> 32) & 0xffffffff;
|
features_hi = (features_hi >> 32) & 0xffffffff;
|
||||||
uint64_t features_lo = config.airplay_features;
|
uint64_t features_lo = config.airplay_features;
|
||||||
features_lo = features_lo & 0xffffffff;
|
features_lo = features_lo & 0xffffffff;
|
||||||
|
|
||||||
|
|
||||||
if (add_pstring_to_malloc(bnprintf(localString, sizeof(localString),
|
if (add_pstring_to_malloc(bnprintf(localString, sizeof(localString),
|
||||||
"features=0x%" PRIX64 ",0x%" PRIX64 "", features_lo,
|
"features=0x%" PRIX64 ",0x%" PRIX64 "", features_lo,
|
||||||
features_hi),
|
features_hi),
|
||||||
@@ -1292,7 +1349,8 @@ void handle_flushbuffered(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
|
|||||||
conn->ap2_immediate_flush_until_sequence_number = flushUntilSeq & 0x7fffff;
|
conn->ap2_immediate_flush_until_sequence_number = flushUntilSeq & 0x7fffff;
|
||||||
conn->ap2_immediate_flush_until_rtp_timestamp = flushUntilTS;
|
conn->ap2_immediate_flush_until_rtp_timestamp = flushUntilTS;
|
||||||
debug(2,
|
debug(2,
|
||||||
"Connection %d: immediate flush request created: flushUntilTS: %" PRIu64 ", flushUntilSeq: %" PRIu64 ".",
|
"Connection %d: immediate flush request created: flushUntilTS: %" PRIu64
|
||||||
|
", flushUntilSeq: %" PRIu64 ".",
|
||||||
conn->connection_number, flushUntilTS, flushUntilSeq & 0x7fffff);
|
conn->connection_number, flushUntilTS, flushUntilSeq & 0x7fffff);
|
||||||
conn->ap2_play_enabled = 0; // stop trying to play audio
|
conn->ap2_play_enabled = 0; // stop trying to play audio
|
||||||
ptp_send_control_message_string(
|
ptp_send_control_message_string(
|
||||||
@@ -1316,7 +1374,8 @@ void handle_flushbuffered(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
|
|||||||
conn->ap2_deferred_flush_requests[i].flushUntilSeq = flushUntilSeq & 0x7fffff;
|
conn->ap2_deferred_flush_requests[i].flushUntilSeq = flushUntilSeq & 0x7fffff;
|
||||||
conn->ap2_deferred_flush_requests[i].flushUntilTS = flushUntilTS;
|
conn->ap2_deferred_flush_requests[i].flushUntilTS = flushUntilTS;
|
||||||
debug(2,
|
debug(2,
|
||||||
"Connection %d: deferred flush request created: flushFromSeq: %" PRIu64 ", flushUntilSeq: %" PRIu64 ".",
|
"Connection %d: deferred flush request created: flushFromSeq: %" PRIu64
|
||||||
|
", flushUntilSeq: %" PRIu64 ".",
|
||||||
conn->connection_number, flushFromSeq, flushUntilSeq);
|
conn->connection_number, flushFromSeq, flushUntilSeq);
|
||||||
} else {
|
} else {
|
||||||
debug(1, "Connection %d: no more room for deferred flush request records",
|
debug(1, "Connection %d: no more room for deferred flush request records",
|
||||||
@@ -1553,7 +1612,8 @@ void handle_pair_add(rtsp_conn_info *conn __attribute__((unused)), rtsp_message
|
|||||||
free(conn->ap2_client_name);
|
free(conn->ap2_client_name);
|
||||||
conn->ap2_client_name = strdup(hdr);
|
conn->ap2_client_name = strdup(hdr);
|
||||||
}
|
}
|
||||||
debug(1, "Connection %d from \"%s\": handle_pair_add", conn->connection_number, conn->ap2_client_name);
|
debug(1, "Connection %d from \"%s\": handle_pair_add", conn->connection_number,
|
||||||
|
conn->ap2_client_name);
|
||||||
debug_log_rtsp_message_conn(conn, 1, "pair-add request", req);
|
debug_log_rtsp_message_conn(conn, 1, "pair-add request", req);
|
||||||
uint8_t *body = NULL;
|
uint8_t *body = NULL;
|
||||||
size_t body_len = 0;
|
size_t body_len = 0;
|
||||||
@@ -1578,7 +1638,8 @@ void handle_pair_list(rtsp_conn_info *conn __attribute__((unused)), rtsp_message
|
|||||||
free(conn->ap2_client_name);
|
free(conn->ap2_client_name);
|
||||||
conn->ap2_client_name = strdup(hdr);
|
conn->ap2_client_name = strdup(hdr);
|
||||||
}
|
}
|
||||||
debug(1, "Connection %d from \"%s\": handle_pair_list", conn->connection_number, conn->ap2_client_name);
|
debug(1, "Connection %d from \"%s\": handle_pair_list", conn->connection_number,
|
||||||
|
conn->ap2_client_name);
|
||||||
uint8_t *body = NULL;
|
uint8_t *body = NULL;
|
||||||
size_t body_len = 0;
|
size_t body_len = 0;
|
||||||
int ret = pair_list(PAIR_SERVER_HOMEKIT, &body, &body_len, pairing_list_cb, NULL,
|
int ret = pair_list(PAIR_SERVER_HOMEKIT, &body, &body_len, pairing_list_cb, NULL,
|
||||||
@@ -1603,7 +1664,8 @@ void handle_pair_remove(rtsp_conn_info *conn __attribute__((unused)), rtsp_messa
|
|||||||
free(conn->ap2_client_name);
|
free(conn->ap2_client_name);
|
||||||
conn->ap2_client_name = strdup(hdr);
|
conn->ap2_client_name = strdup(hdr);
|
||||||
}
|
}
|
||||||
debug(1, "Connection %d from \"%s\": handle_pair_remove", conn->connection_number, conn->ap2_client_name);
|
debug(1, "Connection %d from \"%s\": handle_pair_remove", conn->connection_number,
|
||||||
|
conn->ap2_client_name);
|
||||||
uint8_t *body = NULL;
|
uint8_t *body = NULL;
|
||||||
size_t body_len = 0;
|
size_t body_len = 0;
|
||||||
int ret = pair_remove(PAIR_SERVER_HOMEKIT, &body, &body_len, pairing_remove_cb, NULL,
|
int ret = pair_remove(PAIR_SERVER_HOMEKIT, &body, &body_len, pairing_remove_cb, NULL,
|
||||||
@@ -1633,7 +1695,8 @@ void handle_pair_verify(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *r
|
|||||||
mstage = '0' + b[2];
|
mstage = '0' + b[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(1, "Connection %d from \"%s\": handle_pair_verify, stage M%c, Content-Length %d", conn->connection_number, conn->ap2_client_name, mstage, req->contentlength);
|
debug(1, "Connection %d from \"%s\": handle_pair_verify, stage M%c, Content-Length %d",
|
||||||
|
conn->connection_number, conn->ap2_client_name, mstage, req->contentlength);
|
||||||
debug_log_rtsp_message_conn(conn, 2, "pair-verify request", req);
|
debug_log_rtsp_message_conn(conn, 2, "pair-verify request", req);
|
||||||
int ret;
|
int ret;
|
||||||
uint8_t *body = NULL;
|
uint8_t *body = NULL;
|
||||||
@@ -1692,9 +1755,8 @@ void handle_pair_pin_start(rtsp_conn_info *conn, rtsp_message *req, rtsp_message
|
|||||||
free(conn->ap2_client_name);
|
free(conn->ap2_client_name);
|
||||||
conn->ap2_client_name = strdup(hdr);
|
conn->ap2_client_name = strdup(hdr);
|
||||||
}
|
}
|
||||||
debug(4, "Connection %d from \"%s\": handle_pair_pin_start, Content-Length %d", conn->connection_number,
|
debug(4, "Connection %d from \"%s\": handle_pair_pin_start, Content-Length %d",
|
||||||
conn->ap2_client_name,
|
conn->connection_number, conn->ap2_client_name, req->contentlength);
|
||||||
req->contentlength);
|
|
||||||
debug_log_rtsp_message_conn(conn, 4, "handle_pair_pin_start", req);
|
debug_log_rtsp_message_conn(conn, 4, "handle_pair_pin_start", req);
|
||||||
|
|
||||||
uint8_t *body = NULL;
|
uint8_t *body = NULL;
|
||||||
@@ -1715,9 +1777,8 @@ void handle_pair_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *re
|
|||||||
free(conn->ap2_client_name);
|
free(conn->ap2_client_name);
|
||||||
conn->ap2_client_name = strdup(hdr);
|
conn->ap2_client_name = strdup(hdr);
|
||||||
}
|
}
|
||||||
debug(2, "Connection %d from \"%s\": handle_pair_setup, Content-Length %d", conn->connection_number,
|
debug(2, "Connection %d from \"%s\": handle_pair_setup, Content-Length %d",
|
||||||
conn->ap2_client_name,
|
conn->connection_number, conn->ap2_client_name, req->contentlength);
|
||||||
req->contentlength);
|
|
||||||
debug_log_rtsp_message_conn(conn, 2, "pair-setup request", req);
|
debug_log_rtsp_message_conn(conn, 2, "pair-setup request", req);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@@ -1728,8 +1789,8 @@ void handle_pair_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *re
|
|||||||
debug_log_rtsp_message(3, "handle_pair_setup", req);
|
debug_log_rtsp_message(3, "handle_pair_setup", req);
|
||||||
|
|
||||||
if (!conn->ap2_pairing_context.setup_ctx) {
|
if (!conn->ap2_pairing_context.setup_ctx) {
|
||||||
conn->ap2_pairing_context.setup_ctx = pair_setup_new(PAIR_SERVER_HOMEKIT, config.password,
|
conn->ap2_pairing_context.setup_ctx =
|
||||||
NULL, NULL, config.airplay_device_id);
|
pair_setup_new(PAIR_SERVER_HOMEKIT, config.password, NULL, NULL, config.airplay_device_id);
|
||||||
if (!conn->ap2_pairing_context.setup_ctx) {
|
if (!conn->ap2_pairing_context.setup_ctx) {
|
||||||
debug(1, "Error creating setup context");
|
debug(1, "Error creating setup context");
|
||||||
resp->respcode = 500; // Internal Server Error
|
resp->respcode = 500; // Internal Server Error
|
||||||
@@ -1751,7 +1812,8 @@ void handle_pair_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *re
|
|||||||
// don't activate yet, the response to this request is still plaintext
|
// don't activate yet, the response to this request is still plaintext
|
||||||
conn->ap2_pairing_context.control_cipher_bundle.cipher_ctx =
|
conn->ap2_pairing_context.control_cipher_bundle.cipher_ctx =
|
||||||
pair_cipher_new(PAIR_SERVER_HOMEKIT, 3, conn->pair_setup_result->shared_secret,
|
pair_cipher_new(PAIR_SERVER_HOMEKIT, 3, conn->pair_setup_result->shared_secret,
|
||||||
conn->pair_setup_result->shared_secret_len, ""); // last argument is the (possible) dynamic salt suffix
|
conn->pair_setup_result->shared_secret_len,
|
||||||
|
""); // last argument is the (possible) dynamic salt suffix
|
||||||
if (!conn->ap2_pairing_context.control_cipher_bundle.cipher_ctx) {
|
if (!conn->ap2_pairing_context.control_cipher_bundle.cipher_ctx) {
|
||||||
debug(1, "Error setting up rtsp control channel ciphering");
|
debug(1, "Error setting up rtsp control channel ciphering");
|
||||||
goto out;
|
goto out;
|
||||||
@@ -1760,7 +1822,8 @@ void handle_pair_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *re
|
|||||||
|
|
||||||
conn->ap2_pairing_context.event_cipher_bundle.cipher_ctx =
|
conn->ap2_pairing_context.event_cipher_bundle.cipher_ctx =
|
||||||
pair_cipher_new(PAIR_SERVER_HOMEKIT, 4, conn->pair_setup_result->shared_secret,
|
pair_cipher_new(PAIR_SERVER_HOMEKIT, 4, conn->pair_setup_result->shared_secret,
|
||||||
conn->pair_setup_result->shared_secret_len, ""); // last argument is the (possible) dynamic salt suffix
|
conn->pair_setup_result->shared_secret_len,
|
||||||
|
""); // last argument is the (possible) dynamic salt suffix
|
||||||
if (!conn->ap2_pairing_context.event_cipher_bundle.cipher_ctx) {
|
if (!conn->ap2_pairing_context.event_cipher_bundle.cipher_ctx) {
|
||||||
debug(1, "Error setting up rtsp event channel ciphering");
|
debug(1, "Error setting up rtsp event channel ciphering");
|
||||||
goto out;
|
goto out;
|
||||||
@@ -1789,7 +1852,6 @@ void handle_fp_setup(__attribute__((unused)) rtsp_conn_info *conn, rtsp_message
|
|||||||
conn->ap2_client_name);
|
conn->ap2_client_name);
|
||||||
debug_log_rtsp_message_conn(conn, 2, "fp-setup request", req);
|
debug_log_rtsp_message_conn(conn, 2, "fp-setup request", req);
|
||||||
|
|
||||||
|
|
||||||
/* Fairplay magic */
|
/* Fairplay magic */
|
||||||
static uint8_t server_fp_reply1[] =
|
static uint8_t server_fp_reply1[] =
|
||||||
"\x46\x50\x4c\x59\x03\x01\x02\x00\x00\x00\x00\x82\x02\x00\x0f\x9f\x3f\x9e\x0a"
|
"\x46\x50\x4c\x59\x03\x01\x02\x00\x00\x00\x00\x82\x02\x00\x0f\x9f\x3f\x9e\x0a"
|
||||||
@@ -1927,7 +1989,8 @@ void handle_configure(rtsp_conn_info *conn __attribute__((unused)),
|
|||||||
config.enable_HK_Access_Control = 1;
|
config.enable_HK_Access_Control = 1;
|
||||||
plist_dict_set_item(response_plist, "Identifier", plist_new_string(config.airplay_pi));
|
plist_dict_set_item(response_plist, "Identifier", plist_new_string(config.airplay_pi));
|
||||||
plist_dict_set_item(response_plist, "Enable_HK_Access_Control", plist_new_bool(1));
|
plist_dict_set_item(response_plist, "Enable_HK_Access_Control", plist_new_bool(1));
|
||||||
plist_dict_set_item(response_plist, "PublicKey",
|
plist_dict_set_item(
|
||||||
|
response_plist, "PublicKey",
|
||||||
plist_new_data((const char *)config.airplay_pk, sizeof(config.airplay_pk)));
|
plist_new_data((const char *)config.airplay_pk, sizeof(config.airplay_pk)));
|
||||||
plist_dict_set_item(response_plist, "Device_Name", plist_new_string(config.service_name));
|
plist_dict_set_item(response_plist, "Device_Name", plist_new_string(config.service_name));
|
||||||
plist_dict_set_item(response_plist, "Access_Control_Level", plist_new_uint(0));
|
plist_dict_set_item(response_plist, "Access_Control_Level", plist_new_uint(0));
|
||||||
@@ -1955,8 +2018,10 @@ void handle_configure(rtsp_conn_info *conn __attribute__((unused)),
|
|||||||
|
|
||||||
if (config.enable_HK_Access_Control != existingEnable_HK_Access_Control) {
|
if (config.enable_HK_Access_Control != existingEnable_HK_Access_Control) {
|
||||||
build_bonjour_strings(principal_conn);
|
build_bonjour_strings(principal_conn);
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
mdns_update(NULL, secondary_txt_records);
|
mdns_update(NULL, secondary_txt_records);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
plist_to_bin(response_plist, &resp->content, &resp->contentlength);
|
plist_to_bin(response_plist, &resp->content, &resp->contentlength);
|
||||||
plist_free(response_plist);
|
plist_free(response_plist);
|
||||||
|
|
||||||
@@ -2024,7 +2089,8 @@ void handle_command(rtsp_conn_info *conn, rtsp_message *req,
|
|||||||
// to incur the memory and processing cost. So we'll just send it to the
|
// to incur the memory and processing cost. So we'll just send it to the
|
||||||
// metadata handling code and it can be dealt with there.
|
// metadata handling code and it can be dealt with there.
|
||||||
#ifdef CONFIG_METADATA
|
#ifdef CONFIG_METADATA
|
||||||
send_metadata('ssnc', 'copl', req->content, req->contentlength, req, 1); // COmmand PList (and release 'req' afterwards)
|
send_metadata('ssnc', 'copl', req->content, req->contentlength, req,
|
||||||
|
1); // COmmand PList (and release 'req' afterwards)
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
plist_t command_dict = NULL;
|
plist_t command_dict = NULL;
|
||||||
@@ -2062,10 +2128,8 @@ void handle_command(rtsp_conn_info *conn, rtsp_message *req,
|
|||||||
if (subsidiary_plist) {
|
if (subsidiary_plist) {
|
||||||
char *printable_plist = plist_as_xml_text(subsidiary_plist);
|
char *printable_plist = plist_as_xml_text(subsidiary_plist);
|
||||||
if (printable_plist) {
|
if (printable_plist) {
|
||||||
debug(4, "Connection %d:\n==\n%s\n==", conn->connection_number, printable_plist);
|
debug(4, "Connection %d:\n==\n%s\n==", conn->connection_number,
|
||||||
free(printable_plist);
|
printable_plist); free(printable_plist); } else { debug(1, "Can't print the plist!");
|
||||||
} else {
|
|
||||||
debug(1, "Can't print the plist!");
|
|
||||||
}
|
}
|
||||||
plist_free(subsidiary_plist);
|
plist_free(subsidiary_plist);
|
||||||
} else {
|
} else {
|
||||||
@@ -2219,7 +2283,7 @@ void handle_teardown(rtsp_conn_info *conn, __attribute__((unused)) rtsp_message
|
|||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
void handle_options_2(rtsp_conn_info *conn, __attribute__((unused)) rtsp_message *req,
|
void handle_options_2(rtsp_conn_info *conn, __attribute__((unused)) rtsp_message *req,
|
||||||
rtsp_message *resp) {
|
rtsp_message *resp) {
|
||||||
debug_log_rtsp_message_conn(conn, 1, "OPTIONS request", req);
|
debug_log_rtsp_message_conn(conn, 3, "OPTIONS request", req);
|
||||||
debug(3, "Connection %d: OPTIONS", conn->connection_number);
|
debug(3, "Connection %d: OPTIONS", conn->connection_number);
|
||||||
resp->respcode = 200;
|
resp->respcode = 200;
|
||||||
msg_add_header(resp, "Public",
|
msg_add_header(resp, "Public",
|
||||||
@@ -2234,8 +2298,7 @@ void handle_teardown_2(rtsp_conn_info *conn, __attribute__((unused)) rtsp_messag
|
|||||||
rtsp_message *resp) {
|
rtsp_message *resp) {
|
||||||
|
|
||||||
debug(2, "Connection %d from \"%s\": TEARDOWN 2 %s.", conn->connection_number,
|
debug(2, "Connection %d from \"%s\": TEARDOWN 2 %s.", conn->connection_number,
|
||||||
conn->ap2_client_name,
|
conn->ap2_client_name, get_category_string(conn->airplay_stream_category));
|
||||||
get_category_string(conn->airplay_stream_category));
|
|
||||||
debug_log_rtsp_message(2, "TEARDOWN 2: ", req);
|
debug_log_rtsp_message(2, "TEARDOWN 2: ", req);
|
||||||
|
|
||||||
if (conn->player_thread) {
|
if (conn->player_thread) {
|
||||||
@@ -2391,10 +2454,12 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(2, "Connection %d from \"%s\": Initial (i.e. no streams array) SETUP (AirPlay 2) on %s", conn->connection_number,
|
debug(2,
|
||||||
conn->ap2_client_name,
|
"Connection %d from \"%s\": Initial (i.e. no streams array) SETUP (AirPlay 2) on %s",
|
||||||
|
conn->connection_number, conn->ap2_client_name,
|
||||||
get_category_string(conn->airplay_stream_category));
|
get_category_string(conn->airplay_stream_category));
|
||||||
debug_log_rtsp_message_conn(conn, 2, "Initial (i.e. no streams array) SETUP (AirPlay 2) incoming message", req);
|
debug_log_rtsp_message_conn(
|
||||||
|
conn, 2, "Initial (i.e. no streams array) SETUP (AirPlay 2) incoming message", req);
|
||||||
|
|
||||||
// here, we know it's an initial setup and we know the kind of setup being requested
|
// here, we know it's an initial setup and we know the kind of setup being requested
|
||||||
// if it's a full service PTP stream, we get groupUUID, groupContainsGroupLeader and
|
// if it's a full service PTP stream, we get groupUUID, groupContainsGroupLeader and
|
||||||
@@ -2556,7 +2621,6 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
debug(2, "Connection %d: TCP PTP event port opened: %u.", conn->connection_number,
|
debug(2, "Connection %d: TCP PTP event port opened: %u.", conn->connection_number,
|
||||||
conn->local_event_port);
|
conn->local_event_port);
|
||||||
|
|
||||||
|
|
||||||
if (conn->rtp_event_thread != NULL)
|
if (conn->rtp_event_thread != NULL)
|
||||||
debug(1, "previous rtp_event_thread allocation not freed, it seems.");
|
debug(1, "previous rtp_event_thread allocation not freed, it seems.");
|
||||||
conn->ap2_event_receiver_exited = 0;
|
conn->ap2_event_receiver_exited = 0;
|
||||||
@@ -2581,7 +2645,9 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
build_bonjour_strings(conn);
|
build_bonjour_strings(conn);
|
||||||
debug(2, "Connection %d: SETUP mdns_update on %s.", conn->connection_number,
|
debug(2, "Connection %d: SETUP mdns_update on %s.", conn->connection_number,
|
||||||
get_category_string(conn->airplay_stream_category));
|
get_category_string(conn->airplay_stream_category));
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
mdns_update(NULL, secondary_txt_records);
|
mdns_update(NULL, secondary_txt_records);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA
|
#ifdef CONFIG_METADATA
|
||||||
check_and_send_plist_metadata(messagePlist, "name", 'snam');
|
check_and_send_plist_metadata(messagePlist, "name", 'snam');
|
||||||
@@ -2660,10 +2726,12 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
debug(2, "Connection %d from \"%s\": Subsequent (i.e. with streams array) SETUP (AirPlay 2) on %s", conn->connection_number,
|
debug(2,
|
||||||
conn->ap2_client_name,
|
"Connection %d from \"%s\": Subsequent (i.e. with streams array) SETUP (AirPlay 2) on %s",
|
||||||
|
conn->connection_number, conn->ap2_client_name,
|
||||||
get_category_string(conn->airplay_stream_category));
|
get_category_string(conn->airplay_stream_category));
|
||||||
debug_log_rtsp_message_conn(conn, 2, "Subsequent (i.e. with streams array) SETUP (AirPlay 2) incoming message", req);
|
debug_log_rtsp_message_conn(
|
||||||
|
conn, 2, "Subsequent (i.e. with streams array) SETUP (AirPlay 2) incoming message", req);
|
||||||
|
|
||||||
if (conn->airplay_stream_category == ptp_stream) {
|
if (conn->airplay_stream_category == ptp_stream) {
|
||||||
|
|
||||||
@@ -2789,7 +2857,8 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
conn->input_rate = item_value;
|
conn->input_rate = item_value;
|
||||||
debug(4, "Set conn->input_rate: %u.", conn->input_rate);
|
debug(4, "Set conn->input_rate: %u.", conn->input_rate);
|
||||||
} else {
|
} else {
|
||||||
debug(1, "Connection %d. No sample rate (sr) property found in setup.", conn->connection_number);
|
debug(1, "Connection %d. No sample rate (sr) property found in setup.",
|
||||||
|
conn->connection_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
item = plist_dict_get_item(stream0, "spf"); // samples per frame
|
item = plist_dict_get_item(stream0, "spf"); // samples per frame
|
||||||
@@ -2798,7 +2867,8 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
conn->frames_per_packet = item_value;
|
conn->frames_per_packet = item_value;
|
||||||
debug(4, "Set conn->frames_per_packet: %u.", conn->frames_per_packet);
|
debug(4, "Set conn->frames_per_packet: %u.", conn->frames_per_packet);
|
||||||
} else {
|
} else {
|
||||||
debug(1, "Connection %d. No samples per frame (spf) property found in setup.", conn->connection_number);
|
debug(1, "Connection %d. No samples per frame (spf) property found in setup.",
|
||||||
|
conn->connection_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind a new UDP port and get a socket
|
// bind a new UDP port and get a socket
|
||||||
@@ -2813,7 +2883,7 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
conn->local_realtime_audio_port);
|
conn->local_realtime_audio_port);
|
||||||
|
|
||||||
named_pthread_create(&conn->rtp_realtime_audio_thread, NULL, &rtp_realtime_audio_receiver,
|
named_pthread_create(&conn->rtp_realtime_audio_thread, NULL, &rtp_realtime_audio_receiver,
|
||||||
(void *)conn, "ap2_rat_%d", conn->connection_number);
|
(void *)conn, "ap2_ra_%d", conn->connection_number);
|
||||||
plist_dict_set_item(stream0dict, "type", plist_new_uint(96));
|
plist_dict_set_item(stream0dict, "type", plist_new_uint(96));
|
||||||
plist_dict_set_item(stream0dict, "dataPort",
|
plist_dict_set_item(stream0dict, "dataPort",
|
||||||
plist_new_uint(conn->local_realtime_audio_port));
|
plist_new_uint(conn->local_realtime_audio_port));
|
||||||
@@ -2859,8 +2929,8 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
// debug(1, "Connection %d: create rtp_buffered_audio_thread", conn->connection_number);
|
// debug(1, "Connection %d: create rtp_buffered_audio_thread", conn->connection_number);
|
||||||
|
|
||||||
named_pthread_create_with_priority(&conn->rtp_buffered_audio_thread, 2,
|
named_pthread_create_with_priority(&conn->rtp_buffered_audio_thread, 2,
|
||||||
&rtp_buffered_audio_processor, (void *)conn,
|
&rtp_buffered_audio_processor, (void *)conn, "ap2_ba_%d",
|
||||||
"ap2_bat_%d", conn->connection_number);
|
conn->connection_number);
|
||||||
|
|
||||||
plist_dict_set_item(stream0dict, "type", plist_new_uint(103));
|
plist_dict_set_item(stream0dict, "type", plist_new_uint(103));
|
||||||
plist_dict_set_item(stream0dict, "dataPort",
|
plist_dict_set_item(stream0dict, "dataPort",
|
||||||
@@ -2912,7 +2982,8 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
|
|||||||
snprintf(salt_suffix, sizeof(salt_suffix), "%" PRIu64 "", seed);
|
snprintf(salt_suffix, sizeof(salt_suffix), "%" PRIu64 "", seed);
|
||||||
conn->ap2_pairing_context.data_cipher_bundle.cipher_ctx =
|
conn->ap2_pairing_context.data_cipher_bundle.cipher_ctx =
|
||||||
pair_cipher_new(PAIR_SERVER_HOMEKIT, 5, conn->pair_setup_result->shared_secret,
|
pair_cipher_new(PAIR_SERVER_HOMEKIT, 5, conn->pair_setup_result->shared_secret,
|
||||||
conn->pair_setup_result->shared_secret_len, salt_suffix); // last argument is the (possible) dynamic salt suffix
|
conn->pair_setup_result->shared_secret_len,
|
||||||
|
salt_suffix); // last argument is the (possible) dynamic salt suffix
|
||||||
if (conn->ap2_pairing_context.data_cipher_bundle.cipher_ctx != NULL) {
|
if (conn->ap2_pairing_context.data_cipher_bundle.cipher_ctx != NULL) {
|
||||||
conn->ap2_pairing_context.data_cipher_bundle.description = strdup("DataStream");
|
conn->ap2_pairing_context.data_cipher_bundle.description = strdup("DataStream");
|
||||||
// get a port to use as an data port
|
// get a port to use as an data port
|
||||||
@@ -3692,7 +3763,7 @@ static char *make_nonce(void) {
|
|||||||
// int ignore =
|
// int ignore =
|
||||||
if (read(lfd, random, sizeof(random)) != sizeof(random))
|
if (read(lfd, random, sizeof(random)) != sizeof(random))
|
||||||
debug(1, "Error reading /dev/urandom");
|
debug(1, "Error reading /dev/urandom");
|
||||||
close(lfd);
|
safe_socket_close(&lfd);
|
||||||
return base64_enc(random, 8); // returns a pointer to malloc'ed memory
|
return base64_enc(random, 8); // returns a pointer to malloc'ed memory
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3911,8 +3982,7 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
|
|||||||
"%s:%u.",
|
"%s:%u.",
|
||||||
conn->connection_number, conn->fd, conn->client_ip_string, conn->client_rtsp_port,
|
conn->connection_number, conn->fd, conn->client_ip_string, conn->client_rtsp_port,
|
||||||
conn->self_ip_string, conn->self_rtsp_port);
|
conn->self_ip_string, conn->self_rtsp_port);
|
||||||
close(conn->fd);
|
safe_socket_close(&conn->fd);
|
||||||
conn->fd = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
@@ -3923,19 +3993,7 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
|
|||||||
|
|
||||||
// give the event receiver a chance to exit normally, if it exists
|
// give the event receiver a chance to exit normally, if it exists
|
||||||
if (conn->rtp_event_thread != NULL) {
|
if (conn->rtp_event_thread != NULL) {
|
||||||
uint64_t event_receiver_start_wait_time = get_absolute_time_in_ns();
|
|
||||||
int64_t event_receiver_wait_time = 0;
|
|
||||||
do {
|
|
||||||
if (conn->ap2_event_receiver_exited == 0)
|
|
||||||
usleep(50000);
|
|
||||||
event_receiver_wait_time = get_absolute_time_in_ns() - event_receiver_start_wait_time;
|
|
||||||
} while ((conn->ap2_event_receiver_exited == 0) && (event_receiver_wait_time < 2000000000L));
|
|
||||||
|
|
||||||
if (conn->ap2_event_receiver_exited == 0) {
|
|
||||||
debug(2, "Connection %d: %s event receiver has not exited, so cancelling it.",
|
|
||||||
conn->connection_number, get_category_string(conn->airplay_stream_category));
|
|
||||||
pthread_cancel(*conn->rtp_event_thread);
|
pthread_cancel(*conn->rtp_event_thread);
|
||||||
}
|
|
||||||
pthread_join(*conn->rtp_event_thread, NULL);
|
pthread_join(*conn->rtp_event_thread, NULL);
|
||||||
free(conn->rtp_event_thread);
|
free(conn->rtp_event_thread);
|
||||||
conn->rtp_event_thread = NULL;
|
conn->rtp_event_thread = NULL;
|
||||||
@@ -3950,20 +4008,17 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
|
|||||||
if (conn->control_socket) {
|
if (conn->control_socket) {
|
||||||
debug(3, "Connection %d: terminating -- closing control_socket %d.", conn->connection_number,
|
debug(3, "Connection %d: terminating -- closing control_socket %d.", conn->connection_number,
|
||||||
conn->control_socket);
|
conn->control_socket);
|
||||||
close(conn->control_socket);
|
safe_socket_close(&conn->control_socket);
|
||||||
conn->control_socket = 0;
|
|
||||||
}
|
}
|
||||||
if (conn->timing_socket) {
|
if (conn->timing_socket) {
|
||||||
debug(3, "Connection %d: terminating -- closing timing_socket %d.", conn->connection_number,
|
debug(3, "Connection %d: terminating -- closing timing_socket %d.", conn->connection_number,
|
||||||
conn->timing_socket);
|
conn->timing_socket);
|
||||||
close(conn->timing_socket);
|
safe_socket_close(&conn->timing_socket);
|
||||||
conn->timing_socket = 0;
|
|
||||||
}
|
}
|
||||||
if (conn->audio_socket) {
|
if (conn->audio_socket) {
|
||||||
debug(3, "Connection %d: terminating -- closing audio_socket %d.", conn->connection_number,
|
debug(3, "Connection %d: terminating -- closing audio_socket %d.", conn->connection_number,
|
||||||
conn->audio_socket);
|
conn->audio_socket);
|
||||||
close(conn->audio_socket);
|
safe_socket_close(&conn->audio_socket);
|
||||||
conn->audio_socket = 0;
|
|
||||||
}
|
}
|
||||||
if (conn->auth_nonce) {
|
if (conn->auth_nonce) {
|
||||||
free(conn->auth_nonce);
|
free(conn->auth_nonce);
|
||||||
@@ -4038,7 +4093,7 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
|
|||||||
#endif
|
#endif
|
||||||
debug(3, "Connection %d: Closed.", conn->connection_number);
|
debug(3, "Connection %d: Closed.", conn->connection_number);
|
||||||
conn->running = 0; // for the garbage collector
|
conn->running = 0; // for the garbage collector
|
||||||
release_play_lock(conn);
|
// release_play_lock(conn);
|
||||||
pthread_setcancelstate(oldState, NULL);
|
pthread_setcancelstate(oldState, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4137,18 +4192,17 @@ static void *rtsp_conversation_thread_func(void *pconn) {
|
|||||||
msg_add_header(resp, "Server", "AirTunes/105.1");
|
msg_add_header(resp, "Server", "AirTunes/105.1");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// we are only concerned with classic_airplay_authorized if we are running in classic AirPlay
|
||||||
|
// mode either because the build is for classic AirPlay only or, if the build is for AirPlay
|
||||||
// we are only concerned with classic_airplay_authorized if we are running in classic AirPlay mode
|
// 2, we happen to be running in classic AirPlay compatibility mode
|
||||||
// either because the build is for classic AirPlay only or, if the build is for AirPlay 2,
|
|
||||||
// we happen to be running in classic AirPlay compatibility mode
|
|
||||||
|
|
||||||
if ((conn->authorized == 1) ||
|
if ((conn->authorized == 1) ||
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
(conn->airplay_type != ap_1) ||
|
(conn->airplay_type != ap_1) ||
|
||||||
#endif
|
#endif
|
||||||
(rtsp_classic_airplay_auth(&conn->auth_nonce, req, resp) == 0)) {
|
(rtsp_classic_airplay_auth(&conn->auth_nonce, req, resp) == 0)) {
|
||||||
conn->authorized = 1; // it must have been classic airplay and authorized or didn't need a password, or not classic AirPlay at all
|
conn->authorized = 1; // it must have been classic airplay and authorized or didn't need a
|
||||||
|
// password, or not classic AirPlay at all
|
||||||
struct method_handler *mh;
|
struct method_handler *mh;
|
||||||
int method_selected = 0;
|
int method_selected = 0;
|
||||||
for (mh = method_handlers; mh->method; mh++) {
|
for (mh = method_handlers; mh->method; mh++) {
|
||||||
@@ -4208,7 +4262,9 @@ static void *rtsp_conversation_thread_func(void *pconn) {
|
|||||||
so_linger.l_linger = 0;
|
so_linger.l_linger = 0;
|
||||||
err = setsockopt(conn->fd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger);
|
err = setsockopt(conn->fd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger);
|
||||||
if (err)
|
if (err)
|
||||||
debug(1, "Connection %d: Could not set the RTSP socket to abort due to a write error on closing.",
|
debug(1,
|
||||||
|
"Connection %d: Could not set the RTSP socket to abort due to a write error on "
|
||||||
|
"closing.",
|
||||||
conn->connection_number);
|
conn->connection_number);
|
||||||
conn->stop = 1;
|
conn->stop = 1;
|
||||||
// if (debuglev >= 1)
|
// if (debuglev >= 1)
|
||||||
@@ -4237,12 +4293,14 @@ static void *rtsp_conversation_thread_func(void *pconn) {
|
|||||||
debug(1, "rtsp_read_request_response_bad_packet write response error %d: \"%s\".", errno,
|
debug(1, "rtsp_read_request_response_bad_packet write response error %d: \"%s\".", errno,
|
||||||
(char *)errorstring);
|
(char *)errorstring);
|
||||||
} else if (lreply != (ssize_t)strlen(response_text)) {
|
} else if (lreply != (ssize_t)strlen(response_text)) {
|
||||||
debug(1, "rtsp_read_request_response_bad_packet write %zd bytes requested but %d written.",
|
debug(1,
|
||||||
|
"rtsp_read_request_response_bad_packet write %zd bytes requested but %d written.",
|
||||||
strlen(response_text), reply);
|
strlen(response_text), reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
release_play_lock(conn);
|
||||||
pthread_cleanup_pop(1);
|
pthread_cleanup_pop(1);
|
||||||
debug(2, "Connection %d: exit.", conn->connection_number);
|
debug(2, "Connection %d: exit.", conn->connection_number);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
@@ -4271,24 +4329,20 @@ void rtsp_listen_loop_cleanup_handler(__attribute__((unused)) void *arg) {
|
|||||||
int oldState;
|
int oldState;
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
|
||||||
debug(2, "rtsp_listen_loop_cleanup_handler called.");
|
debug(2, "rtsp_listen_loop_cleanup_handler called.");
|
||||||
|
if (conns) {
|
||||||
cancel_all_RTSP_threads(unspecified_stream_category, 0); // kill all RTSP listeners
|
cancel_all_RTSP_threads(unspecified_stream_category, 0); // kill all RTSP listeners
|
||||||
|
free(conns);
|
||||||
|
conns = NULL;
|
||||||
|
}
|
||||||
int *sockfd = (int *)arg;
|
int *sockfd = (int *)arg;
|
||||||
if (sockfd) {
|
if (sockfd) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i <= sockfd[0]; i++) {
|
for (i = 1; i <= sockfd[0]; i++) {
|
||||||
debug(2, "closing socket %d.", sockfd[i]);
|
safe_socket_close(&sockfd[i]);
|
||||||
close(sockfd[i]);
|
|
||||||
}
|
}
|
||||||
free(sockfd);
|
free(sockfd);
|
||||||
}
|
}
|
||||||
pthread_setcancelstate(oldState, NULL);
|
pthread_setcancelstate(oldState, NULL);
|
||||||
int i;
|
|
||||||
for (i = 0; i < nconns; i++) {
|
|
||||||
if (conns[i] != NULL) {
|
|
||||||
free(conns[i]);
|
|
||||||
conns[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *rtsp_listen_loop(__attribute((unused)) void *arg) {
|
void *rtsp_listen_loop(__attribute((unused)) void *arg) {
|
||||||
@@ -4390,16 +4444,16 @@ void *rtsp_listen_loop(__attribute((unused)) void *arg) {
|
|||||||
char **t1 = txt_records; // ap1 text records
|
char **t1 = txt_records; // ap1 text records
|
||||||
char **t2 = NULL; // possibly two text records
|
char **t2 = NULL; // possibly two text records
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
// make up a secondary set of text records
|
// make up a secondary set of text records
|
||||||
t2 = secondary_txt_records; // second set of text records in AirPlay 2 only
|
t2 = secondary_txt_records; // second set of text records in AirPlay 2 only
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
build_bonjour_strings(NULL); // no conn yet
|
build_bonjour_strings(NULL); // no conn yet
|
||||||
// if a thread is created, e.g. Avahi, it'll inherit the name from this thread
|
// if a thread is created, e.g. Avahi, it'll inherit the name from this thread
|
||||||
mdns_register(t1, t2); // note that the dacp thread could still be using the mdns stuff after
|
mdns_register(t1, t2); // note that the dacp thread could still be using the mdns stuff after
|
||||||
// all player threads have been terminated, so mdns_unregister can't be
|
// all player threads have been terminated, so mdns_unregister can't be
|
||||||
// in the rtsp_listen_loop cleanup.
|
// in the rtsp_listen_loop cleanup.
|
||||||
pthread_t tid = pthread_self();
|
|
||||||
do_pthread_setname(&tid, "listener");
|
|
||||||
pthread_setcancelstate(oldState, NULL);
|
pthread_setcancelstate(oldState, NULL);
|
||||||
int acceptfd;
|
int acceptfd;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@@ -4465,7 +4519,7 @@ void *rtsp_listen_loop(__attribute((unused)) void *arg) {
|
|||||||
} else if ((principal_conn != NULL) && (config.allow_session_interruption == 0)) {
|
} else if ((principal_conn != NULL) && (config.allow_session_interruption == 0)) {
|
||||||
debug(1, "Connection %d: %s session interruption not allowed", conn->connection_number,
|
debug(1, "Connection %d: %s session interruption not allowed", conn->connection_number,
|
||||||
get_category_string(conn->airplay_stream_category));
|
get_category_string(conn->airplay_stream_category));
|
||||||
close(conn->fd);
|
safe_socket_close(&conn->fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,30 +24,13 @@ typedef struct {
|
|||||||
void msg_retain(rtsp_message *msg);
|
void msg_retain(rtsp_message *msg);
|
||||||
void msg_free(rtsp_message **msgh);
|
void msg_free(rtsp_message **msgh);
|
||||||
|
|
||||||
extern pthread_rwlock_t principal_conn_lock;
|
|
||||||
extern rtsp_conn_info *principal_conn;
|
|
||||||
extern rtsp_conn_info **conns;
|
|
||||||
|
|
||||||
void *rtsp_listen_loop(__attribute((unused)) void *arg);
|
void *rtsp_listen_loop(__attribute((unused)) void *arg);
|
||||||
|
|
||||||
void lock_player();
|
|
||||||
void unlock_player();
|
|
||||||
|
|
||||||
// result of trying to acquire or release the play lock
|
|
||||||
typedef enum {
|
|
||||||
play_lock_released,
|
|
||||||
play_lock_already_released,
|
|
||||||
play_lock_already_acquired,
|
|
||||||
play_lock_acquired_without_breaking_in,
|
|
||||||
play_lock_acquired_by_breaking_in,
|
|
||||||
play_lock_aquisition_failed
|
|
||||||
} play_lock_r;
|
|
||||||
|
|
||||||
// this can be used to [try to] forcibly stop a play session
|
// this can be used to [try to] forcibly stop a play session
|
||||||
play_lock_r get_play_lock(rtsp_conn_info *conn, int allow_session_interruption);
|
// play_lock_r get_play_lock(rtsp_conn_info *conn, int allow_session_interruption);
|
||||||
// this will release the play lock only if the conn has it or if the conn is NULL
|
// this will release the play lock only if the conn has it or if the conn is NULL
|
||||||
void release_play_lock(rtsp_conn_info *conn);
|
|
||||||
|
|
||||||
|
void stop_play(); // stop and drop a playing connection
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
ssize_t read_encrypted(int fd, pair_cipher_bundle *ctx, void *buf, size_t count);
|
ssize_t read_encrypted(int fd, pair_cipher_bundle *ctx, void *buf, size_t count);
|
||||||
|
|||||||
@@ -14,11 +14,16 @@ general =
|
|||||||
// %v for the version number, e.g. 3.0 and
|
// %v for the version number, e.g. 3.0 and
|
||||||
// %V for the full version string, e.g. 3.3-OpenSSL-Avahi-ALSA-soxr-metadata-sysconfdir:/etc
|
// %V for the full version string, e.g. 3.3-OpenSSL-Avahi-ALSA-soxr-metadata-sysconfdir:/etc
|
||||||
// Overall length can not exceed 50 characters. Example: "Shairport Sync %v on %H".
|
// Overall length can not exceed 50 characters. Example: "Shairport Sync %v on %H".
|
||||||
|
//
|
||||||
// password = "secret"; // leave this commented out if you don't want to require a password
|
// password = "secret"; // leave this commented out if you don't want to require a password
|
||||||
|
// About the "service_type" setting below: On an AirPlay-2-capable Shairport Sync, if you wish to offer only the older "classic" AirPlay (sometimes called AirPlay 1), set service_type to "classic".
|
||||||
|
// A potential use of this would be for Apple Music on Windows, which is not compatible with the AirPlay 2 service offered by Shairport Sync, but which is compatible with the classic service.
|
||||||
|
// The default is "auto", which means that the AirPlay 2 service will be provided if NQPTP is present and "classic" AirPlay will be provided otherwise, with "(Classic)" appended to the service name (see above).
|
||||||
|
// service_type = "auto"; // This can be "auto", "airplay2" or "classic".
|
||||||
// The interpolation setting below controls how Shairport Sync adds or removes frames of audio to keep in sync.
|
// The interpolation setting below controls how Shairport Sync adds or removes frames of audio to keep in sync.
|
||||||
// "auto" (default) measures the processor's floating point speed and chooses "soxr" if available and it is fast enough. Otherwise, "vernier" is selected.
|
// "auto" (default) measures the processor's floating point speed and chooses "soxr" if available and it is fast enough. Otherwise, "vernier" is selected.
|
||||||
// "soxr" uses the SoX library to recode a packet of frames to a new packet containing more or fewer frames. This needs a processor with fast floating point capability.
|
|
||||||
// "vernier" recodes a packet of frames to a new packet containing more or fewer frames. This is recommended for low powered devices.
|
// "vernier" recodes a packet of frames to a new packet containing more or fewer frames. This is recommended for low powered devices.
|
||||||
|
// "soxr" uses the SoX library to recode a packet of frames to a new packet containing more or fewer frames. This needs a processor with fast floating point capability.
|
||||||
// "basic" causes the simple removal or insertion of frames in a packet of frames. Not recommended.
|
// "basic" causes the simple removal or insertion of frames in a packet of frames. Not recommended.
|
||||||
// interpolation = "auto"; // aka "stuffing". Default is "auto". Alternatives are "vernier", "basic" or "soxr". Choose "soxr" only if you have a reasonably fast processor and Shairport Sync has been built with "soxr" support.
|
// interpolation = "auto"; // aka "stuffing". Default is "auto". Alternatives are "vernier", "basic" or "soxr". Choose "soxr" only if you have a reasonably fast processor and Shairport Sync has been built with "soxr" support.
|
||||||
// output_backend = "alsa"; // Run "shairport-sync -h" to get a list of all output_backends, e.g. "alsa", "pipe", "stdout". The default is the first one.
|
// output_backend = "alsa"; // Run "shairport-sync -h" to get a list of all output_backends, e.g. "alsa", "pipe", "stdout". The default is the first one.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ After=sound.target
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network.target network-online.target
|
After=network.target network-online.target
|
||||||
@SYSTEMD_AFTER_ARGS@
|
@SYSTEMD_AFTER_ARGS@
|
||||||
|
@SYSTEMD_WANTS_ARGS@
|
||||||
@SYSTEMD_REQUIRES_ARGS@
|
@SYSTEMD_REQUIRES_ARGS@
|
||||||
StartLimitIntervalSec=300
|
StartLimitIntervalSec=300
|
||||||
StartLimitBurst=5
|
StartLimitBurst=5
|
||||||
|
|||||||
+156
-136
@@ -2,7 +2,7 @@
|
|||||||
* Shairport, an Apple Airplay receiver
|
* Shairport, an Apple Airplay receiver
|
||||||
* Copyright (c) James Laird 2013
|
* Copyright (c) James Laird 2013
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
* Modifications and additions (c) Mike Brady 2014--2025
|
* Modifications and additions (c) Mike Brady 2014--2026
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
* obtaining a copy of this software and associated documentation
|
* obtaining a copy of this software and associated documentation
|
||||||
@@ -50,12 +50,12 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
#include "ptp-utilities.h"
|
#include "ptp-utilities.h"
|
||||||
|
#include "utilities/generate_device_uuid.h"
|
||||||
|
#include "utilities/generate_random_uuid.h"
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
#include "utilities/generate_random_uuid.h"
|
|
||||||
#include "utilities/generate_device_uuid.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -82,6 +82,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "rtp.h"
|
#include "rtp.h"
|
||||||
#include "rtsp.h"
|
#include "rtsp.h"
|
||||||
|
#include "utilities/string_utilities.h"
|
||||||
|
|
||||||
#if defined(CONFIG_DACP_CLIENT)
|
#if defined(CONFIG_DACP_CLIENT)
|
||||||
#include "dacp.h"
|
#include "dacp.h"
|
||||||
@@ -321,6 +322,7 @@ void usage(char *progname) {
|
|||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -h, --help Show this help.\n");
|
printf(" -h, --help Show this help.\n");
|
||||||
printf(" -V, --version Show version information -- the version string.\n");
|
printf(" -V, --version Show version information -- the version string.\n");
|
||||||
|
printf(" --service-type Select the type of AirPlay service: \"auto\", \"airplay2\" or \"classic\". (You can use \"airplay1\" in place of \"classic\".)\n");
|
||||||
printf(" -X, --displayConfig Output OS information, version string, command line, configuration file and active settings to the log.\n");
|
printf(" -X, --displayConfig Output OS information, version string, command line, configuration file and active settings to the log.\n");
|
||||||
printf(" --statistics Print some interesting statistics. More will be printed if -v / -vv / -vvv are also chosen.\n");
|
printf(" --statistics Print some interesting statistics. More will be printed if -v / -vv / -vvv are also chosen.\n");
|
||||||
printf(" -v, --verbose Print debug information; -v some; -vv more; -vvv lots -- generally too much.\n");
|
printf(" -v, --verbose Print debug information; -v some; -vv more; -vvv lots -- generally too much.\n");
|
||||||
@@ -382,6 +384,7 @@ void usage(char *progname) {
|
|||||||
int parse_options(int argc, char **argv) {
|
int parse_options(int argc, char **argv) {
|
||||||
// there are potential memory leaks here -- it's called a second time, previously allocated
|
// there are potential memory leaks here -- it's called a second time, previously allocated
|
||||||
// strings will dangle.
|
// strings will dangle.
|
||||||
|
char *cli_service_type_string = NULL;
|
||||||
char *raw_service_name = NULL; /* Used to pick up the service name before possibly expanding it */
|
char *raw_service_name = NULL; /* Used to pick up the service name before possibly expanding it */
|
||||||
char *stuffing = NULL; /* used for picking up the stuffing option */
|
char *stuffing = NULL; /* used for picking up the stuffing option */
|
||||||
#if defined(CONFIG_DBUS_INTERFACE) || defined(CONFIG_MPRIS_INTERFACE)
|
#if defined(CONFIG_DBUS_INTERFACE) || defined(CONFIG_MPRIS_INTERFACE)
|
||||||
@@ -415,6 +418,7 @@ int parse_options(int argc, char **argv) {
|
|||||||
{"resync", 'r', POPT_ARG_INT, &resync_threshold_in_frames, 'r', NULL, NULL},
|
{"resync", 'r', POPT_ARG_INT, &resync_threshold_in_frames, 'r', NULL, NULL},
|
||||||
{"timeout", 't', POPT_ARG_INT, &config.timeout, 't', NULL, NULL},
|
{"timeout", 't', POPT_ARG_INT, &config.timeout, 't', NULL, NULL},
|
||||||
{"password", 0, POPT_ARG_STRING, &config.password, 0, NULL, NULL},
|
{"password", 0, POPT_ARG_STRING, &config.password, 0, NULL, NULL},
|
||||||
|
{"service-type", 0, POPT_ARG_STRING, &cli_service_type_string, 0, NULL, NULL},
|
||||||
#if defined(CONFIG_DBUS_INTERFACE) || defined(CONFIG_MPRIS_INTERFACE)
|
#if defined(CONFIG_DBUS_INTERFACE) || defined(CONFIG_MPRIS_INTERFACE)
|
||||||
{"dbus-default-message-bus", 0, POPT_ARG_STRING, &dbus_default_message_bus, 0, NULL, NULL},
|
{"dbus-default-message-bus", 0, POPT_ARG_STRING, &dbus_default_message_bus, 0, NULL, NULL},
|
||||||
#endif
|
#endif
|
||||||
@@ -426,8 +430,7 @@ int parse_options(int argc, char **argv) {
|
|||||||
{"metadata-pipename", 0, POPT_ARG_STRING, &config.metadata_pipename, 0, NULL, NULL},
|
{"metadata-pipename", 0, POPT_ARG_STRING, &config.metadata_pipename, 0, NULL, NULL},
|
||||||
{"get-coverart", 'g', POPT_ARG_NONE, &config.get_coverart, 'g', NULL, NULL},
|
{"get-coverart", 'g', POPT_ARG_NONE, &config.get_coverart, 'g', NULL, NULL},
|
||||||
#endif
|
#endif
|
||||||
POPT_AUTOHELP{NULL, 0, 0, NULL, 0, NULL, NULL}
|
POPT_AUTOHELP{NULL, 0, 0, NULL, 0, NULL, NULL}};
|
||||||
};
|
|
||||||
|
|
||||||
// we have to parse the command line arguments to look for a config file
|
// we have to parse the command line arguments to look for a config file
|
||||||
int optind;
|
int optind;
|
||||||
@@ -628,6 +631,10 @@ int parse_options(int argc, char **argv) {
|
|||||||
// make config.cfg point to it
|
// make config.cfg point to it
|
||||||
config.cfg = &config_file_stuff;
|
config.cfg = &config_file_stuff;
|
||||||
|
|
||||||
|
/* See if a specific service type has been requested */
|
||||||
|
if (config_lookup_non_empty_string(config.cfg, "general.service_type", &str)) {
|
||||||
|
config.service_type = string_to_service_type(str, "general service_type");
|
||||||
|
}
|
||||||
/* Get the Service Name. */
|
/* Get the Service Name. */
|
||||||
if (config_lookup_non_empty_string(config.cfg, "general.name", &str)) {
|
if (config_lookup_non_empty_string(config.cfg, "general.name", &str)) {
|
||||||
raw_service_name = (char *)str;
|
raw_service_name = (char *)str;
|
||||||
@@ -680,8 +687,7 @@ int parse_options(int argc, char **argv) {
|
|||||||
* starting at the port base. Only three ports are needed. */
|
* starting at the port base. Only three ports are needed. */
|
||||||
if (config_lookup_int(config.cfg, "general.udp_port_range", &value)) {
|
if (config_lookup_int(config.cfg, "general.udp_port_range", &value)) {
|
||||||
if ((value < 3) || (value > 65535))
|
if ((value < 3) || (value > 65535))
|
||||||
die("Invalid port range \"%d\". It should be between 3 and 65535, default is 10",
|
die("Invalid port range \"%d\". It should be between 3 and 65535, default is 10", value);
|
||||||
value);
|
|
||||||
else
|
else
|
||||||
config.udp_port_range = value;
|
config.udp_port_range = value;
|
||||||
}
|
}
|
||||||
@@ -1297,15 +1303,6 @@ int parse_options(int argc, char **argv) {
|
|||||||
"controlled by a hardware mixer. "
|
"controlled by a hardware mixer. "
|
||||||
"You must not use a hardware mixer when using the loudness filter.");
|
"You must not use a hardware mixer when using the loudness filter.");
|
||||||
|
|
||||||
} else {
|
|
||||||
if (config_error_type(&config_file_stuff) == CONFIG_ERR_FILE_IO)
|
|
||||||
die("Error reading configuration file \"%s\": \"%s\".", config_file_real_path,
|
|
||||||
config_error_text(&config_file_stuff));
|
|
||||||
else {
|
|
||||||
die("Line %d of the configuration file \"%s\":\n%s", config_error_line(&config_file_stuff),
|
|
||||||
config_error_file(&config_file_stuff), config_error_text(&config_file_stuff));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if defined(CONFIG_DBUS_INTERFACE)
|
#if defined(CONFIG_DBUS_INTERFACE)
|
||||||
/* Get the dbus service sbus setting. */
|
/* Get the dbus service sbus setting. */
|
||||||
if (config_lookup_string(config.cfg, "general.dbus_service_bus", &str)) {
|
if (config_lookup_string(config.cfg, "general.dbus_service_bus", &str)) {
|
||||||
@@ -1328,7 +1325,8 @@ int parse_options(int argc, char **argv) {
|
|||||||
else if (strcasecmp(str, "session") == 0)
|
else if (strcasecmp(str, "session") == 0)
|
||||||
config.mpris_service_bus_type = DBT_session;
|
config.mpris_service_bus_type = DBT_session;
|
||||||
else
|
else
|
||||||
die("Invalid mpris_service_bus option choice \"%s\". It should be \"system\" (default) or "
|
die("Invalid mpris_service_bus option choice \"%s\". It should be \"system\" (default) "
|
||||||
|
"or "
|
||||||
"\"session\"",
|
"\"session\"",
|
||||||
str);
|
str);
|
||||||
}
|
}
|
||||||
@@ -1391,7 +1389,8 @@ int parse_options(int argc, char **argv) {
|
|||||||
config_set_lookup_bool(config.cfg, "mqtt.publish_cover", &config.mqtt_publish_cover);
|
config_set_lookup_bool(config.cfg, "mqtt.publish_cover", &config.mqtt_publish_cover);
|
||||||
config_set_lookup_bool(config.cfg, "mqtt.publish_retain", &config.mqtt_publish_retain);
|
config_set_lookup_bool(config.cfg, "mqtt.publish_retain", &config.mqtt_publish_retain);
|
||||||
if (config.mqtt_publish_cover && !config.get_coverart) {
|
if (config.mqtt_publish_cover && !config.get_coverart) {
|
||||||
die("You need to have metadata.include_cover_art enabled in order to use mqtt.publish_cover");
|
die("You need to have metadata.include_cover_art enabled in order to use "
|
||||||
|
"mqtt.publish_cover");
|
||||||
}
|
}
|
||||||
config_set_lookup_bool(config.cfg, "mqtt.enable_autodiscovery",
|
config_set_lookup_bool(config.cfg, "mqtt.enable_autodiscovery",
|
||||||
&config.mqtt_enable_autodiscovery);
|
&config.mqtt_enable_autodiscovery);
|
||||||
@@ -1414,7 +1413,7 @@ int parse_options(int argc, char **argv) {
|
|||||||
"avahi enabled, or disable remote control.");
|
"avahi enabled, or disable remote control.");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
long long aid;
|
long long aid;
|
||||||
|
|
||||||
@@ -1428,9 +1427,17 @@ int parse_options(int argc, char **argv) {
|
|||||||
temporary_airplay_id += aid;
|
temporary_airplay_id += aid;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (config_error_type(&config_file_stuff) == CONFIG_ERR_FILE_IO)
|
||||||
|
die("Error reading configuration file \"%s\": \"%s\".", config_file_real_path,
|
||||||
|
config_error_text(&config_file_stuff));
|
||||||
|
else {
|
||||||
|
die("Line %d of the configuration file \"%s\":\n%s", config_error_line(&config_file_stuff),
|
||||||
|
config_error_file(&config_file_stuff), config_error_text(&config_file_stuff));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now, do the command line options again, but this time do them fully -- it's a unix convention
|
// now, do the command line options again, but this time do them fully -- it's a unix convention
|
||||||
@@ -1497,6 +1504,10 @@ int parse_options(int argc, char **argv) {
|
|||||||
die("%s: %s", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
|
die("%s: %s", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cli_service_type_string != NULL)
|
||||||
|
config.service_type = string_to_service_type(cli_service_type_string,
|
||||||
|
"command line option \"--service-type\" argument");
|
||||||
|
|
||||||
poptFreeContext(optCon);
|
poptFreeContext(optCon);
|
||||||
|
|
||||||
#if defined(CONFIG_DBUS_INTERFACE) || (CONFIG_MPRIS_INTERFACE)
|
#if defined(CONFIG_DBUS_INTERFACE) || (CONFIG_MPRIS_INTERFACE)
|
||||||
@@ -1527,6 +1538,7 @@ int parse_options(int argc, char **argv) {
|
|||||||
|
|
||||||
config.nqptp_shared_memory_interface_name = strdup(NQPTP_INTERFACE_NAME);
|
config.nqptp_shared_memory_interface_name = strdup(NQPTP_INTERFACE_NAME);
|
||||||
|
|
||||||
|
// create the config.ap1_prefix[i]
|
||||||
char apids[6 * 2 + 5 + 1]; // six pairs of digits, 5 colons and a NUL
|
char apids[6 * 2 + 5 + 1]; // six pairs of digits, 5 colons and a NUL
|
||||||
apids[6 * 2 + 5] = 0; // NUL termination
|
apids[6 * 2 + 5] = 0; // NUL termination
|
||||||
int i;
|
int i;
|
||||||
@@ -1555,15 +1567,13 @@ int parse_options(int argc, char **argv) {
|
|||||||
else
|
else
|
||||||
memcpy(result, config.ap1_prefix, sizeof(result));
|
memcpy(result, config.ap1_prefix, sizeof(result));
|
||||||
|
|
||||||
// OpenSSL is mandatory for AirPlay 2 anyway
|
// OpenSSL is mandatory for AirPlay 2
|
||||||
#ifdef CONFIG_OPENSSL
|
|
||||||
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
|
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
|
||||||
EVP_DigestInit_ex(mdctx, EVP_md5(), NULL);
|
EVP_DigestInit_ex(mdctx, EVP_md5(), NULL);
|
||||||
EVP_DigestUpdate(mdctx, config.ap1_prefix, sizeof(config.ap1_prefix));
|
EVP_DigestUpdate(mdctx, config.ap1_prefix, sizeof(config.ap1_prefix));
|
||||||
unsigned int md5_digest_len = EVP_MD_size(EVP_md5());
|
unsigned int md5_digest_len = EVP_MD_size(EVP_md5());
|
||||||
EVP_DigestFinal_ex(mdctx, result, &md5_digest_len);
|
EVP_DigestFinal_ex(mdctx, result, &md5_digest_len);
|
||||||
EVP_MD_CTX_free(mdctx);
|
EVP_MD_CTX_free(mdctx);
|
||||||
#endif
|
|
||||||
|
|
||||||
// now, convert it into a type 4 UUID
|
// now, convert it into a type 4 UUID
|
||||||
// see https://stackoverflow.com/questions/10867405/generating-v5-uuid-what-is-name-and-namespace
|
// see https://stackoverflow.com/questions/10867405/generating-v5-uuid-what-is-name-and-namespace
|
||||||
@@ -1597,10 +1607,10 @@ int parse_options(int argc, char **argv) {
|
|||||||
// 496155702020608 this setting here is the source of both the plist features response and the
|
// 496155702020608 this setting here is the source of both the plist features response and the
|
||||||
// mDNS string.
|
// mDNS string.
|
||||||
|
|
||||||
config.airplay_features =
|
config.airplay_features = 0x00018340405C4A00; // no AP2 metadata (b50), no AP1 text (b17), no AP1
|
||||||
0x00018340405C4A00; // no AP2 metadata (b50), no AP1 text (b17), no AP1 progress (b16), no AP1 artwork (b15)
|
// progress (b16), no AP1 artwork (b15)
|
||||||
// 0x0001C340405C4A00; // no AP2 metadata (b50), no AP1 text (b17), no AP1 progress (b16), no AP1 artwork (b15)
|
// 0x0001C340405C4A00; // no AP2 metadata (b50), no AP1 text (b17), no AP1 progress (b16), no
|
||||||
// 0x0001C340445D0A00;
|
// AP1 artwork (b15) 0x0001C340445D0A00;
|
||||||
// config.airplay_features |= (1 << 26); // 0x0x4000000
|
// config.airplay_features |= (1 << 26); // 0x0x4000000
|
||||||
|
|
||||||
// features=0x0001C340445D0A00 -- AirPort Express
|
// features=0x0001C340445D0A00 -- AirPort Express
|
||||||
@@ -1620,8 +1630,10 @@ int parse_options(int argc, char **argv) {
|
|||||||
// provides much more information, so should be the default for AirPlay 2
|
// provides much more information, so should be the default for AirPlay 2
|
||||||
|
|
||||||
if (config.metadata_enabled != 0) {
|
if (config.metadata_enabled != 0) {
|
||||||
config.airplay_features |= (uint64_t)1 << 50; // metadata in a binary plist, including more state information
|
config.airplay_features |=
|
||||||
// config.airplay_features |= ((uint64_t)1 << 15) | ((uint64_t)1 << 16) | ((uint64_t)1 << 17); // older metadata flags artwork, progress and text respectively
|
(uint64_t)1 << 50; // metadata in a binary plist, including more state information
|
||||||
|
// config.airplay_features |= ((uint64_t)1 << 15) | ((uint64_t)1 << 16) | ((uint64_t)1 << 17);
|
||||||
|
// // older metadata flags artwork, progress and text respectively
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1708,34 +1720,88 @@ int parse_options(int argc, char **argv) {
|
|||||||
config.airplay_volume =
|
config.airplay_volume =
|
||||||
config.default_airplay_volume; // if no volume is ever set or requested, default to initial
|
config.default_airplay_volume; // if no volume is ever set or requested, default to initial
|
||||||
// default value if nothing else comes in first.
|
// default value if nothing else comes in first.
|
||||||
// now, do the substitutions in the service name
|
|
||||||
char hostname[100];
|
|
||||||
gethostname(hostname, 100);
|
|
||||||
|
|
||||||
// strip off a terminating .<anything>, e.g. .local from the hostname
|
// let's see if we have AirPlay 2 and NQPTP is installed or not and set service_type accordingly
|
||||||
char *last_dot = strrchr(hostname, '.');
|
// or exit. the outcome will be APST_airplay2, APST_classic or APST_forced_classic, and APST_auto
|
||||||
if (last_dot != NULL)
|
// will be gone.
|
||||||
*last_dot = '\0';
|
|
||||||
|
|
||||||
char *i0;
|
char service_type_string[32];
|
||||||
if (raw_service_name == NULL)
|
service_type_to_string(config.service_type, service_type_string);
|
||||||
i0 = strdup("%H"); // this is the default it the Service Name wasn't specified
|
debug(1, "config.service_type is: \"%s\".", service_type_string);
|
||||||
else
|
|
||||||
i0 = strdup(raw_service_name);
|
|
||||||
|
|
||||||
// here, do the substitutions for %h, %H, %v and %V
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
char *i1 = str_replace(i0, "%h", hostname);
|
// don't bother checking for NQPTP if we are providing a classic service
|
||||||
if ((hostname[0] >= 'a') && (hostname[0] <= 'z'))
|
if (config.service_type != APST_classic) {
|
||||||
hostname[0] = hostname[0] - 0x20; // convert a lowercase first letter into a capital letter
|
ptp_send_control_message_string(
|
||||||
char *i2 = str_replace(i1, "%H", hostname);
|
"T"); // send this message to get nqptp to create the named shm interface
|
||||||
char *i3 = str_replace(i2, "%v", PACKAGE_VERSION);
|
int response = 0;
|
||||||
char *vs = get_version_string();
|
/*
|
||||||
config.service_name = str_replace(i3, "%V", vs); // service name complete
|
uint64_t nqptp_start_waiting_time = get_absolute_time_in_ns();
|
||||||
free(i0);
|
int continue_waiting = 0;
|
||||||
free(i1);
|
int64_t time_spent_waiting = 0;
|
||||||
free(i2);
|
do {
|
||||||
free(i3);
|
continue_waiting = 0;
|
||||||
free(vs);
|
response = ptp_shm_interface_open();
|
||||||
|
if ((response == -1) && (errno == ENOENT)) {
|
||||||
|
time_spent_waiting = get_absolute_time_in_ns() - nqptp_start_waiting_time;
|
||||||
|
if (time_spent_waiting < 10000000000L) {
|
||||||
|
continue_waiting = 1;
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (continue_waiting != 0);
|
||||||
|
*/
|
||||||
|
|
||||||
|
response = ptp_shm_interface_open(); // look for NQPTP service
|
||||||
|
|
||||||
|
if ((response == -1) && (errno == ENOENT)) {
|
||||||
|
debug(1, "NQPTP service not found.");
|
||||||
|
// change auto to forced classic
|
||||||
|
if (config.service_type == APST_auto) {
|
||||||
|
config.service_type = APST_forced_classic;
|
||||||
|
} else if (config.service_type == APST_airplay2) {
|
||||||
|
die("The NQPTP service can not be found. NQPTP must be installed and running to provide "
|
||||||
|
"AirPlay 2 service.");
|
||||||
|
}
|
||||||
|
} else if ((response == -1) && (errno == EACCES)) {
|
||||||
|
die("Shairport Sync must have read access to the NQPTP shared memory file in /dev/shm/.");
|
||||||
|
} else if (response != 0) {
|
||||||
|
die("an error occurred accessing the NQPTP service.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response == 0) {
|
||||||
|
// change "auto" to "airplay2"
|
||||||
|
if (config.service_type == APST_auto) {
|
||||||
|
config.service_type = APST_airplay2;
|
||||||
|
}
|
||||||
|
// check that the version of Shairport Sync and NQPTP match...
|
||||||
|
debug(1, "NQPTP service found.");
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
|
// now that we are using AirPlay 2, check NQPTP and SPS match...
|
||||||
|
int ptp_clock_version = ptp_get_clock_version();
|
||||||
|
if (ptp_clock_version == 0) {
|
||||||
|
die("The NQPTP service on this system, which is required for Shairport Sync to operate, "
|
||||||
|
"does "
|
||||||
|
"not seem to be initialised.");
|
||||||
|
} else if (ptp_clock_version < NQPTP_SHM_STRUCTURES_VERSION) {
|
||||||
|
die("The NQPTP service (SMI Version %d) on this system is too old for this version of "
|
||||||
|
"Shairport Sync, which requires SMI Version %d. Please update.",
|
||||||
|
ptp_clock_version, NQPTP_SHM_STRUCTURES_VERSION);
|
||||||
|
} else if (ptp_clock_version > NQPTP_SHM_STRUCTURES_VERSION) {
|
||||||
|
die("This version of Shairport Sync (SMI Version %d) is too old for the version of NQPTP "
|
||||||
|
"(SMI "
|
||||||
|
"Version %d) on this system. Please update.",
|
||||||
|
NQPTP_SHM_STRUCTURES_VERSION, ptp_clock_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// if we don't have AirPLay 2, the service type must be classic
|
||||||
|
config.service_type = APST_classic;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
config.service_name = service_name(raw_service_name);
|
||||||
|
|
||||||
#ifdef CONFIG_MQTT
|
#ifdef CONFIG_MQTT
|
||||||
// mqtt topic was not set. As we have the service name just now, set it
|
// mqtt topic was not set. As we have the service name just now, set it
|
||||||
@@ -1905,9 +1971,6 @@ void exit_function() {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (conns)
|
|
||||||
free(conns); // make sure the connections have been deleted first
|
|
||||||
|
|
||||||
if (config.service_name)
|
if (config.service_name)
|
||||||
free(config.service_name);
|
free(config.service_name);
|
||||||
|
|
||||||
@@ -2328,7 +2391,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
config.log_fd = -1;
|
config.log_fd = -1;
|
||||||
conns = NULL; // no connections active
|
|
||||||
|
|
||||||
#ifdef CONFIG_LIBDAEMON
|
#ifdef CONFIG_LIBDAEMON
|
||||||
daemon_set_verbosity(LOG_DEBUG);
|
daemon_set_verbosity(LOG_DEBUG);
|
||||||
@@ -2340,6 +2402,8 @@ int main(int argc, char **argv) {
|
|||||||
debug(1, "adding the exit function");
|
debug(1, "adding the exit function");
|
||||||
atexit(exit_function);
|
atexit(exit_function);
|
||||||
|
|
||||||
|
config.service_type = APST_auto; // this may be changed by the settings...
|
||||||
|
|
||||||
// get a device id -- the first non-local MAC address
|
// get a device id -- the first non-local MAC address
|
||||||
get_device_id((uint8_t *)&config.hw_addr, 6);
|
get_device_id((uint8_t *)&config.hw_addr, 6);
|
||||||
|
|
||||||
@@ -2389,12 +2453,6 @@ int main(int argc, char **argv) {
|
|||||||
config.resync_threshold = 0.050; // default
|
config.resync_threshold = 0.050; // default
|
||||||
config.tolerance = 0.002;
|
config.tolerance = 0.002;
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
|
||||||
config.port = 7000;
|
|
||||||
#else
|
|
||||||
config.port = 5000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SOXR
|
#ifdef CONFIG_SOXR
|
||||||
config.packet_stuffing = ST_auto; // use soxr interpolation by default if support has been
|
config.packet_stuffing = ST_auto; // use soxr interpolation by default if support has been
|
||||||
// included and if the CPU is fast enough
|
// included and if the CPU is fast enough
|
||||||
@@ -2402,10 +2460,6 @@ int main(int argc, char **argv) {
|
|||||||
config.packet_stuffing = ST_vernier; // you need to explicitly ask for "basic" (ST_basic)
|
config.packet_stuffing = ST_vernier; // you need to explicitly ask for "basic" (ST_basic)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// char hostname[100];
|
|
||||||
// gethostname(hostname, 100);
|
|
||||||
// config.service_name = malloc(20 + 100);
|
|
||||||
// snprintf(config.service_name, 20 + 100, "Shairport Sync on %s", hostname);
|
|
||||||
set_requested_connection_state_to_output(
|
set_requested_connection_state_to_output(
|
||||||
1); // we expect to be able to connect to the output device
|
1); // we expect to be able to connect to the output device
|
||||||
config.audio_backend_buffer_desired_length = 0.15; // seconds
|
config.audio_backend_buffer_desired_length = 0.15; // seconds
|
||||||
@@ -2465,13 +2519,6 @@ int main(int argc, char **argv) {
|
|||||||
// parse arguments into config -- needed to locate pid_dir
|
// parse arguments into config -- needed to locate pid_dir
|
||||||
int audio_arg = parse_options(argc, argv);
|
int audio_arg = parse_options(argc, argv);
|
||||||
|
|
||||||
// mDNS supports maximum of 63-character names (we append 13).
|
|
||||||
if (strlen(config.service_name) > 50) {
|
|
||||||
warn("The service name \"%s\" is too long (max 50 characters) and has been truncated.",
|
|
||||||
config.service_name);
|
|
||||||
config.service_name[50] = '\0'; // truncate it and carry on...
|
|
||||||
}
|
|
||||||
|
|
||||||
if (display_config_selected != 0) {
|
if (display_config_selected != 0) {
|
||||||
display_config(argc, argv);
|
display_config(argc, argv);
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
@@ -2601,21 +2648,36 @@ int main(int argc, char **argv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
|
config.port = 7000;
|
||||||
|
} else {
|
||||||
|
config.port = 5000;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
config.port = 5000;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
if (config.service_type == APST_airplay2) {
|
||||||
if (has_fltp_capable_aac_decoder() == 0) {
|
if (has_fltp_capable_aac_decoder() == 0) {
|
||||||
die("Shairport Sync can not run on this system. Run \"shairport-sync -h\" for more "
|
die("Shairport Sync can not run on this system. Run \"shairport-sync -h\" for more "
|
||||||
"information.");
|
"information.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
uint64_t apf = config.airplay_features;
|
uint64_t apf = config.airplay_features;
|
||||||
uint64_t apfh = config.airplay_features;
|
uint64_t apfh = config.airplay_features;
|
||||||
apfh = apfh >> 32;
|
apfh = apfh >> 32;
|
||||||
uint32_t apf32 = apf;
|
uint32_t apf32 = apf;
|
||||||
uint32_t apfh32 = apfh;
|
uint32_t apfh32 = apfh;
|
||||||
debug(1, "Startup in AirPlay 2 mode, with features 0x%" PRIx32 ",0x%" PRIx32 " on device \"%s\".",
|
if (config.service_type == APST_airplay2) {
|
||||||
|
debug(1,
|
||||||
|
"Startup in AirPlay 2 mode, with features 0x%" PRIx32 ",0x%" PRIx32 " on device \"%s\".",
|
||||||
apf32, apfh32, config.airplay_device_id);
|
apf32, apfh32, config.airplay_device_id);
|
||||||
|
} else {
|
||||||
|
debug(1, "Startup in Classic AirPlay (aka \"AirPlay 1\") mode. (AirPlay2 build.)");
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
debug(1, "Startup in classic Airplay (aka \"AirPlay 1\") mode.");
|
debug(1, "Startup in Classic AirPlay (aka \"AirPlay 1\") mode.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// control-c (SIGINT) cleanly
|
// control-c (SIGINT) cleanly
|
||||||
@@ -2950,8 +3012,8 @@ int main(int argc, char **argv) {
|
|||||||
debug(2, "output channel %d is \"%s\".", i, config.output_channel_map[i]);
|
debug(2, "output channel %d is \"%s\".", i, config.output_channel_map[i]);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
warn("during channel mapping, \"%s\" was not recognised as a channel name -- as a "
|
||||||
warn("during channel mapping, \"%s\" was not recognised as a channel name -- as a result, output channel %d will be silent.",
|
"result, output channel %d will be silent.",
|
||||||
channel_id, i);
|
channel_id, i);
|
||||||
config.output_channel_map[i] = strdup("--");
|
config.output_channel_map[i] = strdup("--");
|
||||||
}
|
}
|
||||||
@@ -3158,7 +3220,6 @@ int main(int argc, char **argv) {
|
|||||||
debug(1, "couldn't get memory to start the soxr_checker");
|
debug(1, "couldn't get memory to start the soxr_checker");
|
||||||
}
|
}
|
||||||
pthread_setcancelstate(oldState, NULL); // make this un-cancellable
|
pthread_setcancelstate(oldState, NULL); // make this un-cancellable
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -3208,11 +3269,14 @@ int main(int argc, char **argv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// In AirPlay 2 mode, the AP1 prefix is the same as the device ID less the colons
|
// In AirPlay 2 mode, the AP1 prefix is the same as the device ID less the colons
|
||||||
|
// and has already been calculated.
|
||||||
|
|
||||||
// In AirPlay 1 mode, the AP1 prefix is calculated by hashing the service name.
|
// In AirPlay 1 mode, the AP1 prefix is calculated by hashing the service name.
|
||||||
#ifndef CONFIG_AIRPLAY_2
|
|
||||||
|
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
if (config.service_type != APST_airplay2) {
|
||||||
|
#endif
|
||||||
uint8_t ap_md5[16];
|
uint8_t ap_md5[16];
|
||||||
|
|
||||||
// debug(1, "size of hw_addr is %u.", sizeof(config.hw_addr));
|
// debug(1, "size of hw_addr is %u.", sizeof(config.hw_addr));
|
||||||
#ifdef CONFIG_OPENSSL
|
#ifdef CONFIG_OPENSSL
|
||||||
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
|
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
|
||||||
@@ -3228,7 +3292,8 @@ int main(int argc, char **argv) {
|
|||||||
#if MBEDTLS_VERSION_MINOR >= 7
|
#if MBEDTLS_VERSION_MINOR >= 7
|
||||||
mbedtls_md5_context tctx;
|
mbedtls_md5_context tctx;
|
||||||
mbedtls_md5_starts_ret(&tctx);
|
mbedtls_md5_starts_ret(&tctx);
|
||||||
mbedtls_md5_update_ret(&tctx, (unsigned char *)config.service_name, strlen(config.service_name));
|
mbedtls_md5_update_ret(&tctx, (unsigned char *)config.service_name,
|
||||||
|
strlen(config.service_name));
|
||||||
mbedtls_md5_update_ret(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
|
mbedtls_md5_update_ret(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
|
||||||
mbedtls_md5_finish_ret(&tctx, ap_md5);
|
mbedtls_md5_finish_ret(&tctx, ap_md5);
|
||||||
#else
|
#else
|
||||||
@@ -3247,8 +3312,10 @@ int main(int argc, char **argv) {
|
|||||||
md5_update(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
|
md5_update(&tctx, (unsigned char *)config.hw_addr, sizeof(config.hw_addr));
|
||||||
md5_finish(&tctx, ap_md5);
|
md5_finish(&tctx, ap_md5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memcpy(config.ap1_prefix, ap_md5, sizeof(config.ap1_prefix));
|
memcpy(config.ap1_prefix, ap_md5, sizeof(config.ap1_prefix));
|
||||||
|
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA
|
#ifdef CONFIG_METADATA
|
||||||
@@ -3275,55 +3342,6 @@ int main(int argc, char **argv) {
|
|||||||
glib_worker_thread = g_thread_new("glib worker", glib_worker_thread_function, NULL);
|
glib_worker_thread = g_thread_new("glib worker", glib_worker_thread_function, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
|
||||||
|
|
||||||
ptp_send_control_message_string(
|
|
||||||
"T"); // send this message to get nqptp to create the named shm interface
|
|
||||||
uint64_t nqptp_start_waiting_time = get_absolute_time_in_ns();
|
|
||||||
int continue_waiting = 0;
|
|
||||||
int response = 0;
|
|
||||||
int64_t time_spent_waiting = 0;
|
|
||||||
do {
|
|
||||||
continue_waiting = 0;
|
|
||||||
response = ptp_shm_interface_open();
|
|
||||||
if ((response == -1) && (errno == ENOENT)) {
|
|
||||||
time_spent_waiting = get_absolute_time_in_ns() - nqptp_start_waiting_time;
|
|
||||||
if (time_spent_waiting < 10000000000L) {
|
|
||||||
continue_waiting = 1;
|
|
||||||
usleep(50000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (continue_waiting != 0);
|
|
||||||
|
|
||||||
if ((response == -1) && (errno == ENOENT)) {
|
|
||||||
die("Shairport Sync can not find the nqptp service on this system. Is nqptp installed and "
|
|
||||||
"running?");
|
|
||||||
} else if ((response == -1) && (errno == EACCES)) {
|
|
||||||
die("Shairport Sync must have read access to the nqptp shared memory file in /dev/shm/.");
|
|
||||||
} else if (response != 0) {
|
|
||||||
die("an error occurred accessing the nqptp service.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int ptp_clock_version = ptp_get_clock_version();
|
|
||||||
if (ptp_clock_version == 0) {
|
|
||||||
die("The nqptp service on this system, which is required for Shairport Sync to operate, does "
|
|
||||||
"not seem to be initialised.");
|
|
||||||
} else if (ptp_clock_version < NQPTP_SHM_STRUCTURES_VERSION) {
|
|
||||||
die("The nqptp service (SMI Version %d) on this system is too old for this version of "
|
|
||||||
"Shairport Sync, which requires SMI Version %d. Please update.",
|
|
||||||
ptp_clock_version, NQPTP_SHM_STRUCTURES_VERSION);
|
|
||||||
} else if (ptp_clock_version > NQPTP_SHM_STRUCTURES_VERSION) {
|
|
||||||
die("This version of Shairport Sync (SMI Version %d) is too old for the version of nqptp (SMI "
|
|
||||||
"Version %d) on this system. Please update.",
|
|
||||||
NQPTP_SHM_STRUCTURES_VERSION, ptp_clock_version);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time_spent_waiting == 0)
|
|
||||||
debug(1, "NQPTP is online.");
|
|
||||||
else
|
|
||||||
debug(1, "NQPTP came online after %.3f milliseconds.", 0.000001 * time_spent_waiting);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_METADATA
|
#ifdef CONFIG_METADATA
|
||||||
send_ssnc_metadata('svna', config.service_name, strlen(config.service_name), 1);
|
send_ssnc_metadata('svna', config.service_name, strlen(config.service_name), 1);
|
||||||
#endif
|
#endif
|
||||||
@@ -3332,8 +3350,10 @@ int main(int argc, char **argv) {
|
|||||||
convolver_pool_init(config.convolution_threads, 8); // 8 channels
|
convolver_pool_init(config.convolution_threads, 8); // 8 channels
|
||||||
#endif
|
#endif
|
||||||
activity_monitor_start();
|
activity_monitor_start();
|
||||||
debug(3, "create an RTSP listener");
|
debug(4, "create an RTSP listener");
|
||||||
named_pthread_create(&rtsp_listener_thread, NULL, &rtsp_listen_loop, NULL, "bonjour");
|
// note: the Avahi Threaded Poll thread will be named after whatever name you use here too, so
|
||||||
|
// you'll see two threads named "listener" or whatever...
|
||||||
|
named_pthread_create(&rtsp_listener_thread, NULL, &rtsp_listen_loop, NULL, "listener");
|
||||||
atexit(exit_rtsp_listener);
|
atexit(exit_rtsp_listener);
|
||||||
pthread_join(rtsp_listener_thread, NULL);
|
pthread_join(rtsp_listener_thread, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+7
-6
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include "tinysvcmdns.h"
|
#include "tinysvcmdns.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "utilities/network_utilities.h"
|
||||||
|
|
||||||
#define DEBUG_PRINTF(...) debug(3, __VA_ARGS__)
|
#define DEBUG_PRINTF(...) debug(3, __VA_ARGS__)
|
||||||
#define log_message(level, ...) \
|
#define log_message(level, ...) \
|
||||||
@@ -1457,11 +1458,11 @@ int write_pipe(int s, char *buf, int len) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int close_pipe(int s) {
|
int close_pipe(int *s) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return closesocket(s);
|
return closesocket(*s);
|
||||||
#else
|
#else
|
||||||
return close(s);
|
return safe_socket_close(s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1566,7 +1567,7 @@ void *main_loop(struct mdnsd *svr) {
|
|||||||
|
|
||||||
free(pkt_buffer);
|
free(pkt_buffer);
|
||||||
|
|
||||||
close_pipe(svr->sockfd);
|
close_pipe(&svr->sockfd);
|
||||||
|
|
||||||
svr->stop_flag = 2;
|
svr->stop_flag = 2;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1749,8 +1750,8 @@ void mdnsd_stop(struct mdnsd *s) {
|
|||||||
while (s->stop_flag != 2)
|
while (s->stop_flag != 2)
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
|
|
||||||
close_pipe(s->notify_pipe[0]);
|
close_pipe(&s->notify_pipe[0]);
|
||||||
close_pipe(s->notify_pipe[1]);
|
close_pipe(&s->notify_pipe[1]);
|
||||||
|
|
||||||
pthread_mutex_destroy(&s->data_lock);
|
pthread_mutex_destroy(&s->data_lock);
|
||||||
rr_group_destroy(s->group);
|
rr_group_destroy(s->group);
|
||||||
|
|||||||
@@ -27,9 +27,10 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include "buffered_read.h"
|
#include "buffered_read.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
ssize_t buffered_read(buffered_tcp_desc *descriptor, void *buf, size_t count,
|
ssize_t buffered_read(buffered_tcp_desc *descriptor, void *buf, size_t count,
|
||||||
size_t *bytes_remaining) {
|
size_t *bytes_remaining) {
|
||||||
@@ -110,8 +111,8 @@ void *buffered_tcp_reader(void *arg) {
|
|||||||
int finished = 0;
|
int finished = 0;
|
||||||
int fd = accept(descriptor->sock_fd, (struct sockaddr *)&remote_addr, &addr_size);
|
int fd = accept(descriptor->sock_fd, (struct sockaddr *)&remote_addr, &addr_size);
|
||||||
// debug(1, "buffered_tcp_reader: the client has opened a buffered audio link.");
|
// debug(1, "buffered_tcp_reader: the client has opened a buffered audio link.");
|
||||||
intptr_t pfd = fd;
|
// intptr_t pfd = fd;
|
||||||
pthread_cleanup_push(socket_cleanup, (void *)pfd);
|
pthread_cleanup_push(socket_cleanup, (void *)&fd);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int have_time_to_sleep = 0;
|
int have_time_to_sleep = 0;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#ifndef _BUFFERED_READ_H
|
#pragma once
|
||||||
#define _BUFFERED_READ_H
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int closed;
|
int closed;
|
||||||
@@ -20,5 +22,3 @@ void *buffered_tcp_reader(void *arg);
|
|||||||
// read the number of bytes specified by "count".
|
// read the number of bytes specified by "count".
|
||||||
ssize_t read_sized_block(buffered_tcp_desc *descriptor, void *buf, size_t count,
|
ssize_t read_sized_block(buffered_tcp_desc *descriptor, void *buf, size_t count,
|
||||||
size_t *bytes_remaining);
|
size_t *bytes_remaining);
|
||||||
|
|
||||||
#endif // _BUFFERED_READ_H
|
|
||||||
|
|||||||
@@ -228,7 +228,6 @@ void _inform(const char *filename, const int linenumber, const char *format, ...
|
|||||||
pthread_setcancelstate(oldState, NULL);
|
pthread_setcancelstate(oldState, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _debug_print_buffer(const char *thefilename, const int linenumber, int level, void *ibuf,
|
void _debug_print_buffer(const char *thefilename, const int linenumber, int level, void *ibuf,
|
||||||
size_t buf_len) {
|
size_t buf_len) {
|
||||||
|
|
||||||
@@ -309,7 +308,6 @@ void _debug_print_buffer(const char *thefilename, const int linenumber, int leve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void _debug_print_buffer(const char *thefilename, const int linenumber, int level, void *vbuf,
|
void _debug_print_buffer(const char *thefilename, const int linenumber, int level, void *vbuf,
|
||||||
size_t buf_len) {
|
size_t buf_len) {
|
||||||
|
|||||||
+10
-5
@@ -58,11 +58,16 @@ EXTERNC void set_show_file_and_line(int setting);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Function declarations with printf-style format checking
|
// Function declarations with printf-style format checking
|
||||||
EXTERNC void _die(const char *filename, const int linenumber, const char *format, ...) PRINTF_LIKE(3,4);
|
EXTERNC void _die(const char *filename, const int linenumber, const char *format, ...)
|
||||||
EXTERNC void _warn(const char *filename, const int linenumber, const char *format, ...) PRINTF_LIKE(3,4);
|
PRINTF_LIKE(3, 4);
|
||||||
EXTERNC void _inform(const char *filename, const int linenumber, const char *format, ...) PRINTF_LIKE(3,4);
|
EXTERNC void _warn(const char *filename, const int linenumber, const char *format, ...)
|
||||||
EXTERNC void _debug(const char *filename, const int linenumber, int level, const char *format, ...) PRINTF_LIKE(4,5);
|
PRINTF_LIKE(3, 4);
|
||||||
EXTERNC void _debug_print_buffer(const char *thefilename, const int linenumber, int level, void *buf,
|
EXTERNC void _inform(const char *filename, const int linenumber, const char *format, ...)
|
||||||
|
PRINTF_LIKE(3, 4);
|
||||||
|
EXTERNC void _debug(const char *filename, const int linenumber, int level, const char *format, ...)
|
||||||
|
PRINTF_LIKE(4, 5);
|
||||||
|
EXTERNC void _debug_print_buffer(const char *thefilename, const int linenumber, int level,
|
||||||
|
void *buf,
|
||||||
size_t buf_len); // not printf-style, no change needed
|
size_t buf_len); // not printf-style, no change needed
|
||||||
#define die(...) _die(__FILE__, __LINE__, __VA_ARGS__)
|
#define die(...) _die(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
#define debug(...) _debug(__FILE__, __LINE__, __VA_ARGS__)
|
#define debug(...) _debug(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Generate a device-related UUID. This file is part of Shairport Sync
|
* Generate a device-related UUID. This file is part of Shairport Sync
|
||||||
* Copyright (c) Mike Brady 2026
|
* Copyright (c) Mike Brady 2026
|
||||||
|
|
||||||
* Modifications, including those associated with audio synchronization, multithreading and
|
|
||||||
* metadata handling copyright (c) Mike Brady 2014--2025
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
@@ -31,8 +28,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
#include "generate_device_uuid.h"
|
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
|
#include "generate_device_uuid.h"
|
||||||
|
|
||||||
// user is responsible for deallocating returned string
|
// user is responsible for deallocating returned string
|
||||||
char *generate_device_uuid(const char *device_id) {
|
char *generate_device_uuid(const char *device_id) {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Generate a random UUID. This file is part of Shairport Sync
|
* Generate a random UUID. This file is part of Shairport Sync
|
||||||
* Copyright (c) Mike Brady 2026
|
* Copyright (c) Mike Brady 2026
|
||||||
|
|
||||||
* Modifications, including those associated with audio synchronization, multithreading and
|
|
||||||
* metadata handling copyright (c) Mike Brady 2014--2025
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
|||||||
+1
-4
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* 23-bit modular arithmetic. This file is part of Shairport Sync
|
* 23-bit modular arithmetic. This file is part of Shairport Sync
|
||||||
* Copyright (c) Mike Brady 2025
|
* Copyright (c) Mike Brady 2025
|
||||||
|
|
||||||
* Modifications, including those associated with audio synchronization, multithreading and
|
|
||||||
* metadata handling copyright (c) Mike Brady 2014--2025
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
@@ -27,8 +24,8 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "mod23.h"
|
#include "mod23.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define MOD_23BIT 0x7FFFFF // 2^23 - 1
|
#define MOD_23BIT 0x7FFFFF // 2^23 - 1
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -1,6 +1,5 @@
|
|||||||
#ifndef _MOD23_H
|
#pragma once
|
||||||
#define _MOD23_H
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
int32_t a_minus_b_mod23(uint32_t a, uint32_t b);
|
int32_t a_minus_b_mod23(uint32_t a, uint32_t b);
|
||||||
|
|
||||||
#endif // _MOD23_H
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Network Utilities. This file is part of Shairport Sync.
|
* Network Utilities. This file is part of Shairport Sync.
|
||||||
* Copyright (c) Mike Brady 2014--2025
|
* Copyright (c) Mike Brady 2026
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
@@ -24,12 +24,13 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "network_utilities.h"
|
#include "network_utilities.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int eintr_checked_accept(int sockfd, struct sockaddr *addr,
|
int eintr_checked_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
|
||||||
socklen_t *addrlen) {
|
|
||||||
int response;
|
int response;
|
||||||
do {
|
do {
|
||||||
response = accept(sockfd, addr, addrlen);
|
response = accept(sockfd, addr, addrlen);
|
||||||
@@ -37,11 +38,33 @@ int eintr_checked_accept(int sockfd, struct sockaddr *addr,
|
|||||||
if (response == -1) {
|
if (response == -1) {
|
||||||
char errorstring[1024];
|
char errorstring[1024];
|
||||||
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
|
strerror_r(errno, (char *)errorstring, sizeof(errorstring));
|
||||||
debug(1,
|
debug(1, "error %d accept()ing a socket %d: \"%s\". (Note: error %d will be ignored.)", errno,
|
||||||
"error %d accept()ing a socket %d: \"%s\". (Note: error %d will be ignored.)",
|
sockfd, errorstring, EINTR);
|
||||||
errno, sockfd, errorstring, EINTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while ((response == -1) && (errno == EINTR));
|
} while ((response == -1) && (errno == EINTR));
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_t safe_socket_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
int _safe_socket_close(const char *filename, const int linenumber, int *sockfd) {
|
||||||
|
int result = 0;
|
||||||
|
int oldstate;
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
|
||||||
|
debug_mutex_lock(&safe_socket_lock, 1000000, 1);
|
||||||
|
if (*sockfd == 0) {
|
||||||
|
_debug(filename, linenumber, 1, "_safe_socket_close: socket is zero!");
|
||||||
|
}
|
||||||
|
if ((*sockfd != -1) && (*sockfd != 0)) {
|
||||||
|
_debug(filename, linenumber, 4, "_safe_socket_close: closing socket %d.", *sockfd);
|
||||||
|
result = close(*sockfd);
|
||||||
|
if (result == 0)
|
||||||
|
*sockfd = -1;
|
||||||
|
} else {
|
||||||
|
_debug(filename, linenumber, 1, "_safe_socket_close: socket already closed!");
|
||||||
|
}
|
||||||
|
debug_mutex_unlock(&safe_socket_lock, 4);
|
||||||
|
pthread_setcancelstate(oldstate, NULL);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef _NETWORK_UTILITIES_H
|
#pragma once
|
||||||
#define _NETWORK_UTILITIES_H
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#define restrict
|
#define restrict
|
||||||
|
int eintr_checked_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||||
|
|
||||||
int eintr_checked_accept(int sockfd, struct sockaddr *addr,
|
int _safe_socket_close(const char *filename, const int linenumber, int *sockfd);
|
||||||
socklen_t *addrlen);
|
|
||||||
#endif // _NETWORK_UTILITIES_H
|
#define safe_socket_close(sockfd) _safe_socket_close(__FILE__, __LINE__, sockfd)
|
||||||
|
|||||||
@@ -1,9 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* RTSP Message Utilities. This file is part of Shairport Sync.
|
||||||
|
* Copyright (c) Mike Brady 2026
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without
|
||||||
|
* restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rtsp_message_utilities.h"
|
||||||
|
#include "../common.h"
|
||||||
|
#include "../rtsp.h"
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "rtsp_message_utilities.h"
|
|
||||||
#include "../rtsp.h"
|
|
||||||
#include "../common.h"
|
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
#include <plist/plist.h>
|
#include <plist/plist.h>
|
||||||
@@ -80,15 +106,16 @@ char *msg_get_header(rtsp_message *msg, char *name) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _debug_print_msg_headers(rtsp_conn_info *conn, const char *filename, const int linenumber, int level,
|
void _debug_print_msg_headers(rtsp_conn_info *conn, const char *filename, const int linenumber,
|
||||||
rtsp_message *msg) {
|
int level, rtsp_message *msg) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
if (conn != NULL) {
|
if (conn != NULL) {
|
||||||
if (msg->respcode != 0)
|
if (msg->respcode != 0)
|
||||||
_debug(filename, linenumber, level, "Connection: %d, Response Code: %d.", conn->connection_number, msg->respcode);
|
_debug(filename, linenumber, level, "Connection: %d, Response Code: %d.",
|
||||||
|
conn->connection_number, msg->respcode);
|
||||||
for (i = 0; i < msg->nheaders; i++) {
|
for (i = 0; i < msg->nheaders; i++) {
|
||||||
_debug(filename, linenumber, level, "Connection: %d, Type: \"%s\", content: \"%s\"", conn->connection_number, msg->name[i],
|
_debug(filename, linenumber, level, "Connection: %d, Type: \"%s\", content: \"%s\"",
|
||||||
msg->value[i]);
|
conn->connection_number, msg->name[i], msg->value[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (msg->respcode != 0)
|
if (msg->respcode != 0)
|
||||||
@@ -243,8 +270,8 @@ char *rtsp_plist_content(rtsp_message *message) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void _debug_log_rtsp_message(rtsp_conn_info *conn, const char *filename, const int linenumber, int level, char *prompt,
|
void _debug_log_rtsp_message(rtsp_conn_info *conn, const char *filename, const int linenumber,
|
||||||
rtsp_message *message) {
|
int level, char *prompt, rtsp_message *message) {
|
||||||
if (level > debug_level())
|
if (level > debug_level())
|
||||||
return;
|
return;
|
||||||
if ((prompt) && (*prompt != '\0')) // okay to pass NULL or an empty list...
|
if ((prompt) && (*prompt != '\0')) // okay to pass NULL or an empty list...
|
||||||
@@ -253,13 +280,13 @@ void _debug_log_rtsp_message(rtsp_conn_info *conn, const char *filename, const i
|
|||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
char *plist_content = rtsp_plist_content(message);
|
char *plist_content = rtsp_plist_content(message);
|
||||||
if (plist_content) {
|
if (plist_content) {
|
||||||
_debug(filename, linenumber, level, " Content length: %u. Content Plist (as XML):\n--\n%s--", message->contentlength, plist_content);
|
_debug(filename, linenumber, level, " Content length: %u. Content Plist (as XML):\n--\n%s--",
|
||||||
|
message->contentlength, plist_content);
|
||||||
free(plist_content);
|
free(plist_content);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
_debug(filename, linenumber, level, " Content length: %u.",
|
_debug(filename, linenumber, level, " Content length: %u.", message->contentlength);
|
||||||
message->contentlength);
|
|
||||||
if (message->contentlength > 0) {
|
if (message->contentlength > 0) {
|
||||||
_debug_print_buffer(filename, linenumber, level, message->content, message->contentlength);
|
_debug_print_buffer(filename, linenumber, level, message->content, message->contentlength);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ int msg_handle_line(rtsp_message **pmsg, char *line);
|
|||||||
int msg_add_header(rtsp_message *msg, char *name, char *value);
|
int msg_add_header(rtsp_message *msg, char *name, char *value);
|
||||||
char *msg_get_header(rtsp_message *msg, char *name);
|
char *msg_get_header(rtsp_message *msg, char *name);
|
||||||
|
|
||||||
void _debug_log_rtsp_message(rtsp_conn_info *conn, const char *filename, const int linenumber, int level, char *prompt,
|
void _debug_log_rtsp_message(rtsp_conn_info *conn, const char *filename, const int linenumber,
|
||||||
rtsp_message *message);
|
int level, char *prompt, rtsp_message *message);
|
||||||
|
|
||||||
#define debug_log_rtsp_message_conn(conn, level, prompt, message) \
|
#define debug_log_rtsp_message_conn(conn, level, prompt, message) \
|
||||||
_debug_log_rtsp_message(conn, __FILE__, __LINE__, level, prompt, message)
|
_debug_log_rtsp_message(conn, __FILE__, __LINE__, level, prompt, message)
|
||||||
@@ -17,16 +17,14 @@ void _debug_log_rtsp_message(rtsp_conn_info *conn, const char *filename, const i
|
|||||||
#define debug_log_rtsp_message(level, prompt, message) \
|
#define debug_log_rtsp_message(level, prompt, message) \
|
||||||
_debug_log_rtsp_message(NULL, __FILE__, __LINE__, level, prompt, message)
|
_debug_log_rtsp_message(NULL, __FILE__, __LINE__, level, prompt, message)
|
||||||
|
|
||||||
|
void _debug_print_msg_headers(rtsp_conn_info *conn, const char *filename, const int linenumber,
|
||||||
void _debug_print_msg_headers(rtsp_conn_info *conn, const char *filename, const int linenumber, int level,
|
int level, rtsp_message *msg);
|
||||||
rtsp_message *msg);
|
|
||||||
#define debug_print_msg_headers(level, message) \
|
#define debug_print_msg_headers(level, message) \
|
||||||
_debug_print_msg_headers(NULL, __FILE__, __LINE__, level, message)
|
_debug_print_msg_headers(NULL, __FILE__, __LINE__, level, message)
|
||||||
|
|
||||||
#define debug_print_msg_headers_conn(level, message) \
|
#define debug_print_msg_headers_conn(level, message) \
|
||||||
_debug_print_msg_headers(conn, __FILE__, __LINE__, level, message)
|
_debug_print_msg_headers(conn, __FILE__, __LINE__, level, message)
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_AIRPLAY_2
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
int rtsp_message_contains_plist(rtsp_message *message);
|
int rtsp_message_contains_plist(rtsp_message *message);
|
||||||
plist_t plist_from_rtsp_content(rtsp_message *message);
|
plist_t plist_from_rtsp_content(rtsp_message *message);
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
* Some character string utilities. This file is part of Shairport Sync
|
||||||
|
* Copyright (c) Mike Brady 2026
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person
|
||||||
|
* obtaining a copy of this software and associated documentation
|
||||||
|
* files (the "Software"), to deal in the Software without
|
||||||
|
* restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
* sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "string_utilities.h"
|
||||||
|
|
||||||
|
// mDNS supports maximum of 63-character names (we prepend 13, so only 50 left).
|
||||||
|
#define MAX_AIRPLAY_SERVICE_NAME_LENGTH 50
|
||||||
|
|
||||||
|
/* from
|
||||||
|
* http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring#comment-722
|
||||||
|
* with thanks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *str_replace(const char *string, const char *substr, const char *replacement) {
|
||||||
|
char *tok = NULL;
|
||||||
|
char *newstr = NULL;
|
||||||
|
char *oldstr = NULL;
|
||||||
|
char *head = NULL;
|
||||||
|
|
||||||
|
/* if either substr or replacement is NULL, duplicate string a let caller handle it */
|
||||||
|
if (substr == NULL || replacement == NULL)
|
||||||
|
return strdup(string);
|
||||||
|
newstr = strdup(string);
|
||||||
|
head = newstr;
|
||||||
|
if (head) {
|
||||||
|
while ((tok = strstr(head, substr))) {
|
||||||
|
oldstr = newstr;
|
||||||
|
newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
|
||||||
|
/*failed to alloc mem, free old string and return NULL */
|
||||||
|
if (newstr == NULL) {
|
||||||
|
free(oldstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(newstr, oldstr, tok - oldstr);
|
||||||
|
memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
|
||||||
|
memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
|
||||||
|
strlen(oldstr) - strlen(substr) - (tok - oldstr));
|
||||||
|
memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
|
||||||
|
/* move back head right after the last replacement */
|
||||||
|
head = newstr + (tok - oldstr) + strlen(replacement);
|
||||||
|
free(oldstr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
die("failed to allocate memory in str_replace.");
|
||||||
|
}
|
||||||
|
return newstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* append_truncated - Append `suffix` to `base`, returning a newly malloc'd
|
||||||
|
* string. If the combined result would exceed `limit` bytes (excluding the
|
||||||
|
* NUL terminator), the base is truncated so that the output is:
|
||||||
|
*
|
||||||
|
* <truncated base>...<suffix>
|
||||||
|
*
|
||||||
|
* The returned string is always NUL-terminated and never exceeds `limit`
|
||||||
|
* bytes of content. The caller is responsible for free()'ing it.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* base - the primary string
|
||||||
|
* suffix - the string to append
|
||||||
|
* limit - maximum byte count of the resulting string (excl. NUL)
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* A newly malloc'd string on success, or NULL on failure (limit too small
|
||||||
|
* to fit "..." + suffix, or malloc failure).
|
||||||
|
*/
|
||||||
|
char *append_truncated(const char *base, const char *suffix, size_t limit) {
|
||||||
|
|
||||||
|
const char *ellipsis = "...";
|
||||||
|
size_t ellipsis_len = strlen(ellipsis);
|
||||||
|
size_t suffix_len = strlen(suffix);
|
||||||
|
size_t base_len = strlen(base);
|
||||||
|
size_t combined_len = base_len + suffix_len;
|
||||||
|
size_t result_len;
|
||||||
|
size_t head_len;
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
if (combined_len <= limit) {
|
||||||
|
/* Fits without truncation. */
|
||||||
|
result_len = combined_len;
|
||||||
|
out = malloc(result_len + 1);
|
||||||
|
if (!out)
|
||||||
|
return NULL;
|
||||||
|
memcpy(out, base, base_len);
|
||||||
|
memcpy(out + base_len, suffix, suffix_len + 1); /* +1 for NUL */
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not enough room to fit even "..." + suffix. */
|
||||||
|
if (limit < ellipsis_len + suffix_len)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
head_len = limit - ellipsis_len - suffix_len;
|
||||||
|
|
||||||
|
/* Respect UTF-8: don't cut in the middle of a multibyte sequence.
|
||||||
|
* Walk back from head_len until we're at a character boundary
|
||||||
|
* (i.e. a byte that is not a UTF-8 continuation byte 0x80–0xBF). */
|
||||||
|
while (head_len > 0 && (base[head_len] & 0xC0) == 0x80)
|
||||||
|
head_len--;
|
||||||
|
|
||||||
|
result_len = head_len + ellipsis_len + suffix_len;
|
||||||
|
out = malloc(result_len + 1);
|
||||||
|
if (!out)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
char *p = out;
|
||||||
|
memcpy(p, base, head_len);
|
||||||
|
p += head_len;
|
||||||
|
memcpy(p, ellipsis, ellipsis_len);
|
||||||
|
p += ellipsis_len;
|
||||||
|
memcpy(p, suffix, suffix_len);
|
||||||
|
p += suffix_len;
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *service_name(const char *raw_service_name) {
|
||||||
|
char *response = NULL;
|
||||||
|
// now, do the substitutions in the service name
|
||||||
|
char hostname[256];
|
||||||
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
// strip off a terminating .<anything>, e.g. .local from the hostname
|
||||||
|
char *last_dot = strrchr(hostname, '.');
|
||||||
|
if (last_dot != NULL)
|
||||||
|
*last_dot = '\0';
|
||||||
|
|
||||||
|
char *i0;
|
||||||
|
if (raw_service_name == NULL)
|
||||||
|
i0 = strdup("%H"); // default
|
||||||
|
else
|
||||||
|
i0 = strdup(raw_service_name); // this is the string provided in the configuration or on the
|
||||||
|
// command line.
|
||||||
|
// here, do the substitutions for %h, %H, %v and %V
|
||||||
|
char *i1 = str_replace(i0, "%h", hostname);
|
||||||
|
if ((hostname[0] >= 'a') && (hostname[0] <= 'z'))
|
||||||
|
hostname[0] = hostname[0] - 0x20; // convert a lowercase first letter into a capital letter
|
||||||
|
char *i2 = str_replace(i1, "%H", hostname);
|
||||||
|
char *i3 = str_replace(i2, "%v", PACKAGE_VERSION);
|
||||||
|
char *vs = get_version_string();
|
||||||
|
char *i4 = str_replace(i3, "%V", vs); // service name complete
|
||||||
|
// now, we may need to add "(Classic)" and/or truncate it to MAX_AIRPLAY_SERVICE_NAME_LENGTH
|
||||||
|
// characters.
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
if ((raw_service_name == NULL) && (config.service_type == APST_forced_classic)) {
|
||||||
|
response = append_truncated(
|
||||||
|
i4, " (Classic)", MAX_AIRPLAY_SERVICE_NAME_LENGTH); // append "(Classic)" to default service
|
||||||
|
// name if forced to Classic
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
response = append_truncated(
|
||||||
|
i4, "",
|
||||||
|
MAX_AIRPLAY_SERVICE_NAME_LENGTH); // make sure it doesn't exceed the max length: 63 - 13
|
||||||
|
#ifdef CONFIG_AIRPLAY_2
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
free(i0);
|
||||||
|
free(i1);
|
||||||
|
free(i2);
|
||||||
|
free(i3);
|
||||||
|
free(i4);
|
||||||
|
free(vs);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* from
|
||||||
|
* http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring#comment-722
|
||||||
|
*/
|
||||||
|
char *str_replace(const char *string, const char *substr, const char *replacement);
|
||||||
|
|
||||||
|
char *service_name(const char *raw_service_name);
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Structured Buffer. This file is part of Shairport Sync
|
* Structured Buffer. This file is part of Shairport Sync
|
||||||
* Copyright (c) Mike Brady 2025
|
* Copyright (c) Mike Brady 2025
|
||||||
|
|
||||||
* Modifications, including those associated with audio synchronization, multithreading and
|
|
||||||
* metadata handling copyright (c) Mike Brady 2014--2025
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
@@ -27,12 +24,11 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|||||||
Reference in New Issue
Block a user