player_control.h 3.33 KB
Newer Older
1 2 3
/*
 * Copyright (C) 2003-2009 The Music Player Daemon Project
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

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

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

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

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

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

	/** 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,
52 53
};

54 55 56 57 58 59 60 61
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
62

63
struct player_control {
64 65
	unsigned buffer_chunks;

66 67
	unsigned int buffered_before_play;

68 69 70 71
	/** the handle of the player thread, or NULL if the player
	    thread isn't running */
	GThread *thread;

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

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

90
void pc_init(unsigned buffer_chunks, unsigned buffered_before_play);
91

92 93
void pc_deinit(void);

94 95 96 97 98 99 100 101
/**
 * 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);

102 103
void
playerPlay(struct song *song);
Warren Dukes's avatar
Warren Dukes committed
104

105 106 107 108 109
/**
 * see PLAYER_COMMAND_CANCEL
 */
void pc_cancel(void);

110
void playerSetPause(int pause_flag);
111

112
void playerPause(void);
Warren Dukes's avatar
Warren Dukes committed
113

114
void playerKill(void);
Warren Dukes's avatar
Warren Dukes committed
115

116
int getPlayerTotalTime(void);
Warren Dukes's avatar
Warren Dukes committed
117

118
int getPlayerElapsedTime(void);
Warren Dukes's avatar
Warren Dukes committed
119

120
unsigned long getPlayerBitRate(void);
Warren Dukes's avatar
Warren Dukes committed
121

122
enum player_state getPlayerState(void);
Warren Dukes's avatar
Warren Dukes committed
123

124
void clearPlayerError(void);
Warren Dukes's avatar
Warren Dukes committed
125

126
char *getPlayerErrorStr(void);
Warren Dukes's avatar
Warren Dukes committed
127

128
enum player_error getPlayerError(void);
Warren Dukes's avatar
Warren Dukes committed
129

130
void playerWait(void);
131

132 133
void
queueSong(struct song *song);
Warren Dukes's avatar
Warren Dukes committed
134

135 136
int
playerSeek(struct song *song, float seek_time);
Warren Dukes's avatar
Warren Dukes committed
137 138 139

void setPlayerCrossFade(float crossFadeInSeconds);

140
float getPlayerCrossFade(void);
Warren Dukes's avatar
Warren Dukes committed
141 142 143

void setPlayerSoftwareVolume(int volume);

144
double getPlayerTotalPlayTime(void);
Warren Dukes's avatar
Warren Dukes committed
145

146 147 148 149 150
static inline const struct audio_format *
player_get_audio_format(void)
{
	return &pc.audio_format;
}
151

152
void playerInit(void);
153

Warren Dukes's avatar
Warren Dukes committed
154
#endif