2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2013-04-17 01:12:05 +02:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2008-09-24 07:20:55 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-24 07:20:55 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-17 01:12:05 +02:00
|
|
|
#ifndef MPD_OUTPUT_INTERNAL_HXX
|
|
|
|
#define MPD_OUTPUT_INTERNAL_HXX
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2013-07-29 08:10:10 +02:00
|
|
|
#include "pcm/PcmBuffer.hxx"
|
2013-04-17 01:19:25 +02:00
|
|
|
#include "thread/Mutex.hxx"
|
|
|
|
#include "thread/Cond.hxx"
|
2013-10-17 18:42:14 +02:00
|
|
|
#include "thread/Thread.hxx"
|
2009-10-29 17:06:40 +01:00
|
|
|
|
2008-10-29 22:32:50 +01:00
|
|
|
#include <time.h>
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
class Error;
|
2013-02-01 18:40:36 +01:00
|
|
|
class Filter;
|
2013-09-26 21:51:45 +02:00
|
|
|
class MusicPipe;
|
2011-09-16 23:31:48 +02:00
|
|
|
struct config_param;
|
2013-09-27 22:56:30 +02:00
|
|
|
typedef struct _GTimer GTimer;
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2009-02-16 00:43:12 +01:00
|
|
|
enum audio_output_command {
|
|
|
|
AO_COMMAND_NONE = 0,
|
2009-10-23 10:55:52 +02:00
|
|
|
AO_COMMAND_ENABLE,
|
|
|
|
AO_COMMAND_DISABLE,
|
2009-02-16 00:43:12 +01:00
|
|
|
AO_COMMAND_OPEN,
|
2009-07-06 10:01:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This command is invoked when the input audio format
|
|
|
|
* changes.
|
|
|
|
*/
|
|
|
|
AO_COMMAND_REOPEN,
|
|
|
|
|
2009-02-16 00:43:12 +01:00
|
|
|
AO_COMMAND_CLOSE,
|
|
|
|
AO_COMMAND_PAUSE,
|
2009-11-09 22:16:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Drains the internal (hardware) buffers of the device. This
|
|
|
|
* operation may take a while to complete.
|
|
|
|
*/
|
|
|
|
AO_COMMAND_DRAIN,
|
|
|
|
|
2009-02-16 00:43:12 +01:00
|
|
|
AO_COMMAND_CANCEL,
|
|
|
|
AO_COMMAND_KILL
|
|
|
|
};
|
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
struct audio_output {
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The device's configured display name.
|
|
|
|
*/
|
2008-09-24 07:20:55 +02:00
|
|
|
const char *name;
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The plugin which implements this output device.
|
|
|
|
*/
|
2008-09-24 07:20:55 +02:00
|
|
|
const struct audio_output_plugin *plugin;
|
|
|
|
|
2009-03-26 18:23:23 +01:00
|
|
|
/**
|
|
|
|
* The #mixer object associated with this audio output device.
|
|
|
|
* May be NULL if none is available, or if software volume is
|
|
|
|
* configured.
|
|
|
|
*/
|
2013-04-16 21:33:25 +02:00
|
|
|
class Mixer *mixer;
|
2009-03-26 18:23:23 +01:00
|
|
|
|
2012-09-25 23:28:53 +02:00
|
|
|
/**
|
|
|
|
* Will this output receive tags from the decoder? The
|
|
|
|
* default is true, but it may be configured to false to
|
|
|
|
* suppress sending tags to the output.
|
|
|
|
*/
|
|
|
|
bool tags;
|
|
|
|
|
2010-03-03 20:29:33 +01:00
|
|
|
/**
|
|
|
|
* Shall this output always play something (i.e. silence),
|
|
|
|
* even when playback is stopped?
|
|
|
|
*/
|
|
|
|
bool always_on;
|
|
|
|
|
2008-10-29 20:49:51 +01:00
|
|
|
/**
|
|
|
|
* Has the user enabled this device?
|
|
|
|
*/
|
|
|
|
bool enabled;
|
|
|
|
|
2009-10-23 10:55:52 +02:00
|
|
|
/**
|
|
|
|
* Is this device actually enabled, i.e. the "enable" method
|
|
|
|
* has succeeded?
|
|
|
|
*/
|
|
|
|
bool really_enabled;
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* Is the device (already) open and functional?
|
2009-03-25 17:07:15 +01:00
|
|
|
*
|
|
|
|
* This attribute may only be modified by the output thread.
|
|
|
|
* It is protected with #mutex: write accesses inside the
|
|
|
|
* output thread and read accesses outside of it may only be
|
|
|
|
* performed while the lock is held.
|
2008-09-24 07:21:46 +02:00
|
|
|
*/
|
2008-10-29 20:40:27 +01:00
|
|
|
bool open;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
2009-08-14 11:52:12 +02:00
|
|
|
/**
|
|
|
|
* Is the device paused? i.e. the output thread is in the
|
|
|
|
* ao_pause() loop.
|
|
|
|
*/
|
|
|
|
bool pause;
|
|
|
|
|
2011-09-01 07:13:21 +02:00
|
|
|
/**
|
|
|
|
* When this flag is set, the output thread will not do any
|
|
|
|
* playback. It will wait until the flag is cleared.
|
|
|
|
*
|
|
|
|
* This is used to synchronize the "clear" operation on the
|
|
|
|
* shared music pipe during the CANCEL command.
|
|
|
|
*/
|
|
|
|
bool allow_play;
|
|
|
|
|
2008-10-29 22:32:50 +01:00
|
|
|
/**
|
2009-02-28 20:43:23 +01:00
|
|
|
* If not NULL, the device has failed, and this timer is used
|
|
|
|
* to estimate how long it should stay disabled (unless
|
|
|
|
* explicitly reopened with "play").
|
2008-10-29 22:32:50 +01:00
|
|
|
*/
|
2009-02-28 20:43:23 +01:00
|
|
|
GTimer *fail_timer;
|
2008-10-29 22:32:50 +01:00
|
|
|
|
2009-10-21 22:37:28 +02:00
|
|
|
/**
|
|
|
|
* The configured audio format.
|
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat config_audio_format;
|
2009-10-21 22:37:28 +02:00
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The audio_format in which audio data is received from the
|
|
|
|
* player thread (which in turn receives it from the decoder).
|
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat in_audio_format;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The audio_format which is really sent to the device. This
|
2009-02-10 21:50:51 +01:00
|
|
|
* is basically config_audio_format (if configured) or
|
|
|
|
* in_audio_format, but may have been modified by
|
2008-09-24 07:21:46 +02:00
|
|
|
* plugin->open().
|
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat out_audio_format;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
2010-05-02 15:31:31 +02:00
|
|
|
/**
|
|
|
|
* The buffer used to allocate the cross-fading result.
|
|
|
|
*/
|
2013-07-29 08:10:10 +02:00
|
|
|
PcmBuffer cross_fade_buffer;
|
2010-05-02 15:31:31 +02:00
|
|
|
|
2009-07-06 10:01:47 +02:00
|
|
|
/**
|
|
|
|
* The filter object of this audio output. This is an
|
|
|
|
* instance of chain_filter_plugin.
|
|
|
|
*/
|
2013-02-01 18:40:36 +01:00
|
|
|
Filter *filter;
|
2009-07-06 10:01:47 +02:00
|
|
|
|
2010-02-14 17:04:39 +01:00
|
|
|
/**
|
|
|
|
* The replay_gain_filter_plugin instance of this audio
|
|
|
|
* output.
|
|
|
|
*/
|
2013-02-01 18:40:36 +01:00
|
|
|
Filter *replay_gain_filter;
|
2010-02-14 17:04:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The serial number of the last replay gain info. 0 means no
|
|
|
|
* replay gain info was available.
|
|
|
|
*/
|
|
|
|
unsigned replay_gain_serial;
|
|
|
|
|
2010-05-02 15:57:59 +02:00
|
|
|
/**
|
|
|
|
* The replay_gain_filter_plugin instance of this audio
|
|
|
|
* output, to be applied to the second chunk during
|
|
|
|
* cross-fading.
|
|
|
|
*/
|
2013-02-01 18:40:36 +01:00
|
|
|
Filter *other_replay_gain_filter;
|
2010-05-02 15:57:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The serial number of the last replay gain info by the
|
|
|
|
* "other" chunk during cross-fading.
|
|
|
|
*/
|
|
|
|
unsigned other_replay_gain_serial;
|
|
|
|
|
2009-07-06 10:01:47 +02:00
|
|
|
/**
|
|
|
|
* The convert_filter_plugin instance of this audio output.
|
|
|
|
* It is the last item in the filter chain, and is responsible
|
|
|
|
* for converting the input data into the appropriate format
|
|
|
|
* for this audio output.
|
|
|
|
*/
|
2013-02-01 18:40:36 +01:00
|
|
|
Filter *convert_filter;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
2008-12-28 22:09:42 +01:00
|
|
|
* The thread handle, or NULL if the output thread isn't
|
2008-09-24 07:21:46 +02:00
|
|
|
* running.
|
|
|
|
*/
|
2013-10-17 18:42:14 +02:00
|
|
|
Thread thread;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The next command to be performed by the output thread.
|
|
|
|
*/
|
2008-09-24 07:20:55 +02:00
|
|
|
enum audio_output_command command;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
|
|
|
/**
|
2009-03-09 19:25:26 +01:00
|
|
|
* The music pipe which provides music chunks to be played.
|
2008-09-24 07:21:46 +02:00
|
|
|
*/
|
2013-09-26 21:51:45 +02:00
|
|
|
const MusicPipe *pipe;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2009-03-09 19:25:26 +01:00
|
|
|
/**
|
2010-11-04 23:40:43 +01:00
|
|
|
* This mutex protects #open, #fail_timer, #chunk and
|
|
|
|
* #chunk_finished.
|
2009-03-09 19:25:26 +01:00
|
|
|
*/
|
2013-04-17 01:19:25 +02:00
|
|
|
Mutex mutex;
|
2009-03-09 19:25:26 +01:00
|
|
|
|
2009-10-29 17:06:40 +01:00
|
|
|
/**
|
|
|
|
* This condition object wakes up the output thread after
|
|
|
|
* #command has been set.
|
|
|
|
*/
|
2013-04-17 01:19:25 +02:00
|
|
|
Cond cond;
|
2009-10-29 17:06:40 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
/**
|
|
|
|
* The player_control object which "owns" this output. This
|
|
|
|
* object is needed to signal command completion.
|
|
|
|
*/
|
|
|
|
struct player_control *player_control;
|
|
|
|
|
2009-03-09 19:25:26 +01:00
|
|
|
/**
|
|
|
|
* The #music_chunk which is currently being played. All
|
|
|
|
* chunks before this one may be returned to the
|
|
|
|
* #music_buffer, because they are not going to be used by
|
|
|
|
* this output anymore.
|
|
|
|
*/
|
|
|
|
const struct music_chunk *chunk;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Has the output finished playing #chunk?
|
|
|
|
*/
|
|
|
|
bool chunk_finished;
|
2008-09-24 07:20:55 +02:00
|
|
|
};
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* Notify object used by the thread's client, i.e. we will send a
|
|
|
|
* notify signal to this object, expecting the caller to wait on it.
|
|
|
|
*/
|
2008-09-24 07:20:55 +02:00
|
|
|
extern struct notify audio_output_client_notify;
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
static inline bool
|
2008-09-24 07:25:07 +02:00
|
|
|
audio_output_is_open(const struct audio_output *ao)
|
|
|
|
{
|
|
|
|
return ao->open;
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
static inline bool
|
2008-09-24 07:23:19 +02:00
|
|
|
audio_output_command_is_finished(const struct audio_output *ao)
|
|
|
|
{
|
|
|
|
return ao->command == AO_COMMAND_NONE;
|
|
|
|
}
|
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
struct audio_output *
|
2013-08-04 12:25:08 +02:00
|
|
|
audio_output_new(const config_param ¶m,
|
2011-09-16 23:31:48 +02:00
|
|
|
struct player_control *pc,
|
2013-08-10 18:02:44 +02:00
|
|
|
Error &error);
|
2011-09-16 23:31:48 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
ao_base_init(struct audio_output *ao,
|
|
|
|
const struct audio_output_plugin *plugin,
|
2013-08-10 18:02:44 +02:00
|
|
|
const config_param ¶m, Error &error);
|
2011-09-16 23:31:48 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
ao_base_finish(struct audio_output *ao);
|
|
|
|
|
2011-08-30 22:28:15 +02:00
|
|
|
void
|
2011-09-16 23:31:48 +02:00
|
|
|
audio_output_free(struct audio_output *ao);
|
2011-08-30 22:28:15 +02:00
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
#endif
|