2016-01-23 19:14:07 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Espen Jürgensen <espenjurgensen@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-02-08 14:36:21 -05:00
|
|
|
#include <stdbool.h>
|
2016-01-23 19:14:07 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
#include <event2/event.h>
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
#include "logger.h"
|
2019-02-08 14:36:21 -05:00
|
|
|
#include "misc.h"
|
|
|
|
#include "transcode.h"
|
2019-02-12 17:43:54 -05:00
|
|
|
#include "db.h"
|
2019-02-12 15:25:27 -05:00
|
|
|
#include "player.h" //TODO remove me when player_pmap is removed again
|
2019-03-18 18:04:34 -04:00
|
|
|
#include "worker.h"
|
2016-01-23 19:14:07 -05:00
|
|
|
#include "outputs.h"
|
|
|
|
|
|
|
|
extern struct output_definition output_raop;
|
2020-11-27 16:46:38 -05:00
|
|
|
extern struct output_definition output_airplay;
|
2016-04-04 10:58:07 -04:00
|
|
|
extern struct output_definition output_streaming;
|
2016-04-04 17:43:34 -04:00
|
|
|
extern struct output_definition output_dummy;
|
2016-10-25 15:23:09 -04:00
|
|
|
extern struct output_definition output_fifo;
|
2022-01-15 07:24:49 -05:00
|
|
|
extern struct output_definition output_rcp;
|
2017-01-06 03:44:18 -05:00
|
|
|
#ifdef HAVE_ALSA
|
2016-01-24 16:19:15 -05:00
|
|
|
extern struct output_definition output_alsa;
|
|
|
|
#endif
|
2017-01-06 03:44:18 -05:00
|
|
|
#ifdef HAVE_LIBPULSE
|
2016-07-21 16:13:32 -04:00
|
|
|
extern struct output_definition output_pulse;
|
|
|
|
#endif
|
2016-04-04 17:43:34 -04:00
|
|
|
#ifdef CHROMECAST
|
|
|
|
extern struct output_definition output_cast;
|
2016-01-24 16:19:15 -05:00
|
|
|
#endif
|
2016-01-23 19:14:07 -05:00
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
/* From player.c */
|
|
|
|
extern struct event_base *evbase_player;
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
// Must be in sync with enum output_types
|
|
|
|
static struct output_definition *outputs[] = {
|
2016-01-24 16:19:15 -05:00
|
|
|
&output_raop,
|
2020-11-27 16:46:38 -05:00
|
|
|
&output_airplay,
|
2016-04-04 10:58:07 -04:00
|
|
|
&output_streaming,
|
2016-04-04 17:43:34 -04:00
|
|
|
&output_dummy,
|
2016-10-25 15:23:09 -04:00
|
|
|
&output_fifo,
|
2022-01-15 07:24:49 -05:00
|
|
|
&output_rcp,
|
2017-01-06 03:44:18 -05:00
|
|
|
#ifdef HAVE_ALSA
|
2016-01-23 19:14:07 -05:00
|
|
|
&output_alsa,
|
|
|
|
#endif
|
2017-01-06 03:44:18 -05:00
|
|
|
#ifdef HAVE_LIBPULSE
|
2016-07-21 16:13:32 -04:00
|
|
|
&output_pulse,
|
|
|
|
#endif
|
2016-04-04 17:43:34 -04:00
|
|
|
#ifdef CHROMECAST
|
|
|
|
&output_cast,
|
2016-01-23 19:14:07 -05:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
// Default volume (must be from 0 - 100)
|
|
|
|
#define OUTPUTS_DEFAULT_VOLUME 50
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
// When we stop, we keep the outputs open for a while, just in case we are
|
|
|
|
// actually just restarting. This timeout determines how long we wait before
|
|
|
|
// full stop.
|
|
|
|
// (value is in seconds)
|
|
|
|
#define OUTPUTS_STOP_TIMEOUT 10
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
#define OUTPUTS_MAX_CALLBACKS 64
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
struct outputs_callback_register
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
|
|
|
output_status_cb cb;
|
|
|
|
struct output_device *device;
|
|
|
|
|
|
|
|
// We have received the callback with the result from the backend
|
|
|
|
bool ready;
|
|
|
|
|
|
|
|
// We store a device_id to avoid the risk of dangling device pointer
|
|
|
|
uint64_t device_id;
|
|
|
|
enum output_device_state state;
|
|
|
|
};
|
|
|
|
|
2019-02-08 14:36:21 -05:00
|
|
|
struct output_quality_subscription
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
struct media_quality quality;
|
|
|
|
struct encode_ctx *encode_ctx;
|
|
|
|
};
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
// Buffer used to pass data to the backends
|
|
|
|
static struct output_buffer output_buffer;
|
|
|
|
|
|
|
|
static struct output_device *outputs_device_list;
|
|
|
|
static int outputs_master_volume;
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
static struct outputs_callback_register outputs_cb_register[OUTPUTS_MAX_CALLBACKS];
|
|
|
|
static struct event *outputs_deferredev;
|
|
|
|
static struct timeval outputs_stop_timeout = { OUTPUTS_STOP_TIMEOUT, 0 };
|
|
|
|
|
2019-02-08 14:36:21 -05:00
|
|
|
// Last element is a zero terminator
|
|
|
|
static struct output_quality_subscription output_quality_subscriptions[OUTPUTS_MAX_QUALITY_SUBSCRIPTIONS + 1];
|
2019-03-05 16:45:38 -05:00
|
|
|
static bool outputs_got_new_subscription;
|
2019-02-08 14:36:21 -05:00
|
|
|
|
2019-02-13 10:56:17 -05:00
|
|
|
|
2019-02-08 14:36:21 -05:00
|
|
|
/* ------------------------------- MISC HELPERS ----------------------------- */
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
static output_status_cb
|
|
|
|
callback_get(struct output_device *device)
|
|
|
|
{
|
|
|
|
int callback_id;
|
|
|
|
|
|
|
|
for (callback_id = 0; callback_id < ARRAY_SIZE(outputs_cb_register); callback_id++)
|
|
|
|
{
|
|
|
|
if (outputs_cb_register[callback_id].device == device)
|
|
|
|
return outputs_cb_register[callback_id].cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
static void
|
|
|
|
callback_remove(struct output_device *device)
|
|
|
|
{
|
|
|
|
int callback_id;
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return;
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
for (callback_id = 0; callback_id < ARRAY_SIZE(outputs_cb_register); callback_id++)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
if (outputs_cb_register[callback_id].device == device)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Removing callback to %s, id %d\n", player_pmap(outputs_cb_register[callback_id].cb), callback_id);
|
|
|
|
memset(&outputs_cb_register[callback_id], 0, sizeof(struct outputs_callback_register));
|
2019-02-12 15:25:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
callback_add(struct output_device *device, output_status_cb cb)
|
|
|
|
{
|
|
|
|
int callback_id;
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// We will replace any previously registered callbacks, since that's what the
|
|
|
|
// player expects
|
|
|
|
callback_remove(device);
|
|
|
|
|
|
|
|
// Find a free slot in the queue
|
2019-03-05 16:45:38 -05:00
|
|
|
for (callback_id = 0; callback_id < ARRAY_SIZE(outputs_cb_register); callback_id++)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
if (outputs_cb_register[callback_id].cb == NULL)
|
2019-02-12 15:25:27 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
if (callback_id == ARRAY_SIZE(outputs_cb_register))
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Output callback queue is full! (size is %d)\n", OUTPUTS_MAX_CALLBACKS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
outputs_cb_register[callback_id].cb = cb;
|
|
|
|
outputs_cb_register[callback_id].device = device; // Don't dereference this later, it might become invalid!
|
2019-02-12 15:25:27 -05:00
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Registered callback to %s with id %d (device %p, %s)\n", player_pmap(cb), callback_id, device, device->name);
|
2019-02-12 15:25:27 -05:00
|
|
|
|
|
|
|
int active = 0;
|
2019-03-05 16:45:38 -05:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(outputs_cb_register); i++)
|
|
|
|
if (outputs_cb_register[i].cb)
|
2019-02-12 15:25:27 -05:00
|
|
|
active++;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Number of active callbacks: %d\n", active);
|
|
|
|
|
|
|
|
return callback_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
deferred_cb(int fd, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
output_status_cb cb;
|
|
|
|
enum output_device_state state;
|
|
|
|
int callback_id;
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
for (callback_id = 0; callback_id < ARRAY_SIZE(outputs_cb_register); callback_id++)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
if (outputs_cb_register[callback_id].ready)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
|
|
|
// Must copy before making callback, since you never know what the
|
|
|
|
// callback might result in (could call back in)
|
2019-03-05 16:45:38 -05:00
|
|
|
cb = outputs_cb_register[callback_id].cb;
|
|
|
|
state = outputs_cb_register[callback_id].state;
|
2019-02-12 15:25:27 -05:00
|
|
|
|
|
|
|
// Will be NULL if the device has disappeared
|
2019-03-05 16:45:38 -05:00
|
|
|
device = outputs_device_get(outputs_cb_register[callback_id].device_id);
|
2019-02-12 15:25:27 -05:00
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
memset(&outputs_cb_register[callback_id], 0, sizeof(struct outputs_callback_register));
|
2019-02-12 15:25:27 -05:00
|
|
|
|
2019-02-13 10:56:17 -05:00
|
|
|
// The device has left the building (stopped/failed), and the backend
|
|
|
|
// is not using it any more
|
2020-05-01 14:11:45 -04:00
|
|
|
if (device && !device->advertised && !device->session)
|
2019-02-13 10:56:17 -05:00
|
|
|
{
|
|
|
|
outputs_device_remove(device);
|
|
|
|
device = NULL;
|
|
|
|
}
|
2020-05-01 14:11:45 -04:00
|
|
|
else if (device)
|
|
|
|
device->state = state;
|
2019-02-13 10:56:17 -05:00
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Making deferred callback to %s, id was %d\n", player_pmap(cb), callback_id);
|
|
|
|
|
|
|
|
cb(device, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(outputs_cb_register); i++)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
if (outputs_cb_register[i].cb)
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "%d. Active callback: %s\n", i, player_pmap(outputs_cb_register[i].cb));
|
2019-02-12 15:25:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
static void
|
|
|
|
stop_timer_cb(int fd, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct output_device *device = arg;
|
|
|
|
output_status_cb cb = callback_get(device);
|
|
|
|
|
|
|
|
outputs_device_stop(device, cb);
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:43:54 -05:00
|
|
|
static void
|
2020-05-01 14:11:45 -04:00
|
|
|
device_stop_cb(struct output_device *device, enum output_device_state state)
|
2019-02-12 17:43:54 -05:00
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
if (device)
|
|
|
|
device->state = state;
|
|
|
|
|
|
|
|
if (state == OUTPUT_STATE_FAILED)
|
2019-02-12 17:43:54 -05:00
|
|
|
DPRINTF(E_WARN, L_PLAYER, "Failed to stop device\n");
|
|
|
|
else
|
|
|
|
DPRINTF(E_INFO, L_PLAYER, "Device stopped properly\n");
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:36:21 -05:00
|
|
|
static enum transcode_profile
|
|
|
|
quality_to_xcode(struct media_quality *quality)
|
|
|
|
{
|
2019-04-02 16:47:11 -04:00
|
|
|
if (quality->bits_per_sample == 16)
|
|
|
|
return XCODE_PCM16;
|
|
|
|
if (quality->bits_per_sample == 24)
|
|
|
|
return XCODE_PCM24;
|
|
|
|
if (quality->bits_per_sample == 32)
|
|
|
|
return XCODE_PCM32;
|
2019-02-08 14:36:21 -05:00
|
|
|
|
|
|
|
return XCODE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
encoding_reset(struct media_quality *quality)
|
|
|
|
{
|
|
|
|
struct output_quality_subscription *subscription;
|
|
|
|
struct decode_ctx *decode_ctx;
|
|
|
|
enum transcode_profile profile;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
profile = quality_to_xcode(quality);
|
|
|
|
if (profile == XCODE_UNKNOWN)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Could not create subscription decoding context, invalid quality (%d/%d/%d)\n",
|
|
|
|
quality->sample_rate, quality->bits_per_sample, quality->channels);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-02 16:47:11 -04:00
|
|
|
decode_ctx = transcode_decode_setup_raw(profile, quality);
|
2019-02-08 14:36:21 -05:00
|
|
|
if (!decode_ctx)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Could not create subscription decoding context (profile %d)\n", profile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; output_quality_subscriptions[i].count > 0; i++)
|
|
|
|
{
|
|
|
|
subscription = &output_quality_subscriptions[i]; // Just for short-hand
|
|
|
|
|
|
|
|
transcode_encode_cleanup(&subscription->encode_ctx); // Will also point the ctx to NULL
|
|
|
|
|
|
|
|
if (quality_is_equal(quality, &subscription->quality))
|
|
|
|
continue; // No resampling required
|
|
|
|
|
|
|
|
profile = quality_to_xcode(&subscription->quality);
|
|
|
|
if (profile != XCODE_UNKNOWN)
|
2023-10-20 18:17:20 -04:00
|
|
|
subscription->encode_ctx = transcode_encode_setup(profile, &subscription->quality, decode_ctx, 0, 0);
|
2019-02-08 14:36:21 -05:00
|
|
|
else
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Could not setup resampling to %d/%d/%d for output\n",
|
|
|
|
subscription->quality.sample_rate, subscription->quality.bits_per_sample, subscription->quality.channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
transcode_decode_cleanup(&decode_ctx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-09 19:54:52 -05:00
|
|
|
buffer_fill(struct output_buffer *obuf, void *buf, size_t bufsize, struct media_quality *quality, int nsamples, struct timespec *pts)
|
2019-02-08 14:36:21 -05:00
|
|
|
{
|
|
|
|
transcode_frame *frame;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
|
2019-02-10 17:20:12 -05:00
|
|
|
obuf->pts = *pts;
|
2019-02-08 14:36:21 -05:00
|
|
|
|
|
|
|
// The resampling/encoding (transcode) contexts work for a given input quality,
|
|
|
|
// so if the quality changes we need to reset the contexts. We also do that if
|
|
|
|
// we have received a subscription for a new quality.
|
2019-03-05 16:45:38 -05:00
|
|
|
if (!quality_is_equal(quality, &obuf->data[0].quality) || outputs_got_new_subscription)
|
2019-02-08 14:36:21 -05:00
|
|
|
{
|
|
|
|
encoding_reset(quality);
|
2019-03-05 16:45:38 -05:00
|
|
|
outputs_got_new_subscription = false;
|
2019-02-08 14:36:21 -05:00
|
|
|
}
|
|
|
|
|
2019-02-22 02:40:59 -05:00
|
|
|
// The first element of the output_buffer is always just the raw input data
|
2019-02-08 14:36:21 -05:00
|
|
|
// TODO can we avoid the copy below? we can't use evbuffer_add_buffer_reference,
|
|
|
|
// because then the outputs can't use it and we would need to copy there instead
|
2019-02-22 02:40:59 -05:00
|
|
|
evbuffer_add(obuf->data[0].evbuf, buf, bufsize);
|
|
|
|
obuf->data[0].buffer = buf;
|
|
|
|
obuf->data[0].bufsize = bufsize;
|
|
|
|
obuf->data[0].quality = *quality;
|
|
|
|
obuf->data[0].samples = nsamples;
|
2019-02-08 14:36:21 -05:00
|
|
|
|
|
|
|
for (i = 0, n = 1; output_quality_subscriptions[i].count > 0; i++)
|
|
|
|
{
|
|
|
|
if (quality_is_equal(&output_quality_subscriptions[i].quality, quality))
|
|
|
|
continue; // Skip, no resampling required and we have the data in element 0
|
|
|
|
|
2019-02-27 15:59:44 -05:00
|
|
|
if (!output_quality_subscriptions[i].encode_ctx)
|
|
|
|
continue;
|
|
|
|
|
2019-04-02 16:47:11 -04:00
|
|
|
frame = transcode_frame_new(buf, bufsize, nsamples, quality);
|
2019-02-08 14:36:21 -05:00
|
|
|
if (!frame)
|
|
|
|
continue;
|
|
|
|
|
2019-02-22 02:40:59 -05:00
|
|
|
ret = transcode_encode(obuf->data[n].evbuf, output_quality_subscriptions[i].encode_ctx, frame, 0);
|
2019-02-08 14:36:21 -05:00
|
|
|
transcode_frame_free(frame);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
2019-02-22 02:40:59 -05:00
|
|
|
obuf->data[n].buffer = evbuffer_pullup(obuf->data[n].evbuf, -1);
|
|
|
|
obuf->data[n].bufsize = evbuffer_get_length(obuf->data[n].evbuf);
|
|
|
|
obuf->data[n].quality = output_quality_subscriptions[i].quality;
|
|
|
|
obuf->data[n].samples = BTOS(obuf->data[n].bufsize, obuf->data[n].quality.bits_per_sample, obuf->data[n].quality.channels);
|
2019-02-08 14:36:21 -05:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
buffer_drain(struct output_buffer *obuf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-02-22 02:40:59 -05:00
|
|
|
for (i = 0; obuf->data[i].buffer; i++)
|
2019-02-08 14:36:21 -05:00
|
|
|
{
|
2019-02-22 02:40:59 -05:00
|
|
|
evbuffer_drain(obuf->data[i].evbuf, obuf->data[i].bufsize);
|
|
|
|
obuf->data[i].buffer = NULL;
|
|
|
|
obuf->data[i].bufsize = 0;
|
2019-02-08 14:36:21 -05:00
|
|
|
// We don't reset quality and samples, would be a waste of time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-01 17:32:57 -04:00
|
|
|
static struct output_buffer *
|
|
|
|
buffer_copy(struct output_buffer *obuf)
|
|
|
|
{
|
|
|
|
struct output_buffer *copy;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!obuf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CHECK_NULL(L_PLAYER, copy = malloc(sizeof(struct output_buffer)));
|
|
|
|
|
|
|
|
memcpy(copy, obuf, sizeof(struct output_buffer));
|
|
|
|
|
|
|
|
for (i = 0; obuf->data[i].buffer; i++)
|
|
|
|
{
|
|
|
|
CHECK_NULL(L_PLAYER, copy->data[i].evbuf = evbuffer_new());
|
|
|
|
evbuffer_add(copy->data[i].evbuf, obuf->data[i].buffer, obuf->data[i].bufsize);
|
|
|
|
copy->data[i].buffer = evbuffer_pullup(copy->data[i].evbuf, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
buffer_free(struct output_buffer *obuf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!obuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; obuf->data[i].buffer; i++)
|
|
|
|
evbuffer_free(obuf->data[i].evbuf);
|
|
|
|
|
|
|
|
free(obuf);
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:43:54 -05:00
|
|
|
static void
|
|
|
|
device_list_sort(void)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
struct output_device *next;
|
|
|
|
struct output_device *prev;
|
|
|
|
int swaps;
|
|
|
|
|
|
|
|
// Swap sorting since even the most inefficient sorting should do fine here
|
|
|
|
do
|
|
|
|
{
|
|
|
|
swaps = 0;
|
|
|
|
prev = NULL;
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device && device->next; device = device->next)
|
2019-02-12 17:43:54 -05:00
|
|
|
{
|
|
|
|
next = device->next;
|
|
|
|
if ( (outputs_priority(device) > outputs_priority(next)) ||
|
|
|
|
(outputs_priority(device) == outputs_priority(next) && strcasecmp(device->name, next->name) > 0) )
|
|
|
|
{
|
2020-06-28 18:19:03 -04:00
|
|
|
if (device == outputs_device_list)
|
|
|
|
outputs_device_list = next;
|
2019-02-12 17:43:54 -05:00
|
|
|
if (prev)
|
|
|
|
prev->next = next;
|
|
|
|
|
|
|
|
device->next = next->next;
|
|
|
|
next->next = device;
|
|
|
|
swaps++;
|
|
|
|
}
|
|
|
|
prev = device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (swaps > 0);
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
// Convenience function
|
|
|
|
static inline int
|
|
|
|
device_state_update(struct output_device *device, int ret)
|
|
|
|
{
|
|
|
|
if (ret < 0)
|
|
|
|
device->state = OUTPUT_STATE_FAILED;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:04:34 -04:00
|
|
|
static void
|
|
|
|
metadata_cb_send(int fd, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct output_metadata *metadata = arg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
event_free(metadata->ev);
|
|
|
|
metadata->ev = NULL;
|
|
|
|
|
|
|
|
ret = metadata->finalize_cb(metadata);
|
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
outputs[metadata->type]->metadata_send(metadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
// *** Worker thread ***
|
|
|
|
static void
|
|
|
|
metadata_cb_prepare(void *arg)
|
|
|
|
{
|
|
|
|
struct output_metadata *metadata = *((struct output_metadata **)arg);
|
|
|
|
|
|
|
|
metadata->priv = outputs[metadata->type]->metadata_prepare(metadata);
|
|
|
|
if (!metadata->priv)
|
|
|
|
{
|
|
|
|
event_free(metadata->ev);
|
|
|
|
free(metadata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metadata is prepared, let the player thread do the actual sending
|
|
|
|
event_active(metadata->ev, 0, 0);
|
|
|
|
}
|
|
|
|
|
2023-01-22 11:23:32 -05:00
|
|
|
static void
|
|
|
|
metadata_free(struct output_metadata *metadata)
|
|
|
|
{
|
|
|
|
if (!metadata)
|
|
|
|
return;
|
|
|
|
if (metadata->ev)
|
|
|
|
event_free(metadata->ev);
|
|
|
|
free(metadata);
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:04:34 -04:00
|
|
|
static void
|
|
|
|
metadata_send(enum output_types type, uint32_t item_id, bool startup, output_metadata_finalize_cb cb)
|
|
|
|
{
|
|
|
|
struct output_metadata *metadata;
|
|
|
|
|
|
|
|
CHECK_NULL(L_PLAYER, metadata = calloc(1, sizeof(struct output_metadata)));
|
|
|
|
|
|
|
|
metadata->type = type;
|
|
|
|
metadata->item_id = item_id;
|
|
|
|
metadata->startup = startup;
|
|
|
|
metadata->finalize_cb = cb;
|
|
|
|
|
|
|
|
metadata->ev = event_new(evbase_player, -1, 0, metadata_cb_send, metadata);
|
|
|
|
|
|
|
|
if (outputs[type]->metadata_prepare)
|
|
|
|
worker_execute(metadata_cb_prepare, &metadata, sizeof(struct output_metadata *), 0);
|
|
|
|
else
|
|
|
|
outputs[type]->metadata_send(metadata);
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:43:54 -05:00
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
/* ----------------------------- Volume helpers ----------------------------- */
|
|
|
|
|
|
|
|
static int
|
|
|
|
rel_to_vol(int relvol, int master_volume)
|
|
|
|
{
|
|
|
|
float vol;
|
|
|
|
|
|
|
|
if (relvol == 100)
|
|
|
|
return master_volume;
|
|
|
|
|
|
|
|
vol = ((float)relvol * (float)master_volume) / 100.0;
|
|
|
|
|
|
|
|
return (int)vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vol_to_rel(int volume, int master_volume)
|
|
|
|
{
|
|
|
|
float rel;
|
|
|
|
|
|
|
|
if (volume == master_volume)
|
|
|
|
return 100;
|
|
|
|
|
|
|
|
rel = ((float)volume / (float)master_volume) * 100.0;
|
|
|
|
|
|
|
|
return (int)rel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vol_adjust(void)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
int selected_highest = -1;
|
|
|
|
int all_highest = -1;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2020-05-01 14:11:45 -04:00
|
|
|
{
|
2020-05-27 16:53:11 -04:00
|
|
|
if (OUTPUTS_DEVICE_DISPLAY_SELECTED(device) && (device->volume > selected_highest))
|
2020-05-01 14:11:45 -04:00
|
|
|
selected_highest = device->volume;
|
|
|
|
|
|
|
|
if (device->volume > all_highest)
|
|
|
|
all_highest = device->volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs_master_volume = (selected_highest >= 0) ? selected_highest : all_highest;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2020-05-01 14:11:45 -04:00
|
|
|
{
|
|
|
|
device->relvol = vol_to_rel(device->volume, outputs_master_volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_VOLUME
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "*** Master: %d\n", outputs_master_volume);
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2020-05-01 14:11:45 -04:00
|
|
|
{
|
2020-05-27 16:53:11 -04:00
|
|
|
DPRINTF(E_DBG, L_PLAYER, "*** %s: abs %d rel %d selected %d\n", device->name, device->volume, device->relvol, OUTPUTS_DEVICE_DISPLAY_SELECTED(device));
|
2020-05-01 14:11:45 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:36:21 -05:00
|
|
|
/* ----------------------------------- API ---------------------------------- */
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
struct output_device *
|
|
|
|
outputs_device_get(uint64_t device_id)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
|
|
|
if (device_id == device->id)
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
DPRINTF(E_WARN, L_PLAYER, "Output device with id %" PRIu64 " has disappeared from our list\n", device_id);
|
2019-02-12 15:25:27 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------- Called by backend modules ------------------------ */
|
|
|
|
|
|
|
|
// Sessions free their sessions themselves, but should not touch the device,
|
|
|
|
// since they can't know for sure that it is still valid in memory
|
|
|
|
int
|
|
|
|
outputs_device_session_add(uint64_t device_id, void *session)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
|
|
|
|
device = outputs_device_get(device_id);
|
|
|
|
if (!device)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
device->session = session;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_device_session_remove(uint64_t device_id)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
|
|
|
|
device = outputs_device_get(device_id);
|
|
|
|
if (device)
|
|
|
|
device->session = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
outputs_quality_subscribe(struct media_quality *quality)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// If someone else is already subscribing to this quality we just increase the
|
|
|
|
// reference count.
|
|
|
|
for (i = 0; output_quality_subscriptions[i].count > 0; i++)
|
|
|
|
{
|
|
|
|
if (!quality_is_equal(quality, &output_quality_subscriptions[i].quality))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
output_quality_subscriptions[i].count++;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Subscription request for quality %d/%d/%d (now %d subscribers)\n",
|
|
|
|
quality->sample_rate, quality->bits_per_sample, quality->channels, output_quality_subscriptions[i].count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= (ARRAY_SIZE(output_quality_subscriptions) - 1))
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Bug! The number of different quality levels requested by outputs is too high\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_quality_subscriptions[i].quality = *quality;
|
|
|
|
output_quality_subscriptions[i].count++;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Subscription request for quality %d/%d/%d (now %d subscribers)\n",
|
|
|
|
quality->sample_rate, quality->bits_per_sample, quality->channels, output_quality_subscriptions[i].count);
|
|
|
|
|
|
|
|
// Better way of signaling this?
|
2019-03-05 16:45:38 -05:00
|
|
|
outputs_got_new_subscription = true;
|
2019-02-12 15:25:27 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_quality_unsubscribe(struct media_quality *quality)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Find subscription
|
|
|
|
for (i = 0; output_quality_subscriptions[i].count > 0; i++)
|
|
|
|
{
|
|
|
|
if (quality_is_equal(quality, &output_quality_subscriptions[i].quality))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_quality_subscriptions[i].count == 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Bug! Unsubscription request for a quality level that there is no subscription for\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_quality_subscriptions[i].count--;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Unsubscription request for quality %d/%d/%d (now %d subscribers)\n",
|
|
|
|
quality->sample_rate, quality->bits_per_sample, quality->channels, output_quality_subscriptions[i].count);
|
|
|
|
|
|
|
|
if (output_quality_subscriptions[i].count > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
transcode_encode_cleanup(&output_quality_subscriptions[i].encode_ctx);
|
|
|
|
|
|
|
|
// Shift elements
|
|
|
|
for (; i < ARRAY_SIZE(output_quality_subscriptions) - 1; i++)
|
|
|
|
output_quality_subscriptions[i] = output_quality_subscriptions[i + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output backends call back through the below wrapper to make sure that:
|
|
|
|
// 1. Callbacks are always deferred
|
|
|
|
// 2. The callback never has a dangling pointer to a device (a device that has been removed from our list)
|
|
|
|
void
|
|
|
|
outputs_cb(int callback_id, uint64_t device_id, enum output_device_state state)
|
|
|
|
{
|
|
|
|
if (callback_id < 0)
|
|
|
|
return;
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
if (!(callback_id < ARRAY_SIZE(outputs_cb_register)) || !outputs_cb_register[callback_id].cb)
|
2019-02-12 15:25:27 -05:00
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Bug! Output backend called us with an illegal callback id (%d)\n", callback_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Callback request received, id is %i\n", callback_id);
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
outputs_cb_register[callback_id].ready = true;
|
|
|
|
outputs_cb_register[callback_id].device_id = device_id;
|
|
|
|
outputs_cb_register[callback_id].state = state;
|
2019-02-12 15:25:27 -05:00
|
|
|
event_active(outputs_deferredev, 0, 0);
|
|
|
|
}
|
|
|
|
|
2023-01-22 11:23:32 -05:00
|
|
|
void
|
|
|
|
outputs_metadata_free(struct output_metadata *metadata)
|
|
|
|
{
|
|
|
|
metadata_free(metadata);
|
|
|
|
}
|
2019-02-12 15:25:27 -05:00
|
|
|
|
2023-05-01 17:35:34 -04:00
|
|
|
struct output_buffer *
|
|
|
|
outputs_buffer_copy(struct output_buffer *buffer)
|
|
|
|
{
|
|
|
|
return buffer_copy(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_buffer_free(struct output_buffer *buffer)
|
|
|
|
{
|
|
|
|
buffer_free(buffer);
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
/* ---------------------------- Called by player ---------------------------- */
|
|
|
|
|
2019-02-17 07:12:29 -05:00
|
|
|
struct output_device *
|
2020-05-01 14:11:45 -04:00
|
|
|
outputs_device_add(struct output_device *add, bool new_deselect)
|
2019-02-12 17:43:54 -05:00
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
char *keep_name;
|
|
|
|
int ret;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2019-02-12 17:43:54 -05:00
|
|
|
{
|
|
|
|
if (device->id == add->id)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:28:26 -05:00
|
|
|
// This is relevant for Airplay 1 and 2 where the same device can support both
|
|
|
|
if (device && device->type != add->type)
|
|
|
|
{
|
|
|
|
if (outputs_priority(device) < outputs_priority(add))
|
|
|
|
{
|
|
|
|
DPRINTF(E_DBG, L_PLAYER, "Ignoring type %s for device '%s', will use type %s\n", add->type_name, add->name, device->type_name);
|
|
|
|
outputs_device_free(add);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove existing device, higher priority device will be added below
|
|
|
|
outputs_device_remove(device);
|
|
|
|
device = NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:43:54 -05:00
|
|
|
// New device
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
device = add;
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
device->stop_timer = evtimer_new(evbase_player, stop_timer_cb, device);
|
|
|
|
|
2019-02-12 17:43:54 -05:00
|
|
|
keep_name = strdup(device->name);
|
|
|
|
ret = db_speaker_get(device, device->id);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
device->selected = 0;
|
2020-05-01 14:11:45 -04:00
|
|
|
device->volume = (outputs_master_volume >= 0) ? outputs_master_volume : OUTPUTS_DEFAULT_VOLUME;;
|
2019-02-12 17:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
free(device->name);
|
|
|
|
device->name = keep_name;
|
|
|
|
|
|
|
|
if (new_deselect)
|
|
|
|
device->selected = 0;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
device->next = outputs_device_list;
|
|
|
|
outputs_device_list = device;
|
2019-02-12 17:43:54 -05:00
|
|
|
}
|
|
|
|
// Update to a device already in the list
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (add->v4_address)
|
|
|
|
{
|
|
|
|
free(device->v4_address);
|
|
|
|
|
|
|
|
device->v4_address = add->v4_address;
|
|
|
|
device->v4_port = add->v4_port;
|
|
|
|
|
|
|
|
// Address is ours now
|
|
|
|
add->v4_address = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add->v6_address)
|
|
|
|
{
|
|
|
|
free(device->v6_address);
|
|
|
|
|
|
|
|
device->v6_address = add->v6_address;
|
|
|
|
device->v6_port = add->v6_port;
|
|
|
|
|
|
|
|
// Address is ours now
|
|
|
|
add->v6_address = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(device->name);
|
|
|
|
device->name = add->name;
|
|
|
|
add->name = NULL;
|
|
|
|
|
|
|
|
device->has_password = add->has_password;
|
|
|
|
device->password = add->password;
|
|
|
|
|
|
|
|
outputs_device_free(add);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_list_sort();
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
vol_adjust();
|
|
|
|
|
2019-02-13 10:56:17 -05:00
|
|
|
device->advertised = 1;
|
|
|
|
|
2019-02-17 07:12:29 -05:00
|
|
|
return device;
|
2019-02-12 17:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_device_remove(struct output_device *remove)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
struct output_device *prev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
// Device stop should be able to handle that we invalidate the device, even
|
|
|
|
// if it is an async stop. It might call outputs_device_session_remove(), but
|
|
|
|
// that just won't do anything since the id will be unknown.
|
|
|
|
if (remove->session)
|
|
|
|
outputs_device_stop(remove, device_stop_cb);
|
|
|
|
|
|
|
|
prev = NULL;
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2019-02-12 17:43:54 -05:00
|
|
|
{
|
|
|
|
if (device == remove)
|
|
|
|
break;
|
|
|
|
|
|
|
|
prev = device;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Save device volume
|
|
|
|
ret = db_speaker_save(remove);
|
|
|
|
if (ret < 0)
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "Could not save state for %s device '%s'\n", remove->type_name, remove->name);
|
|
|
|
|
2021-01-03 17:54:11 -05:00
|
|
|
DPRINTF(E_INFO, L_PLAYER, "Removing %s device '%s'\n", remove->type_name, remove->name);
|
2019-02-12 17:43:54 -05:00
|
|
|
|
|
|
|
if (!prev)
|
2020-06-28 18:19:03 -04:00
|
|
|
outputs_device_list = remove->next;
|
2019-02-12 17:43:54 -05:00
|
|
|
else
|
|
|
|
prev->next = remove->next;
|
|
|
|
|
|
|
|
outputs_device_free(remove);
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
vol_adjust();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-13 14:48:48 -04:00
|
|
|
outputs_device_select(struct output_device *device, int max_volume)
|
2020-05-01 14:11:45 -04:00
|
|
|
{
|
|
|
|
device->selected = 1;
|
|
|
|
device->prevent_playback = 0;
|
|
|
|
device->busy = 0;
|
|
|
|
|
2020-08-13 14:48:48 -04:00
|
|
|
// The purpose of this is to cap the volume for a newly selected device. It is
|
|
|
|
// used by the player to avoid this scenario:
|
|
|
|
// 1 Play on two speakers, say Kitchen (100) and Office (75), master is 100
|
|
|
|
// 2 Disable Office, reduce master to 25, Kitchen is now 25, Office is still 75
|
|
|
|
// 3 Turn on Office, it now blasts at 75
|
|
|
|
// We could avoid this by reducing the unselected Office in step 2, but that
|
|
|
|
// leads to issue #1077, where volumes of unselected devices go to 0 (e.g. by
|
|
|
|
// reducing master to 0 and then increasing again -> unselected stays at 0).
|
|
|
|
if (max_volume >= 0 && device->volume > max_volume)
|
|
|
|
device->volume = max_volume;
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
vol_adjust();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_device_deselect(struct output_device *device)
|
|
|
|
{
|
|
|
|
device->selected = 0;
|
|
|
|
|
|
|
|
vol_adjust();
|
2019-02-12 17:43:54 -05:00
|
|
|
}
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
int
|
2020-05-01 14:11:45 -04:00
|
|
|
outputs_device_start(struct output_device *device, output_status_cb cb, bool only_probe)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_start || !outputs[device->type]->device_probe)
|
2016-01-23 19:14:07 -05:00
|
|
|
return -1;
|
|
|
|
|
2019-02-10 17:20:12 -05:00
|
|
|
if (device->session)
|
2020-05-01 14:11:45 -04:00
|
|
|
return 0; // Device is already running, nothing to do
|
|
|
|
|
|
|
|
if (only_probe)
|
|
|
|
ret = outputs[device->type]->device_probe(device, callback_add(device, cb));
|
|
|
|
else
|
|
|
|
ret = outputs[device->type]->device_start(device, callback_add(device, cb));
|
2019-02-10 17:20:12 -05:00
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
return device_state_update(device, ret);;
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 19:54:52 -05:00
|
|
|
int
|
2019-02-10 17:20:12 -05:00
|
|
|
outputs_device_stop(struct output_device *device, output_status_cb cb)
|
2019-02-09 19:54:52 -05:00
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
int ret;
|
|
|
|
|
2019-02-10 17:20:12 -05:00
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_stop)
|
2019-02-09 19:54:52 -05:00
|
|
|
return -1;
|
|
|
|
|
2019-02-10 17:20:12 -05:00
|
|
|
if (!device->session)
|
2020-05-01 14:11:45 -04:00
|
|
|
return 0; // Device is already stopped, nothing to do
|
2016-01-23 19:14:07 -05:00
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
ret = outputs[device->type]->device_stop(device, callback_add(device, cb));
|
|
|
|
|
|
|
|
return device_state_update(device, ret);
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
int
|
|
|
|
outputs_device_stop_delayed(struct output_device *device, output_status_cb cb)
|
|
|
|
{
|
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_stop)
|
|
|
|
return -1;
|
|
|
|
|
2019-03-18 18:04:34 -04:00
|
|
|
if (!device->session)
|
2020-05-01 14:11:45 -04:00
|
|
|
return 0; // Device is already stopped, nothing to do
|
2019-03-18 18:04:34 -04:00
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
outputs[device->type]->device_cb_set(device, callback_add(device, cb));
|
|
|
|
|
|
|
|
event_add(device->stop_timer, &outputs_stop_timeout);
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
return 1;
|
2019-03-05 16:45:38 -05:00
|
|
|
}
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
int
|
|
|
|
outputs_device_flush(struct output_device *device, output_status_cb cb)
|
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
int ret;
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_flush)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!device->session)
|
2020-05-01 14:11:45 -04:00
|
|
|
return 0; // Nothing to flush
|
|
|
|
|
|
|
|
ret = outputs[device->type]->device_flush(device, callback_add(device, cb));
|
2019-02-16 18:19:13 -05:00
|
|
|
|
2020-05-30 15:31:27 -04:00
|
|
|
return ret; // We don't change device state just because of a failed flush
|
2019-02-16 18:19:13 -05:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
void
|
|
|
|
outputs_device_volume_register(struct output_device *device, int absvol, int relvol)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
if (absvol > -1)
|
|
|
|
device->volume = absvol;
|
|
|
|
else if (relvol > -1)
|
|
|
|
device->volume = rel_to_vol(relvol, outputs_master_volume);
|
2016-01-23 19:14:07 -05:00
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
vol_adjust();
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
outputs_device_volume_set(struct output_device *device, output_status_cb cb)
|
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
int ret;
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_volume_set)
|
2016-01-23 19:14:07 -05:00
|
|
|
return -1;
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
if (!device->session)
|
|
|
|
return 0; // Device isn't active
|
|
|
|
|
|
|
|
ret = outputs[device->type]->device_volume_set(device, callback_add(device, cb));
|
|
|
|
|
2020-05-30 15:31:27 -04:00
|
|
|
return ret; // We don't change device state just because of a failed volume change
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
2018-05-26 19:42:39 -04:00
|
|
|
int
|
|
|
|
outputs_device_volume_to_pct(struct output_device *device, const char *volume)
|
|
|
|
{
|
2019-02-12 15:25:27 -05:00
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_volume_to_pct)
|
2018-05-26 19:42:39 -04:00
|
|
|
return -1;
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
return outputs[device->type]->device_volume_to_pct(device, volume);
|
2018-05-26 19:42:39 -04:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:36:21 -05:00
|
|
|
int
|
2019-02-12 15:25:27 -05:00
|
|
|
outputs_device_quality_set(struct output_device *device, struct media_quality *quality, output_status_cb cb)
|
2019-02-08 14:36:21 -05:00
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
int ret;
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_quality_set)
|
2019-02-08 14:36:21 -05:00
|
|
|
return -1;
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
ret = outputs[device->type]->device_quality_set(device, quality, callback_add(device, cb));
|
|
|
|
|
|
|
|
return device_state_update(device, ret);
|
2019-02-08 14:36:21 -05:00
|
|
|
}
|
|
|
|
|
2020-05-26 16:42:06 -04:00
|
|
|
int
|
|
|
|
outputs_device_authorize(struct output_device *device, const char *pin, output_status_cb cb)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_authorize)
|
|
|
|
return -1;
|
|
|
|
|
2020-05-27 16:25:48 -04:00
|
|
|
if (device->session)
|
|
|
|
return 0; // We are already connected to the device - no auth required
|
|
|
|
|
2020-05-26 16:42:06 -04:00
|
|
|
ret = outputs[device->type]->device_authorize(device, pin, callback_add(device, cb));
|
|
|
|
|
2020-05-30 15:31:27 -04:00
|
|
|
return device_state_update(device, ret); // If ret < 0 then we couldn't reach the speaker
|
2020-05-26 16:42:06 -04:00
|
|
|
}
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
void
|
2019-02-12 15:25:27 -05:00
|
|
|
outputs_device_cb_set(struct output_device *device, output_status_cb cb)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
2019-02-12 15:25:27 -05:00
|
|
|
if (outputs[device->type]->disabled || !outputs[device->type]->device_cb_set)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!device->session)
|
|
|
|
return;
|
|
|
|
|
|
|
|
outputs[device->type]->device_cb_set(device, callback_add(device, cb));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_device_free(struct output_device *device)
|
|
|
|
{
|
|
|
|
if (!device)
|
2019-02-10 17:20:12 -05:00
|
|
|
return;
|
2016-01-23 19:14:07 -05:00
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
if (outputs[device->type]->disabled)
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "BUG! Freeing device from a disabled output?\n");
|
|
|
|
|
|
|
|
if (device->session)
|
|
|
|
DPRINTF(E_LOG, L_PLAYER, "BUG! Freeing device with active session?\n");
|
|
|
|
|
|
|
|
if (outputs[device->type]->device_free_extra)
|
|
|
|
outputs[device->type]->device_free_extra(device);
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
if (device->stop_timer)
|
|
|
|
event_free(device->stop_timer);
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
free(device->name);
|
|
|
|
free(device->auth_key);
|
|
|
|
free(device->v4_address);
|
|
|
|
free(device->v6_address);
|
|
|
|
|
|
|
|
free(device);
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
// The return value will be the number of devices we need to wait for, either
|
|
|
|
// because they are starting or shutting down. The return value is only negative
|
|
|
|
// if we don't have to wait, i.e. all the selected devices failed immediately.
|
2019-03-05 16:45:38 -05:00
|
|
|
int
|
2020-05-01 14:11:45 -04:00
|
|
|
outputs_start(output_status_cb started_cb, output_status_cb stopped_cb, bool only_probe)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
struct output_device *device;
|
2020-05-01 14:11:45 -04:00
|
|
|
int pending = 0;
|
2020-09-05 18:08:40 -04:00
|
|
|
int ret;
|
2016-01-23 19:14:07 -05:00
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
2020-05-01 14:11:45 -04:00
|
|
|
if (device->selected)
|
2020-09-05 18:08:40 -04:00
|
|
|
continue;
|
2020-05-01 14:11:45 -04:00
|
|
|
|
2020-09-05 18:08:40 -04:00
|
|
|
ret = outputs_device_stop(device, stopped_cb);
|
|
|
|
if (ret > 0)
|
|
|
|
pending += ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0; // We don't care about devices that returned an error on stop
|
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
|
|
|
{
|
|
|
|
if (!device->selected)
|
2016-01-23 19:14:07 -05:00
|
|
|
continue;
|
|
|
|
|
2020-09-05 18:08:40 -04:00
|
|
|
ret = outputs_device_start(device, started_cb, only_probe);
|
|
|
|
if (ret > 0)
|
|
|
|
pending += ret;
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
2019-03-05 16:45:38 -05:00
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
return (pending > 0) ? pending : ret;
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
int
|
2019-03-05 16:45:38 -05:00
|
|
|
outputs_stop(output_status_cb cb)
|
2019-02-08 14:36:21 -05:00
|
|
|
{
|
2019-02-16 18:19:13 -05:00
|
|
|
struct output_device *device;
|
2020-05-01 14:11:45 -04:00
|
|
|
int pending = 0;
|
2019-02-16 18:19:13 -05:00
|
|
|
int ret;
|
2019-02-08 14:36:21 -05:00
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2019-02-08 14:36:21 -05:00
|
|
|
{
|
2019-03-05 16:45:38 -05:00
|
|
|
ret = outputs_device_stop(device, cb);
|
2019-02-16 18:19:13 -05:00
|
|
|
if (ret < 0)
|
2019-02-08 14:36:21 -05:00
|
|
|
continue;
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
pending += ret;
|
2019-02-08 14:36:21 -05:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
return pending;
|
2019-02-08 14:36:21 -05:00
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:38 -05:00
|
|
|
int
|
|
|
|
outputs_stop_delayed_cancel(void)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2019-03-05 16:45:38 -05:00
|
|
|
event_del(device->stop_timer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
int
|
|
|
|
outputs_flush(output_status_cb cb)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
int pending = 0;
|
|
|
|
int ret;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2020-05-01 14:11:45 -04:00
|
|
|
{
|
|
|
|
ret = outputs_device_flush(device, cb);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pending += ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
int
|
|
|
|
outputs_volume_get(void)
|
|
|
|
{
|
|
|
|
return outputs_master_volume;
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
int
|
|
|
|
outputs_volume_set(int volume, output_status_cb cb)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
int pending = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (outputs_master_volume == volume)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
outputs_master_volume = volume;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2020-05-01 14:11:45 -04:00
|
|
|
{
|
|
|
|
if (!device->selected)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
device->volume = rel_to_vol(device->relvol, outputs_master_volume);
|
|
|
|
|
|
|
|
ret = outputs_device_volume_set(device, cb);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pending += ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
outputs_sessions_count(void)
|
|
|
|
{
|
|
|
|
struct output_device *device;
|
|
|
|
int count = 0;
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
for (device = outputs_device_list; device; device = device->next)
|
2020-05-01 14:11:45 -04:00
|
|
|
if (device->session)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
void
|
2019-03-03 12:17:57 -05:00
|
|
|
outputs_write(void *buf, size_t bufsize, int nsamples, struct media_quality *quality, struct timespec *pts)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
buffer_fill(&output_buffer, buf, bufsize, quality, nsamples, pts);
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
for (i = 0; outputs[i]; i++)
|
|
|
|
{
|
2019-02-16 18:19:13 -05:00
|
|
|
if (outputs[i]->disabled)
|
2016-01-23 19:14:07 -05:00
|
|
|
continue;
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
if (outputs[i]->write)
|
|
|
|
outputs[i]->write(&output_buffer);
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-16 18:19:13 -05:00
|
|
|
buffer_drain(&output_buffer);
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-18 18:04:34 -04:00
|
|
|
outputs_metadata_send(uint32_t item_id, bool startup, output_metadata_finalize_cb cb)
|
2016-01-23 19:14:07 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; outputs[i]; i++)
|
|
|
|
{
|
2019-03-18 18:04:34 -04:00
|
|
|
if (outputs[i]->disabled || !outputs[i]->metadata_send)
|
2016-01-23 19:14:07 -05:00
|
|
|
continue;
|
|
|
|
|
2019-03-18 18:04:34 -04:00
|
|
|
metadata_send(i, item_id, startup, cb);
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_metadata_purge(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; outputs[i]; i++)
|
|
|
|
{
|
2019-03-18 18:04:34 -04:00
|
|
|
if (outputs[i]->disabled || !outputs[i]->metadata_purge)
|
2016-01-23 19:14:07 -05:00
|
|
|
continue;
|
|
|
|
|
2019-03-18 18:04:34 -04:00
|
|
|
outputs[i]->metadata_purge();
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 15:54:37 -04:00
|
|
|
int
|
|
|
|
outputs_priority(struct output_device *device)
|
|
|
|
{
|
|
|
|
return outputs[device->type]->priority;
|
|
|
|
}
|
2016-01-23 19:14:07 -05:00
|
|
|
|
|
|
|
const char *
|
|
|
|
outputs_name(enum output_types type)
|
|
|
|
{
|
|
|
|
return outputs[type]->name;
|
|
|
|
}
|
|
|
|
|
2020-06-28 18:19:03 -04:00
|
|
|
struct output_device *
|
|
|
|
outputs_list(void)
|
|
|
|
{
|
|
|
|
return outputs_device_list;
|
|
|
|
}
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
int
|
|
|
|
outputs_init(void)
|
|
|
|
{
|
|
|
|
int no_output;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2020-05-01 14:11:45 -04:00
|
|
|
outputs_master_volume = -1;
|
|
|
|
|
2019-02-12 15:25:27 -05:00
|
|
|
CHECK_NULL(L_PLAYER, outputs_deferredev = evtimer_new(evbase_player, deferred_cb, NULL));
|
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
no_output = 1;
|
|
|
|
for (i = 0; outputs[i]; i++)
|
|
|
|
{
|
2016-01-24 16:19:15 -05:00
|
|
|
if (outputs[i]->type != i)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_PLAYER, "BUG! Output definitions are misaligned with output enum\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-11-27 16:46:38 -05:00
|
|
|
if (outputs[i]->disabled)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-22 17:59:50 -04:00
|
|
|
if (!outputs[i]->init)
|
2016-12-26 13:27:37 -05:00
|
|
|
{
|
|
|
|
no_output = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-22 17:59:50 -04:00
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
ret = outputs[i]->init();
|
|
|
|
if (ret < 0)
|
|
|
|
outputs[i]->disabled = 1;
|
|
|
|
else
|
|
|
|
no_output = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_output)
|
|
|
|
return -1;
|
|
|
|
|
2019-02-22 02:40:59 -05:00
|
|
|
for (i = 0; i < ARRAY_SIZE(output_buffer.data); i++)
|
|
|
|
output_buffer.data[i].evbuf = evbuffer_new();
|
2019-02-08 14:36:21 -05:00
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outputs_deinit(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-09-09 16:21:23 -04:00
|
|
|
event_free(outputs_deferredev);
|
2019-02-12 15:25:27 -05:00
|
|
|
|
2016-01-23 19:14:07 -05:00
|
|
|
for (i = 0; outputs[i]; i++)
|
|
|
|
{
|
2016-03-22 17:59:50 -04:00
|
|
|
if (outputs[i]->disabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (outputs[i]->deinit)
|
2016-01-23 19:14:07 -05:00
|
|
|
outputs[i]->deinit();
|
|
|
|
}
|
2019-02-08 14:36:21 -05:00
|
|
|
|
|
|
|
// In case some outputs forgot to unsubscribe
|
|
|
|
for (i = 0; i < ARRAY_SIZE(output_quality_subscriptions); i++)
|
|
|
|
if (output_quality_subscriptions[i].count > 0)
|
|
|
|
{
|
|
|
|
transcode_encode_cleanup(&output_quality_subscriptions[i].encode_ctx);
|
|
|
|
memset(&output_quality_subscriptions[i], 0, sizeof(struct output_quality_subscription));
|
|
|
|
}
|
|
|
|
|
2019-02-22 02:40:59 -05:00
|
|
|
for (i = 0; i < ARRAY_SIZE(output_buffer.data); i++)
|
|
|
|
evbuffer_free(output_buffer.data[i].evbuf);
|
2016-01-23 19:14:07 -05:00
|
|
|
}
|
|
|
|
|