decoder_control.h 2.92 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
	struct notify notify;
49

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

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

63
	struct song *current_song;
64 65
	struct song *next_song;
	float total_time;
66 67 68
};

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

70 71
void dc_init(void);

72 73
void dc_deinit(void);

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

81
static inline bool decoder_is_starting(void)
82
{
83 84
	return dc.command == DECODE_COMMAND_START ||
		dc.state == DECODE_STATE_START;
85 86
}

87 88 89 90 91 92 93
static inline bool decoder_has_failed(void)
{
	assert(dc.command == DECODE_COMMAND_NONE);

	return dc.state == DECODE_STATE_ERROR;
}

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

102 103 104 105 106 107 108
	case DECODE_STATE_START:
	case DECODE_STATE_DECODE:
		return dc.current_song;
	}

	assert(false);
	return NULL;
109 110
}

111 112
void
dc_command_wait(struct notify *notify);
Max Kellermann's avatar
Max Kellermann committed
113

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

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

120 121
void
dc_stop(struct notify *notify);
Max Kellermann's avatar
Max Kellermann committed
122

123
bool
124
dc_seek(struct notify *notify, double where);
Max Kellermann's avatar
Max Kellermann committed
125

126 127 128
void
dc_quit(struct notify *notify);

Warren Dukes's avatar
Warren Dukes committed
129
#endif