1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
//#define PLUGIN_NAME "Nullsoft MPEG Audio Decoder"
#include "main.h"
#include <time.h>
#include "DecodeThread.h"
#include "api__in_mp3.h"
#include "../Winamp/wa_ipc.h"
#include "../nu/ServiceBuilder.h"
#include "config.h"
#include "AlbumArt.h"
#include "MetadataFactory.h"
#include "../nu/Singleton.h"
#include "RawMediaReader.h"
char lastfn_status[256] = {0};
int lastfn_status_err = 0;
CRITICAL_SECTION g_lfnscs;
CRITICAL_SECTION streamInfoLock;
int lastfn_data_ready;
int config_fastvis=0;
unsigned char config_miscopts=0;
unsigned char allow_sctitles=1;
unsigned char sctitle_format=1;
unsigned char config_eqmode=4,config_http_proxynonport80=1;
unsigned int winampVersion=0x00005010; // default version # to use if winamp version is 5.1 or less (and therefore doesn't have a valid HWND during Init)
char config_http_save_dir[MAX_PATH] = "C:\\";
int config_http_buffersize=64, config_http_prebuffer=40, config_http_prebuffer_underrun=10;
unsigned char config_downmix=0, config_downsample=0, allow_scartwork=1;
int config_max_bufsize_k=128;
int config_gapless=1;
char INI_FILE[MAX_PATH] = {0};
wchar_t lastfn[8192] = {0}; // currently playing file (used for getting info on the current file)
// Used for correcting DSP plug-in pitch changes
int paused = 0; // are we paused?
int m_is_stream = 0;
bool m_is_stream_seekable = true;
volatile int killDecodeThread=0; // the kill switch for the decode thread
HANDLE thread_handle=INVALID_HANDLE_VALUE; // the handle to the decode thread
DWORD WINAPI DecodeThread(LPVOID b); // the decode thread procedure
extern char *getfileextensions();
#include "api/service/waservicefactory.h"
#include "FactoryHelper.h"
// wasabi based services for localisation support
HINSTANCE WASABI_API_LNG_HINST = 0;
HINSTANCE WASABI_API_ORIG_HINST = 0;
api_language *WASABI_API_LNG = 0;
api_application *WASABI_API_APP = 0;
api_config *AGAVE_API_CONFIG = 0;
api_memmgr *WASABI_API_MEMMGR = 0;
AlbumArtFactory albumArtFactory;
MetadataFactory metadataFactory;
static RawMediaReaderService raw_media_reader_service;
static SingletonServiceFactory<svc_raw_media_reader, RawMediaReaderService> raw_factory;
int init()
{
if (!IsWindow(mod.hMainWindow))
return IN_INIT_FAILURE;
winampVersion = (unsigned int)SendMessage(mod.hMainWindow, WM_WA_IPC, 0, IPC_GETVERSION);
mod.service->service_register(&metadataFactory);
mod.service->service_register(&albumArtFactory);
raw_factory.Register(mod.service, &raw_media_reader_service);
ServiceBuild(AGAVE_API_CONFIG, AgaveConfigGUID);
ServiceBuild(WASABI_API_LNG, languageApiGUID);
ServiceBuild(WASABI_API_APP, applicationApiServiceGuid);
ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
// need to have this initialised before we try to do anything with localisation features
WASABI_API_START_LANG(mod.hDllInstance,InMp3LangGUID);
static wchar_t szDescription[256];
swprintf(szDescription, 256, WASABI_API_LNGSTRINGW(IDS_NULLSOFT_MPEG_AUDIO_DECODER), PLUGIN_VERSION);
mod.description = (char*)szDescription;
InitializeCriticalSection(&g_lfnscs);
InitializeCriticalSection(&streamInfoLock);
mod.UsesOutputPlug|=2;
config_read();
mod.FileExtensions=getfileextensions();
return IN_INIT_SUCCESS;
}
void quit()
{
DeleteCriticalSection(&g_lfnscs);
DeleteCriticalSection(&streamInfoLock);
ServiceRelease(mod.service, AGAVE_API_CONFIG, AgaveConfigGUID);
ServiceRelease(mod.service, WASABI_API_APP, applicationApiServiceGuid);
ServiceRelease(mod.service, WASABI_API_MEMMGR, memMgrApiServiceGuid);
mod.service->service_deregister(&albumArtFactory);
raw_factory.Deregister(mod.service);
}
int g_eq_ok;
int isourfile(const wchar_t *fn)
{
if (!_wcsnicmp(fn,L"uvox://",7)) return 1;
if (!_wcsnicmp(fn,L"icy://",6)) return 1;
if (!_wcsnicmp(fn,L"sc://",5)) return 1;
if (!_wcsnicmp(fn,L"shoutcast://",12)) return 1;
return 0;
}
int m_force_seek=-1;
// called when winamp wants to play a file
int play(const in_char *fn)
{
DWORD thread_id;
lastfn_status_err=0;
paused=0;
g_length=-1000;
decode_pos_ms=0;
seek_needed=m_force_seek;
m_force_seek=-1;
m_is_stream = 0;
m_is_stream_seekable = false;
killDecodeThread=0;
g_sndopened=0;
lastfn_data_ready=0;
lastfn_status[0]=0;
g_bufferstat=0;
g_closeaudio=0;
lstrcpynW(lastfn,fn, 8192);
mod.is_seekable = 0;
mod.SetInfo(0,0,0,0);
g_ds=config_downsample;
g_eq_ok=1;
// launch decode thread
thread_handle = (HANDLE)CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) DecodeThread,NULL,0,&thread_id);
SetThreadPriority(thread_handle, (int)AGAVE_API_CONFIG->GetInt(playbackConfigGroupGUID, L"priority", THREAD_PRIORITY_HIGHEST));
return 0;
}
// standard pause implementation
void pause()
{
paused=1;
if (g_sndopened)
mod.outMod->Pause(1);
}
void unpause()
{
paused=0;
if (g_sndopened)
mod.outMod->Pause(0);
}
int ispaused()
{
return paused;
}
// stop playing.
void stop()
{
killDecodeThread=1;
WaitForSingleObject(thread_handle,INFINITE);
CloseHandle(thread_handle);
g_eq_ok=0;
thread_handle = INVALID_HANDLE_VALUE;
g_length=-1000;
lastfn[0]=0;
if (g_closeaudio)
{
g_closeaudio=0;
mod.outMod->Close();
mod.SAVSADeInit();
}
g_sndopened=0;
m_force_seek=-1;
}
// returns length of playing track
int getlength()
{
return g_length;
}
// returns current output position, in ms.
// you could just use return mod.outMod->GetOutputTime(),
// but the dsp plug-ins that do tempo changing tend to make
// that wrong.
int getoutputtime()
{
if (g_bufferstat)
return g_bufferstat;
if (!lastfn_data_ready||!g_sndopened)
return 0;
if (seek_needed!=-1)
return seek_needed;
return decode_pos_ms +
(mod.outMod->GetOutputTime()-mod.outMod->GetWrittenTime());
}
// called when the user releases the seek scroll bar.
// usually we use it to set seek_needed to the seek
// point (seek_needed is -1 when no seek is needed)
// and the decode thread checks seek_needed.
void setoutputtime(int time_in_ms)
{
if (m_is_stream == 0 || (m_is_stream !=0 && m_is_stream_seekable))
{
seek_needed=time_in_ms;
m_force_seek=-1;
}
}
// standard volume/pan functions
void setvolume(int volume)
{
mod.outMod->SetVolume(volume);
}
void setpan(int pan)
{
mod.outMod->SetPan(pan);
}
// this is an odd function. it is used to get the title and/or
// length of a track.
// if filename is either NULL or of length 0, it means you should
// return the info of lastfn. Otherwise, return the information
// for the file in filename.
// if title is NULL, no title is copied into it.
// if length_in_ms is NULL, no length is copied into it.
static int memcmpv(char *d, char v, int l)
{
while (l--)
if (*d++ != v) return 1;
return 0;
}
void eq_set(int on, char data[10], int preamp)
{
int x;
eq_preamp = preamp;
eq_enabled = on;
for (x = 0; x < 10; x ++)
eq_tab[x] = data[x];
// if eq zeroed out, dont use eq
if (eq_enabled && preamp==31 && !memcmpv(data,31,10))
eq_enabled=0;
}
// render 576 samples into buf.
// this function is only used by DecodeThread.
// note that if you adjust the size of sample_buffer, for say, 1024
// sample blocks, it will still work, but some of the visualization
// might not look as good as it could. Stick with 576 sample blocks
// if you can, and have an additional auxiliary (overflow) buffer if
// necessary..
// module definition.
extern In_Module mod =
{
IN_VER_RET, // defined in IN2.H
"nullsoft(in_mp3.dll)",
0, // hMainWindow (filled in by winamp)
0, // hDllInstance (filled in by winamp)
0,
// this is a double-null limited list. "EXT\0Description\0EXT\0Description\0" etc.
0, // is_seekable
1, // uses output plug-in system
config,
about,
init,
quit,
getfileinfo,
id3Dlg,
isourfile,
play,
pause,
unpause,
ispaused,
stop,
getlength,
getoutputtime,
setoutputtime,
setvolume,
setpan,
0,0,0,0,0,0,0,0,0, // visualization calls filled in by winamp
0,0, // dsp calls filled in by winamp
eq_set,
NULL, // setinfo call filled in by winamp
0, // out_mod filled in by winamp
};
// exported symbol. Returns output module.
extern "C"
{
__declspec(dllexport) In_Module * winampGetInModule2()
{
return &mod;
}
}
|