annotate libmpdemux/demux_xmms.c @ 12375:48a655d09522

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