2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01: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.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2008-10-31 09:19:53 +01:00
|
|
|
#ifndef MPD_PLAYER_H
|
|
|
|
#define MPD_PLAYER_H
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2013-01-10 09:30:01 +01:00
|
|
|
#include "thread/Mutex.hxx"
|
|
|
|
#include "thread/Cond.hxx"
|
2013-10-17 18:42:14 +02:00
|
|
|
#include "thread/Thread.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2013-10-29 00:14:27 +01:00
|
|
|
#include "CrossFade.hxx"
|
2014-08-27 18:50:16 +02:00
|
|
|
#include "Chrono.hxx"
|
2008-10-08 10:49:29 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2014-02-21 08:55:52 +01:00
|
|
|
class PlayerListener;
|
2014-01-27 08:20:25 +01:00
|
|
|
class MultipleOutputs;
|
2014-01-07 21:39:47 +01:00
|
|
|
class DetachedSong;
|
2009-10-31 19:22:56 +01:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
enum class PlayerState : uint8_t {
|
|
|
|
STOP,
|
|
|
|
PAUSE,
|
|
|
|
PLAY
|
2008-08-26 08:27:08 +02:00
|
|
|
};
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
enum class PlayerCommand : uint8_t {
|
|
|
|
NONE,
|
|
|
|
EXIT,
|
|
|
|
STOP,
|
|
|
|
PAUSE,
|
|
|
|
SEEK,
|
|
|
|
CLOSE_AUDIO,
|
2008-10-12 00:07:54 +02:00
|
|
|
|
2009-10-23 10:55:52 +02:00
|
|
|
/**
|
2014-01-28 11:34:09 +01:00
|
|
|
* At least one AudioOutput.enabled flag has been modified;
|
2009-10-23 10:55:52 +02:00
|
|
|
* commit those changes to the output threads.
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
UPDATE_AUDIO,
|
2009-10-23 10:55:52 +02:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
/** PlayerControl.next_song has been updated */
|
2013-09-27 22:07:20 +02:00
|
|
|
QUEUE,
|
2008-10-12 00:07:54 +02:00
|
|
|
|
|
|
|
/**
|
2013-10-28 10:12:21 +01:00
|
|
|
* cancel pre-decoding PlayerControl.next_song; if the player
|
2008-10-12 00:07:54 +02:00
|
|
|
* has already started playing this song, it will completely
|
|
|
|
* stop
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
CANCEL,
|
2009-10-08 22:09:25 +02:00
|
|
|
|
|
|
|
/**
|
2013-10-28 10:12:21 +01:00
|
|
|
* Refresh status information in the #PlayerControl struct,
|
2009-10-08 22:09:25 +02:00
|
|
|
* e.g. elapsed_time.
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
REFRESH,
|
2008-08-26 08:27:07 +02:00
|
|
|
};
|
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
enum class PlayerError : uint8_t {
|
|
|
|
NONE,
|
2012-08-08 22:22:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The decoder has failed to decode the song.
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
DECODER,
|
2012-08-08 22:22:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The audio output has failed.
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
OUTPUT,
|
2008-11-03 21:49:40 +01:00
|
|
|
};
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-10-08 20:48:07 +02:00
|
|
|
struct player_status {
|
2013-09-27 22:07:20 +02:00
|
|
|
PlayerState state;
|
2009-10-08 20:48:07 +02:00
|
|
|
uint16_t bit_rate;
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat audio_format;
|
2009-10-08 20:48:07 +02:00
|
|
|
float total_time;
|
|
|
|
float elapsed_time;
|
|
|
|
};
|
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
struct PlayerControl {
|
2014-02-21 08:55:52 +01:00
|
|
|
PlayerListener &listener;
|
|
|
|
|
2014-01-27 08:20:25 +01:00
|
|
|
MultipleOutputs &outputs;
|
|
|
|
|
2009-03-06 00:42:03 +01:00
|
|
|
unsigned buffer_chunks;
|
|
|
|
|
2008-08-26 08:45:14 +02:00
|
|
|
unsigned int buffered_before_play;
|
|
|
|
|
2013-10-17 18:42:14 +02:00
|
|
|
/**
|
|
|
|
* The handle of the player thread.
|
|
|
|
*/
|
|
|
|
Thread thread;
|
2009-01-25 13:44:33 +01:00
|
|
|
|
2009-10-31 17:02:12 +01:00
|
|
|
/**
|
2013-10-21 23:22:16 +02:00
|
|
|
* This lock protects #command, #state, #error, #tagged_song.
|
2009-10-31 17:02:12 +01:00
|
|
|
*/
|
2013-01-20 17:48:23 +01:00
|
|
|
mutable Mutex mutex;
|
2009-10-31 17:02:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger this object after you have modified #command.
|
|
|
|
*/
|
2013-01-10 09:30:01 +01:00
|
|
|
Cond cond;
|
2009-10-31 17:02:12 +01:00
|
|
|
|
2013-01-25 23:53:43 +01:00
|
|
|
/**
|
|
|
|
* This object gets signalled when the player thread has
|
|
|
|
* finished the #command. It wakes up the client that waits
|
|
|
|
* (i.e. the main thread).
|
|
|
|
*/
|
|
|
|
Cond client_cond;
|
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
PlayerCommand command;
|
|
|
|
PlayerState state;
|
2012-08-08 22:25:02 +02:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
PlayerError error_type;
|
2012-08-08 22:25:02 +02:00
|
|
|
|
2012-08-08 22:18:08 +02:00
|
|
|
/**
|
|
|
|
* The error that occurred in the player thread. This
|
|
|
|
* attribute is only valid if #error is not
|
2013-09-27 22:07:20 +02:00
|
|
|
* #PlayerError::NONE. The object must be freed when this
|
|
|
|
* object transitions back to #PlayerError::NONE.
|
2012-08-08 22:18:08 +02:00
|
|
|
*/
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2012-08-08 22:18:08 +02:00
|
|
|
|
2013-10-21 23:22:16 +02:00
|
|
|
/**
|
2014-01-07 21:39:47 +01:00
|
|
|
* A copy of the current #DetachedSong after its tags have
|
|
|
|
* been updated by the decoder (for example, a radio stream
|
|
|
|
* that has sent a new tag after switching to the next song).
|
2014-02-21 08:55:52 +01:00
|
|
|
* This shall be used by PlayerListener::OnPlayerTagModified()
|
|
|
|
* to update the current #DetachedSong in the queue.
|
2013-10-21 23:22:16 +02:00
|
|
|
*
|
|
|
|
* Protected by #mutex. Set by the PlayerThread and consumed
|
|
|
|
* by the main thread.
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
DetachedSong *tagged_song;
|
2013-10-21 23:22:16 +02:00
|
|
|
|
2008-11-03 21:49:36 +01:00
|
|
|
uint16_t bit_rate;
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat audio_format;
|
2008-11-03 21:49:36 +01:00
|
|
|
float total_time;
|
|
|
|
float elapsed_time;
|
2012-08-09 22:19:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The next queued song.
|
|
|
|
*
|
|
|
|
* This is a duplicate, and must be freed when this attribute
|
|
|
|
* is cleared.
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
DetachedSong *next_song;
|
2012-08-09 22:19:39 +02:00
|
|
|
|
2014-08-27 18:50:16 +02:00
|
|
|
SongTime seek_time;
|
2013-10-29 00:14:27 +01:00
|
|
|
|
|
|
|
CrossFadeSettings cross_fade;
|
|
|
|
|
2008-11-03 21:49:36 +01:00
|
|
|
double total_play_time;
|
2012-08-25 08:44:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this flag is set, then the player will be auto-paused at
|
|
|
|
* the end of the song, before the next song starts to play.
|
|
|
|
*
|
|
|
|
* This is a copy of the queue's "single" flag most of the
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
bool border_pause;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2014-02-21 08:55:52 +01:00
|
|
|
PlayerControl(PlayerListener &_listener,
|
|
|
|
MultipleOutputs &_outputs,
|
2014-01-27 08:20:25 +01:00
|
|
|
unsigned buffer_chunks,
|
2013-10-28 10:12:21 +01:00
|
|
|
unsigned buffered_before_play);
|
|
|
|
~PlayerControl();
|
2008-09-24 07:14:11 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Locks the object.
|
|
|
|
*/
|
|
|
|
void Lock() const {
|
|
|
|
mutex.lock();
|
|
|
|
}
|
2009-10-31 17:02:12 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Unlocks the object.
|
|
|
|
*/
|
|
|
|
void Unlock() const {
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Signals the object. The object should be locked prior to
|
|
|
|
* calling this function.
|
|
|
|
*/
|
|
|
|
void Signal() {
|
|
|
|
cond.signal();
|
|
|
|
}
|
2008-10-12 00:07:54 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Signals the object. The object is temporarily locked by
|
|
|
|
* this function.
|
|
|
|
*/
|
|
|
|
void LockSignal() {
|
|
|
|
Lock();
|
|
|
|
Signal();
|
|
|
|
Unlock();
|
|
|
|
}
|
2004-02-25 01:08:48 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Waits for a signal on the object. This function is only
|
|
|
|
* valid in the player thread. The object must be locked
|
|
|
|
* prior to calling this function.
|
|
|
|
*/
|
|
|
|
void Wait() {
|
2013-10-17 18:42:14 +02:00
|
|
|
assert(thread.IsInside());
|
2013-01-25 23:53:43 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
cond.wait(mutex);
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-25 23:53:43 +01:00
|
|
|
/**
|
|
|
|
* Wake up the client waiting for command completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the object.
|
|
|
|
*/
|
|
|
|
void ClientSignal() {
|
2013-10-17 18:42:14 +02:00
|
|
|
assert(thread.IsInside());
|
2013-01-25 23:53:43 +01:00
|
|
|
|
|
|
|
client_cond.signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The client calls this method to wait for command
|
|
|
|
* completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the object.
|
|
|
|
*/
|
|
|
|
void ClientWait() {
|
2013-10-17 18:42:14 +02:00
|
|
|
assert(!thread.IsInside());
|
2013-01-25 23:53:43 +01:00
|
|
|
|
|
|
|
client_cond.wait(mutex);
|
|
|
|
}
|
|
|
|
|
2013-09-27 07:58:48 +02:00
|
|
|
/**
|
|
|
|
* A command has been finished. This method clears the
|
|
|
|
* command and signals the client.
|
|
|
|
*
|
|
|
|
* To be called from the player thread. Caller must lock the
|
|
|
|
* object.
|
|
|
|
*/
|
|
|
|
void CommandFinished() {
|
2013-09-27 22:07:20 +02:00
|
|
|
assert(command != PlayerCommand::NONE);
|
2013-09-27 07:58:48 +02:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
command = PlayerCommand::NONE;
|
2013-09-27 07:58:48 +02:00
|
|
|
ClientSignal();
|
|
|
|
}
|
|
|
|
|
2013-09-27 09:20:53 +02:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Wait for the command to be finished by the player thread.
|
|
|
|
*
|
|
|
|
* To be called from the main thread. Caller must lock the
|
|
|
|
* object.
|
|
|
|
*/
|
|
|
|
void WaitCommandLocked() {
|
2013-09-27 22:07:20 +02:00
|
|
|
while (command != PlayerCommand::NONE)
|
2013-09-27 09:20:53 +02:00
|
|
|
ClientWait();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a command to the player thread and synchronously wait
|
|
|
|
* for it to finish.
|
|
|
|
*
|
|
|
|
* To be called from the main thread. Caller must lock the
|
|
|
|
* object.
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
void SynchronousCommand(PlayerCommand cmd) {
|
|
|
|
assert(command == PlayerCommand::NONE);
|
2013-09-27 09:20:53 +02:00
|
|
|
|
|
|
|
command = cmd;
|
|
|
|
Signal();
|
|
|
|
WaitCommandLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a command to the player thread and synchronously wait
|
|
|
|
* for it to finish.
|
|
|
|
*
|
|
|
|
* To be called from the main thread. This method locks the
|
|
|
|
* object.
|
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
void LockSynchronousCommand(PlayerCommand cmd) {
|
2013-09-27 09:20:53 +02:00
|
|
|
Lock();
|
|
|
|
SynchronousCommand(cmd);
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* @param song the song to be queued; the given instance will
|
|
|
|
* be owned and freed by the player
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
void Play(DetachedSong *song);
|
2012-08-25 08:44:31 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
2013-09-27 22:07:20 +02:00
|
|
|
* see PlayerCommand::CANCEL
|
2013-01-20 17:48:23 +01:00
|
|
|
*/
|
|
|
|
void Cancel();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
void SetPause(bool pause_flag);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-09-27 09:20:53 +02:00
|
|
|
private:
|
|
|
|
void PauseLocked();
|
|
|
|
|
|
|
|
public:
|
2013-01-20 17:48:23 +01:00
|
|
|
void Pause();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Set the player's #border_pause flag.
|
|
|
|
*/
|
|
|
|
void SetBorderPause(bool border_pause);
|
2012-08-08 22:18:08 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
void Kill();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
gcc_pure
|
|
|
|
player_status GetStatus();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
PlayerState GetState() const {
|
2013-01-20 17:48:23 +01:00
|
|
|
return state;
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* Set the error. Discards any previous error condition.
|
|
|
|
*
|
|
|
|
* Caller must lock the object.
|
|
|
|
*
|
2013-09-27 22:07:20 +02:00
|
|
|
* @param type the error type; must not be #PlayerError::NONE
|
2013-08-10 18:02:44 +02:00
|
|
|
* @param error detailed error information; must be defined.
|
2013-01-20 17:48:23 +01:00
|
|
|
*/
|
2013-09-27 22:07:20 +02:00
|
|
|
void SetError(PlayerError type, Error &&error);
|
2007-06-01 20:10:13 +02:00
|
|
|
|
2013-10-17 19:34:59 +02:00
|
|
|
/**
|
|
|
|
* Checks whether an error has occurred, and if so, returns a
|
|
|
|
* copy of the #Error object.
|
|
|
|
*
|
|
|
|
* Caller must lock the object.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
Error GetError() const {
|
|
|
|
Error result;
|
|
|
|
if (error_type != PlayerError::NONE)
|
|
|
|
result.Set(error);
|
|
|
|
return result;
|
|
|
|
}
|
2009-10-23 10:55:52 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
2013-10-17 19:34:59 +02:00
|
|
|
* Like GetError(), but locks and unlocks the object.
|
2013-01-20 17:48:23 +01:00
|
|
|
*/
|
2013-10-17 19:34:59 +02:00
|
|
|
gcc_pure
|
|
|
|
Error LockGetError() const {
|
|
|
|
Lock();
|
|
|
|
Error result = GetError();
|
|
|
|
Unlock();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearError();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
PlayerError GetErrorType() const {
|
2013-01-20 17:48:23 +01:00
|
|
|
return error_type;
|
|
|
|
}
|
|
|
|
|
2013-10-21 23:22:16 +02:00
|
|
|
/**
|
|
|
|
* Set the #tagged_song attribute to a newly allocated copy of
|
2014-01-07 21:39:47 +01:00
|
|
|
* the given #DetachedSong. Locks and unlocks the object.
|
2013-10-21 23:22:16 +02:00
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
void LockSetTaggedSong(const DetachedSong &song);
|
2013-10-21 23:22:16 +02:00
|
|
|
|
|
|
|
void ClearTaggedSong();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read and clear the #tagged_song attribute.
|
|
|
|
*
|
|
|
|
* Caller must lock the object.
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
DetachedSong *ReadTaggedSong() {
|
|
|
|
DetachedSong *result = tagged_song;
|
2013-10-21 23:22:16 +02:00
|
|
|
tagged_song = nullptr;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like ReadTaggedSong(), but locks and unlocks the object.
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
DetachedSong *LockReadTaggedSong() {
|
2013-10-21 23:22:16 +02:00
|
|
|
Lock();
|
2014-01-07 21:39:47 +01:00
|
|
|
DetachedSong *result = ReadTaggedSong();
|
2013-10-21 23:22:16 +02:00
|
|
|
Unlock();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
void Stop();
|
|
|
|
|
|
|
|
void UpdateAudio();
|
|
|
|
|
2013-09-27 09:20:53 +02:00
|
|
|
private:
|
2014-01-07 21:39:47 +01:00
|
|
|
void EnqueueSongLocked(DetachedSong *song) {
|
2013-09-27 09:20:53 +02:00
|
|
|
assert(song != nullptr);
|
|
|
|
assert(next_song == nullptr);
|
|
|
|
|
|
|
|
next_song = song;
|
2013-09-27 22:07:20 +02:00
|
|
|
SynchronousCommand(PlayerCommand::QUEUE);
|
2013-09-27 09:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-01-20 17:48:23 +01:00
|
|
|
/**
|
|
|
|
* @param song the song to be queued; the given instance will be owned
|
|
|
|
* and freed by the player
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
void EnqueueSong(DetachedSong *song);
|
2013-01-20 17:48:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the player thread seek the specified song to a position.
|
|
|
|
*
|
|
|
|
* @param song the song to be queued; the given instance will be owned
|
|
|
|
* and freed by the player
|
|
|
|
* @return true on success, false on failure (e.g. if MPD isn't
|
|
|
|
* playing currently)
|
|
|
|
*/
|
2014-08-27 18:50:16 +02:00
|
|
|
bool Seek(DetachedSong *song, SongTime t);
|
2013-01-20 17:48:23 +01:00
|
|
|
|
|
|
|
void SetCrossFade(float cross_fade_seconds);
|
|
|
|
|
|
|
|
float GetCrossFade() const {
|
2013-10-29 00:14:27 +01:00
|
|
|
return cross_fade.duration;
|
2013-01-20 17:48:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetMixRampDb(float mixramp_db);
|
|
|
|
|
|
|
|
float GetMixRampDb() const {
|
2013-10-29 00:14:27 +01:00
|
|
|
return cross_fade.mixramp_db;
|
2013-01-20 17:48:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetMixRampDelay(float mixramp_delay_seconds);
|
|
|
|
|
|
|
|
float GetMixRampDelay() const {
|
2013-10-29 00:14:27 +01:00
|
|
|
return cross_fade.mixramp_delay;
|
2013-01-20 17:48:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetTotalPlayTime() const {
|
|
|
|
return total_play_time;
|
|
|
|
}
|
|
|
|
};
|
Initial cut of fork() => pthreads() for decoder and player
I initially started to do a heavy rewrite that changed the way processes
communicated, but that was too much to do at once. So this change only
focuses on replacing the player and decode processes with threads and
using condition variables instead of polling in loops; so the changeset
itself is quiet small.
* The shared output buffer variables will still need locking
to guard against race conditions. So in this effect, we're probably
just as buggy as before. The reduced context-switching overhead of
using threads instead of processes may even make bugs show up more or
less often...
* Basic functionality appears to be working for playing local (and NFS)
audio, including:
play, pause, stop, seek, previous, next, and main playlist editing
* I haven't tested HTTP streams yet, they should work.
* I've only tested ALSA and Icecast. ALSA works fine, Icecast
metadata seems to get screwy at times and breaks song
advancement in the playlist at times.
* state file loading works, too (after some last-minute hacks with
non-blocking wakeup functions)
* The non-blocking (*_nb) variants of the task management functions are
probably overused. They're more lenient and easier to use because
much of our code is still based on our previous polling-based system.
* It currently segfaults on exit. I haven't paid much attention
to the exit/signal-handling routines other than ensuring it
compiles. At least the state file seems to work. We don't
do any cleanups of the threads on exit, yet.
* Update is still done in a child process and not in a thread.
To do this in a thread, we'll need to ensure it does proper
locking and communication with the main thread; but should
require less memory in the end because we'll be updating
the database "in-place" rather than updating a copy and
then bulk-loading when done.
* We're more sensitive to bugs in 3rd party libraries now.
My plan is to eventually use a master process which forks()
and restarts the child when it dies:
locking and communication with the main thread; but should
require less memory in the end because we'll be updating
the database "in-place" rather than updating a copy and
then bulk-loading when done.
* We're more sensitive to bugs in 3rd party libraries now.
My plan is to eventually use a master process which forks()
and restarts the child when it dies:
master - just does waitpid() + fork() in a loop
\- main thread
\- decoder thread
\- player thread
At the beginning of every song, the main thread will set
a dirty flag and update the state file. This way, if we
encounter a song that triggers a segfault killing the
main thread, the master will start the replacement main
on the next song.
* The main thread still wakes up every second on select()
to check for signals; which affects power management.
[merged r7138 from branches/ew]
git-svn-id: https://svn.musicpd.org/mpd/trunk@7240 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 06:08:00 +02:00
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#endif
|