2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2013-01-04 08:41:16 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2008-08-26 08:41:05 +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-08-26 08:41:05 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-04 22:31:53 +01:00
|
|
|
#include "PlayerControl.hxx"
|
2013-01-09 08:36:52 +01:00
|
|
|
#include "Idle.hxx"
|
2013-07-28 13:25:12 +02:00
|
|
|
#include "Song.hxx"
|
2013-01-04 08:41:16 +01:00
|
|
|
#include "DecoderControl.hxx"
|
2008-08-26 08:41:05 +02:00
|
|
|
|
2013-01-07 08:53:08 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <assert.h>
|
2010-06-19 13:17:53 +02:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::PlayerControl(unsigned _buffer_chunks,
|
|
|
|
unsigned _buffered_before_play)
|
2013-01-04 22:45:14 +01:00
|
|
|
:buffer_chunks(_buffer_chunks),
|
|
|
|
buffered_before_play(_buffered_before_play),
|
2013-09-27 22:07:20 +02:00
|
|
|
command(PlayerCommand::NONE),
|
|
|
|
state(PlayerState::STOP),
|
|
|
|
error_type(PlayerError::NONE),
|
2013-10-26 15:37:35 +02:00
|
|
|
tagged_song(nullptr),
|
2013-01-04 23:04:42 +01:00
|
|
|
next_song(nullptr),
|
2013-01-15 23:21:14 +01:00
|
|
|
total_play_time(0),
|
|
|
|
border_pause(false)
|
2008-08-26 08:45:14 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::~PlayerControl()
|
2008-09-24 07:14:11 +02:00
|
|
|
{
|
2013-01-04 22:45:14 +01:00
|
|
|
if (next_song != nullptr)
|
2013-07-28 13:25:12 +02:00
|
|
|
next_song->Free();
|
2013-10-21 23:22:16 +02:00
|
|
|
|
|
|
|
if (tagged_song != nullptr)
|
|
|
|
tagged_song->Free();
|
2009-10-31 17:02:12 +01:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::Play(Song *song)
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-10-19 18:19:03 +02:00
|
|
|
assert(song != nullptr);
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
2010-06-19 13:17:53 +02:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
if (state != PlayerState::STOP)
|
|
|
|
SynchronousCommand(PlayerCommand::STOP);
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
assert(next_song == nullptr);
|
2009-10-08 21:17:00 +02:00
|
|
|
|
2013-09-27 09:20:53 +02:00
|
|
|
EnqueueSongLocked(song);
|
2008-10-14 22:38:14 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
assert(next_song == nullptr);
|
2009-10-08 21:17:00 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Unlock();
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::Cancel()
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-09-27 22:07:20 +02:00
|
|
|
LockSynchronousCommand(PlayerCommand::CANCEL);
|
2013-10-19 18:19:03 +02:00
|
|
|
assert(next_song == nullptr);
|
2008-10-12 00:07:54 +02:00
|
|
|
}
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2009-10-08 21:12:57 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::Stop()
|
2008-10-12 00:07:54 +02:00
|
|
|
{
|
2013-09-27 22:07:20 +02:00
|
|
|
LockSynchronousCommand(PlayerCommand::CLOSE_AUDIO);
|
2013-01-20 17:48:23 +01:00
|
|
|
assert(next_song == nullptr);
|
2008-10-14 22:38:14 +02:00
|
|
|
|
|
|
|
idle_add(IDLE_PLAYER);
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-23 10:55:52 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::UpdateAudio()
|
2009-10-23 10:55:52 +02:00
|
|
|
{
|
2013-09-27 22:07:20 +02:00
|
|
|
LockSynchronousCommand(PlayerCommand::UPDATE_AUDIO);
|
2009-10-23 10:55:52 +02:00
|
|
|
}
|
|
|
|
|
2009-10-08 21:12:57 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::Kill()
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-10-17 18:42:14 +02:00
|
|
|
assert(thread.IsDefined());
|
2009-01-25 13:44:33 +01:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
LockSynchronousCommand(PlayerCommand::EXIT);
|
2013-10-17 18:42:14 +02:00
|
|
|
thread.Join();
|
2008-10-14 22:38:14 +02:00
|
|
|
|
|
|
|
idle_add(IDLE_PLAYER);
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-08 21:12:57 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::PauseLocked()
|
2010-06-19 13:17:53 +02:00
|
|
|
{
|
2013-09-27 22:07:20 +02:00
|
|
|
if (state != PlayerState::STOP) {
|
|
|
|
SynchronousCommand(PlayerCommand::PAUSE);
|
2010-06-19 13:17:53 +02:00
|
|
|
idle_add(IDLE_PLAYER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 09:20:53 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::Pause()
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-09-27 09:20:53 +02:00
|
|
|
Lock();
|
|
|
|
PauseLocked();
|
|
|
|
Unlock();
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-08 21:12:57 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::SetPause(bool pause_flag)
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
2010-06-19 13:17:53 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
switch (state) {
|
2013-09-27 22:07:20 +02:00
|
|
|
case PlayerState::STOP:
|
2008-08-26 08:44:38 +02:00
|
|
|
break;
|
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
case PlayerState::PLAY:
|
2008-08-26 08:44:38 +02:00
|
|
|
if (pause_flag)
|
2013-09-27 09:20:53 +02:00
|
|
|
PauseLocked();
|
2008-08-26 08:44:38 +02:00
|
|
|
break;
|
2009-10-08 21:12:57 +02:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
case PlayerState::PAUSE:
|
2008-08-26 08:44:38 +02:00
|
|
|
if (!pause_flag)
|
2013-09-27 09:20:53 +02:00
|
|
|
PauseLocked();
|
2008-08-26 08:44:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-06-19 13:17:53 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Unlock();
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2012-08-25 08:44:31 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::SetBorderPause(bool _border_pause)
|
2012-08-25 08:44:31 +02:00
|
|
|
{
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
|
|
|
border_pause = _border_pause;
|
|
|
|
Unlock();
|
2012-08-25 08:44:31 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
player_status
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::GetStatus()
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-01-20 17:48:23 +01:00
|
|
|
player_status status;
|
2009-10-08 22:09:25 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
2013-09-27 22:07:20 +02:00
|
|
|
SynchronousCommand(PlayerCommand::REFRESH);
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
status.state = state;
|
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
if (state != PlayerState::STOP) {
|
2013-01-20 17:48:23 +01:00
|
|
|
status.bit_rate = bit_rate;
|
|
|
|
status.audio_format = audio_format;
|
|
|
|
status.total_time = total_time;
|
|
|
|
status.elapsed_time = elapsed_time;
|
2009-10-08 20:48:07 +02:00
|
|
|
}
|
2009-11-12 18:40:36 +01:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Unlock();
|
|
|
|
|
|
|
|
return status;
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-08 21:12:57 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::SetError(PlayerError type, Error &&_error)
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-09-27 22:07:20 +02:00
|
|
|
assert(type != PlayerError::NONE);
|
2013-08-10 18:02:44 +02:00
|
|
|
assert(_error.IsDefined());
|
2012-08-08 22:18:08 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
error_type = type;
|
2013-08-10 18:02:44 +02:00
|
|
|
error = std::move(_error);
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2012-08-08 22:18:08 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::ClearError()
|
2008-12-17 16:46:12 +01:00
|
|
|
{
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
2012-08-08 22:18:08 +02:00
|
|
|
|
2013-09-27 22:07:20 +02:00
|
|
|
if (error_type != PlayerError::NONE) {
|
|
|
|
error_type = PlayerError::NONE;
|
2013-08-10 18:02:44 +02:00
|
|
|
error.Clear();
|
2012-08-08 22:18:08 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Unlock();
|
2008-12-17 16:46:12 +01:00
|
|
|
}
|
|
|
|
|
2013-10-21 23:22:16 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::LockSetTaggedSong(const Song &song)
|
2013-10-21 23:22:16 +02:00
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
if (tagged_song != nullptr)
|
|
|
|
tagged_song->Free();
|
|
|
|
tagged_song = song.DupDetached();
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::ClearTaggedSong()
|
2013-10-21 23:22:16 +02:00
|
|
|
{
|
|
|
|
if (tagged_song != nullptr) {
|
|
|
|
tagged_song->Free();
|
|
|
|
tagged_song = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-19 13:17:53 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::EnqueueSong(Song *song)
|
2010-06-19 13:17:53 +02:00
|
|
|
{
|
2013-10-19 18:19:03 +02:00
|
|
|
assert(song != nullptr);
|
2010-06-19 13:17:53 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
2013-09-27 09:20:53 +02:00
|
|
|
EnqueueSongLocked(song);
|
2013-01-20 17:48:23 +01:00
|
|
|
Unlock();
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 18:35:22 +02:00
|
|
|
bool
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::Seek(Song *song, float seek_time)
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-10-19 18:19:03 +02:00
|
|
|
assert(song != nullptr);
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
Lock();
|
2012-08-09 22:19:39 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
if (next_song != nullptr)
|
2013-07-28 13:25:12 +02:00
|
|
|
next_song->Free();
|
2012-08-09 22:19:39 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
next_song = song;
|
|
|
|
seek_where = seek_time;
|
2013-09-27 22:07:20 +02:00
|
|
|
SynchronousCommand(PlayerCommand::SEEK);
|
2013-01-20 17:48:23 +01:00
|
|
|
Unlock();
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2013-01-20 17:48:23 +01:00
|
|
|
assert(next_song == nullptr);
|
2009-05-06 18:46:59 +02:00
|
|
|
|
2009-05-06 18:46:52 +02:00
|
|
|
idle_add(IDLE_PLAYER);
|
2008-08-26 08:44:38 +02:00
|
|
|
|
2009-05-06 18:35:22 +02:00
|
|
|
return true;
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2009-10-08 21:12:57 +02:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::SetCrossFade(float _cross_fade_seconds)
|
2008-08-26 08:44:38 +02:00
|
|
|
{
|
2013-01-20 17:48:23 +01:00
|
|
|
if (_cross_fade_seconds < 0)
|
|
|
|
_cross_fade_seconds = 0;
|
2013-10-29 00:14:27 +01:00
|
|
|
cross_fade.duration = _cross_fade_seconds;
|
2008-10-14 22:38:14 +02:00
|
|
|
|
|
|
|
idle_add(IDLE_OPTIONS);
|
2008-08-26 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
2010-03-21 18:21:47 +01:00
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::SetMixRampDb(float _mixramp_db)
|
2010-03-21 18:21:47 +01:00
|
|
|
{
|
2013-10-29 00:14:27 +01:00
|
|
|
cross_fade.mixramp_db = _mixramp_db;
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
idle_add(IDLE_OPTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 10:12:21 +01:00
|
|
|
PlayerControl::SetMixRampDelay(float _mixramp_delay_seconds)
|
2010-03-21 18:21:47 +01:00
|
|
|
{
|
2013-10-29 00:14:27 +01:00
|
|
|
cross_fade.mixramp_delay = _mixramp_delay_seconds;
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
idle_add(IDLE_OPTIONS);
|
|
|
|
}
|