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
|
#include "main.h"
#include "Metadata.h"
#include "api__in_mp3.h"
#include "../nu/AutoWide.h"
#include "AlbumArt.h"
#include "Stopper.h"
#include <shlwapi.h>
#include <strsafe.h>
bool IsMyExtension(const wchar_t *filename)
{
// check if it's the current stream and is playing and is SHOUTcast2
if (PathIsURLW(filename))
{
if (g_playing_file)
{
EnterCriticalSection(&streamInfoLock);
if (g_playing_file &&
(g_playing_file->uvox_artwork.uvox_stream_artwork || g_playing_file->uvox_artwork.uvox_playing_artwork) &&
!lstrcmpW(lastfn, filename)) // check again now that we've acquired the lock
{
LeaveCriticalSection(&streamInfoLock);
return true;
}
LeaveCriticalSection(&streamInfoLock);
}
}
// otherwise handle as normal embedded
else
{
const wchar_t *extension = PathFindExtension(filename);
if (extension && *extension)
{
AutoWide wideList(config_extlist); // TODO: build a copy of this at config load time so we don't have to run this every time
extension++;
wchar_t *b = wideList;
wchar_t *c = 0;
do
{
wchar_t d[20] = {0};
StringCchCopyW(d, 15, b);
if ((c = wcschr(b, L';')))
{
if ((c-b)<15)
d[c - b] = 0;
}
if (!lstrcmpiW(extension, d))
return true;
b = c + 1;
}
while (c);
}
}
return false;
}
bool ID3v2_AlbumArtProvider::IsMine(const wchar_t *filename)
{
return IsMyExtension(filename);
}
int ID3v2_AlbumArtProvider::ProviderType()
{
return ALBUMARTPROVIDER_TYPE_EMBEDDED;
}
int ID3v2_AlbumArtProvider::GetAlbumArtData(const wchar_t *filename, const wchar_t *type, void **bits, size_t *len, wchar_t **mimeType)
{
if (g_playing_file)
{
EnterCriticalSection(&streamInfoLock);
if (g_playing_file && !lstrcmpW(lastfn, filename)) // check again now that we've acquired the lock
{
wchar_t* mimeType[] = {
L"image/jpeg",
L"image/png",
L"image/bmp",
L"image/gif"
};
if (!g_playing_file->uvox_artwork.uvox_stream_artwork)
{
int ret = g_playing_file->info.GetAlbumArt(type, bits, len, mimeType);
LeaveCriticalSection(&streamInfoLock);
return ret;
}
else
{
// will handle "playing" and "cover" - cover is the stream branding
// with "playing" used to provide song specific stream artwork
if (!_wcsicmp(type, L"playing"))
{
if (g_playing_file->uvox_artwork.uvox_playing_artwork_len > 0)
{
*len = g_playing_file->uvox_artwork.uvox_playing_artwork_len;
int type = g_playing_file->uvox_artwork.uvox_playing_artwork_type;
if(type >= 0 && type <= 3)
{
*mimeType = (wchar_t *)WASABI_API_MEMMGR->sysMalloc(12 * sizeof(wchar_t));
wcsncpy(*mimeType, mimeType[type], 12);
}
else
{
*mimeType = 0;
}
*bits = WASABI_API_MEMMGR->sysMalloc(*len);
memcpy(*bits, g_playing_file->uvox_artwork.uvox_playing_artwork, *len);
LeaveCriticalSection(&streamInfoLock);
return ALBUMARTPROVIDER_SUCCESS;
}
else
{
LeaveCriticalSection(&streamInfoLock);
return ALBUMARTPROVIDER_FAILURE;
}
}
else
{
if (g_playing_file->uvox_artwork.uvox_stream_artwork_len > 0)
{
*len = g_playing_file->uvox_artwork.uvox_stream_artwork_len;
int type = g_playing_file->uvox_artwork.uvox_stream_artwork_type;
if(type >= 0 && type <= 3)
{
*mimeType = (wchar_t *)WASABI_API_MEMMGR->sysMalloc(12 * sizeof(wchar_t));
wcsncpy(*mimeType, mimeType[type], 12);
}
else
{
*mimeType = 0;
}
*bits = WASABI_API_MEMMGR->sysMalloc(*len);
memcpy(*bits, g_playing_file->uvox_artwork.uvox_stream_artwork, *len);
LeaveCriticalSection(&streamInfoLock);
return ALBUMARTPROVIDER_SUCCESS;
}
else
{
LeaveCriticalSection(&streamInfoLock);
return ALBUMARTPROVIDER_FAILURE;
}
}
}
}
LeaveCriticalSection(&streamInfoLock);
}
Metadata metadata;
if (metadata.Open(filename) == METADATA_SUCCESS)
{
return metadata.id3v2.GetAlbumArt(type, bits, len, mimeType);
}
return ALBUMARTPROVIDER_FAILURE;
}
extern Metadata *m_ext_get_mp3info;
int ID3v2_AlbumArtProvider::SetAlbumArtData(const wchar_t *filename, const wchar_t *type, void *bits, size_t len, const wchar_t *mimeType)
{
Metadata metadata;
if (metadata.Open(filename) == METADATA_SUCCESS)
{
int ret = metadata.id3v2.SetAlbumArt(type, bits, len, mimeType);
if (ret == METADATA_SUCCESS)
{
// flush our read cache too :)
if (m_ext_get_mp3info) m_ext_get_mp3info->Release();
m_ext_get_mp3info = NULL;
Stopper stopper;
if (metadata.IsMe(lastfn))
stopper.Stop();
metadata.Save();
stopper.Play();
}
return ret;
}
return ALBUMARTPROVIDER_FAILURE;
}
int ID3v2_AlbumArtProvider::DeleteAlbumArt(const wchar_t *filename, const wchar_t *type)
{
Metadata metadata;
if (metadata.Open(filename) == METADATA_SUCCESS)
{
int ret = metadata.id3v2.DeleteAlbumArt(type);
if (ret == METADATA_SUCCESS)
{
// flush our read cache too :)
if (m_ext_get_mp3info) m_ext_get_mp3info->Release();
m_ext_get_mp3info = NULL;
Stopper stopper;
if (metadata.IsMe(lastfn))
stopper.Stop();
metadata.Save();
stopper.Play();
}
return ret;
}
return ALBUMARTPROVIDER_FAILURE;
}
#define CBCLASS ID3v2_AlbumArtProvider
START_DISPATCH;
CB(SVC_ALBUMARTPROVIDER_PROVIDERTYPE, ProviderType);
CB(SVC_ALBUMARTPROVIDER_GETALBUMARTDATA, GetAlbumArtData);
CB(SVC_ALBUMARTPROVIDER_ISMINE, IsMine);
CB(SVC_ALBUMARTPROVIDER_SETALBUMARTDATA, SetAlbumArtData);
CB(SVC_ALBUMARTPROVIDER_DELETEALBUMART, DeleteAlbumArt);
END_DISPATCH;
#undef CBCLASS
static ID3v2_AlbumArtProvider albumArtProvider;
// {C8222317-8F0D-4e79-9222-447381C46E07}
static const GUID id3v2_albumartproviderGUID =
{ 0xc8222317, 0x8f0d, 0x4e79, { 0x92, 0x22, 0x44, 0x73, 0x81, 0xc4, 0x6e, 0x7 } };
FOURCC AlbumArtFactory::GetServiceType()
{
return svc_albumArtProvider::SERVICETYPE;
}
const char *AlbumArtFactory::GetServiceName()
{
return "ID3v2 Album Art Provider";
}
GUID AlbumArtFactory::GetGUID()
{
return id3v2_albumartproviderGUID;
}
void *AlbumArtFactory::GetInterface(int global_lock)
{
return &albumArtProvider;
}
int AlbumArtFactory::SupportNonLockingInterface()
{
return 1;
}
int AlbumArtFactory::ReleaseInterface(void *ifc)
{
//plugin.service->service_unlock(ifc);
return 1;
}
const char *AlbumArtFactory::GetTestString()
{
return 0;
}
int AlbumArtFactory::ServiceNotify(int msg, int param1, int param2)
{
return 1;
}
#ifdef CBCLASS
#undef CBCLASS
#endif
#define CBCLASS AlbumArtFactory
START_DISPATCH;
CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
CB(WASERVICEFACTORY_GETGUID, GetGUID)
CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface)
CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
END_DISPATCH;
|