player_control.h 3.39 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)
Warren Dukes's avatar
Warren Dukes committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * 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
 */

19 20
#ifndef MPD_PLAYER_H
#define MPD_PLAYER_H
Warren Dukes's avatar
Warren Dukes committed
21

Max Kellermann's avatar
Max Kellermann committed
22
#include "notify.h"
23
#include "audio_format.h"
24 25

#include <stdint.h>
Warren Dukes's avatar
Warren Dukes committed
26

27 28 29 30 31
enum player_state {
	PLAYER_STATE_STOP = 0,
	PLAYER_STATE_PAUSE,
	PLAYER_STATE_PLAY
};
Warren Dukes's avatar
Warren Dukes committed
32

33 34
enum player_command {
	PLAYER_COMMAND_NONE = 0,
Max Kellermann's avatar
Max Kellermann committed
35
	PLAYER_COMMAND_EXIT,
36 37 38 39 40
	PLAYER_COMMAND_STOP,
	PLAYER_COMMAND_PLAY,
	PLAYER_COMMAND_PAUSE,
	PLAYER_COMMAND_SEEK,
	PLAYER_COMMAND_CLOSE_AUDIO,
41 42 43 44 45 46 47 48 49 50

	/** player_control.next_song has been updated */
	PLAYER_COMMAND_QUEUE,

	/**
	 * cancel pre-decoding player_control.next_song; if the player
	 * has already started playing this song, it will completely
	 * stop
	 */
	PLAYER_COMMAND_CANCEL,
51 52
};

53 54 55 56 57 58 59 60
enum player_error {
	PLAYER_ERROR_NOERROR = 0,
	PLAYER_ERROR_FILE,
	PLAYER_ERROR_AUDIO,
	PLAYER_ERROR_SYSTEM,
	PLAYER_ERROR_UNKTYPE,
	PLAYER_ERROR_FILENOTFOUND,
};
Warren Dukes's avatar
Warren Dukes committed
61

62
struct player_control {
63 64
	unsigned int buffered_before_play;

65 66 67 68
	/** the handle of the player thread, or NULL if the player
	    thread isn't running */
	GThread *thread;

69
	struct notify notify;
70
	volatile enum player_command command;
71
	volatile enum player_state state;
72
	volatile enum player_error error;
73
	uint16_t bit_rate;
74
	struct audio_format audio_format;
75 76
	float total_time;
	float elapsed_time;
77 78
	struct song *volatile next_song;
	struct song *errored_song;
Max Kellermann's avatar
Max Kellermann committed
79
	volatile double seek_where;
80 81 82
	float cross_fade_seconds;
	uint16_t software_volume;
	double total_play_time;
83 84 85
};

extern struct player_control pc;
Warren Dukes's avatar
Warren Dukes committed
86

87
void pc_init(unsigned int _buffered_before_play);
88

89 90
void pc_deinit(void);

91 92 93 94 95 96 97 98
/**
 * Call this function when the specified song pointer is about to be
 * invalidated.  This makes sure that player_control.errored_song does
 * not point to an invalid pointer.
 */
void
pc_song_deleted(const struct song *song);

99 100
void
playerPlay(struct song *song);
Warren Dukes's avatar
Warren Dukes committed
101

102 103 104 105 106
/**
 * see PLAYER_COMMAND_CANCEL
 */
void pc_cancel(void);

107
void playerSetPause(int pause_flag);
108

109
void playerPause(void);
Warren Dukes's avatar
Warren Dukes committed
110

111
void playerKill(void);
Warren Dukes's avatar
Warren Dukes committed
112

113
int getPlayerTotalTime(void);
Warren Dukes's avatar
Warren Dukes committed
114

115
int getPlayerElapsedTime(void);
Warren Dukes's avatar
Warren Dukes committed
116

117
unsigned long getPlayerBitRate(void);
Warren Dukes's avatar
Warren Dukes committed
118

119
enum player_state getPlayerState(void);
Warren Dukes's avatar
Warren Dukes committed
120

121
void clearPlayerError(void);
Warren Dukes's avatar
Warren Dukes committed
122

123
char *getPlayerErrorStr(void);
Warren Dukes's avatar
Warren Dukes committed
124

125
enum player_error getPlayerError(void);
Warren Dukes's avatar
Warren Dukes committed
126

127
void playerWait(void);
128

129 130
void
queueSong(struct song *song);
Warren Dukes's avatar
Warren Dukes committed
131

132 133
int
playerSeek(struct song *song, float seek_time);
Warren Dukes's avatar
Warren Dukes committed
134 135 136

void setPlayerCrossFade(float crossFadeInSeconds);

137
float getPlayerCrossFade(void);
Warren Dukes's avatar
Warren Dukes committed
138 139 140

void setPlayerSoftwareVolume(int volume);

141
double getPlayerTotalPlayTime(void);
Warren Dukes's avatar
Warren Dukes committed
142

143 144 145 146 147
static inline const struct audio_format *
player_get_audio_format(void)
{
	return &pc.audio_format;
}
148

149 150
struct song *
playerCurrentDecodeSong(void);
151

152
void playerInit(void);
153

Warren Dukes's avatar
Warren Dukes committed
154
#endif