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:27:18 +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:27:18 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-04 08:41:16 +01:00
|
|
|
#include "DecoderControl.hxx"
|
2013-01-04 10:16:16 +01:00
|
|
|
#include "MusicPipe.hxx"
|
2013-07-28 13:25:12 +02:00
|
|
|
#include "Song.hxx"
|
2008-08-26 08:40:47 +02:00
|
|
|
|
2013-09-27 22:56:30 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2008-10-08 10:49:29 +02:00
|
|
|
#include <assert.h>
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "decoder_control"
|
2008-10-08 10:49:29 +02:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::decoder_control()
|
|
|
|
:thread(nullptr),
|
2013-09-27 12:27:33 +02:00
|
|
|
state(DecoderState::STOP),
|
2013-09-27 12:11:37 +02:00
|
|
|
command(DecoderCommand::NONE),
|
2013-01-21 10:13:29 +01:00
|
|
|
song(nullptr),
|
|
|
|
replay_gain_db(0), replay_gain_prev_db(0),
|
|
|
|
mixramp_start(nullptr), mixramp_end(nullptr),
|
|
|
|
mixramp_prev_end(nullptr) {}
|
|
|
|
|
|
|
|
decoder_control::~decoder_control()
|
2008-08-26 08:45:14 +02:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
ClearError();
|
2011-01-10 20:46:04 +01:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
if (song != NULL)
|
2013-07-28 13:25:12 +02:00
|
|
|
song->Free();
|
2009-10-31 19:22:56 +01:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
g_free(mixramp_start);
|
|
|
|
g_free(mixramp_end);
|
|
|
|
g_free(mixramp_prev_end);
|
2008-09-24 07:14:11 +02:00
|
|
|
}
|
|
|
|
|
2012-08-15 17:49:23 +02:00
|
|
|
bool
|
2013-07-28 13:25:12 +02:00
|
|
|
decoder_control::IsCurrentSong(const Song *_song) const
|
2012-08-15 17:49:23 +02:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
assert(_song != NULL);
|
2012-08-15 17:49:23 +02:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
switch (state) {
|
2013-09-27 12:27:33 +02:00
|
|
|
case DecoderState::STOP:
|
|
|
|
case DecoderState::ERROR:
|
2012-08-15 17:49:23 +02:00
|
|
|
return false;
|
|
|
|
|
2013-09-27 12:27:33 +02:00
|
|
|
case DecoderState::START:
|
|
|
|
case DecoderState::DECODE:
|
2013-01-21 10:13:29 +01:00
|
|
|
return song_equals(song, _song);
|
2012-08-15 17:49:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(false);
|
2013-08-03 21:34:17 +02:00
|
|
|
gcc_unreachable();
|
2012-08-15 17:49:23 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
void
|
2013-07-28 13:25:12 +02:00
|
|
|
decoder_control::Start(Song *_song,
|
2013-01-21 10:13:29 +01:00
|
|
|
unsigned _start_ms, unsigned _end_ms,
|
2013-09-26 22:09:42 +02:00
|
|
|
MusicBuffer &_buffer, MusicPipe &_pipe)
|
2008-08-26 08:27:18 +02:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
assert(_song != NULL);
|
2013-09-26 21:51:45 +02:00
|
|
|
assert(_pipe.IsEmpty());
|
2008-08-26 08:27:18 +02:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
if (song != nullptr)
|
2013-07-28 13:25:12 +02:00
|
|
|
song->Free();
|
2013-01-21 10:13:29 +01:00
|
|
|
|
|
|
|
song = _song;
|
|
|
|
start_ms = _start_ms;
|
|
|
|
end_ms = _end_ms;
|
2013-09-26 22:09:42 +02:00
|
|
|
buffer = &_buffer;
|
2013-09-26 21:51:45 +02:00
|
|
|
pipe = &_pipe;
|
2012-08-09 20:55:18 +02:00
|
|
|
|
2013-09-27 12:11:37 +02:00
|
|
|
LockSynchronousCommand(DecoderCommand::START);
|
2008-08-26 08:27:18 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:16 +02:00
|
|
|
void
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::Stop()
|
2008-08-26 08:27:18 +02:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
Lock();
|
2009-08-13 23:33:46 +02:00
|
|
|
|
2013-09-27 12:11:37 +02:00
|
|
|
if (command != DecoderCommand::NONE)
|
2009-04-25 15:19:01 +02:00
|
|
|
/* Attempt to cancel the current command. If it's too
|
|
|
|
late and the decoder thread is already executing
|
|
|
|
the old command, we'll call STOP again in this
|
|
|
|
function (see below). */
|
2013-09-27 12:11:37 +02:00
|
|
|
SynchronousCommandLocked(DecoderCommand::STOP);
|
2009-04-25 15:19:01 +02:00
|
|
|
|
2013-09-27 12:27:33 +02:00
|
|
|
if (state != DecoderState::STOP && state != DecoderState::ERROR)
|
2013-09-27 12:11:37 +02:00
|
|
|
SynchronousCommandLocked(DecoderCommand::STOP);
|
2009-08-13 23:33:46 +02:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
Unlock();
|
2008-08-26 08:27:18 +02:00
|
|
|
}
|
|
|
|
|
2008-10-30 08:38:54 +01:00
|
|
|
bool
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::Seek(double where)
|
2008-08-26 08:27:18 +02:00
|
|
|
{
|
2013-09-27 12:27:33 +02:00
|
|
|
assert(state != DecoderState::START);
|
2008-08-26 08:27:18 +02:00
|
|
|
assert(where >= 0.0);
|
|
|
|
|
2013-09-27 12:27:33 +02:00
|
|
|
if (state == DecoderState::STOP ||
|
|
|
|
state == DecoderState::ERROR || !seekable)
|
2008-10-30 08:38:54 +01:00
|
|
|
return false;
|
2008-08-26 08:27:18 +02:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
seek_where = where;
|
|
|
|
seek_error = false;
|
2013-09-27 12:11:37 +02:00
|
|
|
SynchronousCommandLocked(DecoderCommand::SEEK);
|
2008-08-26 08:27:18 +02:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
return !seek_error;
|
2008-08-26 08:27:18 +02:00
|
|
|
}
|
2008-12-28 19:48:53 +01:00
|
|
|
|
|
|
|
void
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::Quit()
|
2008-12-28 19:48:53 +01:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
assert(thread != nullptr);
|
2009-01-25 13:44:27 +01:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
quit = true;
|
2013-09-27 12:11:37 +02:00
|
|
|
LockAsynchronousCommand(DecoderCommand::STOP);
|
2009-01-25 13:44:27 +01:00
|
|
|
|
2013-01-21 10:13:29 +01:00
|
|
|
g_thread_join(thread);
|
|
|
|
thread = nullptr;
|
2008-12-28 19:48:53 +01:00
|
|
|
}
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
void
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::MixRampStart(char *_mixramp_start)
|
2010-03-21 18:21:47 +01:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
g_free(mixramp_start);
|
|
|
|
mixramp_start = _mixramp_start;
|
2010-03-21 18:21:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::MixRampEnd(char *_mixramp_end)
|
2010-03-21 18:21:47 +01:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
g_free(mixramp_end);
|
|
|
|
mixramp_end = _mixramp_end;
|
2010-03-21 18:21:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-21 10:13:29 +01:00
|
|
|
decoder_control::MixRampPrevEnd(char *_mixramp_prev_end)
|
2010-03-21 18:21:47 +01:00
|
|
|
{
|
2013-01-21 10:13:29 +01:00
|
|
|
g_free(mixramp_prev_end);
|
|
|
|
mixramp_prev_end = _mixramp_prev_end;
|
2010-03-21 18:21:47 +01:00
|
|
|
}
|