annotate libmpdemux/demux_xmms.c @ 20724:b8fe18a742ce

Fix MacIntel build: "/nop" is illegal on Apple's older version of GAS Patch by Nigel Pearson % nigel A ind P tansu P com P au % Original thread: Date: Nov 6, 2006 10:43 PM Subject: [Ffmpeg-devel] [PATCH] swscale uses /nop, illegal for old versions of GAS
author gpoirier
date Tue, 07 Nov 2006 07:07:05 +0000
parents 83c3afeab35d
children 02333de881a7
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
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16877
diff changeset
15 #include "m_option.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16877
diff changeset
16 #include "libaf/af_format.h"
8528
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
18176
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
21 #include "mp_msg.h"
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
22 #include "help_mp.h"
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
23
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
24 #define XMMS_PACKETSIZE 65536 // some plugins won't play if this is too small
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
25
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
26 #include "demux_xmms_plugin.h"
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
27
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
28 typedef struct {
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
29 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
30 InputPlugin* ip;
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
31 } xmms_priv_t;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
32
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
33 static pthread_mutex_t xmms_mutex;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
34 static int format = 0x1; // Raw PCM
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
35 static char xmms_audiobuffer[XMMS_PACKETSIZE];
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
36 static uint32_t xmms_channels;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
37 static uint32_t xmms_samplerate;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
38 static uint32_t xmms_afmt;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
39 static int xmms_length;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
40 static char *xmms_title=NULL;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
41 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
42 static int xmms_playing=0;
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
43 static xmms_priv_t *xmms_priv=NULL;
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
44 static uint32_t xmms_byterate;
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
45 static int64_t xmms_flushto=-1;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
46
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
47 // =========== mplayer xmms outputplugin stuff ==============
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
48
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
49 static void disk_close(void) {}
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
50 static void disk_pause(short p) {}
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
51 static void disk_init(void) {}
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
52
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
53 static void disk_flush(int time) {
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
54 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
55 }
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
56
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
57 static int disk_free(void) { // vqf plugin sends more than it should
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
58 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
59 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
60
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
61 static int disk_playing(void) {
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
62 return 0; //?? maybe plugins wait on exit until oplugin is not playing?
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
63 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
64
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
65 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
66 if (xmms_byterate)
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
67 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
68 else return 0;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
69 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
70
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
71 static int disk_open(AFormat fmt, int rate, int nch) {
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
72 switch (fmt) {
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
73 case FMT_U8:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
74 xmms_afmt=AF_FORMAT_U8;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
75 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
76 case FMT_S8:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
77 xmms_afmt=AF_FORMAT_S8;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
78 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
79 case FMT_U16_LE:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
80 xmms_afmt=AF_FORMAT_U16_LE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
81 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
82 case FMT_U16_NE:
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
83 #if WORDS_BIGENDIAN
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
84 xmms_afmt=AF_FORMAT_U16_BE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
85 #else
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
86 xmms_afmt=AF_FORMAT_U16_LE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
87 #endif
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
88 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
89 case FMT_U16_BE:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
90 xmms_afmt=AF_FORMAT_U16_BE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
91 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
92 case FMT_S16_NE:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
93 xmms_afmt=AF_FORMAT_S16_NE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
94 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
95 case FMT_S16_LE:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
96 xmms_afmt=AF_FORMAT_S16_LE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
97 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
98 case FMT_S16_BE:
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
99 xmms_afmt=AF_FORMAT_S16_BE;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
100 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
101 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
102 xmms_samplerate=rate;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
103 xmms_channels=nch;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
104 return 1;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
105 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
106
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
107 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
108 if (!xmms_playing) return;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
109 pthread_mutex_lock(&xmms_mutex);
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
110 if (xmms_flushto!=-1) {
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
111 xmms_priv->spos=xmms_flushto;
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
112 xmms_flushto=-1;
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
113 xmms_audiopos=0;
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
114 }
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
115 xmms_priv->spos+= length;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
116 memcpy(&xmms_audiobuffer[xmms_audiopos],ptr,length);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
117 xmms_audiopos+=length;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
118 pthread_mutex_unlock(&xmms_mutex);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
119 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
120
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
121 static OutputPlugin xmms_output_plugin =
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
122 {
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
123 NULL,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
124 NULL,
12860
03d3ab9f6400 embarassing typo
diego
parents: 10594
diff changeset
125 "MPlayer output interface plugin ", /* Description */
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
126 disk_init,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
127 NULL, /* about */
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
128 NULL, /* configure */
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
129 NULL, /* get_volume */
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
130 NULL, /* set_volume */
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
131 disk_open,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
132 disk_write,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
133 disk_close,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
134 disk_flush,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
135 disk_pause,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
136 disk_free,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
137 disk_playing,
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
138 disk_get_output_time,
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
139 disk_get_output_time //we pretend that everything written is played at once
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
140 };
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
141
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
142 // ==================== mplayer xmms inputplugin helper stuff =================
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
143
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
144 static InputPlugin* input_plugins[100];
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
145 static int no_plugins=0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
146
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
147 /* Dummy functions */
10211
4bc481804519 warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
alex
parents: 9211
diff changeset
148 static InputVisType input_get_vis_type(){return 0;}
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
149 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
150 static void input_set_info_text(char * text){}
9211
383e3cc8ee88 xmms_demuxer missing symbol
arpi
parents: 8623
diff changeset
151 char *xmms_get_gentitle_format(){ return ""; }
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
152 /* Dummy functions END*/
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
153
8536
ff192e1b018f xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents: 8528
diff changeset
154 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
155 xmms_length=length;
ff192e1b018f xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents: 8528
diff changeset
156 }
ff192e1b018f xmp hangign I noticed too, and is fixed with this patch, seeking works now
arpi
parents: 8528
diff changeset
157
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
158 static void init_plugins(){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
159 DIR *dir;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
160 struct dirent *ent;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
161
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
162 no_plugins=0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
163
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
164 dir = opendir(XMMS_INPUT_PLUGIN_DIR);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
165 if (!dir) return;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
166
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
167 while ((ent = readdir(dir)) != NULL){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
168 char filename[strlen(XMMS_INPUT_PLUGIN_DIR)+strlen(ent->d_name)+4];
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
169 void* handle;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
170 sprintf(filename,XMMS_INPUT_PLUGIN_DIR "/%s",ent->d_name);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
171 handle=dlopen(filename, RTLD_NOW);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
172 if(handle){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
173 void *(*gpi) (void);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
174 gpi=dlsym(handle, "get_iplugin_info");
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
175 if(gpi){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
176 InputPlugin *p=gpi();
18176
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
177 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_XMMS_FoundPlugin,ent->d_name,p->description);
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
178 p->handle = handle;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
179 p->filename = strdup(filename);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
180 p->get_vis_type = input_get_vis_type;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
181 p->add_vis_pcm = input_add_vis_pcm;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
182 p->set_info = input_set_info;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
183 p->set_info_text = input_set_info_text;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
184 if(p->init) p->init();
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
185 input_plugins[no_plugins++]=p;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
186 } else
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
187 dlclose(handle);
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 closedir(dir);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
191 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
192
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
193 static void cleanup_plugins(){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
194 while(no_plugins>0){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
195 --no_plugins;
18176
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
196 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_XMMS_ClosingPlugin,input_plugins[no_plugins]->filename);
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
197 if(input_plugins[no_plugins]->cleanup)
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
198 input_plugins[no_plugins]->cleanup();
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
199 dlclose(input_plugins[no_plugins]->handle);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
200 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
201 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
202
8542
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
203 // ============================ mplayer demuxer stuff ===============
222c0a39c977 I cleaned up the source a bit, hopefully fixed hanging, also
arpi
parents: 8536
diff changeset
204
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
205 static int demux_xmms_open(demuxer_t* demuxer) {
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
206 InputPlugin* ip = NULL;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
207 sh_audio_t* sh_audio;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
208 WAVEFORMATEX* w;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
209 xmms_priv_t *priv;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
210 int i;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
213 init_plugins();
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
214 for(i=0;i<no_plugins;i++){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
215 if (input_plugins[i]->is_our_file(demuxer->stream->url)){
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
216 ip=input_plugins[i]; break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
217 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
218 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
219 if(!ip) return 0; // no plugin to handle this...
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
220
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
221 pthread_mutex_init(&xmms_mutex,NULL);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
222
19062
83c3afeab35d drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents: 18710
diff changeset
223 xmms_priv=priv=malloc(sizeof(xmms_priv_t));
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
224 memset(priv,0,sizeof(xmms_priv_t));
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
225 priv->ip=ip;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
226
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
227 memset(xmms_audiobuffer,0,XMMS_PACKETSIZE);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
228
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
229 xmms_channels=0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
230 sh_audio = new_sh_audio(demuxer,0);
19062
83c3afeab35d drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents: 18710
diff changeset
231 sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX));
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
232 w->wFormatTag = sh_audio->format = format;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
233
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
234 demuxer->movi_start = 0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
235 demuxer->movi_end = 100;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
236 demuxer->audio->id = 0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
237 demuxer->audio->sh = sh_audio;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
238 demuxer->priv=priv;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
239 sh_audio->ds = demuxer->audio;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
240
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
246 if (xmms_length<=0) demuxer->seekable=0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
247
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
248 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
249 while (xmms_channels==0) {
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
250 usleep(10000);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
251 if(ip->get_time()<0) return 0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
252 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
253 sh_audio->sample_format= xmms_afmt;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
254 switch (xmms_afmt) {
14248
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
255 case AF_FORMAT_S16_LE:
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
256 case AF_FORMAT_S16_BE:
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
257 case AF_FORMAT_U16_LE:
92a2b97ccc4f removing AFMT_ dependancy
alex
parents: 12860
diff changeset
258 case AF_FORMAT_U16_BE:
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
259 sh_audio->samplesize = 2;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
260 break;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
261 default:
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
262 sh_audio->samplesize = 1;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
263 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
264 w->wBitsPerSample = sh_audio->samplesize*8;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
265 w->nChannels = sh_audio->channels = xmms_channels;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
268 w->nBlockAlign = sh_audio->samplesize*sh_audio->channels;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
269 w->cbSize = 0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
270
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
271 return DEMUXER_TYPE_XMMS;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
272 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
273
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
274 static int demux_xmms_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
275 sh_audio_t *sh_audio = demuxer->audio->sh;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
276 xmms_priv_t *priv=demuxer->priv;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
281
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
285 usleep(1000);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
286 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
287
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
288 pthread_mutex_lock(&xmms_mutex);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
289 dp = new_demux_packet(XMMS_PACKETSIZE/2);
18710
c528c6c518f1 Clean up audio pts handling, make audio pts tracking in the audio-only
uau
parents: 18176
diff changeset
290 dp->pts = priv->spos / sh_audio->wf->nAvgBytesPerSec;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
293 memcpy(dp->buffer,xmms_audiobuffer,XMMS_PACKETSIZE/2);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
294 memcpy(xmms_audiobuffer,&xmms_audiobuffer[XMMS_PACKETSIZE/2],xmms_audiopos-XMMS_PACKETSIZE/2);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
295 xmms_audiopos-=XMMS_PACKETSIZE/2;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
296 pthread_mutex_unlock(&xmms_mutex);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
297
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
298 ds_add_packet(ds,dp);
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
299
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
300 return 1;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
301 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
302
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17012
diff changeset
303 static void demux_xmms_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
304 stream_t* s = demuxer->stream;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
305 sh_audio_t* sh_audio = demuxer->audio->sh;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
308
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
309 if(priv->ip->get_time()<0) return;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
312 if (flags & 2)
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
313 pos+= rel_seek_secs*xmms_length;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
314 else
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
315 pos+= rel_seek_secs;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
316
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
317 if (pos<0) pos=0;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
318 if (pos>=xmms_length) pos=xmms_length-1;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
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;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
322 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
323
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
324 static void demux_close_xmms(demuxer_t* demuxer) {
8528
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 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
335
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
336 static int demux_xmms_control(demuxer_t *demuxer,int cmd, void *arg){
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
337 demux_stream_t *d_video=demuxer->video;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
338 sh_audio_t *sh_audio=demuxer->audio->sh;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
339 xmms_priv_t *priv=demuxer->priv;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
340
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
341 switch(cmd) {
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
342 case DEMUXER_CTRL_GET_TIME_LENGTH:
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
343 if (xmms_length<=0) return DEMUXER_CTRL_DONTKNOW;
16346
6ff303d2876b Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents: 16175
diff changeset
344 *((double *)arg)=(double)xmms_length/1000;
8528
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
345 return DEMUXER_CTRL_GUESS;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
346
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
347 case DEMUXER_CTRL_GET_PERCENT_POS:
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
348 if (xmms_length<=0)
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
349 return DEMUXER_CTRL_DONTKNOW;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
350 *((int *)arg)=(int)( priv->spos / (float)(sh_audio->wf->nAvgBytesPerSec) / xmms_length );
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
351 return DEMUXER_CTRL_OK;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
352
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
353 default:
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
354 return DEMUXER_CTRL_NOTIMPL;
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
355 }
9d143176d95f XMMS Input plugin support
arpi
parents:
diff changeset
356 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
357
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
358
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
359 demuxer_desc_t demuxer_desc_xmms = {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
360 "XMMS demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
361 "xmms",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
362 "XMMS",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
363 "?",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
364 "requires XMMS plugins",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
365 DEMUXER_TYPE_XMMS,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
366 0, // safe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
367 demux_xmms_open,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
368 demux_xmms_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
369 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
370 demux_close_xmms,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
371 demux_xmms_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
372 demux_xmms_control
6b86089c2edd Demuxer modularization
rtognimp
parents: 14248
diff changeset
373 };