Add RVA2 tag support to MPD
[mpd-mk/avuton.git] / src / decoder_control.h
blobe9fa449e6c0eff04920dfd8f53cd61e8f51dcdcc
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>
4 * This project's homepage is: http://www.musicpd.org
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef MPD_DECODER_CONTROL_H
21 #define MPD_DECODER_CONTROL_H
23 #include "decoder_api.h"
25 #include "audio_format.h"
26 #include "notify.h"
28 #include <assert.h>
30 #define DECODE_TYPE_FILE 0
31 #define DECODE_TYPE_URL 1
33 enum decoder_state {
34 DECODE_STATE_STOP = 0,
35 DECODE_STATE_START,
36 DECODE_STATE_DECODE,
38 /**
39 * The last "START" command failed, because there was an I/O
40 * error or because no decoder was able to decode the file.
41 * This state will only come after START; once the state has
42 * turned to DECODE, by definition no such error can occur.
44 DECODE_STATE_ERROR,
47 struct decoder_control {
48 struct notify notify;
50 volatile enum decoder_state state;
51 volatile enum decoder_command command;
52 bool seek_error;
53 bool seekable;
54 volatile double seek_where;
56 /** the format of the song file */
57 struct audio_format in_audio_format;
59 /** the format being sent to the music pipe */
60 struct audio_format out_audio_format;
62 struct song *current_song;
63 struct song *next_song;
64 float total_time;
67 extern struct decoder_control dc;
69 void dc_init(void);
71 void dc_deinit(void);
73 static inline bool decoder_is_idle(void)
75 return (dc.state == DECODE_STATE_STOP ||
76 dc.state == DECODE_STATE_ERROR) &&
77 dc.command != DECODE_COMMAND_START;
80 static inline bool decoder_is_starting(void)
82 return dc.command == DECODE_COMMAND_START ||
83 dc.state == DECODE_STATE_START;
86 static inline bool decoder_has_failed(void)
88 assert(dc.command == DECODE_COMMAND_NONE);
90 return dc.state == DECODE_STATE_ERROR;
93 static inline struct song *
94 decoder_current_song(void)
96 switch (dc.state) {
97 case DECODE_STATE_STOP:
98 case DECODE_STATE_ERROR:
99 return NULL;
101 case DECODE_STATE_START:
102 case DECODE_STATE_DECODE:
103 return dc.current_song;
106 assert(false);
107 return NULL;
110 void
111 dc_command_wait(struct notify *notify);
113 void
114 dc_start(struct notify *notify, struct song *song);
116 void
117 dc_start_async(struct song *song);
119 void
120 dc_stop(struct notify *notify);
122 bool
123 dc_seek(struct notify *notify, double where);
125 #endif