added decoder_control.c
The source "decoder_control.c" provides an API for controlling the decoder. This replaces various direct accesses to the DecoderControl struct.
This commit is contained in:
parent
7d3429a6d8
commit
8a4970f863
@ -107,6 +107,7 @@ mpd_SOURCES = \
|
|||||||
crossfade.c \
|
crossfade.c \
|
||||||
dbUtils.c \
|
dbUtils.c \
|
||||||
decode.c \
|
decode.c \
|
||||||
|
decoder_control.c \
|
||||||
decoder_api.c \
|
decoder_api.c \
|
||||||
directory.c \
|
directory.c \
|
||||||
decoder_list.c \
|
decoder_list.c \
|
||||||
|
10
src/decode.h
10
src/decode.h
@ -61,4 +61,14 @@ typedef struct _DecoderControl {
|
|||||||
|
|
||||||
void decoderInit(void);
|
void decoderInit(void);
|
||||||
|
|
||||||
|
void dc_command_wait(Notify *notify);
|
||||||
|
|
||||||
|
void dc_start(Notify *notify, Song *song);
|
||||||
|
|
||||||
|
void dc_start_async(Song *song);
|
||||||
|
|
||||||
|
void dc_stop(Notify *notify);
|
||||||
|
|
||||||
|
int dc_seek(Notify *notify, double where);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
82
src/decoder_control.c
Normal file
82
src/decoder_control.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/* the Music Player Daemon (MPD)
|
||||||
|
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
|
||||||
|
* This project's homepage is: http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "decode.h"
|
||||||
|
#include "playerData.h"
|
||||||
|
|
||||||
|
void dc_command_wait(Notify *notify)
|
||||||
|
{
|
||||||
|
while (dc.command != DECODE_COMMAND_NONE) {
|
||||||
|
notify_signal(&dc.notify);
|
||||||
|
notify_wait(notify);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dc_command(Notify *notify, enum decoder_command cmd)
|
||||||
|
{
|
||||||
|
dc.command = cmd;
|
||||||
|
dc_command_wait(notify);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dc_command_async(enum decoder_command cmd)
|
||||||
|
{
|
||||||
|
dc.command = cmd;
|
||||||
|
notify_signal(&dc.notify);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dc_start(Notify *notify, Song *song)
|
||||||
|
{
|
||||||
|
assert(song != NULL);
|
||||||
|
|
||||||
|
dc.next_song = song;
|
||||||
|
dc.error = DECODE_ERROR_NOERROR;
|
||||||
|
dc_command(notify, DECODE_COMMAND_START);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dc_start_async(Song *song)
|
||||||
|
{
|
||||||
|
assert(song != NULL);
|
||||||
|
|
||||||
|
dc.next_song = song;
|
||||||
|
dc.error = DECODE_ERROR_NOERROR;
|
||||||
|
dc_command_async(DECODE_COMMAND_START);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dc_stop(Notify *notify)
|
||||||
|
{
|
||||||
|
if (dc.command == DECODE_COMMAND_START ||
|
||||||
|
dc.state != DECODE_STATE_STOP)
|
||||||
|
dc_command(notify, DECODE_COMMAND_STOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
int dc_seek(Notify *notify, double where)
|
||||||
|
{
|
||||||
|
assert(where >= 0.0);
|
||||||
|
|
||||||
|
if (dc.state == DECODE_STATE_STOP || !dc.seekable)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
dc.seekWhere = where;
|
||||||
|
dc.seekError = 0;
|
||||||
|
dc_command(notify, DECODE_COMMAND_SEEK);
|
||||||
|
|
||||||
|
if (dc.seekError)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -31,30 +31,9 @@ enum xfade_state {
|
|||||||
XFADE_ENABLED = 1
|
XFADE_ENABLED = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
static void dc_command_wait(void)
|
|
||||||
{
|
|
||||||
while (dc.command != DECODE_COMMAND_NONE) {
|
|
||||||
notify_signal(&dc.notify);
|
|
||||||
notify_wait(&pc.notify);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dc_command(enum decoder_command cmd)
|
|
||||||
{
|
|
||||||
dc.command = cmd;
|
|
||||||
dc_command_wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void stopDecode(void)
|
|
||||||
{
|
|
||||||
if (dc.command == DECODE_COMMAND_START ||
|
|
||||||
dc.state != DECODE_STATE_STOP)
|
|
||||||
dc_command(DECODE_COMMAND_STOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void quitDecode(void)
|
static void quitDecode(void)
|
||||||
{
|
{
|
||||||
stopDecode();
|
dc_stop(&pc.notify);
|
||||||
pc.state = PLAYER_STATE_STOP;
|
pc.state = PLAYER_STATE_STOP;
|
||||||
dc.command = DECODE_COMMAND_NONE;
|
dc.command = DECODE_COMMAND_NONE;
|
||||||
pc.command = PLAYER_COMMAND_NONE;
|
pc.command = PLAYER_COMMAND_NONE;
|
||||||
@ -63,10 +42,7 @@ static void quitDecode(void)
|
|||||||
|
|
||||||
static int waitOnDecode(int *decodeWaitedOn)
|
static int waitOnDecode(int *decodeWaitedOn)
|
||||||
{
|
{
|
||||||
while (dc.command == DECODE_COMMAND_START) {
|
dc_command_wait(&pc.notify);
|
||||||
notify_signal(&dc.notify);
|
|
||||||
notify_wait(&pc.notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dc.error != DECODE_ERROR_NOERROR) {
|
if (dc.error != DECODE_ERROR_NOERROR) {
|
||||||
assert(dc.next_song == NULL || dc.next_song->url != NULL);
|
assert(dc.next_song == NULL || dc.next_song->url != NULL);
|
||||||
@ -88,30 +64,27 @@ static int waitOnDecode(int *decodeWaitedOn)
|
|||||||
static int decodeSeek(int *decodeWaitedOn, int *next)
|
static int decodeSeek(int *decodeWaitedOn, int *next)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
double where;
|
||||||
|
|
||||||
if (dc.state == DECODE_STATE_STOP ||
|
if (dc.state == DECODE_STATE_STOP ||
|
||||||
dc.error != DECODE_ERROR_NOERROR ||
|
dc.error != DECODE_ERROR_NOERROR ||
|
||||||
dc.current_song != pc.next_song) {
|
dc.current_song != pc.next_song) {
|
||||||
stopDecode();
|
dc_stop(&pc.notify);
|
||||||
*next = -1;
|
*next = -1;
|
||||||
ob_clear();
|
ob_clear();
|
||||||
dc.next_song = pc.next_song;
|
dc_start_async(pc.next_song);
|
||||||
dc.error = DECODE_ERROR_NOERROR;
|
|
||||||
dc.command = DECODE_COMMAND_START;
|
|
||||||
waitOnDecode(decodeWaitedOn);
|
waitOnDecode(decodeWaitedOn);
|
||||||
}
|
}
|
||||||
if (dc.state != DECODE_STATE_STOP && dc.seekable) {
|
|
||||||
*next = -1;
|
where = pc.seekWhere;
|
||||||
dc.seekWhere = pc.seekWhere > pc.totalTime - 0.1 ?
|
if (where > pc.totalTime)
|
||||||
pc.totalTime - 0.1 : pc.seekWhere;
|
where = pc.totalTime - 0.1;
|
||||||
dc.seekWhere = 0 > dc.seekWhere ? 0 : dc.seekWhere;
|
if (where < 0.0)
|
||||||
dc.seekError = 0;
|
where = 0.0;
|
||||||
dc_command(DECODE_COMMAND_SEEK);
|
|
||||||
if (!dc.seekError) {
|
ret = dc_seek(&pc.notify, where);
|
||||||
pc.elapsedTime = dc.seekWhere;
|
if (ret == 0)
|
||||||
ret = 0;
|
pc.elapsedTime = where;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player_command_finished();
|
player_command_finished();
|
||||||
|
|
||||||
@ -291,12 +264,9 @@ static void decodeParent(void)
|
|||||||
/* the decoder has finished the current song;
|
/* the decoder has finished the current song;
|
||||||
make it decode the next song */
|
make it decode the next song */
|
||||||
next = ob.end;
|
next = ob.end;
|
||||||
dc.next_song = pc.next_song;
|
dc_start_async(pc.next_song);
|
||||||
dc.error = DECODE_ERROR_NOERROR;
|
|
||||||
dc.command = DECODE_COMMAND_START;
|
|
||||||
pc.queueState = PLAYER_QUEUE_DECODE;
|
pc.queueState = PLAYER_QUEUE_DECODE;
|
||||||
wakeup_main_task();
|
wakeup_main_task();
|
||||||
notify_signal(&dc.notify);
|
|
||||||
}
|
}
|
||||||
if (next >= 0 && do_xfade == XFADE_UNKNOWN &&
|
if (next >= 0 && do_xfade == XFADE_UNKNOWN &&
|
||||||
dc.command != DECODE_COMMAND_START &&
|
dc.command != DECODE_COMMAND_START &&
|
||||||
@ -416,10 +386,7 @@ static void decode(void)
|
|||||||
{
|
{
|
||||||
ob_clear();
|
ob_clear();
|
||||||
|
|
||||||
dc.next_song = pc.next_song;
|
dc_start(&pc.notify, pc.next_song);
|
||||||
dc.error = DECODE_ERROR_NOERROR;
|
|
||||||
dc_command(DECODE_COMMAND_START);
|
|
||||||
|
|
||||||
decodeParent();
|
decodeParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user