33 #include <sbFileUtils.h>
34 #include <sbIDeviceEvent.h>
35 #include <sbIAlbumArtScanner.h>
36 #include <sbIJobCancelable.h>
37 #include <sbIJobProgress.h>
38 #include <sbIMediacoreEventTarget.h>
39 #include <sbITranscodeAlbumArt.h>
58 #include <nsArrayUtils.h>
59 #include <nsIBufferedStreams.h>
61 #include <nsIFileURL.h>
62 #include <nsIIOService.h>
63 #include <nsILocalFile.h>
64 #include <nsIProxyObjectManager.h>
65 #include <nsISimpleEnumerator.h>
66 #include <nsIStringEnumerator.h>
68 #include <nsIDOMWindow.h>
69 #include <nsIWindowWatcher.h>
70 #include <nsNetUtil.h>
71 #include <nsThreadUtils.h>
72 #include <nsComponentManagerUtils.h>
74 #define SB_CD_DEVICE_AUTO_INVOKE(aName, aMethod) \
75 SB_AUTO_NULL_CLASS(aName, sbCDDevice*, mValue->aMethod)
90 mValue->UnignoreMediaItem(mValue2),
103 : mCDDevice(aCDDevice)
108 PRBool isLocked = PR_FALSE;
109 rv = mCDDevice->GetIsDeviceLocked(&isLocked);
110 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
111 "Could not get the device lock state!");
114 rv = mCDDevice->LockDevice();
115 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not lock the cd device!");
130 PRBool isLocked = PR_FALSE;
131 rv = mCDDevice->GetIsDeviceLocked(&isLocked);
132 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
133 "Could not get the device lock state!");
136 rv = mCDDevice->UnlockDevice();
137 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not lock the cd device!");
143 nsCOMPtr<sbICDDevice> mCDDevice;
149 sbCDDevice::InitRequestHandler()
155 sbCDDevice::ProcessBatch(Batch & aBatch)
159 NS_ENSURE_TRUE(
mConnected, NS_ERROR_NOT_AVAILABLE);
172 NS_ENSURE_SUCCESS(rv, rv);
185 PRBool isDeviceLocked = PR_FALSE;
186 rv = mCDDevice->GetIsDeviceLocked(&isDeviceLocked);
187 NS_ENSURE_SUCCESS(rv, rv);
188 if (isDeviceLocked) {
189 rv = mCDDevice->UnlockDevice();
190 NS_ENSURE_SUCCESS(rv, rv);
194 mTranscodeProfile = nsnull;
198 TransferRequest * requestItem =
static_cast<TransferRequest*
>(*iter);
199 const PRUint32 type = requestItem->GetType();
203 LOG(
"sbCDDevice::ReqHandleRequestAdded 0x%08x\n", type);
208 rv = ReqHandleMount(requestItem);
209 NS_ENSURE_SUCCESS(rv, rv);
215 rv = ReqHandleRead(requestItem, aBatch.CountableItems());
218 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
219 "Could not read a track off of disc!");
225 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not eject the CD!");
229 rv = AttemptCDLookup();
230 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not lookup CD data!");
234 rv = ReqHandleUpdate(requestItem);
235 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not update CD data!");
239 NS_WARNING(
"Unsupported request type.");
243 if (NS_SUCCEEDED(rv)) {
244 requestItem->SetIsProcessed(PR_TRUE);
252 PRBool isDeviceLocked = PR_FALSE;
253 rv = mCDDevice->GetIsDeviceLocked(&isDeviceLocked);
254 NS_ENSURE_SUCCESS(rv, rv);
255 if (isDeviceLocked) {
256 rv = mCDDevice->UnlockDevice();
257 NS_ENSURE_SUCCESS(rv, rv);
264 mTranscodeProfile = nsnull;
272 sbCDDevice::ReqHandleMount(TransferRequest* aRequest)
275 NS_ENSURE_ARG_POINTER(aRequest);
281 LOG(
"Enter sbCDDevice::ReqHandleMount \n");
286 TransferRequest * request = static_cast<TransferRequest*>(aRequest);
299 NS_ENSURE_SUCCESS(rv, rv);
303 rv = volume->GetStatistics(getter_AddRefs(deviceStatistics));
304 NS_ENSURE_SUCCESS(rv, rv);
307 rv = UpdateDeviceLibrary(mDeviceLibrary);
308 NS_ENSURE_SUCCESS(rv, rv);
311 rv = deviceStatistics->
AddLibrary(mDeviceLibrary);
312 NS_ENSURE_SUCCESS(rv, rv);
315 nsAutoString cdDiscHash;
316 rv = GetCDDiscHash(mCDDevice, cdDiscHash);
317 NS_ENSURE_SUCCESS(rv, rv);
320 NS_ENSURE_SUCCESS(rv, rv);
323 autoStatus.SetResult(
NS_OK);
326 autoDisconnect.forget();
341 NS_ENSURE_ARG_POINTER(aLibrary);
350 (AutoIgnoreLibraryListener,
353 (AutoIgnoreMediaListListeners,
357 nsAutoString cdDiscHash;
358 rv = GetCDDiscHash(mCDDevice, cdDiscHash);
359 NS_ENSURE_SUCCESS(rv, rv);
362 nsAutoString prevCDDiscHash;
363 rv = aLibrary->
GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CDDISCHASH),
365 if (rv == NS_ERROR_NOT_AVAILABLE) {
366 prevCDDiscHash.Truncate();
369 NS_ENSURE_SUCCESS(rv, rv);
373 if (cdDiscHash.Equals(prevCDDiscHash)) {
374 nsAutoString albumName;
377 if (NS_SUCCEEDED(rv) && !albumName.IsEmpty()) {
378 rv = mProperties->SetFriendlyName(albumName);
379 NS_ENSURE_SUCCESS(rv, rv);
382 rv = mProperties->SetFriendlyName
384 NS_ENSURE_SUCCESS(rv, rv);
394 NS_LITERAL_STRING(
"0"));
395 NS_ENSURE_SUCCESS(rv, rv);
398 nsCOMPtr<nsIArray> newFileURIList;
399 rv = GetMediaFiles(getter_AddRefs(newFileURIList));
400 NS_ENSURE_SUCCESS(rv, rv);
403 nsCOMPtr<nsIArray> newPropsArray;
404 rv = GetMediaProperties(getter_AddRefs(newPropsArray));
405 NS_ENSURE_SUCCESS(rv, rv);
410 rv = mDeviceLibrary->Clear();
411 NS_ENSURE_SUCCESS(rv, rv);
414 nsCOMPtr<nsIArray> mediaItemList;
415 rv = mDeviceLibrary->BatchCreateMediaItems(newFileURIList,
418 getter_AddRefs(mediaItemList));
419 NS_ENSURE_SUCCESS(rv, rv);
422 PRUint32 mediaItemCount;
423 rv = mediaItemList->GetLength(&mediaItemCount);
424 NS_ENSURE_SUCCESS(rv, rv);
429 NS_ENSURE_SUCCESS(rv, rv);
430 nsString deviceLibraryGuid;
431 rv = mDeviceLibrary->GetGuid(deviceLibraryGuid);
432 NS_ENSURE_SUCCESS(rv, rv);
433 deviceLibraryGuid.AppendLiteral(
".needsLookup");
434 prefBranch.SetBoolPref(NS_ConvertUTF16toUTF8(deviceLibraryGuid).
get(),
441 sbCDDevice::GetMediaFiles(nsIArray ** aURIList)
445 nsCOMPtr<nsIMutableArray> list =
446 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1",
448 NS_ENSURE_SUCCESS(rv, rv);
450 nsCOMPtr<sbICDTOC> toc;
451 rv = mCDDevice->GetDiscTOC(getter_AddRefs(toc));
452 NS_ENSURE_SUCCESS(rv, rv);
458 nsCOMPtr<nsIArray> tracks;
459 rv = toc->GetTracks(getter_AddRefs(tracks));
460 NS_ENSURE_SUCCESS(rv, rv);
462 nsCOMPtr<nsIIOService> ioservice =
464 NS_ENSURE_SUCCESS(rv, rv);
466 nsCOMPtr<sbICDTOCEntry>
entry;
469 rv = tracks->GetLength(&length);
470 NS_ENSURE_SUCCESS(rv, rv);
472 for (PRUint32 index = 0; index < length; ++index) {
474 entry = do_QueryElementAt(tracks, index, &rv);
475 NS_ENSURE_SUCCESS(rv, rv);
478 PRInt16 curTrackMode;
479 rv = entry->GetTrackMode(&curTrackMode);
484 if (NS_SUCCEEDED(rv)) {
486 rv = entry->GetTrackURI(uriSpec);
487 NS_ENSURE_SUCCESS(rv, rv);
489 nsCOMPtr<nsIURI>
uri;
490 rv = ioservice->NewURI(NS_LossyConvertUTF16toASCII(uriSpec),
493 getter_AddRefs(uri));
494 NS_ENSURE_SUCCESS(rv, rv);
496 rv = list->AppendElement(uri, PR_FALSE);
497 NS_ENSURE_SUCCESS(rv, rv);
501 rv = CallQueryInterface(list, aURIList);
502 NS_ENSURE_SUCCESS(rv, rv);
508 sbCDDevice::GetMediaProperties(nsIArray ** aPropertyList)
512 nsCOMPtr<nsIMutableArray> newPropsArray =
514 NS_ENSURE_SUCCESS(rv, rv);
516 nsCOMPtr<sbICDTOC> toc;
517 rv = mCDDevice->GetDiscTOC(getter_AddRefs(toc));
518 NS_ENSURE_SUCCESS(rv, rv);
524 nsCOMPtr<nsIArray> tracks;
525 rv = toc->GetTracks(getter_AddRefs(tracks));
526 NS_ENSURE_SUCCESS(rv, rv);
528 nsCOMPtr<sbICDTOCEntry>
entry;
531 rv = tracks->GetLength(&length);
532 NS_ENSURE_SUCCESS(rv, rv);
534 for (PRUint32 index = 0; index < length; ++index) {
536 entry = do_QueryElementAt(tracks, index, &rv);
537 NS_ENSURE_SUCCESS(rv, rv);
540 rv = entry->GetTrackNumber(&trackNumber);
541 if (NS_SUCCEEDED(rv)) {
542 nsCOMPtr<sbIMutablePropertyArray> propList =
544 NS_ENSURE_SUCCESS(rv, rv);
548 NS_LITERAL_STRING(
"1"));
549 NS_ENSURE_SUCCESS(rv, rv);
552 nsAutoString trackNumberStr;
553 trackNumberStr.AppendInt(trackNumber+1);
556 NS_ENSURE_SUCCESS(rv, rv);
560 NS_LITERAL_STRING(
"2"));
561 NS_ENSURE_SUCCESS(rv, rv);
565 NS_LITERAL_STRING(
"44100"));
566 NS_ENSURE_SUCCESS(rv, rv);
570 rv = entry->GetLength(&duration);
571 NS_ENSURE_SUCCESS(rv, rv);
573 nsAutoString durationStr;
577 NS_ENSURE_SUCCESS(rv, rv);
579 newPropsArray->AppendElement(propList,
false);
583 rv = CallQueryInterface(newPropsArray, aPropertyList);
584 NS_ENSURE_SUCCESS(rv, rv);
590 sbCDDevice::ProxyCDLookup() {
595 NS_ENSURE_SUCCESS(rv, );
603 nsCOMPtr<sbIMetadataLookupManager> mlm =
604 do_GetService(
"@songbirdnest.com/Songbird/MetadataLookup/manager;1", &rv);
605 NS_ENSURE_SUCCESS(rv, );
607 nsCOMPtr<sbIMetadataLookupProvider> provider;
608 rv = mlm->GetDefaultProvider(getter_AddRefs(provider));
612 if (NS_FAILED(rv) || !provider) {
613 rv = CompleteCDLookup(nsnull);
614 NS_ENSURE_SUCCESS(rv, );
619 nsCOMPtr<sbICDTOC> toc;
620 rv = mCDDevice->GetDiscTOC(getter_AddRefs(toc));
621 NS_ENSURE_SUCCESS(rv, );
624 LOG(
"Querying metadata lookup provider for disc");
625 nsCOMPtr<sbIMetadataLookupJob> job;
626 rv = provider->QueryDisc(toc, getter_AddRefs(job));
627 if (NS_SUCCEEDED(rv) && job) {
632 rv = job->GetStatus(&jobStatus);
633 NS_ENSURE_SUCCESS(rv, );
637 rv = this->OnJobProgress(job);
638 NS_ENSURE_SUCCESS(rv, );
642 NS_ENSURE_SUCCESS(rv, );
648 rv = CompleteCDLookup(nsnull);
649 NS_ENSURE_SUCCESS(rv, );
654 sbCDDevice::ShowMetadataLookupDialog(
const char *aLookupDialogURI,
656 PRBool aShouldReportEvents)
658 NS_ENSURE_ARG_POINTER(aLookupDialogURI);
662 nsCOMPtr<nsIDOMWindow> parentWindow;
663 nsCOMPtr<nsIDOMWindow> domWindow;
664 nsCOMPtr<nsIWindowWatcher> windowWatcher =
666 NS_ENSURE_SUCCESS(rv, rv);
667 rv = windowWatcher->GetActiveWindow(getter_AddRefs(parentWindow));
668 NS_ENSURE_SUCCESS(rv, rv);
675 nsCOMPtr<nsIMutableArray>
args =
676 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
677 NS_ENSURE_SUCCESS(rv, rv);
680 rv = args->AppendElement(mDeviceLibrary, PR_FALSE);
681 NS_ENSURE_SUCCESS(rv, rv);
684 if (aLookupResultsEnum) {
685 rv = args->AppendElement(aLookupResultsEnum, PR_FALSE);
686 NS_ENSURE_SUCCESS(rv, rv);
691 rv = windowWatcher->OpenWindow(parentWindow,
694 "centerscreen,chrome,modal,titlebar=no,resizable=no,scrollbars=yes",
696 getter_AddRefs(domWindow));
697 NS_ENSURE_SUCCESS(rv, rv);
699 if (aShouldReportEvents) {
709 sbCDDevice::AttemptCDLookup()
713 if (!NS_IsMainThread()) {
714 nsCOMPtr<nsIThreadManager> threadMgr =
715 do_GetService(
"@mozilla.org/thread-manager;1", &rv);
716 NS_ENSURE_SUCCESS(rv, rv);
718 nsCOMPtr<nsIThread> mainThread;
719 rv = threadMgr->GetMainThread(getter_AddRefs(mainThread));
720 NS_ENSURE_SUCCESS(rv, rv);
722 nsCOMPtr<nsIRunnable> runnable =
723 NS_NEW_RUNNABLE_METHOD(
sbCDDevice,
this, ProxyCDLookup);
724 NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE);
726 rv = mainThread->Dispatch(runnable, NS_DISPATCH_SYNC);
727 NS_ENSURE_SUCCESS(rv, rv);
743 PRUint16 numResults = 0;
744 nsCOMPtr<nsISimpleEnumerator> metadataResultsEnum;
746 aJob->RemoveJobProgressListener(
this);
748 nsCOMPtr<sbIMetadataLookupJob> metalookupJob = do_QueryInterface(aJob, &rv);
749 NS_ENSURE_SUCCESS(rv, rv);
751 rv = metalookupJob->GetMlNumResults(&numResults);
752 NS_ENSURE_SUCCESS(rv, rv);
754 rv = metalookupJob->GetMetadataResults(getter_AddRefs(metadataResultsEnum));
755 NS_ENSURE_SUCCESS(rv, rv);
762 LOG(
"Number of metadata lookup results found: %d", numResults);
764 if (numResults == 1) {
771 rv = metadataResultsEnum->HasMoreElements(&hasMore);
772 NS_ENSURE_SUCCESS(rv, rv);
773 NS_ENSURE_TRUE(hasMore, NS_ERROR_UNEXPECTED);
775 nsCOMPtr<nsISupports> curItem;
776 rv = metadataResultsEnum->GetNext(getter_AddRefs(curItem));
777 NS_ENSURE_SUCCESS(rv, rv);
779 nsCOMPtr<sbIMetadataAlbumDetail> albumDetail =
780 do_QueryInterface(curItem, &rv);
781 NS_ENSURE_SUCCESS(rv, rv);
784 nsCOMPtr<sbIMutablePropertyArray> albumProperties;
785 rv = albumDetail->GetProperties(getter_AddRefs(albumProperties));
786 NS_ENSURE_SUCCESS(rv, rv);
789 rv = albumProperties->GetPropertyValue(
791 NS_ENSURE_SUCCESS(rv, rv);
795 NS_ENSURE_SUCCESS(rv, rv);
797 rv = mProperties->SetFriendlyName(albumName);
798 NS_ENSURE_SUCCESS(rv, rv);
800 nsCOMPtr<nsIArray> trackPropResults;
801 rv = albumDetail->GetTracks(getter_AddRefs(trackPropResults));
802 NS_ENSURE_SUCCESS(rv, rv);
805 rv = trackPropResults->GetLength(&length);
806 NS_ENSURE_SUCCESS(rv, rv);
808 for (PRUint32
i = 0;
i < length;
i++) {
809 nsCOMPtr<sbIMutablePropertyArray> curTrackPropArray =
810 do_QueryElementAt(trackPropResults,
i, &rv);
811 NS_ENSURE_SUCCESS(rv, rv);
813 PRUint32 propCount = 0;
814 rv = curTrackPropArray->GetLength(&propCount);
815 if (NS_FAILED(rv) || propCount == 0) {
822 indexStr.AppendInt(
i+1);
823 nsCOMPtr<nsIArray> tracks;
824 rv = mDeviceLibrary->GetItemsByProperty(NS_LITERAL_STRING(
827 getter_AddRefs(tracks));
834 rv = tracks->GetLength(&length);
835 NS_ENSURE_SUCCESS(rv, rv);
836 NS_ASSERTION(length == 1,
837 "More than one track in the device library with same #");
840 nsCOMPtr<sbIMediaItem> curLibraryItem = do_QueryElementAt(tracks, 0, &rv);
841 NS_ENSURE_SUCCESS(rv, rv);
843 rv = curLibraryItem->SetProperties(curTrackPropArray);
844 NS_ENSURE_SUCCESS(rv, rv);
848 rv = ShowMetadataLookupDialog(
852 aJob ? PR_FALSE : PR_TRUE);
853 NS_ENSURE_SUCCESS(rv, rv);
858 nsAutoString albumName;
859 PRBool albumNameUnknown = PR_FALSE;
862 if ((rv == NS_ERROR_NOT_AVAILABLE) || albumName.IsEmpty()) {
863 albumNameUnknown = PR_TRUE;
864 rv = mProperties->SetFriendlyName
866 NS_ENSURE_SUCCESS(rv, rv);
869 NS_ENSURE_SUCCESS(rv, rv);
873 if (!albumNameUnknown) {
874 nsCOMPtr<sbIAlbumArtScanner> artworkScanner =
875 do_CreateInstance(
"@songbirdnest.com/Songbird/album-art/scanner;1", &rv);
876 NS_ENSURE_SUCCESS(rv, rv);
879 rv = artworkScanner->SetUpdateArtwork(PR_TRUE);
880 NS_ENSURE_SUCCESS(rv, rv);
882 rv = artworkScanner->ScanListForArtwork(mDeviceLibrary);
883 NS_ENSURE_SUCCESS(rv, rv);
895 sbCDDevice::ReqHandleUpdate(TransferRequest * aRequest)
900 nsCOMPtr<sbILibrary> library = do_QueryInterface(aRequest->item);
905 nsAutoString albumName;
908 if (NS_SUCCEEDED(rv) && !albumName.IsEmpty()) {
909 rv = mProperties->SetFriendlyName(albumName);
910 NS_ENSURE_SUCCESS(rv, rv);
923 NS_ENSURE_ARG_POINTER(aJob);
927 rv = aJob->GetStatus(&jobStatus);
928 NS_ENSURE_SUCCESS(rv, rv);
935 rv = CompleteCDLookup(aJob);
936 NS_ENSURE_SUCCESS(rv, rv);
943 nsACString & aOutFilename)
945 NS_ENSURE_ARG_POINTER(aItem);
951 nsString trackNumProp;
954 NS_ENSURE_SUCCESS(rv, rv);
957 if (trackNumProp.Length() == 1) {
958 trackNumProp.Insert(NS_LITERAL_STRING(
"0"), 0);
961 nsString trackNameProp;
964 NS_ENSURE_SUCCESS(rv, rv);
966 aOutFilename.Append(NS_ConvertUTF16toUTF8(trackNumProp));
967 aOutFilename.AppendLiteral(
" - ");
968 aOutFilename.Append(NS_ConvertUTF16toUTF8(trackNameProp));
971 aOutFilename.StripChars(FILE_ILLEGAL_CHARACTERS);
973 aOutFilename.StripChars(FILE_PATH_SEPARATOR);
976 aOutFilename.Trim(
" .", PR_TRUE, PR_TRUE);
981 aOutFilename.AppendLiteral(
".cdda");
987 sbCDDevice::ReqHandleRead(TransferRequest * aRequest, PRUint32 aBatchCount)
989 NS_ENSURE_ARG_POINTER(aRequest);
991 LOG(
"Enter sbMSCDeviceBase::ReqHandleRead\n");
1004 nsCOMPtr<sbIMediaItem> source = do_QueryInterface(aRequest->data, &rv);
1005 NS_ENSURE_SUCCESS(rv, rv);
1011 NS_ENSURE_SUCCESS(rv, rv);
1024 if (!mTranscodeProfile)
1028 getter_AddRefs(mTranscodeProfile));
1029 NS_ENSURE_SUCCESS(rv, rv);
1035 mTranscodeBitrateStr.Truncate();
1036 nsCOMPtr<nsIVariant> bitrateVariant;
1038 NS_LITERAL_STRING(
"bitrate"),
1039 getter_AddRefs(bitrateVariant));
1040 if (NS_SUCCEEDED(rv) && bitrateVariant) {
1042 rv = bitrateVariant->GetAsUint32(&bitrate);
1043 if (NS_SUCCEEDED(rv))
1044 mTranscodeBitrateStr.AppendInt(bitrate/1000);
1048 if (!mTranscodeBitrateStr.IsEmpty()) {
1050 mTranscodeBitrateStr);
1053 nsCOMPtr<nsIURI> sourceContentURI;
1054 rv = source->GetContentSrc(getter_AddRefs(sourceContentURI));
1055 NS_ENSURE_SUCCESS(rv, rv);
1058 nsCOMPtr<nsIURI> musicFolderURI;
1060 NS_ENSURE_SUCCESS(rv, rv);
1062 nsCOMPtr<nsIURL> musicFolderURL = do_QueryInterface(musicFolderURI, &rv);
1063 NS_ENSURE_SUCCESS(rv, rv);
1065 nsCString extension;
1067 NS_ENSURE_SUCCESS(rv, rv);
1069 musicFolderURL->SetFileExtension(extension);
1072 nsCOMPtr<nsIFile> mediaFile;
1074 getter_AddRefs(mediaFile),
1075 getter_AddRefs(musicFolderURI));
1076 NS_ENSURE_SUCCESS(rv, rv);
1077 sbAutoRemoveFile autoRemoveMediaFile(mediaFile);
1082 sbCDAutoIgnoreItem autoUnignore(
this, destination);
1085 nsCOMPtr<nsIURI> contentURI;
1087 getter_AddRefs(contentURI));
1088 rv = destination->SetContentSrc(contentURI);
1089 NS_ENSURE_SUCCESS(rv, rv);
1092 nsCOMPtr<sbITranscodeJob> tcJob = do_CreateInstance(
1093 "@songbirdnest.com/Songbird/Mediacore/Transcode/GStreamer;1", &rv);
1094 NS_ENSURE_SUCCESS(rv, rv);
1096 nsCOMPtr<nsIThread>
target;
1097 rv = NS_GetMainThread(getter_AddRefs(target));
1098 NS_ENSURE_SUCCESS(rv, rv);
1100 nsCOMPtr<sbITranscodeJob> proxiedJob;
1103 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
1104 getter_AddRefs(proxiedJob));
1105 NS_ENSURE_SUCCESS(rv, rv);
1107 rv = proxiedJob->SetProfile(mTranscodeProfile);
1108 NS_ENSURE_SUCCESS(rv, rv);
1111 rv = musicFolderURI->GetSpec(URISpec);
1112 NS_ENSURE_SUCCESS(rv, rv);
1115 nsRefPtr<sbAutoIgnoreWatchFolderPath> autoWFPathIgnore =
1117 NS_ENSURE_TRUE(autoWFPathIgnore, NS_ERROR_OUT_OF_MEMORY);
1119 nsCOMPtr<nsIFileURL> destFileURL =
1120 do_QueryInterface(musicFolderURI, &rv);
1121 NS_ENSURE_SUCCESS(rv, rv);
1123 nsCOMPtr<nsIFile> destFileSpec;
1124 rv = destFileURL->GetFile(getter_AddRefs(destFileSpec));
1125 NS_ENSURE_SUCCESS(rv, rv);
1127 nsString destFilePath;
1128 rv = destFileSpec->GetPath(destFilePath);
1129 NS_ENSURE_SUCCESS(rv, rv);
1131 rv = autoWFPathIgnore->Init(destFilePath);
1132 NS_ENSURE_SUCCESS(rv, rv);
1134 rv = proxiedJob->SetDestURI(NS_ConvertUTF8toUTF16(URISpec));
1135 NS_ENSURE_SUCCESS(rv, rv);
1137 rv = sourceContentURI->GetSpec(URISpec);
1138 NS_ENSURE_SUCCESS(rv, rv);
1140 rv = proxiedJob->SetSourceURI(NS_ConvertUTF8toUTF16(URISpec));
1141 NS_ENSURE_SUCCESS(rv, rv);
1144 nsCOMPtr<sbIPropertyArray> metadata;
1145 rv = aRequest->item->GetProperties(nsnull, getter_AddRefs(metadata));
1146 NS_ENSURE_SUCCESS(rv, rv);
1148 rv = proxiedJob->SetMetadata(metadata);
1149 NS_ENSURE_SUCCESS(rv, rv);
1151 nsCOMPtr<sbITranscodeAlbumArt> albumArt = do_CreateInstance(
1153 NS_ENSURE_SUCCESS(rv, rv);
1155 nsCOMPtr<nsIArray> imageFormats = do_CreateInstance(
1157 NS_ENSURE_SUCCESS(rv, rv);
1164 rv = albumArt->Init(aRequest->item, imageFormats);
1165 if (NS_SUCCEEDED(rv)) {
1166 nsCOMPtr<nsIInputStream> imageStream;
1167 rv = albumArt->GetTranscodedArt(getter_AddRefs(imageStream));
1168 if (imageStream && NS_SUCCEEDED(rv)) {
1169 rv = proxiedJob->SetMetadataImage(imageStream);
1171 NS_WARNING(
"Setting metadata image failed");
1177 StatusProperty statusProperty(source,
1180 nsCOMPtr<sbIJobCancelable> cancel = do_QueryInterface(proxiedJob);
1182 PRMonitor *
const stopWaitMonitor =
1186 nsRefPtr<sbTranscodeProgressListener>
listener =
1193 NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY);
1196 nsCOMPtr<sbIJobProgress> progress = do_QueryInterface(proxiedJob, &rv);
1197 NS_ENSURE_SUCCESS(rv, rv);
1198 rv = progress->AddJobProgressListener(listener);
1199 NS_ENSURE_SUCCESS(rv, rv);
1202 nsCOMPtr<sbIMediacoreEventTarget>
eventTarget = do_QueryInterface(proxiedJob,
1204 NS_ENSURE_SUCCESS(rv, rv);
1205 rv = eventTarget->AddListener(listener);
1206 NS_ENSURE_SUCCESS(rv, rv);
1209 rv = proxiedJob->Transcode();
1210 NS_ENSURE_SUCCESS(rv, rv);
1213 PRBool isComplete = PR_FALSE;
1214 while (!isComplete) {
1216 nsAutoMonitor monitor(stopWaitMonitor);
1219 isComplete = listener->IsComplete();
1226 if (listener->IsAborted()) {
1227 autoComplete.SetResult(NS_OK);
1234 rv = progress->GetStatus(&status);
1235 NS_ENSURE_SUCCESS(rv, rv);
1241 nsCOMPtr<nsIStringEnumerator> errorMessageEnum;
1242 rv = progress->GetErrorMessages(getter_AddRefs(errorMessageEnum));
1245 if (NS_SUCCEEDED(rv)) {
1247 rv = errorMessageEnum->HasMore(&hasMore);
1252 nsAutoString errorMessage;
1253 rv = errorMessageEnum->GetNext(errorMessage);
1258 LOG(
"sbCDDevice::ReqTranscodeWrite error %s\n",
1259 NS_ConvertUTF16toUTF8(errorMessage).
get());
1262 rv = errorMessageEnum->HasMore(&hasMore);
1276 NS_LITERAL_STRING(
"0"));
1277 NS_ENSURE_SUCCESS(rv, rv);
1280 autoRemoveMediaFile.forget();
1282 autoComplete.SetResult(NS_OK);
1286 rv = NS_ERROR_FAILURE;
1289 const PRUint32 batchIndex = aRequest->GetBatchIndex() + 1;
1293 if (batchIndex == aBatchCount) {
1295 mTranscodeProfile = nsnull;
1297 rv2 = HandleRipEnd();
1298 NS_ENSURE_SUCCESS(rv2, rv2);
const unsigned long EVENT_CDLOOKUP_METADATA_COMPLETE
static nsresult GetTranscodedFileExtension(sbITranscodeProfile *aProfile, nsCString &aExtension)
#define SB_PROPERTY_SHOULDRIP
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
#define SB_PRLOG_SETUP(x)
#define SB_PROPERTY_CDRIP_STATUS
SB_AUTO_CLASS2(sbCDAutoIgnoreItem, sbCDDevice *, sbIMediaItem *, mValue!=nsnull, mValue->UnignoreMediaItem(mValue2), mValue=nsnull)
const unsigned long REQUEST_CDLOOKUP
static nsresult GetContentLength(sbIMediaItem *aItem, PRInt64 *_retval=nsnull)
nsAutoPtr< sbDeviceStatusHelper > mStatus
#define SB_PROPERTY_ORIGINLIBRARYGUID
#define SB_PROPERTY_SAMPLERATE
#define MULTI_CD_INFO_FOUND_DIALOG_URI
#define SB_PROPERTY_CHANNELS
nsRefPtr< sbDeviceRequestThreadQueue > mRequestThreadQueue
#define PREF_CDDEVICE_AUTOEJECT
static nsresult BulkSetProperty(sbIMediaList *aMediaList, const nsAString &aPropertyId, const nsAString &aPropertyValue, sbIPropertyArray *aPropertyFilter=nsnull, PRInt32 *aAbortFlag=nsnull)
const unsigned long EVENT_CDLOOKUP_COMPLETED
Generic interface for exposing long running jobs to the UI.
#define SB_THREADSAFE_ARRAY_CONTRACTID
#define SB_CD_DEVICE_AUTO_INVOKE(aName, aMethod)
#define SB_PROPERTY_HIDDEN
const unsigned long TRANSCODE_TYPE_AUDIO
const unsigned short STATUS_SUCCEEDED
Constant indicating that the job has completed.
nsresult do_GetProxyForObject(nsIEventTarget *aTarget, REFNSIID aIID, nsISupports *aObj, PRInt32 aProxyType, void **aProxyObject)
Songbird Variant Utility Definitions.
static nsresult GetContentURI(nsIURI *aURI, nsIURI **_retval, nsIIOService *aIOService=nsnull)
Return a library content URI for the URI specified by aURI. A library content URI is a specially form...
#define NO_CD_INFO_FOUND_DIALOG_URI
#define SB_PROPERTY_BITRATE
nsString GetValue() const
sbDeviceTranscoding * GetDeviceTranscoding() const
const unsigned short STATUS_RUNNING
Constant indicating that the job is active.
nsresult GetDeviceTranscodingProperty(PRUint32 aTranscodeType, const nsAString &aPropertyName, nsIVariant **aPropertyValue)
#define PREF_CDDEVICE_RIPBRANCH
#define SONGBIRD_TRANSCODEALBUMART_CONTRACTID
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)
RequestItems::const_iterator const_iterator
nsresult RegenerateMediaURL(sbIMediaItem *aItem, nsIURI **_retval)
#define SB_PROPERTY_CDDISCHASH
static nsresult GetProperty(nsIPropertyBag2 *aProperties, nsAString const &aProp, nsAString &aValue)
#define SB_PROPERTY_DURATION
const unsigned long STATE_IDLE
SB_AUTO_NULL_CLASS(sbCDAutoFalse, PRBool *,*mValue=PR_FALSE)
#define PREF_CDDEVICE_NOTIFYSOUND
nsresult SetIgnoreMediaListListeners(PRBool aIgnoreListener)
const unsigned long STATE_MOUNTING
virtual ~sbCDAutoDeviceLocker()
const unsigned long STATE_TRANSCODE
const unsigned long STATE_LOOKINGUPCD
static sbTranscodeProgressListener * New(sbBaseDevice *aDeviceBase, sbDeviceStatusHelper *aDeviceStatusHelper, sbIMediaItem *aItem, PRMonitor *aCompleteNotifyMonitor=nsnull, StatusProperty const &aStatusProperty=StatusProperty(), sbIJobCancelable *aCancel=nsnull)
nsresult SetIgnoreLibraryListener(PRBool aIgnoreListener)
const unsigned short TRACKMODE_AUDIO
StringArrayEnumerator prototype hasMore
#define SB_PROPERTY_ALBUMNAME
nsresult CreateUniqueMediaFile(nsIURI *aFileURI, nsIFile **aUniqueFile, nsIURI **aUniqueFileURI)
Songbird Device Status Services Definitions.
Implemented to receive notifications from sbIJobProgress interfaces.
const unsigned long EVENT_CDLOOKUP_INITIATED
#define SB_PROPERTY_TRACKNAME
nsresult GetVolumeForItem(sbIMediaItem *aItem, sbBaseDeviceVolume **aVolume)
#define SB_PROPERTY_AVAILABILITY
const unsigned short STATUS_FAILED
Constant indicating that the job has completed with errors.
#define SB_PROPERTY_ORIGINITEMGUID
_getSelectedPageStyle s i
sbCDAutoDeviceLocker(sbICDDevice *aCDDevice)
virtual PRBool IsRequestAborted()
nsresult SelectTranscodeProfile(PRUint32 aTranscodeType, sbITranscodeProfile **aProfile)
Select a transcode profile to use when transcoding to this device.
#define SB_PROPERTY_TRACKNUMBER
nsresult AddLibrary(sbIDeviceLibrary *aDevLib)