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 #define DECODE_TYPE_FILE 0 00030 #define DECODE_TYPE_URL 1 00031 00032 enum decoder_state { 00033 DECODE_STATE_STOP = 0, 00034 DECODE_STATE_START, 00035 DECODE_STATE_DECODE, 00036 00043 DECODE_STATE_ERROR, 00044 }; 00045 00046 struct decoder_control { 00049 GThread *thread; 00050 00051 struct notify notify; 00052 00053 volatile enum decoder_state state; 00054 volatile enum decoder_command command; 00055 bool quit; 00056 bool seek_error; 00057 bool seekable; 00058 volatile double seek_where; 00059 00061 struct audio_format in_audio_format; 00062 00064 struct audio_format out_audio_format; 00065 00066 struct song *current_song; 00067 struct song *next_song; 00068 float total_time; 00069 00071 struct music_buffer *buffer; 00072 00074 struct music_pipe *pipe; 00075 }; 00076 00077 extern struct decoder_control dc; 00078 00079 void dc_init(void); 00080 00081 void dc_deinit(void); 00082 00083 static inline bool decoder_is_idle(void) 00084 { 00085 return (dc.state == DECODE_STATE_STOP || 00086 dc.state == DECODE_STATE_ERROR) && 00087 dc.command != DECODE_COMMAND_START; 00088 } 00089 00090 static inline bool decoder_is_starting(void) 00091 { 00092 return dc.command == DECODE_COMMAND_START || 00093 dc.state == DECODE_STATE_START; 00094 } 00095 00096 static inline bool decoder_has_failed(void) 00097 { 00098 assert(dc.command == DECODE_COMMAND_NONE); 00099 00100 return dc.state == DECODE_STATE_ERROR; 00101 } 00102 00103 static inline struct song * 00104 decoder_current_song(void) 00105 { 00106 switch (dc.state) { 00107 case DECODE_STATE_STOP: 00108 case DECODE_STATE_ERROR: 00109 return NULL; 00110 00111 case DECODE_STATE_START: 00112 case DECODE_STATE_DECODE: 00113 return dc.current_song; 00114 } 00115 00116 assert(false); 00117 return NULL; 00118 } 00119 00120 void 00121 dc_command_wait(struct notify *notify); 00122 00123 void 00124 dc_start(struct notify *notify, struct song *song); 00125 00126 void 00127 dc_start_async(struct song *song); 00128 00129 void 00130 dc_stop(struct notify *notify); 00131 00132 bool 00133 dc_seek(struct notify *notify, double where); 00134 00135 void 00136 dc_quit(void); 00137 00138 #endif