Mercurial > mplayer.hg
annotate libmpdemux/demux_xmms.c @ 8544:94564cc01c07
don't redefine decwin as static
author | arpi |
---|---|
date | Tue, 24 Dec 2002 00:06:33 +0000 |
parents | 222c0a39c977 |
children | 668161e96ab9 |
rev | line source |
---|---|
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
1 // This is not reentrant because of global static variables, but most of |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
2 // the plugins are not reentrant either perhaps |
8528 | 3 #include "config.h" |
4 | |
5 #include <stdlib.h> | |
6 #include <stdio.h> | |
7 #include <unistd.h> | |
8 #include <pthread.h> | |
9 #include <dlfcn.h> | |
10 #include <dirent.h> | |
11 #include <inttypes.h> | |
12 | |
13 #include "../cfgparser.h" | |
14 #include "../libao2/afmt.h" | |
15 #include "stream.h" | |
16 #include "demuxer.h" | |
17 #include "stheader.h" | |
18 | |
19 #include <dirent.h> | |
20 #include <string.h> | |
21 #include <sys/stat.h> | |
22 | |
23 #define XMMS_PACKETSIZE 65536 // some plugins won't play if this is too small | |
24 | |
25 #include "demux_xmms_plugin.h" | |
26 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
27 typedef struct { |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
28 uint64_t spos; // stream position in number of output bytes from 00:00:00 |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
29 InputPlugin* ip; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
30 } xmms_priv_t; |
8528 | 31 |
32 static pthread_mutex_t xmms_mutex; | |
33 static int format = 0x1; // Raw PCM | |
34 static char xmms_audiobuffer[XMMS_PACKETSIZE]; | |
35 static uint32_t xmms_channels; | |
36 static uint32_t xmms_samplerate; | |
37 static uint32_t xmms_afmt; | |
38 static int xmms_length; | |
39 static char *xmms_title=NULL; | |
40 static uint32_t xmms_audiopos=0; | |
8536
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
41 static int xmms_playing=0; |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
42 static xmms_priv_t *xmms_priv=NULL; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
43 static uint32_t xmms_byterate; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
44 static int64_t xmms_flushto=-1; |
8528 | 45 |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
46 // =========== mplayer xmms outputplugin stuff ============== |
8528 | 47 |
48 static void disk_close(void) {} | |
49 static void disk_pause(short p) {} | |
50 static void disk_init(void) {} | |
51 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
52 static void disk_flush(int time) { |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
53 if (xmms_priv) xmms_flushto=time*((long long) xmms_byterate)/1000LL; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
54 } |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
55 |
8528 | 56 static int disk_free(void) { // vqf plugin sends more than it should |
57 return (XMMS_PACKETSIZE-xmms_audiopos<XMMS_PACKETSIZE/4 ? 0:XMMS_PACKETSIZE-xmms_audiopos-XMMS_PACKETSIZE/4); | |
58 } | |
59 | |
60 static int disk_playing(void) { | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
61 return 0; //?? maybe plugins wait on exit until oplugin is not playing? |
8528 | 62 } |
63 | |
64 static int disk_get_output_time(void) { | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
65 if (xmms_byterate) |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
66 return xmms_priv->spos*1000LL/((long long)xmms_byterate); |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
67 else return 0; |
8528 | 68 } |
69 | |
70 static int disk_open(AFormat fmt, int rate, int nch) { | |
71 switch (fmt) { | |
72 case FMT_U8: | |
73 xmms_afmt=AFMT_U8; | |
74 break; | |
75 case FMT_S8: | |
76 xmms_afmt=AFMT_S8; | |
77 break; | |
78 case FMT_U16_LE: | |
79 xmms_afmt=AFMT_U16_LE; | |
80 break; | |
81 case FMT_U16_NE: | |
82 #if WORDS_BIGENDIAN | |
83 xmms_afmt=AFMT_U16_BE; | |
84 #else | |
85 xmms_afmt=AFMT_U16_LE; | |
86 #endif | |
87 break; | |
88 case FMT_U16_BE: | |
89 xmms_afmt=AFMT_U16_BE; | |
90 break; | |
91 case FMT_S16_NE: | |
92 xmms_afmt=AFMT_S16_NE; | |
93 break; | |
94 case FMT_S16_LE: | |
95 xmms_afmt=AFMT_S16_LE; | |
96 break; | |
97 case FMT_S16_BE: | |
98 xmms_afmt=AFMT_S16_BE; | |
99 break; | |
100 } | |
101 xmms_samplerate=rate; | |
102 xmms_channels=nch; | |
103 return 1; | |
104 } | |
105 | |
106 static void disk_write(void *ptr, int length) { | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
107 if (!xmms_playing) return; |
8528 | 108 pthread_mutex_lock(&xmms_mutex); |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
109 if (xmms_flushto!=-1) { |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
110 xmms_priv->spos=xmms_flushto; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
111 xmms_flushto=-1; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
112 xmms_audiopos=0; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
113 } |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
114 xmms_priv->spos+= length; |
8528 | 115 memcpy(&xmms_audiobuffer[xmms_audiopos],ptr,length); |
116 xmms_audiopos+=length; | |
117 pthread_mutex_unlock(&xmms_mutex); | |
118 } | |
119 | |
120 static OutputPlugin xmms_output_plugin = | |
121 { | |
122 NULL, | |
123 NULL, | |
124 "Mplayer output interface Plugin ", /* Description */ | |
125 disk_init, | |
126 NULL, /* about */ | |
127 NULL, /* configure */ | |
128 NULL, /* get_volume */ | |
129 NULL, /* set_volume */ | |
130 disk_open, | |
131 disk_write, | |
132 disk_close, | |
133 disk_flush, | |
134 disk_pause, | |
135 disk_free, | |
136 disk_playing, | |
137 disk_get_output_time, | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
138 disk_get_output_time //we pretend that everything written is played at once |
8528 | 139 }; |
140 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
141 // ==================== mplayer xmms inputplugin helper stuff ================= |
8528 | 142 |
143 static InputPlugin* input_plugins[100]; | |
144 static int no_plugins=0; | |
145 | |
146 /* Dummy functions */ | |
147 static int input_get_vis_type(){return 0;} | |
148 static void input_add_vis_pcm(int time, AFormat fmt, int nch, int length, void *ptr){} | |
149 static void input_set_info_text(char * text){} | |
150 /* Dummy functions END*/ | |
151 | |
8536
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
152 static void input_set_info(char* title,int length, int rate, int freq, int nch){ |
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
153 xmms_length=length; |
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
154 } |
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
155 |
8528 | 156 static void init_plugins(){ |
157 DIR *dir; | |
158 struct dirent *ent; | |
159 | |
160 no_plugins=0; | |
161 | |
162 dir = opendir(XMMS_INPUT_PLUGIN_DIR); | |
163 if (!dir) return; | |
164 | |
165 while ((ent = readdir(dir)) != NULL){ | |
166 char filename[strlen(XMMS_INPUT_PLUGIN_DIR)+strlen(ent->d_name)+4]; | |
167 void* handle; | |
168 sprintf(filename,XMMS_INPUT_PLUGIN_DIR "/%s",ent->d_name); | |
169 handle=dlopen(filename, RTLD_NOW); | |
170 if(handle){ | |
171 void *(*gpi) (void); | |
172 gpi=dlsym(handle, "get_iplugin_info"); | |
173 if(gpi){ | |
174 InputPlugin *p=gpi(); | |
175 printf("XMMS: found plugin: %s (%s)\n",ent->d_name,p->description); | |
176 p->handle = handle; | |
177 p->filename = strdup(filename); | |
178 p->get_vis_type = input_get_vis_type; | |
179 p->add_vis_pcm = input_add_vis_pcm; | |
180 p->set_info = input_set_info; | |
181 p->set_info_text = input_set_info_text; | |
182 if(p->init) p->init(); | |
183 input_plugins[no_plugins++]=p; | |
184 } else | |
185 dlclose(handle); | |
186 } | |
187 } | |
188 closedir(dir); | |
189 } | |
190 | |
191 static void cleanup_plugins(){ | |
192 while(no_plugins>0){ | |
193 --no_plugins; | |
194 printf("XMMS: Closing plugin %s\n",input_plugins[no_plugins]->filename); | |
195 if(input_plugins[no_plugins]->cleanup) | |
196 input_plugins[no_plugins]->cleanup(); | |
197 dlclose(input_plugins[no_plugins]->handle); | |
198 } | |
199 } | |
200 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
201 // ============================ mplayer demuxer stuff =============== |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
202 |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
203 //extern void resync_audio_stream(sh_audio_t *sh_audio); |
8528 | 204 |
205 int demux_xmms_open(demuxer_t* demuxer) { | |
206 InputPlugin* ip = NULL; | |
207 sh_audio_t* sh_audio; | |
208 WAVEFORMATEX* w; | |
209 xmms_priv_t *priv; | |
210 int i; | |
211 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
212 if (xmms_priv) return 0; // as I said, it's not reentrant :) |
8528 | 213 init_plugins(); |
214 for(i=0;i<no_plugins;i++){ | |
215 if (input_plugins[i]->is_our_file(demuxer->stream->url)){ | |
216 ip=input_plugins[i]; break; | |
217 } | |
218 } | |
219 if(!ip) return 0; // no plugin to handle this... | |
220 | |
221 pthread_mutex_init(&xmms_mutex,NULL); | |
222 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
223 xmms_priv=priv=(xmms_priv_t *)malloc(sizeof(xmms_priv_t)); |
8528 | 224 memset(priv,0,sizeof(xmms_priv_t)); |
225 priv->ip=ip; | |
226 | |
227 memset(xmms_audiobuffer,0,XMMS_PACKETSIZE); | |
228 | |
229 xmms_channels=0; | |
230 sh_audio = new_sh_audio(demuxer,0); | |
231 sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX)); | |
232 w->wFormatTag = sh_audio->format = format; | |
233 | |
234 demuxer->movi_start = 0; | |
235 demuxer->movi_end = 100; | |
236 demuxer->audio->id = 0; | |
237 demuxer->audio->sh = sh_audio; | |
238 demuxer->priv=priv; | |
239 sh_audio->ds = demuxer->audio; | |
240 | |
241 xmms_output_plugin.init(); | |
8536
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
242 ip->output = &xmms_output_plugin; |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
243 xmms_playing=1; |
8536
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
244 ip->play_file(demuxer->stream->url); |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
245 if (ip->get_song_info) ip->get_song_info(demuxer->stream->url,&xmms_title,&xmms_length); |
8528 | 246 if (xmms_length<=0) demuxer->seekable=0; |
247 | |
248 mp_msg(MSGT_DEMUX,MSGL_INFO,"Waiting for the XMMS plugin to start playback of '%s'...\n",demuxer->stream->url); | |
249 while (xmms_channels==0) { | |
250 usleep(10000); | |
251 if(ip->get_time()<0) return 0; | |
252 } | |
253 sh_audio->sample_format= xmms_afmt; | |
254 switch (xmms_afmt) { | |
255 case AFMT_S16_LE: | |
256 case AFMT_S16_BE: | |
257 case AFMT_U16_LE: | |
258 case AFMT_U16_BE: | |
259 sh_audio->samplesize = 2; | |
260 break; | |
261 default: | |
262 sh_audio->samplesize = 1; | |
263 } | |
264 w->wBitsPerSample = sh_audio->samplesize*8; | |
265 w->nChannels = sh_audio->channels = xmms_channels; | |
266 w->nSamplesPerSec = sh_audio->samplerate = xmms_samplerate; | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
267 xmms_byterate = w->nAvgBytesPerSec = xmms_samplerate*sh_audio->channels*sh_audio->samplesize; |
8528 | 268 w->nBlockAlign = sh_audio->samplesize*sh_audio->channels; |
269 w->cbSize = 0; | |
270 | |
271 return 1; | |
272 } | |
273 | |
274 int demux_xmms_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) { | |
275 sh_audio_t *sh_audio = demuxer->audio->sh; | |
276 xmms_priv_t *priv=demuxer->priv; | |
277 demux_packet_t* dp; | |
8536
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
278 |
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
279 if (xmms_length<=0) demuxer->seekable=0; |
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
280 else demuxer->seekable=1; |
8528 | 281 |
282 while (xmms_audiopos<XMMS_PACKETSIZE/2) { | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
283 if((priv->ip->get_time()<0) || !xmms_playing) |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
284 return 0; |
8528 | 285 usleep(1000); |
286 } | |
287 | |
288 pthread_mutex_lock(&xmms_mutex); | |
289 dp = new_demux_packet(XMMS_PACKETSIZE/2); | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
290 ds->pts = priv->spos / sh_audio->wf->nAvgBytesPerSec; |
8528 | 291 ds->pos = priv->spos; |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
292 |
8528 | 293 memcpy(dp->buffer,xmms_audiobuffer,XMMS_PACKETSIZE/2); |
294 memcpy(xmms_audiobuffer,&xmms_audiobuffer[XMMS_PACKETSIZE/2],xmms_audiopos-XMMS_PACKETSIZE/2); | |
295 xmms_audiopos-=XMMS_PACKETSIZE/2; | |
296 pthread_mutex_unlock(&xmms_mutex); | |
297 | |
298 ds_add_packet(ds,dp); | |
299 | |
300 return 1; | |
301 } | |
302 | |
303 void demux_xmms_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ | |
304 stream_t* s = demuxer->stream; | |
305 sh_audio_t* sh_audio = demuxer->audio->sh; | |
306 xmms_priv_t *priv=demuxer->priv; | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
307 int32_t pos; |
8528 | 308 |
309 if(priv->ip->get_time()<0) return; | |
310 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
311 pos = (flags & 1) ? 0 : priv->spos / sh_audio->wf->nAvgBytesPerSec; |
8528 | 312 if (flags & 2) |
313 pos+= rel_seek_secs*xmms_length; | |
314 else | |
315 pos+= rel_seek_secs; | |
316 | |
317 if (pos<0) pos=0; | |
318 if (pos>=xmms_length) pos=xmms_length-1; | |
319 | |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
320 priv->ip->seek((pos<0)?0:pos); |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
321 priv->spos=pos * sh_audio->wf->nAvgBytesPerSec; |
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
322 sh_audio->delay=pos; //priv->spos / sh_audio->wf->nAvgBytesPerSec; |
8528 | 323 } |
324 | |
325 int demux_close_xmms(demuxer_t* demuxer) { | |
326 xmms_priv_t *priv=demuxer->priv; | |
8536
ff192e1b018f
xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents:
8528
diff
changeset
|
327 xmms_playing=0; |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
328 xmms_audiopos=0; // xmp on exit waits until buffer is free enough |
8528 | 329 priv->ip->stop(); |
8542
222c0a39c977
I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents:
8536
diff
changeset
|
330 free(priv); xmms_priv=demuxer->priv=NULL; |
8528 | 331 cleanup_plugins(); |
332 return 1; | |
333 } | |
334 | |
335 int demux_xmms_control(demuxer_t *demuxer,int cmd, void *arg){ | |
336 demux_stream_t *d_video=demuxer->video; | |
337 sh_audio_t *sh_audio=demuxer->audio->sh; | |
338 xmms_priv_t *priv=demuxer->priv; | |
339 | |
340 switch(cmd) { | |
341 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
342 if (xmms_length<=0) return DEMUXER_CTRL_DONTKNOW; | |
343 *((unsigned long *)arg)=(unsigned long)xmms_length/1000; | |
344 return DEMUXER_CTRL_GUESS; | |
345 | |
346 case DEMUXER_CTRL_GET_PERCENT_POS: | |
347 if (xmms_length<=0) | |
348 return DEMUXER_CTRL_DONTKNOW; | |
349 *((int *)arg)=(int)( priv->spos / (float)(sh_audio->wf->nAvgBytesPerSec) / xmms_length ); | |
350 return DEMUXER_CTRL_OK; | |
351 | |
352 default: | |
353 return DEMUXER_CTRL_NOTIMPL; | |
354 } | |
355 } |