player_control.h 3.09 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 19 20 21
 * 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
 */

#ifndef PLAYER_H
#define PLAYER_H

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
};

Warren Dukes's avatar
Warren Dukes committed
53 54 55 56 57 58 59
#define PLAYER_ERROR_NOERROR		0
#define PLAYER_ERROR_FILE		1
#define PLAYER_ERROR_AUDIO		2
#define PLAYER_ERROR_SYSTEM		3
#define PLAYER_ERROR_UNKTYPE		4
#define PLAYER_ERROR_FILENOTFOUND	5

60
struct player_control {
61 62
	unsigned int buffered_before_play;

63
	struct notify notify;
64
	volatile enum player_command command;
65
	volatile enum player_state state;
66 67
	volatile int8_t error;
	volatile uint16_t bitRate;
68
	struct audio_format audio_format;
Warren Dukes's avatar
Warren Dukes committed
69 70
	volatile float totalTime;
	volatile float elapsedTime;
71 72
	struct song *volatile next_song;
	struct song *errored_song;
Warren Dukes's avatar
Warren Dukes committed
73 74
	volatile double seekWhere;
	volatile float crossFade;
75
	volatile uint16_t softwareVolume;
Warren Dukes's avatar
Warren Dukes committed
76
	volatile double totalPlayTime;
77 78 79
};

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

81 82
void pc_init(unsigned int buffered_before_play);

83 84
void pc_deinit(void);

85 86
void
playerPlay(struct song *song);
Warren Dukes's avatar
Warren Dukes committed
87

88 89 90 91 92
/**
 * see PLAYER_COMMAND_CANCEL
 */
void pc_cancel(void);

93
void playerSetPause(int pause_flag);
94

95
void playerPause(void);
Warren Dukes's avatar
Warren Dukes committed
96

97
void playerKill(void);
Warren Dukes's avatar
Warren Dukes committed
98

99
int getPlayerTotalTime(void);
Warren Dukes's avatar
Warren Dukes committed
100

101
int getPlayerElapsedTime(void);
Warren Dukes's avatar
Warren Dukes committed
102

103
unsigned long getPlayerBitRate(void);
Warren Dukes's avatar
Warren Dukes committed
104

105
enum player_state getPlayerState(void);
Warren Dukes's avatar
Warren Dukes committed
106

107
void clearPlayerError(void);
Warren Dukes's avatar
Warren Dukes committed
108

109
char *getPlayerErrorStr(void);
Warren Dukes's avatar
Warren Dukes committed
110

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

113
void playerWait(void);
114

115 116
void
queueSong(struct song *song);
Warren Dukes's avatar
Warren Dukes committed
117

118 119
int
playerSeek(struct song *song, float seek_time);
Warren Dukes's avatar
Warren Dukes committed
120 121 122

void setPlayerCrossFade(float crossFadeInSeconds);

123
float getPlayerCrossFade(void);
Warren Dukes's avatar
Warren Dukes committed
124 125 126

void setPlayerSoftwareVolume(int volume);

127
double getPlayerTotalPlayTime(void);
Warren Dukes's avatar
Warren Dukes committed
128

129 130 131 132 133
static inline const struct audio_format *
player_get_audio_format(void)
{
	return &pc.audio_format;
}
134

135 136
struct song *
playerCurrentDecodeSong(void);
137

138
void playerInit(void);
139

Warren Dukes's avatar
Warren Dukes committed
140
#endif