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_command.h"
24
#include "audio_format.h"
25
#include "notify.h"
Warren Dukes's avatar
Warren Dukes committed
26

27 28
#include <assert.h>

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

32 33 34
enum decoder_state {
	DECODE_STATE_STOP = 0,
	DECODE_STATE_START,
35 36 37 38 39 40 41 42 43
	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,
44
};
45

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

51
	struct notify notify;
52

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

	/** 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;

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

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

73 74
void dc_init(void);

75 76
void dc_deinit(void);

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

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

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

	return dc.state == DECODE_STATE_ERROR;
}

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

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

	assert(false);
	return NULL;
112 113
}

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

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

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

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

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

129
void
130
dc_quit(void);
131

Warren Dukes's avatar
Warren Dukes committed
132
#endif