29 #include <nsAutoLock.h>
31 #include <nsAutoPtr.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsComponentManagerUtils.h>
35 #include <nsIComponentRegistrar.h>
36 #include <nsISupportsPrimitives.h>
38 #include <nsStringGlue.h>
39 #include <nsISimpleEnumerator.h>
40 #include <nsArrayUtils.h>
42 #include <sbITranscodingConfigurator.h>
43 #include <sbITranscodeVideoJob.h>
49 "@songbirdnest.com/Songbird/Mediacore/Transcode/";
55 m_pContractListLock = PR_NewLock();
56 NS_ASSERTION(m_pContractListLock,
57 "Failed to create sbTranscodeManager::m_pContractListLock! "
58 "Object *not* threadsafe!");
62 nsCOMPtr<nsIComponentRegistrar>
registrar;
63 rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
64 NS_ENSURE_SUCCESS (rv, );
66 nsCOMPtr<nsISimpleEnumerator> simpleEnumerator;
67 rv = registrar->EnumerateContractIDs(getter_AddRefs(simpleEnumerator));
68 NS_ENSURE_SUCCESS (rv, );
70 PRBool moreAvailable = PR_FALSE;
71 while(simpleEnumerator->HasMoreElements(&moreAvailable) ==
NS_OK &&
74 nsCOMPtr<nsISupportsCString> contractString;
75 rv = simpleEnumerator->GetNext(getter_AddRefs(contractString));
76 if (NS_SUCCEEDED (rv))
79 contractString->GetData(contractID);
82 m_ContractList.push_back(contractID);
89 sbTranscodeManager::~sbTranscodeManager()
91 if(m_pContractListLock)
93 PR_DestroyLock(m_pContractListLock);
94 m_pContractListLock = nsnull;
101 if (gTranscodeManager) {
102 NS_ADDREF(gTranscodeManager);
107 if (!gTranscodeManager)
110 NS_ADDREF(gTranscodeManager);
111 NS_ADDREF(gTranscodeManager);
117 void sbTranscodeManager::DestroySingleton()
119 nsRefPtr<sbTranscodeManager> dummy;
120 dummy.swap(gTranscodeManager);
124 sbTranscodeManager::GetTranscoderForMediaItem(
sbIMediaItem *aMediaItem,
127 NS_ENSURE_ARG_POINTER(aMediaItem);
128 NS_ENSURE_ARG_POINTER(_retval);
132 nsCOMPtr<nsISupports> bestHandler;
134 for (contractlist_t::iterator contractid = m_ContractList.begin();
135 contractid != m_ContractList.end();
138 nsCOMPtr<nsISupports> supports =
139 do_CreateInstance((*contractid).get(), &rv);
140 if (NS_FAILED(rv) || !supports)
145 nsCOMPtr<sbITranscodeVideoJob> videoJob = do_QueryInterface(supports, &rv);
146 if (NS_SUCCEEDED(rv) && videoJob)
150 rv = videoJob->Vote(aMediaItem, &vote);
156 if (vote >= bestVote) {
158 bestHandler = supports;
164 NS_ADDREF(*_retval = bestHandler);
168 return NS_ERROR_FAILURE;
172 sbTranscodeManager::GetTranscodeProfiles(PRUint32 aType, nsIArray **_retval)
175 nsCOMPtr<nsIMutableArray>
array =
176 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
177 NS_ENSURE_SUCCESS(rv, rv);
179 for (contractlist_t::iterator contractid = m_ContractList.begin();
180 contractid != m_ContractList.end();
183 nsCOMPtr<sbITranscodingConfigurator>
handler = do_CreateInstance(
184 (*contractid).get(), &rv);
186 if(NS_SUCCEEDED(rv) &&
handler)
188 nsCOMPtr<nsIArray> profiles;
191 rv = handler->GetAvailableProfiles(getter_AddRefs(profiles));
192 NS_ENSURE_SUCCESS (rv, rv);
194 rv = profiles->GetLength(&length);
195 NS_ENSURE_SUCCESS (rv, rv);
197 for (PRUint32
i = 0;
i < length;
i++) {
198 nsCOMPtr<sbITranscodeProfile> profile =
199 do_QueryElementAt(profiles,
i, &rv);
200 NS_ENSURE_SUCCESS (rv, rv);
202 PRUint32 profileType;
203 rv = profile->GetType(&profileType);
204 NS_ENSURE_SUCCESS (rv, rv);
206 if (profileType == aType) {
207 rv = array->AppendElement(profile, PR_FALSE);
208 NS_ENSURE_SUCCESS (rv, rv);
214 nsCOMPtr<nsIArray> arr = do_QueryInterface(array, &rv);
215 NS_ENSURE_SUCCESS (rv, rv);
static const char TranscodeContractIDPrefix[]
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceCapsCompatibility, sbIDeviceCapsCompatibility) sbDeviceCapsCompatibility
sbTranscodeManager * gTranscodeManager
_getSelectedPageStyle s i
The manager from which to request a transcoding job, transcoding profiles, etc.