decoder_control.h 3.02 KB
Newer Older
Warren Dukes's avatar
Warren Dukes committed
1
/* the Music Player Daemon (MPD)
2
 * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3
 * Copyright (C) 2008 Max Kellermann <max@duempel.org>
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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
 */

20 21
#ifndef MPD_DECODER_CONTROL_H
#define MPD_DECODER_CONTROL_H
Warren Dukes's avatar
Warren Dukes committed
22

23
#include "decoder_api.h"
24

25
#include "audio_format.h"
26
#include "notify.h"
Warren Dukes's avatar
Warren Dukes committed
27

28 29
#include <assert.h>

30 31
#define DECODE_TYPE_FILE	0
#define DECODE_TYPE_URL		1
Warren Dukes's avatar
Warren Dukes committed
32

33 34 35
enum decoder_state {
	DECODE_STATE_STOP = 0,
	DECODE_STATE_START,
36 37 38 39 40 41 42 43 44
	DECODE_STATE_DECODE,

	/**
	 * The last "START" command failed, because there was an I/O
	 * error or because no decoder was able to decode the file.
	 * This state will only come after START; once the state has
	 * turned to DECODE, by definition no such error can occur.
	 */
	DECODE_STATE_ERROR,
45
};
46

47
struct decoder_control {
48 49 50 51
	/** the handle of the decoder thread, or NULL if the decoder
	    thread isn't running */
	GThread *thread;

52
	struct notify notify;
53

54
	volatile enum decoder_state state;
55
	volatile enum decoder_command command;
56
	bool quit;
Max Kellermann's avatar
Max Kellermann committed
57
	bool seek_error;
58
	bool seekable;
Max Kellermann's avatar
Max Kellermann committed
59
	volatile double seek_where;
60 61 62 63 64 65 66

	/** the format of the song file */
	struct audio_format in_audio_format;

	/** the format being sent to the music pipe */
	struct audio_format out_audio_format;

67
	struct song *current_song;
68 69
	struct song *next_song;
	float total_time;
70 71 72
};

extern struct decoder_control dc;
Warren Dukes's avatar
Warren Dukes committed
73

74 75
void dc_init(void);

76 77
void dc_deinit(void);

78
static inline bool decoder_is_idle(void)
79
{
80 81
	return (dc.state == DECODE_STATE_STOP ||
		dc.state == DECODE_STATE_ERROR) &&
82
		dc.command != DECODE_COMMAND_START;
83 84
}

85
static inline bool decoder_is_starting(void)
86
{
87 88
	return dc.command == DECODE_COMMAND_START ||
		dc.state == DECODE_STATE_START;
89 90
}

91 92 93 94 95 96 97
static inline bool decoder_has_failed(void)
{
	assert(dc.command == DECODE_COMMAND_NONE);

	return dc.state == DECODE_STATE_ERROR;
}

98 99
static inline struct song *
decoder_current_song(void)
100
{
101 102 103
	switch (dc.state) {
	case DECODE_STATE_STOP:
	case DECODE_STATE_ERROR:
104 105
		return NULL;

106 107 108 109 110 111 112
	case DECODE_STATE_START:
	case DECODE_STATE_DECODE:
		return dc.current_song;
	}

	assert(false);
	return NULL;
113 114
}

115 116
void
dc_command_wait(struct notify *notify);
Max Kellermann's avatar
Max Kellermann committed
117

118
void
119
dc_start(struct notify *notify, struct song *song);
Max Kellermann's avatar
Max Kellermann committed
120

121 122
void
dc_start_async(struct song *song);
Max Kellermann's avatar
Max Kellermann committed
123

124 125
void
dc_stop(struct notify *notify);
Max Kellermann's avatar
Max Kellermann committed
126

127
bool
128
dc_seek(struct notify *notify, double where);
Max Kellermann's avatar
Max Kellermann committed
129

130
void
131
dc_quit(void);
132

Warren Dukes's avatar
Warren Dukes committed
133
#endif