00001 /* 00002 * Copyright (C) 2003-2009 The Music Player Daemon Project 00003 * http://www.musicpd.org 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #ifndef MPD_DECODER_CONTROL_H 00021 #define MPD_DECODER_CONTROL_H 00022 00023 #include "decoder_command.h" 00024 #include "audio_format.h" 00025 #include "notify.h" 00026 00027 #include <assert.h> 00028 00029 enum decoder_state { 00030 DECODE_STATE_STOP = 0, 00031 DECODE_STATE_START, 00032 DECODE_STATE_DECODE, 00033 00040 DECODE_STATE_ERROR, 00041 }; 00042 00043 struct decoder_control { 00046 GThread *thread; 00047 00048 struct notify notify; 00049 00050 volatile enum decoder_state state; 00051 volatile enum decoder_command command; 00052 bool quit; 00053 bool seek_error; 00054 bool seekable; 00055 volatile double seek_where; 00056 00058 struct audio_format in_audio_format; 00059 00061 struct audio_format out_audio_format; 00062 00063 struct song *current_song; 00064 struct song *next_song; 00065 float total_time; 00066 00068 struct music_buffer *buffer; 00069 00071 struct music_pipe *pipe; 00072 }; 00073 00074 extern struct decoder_control dc; 00075 00076 void dc_init(void); 00077 00078 void dc_deinit(void); 00079 00080 static inline bool decoder_is_idle(void) 00081 { 00082 return (dc.state == DECODE_STATE_STOP || 00083 dc.state == DECODE_STATE_ERROR) && 00084 dc.command != DECODE_COMMAND_START; 00085 } 00086 00087 static inline bool decoder_is_starting(void) 00088 { 00089 return dc.command == DECODE_COMMAND_START || 00090 dc.state == DECODE_STATE_START; 00091 } 00092 00093 static inline bool decoder_has_failed(void) 00094 { 00095 assert(dc.command == DECODE_COMMAND_NONE); 00096 00097 return dc.state == DECODE_STATE_ERROR; 00098 } 00099 00100 static inline struct song * 00101 decoder_current_song(void) 00102 { 00103 switch (dc.state) { 00104 case DECODE_STATE_STOP: 00105 case DECODE_STATE_ERROR: 00106 return NULL; 00107 00108 case DECODE_STATE_START: 00109 case DECODE_STATE_DECODE: 00110 return dc.current_song; 00111 } 00112 00113 assert(false); 00114 return NULL; 00115 } 00116 00117 void 00118 dc_command_wait(struct notify *notify); 00119 00120 void 00121 dc_start(struct notify *notify, struct song *song); 00122 00123 void 00124 dc_start_async(struct song *song); 00125 00126 void 00127 dc_stop(struct notify *notify); 00128 00129 bool 00130 dc_seek(struct notify *notify, double where); 00131 00132 void 00133 dc_quit(void); 00134 00135 #endif