31 #include <nsXPCOMCID.h>
32 #include <nsIObserverService.h>
33 #include <nsIPrefBranch.h>
34 #include <nsIPrefService.h>
39 #include <sbIGStreamerService.h>
53 static PRLogModuleInfo* gGStreamerMediacoreFactory =
54 PR_NewLogModule(
"sbGStreamerMediacoreFactory");
57 if (gGStreamerMediacoreFactory) \
58 PR_LOG(gGStreamerMediacoreFactory, PR_LOG_WARNING, args)
61 if (gGStreamerMediacoreFactory) \
62 PR_LOG(gGStreamerMediacoreFactory, PR_LOG_DEBUG, args)
71 #define BLACKLIST_EXTENSIONS_PREF "songbird.mediacore.gstreamer.blacklistExtensions"
72 #define VIDEO_EXTENSIONS_PREF "songbird.mediacore.gstreamer.videoExtensions"
73 #define VIDEO_DISABLED_PREF "songbird.mediacore.gstreamer.disablevideo"
83 sbGStreamerMediacoreFactory::sbGStreamerMediacoreFactory()
96 NS_ENSURE_SUCCESS(rv, rv);
101 nsCOMPtr<sbIGStreamerService>
service =
103 NS_ENSURE_SUCCESS(rv, rv);
105 nsCOMPtr<nsIObserverService> obs =
106 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
107 NS_ENSURE_SUCCESS(rv, rv);
109 rv = obs->AddObserver(
this,
"quit-application", PR_FALSE);
110 NS_ENSURE_SUCCESS(rv, rv);
112 nsCOMPtr<nsIPrefBranch2> rootPrefBranch =
114 NS_ENSURE_SUCCESS(rv, rv);
117 NS_ENSURE_SUCCESS(rv, rv);
120 NS_ENSURE_SUCCESS(rv, rv);
130 nsCOMPtr<nsIObserverService> obs =
131 do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
132 NS_ENSURE_SUCCESS(rv, rv);
134 rv = obs->RemoveObserver(
this,
"quit-application");
135 NS_ENSURE_SUCCESS(rv, rv);
137 nsCOMPtr<nsIPrefBranch2> rootPrefBranch =
139 NS_ENSURE_SUCCESS(rv, rv);
142 NS_ENSURE_SUCCESS(rv, rv);
145 NS_ENSURE_SUCCESS(rv, rv);
155 NS_ENSURE_SUCCESS(rv, rv);
159 NS_ENSURE_SUCCESS(rv, rv);
168 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
179 nsRefPtr<sbMediacoreCapabilities> caps;
181 NS_ENSURE_TRUE(caps, NS_ERROR_OUT_OF_MEMORY);
184 NS_ENSURE_SUCCESS(rv, rv);
190 nsCOMPtr<nsIPrefBranch> rootPrefBranch =
192 NS_ENSURE_SUCCESS(rv, rv);
194 nsTArray<nsString> audioExtensions;
195 nsTArray<nsString> videoExtensions;
202 nsCString blacklistExtensions;
204 const char defaultBlacklistExtensions[] =
205 "txt,htm,html,xml,pdf,cpl,msstyles,scr,sys,ocx,bz2,gz,zip,Z,rar,tar,dll,"
206 "exe,a,bmp,png,gif,jpeg,jpg,jpe,tif,tiff,xpm,dat,swf,swfl,stm,cgi,sf,xcf,"
207 "far,wvc,mpc,mpp,mp+,ra,rm,rmvb";
208 char* blacklistExtensionsPtr = nsnull;
210 &blacklistExtensionsPtr);
211 if (NS_SUCCEEDED(rv)) {
212 blacklistExtensions.Adopt(blacklistExtensionsPtr);
214 blacklistExtensions.Assign(defaultBlacklistExtensions);
216 blacklistExtensions.Insert(
',', 0);
217 blacklistExtensions.Append(
',');
218 LOG((
"sbGStreamerMediacoreFactory: blacklisted extensions: %s\n",
219 blacklistExtensions.BeginReading()));
222 const char *extraAudioExtensions[] = {
"m4r",
"m4p",
"oga",
223 "ogg",
"aac",
"3gp"};
224 #if defined(XP_WIN) || defined(XP_UNIX)
225 const char *extraWindowsAudioExtensions[] = {
"wma" };
240 videoExtensions.AppendElement(NS_LITERAL_STRING(
"ogv"));
241 videoExtensions.AppendElement(NS_LITERAL_STRING(
"ogx"));
242 videoExtensions.AppendElement(NS_LITERAL_STRING(
"divx"));
243 videoExtensions.AppendElement(NS_LITERAL_STRING(
"avi"));
244 videoExtensions.AppendElement(NS_LITERAL_STRING(
"mkv"));
245 videoExtensions.AppendElement(NS_LITERAL_STRING(
"vob"));
248 videoExtensions.AppendElement(NS_LITERAL_STRING(
"mpg"));
249 videoExtensions.AppendElement(NS_LITERAL_STRING(
"mpeg"));
252 videoExtensions.AppendElement(NS_LITERAL_STRING(
"wmv"));
255 char* knownVideoExtensionsPtr = nsnull;
257 &knownVideoExtensionsPtr);
258 if (NS_SUCCEEDED(rv)) {
261 NS_LITERAL_STRING(
","),
266 nsString videoExtensionStr;
267 for (PRUint32
i = 0;
i < videoExtensions.Length();
i++) {
268 videoExtensionStr.Append(videoExtensions[
i]);
269 if (i < videoExtensions.Length() - 1) {
270 videoExtensionStr.AppendLiteral(
", ");
274 LOG((
"sbGStreamerMediacoreFactory: video file extensions: %s\n",
275 videoExtensionStr.get()));
279 GstPlugin *plugin = gst_default_registry_find_plugin(
"qtvideowrapper");
281 videoExtensions.AppendElement(NS_LITERAL_STRING(
"mp4"));
282 videoExtensions.AppendElement(NS_LITERAL_STRING(
"m4v"));
283 videoExtensions.AppendElement(NS_LITERAL_STRING(
"mov"));
284 gst_object_unref(plugin);
288 GList *walker, *list;
290 list = gst_type_find_factory_get_list ();
293 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walker->data);
294 gboolean blacklisted = FALSE;
295 const gchar* factoryName = gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory));
296 gboolean isAudioFactory = g_str_has_prefix(factoryName,
"audio/");
298 gchar **factoryexts = gst_type_find_factory_get_extensions (factory);
300 while (*factoryexts) {
301 gboolean isAudioExtension = isAudioFactory;
302 nsCString extension(*factoryexts);
303 nsCString delimitedExtension(extension);
304 delimitedExtension.Insert(
',', 0);
305 delimitedExtension.Append(
',');
307 blacklisted = (blacklistExtensions.Find(delimitedExtension) != -1);
310 LOG((
"sbGStreamerMediacoreFactory: Ignoring extension '%s'", *factoryexts));
314 if (!blacklisted && isAudioExtension) {
315 audioExtensions.AppendElement(NS_ConvertUTF8toUTF16(*factoryexts));
316 LOG((
"sbGStreamerMediacoreFactory: registering audio extension %s\n",
323 walker = g_list_next (walker);
327 for (
unsigned int i = 0;
i < NS_ARRAY_LENGTH(extraAudioExtensions);
i++) {
328 nsString ext = NS_ConvertUTF8toUTF16(extraAudioExtensions[
i]);
329 if(!audioExtensions.Contains(ext))
330 audioExtensions.AppendElement(ext);
333 #if defined(XP_WIN) || defined(XP_UNIX)
334 for (
unsigned int i = 0;
i < NS_ARRAY_LENGTH(extraWindowsAudioExtensions);
i++) {
335 nsString ext = NS_ConvertUTF8toUTF16(extraWindowsAudioExtensions[
i]);
336 if(!audioExtensions.Contains(ext))
337 audioExtensions.AppendElement(ext);
341 rv = caps->SetAudioExtensions(audioExtensions);
342 NS_ENSURE_SUCCESS(rv, rv);
345 rv = caps->SetSupportsAudioPlayback(PR_TRUE);
346 NS_ENSURE_SUCCESS(rv, rv);
348 PRBool videoDisabled = PR_FALSE;
349 rv = rootPrefBranch->GetBoolPref(
350 "songbird.mediacore.gstreamer.disablevideo",
352 NS_ENSURE_SUCCESS(rv, rv);
353 if (!videoDisabled) {
354 rv = caps->SetVideoExtensions(videoExtensions);
355 NS_ENSURE_SUCCESS(rv, rv);
357 rv = caps->SetSupportsVideoPlayback(PR_TRUE);
358 NS_ENSURE_SUCCESS(rv, rv);
365 NS_ENSURE_SUCCESS(rv, rv);
374 nsRefPtr<sbGStreamerMediacore> mediacore;
376 NS_ENSURE_TRUE(mediacore, NS_ERROR_OUT_OF_MEMORY);
378 nsresult rv = mediacore->Init();
379 NS_ENSURE_SUCCESS(rv, rv);
381 rv = mediacore->SetInstanceName(aInstanceName);
382 NS_ENSURE_SUCCESS(rv, rv);
384 rv = CallQueryInterface(mediacore.get(), _retval);
385 NS_ENSURE_SUCCESS(rv, rv);
391 sbGStreamerMediacoreFactory::Observe(
nsISupports *subject,
393 const PRUnichar *
aData)
395 if (!strcmp(topic,
"quit-application")) {
399 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
const NS_PREFSERVICE_CONTRACTID
#define SBGSTREAMERSERVICE_CONTRACTID
void nsString_Split(const nsAString &aString, const nsAString &aDelimiter, nsTArray< nsString > &aSubStringArray)
const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData