sbGStreamerStub.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #include <nscore.h>
28 #include <prlink.h>
29 #include <nsILocalFile.h>
30 #include <nsStringAPI.h>
31 #include <nsCOMPtr.h>
32 #include <nsIComponentManager.h>
33 #include <nsIModule.h>
34 #include <nsXPCOM.h>
35 #include <sbLibraryLoaderUtils.h>
36 #include <mozilla-config.h>
37 
38 #include <nsIEnvironment.h>
39 
40 #ifdef DEBUG
41 static char kRealComponent[] = "sbGStreamerMediacore_d" MOZ_DLL_SUFFIX;
42 #else
43 static char kRealComponent[] = "sbGStreamerMediacore" MOZ_DLL_SUFFIX;
44 #endif
45 
46 extern "C" NS_EXPORT nsresult
47 NSGetModule(nsIComponentManager* aCompMgr,
48  nsIFile* aLocation,
49  nsIModule* *aResult)
50 {
51  nsresult rv;
52  PRBool systemGst;
53 
54  // aLocation starts off pointing to this component.
55  nsCOMPtr<nsIFile> parent;
56  rv = aLocation->GetParent(getter_AddRefs(parent));
57  NS_ENSURE_SUCCESS(rv, rv);
58 
59  nsCOMPtr<nsIFile> libDir;
60  rv = parent->Clone(getter_AddRefs(libDir));
61  NS_ENSURE_SUCCESS(rv, rv);
62  rv = libDir->SetNativeLeafName(NS_LITERAL_CSTRING("lib"));
63  NS_ENSURE_SUCCESS(rv, rv);
64 
65  // Always bundled on OSX, Windows. Default to using the bundled version
66  // elsewhere, unless SB_GST_SYSTEM is set.
67 #if defined(XP_MACOSX) || defined(XP_WIN)
68  systemGst = PR_FALSE;
69 #else
70  nsCOMPtr<nsIEnvironment> envSvc =
71  do_GetService("@mozilla.org/process/environment;1", &rv);
72  NS_ENSURE_SUCCESS(rv, rv);
73 
74  rv = envSvc->Exists(NS_LITERAL_STRING("SB_GST_SYSTEM"), &systemGst);
75  NS_ENSURE_SUCCESS(rv, rv);
76 #endif
77 
78  if (!systemGst) {
79  // Load the libraries in this lib dir from the gst_libs.txt list,
80  // when we're running against the bundled version of gstreamer.
81  nsCOMPtr<nsIFile> manifest;
82  rv = parent->Clone(getter_AddRefs(manifest));
83  NS_ENSURE_SUCCESS(rv, rv);
84 
85  rv = manifest->AppendNative(NS_LITERAL_CSTRING("gst_libs.txt"));
86  NS_ENSURE_SUCCESS(rv, rv);
87 
88  rv = SB_LoadLibraries(manifest);
89  NS_ENSURE_SUCCESS(rv, rv);
90  }
91 
92  rv = libDir->AppendNative(NS_LITERAL_CSTRING(kRealComponent));
93  NS_ENSURE_SUCCESS(rv, rv);
94 
95  // load the actual component
96  nsCOMPtr<nsILocalFile> libDirLocal = do_QueryInterface(libDir, &rv);
97  NS_ENSURE_SUCCESS(rv, rv);
98 
99  PRLibrary* lib;
100  rv = libDirLocal->Load(&lib);
101  NS_ENSURE_SUCCESS(rv, rv);
102 
103  nsGetModuleProc getmoduleproc = (nsGetModuleProc)
104  PR_FindFunctionSymbol(lib, "NSGetModule");
105  NS_ENSURE_TRUE(getmoduleproc, NS_ERROR_FAILURE);
106 
107  return getmoduleproc(aCompMgr, aLocation, aResult);
108 }
109 
110 /*
111 
112 This file was derived from:
113 http://developer.mozilla.org/en/docs/Using_Dependent_Libraries_In_Extension_Components
114 Copyright (c) 2005 Benjamin Smedberg <benjamin@smedbergs.us>
115 It had the following license:
116 
117 The MIT License
118 
119 Copyright (c) 2005 Benjamin Smedberg <benjamin@smedbergs.us>
120 
121 Permission is hereby granted, free of charge, to any person obtaining a
122 copy of this software and associated documentation files (the "Software"),
123 to deal in the Software without restriction, including without limitation
124 the rights to use, copy, modify, merge, publish, distribute, sublicense,
125 and/or sell copies of the Software, and to permit persons to whom the
126 Software is furnished to do so, subject to the following conditions:
127 
128 The above copyright notice and this permission notice shall be included in
129 all copies or substantial portions of the Software.
130 
131 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
132 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
133 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
134 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
135 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
136 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
137 DEALINGS IN THE SOFTWARE.
138 */
static nsresult SB_LoadLibraries(nsIFile *aManifest)
static char kRealComponent[]
NS_EXPORT nsresult NSGetModule(nsIComponentManager *aCompMgr, nsIFile *aLocation, nsIModule **aResult)