sbDeviceUtils.cpp
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2010 POTI, Inc.
8  * http://www.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 #include "sbDeviceUtils.h"
27 
28 #include <algorithm>
29 
30 #include <nsAlgorithm.h>
31 #include <nsArrayUtils.h>
32 #include <nsAutoPtr.h>
33 #include <nsCOMPtr.h>
34 #include <nsCRT.h>
35 #include <nsComponentManagerUtils.h>
36 #include <nsIDOMWindow.h>
37 #include <nsIDialogParamBlock.h>
38 #include <nsIMutableArray.h>
39 #include <nsIFile.h>
40 #include <nsISimpleEnumerator.h>
41 #include <nsIStandardURL.h>
42 #include <nsISupportsArray.h>
43 #include <nsIURI.h>
44 #include <nsIURL.h>
45 #include <nsIWindowWatcher.h>
46 #include <nsNetCID.h>
47 #include <nsThreadUtils.h>
48 
49 #include "sbBaseDevice.h"
51 #include "sbIDeviceCapabilities.h"
52 #include "sbIDeviceContent.h"
53 #include "sbIDeviceErrorMonitor.h"
54 #include "sbIDeviceHelper.h"
55 #include "sbIDeviceLibrary.h"
56 #include "sbIDeviceLibraryMediaSyncSettings.h"
57 #include "sbIDeviceLibrarySyncSettings.h"
58 #include "sbIDeviceRegistrar.h"
59 #include "sbIMediaItem.h"
60 #include <sbIMediaItemDownloader.h>
61 #include <sbIMediaItemDownloadService.h>
62 #include "sbIMediaList.h"
63 #include "sbIMediaListListener.h"
64 #include <sbITranscodeProfile.h>
65 #include <sbITranscodeManager.h>
66 #include <sbIPrompter.h>
67 #include "sbIWindowWatcher.h"
68 #include "sbLibraryUtils.h"
69 #include <sbPrefBranch.h>
71 #include "sbStandardProperties.h"
72 #include "sbStringUtils.h"
73 #include <sbVariantUtils.h>
75 #include <sbMemoryUtils.h>
76 #include <sbArray.h>
77 #include <sbIMediaInspector.h>
78 
79 #ifdef PR_LOGGING
80 static PRLogModuleInfo* gDeviceUtilsLog = NULL;
81 #define LOG(args) \
82  PR_BEGIN_MACRO \
83  if (!gDeviceUtilsLog) \
84  gDeviceUtilsLog = PR_NewLogModule("sbDeviceUtils"); \
85  PR_LOG(gDeviceUtilsLog, PR_LOG_WARN, args); \
86  PR_END_MACRO
87 #define TRACE(args) \
88  PR_BEGIN_MACRO \
89  if (!gDeviceUtilsLog) \
90  gDeviceUtilsLog = PR_NewLogModule("sbDeviceUtils"); \
91  PR_LOG(gDeviceUtilsLog, PR_LOG_DEBUG, args); \
92  PR_END_MACRO
93 #else
94 #define LOG(args) PR_BEGIN_MACRO /* nothing */ PR_END_MACRO
95 #define TRACE(args) PR_BEGIN_MACRO /* nothing */ PR_END_MACRO
96 #endif
97 
99 {
100 public:
102  NS_DECL_SBICALLWITHWINDOWCALLBACK
103 
104  nsresult Query(sbIDevice* aDevice,
105  sbIDeviceLibrary* aLibrary,
106  PRInt64 aSpaceNeeded,
107  PRInt64 aSpaceAvailable,
108  PRBool* aAbort);
109 
110 private:
111  nsCOMPtr<sbIDevice> mDevice;
112  nsCOMPtr<sbIDeviceLibrary> mLibrary;
113  PRBool mSync;
114  PRInt64 mSpaceNeeded;
115  PRInt64 mSpaceAvailable;
116  PRBool* mAbort;
117 };
118 
119 /*static*/
120 nsresult sbDeviceUtils::GetOrganizedPath(/* in */ nsIFile *aParent,
121  /* in */ sbIMediaItem *aItem,
122  nsIFile **_retval)
123 {
124  NS_ENSURE_ARG_POINTER(aParent);
125  NS_ENSURE_ARG_POINTER(aItem);
126  NS_ENSURE_ARG_POINTER(_retval);
127 
128  nsresult rv;
129 
130  nsString kIllegalChars = NS_ConvertASCIItoUTF16(FILE_ILLEGAL_CHARACTERS);
131  kIllegalChars.AppendLiteral(FILE_PATH_SEPARATOR);
132 
133  nsCOMPtr<nsIFile> file;
134  rv = aParent->Clone(getter_AddRefs(file));
135 
136  nsString propValue;
137  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_ARTISTNAME),
138  propValue);
139  NS_ENSURE_SUCCESS(rv, rv);
140  if (!propValue.IsEmpty()) {
141  nsString_ReplaceChar(propValue, kIllegalChars, PRUnichar('_'));
142  rv = file->Append(propValue);
143  NS_ENSURE_SUCCESS(rv, rv);
144  }
145 
146  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_ALBUMNAME),
147  propValue);
148  NS_ENSURE_SUCCESS(rv, rv);
149  if (!propValue.IsEmpty()) {
150  nsString_ReplaceChar(propValue, kIllegalChars, PRUnichar('_'));
151  rv = file->Append(propValue);
152  NS_ENSURE_SUCCESS(rv, rv);
153  }
154 
155  nsCOMPtr<nsIURI> itemUri;
156  rv = aItem->GetContentSrc(getter_AddRefs(itemUri));
157  NS_ENSURE_SUCCESS(rv, rv);
158 
159  nsCOMPtr<nsIURL> itemUrl = do_QueryInterface(itemUri, &rv);
160  NS_ENSURE_SUCCESS(rv, rv);
161 
162  nsCString fileCName;
163  rv = itemUrl->GetFileName(fileCName);
164  NS_ENSURE_SUCCESS(rv, rv);
165 
166  nsString fileName = NS_ConvertUTF8toUTF16(fileCName);
167  nsString_ReplaceChar(fileName, kIllegalChars, PRUnichar('_'));
168  rv = file->Append(fileName);
169  NS_ENSURE_SUCCESS(rv, rv);
170 
171  file.swap(*_retval);
172 
173  return NS_OK;
174 }
175 
182 {
183 public:
185  const nsAString& aValue,
186  PRInt32 *aAbortFlag = nsnull)
187  : mId(aId),
188  mValue(aValue),
189  mAbortFlag(aAbortFlag)
190  {}
191 
193 
194  NS_IMETHODIMP OnEnumerationBegin(sbIMediaList *aMediaList, PRUint16 *_retval)
195  {
196  NS_ENSURE_ARG_POINTER(_retval);
197 
198  PRBool abortRequests = PR_FALSE;
199  if (mAbortFlag)
200  abortRequests = PR_AtomicAdd(mAbortFlag, 0);
201 
202  if (abortRequests) {
204  return NS_OK;
205  } else {
207  return NS_OK;
208  }
209  }
210 
211  NS_IMETHODIMP OnEnumeratedItem(sbIMediaList *aMediaList, sbIMediaItem *aItem,
212  PRUint16 *_retval)
213  {
214  NS_ENSURE_ARG_POINTER(aItem);
215  NS_ENSURE_ARG_POINTER(_retval);
216 
217  PRBool abortRequests = PR_FALSE;
218  if (mAbortFlag)
219  abortRequests = PR_AtomicAdd(mAbortFlag, 0);
220 
221  if (abortRequests) {
223  return NS_OK;
224  }
225 
226  nsresult rv = aItem->SetProperty(mId, mValue);
227  NS_ENSURE_SUCCESS(rv, rv);
228 
230 
231  return NS_OK;
232  }
233 
234  NS_IMETHODIMP OnEnumerationEnd(sbIMediaList *aMediaList, nsresult aStatusCode)
235  {
236  return NS_OK;
237  }
238 
239 protected:
240  nsString mId;
241  nsString mValue;
242  PRBool *mAbortFlag;
244 };
245 
248 
249 /*static*/
251  const nsAString& aPropertyId,
252  const nsAString& aPropertyValue,
253  sbIPropertyArray* aPropertyFilter,
254  PRInt32 *aAbortFlag)
255 {
256  NS_ENSURE_ARG_POINTER(aMediaList);
257 
258  nsRefPtr<sbDeviceUtilsBulkSetPropertyEnumerationListener> listener =
260  aPropertyValue,
261  aAbortFlag);
262  NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY);
263 
264  if (!aPropertyFilter) {
265  // set all items
266  return aMediaList->EnumerateAllItems(listener,
268  }
269 
270  // set some filtered set of items
271  return aMediaList->EnumerateItemsByProperties(aPropertyFilter,
272  listener,
274 }
275 
276 /*static*/
278  nsAString const & aProperty,
279  nsAString const & aValue)
280 {
281  nsresult rv;
282 
283  NS_ASSERTION(aMediaList, "Attempting to delete null media list");
284 
285  nsCOMPtr<nsIArray> array;
286  rv = aMediaList->GetItemsByProperty(aProperty,
287  aValue,
288  getter_AddRefs(array));
289  if (NS_SUCCEEDED(rv)) {
290 
291  nsCOMPtr<nsISimpleEnumerator> enumerator;
292  rv = array->Enumerate(getter_AddRefs(enumerator));
293  NS_ENSURE_SUCCESS(rv, rv);
294 
295  return aMediaList->RemoveSome(enumerator);
296  }
297  // No items is not an error
298  else if (rv == NS_ERROR_NOT_AVAILABLE) {
299  return NS_OK;
300  }
301  // Return failure of GetItemsByProperty
302  return rv;
303 }
304 
305 /*static*/
307 {
308  return sbDeviceUtils::DeleteByProperty(aMediaList,
309  NS_LITERAL_STRING(SB_PROPERTY_AVAILABILITY),
310  NS_LITERAL_STRING("0"));
311 }
312 
313 /* static */
315  sbIMediaItem* aItem,
316  sbIDeviceLibrary** _retval)
317 {
318  NS_ASSERTION(aDevice, "Getting device library with no device");
319  NS_ASSERTION(aItem, "Getting device library for nothing");
320  NS_ASSERTION(_retval, "null retval");
321 
322  nsresult rv;
323 
324  nsCOMPtr<sbILibrary> ownerLibrary;
325  rv = aItem->GetLibrary(getter_AddRefs(ownerLibrary));
326  NS_ENSURE_SUCCESS(rv, rv);
327 
328  rv = GetDeviceLibraryForLibrary(aDevice, ownerLibrary, _retval);
329  NS_ENSURE_SUCCESS(rv, rv);
330 
331  return NS_OK;
332 }
333 
334 /* static */
336  const nsCString& aSpec,
337  nsIURI** aURI)
338 {
339  // Validate arguments.
340  NS_ENSURE_ARG_POINTER(aDeviceLibrary);
341  NS_ENSURE_ARG_POINTER(aURI);
342 
343  // Function variables.
344  nsresult rv;
345 
346  // Get the device.
347  nsCOMPtr<sbIDevice> device;
348  rv = aDeviceLibrary->GetDevice(getter_AddRefs(device));
349  NS_ENSURE_SUCCESS(rv, rv);
350 
351  // Get the device ID.
352  char deviceIDString[NSID_LENGTH];
353  sbAutoMemPtr<nsID> deviceID;
354  rv = device->GetId(deviceID.StartAssignment());
355  NS_ENSURE_SUCCESS(rv, rv);
356  deviceID->ToProvidedString(deviceIDString);
357 
358  // Get the device library GUID.
359  nsAutoString guid;
360  rv = aDeviceLibrary->GetGuid(guid);
361  NS_ENSURE_SUCCESS(rv, rv);
362 
363  // Produce the base URI spec.
364  nsCAutoString baseURISpec;
365  baseURISpec.Assign("x-device:///");
366  baseURISpec.Append(deviceIDString);
367  baseURISpec.Append("/");
368  baseURISpec.Append(NS_ConvertUTF16toUTF8(guid));
369  baseURISpec.Append("/");
370 
371  // Produce the base URI.
372  nsCOMPtr<nsIStandardURL>
373  baseStandardURL = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
374  NS_ENSURE_SUCCESS(rv, rv);
375  rv = baseStandardURL->Init(nsIStandardURL::URLTYPE_NO_AUTHORITY,
376  -1,
377  baseURISpec,
378  nsnull,
379  nsnull);
380  NS_ENSURE_SUCCESS(rv, rv);
381  nsCOMPtr<nsIURI> baseURI = do_QueryInterface(baseStandardURL, &rv);
382  NS_ENSURE_SUCCESS(rv, rv);
383 
384  // Produce the requested URI.
385  nsCOMPtr<nsIStandardURL>
386  standardURL = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
387  NS_ENSURE_SUCCESS(rv, rv);
388  rv = standardURL->Init(nsIStandardURL::URLTYPE_NO_AUTHORITY,
389  -1,
390  aSpec,
391  nsnull,
392  baseURI);
393  NS_ENSURE_SUCCESS(rv, rv);
394 
395  // Return results.
396  rv = CallQueryInterface(standardURL, aURI);
397  NS_ENSURE_SUCCESS(rv, rv);
398 
399  return NS_OK;
400 }
401 
402 /* static */
404  sbILibrary* aLibrary,
405  sbIDeviceLibrary** _retval)
406 {
407  NS_ASSERTION(aDevice, "Getting device library with no device");
408  NS_ASSERTION(aLibrary, "Getting device library for nothing");
409  NS_ASSERTION(_retval, "null retval");
410 
411  nsresult rv;
412 
413  // mediaItem.library is not a sbIDeviceLibrary, test GUID :(
414  nsCOMPtr<sbIDeviceContent> content;
415  rv = aDevice->GetContent(getter_AddRefs(content));
416  NS_ENSURE_SUCCESS(rv, rv);
417 
418  nsCOMPtr<nsIArray> libraries;
419  rv = content->GetLibraries(getter_AddRefs(libraries));
420  NS_ENSURE_SUCCESS(rv, rv);
421 
422  PRUint32 libraryCount;
423  rv = libraries->GetLength(&libraryCount);
424  NS_ENSURE_SUCCESS(rv, rv);
425 
426  for (PRUint32 index = 0; index < libraryCount; ++index) {
427  nsCOMPtr<sbIDeviceLibrary> deviceLib =
428  do_QueryElementAt(libraries, index, &rv);
429  if (NS_FAILED(rv))
430  continue;
431 
432  PRBool equalsLibrary;
433  rv = aLibrary->Equals(deviceLib, &equalsLibrary);
434  NS_ENSURE_SUCCESS(rv, rv);
435 
436  if (equalsLibrary) {
437  deviceLib.forget(_retval);
438  return NS_OK;
439  }
440  }
441 
442  *_retval = nsnull;
443  return NS_ERROR_FAILURE;
444 }
445 
446 /* static */
448  (sbILibrary* aLibrary,
449  const nsAString& aDevicePersistentId,
450  sbIMediaItem** aItem)
451 {
452  NS_ENSURE_ARG_POINTER(aLibrary);
453  NS_ENSURE_ARG_POINTER(aItem);
454 
455  nsresult rv;
456 
457  // get the library items with the device persistent ID
458  nsCOMPtr<nsIArray> mediaItemList;
459  rv = aLibrary->GetItemsByProperty
460  (NS_LITERAL_STRING(SB_PROPERTY_DEVICE_PERSISTENT_ID),
461  aDevicePersistentId,
462  getter_AddRefs(mediaItemList));
463  if (rv == NS_ERROR_NOT_AVAILABLE)
464  return NS_ERROR_NOT_AVAILABLE;
465  NS_ENSURE_SUCCESS(rv, rv);
466 
467  // Return the first item with an exactly matching persistent ID.
468  // GetItemsByProperty does not do an exact match (e.g., case insensitive,
469  // number strings limited to 64-bit float precision; see bug 15640).
470  PRUint32 length;
471  rv = mediaItemList->GetLength(&length);
472  NS_ENSURE_SUCCESS(rv, rv);
473  for (PRUint32 i = 0; i < length; i++) {
474  // get the next media item
475  nsCOMPtr<sbIMediaItem> mediaItem;
476  rv = mediaItemList->QueryElementAt(i,
477  NS_GET_IID(sbIMediaItem),
478  getter_AddRefs(mediaItem));
479  NS_ENSURE_SUCCESS(rv, rv);
480 
481  // check for an exact match
482  nsAutoString devicePersistentId;
483  rv = mediaItem->GetProperty
484  (NS_LITERAL_STRING(SB_PROPERTY_DEVICE_PERSISTENT_ID),
485  devicePersistentId);
486  NS_ENSURE_SUCCESS(rv, rv);
487  if (aDevicePersistentId.Equals(devicePersistentId)) {
488  mediaItem.forget(aItem);
489  return NS_OK;
490  }
491  }
492 
493  return NS_ERROR_NOT_AVAILABLE;
494 }
495 
496 /* static */
498  (sbILibrary* aLibrary,
499  const nsAString& aDevicePersistentId,
500  sbIMediaItem** aItem)
501 {
502  NS_ENSURE_ARG_POINTER(aLibrary);
503  NS_ENSURE_ARG_POINTER(aItem);
504 
505  nsresult rv;
506 
507  // get the device media item from the device persistent ID
508  nsCOMPtr<sbIMediaItem> deviceMediaItem;
509  rv = GetMediaItemByDevicePersistentId(aLibrary,
510  aDevicePersistentId,
511  getter_AddRefs(deviceMediaItem));
512  NS_ENSURE_SUCCESS(rv, rv);
513 
514  // get the original item from the device media item
515  rv = sbLibraryUtils::GetOriginItem(deviceMediaItem, aItem);
516  NS_ENSURE_SUCCESS(rv, rv);
517 
518  return NS_OK;
519 }
520 
521 /* static */
523  sbIMediaItem* aMediaItem,
524  PRUint64* aWriteLength)
525 {
526  // Validate arguments.
527  NS_ENSURE_ARG_POINTER(aMediaItem);
528  NS_ENSURE_ARG_POINTER(aWriteLength);
529 
530  // Function variables.
531  nsresult rv;
532 
533  // Get the download service to check if the media item needs to be downloaded.
534  // Even if the media item has a local content source file, a version that's
535  // compatible with the device may still need to be downloaded (e.g., for DRM
536  // purposes or for a compatible format).
537  nsCOMPtr<sbIMediaItemDownloadService> downloadService =
538  do_GetService("@songbirdnest.com/Songbird/MediaItemDownloadService;1", &rv);
539  NS_ENSURE_SUCCESS(rv, rv);
540 
541  // Get a downloader for the media item and target device library.
542  nsCOMPtr<sbIMediaItemDownloader> downloader;
543  rv = downloadService->GetDownloader(aMediaItem,
544  aDeviceLibrary,
545  getter_AddRefs(downloader));
546  NS_ENSURE_SUCCESS(rv, rv);
547 
548  // If a downloader was returned, the media item needs to be downloaded. Get
549  // the download size.
550  if (downloader) {
551  rv = downloader->GetDownloadSize(aMediaItem,
552  aDeviceLibrary,
553  aWriteLength);
554  NS_ENSURE_SUCCESS(rv, rv);
555  return NS_OK;
556  }
557 
558  // Try getting the content length directly from the media item.
559  PRInt64 contentLength;
560  rv = sbLibraryUtils::GetContentLength(aMediaItem, &contentLength);
561  NS_ENSURE_SUCCESS(rv, rv);
562  NS_ENSURE_TRUE(contentLength >= 0, NS_ERROR_FAILURE);
563 
564  // Return results.
565  *aWriteLength = static_cast<PRUint64>(contentLength);
566 
567  return NS_OK;
568 }
569 
570 /* static */
572  (/* in */ sbIDevice* aDevice,
573  /* in */ sbIDeviceLibrary* aLibrary,
574  /* in */ PRInt64 aSpaceNeeded,
575  /* in */ PRInt64 aSpaceAvailable,
576  /* out */ PRBool* aAbort)
577 {
578  NS_ENSURE_ARG_POINTER(aDevice);
579  NS_ENSURE_ARG_POINTER(aLibrary);
580  NS_ENSURE_ARG_POINTER(aAbort);
581 
582  nsresult rv;
583 
584  // create a query object and query the user
585  nsRefPtr<sbDeviceUtilsQueryUserSpaceExceeded> query;
587  NS_ENSURE_TRUE(query, NS_ERROR_OUT_OF_MEMORY);
588  rv = query->Query(aDevice, aLibrary, aSpaceNeeded, aSpaceAvailable, aAbort);
589  NS_ENSURE_SUCCESS(rv, rv);
590 
591  return NS_OK;
592 }
593 
594 /* static */
595 nsresult sbDeviceUtils::QueryUserAbortRip(PRBool* aAbort)
596 {
597  NS_ENSURE_ARG_POINTER(aAbort);
598 
599  nsresult rv;
600 
601  // By default assume the user says yes.
602  *aAbort = PR_TRUE;
603 
604  // Get a prompter that does not wait for a window.
605  nsCOMPtr<sbIPrompter> prompter =
606  do_CreateInstance(SONGBIRD_PROMPTER_CONTRACTID, &rv);
607  NS_ENSURE_SUCCESS(rv, rv);
608  rv = prompter->SetWaitForWindow(PR_FALSE);
609  NS_ENSURE_SUCCESS(rv, rv);
610 
611  // Get the prompt title.
612  nsAString const& title =
613  SBLocalizedString("device.dialog.cddevice.stopripping.title");
614 
615  // Get the prompt message.
616  nsAString const& message =
617  SBLocalizedString("device.dialog.cddevice.stopripping.msg");
618 
619  // Configure the buttons.
620  PRUint32 buttonFlags = nsIPromptService::STD_YES_NO_BUTTONS;
621 
622  // Query the user if they wish to cancel the rip or not.
623  PRInt32 buttonPressed;
624  rv = prompter->ConfirmEx(nsnull,
625  title.BeginReading(),
626  message.BeginReading(),
627  buttonFlags,
628  nsnull, // "Yes" Button
629  nsnull, // "No" Button
630  nsnull, // No button 2.
631  nsnull, // No check message.
632  nsnull, // No check result.
633  &buttonPressed);
634  NS_ENSURE_SUCCESS(rv, rv);
635 
636  // Yes = 0, No = 1
637  *aAbort = (buttonPressed == 0);
638 
639  return NS_OK;
640 }
641 
642 /* static */
644 {
645  NS_ENSURE_ARG_POINTER(aDevice);
646  nsresult rv;
647 
648  nsCOMPtr<sbIDeviceErrorMonitor> errMonitor =
649  do_GetService("@songbirdnest.com/device/error-monitor-service;1", &rv);
650  NS_ENSURE_SUCCESS(rv, rv);
651 
652  PRBool hasErrors;
653  rv = errMonitor->DeviceHasErrors(aDevice, EmptyString(), 0, &hasErrors);
654  NS_ENSURE_SUCCESS(rv, rv);
655 
656  if (hasErrors) {
657  // Query the user if they wish to see the errors
658 
659  // Get a prompter that does not wait for a window.
660  nsCOMPtr<sbIPrompter> prompter =
661  do_CreateInstance(SONGBIRD_PROMPTER_CONTRACTID, &rv);
662  NS_ENSURE_SUCCESS(rv, rv);
663  rv = prompter->SetWaitForWindow(PR_FALSE);
664  NS_ENSURE_SUCCESS(rv, rv);
665 
666  // Get the prompt title.
667  nsAString const& title =
668  SBLocalizedString("device.dialog.cddevice.viewerrors.title");
669 
670  // Get the prompt message.
671  nsAString const& message =
672  SBLocalizedString("device.dialog.cddevice.viewerrors.msg");
673 
674  // Configure the buttons.
675  PRUint32 buttonFlags = nsIPromptService::STD_YES_NO_BUTTONS;
676 
677  // Query the user if they wish to see the errors
678  PRInt32 buttonPressed;
679  rv = prompter->ConfirmEx(nsnull,
680  title.BeginReading(),
681  message.BeginReading(),
682  buttonFlags,
683  nsnull, // "Yes" Button
684  nsnull, // "No" Button
685  nsnull, // No button 2.
686  nsnull, // No check message.
687  nsnull, // No check result.
688  &buttonPressed);
689  NS_ENSURE_SUCCESS(rv, rv);
690 
691  if (buttonPressed == 0) {
692  ShowDeviceErrors(aDevice);
693  }
694  }
695 
696  return NS_OK;
697 }
698 
699 
700 /* static */
702 {
703  NS_ENSURE_ARG_POINTER(aDevice);
704 
705  nsresult rv;
706 
707  // We have to send an comglmeration of stuff into the OpenWindow to get
708  // all the parameters the dialog needs to display the errors.
709  // nsISupports = nsIDialogParamBlock =
710  // String[0] = "" Bank string for options.
711  // String[1] = "Ripping" Localized string for operation message.
712  // Objects = nsIMutableArray =
713  // [0] = sbIDevice
714  // [1] = nsIArray of nsISupportStrings for error messages.
715 
716  // Start with the DialogParamBlock and add strings/objects to it
717  nsCOMPtr<nsIDialogParamBlock> dialogBlock =
718  do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &rv);
719  NS_ENSURE_SUCCESS(rv, rv);
720 
721  // First add strings
722  // Options string
723  rv = dialogBlock->SetString(0, NS_LITERAL_STRING("").get());
724  NS_ENSURE_SUCCESS(rv, rv);
725  // Operation string
726  rv = dialogBlock->SetString(1, NS_LITERAL_STRING("ripping").get());
727  NS_ENSURE_SUCCESS(rv, rv);
728 
729  // Now add Objects (nsIMutableArray)
730  nsCOMPtr<nsIMutableArray> objects =
731  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
732  NS_ENSURE_SUCCESS(rv, rv);
733  // Append device
734  rv = objects->AppendElement(aDevice, PR_FALSE);
735  NS_ENSURE_SUCCESS(rv, rv);
736  // Append error strings
737  nsCOMPtr<sbIDeviceErrorMonitor> errMonitor =
738  do_GetService("@songbirdnest.com/device/error-monitor-service;1", &rv);
739  NS_ENSURE_SUCCESS(rv, rv);
740  nsCOMPtr<nsIArray> errorStrings;
741  rv = errMonitor->GetDeviceErrors(aDevice,
742  EmptyString(),
743  0,
744  getter_AddRefs(errorStrings));
745  NS_ENSURE_SUCCESS(rv, rv);
746  rv = objects->AppendElement(errorStrings, PR_FALSE);
747  NS_ENSURE_SUCCESS(rv, rv);
748  // Append the objects to the dialogBlock
749  rv = dialogBlock->SetObjects(objects);
750  NS_ENSURE_SUCCESS(rv, rv);
751 
752  // Convert the DialogParamBlock to an nsISuports
753  nsCOMPtr<nsISupports> arguments = do_QueryInterface(dialogBlock, &rv);
754  NS_ENSURE_SUCCESS(rv, rv);
755 
756  // Get a prompter that does not wait for a window.
757  nsCOMPtr<sbIPrompter> prompter =
758  do_CreateInstance(SONGBIRD_PROMPTER_CONTRACTID, &rv);
759  NS_ENSURE_SUCCESS(rv, rv);
760  rv = prompter->SetWaitForWindow(PR_FALSE);
761  NS_ENSURE_SUCCESS(rv, rv);
762 
763  // Display the dialog.
764  nsCOMPtr<nsIDOMWindow> dialogWindow;
765  rv = prompter->OpenDialog(nsnull, // Default to parent window
766  NS_LITERAL_STRING("chrome://songbird/content/xul/device/deviceErrorDialog.xul"),
767  NS_LITERAL_STRING("device_error_dialog"),
768  NS_LITERAL_STRING("chrome,centerscreen,model=yes,titlebar=no"),
769  arguments,
770  getter_AddRefs(dialogWindow));
771  NS_ENSURE_SUCCESS(rv, rv);
772 
773  return NS_OK;
774 }
775 
776 /* static */
778 {
779  // Validate arguments.
780  NS_ENSURE_ARG_POINTER(aDevice);
781 
782  // Function variables.
783  nsresult rv;
784 
785  // Get the device sync partner ID and determine if the device is linked to a
786  // sync partner.
787  PRBool deviceIsLinked;
788  nsCOMPtr<nsIVariant> deviceSyncPartnerIDVariant;
789  nsAutoString deviceSyncPartnerID;
790  rv = aDevice->GetPreference(NS_LITERAL_STRING("SyncPartner"),
791  getter_AddRefs(deviceSyncPartnerIDVariant));
792  if (NS_SUCCEEDED(rv)) {
793  rv = deviceSyncPartnerIDVariant->GetAsAString(deviceSyncPartnerID);
794  NS_ENSURE_SUCCESS(rv, rv);
795  deviceIsLinked = PR_TRUE;
796  } else {
797  deviceIsLinked = PR_FALSE;
798  }
799 
800  // Get the local sync partner ID.
801  nsAutoString localSyncPartnerID;
802  rv = GetMainLibraryId(localSyncPartnerID);
803  NS_ENSURE_SUCCESS(rv, rv);
804 
805  // Check if device is linked to local sync partner.
806  PRBool isLinkedLocally = PR_FALSE;
807  if (deviceIsLinked)
808  isLinkedLocally = deviceSyncPartnerID.Equals(localSyncPartnerID);
809 
810  // If device is not linked locally, set its sync partner.
811  if (!isLinkedLocally) {
812  rv = aDevice->SetPreference(NS_LITERAL_STRING("SyncPartner"),
813  sbNewVariant(localSyncPartnerID));
814  NS_ENSURE_SUCCESS(rv, rv);
815  }
816 
817  return NS_OK;
818 }
819 
820 SB_AUTO_CLASS(sbAutoNSMemoryPtr, void*, !!mValue, NS_Free(mValue), mValue = nsnull);
821 
823 {
824  nsCOMPtr<sbIDeviceCapabilities> capabilities;
825  nsresult rv = aDevice->GetCapabilities(getter_AddRefs(capabilities));
826  NS_ENSURE_SUCCESS(rv, false);
827 
828  bool supported = false;
829  PRUint32 * functionTypes;
830  PRUint32 functionTypesLength;
831  rv = capabilities->GetSupportedFunctionTypes(&functionTypesLength,
832  &functionTypes);
833  NS_ENSURE_SUCCESS(rv, false);
834  sbAutoNSMemoryPtr functionTypesPtr(functionTypes);
835  for (PRUint32 functionType = 0;
836  !supported && functionType < functionTypesLength;
837  ++functionType) {
838  PRUint32 * contentTypes;
839  PRUint32 contentTypesLength;
840  rv = capabilities->GetSupportedContentTypes(functionTypes[functionType],
841  &contentTypesLength,
842  &contentTypes);
843  NS_ENSURE_SUCCESS(rv, false);
844  sbAutoNSMemoryPtr contentTypesPtr(contentTypes);
845  PRUint32 * const end = contentTypes + contentTypesLength;
846  PRUint32 const CONTENT_PLAYLIST =
847  static_cast<PRUint32>(sbIDeviceCapabilities::CONTENT_PLAYLIST);
848  supported = std::find(contentTypes,
849  end,
850  CONTENT_PLAYLIST) != end;
851  }
852  return supported;
853 }
854 
855 //------------------------------------------------------------------------------
856 //
857 // sbDeviceUtilsQueryUserSpaceExceeded class.
858 //
859 //------------------------------------------------------------------------------
860 
863 
864 NS_IMETHODIMP
865 sbDeviceUtilsQueryUserSpaceExceeded::HandleWindowCallback(nsIDOMWindow* aWindow)
866 {
867  NS_ENSURE_ARG_POINTER(aWindow);
868 
869  nsresult rv;
870 
871  // get the device helper
872  nsCOMPtr<sbIDeviceHelper> deviceHelper =
873  do_GetService("@songbirdnest.com/Songbird/Device/Base/Helper;1", &rv);
874  NS_ENSURE_SUCCESS(rv, rv);
875 
876  // query the user
877  PRBool proceed;
878  rv = deviceHelper->QueryUserSpaceExceeded(aWindow,
879  mDevice,
880  mLibrary,
881  mSpaceNeeded,
882  mSpaceAvailable,
883  &proceed);
884  NS_ENSURE_SUCCESS(rv, rv);
885 
886  // return results
887  *mAbort = !proceed;
888 
889  return NS_OK;
890 }
891 
892 nsresult
894  sbIDeviceLibrary* aLibrary,
895  PRInt64 aSpaceNeeded,
896  PRInt64 aSpaceAvailable,
897  PRBool* aAbort)
898 {
899  nsresult rv;
900 
901  // get the query parameters
902  mDevice = aDevice;
903  mLibrary = aLibrary;
904  mSpaceNeeded = aSpaceNeeded;
905  mSpaceAvailable = aSpaceAvailable;
906  mAbort = aAbort;
907 
908  // wait to query user until a window is available
909  nsCOMPtr<sbIWindowWatcher> windowWatcher;
910  windowWatcher = do_GetService("@songbirdnest.com/Songbird/window-watcher;1",
911  &rv);
912  NS_ENSURE_SUCCESS(rv, rv);
913  rv = windowWatcher->CallWithWindow(NS_LITERAL_STRING("Songbird:Main"),
914  this,
915  PR_TRUE);
916  NS_ENSURE_SUCCESS(rv, rv);
917 
918  return NS_OK;
919 }
920 
921 /* For most of these, the file extension -> container format mapping is fairly
922  reliable, but the codecs can vary wildly. There is no way to do better
923  without actually looking inside the files. The codecs listed are usually the
924  most commonly found ones for this extension.
925  */
928  /* audio */
929  { "mp3", "audio/mpeg", "audio/mpeg", "audio/mpeg", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
930  { "wma", "audio/x-ms-wma", "video/x-ms-asf", "audio/x-ms-wma", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
931  { "aac", "audio/aac", "", "audio/aac", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
932  { "m4a", "audio/aac", "video/mp4", "audio/aac", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
933  { "3gp", "audio/aac", "video/3gpp", "audio/aac", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
934  { "aa", "audio/audible", "", "", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
935  { "aa", "audio/x-pn-audibleaudio", "", "", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
936  { "ogg", "application/ogg", "application/ogg", "audio/x-vorbis", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
937  { "oga", "application/ogg", "application/ogg", "audio/x-flac", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
938  { "flac", "audio/x-flac", "", "audio/x-flac", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
939  { "wav", "audio/x-wav", "audio/x-wav", "audio/x-pcm-int", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
940  { "wav", "audio/x-adpcm", "audio/x-wav", "audio/x-adpcm", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
941  { "aiff", "audio/x-aiff", "audio/x-aiff", "audio/x-pcm-int", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
942  { "aif", "audio/x-aiff", "audio/x-aiff", "audio/x-pcm-int", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
943  { "ape", "audio/x-ape", "", "", "", "", sbIDeviceCapabilities::CONTENT_AUDIO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO },
944 
945  /* video */
947  { "mov", "video/quicktime", "", "", "", "", sbIDeviceCapabilities::CONTENT_VIDEO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO_VIDEO },
948  { "mp4", "video/quicktime", "", "", "", "", sbIDeviceCapabilities::CONTENT_VIDEO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO_VIDEO },
952  { "wmv", "video/x-ms-asf", "video/x-ms-asf", "", "video/x-ms-wmv", "audio/x-ms-wma", sbIDeviceCapabilities::CONTENT_VIDEO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO_VIDEO },
953  { "avi", "video/x-msvideo", "", "", "mpeg4", "wma", sbIDeviceCapabilities::CONTENT_VIDEO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO_VIDEO },
954  { "divx", "video/x-msvideo", "", "", "mpeg4", "mp3", sbIDeviceCapabilities::CONTENT_VIDEO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO_VIDEO },
957  { "ogv", "application/ogg", "application/ogg", "", "video/x-theora", "audio/x-vorbis", sbIDeviceCapabilities::CONTENT_VIDEO, sbITranscodeProfile::TRANSCODE_TYPE_AUDIO_VIDEO },
958  /* images */
961  { "jpeg", "image/jpeg", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
964  { "ico", "image/x-icon", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
965  { "tiff", "image/tiff", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
967  { "wmf", "application/x-msmetafile", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
970  { "fpx", "application/vnd.netfpx", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
971  { "pcd", "image/x-photo-cd", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
972  { "pict", "image/pict", "", "", "", "", sbIDeviceCapabilities::CONTENT_IMAGE, sbITranscodeProfile::TRANSCODE_TYPE_IMAGE },
973 
974  /* playlists */
975  { "m3u", "audio/x-mpegurl", "", "", "", "", sbIDeviceCapabilities::CONTENT_PLAYLIST, sbITranscodeProfile::TRANSCODE_TYPE_UNKNOWN },
976  { "m3u8", "audio/x-mpegurl", "", "", "", "", sbIDeviceCapabilities::CONTENT_PLAYLIST, sbITranscodeProfile::TRANSCODE_TYPE_UNKNOWN }
977 };
978 
980  NS_ARRAY_LENGTH(MAP_FILE_EXTENSION_CONTENT_FORMAT);
981 
982 const PRInt32 K = 1000;
983 
989 static PRInt32 ParseInteger(nsAString const & aValue) {
990  TRACE(("%s: %s", __FUNCTION__, NS_LossyConvertUTF16toASCII(aValue).get()));
991  nsresult rv;
992  if (aValue.IsEmpty()) {
993  return 0;
994  }
995  PRUint32 val = aValue.ToInteger(&rv, 10);
996  if (NS_FAILED(rv)) {
997  val = 0;
998  }
999  return val;
1000 }
1001 
1009 /* static */ nsresult
1011  sbIMediaItem * aItem,
1012  sbExtensionToContentFormatEntry_t & aFormatType,
1013  PRUint32 & aBitRate,
1014  PRUint32 & aSampleRate)
1015 {
1016  TRACE(("%s", __FUNCTION__));
1017  NS_ENSURE_ARG_POINTER(aItem);
1018 
1019  nsresult rv;
1020 
1021  // We do it with string manipulation here rather than proper URL objects due
1022  // to thread-unsafety of URLs.
1023  nsString contentURL;
1024  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CONTENTURL),
1025  contentURL);
1026  NS_ENSURE_SUCCESS(rv, rv);
1027 
1028  // Get the format type.
1029  rv = GetFormatTypeForURL(contentURL, aFormatType);
1030  if (rv == NS_ERROR_NOT_AVAILABLE)
1031  return rv;
1032  NS_ENSURE_SUCCESS(rv, rv);
1033 
1034  // Get the bit rate.
1035  nsString bitRate;
1036  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_BITRATE), bitRate);
1037  NS_ENSURE_SUCCESS(rv, rv);
1038  aBitRate = NS_MIN (ParseInteger(bitRate) * K, 0);
1039 
1040  // Get the sample rate.
1041  nsString sampleRate;
1042  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_SAMPLERATE),
1043  sampleRate);
1044  NS_ENSURE_SUCCESS(rv, rv);
1045  aSampleRate = NS_MIN (ParseInteger(sampleRate), 0);
1046 
1047  return NS_OK;
1048 }
1049 
1058 /* static */ nsresult
1060  sbIMediaItem * aItem,
1061  sbExtensionToContentFormatEntry_t & aFormatType,
1062  PRUint32 & aSampleRate,
1063  PRUint32 & aChannels,
1064  PRUint32 & aBitRate)
1065 {
1066  TRACE(("%s", __FUNCTION__));
1067  NS_ENSURE_ARG_POINTER(aItem);
1068 
1069  nsresult rv;
1070 
1071  // We do it with string manipulation here rather than proper URL objects due
1072  // to thread-unsafety of URLs.
1073  nsString contentURL;
1074  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CONTENTURL),
1075  contentURL);
1076  NS_ENSURE_SUCCESS(rv, rv);
1077 
1078  // Get the format type.
1079  rv = GetFormatTypeForURL(contentURL, aFormatType);
1080  if (rv == NS_ERROR_NOT_AVAILABLE)
1081  return rv;
1082  NS_ENSURE_SUCCESS(rv, rv);
1083 
1084  // Get the bit rate.
1085  nsString bitRate;
1086  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_BITRATE), bitRate);
1087  NS_ENSURE_SUCCESS(rv, rv);
1088  aBitRate = NS_MIN (ParseInteger(bitRate) * K, 0);
1089 
1090  // Get the sample rate.
1091  nsString sampleRate;
1092  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_SAMPLERATE),
1093  sampleRate);
1094  NS_ENSURE_SUCCESS(rv, rv);
1095  aSampleRate = NS_MIN (ParseInteger(sampleRate), 0);
1096 
1097  // Get the channel count.
1098  nsString channels;
1099  rv = aItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CHANNELS),
1100  channels);
1101  NS_ENSURE_SUCCESS(rv, rv);
1102  aChannels = NS_MIN (ParseInteger(channels), 0);
1103 
1104  return NS_OK;
1105 }
1106 
1112 /* static */ nsresult
1114  (nsIURI* aURI,
1115  sbExtensionToContentFormatEntry_t& aFormatType)
1116 {
1117  TRACE(("%s", __FUNCTION__));
1118  NS_ENSURE_ARG_POINTER(aURI);
1119 
1120  nsresult rv;
1121 
1122  // Get the URI spec.
1123  nsCAutoString uriSpec;
1124  rv = aURI->GetSpec(uriSpec);
1125  NS_ENSURE_SUCCESS(rv, rv);
1126 
1127  // Get the format type.
1128  return GetFormatTypeForURL(NS_ConvertUTF8toUTF16(uriSpec), aFormatType);
1129 }
1130 
1136 /* static */ nsresult
1138  (const nsAString& aURL,
1139  sbExtensionToContentFormatEntry_t& aFormatType)
1140 {
1141  TRACE(("%s", __FUNCTION__));
1142 
1143  PRInt32 const lastDot = aURL.RFind(NS_LITERAL_STRING("."));
1144  if (lastDot != -1) {
1145  nsDependentSubstring fileExtension(aURL,
1146  lastDot + 1,
1147  aURL.Length() - lastDot - 1);
1148  nsCAutoString extension = NS_ConvertUTF16toUTF8(fileExtension);
1149  ToLowerCase(extension);
1150  for (PRUint32 index = 0;
1151  index < NS_ARRAY_LENGTH(MAP_FILE_EXTENSION_CONTENT_FORMAT);
1152  ++index) {
1155  if (extension.EqualsLiteral(entry.Extension)) {
1156  TRACE(("%s: ext %s type %s container %s codec %s",
1157  __FUNCTION__, entry.Extension, entry.MimeType,
1158  entry.ContainerFormat, entry.Codec));
1159  aFormatType = entry;
1160  return NS_OK;
1161  }
1162  }
1163  }
1164 
1165  return NS_ERROR_NOT_AVAILABLE;
1166 }
1167 
1173 /* static */ nsresult
1175  (const nsAString& aMimeType,
1176  const PRUint32 aContentType,
1177  nsTArray<sbExtensionToContentFormatEntry_t>& aFormatTypeList)
1178 {
1179  TRACE(("%s", __FUNCTION__));
1180 
1181  aFormatTypeList.Clear();
1182  for (PRUint32 index = 0;
1183  index < NS_ARRAY_LENGTH(MAP_FILE_EXTENSION_CONTENT_FORMAT);
1184  ++index) {
1187 
1188  if (aMimeType.EqualsLiteral(entry.MimeType) &&
1189  aContentType == entry.ContentType) {
1190  TRACE(("%s: ext %s type %s container %s codec %s",
1191  __FUNCTION__, entry.Extension, entry.MimeType,
1192  entry.ContainerFormat, entry.Codec));
1193  NS_ENSURE_TRUE(aFormatTypeList.AppendElement(entry),
1194  NS_ERROR_OUT_OF_MEMORY);
1195  }
1196  }
1197 
1198  return NS_OK;
1199 }
1200 
1209 /* static */ nsresult
1211  const nsAString& aCodec,
1212  nsAString& aMimeType)
1213 {
1214  TRACE(("%s", __FUNCTION__));
1215 
1216  // Search the content format map for a match.
1217  for (PRUint32 index = 0;
1218  index < NS_ARRAY_LENGTH(MAP_FILE_EXTENSION_CONTENT_FORMAT);
1219  ++index) {
1220  // Get the next format entry.
1223 
1224  // Skip entry if it's not audio.
1226  continue;
1227 
1228  // Check for a match, returning if a match is found.
1229  if (aContainer.EqualsLiteral(entry.ContainerFormat) &&
1230  aCodec.EqualsLiteral(entry.Codec)) {
1231  TRACE(("%s: container %s codec %s mime type %s",
1232  __FUNCTION__, entry.ContainerFormat, entry.Codec, entry.MimeType));
1233  aMimeType.AssignLiteral(entry.MimeType);
1234  return NS_OK;
1235  }
1236  }
1237 
1238  return NS_ERROR_NOT_AVAILABLE;
1239 }
1240 
1244 static PRUint32 TranscodeToCapsContentTypeMap[] = {
1249 };
1250 
1254 static nsresult
1256  PRUint32 aContentType,
1257  nsAString & aContainerFormat,
1258  nsAString & aVideoType,
1259  nsAString & aAudioType,
1260  nsAString & aCodec,
1261  sbIDevCapRange ** aBitRateRange = nsnull,
1262  sbIDevCapRange ** aSampleRateRange = nsnull)
1263 {
1264  nsresult rv;
1265 
1266  TRACE(("%s", __FUNCTION__));
1267 
1268  switch (aContentType) {
1270  nsCOMPtr<sbIAudioFormatType> audioFormat =
1271  do_QueryInterface(aFormatType);
1272  if (audioFormat) {
1273  nsCString temp;
1274  audioFormat->GetContainerFormat(temp);
1275  aContainerFormat = NS_ConvertASCIItoUTF16(temp);
1276  audioFormat->GetAudioCodec(temp);
1277  aCodec = NS_ConvertASCIItoUTF16(temp);
1278  if (aBitRateRange) {
1279  audioFormat->GetSupportedBitrates(aBitRateRange);
1280  }
1281  if (aSampleRateRange) {
1282  audioFormat->GetSupportedSampleRates(aSampleRateRange);
1283  }
1284  }
1285  }
1286  break;
1288  nsCOMPtr<sbIImageFormatType> imageFormat =
1289  do_QueryInterface(aFormatType);
1290  if (imageFormat) {
1291  nsCString temp;
1292  imageFormat->GetImageFormat(temp);
1293  aContainerFormat = NS_ConvertASCIItoUTF16(temp);
1294  if (aBitRateRange) {
1295  *aBitRateRange = nsnull;
1296  }
1297  if (aSampleRateRange) {
1298  *aSampleRateRange = nsnull;
1299  }
1300  }
1301  }
1302  break;
1304  nsCOMPtr<sbIVideoFormatType> videoFormat =
1305  do_QueryInterface(aFormatType);
1306  if (videoFormat) {
1307 
1308  nsCOMPtr<sbIDevCapVideoStream> videoStream;
1309  rv = videoFormat->GetVideoStream(getter_AddRefs(videoStream));
1310  NS_ENSURE_SUCCESS(rv, rv);
1311 
1312  nsCOMPtr<sbIDevCapAudioStream> audioStream;
1313  rv = videoFormat->GetAudioStream(getter_AddRefs(audioStream));
1314  nsCString videoType;
1315  if (aBitRateRange && videoStream) {
1316  videoStream->GetSupportedBitRates(aBitRateRange);
1317  rv = videoStream->GetType(videoType);
1318  NS_ENSURE_SUCCESS(rv, rv);
1319  aVideoType = NS_ConvertASCIItoUTF16(videoType);
1320  }
1321  nsCString audioType;
1322  if (aSampleRateRange && audioStream) {
1323  audioStream->GetSupportedSampleRates(aSampleRateRange);
1324  rv = audioStream->GetType(audioType);
1325  NS_ENSURE_SUCCESS(rv, rv);
1326  aAudioType = NS_ConvertASCIItoUTF16(audioType);
1327  }
1328  }
1329  if (aSampleRateRange) {
1330  *aSampleRateRange = nsnull;
1331  }
1332  }
1333  break;
1334  default: {
1335  NS_WARNING("Unexpected content type in GetContainerFormatAndCodec");
1336  if (aBitRateRange) {
1337  *aBitRateRange = nsnull;
1338  }
1339  if (aSampleRateRange) {
1340  *aSampleRateRange = nsnull;
1341  }
1342  }
1343  break;
1344  }
1345  return NS_OK;
1346 }
1347 
1348 nsresult
1349 sbDeviceUtils::GetTranscodeProfiles(PRUint32 aType, nsIArray ** aProfiles)
1350 {
1351  nsresult rv;
1352 
1353  nsCOMPtr<sbITranscodeManager> tcManager = do_ProxiedGetService(
1354  "@songbirdnest.com/Songbird/Mediacore/TranscodeManager;1", &rv);
1355  NS_ENSURE_SUCCESS(rv, rv);
1356 
1357  rv = tcManager->GetTranscodeProfiles(aType, aProfiles);
1358  NS_ENSURE_SUCCESS(rv, rv);
1359 
1360  return NS_OK;
1361 }
1362 
1363 nsresult
1365  sbIDevice * aDevice,
1366  nsIArray **aProfiles)
1367 {
1368  TRACE(("%s", __FUNCTION__));
1369  NS_ENSURE_ARG_POINTER(aDevice);
1370  NS_ENSURE_ARG_POINTER(aProfiles);
1371 
1372  nsresult rv;
1373 
1374  nsCOMPtr<nsIMutableArray> supportedProfiles = do_CreateInstance(
1376  NS_ENSURE_SUCCESS(rv, rv);
1377 
1378  nsCOMPtr<nsIArray> profiles;
1379  rv = GetTranscodeProfiles(aType, getter_AddRefs(profiles));
1380  NS_ENSURE_SUCCESS(rv, rv);
1381 
1382  nsCOMPtr<sbIDeviceCapabilities> devCaps;
1383  rv = aDevice->GetCapabilities(getter_AddRefs(devCaps));
1384  NS_ENSURE_SUCCESS(rv, rv);
1385 
1386  // These are the content types we care about
1387  static PRUint32 contentTypes[] = {
1391  };
1392 
1393  // Process each content type
1394  for (PRUint32 contentTypeIndex = 0;
1395  contentTypeIndex < NS_ARRAY_LENGTH(contentTypes);
1396  ++contentTypeIndex)
1397  {
1398  PRUint32 const contentType = contentTypes[contentTypeIndex];
1399  TRACE(("%s: Finding profiles for content type %d", __FUNCTION__, contentType));
1400  PRUint32 mimeTypesLength;
1401  char ** mimeTypes;
1402  rv = devCaps->GetSupportedMimeTypes(contentType,
1403  &mimeTypesLength,
1404  &mimeTypes);
1405  // Not found error is expected, we'll not do anything in that case, but we
1406  // need to finish out processing and not return early
1407  if (rv != NS_ERROR_NOT_AVAILABLE) {
1408  NS_ENSURE_SUCCESS(rv, rv);
1409  }
1410  if (NS_SUCCEEDED(rv)) {
1411  TRACE(("%s: Checking %d mime types for type %d", __FUNCTION__,
1412  mimeTypesLength, contentType));
1413 
1414  for (PRUint32 mimeTypeIndex = 0;
1415  mimeTypeIndex < mimeTypesLength && NS_SUCCEEDED(rv);
1416  ++mimeTypeIndex)
1417  {
1418  TRACE(("%s: Checking mime type %s", __FUNCTION__,
1419  mimeTypes[mimeTypeIndex]));
1420  nsString mimeType;
1421  mimeType.AssignLiteral(mimeTypes[mimeTypeIndex]);
1422  NS_Free(mimeTypes[mimeTypeIndex]);
1423 
1424  nsISupports** formatTypes;
1425  PRUint32 formatTypeCount;
1426  rv = devCaps->GetFormatTypes(contentType,
1427  mimeType,
1428  &formatTypeCount,
1429  &formatTypes);
1430  NS_ENSURE_SUCCESS (rv, rv);
1431  sbAutoFreeXPCOMPointerArray<nsISupports> freeFormats(formatTypeCount,
1432  formatTypes);
1433 
1434  for (PRUint32 formatIndex = 0;
1435  formatIndex < formatTypeCount;
1436  formatIndex++)
1437  {
1438  nsCOMPtr<nsISupports> formatTypeSupports = formatTypes[formatIndex];
1439 
1440  nsString containerFormat;
1441  nsString codec;
1442  nsString videoType; // Not used
1443  nsString audioType; // Not used
1444  rv = GetContainerFormatAndCodec(formatTypeSupports,
1445  contentType,
1446  containerFormat,
1447  videoType,
1448  audioType,
1449  codec);
1450  NS_ENSURE_SUCCESS(rv, rv);
1451  TRACE(("%s: Checking format %d with container %s, video %s, audio %s, codec %s",
1452  __FUNCTION__, formatIndex,
1453  NS_ConvertUTF16toUTF8(containerFormat).BeginReading(),
1454  NS_ConvertUTF16toUTF8(videoType).BeginReading(),
1455  NS_ConvertUTF16toUTF8(audioType).BeginReading(),
1456  NS_ConvertUTF16toUTF8(codec).BeginReading()));
1457 
1458  // Look for a match among our transcoding profile
1459  PRUint32 length;
1460  rv = profiles->GetLength(&length);
1461  NS_ENSURE_SUCCESS(rv, rv);
1462 
1463  for (PRUint32 index = 0;
1464  index < length && NS_SUCCEEDED(rv);
1465  ++index)
1466  {
1467  nsCOMPtr<sbITranscodeProfile> profile = do_QueryElementAt(profiles,
1468  index,
1469  &rv);
1470  NS_ENSURE_SUCCESS(rv, rv);
1471  nsString profileContainerFormat;
1472  rv = profile->GetContainerFormat(profileContainerFormat);
1473  NS_ENSURE_SUCCESS(rv, rv);
1474 
1475  PRUint32 profileType;
1476  rv = profile->GetType(&profileType);
1477  NS_ENSURE_SUCCESS(rv, rv);
1478 
1479  nsString audioCodec;
1480  rv = profile->GetAudioCodec(audioCodec);
1481  NS_ENSURE_SUCCESS(rv, rv);
1482 
1483  nsString videoCodec;
1484  rv = profile->GetVideoCodec(videoCodec);
1485 
1486  if (TranscodeToCapsContentTypeMap[profileType] == contentType &&
1487  profileContainerFormat.Equals(containerFormat))
1488  {
1489  if ((contentType == sbIDeviceCapabilities::CONTENT_AUDIO &&
1490  audioCodec.Equals(codec)) ||
1491  (contentType == sbIDeviceCapabilities::CONTENT_VIDEO &&
1492  videoCodec.Equals(codec)))
1493  {
1494  TRACE(("%s: Adding this format", __FUNCTION__));
1495  rv = supportedProfiles->AppendElement(profile, PR_FALSE);
1496  NS_ENSURE_SUCCESS(rv, rv);
1497  }
1498  }
1499  }
1500  }
1501  }
1502  NS_Free(mimeTypes);
1503  }
1504  }
1505 
1506  rv = CallQueryInterface(supportedProfiles.get(), aProfiles);
1507  NS_ENSURE_SUCCESS(rv, rv);
1508 
1509  return NS_OK;
1510 }
1511 
1518 static
1519 bool IsValueInRange(PRInt32 aValue, sbIDevCapRange * aRange) {
1520  if (!aValue || !aRange) {
1521  return true;
1522  }
1523  PRBool inRange;
1524  nsresult rv = aRange->IsValueInRange(aValue, &inRange);
1525  NS_ENSURE_SUCCESS(rv, PR_FALSE);
1526 
1527  return inRange != PR_FALSE;
1528 }
1529 
1539 nsresult
1541  sbExtensionToContentFormatEntry_t & aFormatType,
1542  PRUint32 & aBitRate,
1543  PRUint32 & aSampleRate,
1544  sbIDevice * aDevice,
1545  bool & aNeedsTranscoding)
1546 {
1547  TRACE(("%s", __FUNCTION__));
1548  nsCOMPtr<sbIDeviceCapabilities> devCaps;
1549  nsresult rv = aDevice->GetCapabilities(getter_AddRefs(devCaps));
1550  NS_ENSURE_SUCCESS(rv, rv);
1551 
1552  PRInt32 const devCapContentType =
1553  TranscodeToCapsContentTypeMap[aFormatType.TranscodeType];
1554 
1555  nsString itemContainerFormat;
1556  itemContainerFormat.AssignLiteral(aFormatType.ContainerFormat);
1557  nsString itemCodec;
1558  itemCodec.AssignLiteral(aFormatType.Codec);
1559 
1560  LOG(("Determining if item needs transcoding\n\tItem Container: '%s'\n\tItem Codec: '%s'",
1561  NS_LossyConvertUTF16toASCII(itemContainerFormat).get(),
1562  NS_LossyConvertUTF16toASCII(itemCodec).get()));
1563 
1564  PRUint32 mimeTypesLength;
1565  char ** mimeTypes;
1566  rv = devCaps->GetSupportedMimeTypes(devCapContentType,
1567  &mimeTypesLength,
1568  &mimeTypes);
1569  // If we know of transcoding formats than check them
1570  if (NS_SUCCEEDED(rv) && mimeTypesLength > 0) {
1571  aNeedsTranscoding = true;
1572  for (PRUint32 mimeTypesIndex = 0;
1573  mimeTypesIndex < mimeTypesLength;
1574  ++mimeTypesIndex) {
1575 
1576  NS_ConvertASCIItoUTF16 mimeType(mimeTypes[mimeTypesIndex]);
1577  nsISupports** formatTypes;
1578  PRUint32 formatTypeCount;
1579  rv = devCaps->GetFormatTypes(devCapContentType,
1580  mimeType,
1581  &formatTypeCount,
1582  &formatTypes);
1583  NS_ENSURE_SUCCESS (rv, rv);
1584  sbAutoFreeXPCOMPointerArray<nsISupports> freeFormats(formatTypeCount,
1585  formatTypes);
1586 
1587  for (PRUint32 formatIndex = 0;
1588  formatIndex < formatTypeCount;
1589  formatIndex++)
1590  {
1591  nsCOMPtr<nsISupports> formatType = formatTypes[formatIndex];
1592  nsString containerFormat;
1593  nsString codec;
1594 
1595  nsCOMPtr<sbIDevCapRange> bitRateRange;
1596  nsCOMPtr<sbIDevCapRange> sampleRateRange;
1597  nsString videoType; // Not used
1598  nsString audioType; // Not used
1599  rv = GetContainerFormatAndCodec(formatType,
1600  devCapContentType,
1601  containerFormat,
1602  videoType,
1603  audioType,
1604  codec,
1605  getter_AddRefs(bitRateRange),
1606  getter_AddRefs(sampleRateRange));
1607  if (NS_SUCCEEDED(rv)) {
1608 
1609  LOG(("Comparing container and codec\n\tCaps Container: '%s'\n\tCaps Codec: '%s'",
1610  NS_LossyConvertUTF16toASCII(containerFormat).get(),
1611  NS_LossyConvertUTF16toASCII(codec).get()));
1612 
1613  // Compare the various attributes, if bit rate and sample rate are
1614  // not specified then they always match
1615  if (containerFormat.Equals(itemContainerFormat) &&
1616  codec.Equals(itemCodec) &&
1617  (!aBitRate || IsValueInRange(aBitRate, bitRateRange)) &&
1618  (!aSampleRate || IsValueInRange(aSampleRate, sampleRateRange)))
1619  {
1620  TRACE(("%s: no transcoding needed, matches mime type '%s' "
1621  "container '%s' codec '%s'",
1622  __FUNCTION__, mimeTypes[mimeTypesIndex],
1623  NS_LossyConvertUTF16toASCII(containerFormat).get(),
1624  NS_LossyConvertUTF16toASCII(codec).get()));
1625  aNeedsTranscoding = false;
1626  break;
1627  }
1628  }
1629  }
1630  }
1631  NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mimeTypesLength, mimeTypes);
1632  }
1633  else { // We don't know the transcoding formats of the device so just copy
1634  TRACE(("%s: no information on device, assuming no transcoding needed",
1635  __FUNCTION__));
1636  aNeedsTranscoding = false;
1637  }
1638  TRACE(("%s: result %s", __FUNCTION__, aNeedsTranscoding ? "yes" : "no"));
1639  return NS_OK;
1640 }
1641 
1642 nsresult
1644  sbIMediaFormat * aMediaFormat,
1645  sbIDevice* aDevice,
1646  bool & aNeedsTranscoding)
1647 {
1648  TRACE(("%s", __FUNCTION__));
1649  nsCOMPtr<sbIDeviceCapabilities> devCaps;
1650  nsresult rv = aDevice->GetCapabilities(getter_AddRefs(devCaps));
1651  NS_ENSURE_SUCCESS(rv, rv);
1652 
1653  PRInt32 const devCapContentType =
1654  TranscodeToCapsContentTypeMap[aTranscodeType];
1655 
1656  nsCOMPtr<sbIDeviceCapsCompatibility> devCompatible =
1657  do_CreateInstance(SONGBIRD_DEVICECAPSCOMPATIBILITY_CONTRACTID, &rv);
1658  NS_ENSURE_SUCCESS(rv, rv);
1659  rv = devCompatible->Initialize(devCaps, aMediaFormat, devCapContentType);
1660  NS_ENSURE_SUCCESS(rv, rv);
1661 
1662  PRBool compatible;
1663  rv = devCompatible->Compare(&compatible);
1664  NS_ENSURE_SUCCESS(rv, rv);
1665 
1666  aNeedsTranscoding = !compatible;
1667  return NS_OK;
1668 }
1669 
1670 // XXX this needs to be fixed to be not gstreamer specific
1671 nsresult
1673  PRUint32 aTranscodeType,
1674  sbIDeviceTranscodingConfigurator **aConfigurator)
1675 {
1676  nsresult rv;
1677  nsCOMPtr<sbIDeviceTranscodingConfigurator> configurator;
1678  if (aTranscodeType == sbITranscodeProfile::TRANSCODE_TYPE_AUDIO) {
1679  configurator = do_CreateInstance(
1680  "@songbirdnest.com/Songbird/Mediacore/Transcode/Configurator/"
1681  "Audio/GStreamer;1", &rv);
1682  NS_ENSURE_SUCCESS(rv, rv);
1683  }
1684  else {
1685  configurator = do_CreateInstance(
1686  "@songbirdnest.com/Songbird/Mediacore/Transcode/Configurator/"
1687  "Device/GStreamer;1", &rv);
1688  NS_ENSURE_SUCCESS(rv, rv);
1689  }
1690 
1691  NS_ADDREF (*aConfigurator = configurator);
1692 
1693  return NS_OK;
1694 }
1695 
1696 nsresult
1698  nsIArray* aPropertyArray,
1699  nsString aPrefNameBase)
1700 {
1701  nsresult rv;
1702 
1703  if(!aPropertyArray) {
1704  // Perfectly ok; this just means there aren't any properties.
1705  return NS_OK;
1706  }
1707 
1708  PRUint32 numProperties;
1709  rv = aPropertyArray->GetLength(&numProperties);
1710  NS_ENSURE_SUCCESS(rv, rv);
1711 
1712  for (PRUint32 i = 0; i < numProperties; i++) {
1713  nsCOMPtr<sbITranscodeProfileProperty> property =
1714  do_QueryElementAt(aPropertyArray, i, &rv);
1715  NS_ENSURE_SUCCESS(rv, rv);
1716 
1717  nsString propName;
1718  rv = property->GetPropertyName(propName);
1719  NS_ENSURE_SUCCESS(rv, rv);
1720 
1721  nsString prefName = aPrefNameBase;
1722  prefName.AppendLiteral(".");
1723  prefName.Append(propName);
1724 
1725  nsCOMPtr<nsIVariant> prefVariant;
1726  rv = aDevice->GetPreference(prefName, getter_AddRefs(prefVariant));
1727  NS_ENSURE_SUCCESS(rv, rv);
1728 
1729  // Only use the property if we have a real value (not a void/empty variant)
1730  PRUint16 dataType;
1731  rv = prefVariant->GetDataType(&dataType);
1732  NS_ENSURE_SUCCESS(rv, rv);
1733  if (dataType != nsIDataType::VTYPE_VOID &&
1734  dataType != nsIDataType::VTYPE_EMPTY)
1735  {
1736  rv = property->SetValue(prefVariant);
1737  NS_ENSURE_SUCCESS(rv, rv);
1738  }
1739  }
1740 
1741  return NS_OK;
1742 }
1743 
1744 nsresult
1746  nsCString &aExtension)
1747 {
1748  NS_ENSURE_TRUE(aProfile, NS_ERROR_UNEXPECTED);
1749 
1750  nsString temp;
1751  nsresult rv = aProfile->GetContainerFormat(temp);
1752  NS_ENSURE_SUCCESS(rv, rv);
1753  NS_ConvertUTF16toUTF8 containerFormat(temp);
1754 
1755  rv = aProfile->GetAudioCodec(temp);
1756  NS_ENSURE_SUCCESS(rv, rv);
1757  NS_ConvertUTF16toUTF8 codec(temp);
1758 
1759  for (PRUint32 index = 0;
1761  ++index) {
1764  if (containerFormat.Equals(entry.ContainerFormat) &&
1765  codec.Equals(entry.Codec)) {
1766  aExtension.AssignLiteral(entry.Extension);
1767  return NS_OK;
1768  }
1769  }
1770  return NS_ERROR_NOT_AVAILABLE;
1771 }
1772 
1773 
1774 nsresult
1776  nsCString &aContainer,
1777  nsCString &aCodec,
1778  nsCString &aVideoType,
1779  nsCString &aAudioType)
1780 {
1781  for (PRUint32 index = 0;
1783  ++index)
1784  {
1787 
1788  if (aMimeType.EqualsLiteral(entry.MimeType)) {
1789  aContainer.AssignLiteral(entry.ContainerFormat);
1790  aCodec.AssignLiteral(entry.Codec);
1791  aVideoType.AssignLiteral(entry.VideoType);
1792  aAudioType.AssignLiteral(entry.AudioType);
1793  return NS_OK;
1794  }
1795  }
1796 
1797  return NS_ERROR_NOT_AVAILABLE;
1798 }
1799 
1800 bool
1802 {
1803  nsresult rv;
1804 
1805  nsString isDRMProtected;
1806  rv = aMediaItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_ISDRMPROTECTED),
1807  isDRMProtected);
1808  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_AVAILABLE,
1809  "sbDeviceUtils::IsItemDRMProtected Unexpected error, "
1810  "returning false");
1811  return NS_SUCCEEDED(rv) && isDRMProtected.EqualsLiteral("1");
1812 }
1813 
1814 /* static */ nsresult
1816  PRUint32 *aContentType,
1817  PRUint32 *aFunctionType)
1818 {
1819  // Validate arguments.
1820  NS_ENSURE_ARG_POINTER(aMediaItem);
1821  NS_ENSURE_ARG_POINTER(aContentType);
1822  NS_ENSURE_ARG_POINTER(aFunctionType);
1823 
1824  nsresult rv;
1825 
1827  *aFunctionType = sbIDeviceCapabilities::FUNCTION_UNKNOWN;
1828 
1829  nsString itemContentType;
1830  rv = aMediaItem->GetContentType(itemContentType);
1831  NS_ENSURE_SUCCESS(rv, rv);
1832 
1833  PRUint32 contentType, functionType;
1834  if (itemContentType.Equals(NS_LITERAL_STRING("audio"))) {
1837  }
1838  else if (itemContentType.Equals(NS_LITERAL_STRING("video"))) {
1841  }
1842  else if (itemContentType.Equals(NS_LITERAL_STRING("image"))) {
1845  }
1846  else {
1847  NS_WARNING("sbDeviceUtils::GetDeviceCapsTypeFromMediaItem: "
1848  "returning unknown device capabilities type");
1851  }
1852 
1853  *aContentType = contentType;
1854  *aFunctionType = functionType;
1855  return NS_OK;
1856 };
1857 
1858 /* static */ nsresult
1860  PRUint32 *aContentType,
1861  PRUint32 *aFunctionType)
1862 {
1863  NS_ENSURE_ARG_POINTER(aContentType);
1864  NS_ENSURE_ARG_POINTER(aFunctionType);
1865 
1866  PRUint32 contentType, functionType;
1867  // Map mix type list to audio.
1868  if (aListContentType & sbIMediaList::CONTENTTYPE_AUDIO) {
1871  }
1872  else if (aListContentType == sbIMediaList::CONTENTTYPE_VIDEO) {
1875  }
1876  else {
1877  NS_WARNING("sbDeviceUtils::GetDeviceCapsTypeFromListContentType: "
1878  "returning unknown device capabilities type");
1881  }
1882 
1883  *aContentType = contentType;
1884  *aFunctionType = functionType;
1885 
1886  return NS_OK;
1887 };
1888 
1889 /* static */ PRBool
1891  sbIMediaItem *aMediaItem)
1892 {
1893  NS_ENSURE_TRUE(aDevice, PR_FALSE);
1894  NS_ENSURE_TRUE(aMediaItem, PR_FALSE);
1895 
1896  nsresult rv;
1897 
1898  PRUint32 contentType, functionType;
1899  rv = GetDeviceCapsTypeFromMediaItem(aMediaItem,
1900  &contentType,
1901  &functionType);
1902  NS_ENSURE_SUCCESS(rv, PR_FALSE);
1903 
1904  nsCOMPtr<sbIDeviceCapabilities> capabilities;
1905  rv = aDevice->GetCapabilities(getter_AddRefs(capabilities));
1906  NS_ENSURE_SUCCESS(rv, PR_FALSE);
1907 
1908  PRBool isSupported;
1909  rv = capabilities->SupportsContent(functionType,
1910  contentType,
1911  &isSupported);
1912  NS_ENSURE_SUCCESS(rv, PR_FALSE);
1913 
1914  return isSupported;
1915 }
1916 
1917 /* static */ PRBool
1919  PRUint16 aListContentType)
1920 {
1921  NS_ENSURE_TRUE(aDevice, PR_FALSE);
1922 
1923  nsresult rv;
1924 
1925  PRUint32 contentType, functionType;
1926  rv = GetDeviceCapsTypeFromListContentType(aListContentType,
1927  &contentType,
1928  &functionType);
1929  NS_ENSURE_TRUE(NS_SUCCEEDED(rv), PR_FALSE);
1930 
1931  nsCOMPtr<sbIDeviceCapabilities> capabilities;
1932  rv = aDevice->GetCapabilities(getter_AddRefs(capabilities));
1933  NS_ENSURE_SUCCESS(rv, PR_FALSE);
1934 
1935  PRBool isSupported;
1936  rv = capabilities->SupportsContent(functionType,
1937  contentType,
1938  &isSupported);
1939  NS_ENSURE_SUCCESS(rv, PR_FALSE);
1940 
1941  return isSupported;
1942 }
1943 
1944 /*static*/
1946  (sbIDevice* aDevice,
1947  PRUint32 aContentType,
1948  nsTArray<nsString>& aFileExtensionList)
1949 {
1950  // Validate arguments.
1951  NS_ENSURE_ARG_POINTER(aDevice);
1952 
1953  // Function variables.
1954  nsresult rv;
1955 
1956  // Get the device capabilities.
1957  nsCOMPtr<sbIDeviceCapabilities> caps;
1958  rv = aDevice->GetCapabilities(getter_AddRefs(caps));
1959  NS_ENSURE_SUCCESS(rv, rv);
1960 
1961  // Get the list of supported MIME types and set it up for auto-disposal. Just
1962  // return if content type is not available.
1963  char** mimeTypeList;
1964  PRUint32 mimeTypeCount;
1965  rv = caps->GetSupportedMimeTypes(aContentType, &mimeTypeCount, &mimeTypeList);
1966  if (rv == NS_ERROR_NOT_AVAILABLE)
1967  return NS_OK;
1968  NS_ENSURE_SUCCESS(rv, rv);
1969  sbAutoNSArray<char*> autoMimeTypeList(mimeTypeList, mimeTypeCount);
1970 
1971  // Get the set of file extensions from the MIME type list.
1972  for (PRUint32 i = 0; i < mimeTypeCount; ++i) {
1973  // Get the format types for the MIME type.
1974  nsTArray<sbExtensionToContentFormatEntry_t> formatTypeList;
1976  (NS_ConvertASCIItoUTF16(mimeTypeList[i]),
1977  aContentType,
1978  formatTypeList);
1979  NS_ENSURE_SUCCESS(rv, rv);
1980 
1981  // Add each file extension to the list.
1982  for (PRUint32 j = 0; j < formatTypeList.Length(); ++j) {
1983  // Add the file extension to the list.
1984  NS_ConvertASCIItoUTF16 extension(formatTypeList[j].Extension);
1985  if (!aFileExtensionList.Contains(extension)) {
1986  aFileExtensionList.AppendElement(extension);
1987  }
1988  }
1989  }
1990 
1991  return NS_OK;
1992 }
1993 
1994 nsresult
1996  sbIDeviceLibrary * aDevLib,
1997  PRUint32 aMediaType,
1998  sbIDeviceLibraryMediaSyncSettings ** aMediaSettings)
1999 {
2000  NS_ASSERTION(aDevLib, "aDevLib is null");
2001 
2002  nsCOMPtr<sbIDeviceLibrarySyncSettings> syncSettings;
2003  nsresult rv = aDevLib->GetSyncSettings(getter_AddRefs(syncSettings));
2004  NS_ENSURE_SUCCESS(rv, rv);
2005 
2006  rv = syncSettings->GetMediaSettings(sbIDeviceLibrary::MEDIATYPE_IMAGE,
2007  aMediaSettings);
2008  NS_ENSURE_SUCCESS(rv, rv);
2009 
2010  return NS_OK;
2011 }
2012 
2013 nsresult
2015  PRUint32 aMediaType,
2016  PRUint32 & aMgmtType)
2017 {
2018  NS_ASSERTION(aDevLib, "aDevLib is null");
2019  nsresult rv;
2020 
2021  nsCOMPtr<sbIDeviceLibraryMediaSyncSettings> mediaSyncSettings;
2022  rv = GetMediaSettings(aDevLib,
2024  getter_AddRefs(mediaSyncSettings));
2025  NS_ENSURE_SUCCESS(rv, rv);
2026 
2027  rv = mediaSyncSettings->GetMgmtType(&aMgmtType);
2028  NS_ENSURE_SUCCESS(rv, rv);
2029 
2030  return NS_OK;
2031 }
2032 
2033 nsresult sbDeviceUtils::GetDeviceLibrary(nsAString const & aDeviceLibGuid,
2034  sbIDevice * aDevice,
2035  sbIDeviceLibrary ** aDeviceLibrary)
2036 {
2037  NS_ENSURE_ARG_POINTER(aDeviceLibrary);
2038 
2039  nsresult rv;
2040 
2041  // mediaItem.library is not a sbIDeviceLibrary, test GUID :(
2042  nsCOMPtr<sbIDeviceContent> content;
2043  rv = aDevice->GetContent(getter_AddRefs(content));
2044  NS_ENSURE_SUCCESS(rv, rv);
2045 
2046  nsCOMPtr<nsIArray> libraries;
2047  rv = content->GetLibraries(getter_AddRefs(libraries));
2048  NS_ENSURE_SUCCESS(rv, rv);
2049 
2050  PRUint32 libraryCount;
2051  rv = libraries->GetLength(&libraryCount);
2052  NS_ENSURE_SUCCESS(rv, rv);
2053 
2054  for (PRUint32 index = 0; index < libraryCount; ++index) {
2055  nsCOMPtr<sbIDeviceLibrary> deviceLib =
2056  do_QueryElementAt(libraries, index, &rv);
2057  if (NS_FAILED(rv))
2058  continue;
2059 
2060  nsString deviceLibGuid;
2061  rv = deviceLib->GetGuid(deviceLibGuid);
2062  NS_ENSURE_SUCCESS(rv, rv);
2063 
2064  if (deviceLibGuid.Equals(aDeviceLibGuid)) {
2065  deviceLib.forget(aDeviceLibrary);
2066  return NS_OK;
2067  }
2068  }
2069 
2070  *aDeviceLibrary = nsnull;
2071  return NS_OK;
2072 }
2073 
2074 nsresult sbDeviceUtils::GetDeviceLibrary(nsAString const & aDevLibGuid,
2075  nsID const * aDeviceID,
2076  sbIDeviceLibrary ** aDeviceLibrary)
2077 {
2078  NS_ENSURE_ARG_POINTER(aDeviceLibrary);
2079 
2080  nsresult rv;
2081 
2082  nsCOMPtr<sbIDeviceLibrary> deviceLibrary;
2083 
2084  nsCOMPtr<sbIDeviceRegistrar> deviceRegistrar =
2085  do_GetService("@songbirdnest.com/Songbird/DeviceManager;2", &rv);
2086 
2087  if (aDeviceID) {
2088  nsCOMPtr<sbIDevice> device;
2089  rv = deviceRegistrar->GetDevice(aDeviceID, getter_AddRefs(device));
2090  NS_ENSURE_SUCCESS(rv, rv);
2091 
2092  rv = GetDeviceLibrary(aDevLibGuid, device, getter_AddRefs(deviceLibrary));
2093  NS_ENSURE_SUCCESS(rv, rv);
2094  }
2095  else {
2096  nsCOMPtr<nsIArray> devices;
2097  rv = deviceRegistrar->GetDevices(getter_AddRefs(devices));
2098  NS_ENSURE_SUCCESS(rv, rv);
2099  nsCOMPtr<sbIDevice> device;
2100  PRUint32 length;
2101  rv = devices->GetLength(&length);
2102  for (PRUint32 index = 0; index < length && !deviceLibrary; ++index) {
2103  device = do_QueryElementAt(devices, index, &rv);
2104  NS_ENSURE_SUCCESS(rv, rv);
2105 
2106  rv = GetDeviceLibrary(aDevLibGuid, device, getter_AddRefs(deviceLibrary));
2107  NS_ENSURE_SUCCESS(rv, rv);
2108  }
2109  }
2110 
2111  deviceLibrary.forget(aDeviceLibrary);
2112 
2113  return NS_OK;
2114 }
2115 
2117  sbILibrary* aTargetLibrary,
2118  sbIMediaItem** aSyncItem)
2119 {
2120  // Validate arguments.
2121  NS_ENSURE_ARG_POINTER(aMediaItem);
2122  NS_ENSURE_ARG_POINTER(aTargetLibrary);
2123  NS_ENSURE_ARG_POINTER(aSyncItem);
2124 
2125  // Function variables.
2126  nsresult rv;
2127 
2128  // Try getting the sync item directly in the target library.
2129  rv = sbLibraryUtils::GetItemInLibrary(aMediaItem, aTargetLibrary, aSyncItem);
2130  NS_ENSURE_SUCCESS(rv, rv);
2131  if (*aSyncItem)
2132  return NS_OK;
2133 
2134  // Get the source library.
2135  nsCOMPtr<sbILibrary> sourceLibrary;
2136  rv = aMediaItem->GetLibrary(getter_AddRefs(sourceLibrary));
2137  NS_ENSURE_SUCCESS(rv, rv);
2138 
2139  // Try getting the sync item using the outer GUID property.
2140  nsAutoString outerGUID;
2141  rv = aMediaItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_OUTERGUID),
2142  outerGUID);
2143  NS_ENSURE_SUCCESS(rv, rv);
2144  if (!outerGUID.IsEmpty()) {
2145  // Get the outer media item.
2146  nsCOMPtr<sbIMediaItem> outerMediaItem;
2147  rv = sourceLibrary->GetMediaItem(outerGUID, getter_AddRefs(outerMediaItem));
2148  NS_ENSURE_SUCCESS(rv, rv);
2149 
2150  // Try getting the sync item from the outer media item.
2151  rv = sbLibraryUtils::GetItemInLibrary(outerMediaItem,
2152  aTargetLibrary,
2153  aSyncItem);
2154  NS_ENSURE_SUCCESS(rv, rv);
2155  if (*aSyncItem)
2156  return NS_OK;
2157  }
2158 
2159  // Try getting the sync item using the storage GUID property.
2160  nsAutoString storageGUID;
2161  rv = aMediaItem->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_STORAGEGUID),
2162  storageGUID);
2163  NS_ENSURE_SUCCESS(rv, rv);
2164  if (!storageGUID.IsEmpty()) {
2165  // Get the storage media item.
2166  nsCOMPtr<sbIMediaItem> storageMediaItem;
2167  rv = sourceLibrary->GetMediaItem(storageGUID,
2168  getter_AddRefs(storageMediaItem));
2169  NS_ENSURE_SUCCESS(rv, rv);
2170 
2171  // Try getting the sync item from the storage media item.
2172  rv = sbLibraryUtils::GetItemInLibrary(storageMediaItem,
2173  aTargetLibrary,
2174  aSyncItem);
2175  NS_ENSURE_SUCCESS(rv, rv);
2176  if (*aSyncItem)
2177  return NS_OK;
2178  }
2179 
2180  // Could not find the sync item.
2181  *aSyncItem = nsnull;
2182 
2183  return NS_OK;
2184 }
2185 
2187  sbILibrary * aDevLibrary,
2188  PRBool aMark)
2189 {
2190  NS_ENSURE_ARG_POINTER(aMediaItem);
2191 
2192  nsresult rv;
2193 
2194  NS_NAMED_LITERAL_STRING(SB_PROPERTY_TRUE, "1");
2195  NS_NAMED_LITERAL_STRING(SB_PROPERTY_FALSE, "0");
2196 
2197  nsCOMPtr<sbIMediaItem> itemInDeviceLibrary;
2198  rv = sbDeviceUtils::GetSyncItemInLibrary(aMediaItem,
2199  aDevLibrary,
2200  getter_AddRefs(itemInDeviceLibrary));
2201  NS_ENSURE_SUCCESS(rv, rv);
2202  if (itemInDeviceLibrary) {
2203  nsString inMainLibrary;
2204  rv = itemInDeviceLibrary->GetProperty(
2205  NS_LITERAL_STRING(SB_PROPERTY_ORIGIN_IS_IN_MAIN_LIBRARY),
2206  inMainLibrary);
2207  NS_ENSURE_SUCCESS(rv, rv);
2208  // Default to "false" if there is no property
2209  if (NS_FAILED(rv) || inMainLibrary.IsVoid()) {
2210  inMainLibrary = SB_PROPERTY_FALSE;
2211  }
2212  // If the flag is different than what we want change it
2213  const PRBool isMarked =
2214  !inMainLibrary.Equals(SB_PROPERTY_FALSE) ? PR_TRUE : PR_FALSE;
2215  if (aMark != isMarked) {
2216  rv = itemInDeviceLibrary->SetProperty(
2217  NS_LITERAL_STRING(SB_PROPERTY_ORIGIN_IS_IN_MAIN_LIBRARY),
2218  aMark ? SB_PROPERTY_TRUE : SB_PROPERTY_FALSE);
2219  NS_ENSURE_SUCCESS(rv, rv);
2220  }
2221  }
2222 
2223  return NS_OK;
2224 }
2225 
2226 
2228  sbIMediaItem * aItem) :
2229  mDevice(aDevice),
2230  mIgnoring(PR_FALSE),
2231  mListenerType(LIBRARY),
2232  mMediaItem(aItem) {
2233  NS_ASSERTION(aItem, "aItem is null");
2234  NS_ADDREF(mMediaItem);
2235  mDevice->IgnoreMediaItem(aItem);
2236 }
2237 
2239  if (mMediaItem) {
2240  mDevice->UnignoreMediaItem(mMediaItem);
2241  NS_RELEASE(mMediaItem);
2242  }
2243  else {
2244  SetIgnore(PR_FALSE);
2245  }
2246 }
2247 
2252  // If we're changing the ignore state
2253  if (mIgnoring != aIgnore) {
2254 
2255  // If the library listener was specified
2256  if ((mListenerType & LIBRARY) != 0) {
2257  mDevice->SetIgnoreLibraryListener(aIgnore);
2258  }
2259 
2260  // If the media list listener was specified
2261  if ((mListenerType & MEDIA_LIST) != 0) {
2262  mDevice->SetIgnoreMediaListListeners(aIgnore);
2263  }
2264  mIgnoring = aIgnore;
2265  }
2266 }
2267 
2268 
2269 //------------------------------------------------------------------------------
2270 // sbIDeviceCapabilities Logging functions
2271 // NOTE: This is built only w/ PR_LOGGING turned on.
2272 
2273 #ifdef PR_LOGGING
2274 #define LOG_MODULE(aLogModule, args) PR_LOG(aLogModule, PR_LOG_WARN, args)
2275 
2276 #ifdef __GNUC__
2277 #define __FUNCTION__ __PRETTY_FUNCTION__
2278 #endif /* __GNUC__ */
2279 
2280 static nsresult LogFormatType(PRUint32 aContentType,
2281  const nsAString & aFormat,
2282  sbIDeviceCapabilities *aDeviceCaps,
2283  PRLogModuleInfo *aLogModule);
2284 
2285 static nsresult LogImageFormatType(sbIImageFormatType *aImageFormatType,
2286  const nsAString & aFormat,
2287  PRLogModuleInfo *aLogModule);
2288 
2289 static nsresult LogVideoFormatType(sbIVideoFormatType *aVideoFormatType,
2290  const nsAString & aFormat,
2291  PRLogModuleInfo *aLogModule);
2292 
2293 static nsresult LogAudioFormatType(sbIAudioFormatType *aAudioFormatType,
2294  const nsAString & aFormat,
2295  PRLogModuleInfo *aLogModule);
2296 
2297 static nsresult LogSizeArray(nsIArray *aSizeArray, PRLogModuleInfo *aLogModule);
2298 
2299 static nsresult LogRange(sbIDevCapRange *aRange,
2300  PRBool aIsMinMax,
2301  PRLogModuleInfo *aLogModule);
2302 
2303 
2304 /* static */ nsresult
2305 sbDeviceUtils::LogDeviceCapabilities(sbIDeviceCapabilities *aDeviceCaps,
2306  PRLogModuleInfo *aLogModule)
2307 {
2308  NS_ENSURE_ARG_POINTER(aDeviceCaps);
2309  NS_ENSURE_ARG_POINTER(aLogModule);
2310 
2311  nsresult rv;
2312 
2313  LOG_MODULE(aLogModule,
2314  ("DEVICE CAPS:\n===============================================\n"));
2315 
2316  PRUint32 functionTypeCount;
2317  PRUint32 *functionTypes;
2318  rv = aDeviceCaps->GetSupportedFunctionTypes(&functionTypeCount,
2319  &functionTypes);
2320  NS_ENSURE_SUCCESS(rv, rv);
2321  sbAutoNSMemoryPtr functionTypesPtr(functionTypes);
2322  for (PRUint32 functionType = 0;
2323  functionType < functionTypeCount;
2324  functionType++)
2325  {
2326  PRUint32 *contentTypes;
2327  PRUint32 contentTypesLength;
2328 
2329  rv = aDeviceCaps->GetSupportedContentTypes(functionTypes[functionType],
2330  &contentTypesLength,
2331  &contentTypes);
2332  NS_ENSURE_SUCCESS(rv, rv);
2333 
2334  sbAutoNSMemoryPtr contentTypesPtr(contentTypes);
2335 
2336  for (PRUint32 contentType = 0;
2337  contentType < contentTypesLength;
2338  contentType++)
2339  {
2340  PRUint32 mimeTypesCount;
2341  char **mimeTypes;
2342  rv = aDeviceCaps->GetSupportedMimeTypes(contentTypes[contentType],
2343  &mimeTypesCount,
2344  &mimeTypes);
2345  NS_ENSURE_SUCCESS(rv, rv);
2346  sbAutoNSArray<char *> autoMimeTypesPtr(mimeTypes, mimeTypesCount);
2347 
2348  for (PRUint32 mimeType = 0; mimeType < mimeTypesCount; mimeType++) {
2349  rv = LogFormatType(contentTypes[contentType],
2350  NS_ConvertUTF8toUTF16(mimeTypes[mimeType]),
2351  aDeviceCaps,
2352  aLogModule);
2353  }
2354  }
2355  }
2356 
2357  // Output style
2358  LOG_MODULE(aLogModule,
2359  ("\n===============================================\n"));
2360 
2361  return NS_OK;
2362 }
2363 
2364 /* static */ nsresult
2365 LogFormatType(PRUint32 aContentType,
2366  const nsAString & aFormat,
2367  sbIDeviceCapabilities *aDeviceCaps,
2368  PRLogModuleInfo *aLogModule)
2369 {
2370  NS_ENSURE_ARG_POINTER(aDeviceCaps);
2371  NS_ENSURE_ARG_POINTER(aLogModule);
2372 
2373  nsresult rv;
2374  nsISupports** formatTypes;
2375  PRUint32 formatTypeCount;
2376  rv = aDeviceCaps->GetFormatTypes(aContentType,
2377  aFormat,
2378  &formatTypeCount,
2379  &formatTypes);
2380  NS_ENSURE_SUCCESS(rv, rv);
2381  sbAutoFreeXPCOMPointerArray<nsISupports> freeFormats(formatTypeCount,
2382  formatTypes);
2383 
2384  for (PRUint32 formatIndex = 0;
2385  formatIndex < formatTypeCount;
2386  formatIndex++)
2387  {
2388  nsCOMPtr<nsISupports> formatSupports = formatTypes[formatIndex];
2389 
2390  // QI to find out which format this is.
2391  nsCOMPtr<sbIAudioFormatType> audioFormatType =
2392  do_QueryInterface(formatSupports, &rv);
2393  if (NS_SUCCEEDED(rv) && audioFormatType) {
2394  rv = LogAudioFormatType(audioFormatType, aFormat, aLogModule);
2395  NS_ENSURE_SUCCESS(rv, rv);
2396  }
2397  else {
2398  nsCOMPtr<sbIVideoFormatType> videoFormatType =
2399  do_QueryInterface(formatSupports, &rv);
2400  if (NS_SUCCEEDED(rv) && videoFormatType) {
2401  rv = LogVideoFormatType(videoFormatType, aFormat, aLogModule);
2402  NS_ENSURE_SUCCESS(rv, rv);
2403  }
2404  else {
2405  // Last chance, attempt image type.
2406  nsCOMPtr<sbIImageFormatType> imageFormatType =
2407  do_QueryInterface(formatSupports, &rv);
2408  if (NS_SUCCEEDED(rv) && imageFormatType) {
2409  rv = LogImageFormatType(imageFormatType, aFormat, aLogModule);
2410  NS_ENSURE_SUCCESS(rv, rv);
2411  }
2412  }
2413  }
2414  }
2415 
2416  return NS_OK;
2417 }
2418 
2419 /* static */ nsresult
2420 LogImageFormatType(sbIImageFormatType *aImageFormatType,
2421  const nsAString & aFormat,
2422  PRLogModuleInfo *aLogModule)
2423 {
2424  NS_ENSURE_ARG_POINTER(aImageFormatType);
2425  NS_ENSURE_ARG_POINTER(aLogModule);
2426 
2427  nsresult rv;
2428 
2429  nsString format(aFormat);
2430  LOG_MODULE(aLogModule, (" *** IMAGE FORMAT TYPE '%s' ***",
2431  NS_ConvertUTF16toUTF8(format).get()));
2432 
2433  nsCString imgFormat;
2434  rv = aImageFormatType->GetImageFormat(imgFormat);
2435  NS_ENSURE_SUCCESS(rv, rv);
2436 
2437  nsCOMPtr<sbIDevCapRange> widths;
2438  rv = aImageFormatType->GetSupportedWidths(getter_AddRefs(widths));
2439  NS_ENSURE_SUCCESS(rv, rv);
2440 
2441  nsCOMPtr<sbIDevCapRange> heights;
2442  rv = aImageFormatType->GetSupportedHeights(getter_AddRefs(heights));
2443  NS_ENSURE_SUCCESS(rv, rv);
2444 
2445  nsCOMPtr<nsIArray> sizes;
2446  rv = aImageFormatType->GetSupportedExplicitSizes(getter_AddRefs(sizes));
2447  NS_ENSURE_SUCCESS(rv, rv);
2448 
2449  LOG_MODULE(aLogModule, (" * image format: %s", imgFormat.get()));
2450 
2451  LOG_MODULE(aLogModule, (" * image widths:\n"));;
2452  rv = LogRange(widths, PR_TRUE, aLogModule);
2453  NS_ENSURE_SUCCESS(rv, rv);
2454 
2455  LOG_MODULE(aLogModule, (" * image heights:\n"));
2456  rv = LogRange(heights, PR_TRUE, aLogModule);
2457  NS_ENSURE_SUCCESS(rv, rv);
2458 
2459  LOG_MODULE(aLogModule, (" * image supported sizes:\n"));
2460  rv = LogSizeArray(sizes, aLogModule);
2461  NS_ENSURE_SUCCESS(rv, rv);
2462 
2463  // Output style
2464  LOG_MODULE(aLogModule, ("\n"));
2465  return NS_OK;
2466 }
2467 
2468 /* static */ nsresult
2469 LogVideoFormatType(sbIVideoFormatType *aVideoFormatType,
2470  const nsAString & aFormat,
2471  PRLogModuleInfo *aLogModule)
2472 {
2473  NS_ENSURE_ARG_POINTER(aVideoFormatType);
2474  NS_ENSURE_ARG_POINTER(aLogModule);
2475 
2476  nsresult rv;
2477 
2478  nsString format(aFormat);
2479  LOG_MODULE(aLogModule, (" *** VIDEO FORMAT TYPE '%s' ***",
2480  NS_ConvertUTF16toUTF8(format).get()));
2481 
2482  nsCString containerType;
2483  rv = aVideoFormatType->GetContainerType(containerType);
2484  NS_ENSURE_SUCCESS(rv, rv);
2485 
2486  nsCOMPtr<sbIDevCapVideoStream> videoStream;
2487  rv = aVideoFormatType->GetVideoStream(getter_AddRefs(videoStream));
2488  NS_ENSURE_SUCCESS(rv, rv);
2489 
2490  nsCString videoStreamType;
2491  rv = videoStream->GetType(videoStreamType);
2492  NS_ENSURE_SUCCESS(rv, rv);
2493 
2494  nsCOMPtr<nsIArray> videoSizes;
2495  rv = videoStream->GetSupportedExplicitSizes(getter_AddRefs(videoSizes));
2496  NS_ENSURE_SUCCESS(rv, rv);
2497 
2498  nsCOMPtr<sbIDevCapRange> videoWidths;
2499  rv = videoStream->GetSupportedWidths(getter_AddRefs(videoWidths));
2500  NS_ENSURE_SUCCESS(rv, rv);
2501 
2502  nsCOMPtr<sbIDevCapRange> videoHeights;
2503  rv = videoStream->GetSupportedHeights(getter_AddRefs(videoHeights));
2504  NS_ENSURE_SUCCESS(rv, rv);
2505 
2506  nsCOMPtr<sbIDevCapRange> videoBitrates;
2507  rv = videoStream->GetSupportedBitRates(getter_AddRefs(videoBitrates));
2508  NS_ENSURE_SUCCESS(rv, rv);
2509 
2510  PRUint32 num, den;
2511 
2512 
2513  LOG_MODULE(aLogModule, (" * videostream type = %s)", videoStreamType.get()));
2514 
2515  LOG_MODULE(aLogModule, (" * videostream supported widths:"));
2516  rv = LogRange(videoWidths, PR_TRUE, aLogModule);
2517 
2518  LOG_MODULE(aLogModule, (" * videosream supported heights:"));
2519  rv = LogRange(videoHeights, PR_TRUE, aLogModule);
2520 
2521  LOG_MODULE(aLogModule, (" * videostream bitrates:"));
2522  rv = LogRange(videoBitrates, PR_TRUE, aLogModule);
2523 
2524  PRBool supportsPARRange = PR_FALSE;
2525  rv = videoStream->GetDoesSupportPARRange(&supportsPARRange);
2526  if (NS_SUCCEEDED(rv) && supportsPARRange) {
2527  // Simply log the min and the max values here.
2528  nsCOMPtr<sbIDevCapFraction> minSupportedPAR;
2529  rv = videoStream->GetMinimumSupportedPAR(getter_AddRefs(minSupportedPAR));
2530  NS_ENSURE_SUCCESS(rv, rv);
2531 
2532  nsCOMPtr<sbIDevCapFraction> maxSupportedPAR;
2533  rv = videoStream->GetMaximumSupportedPAR(getter_AddRefs(maxSupportedPAR));
2534  NS_ENSURE_SUCCESS(rv, rv);
2535 
2536  rv = minSupportedPAR->GetNumerator(&num);
2537  NS_ENSURE_SUCCESS(rv, rv);
2538  rv = minSupportedPAR->GetDenominator(&den);
2539  NS_ENSURE_SUCCESS(rv, rv);
2540  LOG_MODULE(aLogModule, (" * videostream min PAR: %i/%i", num, den));
2541 
2542  rv = maxSupportedPAR->GetNumerator(&num);
2543  NS_ENSURE_SUCCESS(rv, rv);
2544  rv = maxSupportedPAR->GetDenominator(&den);
2545  NS_ENSURE_SUCCESS(rv, rv);
2546  LOG_MODULE(aLogModule, (" * videostream max PAR: %i/%i", num, den));
2547  }
2548  else {
2549  // Log out the list of PARs.
2550  nsCOMPtr<nsIArray> supportedPARs;
2551  rv = videoStream->GetSupportedPARs(getter_AddRefs(supportedPARs));
2552  NS_ENSURE_SUCCESS(rv, rv);
2553 
2554  PRUint32 length = 0;
2555  rv = supportedPARs->GetLength(&length);
2556  NS_ENSURE_SUCCESS(rv, rv);
2557 
2558  LOG_MODULE(aLogModule, (" * videostream PAR count: %i", length));
2559 
2560  for (PRUint32 i = 0; i < length; i++) {
2561  nsCOMPtr<sbIDevCapFraction> curFraction =
2562  do_QueryElementAt(supportedPARs, i, &rv);
2563  NS_ENSURE_SUCCESS(rv, rv);
2564 
2565  rv = curFraction->GetNumerator(&num);
2566  NS_ENSURE_SUCCESS(rv, rv);
2567  rv = curFraction->GetDenominator(&den);
2568  NS_ENSURE_SUCCESS(rv, rv);
2569 
2570  LOG_MODULE(aLogModule, (" - %i/%i", num, den));
2571  }
2572  }
2573 
2574  PRBool supportsFrameRange = PR_FALSE;
2575  rv = videoStream->GetDoesSupportFrameRateRange(&supportsFrameRange);
2576  if (NS_SUCCEEDED(rv) && supportsFrameRange) {
2577  nsCOMPtr<sbIDevCapFraction> minFrameRate;
2578  rv = videoStream->GetMinimumSupportedFrameRate(
2579  getter_AddRefs(minFrameRate));
2580  NS_ENSURE_SUCCESS(rv, rv);
2581 
2582  nsCOMPtr<sbIDevCapFraction> maxFrameRate;
2583  rv = videoStream->GetMaximumSupportedFrameRate(
2584  getter_AddRefs(maxFrameRate));
2585  NS_ENSURE_SUCCESS(rv, rv);
2586 
2587  rv = minFrameRate->GetNumerator(&num);
2588  NS_ENSURE_SUCCESS(rv, rv);
2589  rv = minFrameRate->GetDenominator(&den);
2590  NS_ENSURE_SUCCESS(rv, rv);
2591  LOG_MODULE(aLogModule, (" * videostream min framerate: %i/%i", num, den));
2592 
2593  rv = maxFrameRate->GetNumerator(&num);
2594  NS_ENSURE_SUCCESS(rv, rv);
2595  rv = maxFrameRate->GetDenominator(&den);
2596  NS_ENSURE_SUCCESS(rv, rv);
2597  LOG_MODULE(aLogModule, (" * videostream max framerate: %i/%i", num, den));
2598  }
2599  else {
2600  nsCOMPtr<nsIArray> frameRates;
2601  rv = videoStream->GetSupportedFrameRates(getter_AddRefs(frameRates));
2602  NS_ENSURE_SUCCESS(rv, rv);
2603 
2604  PRUint32 length = 0;
2605  rv = frameRates->GetLength(&length);
2606  NS_ENSURE_SUCCESS(rv, rv);
2607 
2608  LOG_MODULE(aLogModule, (" * videostream framerate count: %i", length));
2609 
2610  for (PRUint32 i = 0; i < length; i++) {
2611  nsCOMPtr<sbIDevCapFraction> curFraction =
2612  do_QueryElementAt(frameRates, i, &rv);
2613  NS_ENSURE_SUCCESS(rv, rv);
2614 
2615  rv = curFraction->GetNumerator(&num);
2616  NS_ENSURE_SUCCESS(rv, rv);
2617  rv = curFraction->GetDenominator(&den);
2618  NS_ENSURE_SUCCESS(rv, rv);
2619 
2620  LOG_MODULE(aLogModule, (" - %i/%i", num, den));
2621  }
2622  }
2623 
2624  nsCOMPtr<sbIDevCapAudioStream> audioStream;
2625  rv = aVideoFormatType->GetAudioStream(getter_AddRefs(audioStream));
2626  NS_ENSURE_SUCCESS(rv, rv);
2627 
2628  nsCString audioStreamType;
2629  rv = audioStream->GetType(audioStreamType);
2630  NS_ENSURE_SUCCESS(rv, rv);
2631 
2632  nsCOMPtr<sbIDevCapRange> audioBitrates;
2633  rv = audioStream->GetSupportedBitRates(getter_AddRefs(audioBitrates));
2634  NS_ENSURE_SUCCESS(rv, rv);
2635 
2636  nsCOMPtr<sbIDevCapRange> audioSamplerates;
2637  rv = audioStream->GetSupportedSampleRates(getter_AddRefs(audioSamplerates));
2638  NS_ENSURE_SUCCESS(rv, rv);
2639 
2640  nsCOMPtr<sbIDevCapRange> audioChannels;
2641  rv = audioStream->GetSupportedChannels(getter_AddRefs(audioChannels));
2642  NS_ENSURE_SUCCESS(rv, rv);
2643 
2644  LOG_MODULE(aLogModule, (" * audiostream type = %s", audioStreamType.get()));
2645 
2646  LOG_MODULE(aLogModule, (" * audiostream bitrates:"));
2647  rv = LogRange(audioBitrates, PR_TRUE, aLogModule);
2648 
2649  LOG_MODULE(aLogModule, (" * audiostream samplerates:"));
2650  rv = LogRange(audioSamplerates, PR_FALSE, aLogModule);
2651 
2652  LOG_MODULE(aLogModule, (" * audiostream channels"));
2653  rv = LogRange(audioChannels, PR_TRUE, aLogModule);
2654 
2655  // Output style
2656  LOG_MODULE(aLogModule, ("\n"));
2657  return NS_OK;
2658 }
2659 
2660 /* static */ nsresult
2661 LogAudioFormatType(sbIAudioFormatType *aAudioFormatType,
2662  const nsAString & aFormat,
2663  PRLogModuleInfo *aLogModule)
2664 {
2665  NS_ENSURE_ARG_POINTER(aAudioFormatType);
2666  NS_ENSURE_ARG_POINTER(aLogModule);
2667 
2668  nsresult rv;
2669 
2670  nsString format(aFormat);
2671  LOG_MODULE(aLogModule, (" *** AUDIO FORMAT TYPE '%s' ***",
2672  NS_ConvertUTF16toUTF8(format).get()));
2673 
2674  nsCString audioCodec;
2675  rv = aAudioFormatType->GetAudioCodec(audioCodec);
2676  NS_ENSURE_SUCCESS(rv, rv);
2677 
2678  nsCString containerFormat;
2679  rv = aAudioFormatType->GetContainerFormat(containerFormat);
2680  NS_ENSURE_SUCCESS(rv, rv);
2681 
2682  nsCOMPtr<sbIDevCapRange> bitrates;
2683  rv = aAudioFormatType->GetSupportedBitrates(getter_AddRefs(bitrates));
2684  NS_ENSURE_SUCCESS(rv, rv);
2685 
2686  nsCOMPtr<sbIDevCapRange> samplerates;
2687  rv = aAudioFormatType->GetSupportedSampleRates(getter_AddRefs(samplerates));
2688  NS_ENSURE_SUCCESS(rv, rv);
2689 
2690  nsCOMPtr<sbIDevCapRange> channels;
2691  rv = aAudioFormatType->GetSupportedChannels(getter_AddRefs(channels));
2692  NS_ENSURE_SUCCESS(rv, rv);
2693 
2694  // Output
2695  LOG_MODULE(aLogModule, (" * audioCodec = %s", audioCodec.get()));
2696  LOG_MODULE(aLogModule, (" * containerFormat = %s", containerFormat.get()));
2697 
2698  LOG_MODULE(aLogModule, (" * audio bitrates:"));
2699  rv = LogRange(bitrates, PR_TRUE, aLogModule);
2700  NS_ENSURE_SUCCESS(rv, rv);
2701 
2702  LOG_MODULE(aLogModule, (" * audio samplerates:"));
2703  rv = LogRange(samplerates, PR_FALSE, aLogModule);
2704  NS_ENSURE_SUCCESS(rv, rv);
2705 
2706  LOG_MODULE(aLogModule, (" * audio channels:"));
2707  rv = LogRange(channels, PR_TRUE, aLogModule);
2708  NS_ENSURE_SUCCESS(rv, rv);
2709 
2710  // Output style
2711  LOG_MODULE(aLogModule, ("\n"));
2712  return NS_OK;
2713 }
2714 
2715 /* static */ nsresult
2716 LogSizeArray(nsIArray *aSizeArray, PRLogModuleInfo *aLogModule)
2717 {
2718  NS_ENSURE_ARG_POINTER(aSizeArray);
2719  NS_ENSURE_ARG_POINTER(aLogModule);
2720 
2721  nsresult rv;
2722  PRUint32 arrayCount = 0;
2723  rv = aSizeArray->GetLength(&arrayCount);
2724  NS_ENSURE_SUCCESS(rv, rv);
2725 
2726  for (PRUint32 i = 0; i < arrayCount; i++) {
2727  nsCOMPtr<sbIImageSize> curImageSize =
2728  do_QueryElementAt(aSizeArray, i, &rv);
2729  NS_ENSURE_SUCCESS(rv, rv);
2730 
2731  PRInt32 width, height;
2732  rv = curImageSize->GetWidth(&width);
2733  NS_ENSURE_SUCCESS(rv, rv);
2734 
2735  rv = curImageSize->GetHeight(&height);
2736  NS_ENSURE_SUCCESS(rv, rv);
2737 
2738  LOG_MODULE(aLogModule, (" - %i x %i", width, height));
2739  }
2740 
2741  return NS_OK;
2742 }
2743 
2744 /* static */ nsresult
2745 LogRange(sbIDevCapRange *aRange,
2746  PRBool aIsMinMax,
2747  PRLogModuleInfo *aLogModule)
2748 {
2749  NS_ENSURE_ARG_POINTER(aRange);
2750  NS_ENSURE_ARG_POINTER(aLogModule);
2751 
2752  nsresult rv;
2753  if (aIsMinMax) {
2754  PRInt32 min, max, step;
2755  rv = aRange->GetMin(&min);
2756  NS_ENSURE_SUCCESS(rv, rv);
2757  rv = aRange->GetMax(&max);
2758  NS_ENSURE_SUCCESS(rv, rv);
2759  rv = aRange->GetStep(&step);
2760  NS_ENSURE_SUCCESS(rv, rv);
2761 
2762  LOG_MODULE(aLogModule, (" - min: %i", min));
2763  LOG_MODULE(aLogModule, (" - max: %i", max));
2764  LOG_MODULE(aLogModule, (" - step: %i", step));
2765  }
2766  else {
2767  PRUint32 valueCount = 0;
2768  rv = aRange->GetValueCount(&valueCount);
2769  NS_ENSURE_SUCCESS(rv, rv);
2770 
2771  for (PRUint32 i = 0; i < valueCount; i++) {
2772  PRInt32 curValue = 0;
2773  rv = aRange->GetValue(i, &curValue);
2774  NS_ENSURE_SUCCESS(rv, rv);
2775 
2776  LOG_MODULE(aLogModule, (" - %i", curValue));
2777  }
2778  }
2779 
2780  return NS_OK;
2781 }
2782 
2783 #endif
2784 
2786 {
2787  const char * const DEVICE_PREF_BRANCH = "songbird.device.";
2788  const char * const LOG_DEVICE_INFO_PREF = "log_device_info";
2789 
2790  nsresult rv;
2791  sbPrefBranch prefBranch(DEVICE_PREF_BRANCH, &rv);
2792  NS_ENSURE_SUCCESS(rv, rv);
2793 
2794  return prefBranch.GetBoolPref(LOG_DEVICE_INFO_PREF, PR_FALSE) != PR_FALSE;
2795 }
2796 
2798 {
2799  nsresult rv;
2800 
2801  if (!aDevice) {
2802  return NS_LITERAL_CSTRING("Device Unknown");
2803  }
2804  nsCString result;
2805 
2806  nsString deviceIdentifier;
2807  rv = aDevice->GetName(deviceIdentifier);
2808  if (NS_FAILED(rv)) {
2809  deviceIdentifier.Truncate();
2810  }
2811  // Convert to ascii since this is going to be output to an ascii device
2812  result = NS_LossyConvertUTF16toASCII(deviceIdentifier);
2813  nsID *deviceID;
2814  rv = aDevice->GetId(&deviceID);
2815  sbAutoNSMemPtr autoDeviceID(deviceID);
2816  NS_ENSURE_SUCCESS(rv, result);
2817 
2818  char volumeGUID[NSID_LENGTH];
2819  deviceID->ToProvidedString(volumeGUID);
2820 
2821  if (!result.IsEmpty()) {
2822  result.Append(NS_LITERAL_CSTRING("-"));
2823  }
2824  result.Append(volumeGUID);
2825 
2826  return result;
2827 }
PRUint32 const MAP_FILE_EXTENSION_CONTENT_FORMAT_LENGTH
const unsigned long TRANSCODE_TYPE_IMAGE
classDescription entry
Definition: FeedWriter.js:1427
static nsresult GetTranscodeProfiles(PRUint32 aType, nsIArray **aProfiles)
static nsresult GetOriginMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
static nsresult GetTranscodedFileExtension(sbITranscodeProfile *aProfile, nsCString &aExtension)
const PRUint32 FUNCTION_AUDIO_PLAYBACK
A callback interface that is called with a window.
return NS_OK
const PRUint32 FUNCTION_VIDEO_PLAYBACK
static nsresult GetContentLength(sbIMediaItem *aItem, PRInt64 *_retval=nsnull)
#define SB_PROPERTY_SAMPLERATE
static nsresult GetItemInLibrary(sbIMediaItem *aItem, sbILibrary *aLibrary, sbIMediaItem **_retval)
[UNIMPLEMENTED UNTIL AFTER 0.3]
static nsresult ShowDeviceErrors(sbIDevice *aDevice)
Interface used to enumerate the items in a media list.
NS_DECL_ISUPPORTS NS_DECL_SBICALLWITHWINDOWCALLBACK nsresult Query(sbIDevice *aDevice, sbIDeviceLibrary *aLibrary, PRInt64 aSpaceNeeded, PRInt64 aSpaceAvailable, PRBool *aAbort)
#define SB_PROPERTY_CHANNELS
onPageChanged aValue
Definition: FeedWriter.js:1395
inArray array
static nsresult BulkSetProperty(sbIMediaList *aMediaList, const nsAString &aPropertyId, const nsAString &aPropertyValue, sbIPropertyArray *aPropertyFilter=nsnull, PRInt32 *aAbortFlag=nsnull)
char const * Codec
Definition: sbDeviceUtils.h:58
static nsresult SetLinkedSyncPartner(sbIDevice *aDevice)
NS_DECL_ISUPPORTS NS_IMETHODIMP OnEnumerationBegin(sbIMediaList *aMediaList, PRUint16 *_retval)
static nsresult QueryUserAbortRip(PRBool *aAbort)
#define SB_PROPERTY_ISDRMPROTECTED
sbDeviceUtilsBulkSetPropertyEnumerationListener(const nsAString &aId, const nsAString &aValue, PRInt32 *aAbortFlag=nsnull)
static nsresult QueryUserViewErrors(sbIDevice *aDevice)
static nsresult SetOriginIsInMainLibrary(sbIMediaItem *aMediaItem, sbILibrary *aDevLibrary, PRBool aMark)
#define SB_THREADSAFE_ARRAY_CONTRACTID
Definition: sbArrayUtils.h:40
static nsresult GetDeviceLibraryForItem(sbIDevice *aDevice, sbIMediaItem *aItem, sbIDeviceLibrary **_retval)
static nsresult NewDeviceLibraryURI(sbIDeviceLibrary *aDeviceLibrary, const nsCString &aSpec, nsIURI **aURI)
static bool IsItemDRMProtected(sbIMediaItem *aMediaItem)
static nsresult GetDeviceCapsTypeFromListContentType(PRUint16 aListContentType, PRUint32 *aContentType, PRUint32 *aFunctionType)
#define SB_PROPERTY_DEVICE_PERSISTENT_ID
void nsString_ReplaceChar(nsAString &aString, const nsAString &aOldChars, const PRUnichar aNewChar)
const unsigned long TRANSCODE_TYPE_AUDIO
const unsigned long TRANSCODE_TYPE_UNKNOWN
An object defining a transcoding profile.
static nsresult GetOriginItem(sbIMediaItem *aItem, sbIMediaItem **_retval)
sbDeviceListenerIgnore(sbBaseDevice *aDevice, PRUint32 aListenerType=ALL)
Songbird Variant Utility Definitions.
A brief description of the contents of this interface.
#define SONGBIRD_PROMPTER_CONTRACTID
static nsresult QueryUserSpaceExceeded(sbIDevice *aDevice, sbIDeviceLibrary *aLibrary, PRInt64 aSpaceNeeded, PRInt64 aSpaceAvailable, PRBool *aAbort)
const unsigned short CONTENTTYPE_AUDIO
static nsresult GetOrganizedPath(nsIFile *aParent, sbIMediaItem *aItem, nsIFile **_retval)
static nsresult ApplyPropertyPreferencesToProfile(sbIDevice *aDevice, nsIArray *aPropertyArray, nsString aPrefNameBase)
#define SB_PROPERTY_BITRATE
char const * Extension
Definition: sbDeviceUtils.h:55
const unsigned long MEDIATYPE_IMAGE
static nsresult GetSupportedTranscodeProfiles(PRUint32 aType, sbIDevice *aDevice, nsIArray **aProfiles)
function width(ele) rect(ele).width
#define DEVICE_PREF_BRANCH
static PRUint32 TranscodeToCapsContentTypeMap[]
const unsigned long TRANSCODE_TYPE_AUDIO_VIDEO
SB_AUTO_CLASS(sbAutoNSMemoryPtr, void *,!!mValue, NS_Free(mValue), mValue=nsnull)
static nsresult GetDeviceCapsTypeFromMediaItem(sbIMediaItem *aMediaItem, PRUint32 *aContentType, PRUint32 *aFunctionType)
#define SB_PROPERTY_STORAGEGUID
static PRBool IsMediaItemSupported(sbIDevice *aDevice, sbIMediaItem *aMediaItem)
char const * AudioType
Definition: sbDeviceUtils.h:60
static nsresult GetFormatTypesForMimeType(const nsAString &aMimeType, const PRUint32 aContentType, nsTArray< sbExtensionToContentFormatEntry_t > &aFormatTypeList)
For a MIME type, get format information describing it (extension, mime type, etc. ...
static nsresult GetFormatTypeForURL(const nsAString &aURL, sbExtensionToContentFormatEntry_t &aFormatType)
For a URL, get format information describing it (extension, mime type, etc.
const PRInt32 K
NS_IMETHODIMP OnEnumeratedItem(sbIMediaList *aMediaList, sbIMediaItem *aItem, PRUint16 *_retval)
const char * propName
const nsIDOMWindow
static nsresult GetCodecAndContainerForMimeType(nsCString aMimeType, nsCString &aContainer, nsCString &aCodec, nsCString &aVideoType, nsCString &aAudioType)
NS_IMETHODIMP OnEnumerationEnd(sbIMediaList *aMediaList, nsresult aStatusCode)
#define SB_PROPERTY_OUTERGUID
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)
static nsresult GetDeviceWriteLength(sbIDeviceLibrary *aDeviceLibrary, sbIMediaItem *aMediaItem, PRUint64 *aWriteLength)
nsresult UnignoreMediaItem(sbIMediaItem *aItem)
static bool ArePlaylistsSupported(sbIDevice *aDevice)
const unsigned short CONTENTTYPE_VIDEO
BogusChannel prototype contentLength
const unsigned short ENUMERATIONTYPE_SNAPSHOT
This flag means that the list being enumerated is a copy that may become out of date.
void SetIgnore(PRBool aIgnore)
#define LOG(args)
function num(elem, prop)
static nsresult GetFormatTypeForURI(nsIURI *aURI, sbExtensionToContentFormatEntry_t &aFormatType)
For a URI, get format information describing it (extension, mime type, etc.
this _dialogInput val(dateText)
static nsresult GetFormatTypeForItem(sbIMediaItem *aItem, sbExtensionToContentFormatEntry_t &aFormatType, PRUint32 &aBitRate, PRUint32 &aSampleRate)
For a media item, get format information describing it (extension, mime type, etc.
char const * VideoType
Definition: sbDeviceUtils.h:59
Definition: sbDeviceUtils.h:54
static bool ShouldLogDeviceInfo()
#define SB_PROPERTY_ORIGIN_IS_IN_MAIN_LIBRARY
static nsresult GetSyncItemInLibrary(sbIMediaItem *aMediaItem, sbILibrary *aTargetLibrary, sbIMediaItem **aSyncItem)
GstMessage * message
Media library abstraction.
Definition: sbILibrary.idl:82
#define SB_PROPERTY_ARTISTNAME
static nsCString GetDeviceIdentifier(sbIDevice *aDevice)
char const * MimeType
Definition: sbDeviceUtils.h:56
nsresult SetIgnoreMediaListListeners(PRBool aIgnoreListener)
_updateDatepicker height
static nsresult GetMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
return!aWindow arguments!aWindow arguments[0]
sbExtensionToContentFormatEntry_t const MAP_FILE_EXTENSION_CONTENT_FORMAT[]
nsresult IgnoreMediaItem(sbIMediaItem *aItem)
static nsresult DeleteByProperty(sbIMediaList *aMediaList, nsAString const &aProperty, nsAString const &aValue)
PRUint32 TranscodeType
Definition: sbDeviceUtils.h:62
nsresult SetIgnoreLibraryListener(PRBool aIgnoreListener)
static PRBool IsMediaListContentTypeSupported(sbIDevice *aDevice, PRUint16 aListContentType)
static nsresult DoesItemNeedTranscoding(sbExtensionToContentFormatEntry_t &aFormatType, PRUint32 &aBitRate, PRUint32 &aSampleRate, sbIDevice *aDevice, bool &aNeedsTranscoding)
Determine if an item needs transcoding.
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceUtilsBulkSetPropertyEnumerationListener, sbIMediaListEnumerationListener)
#define SB_PROPERTY_ALBUMNAME
boolean IsValueInRange(in long aValue)
#define TRACE(args)
static nsresult GetDeviceLibraryForLibrary(sbIDevice *aDevice, sbILibrary *aLibrary, sbIDeviceLibrary **_retval)
long GetValue(in unsigned long aIndex)
T ** StartAssignment()
PRUint32 ContentType
Definition: sbDeviceUtils.h:61
Interface that defines a single item of media in the system.
static nsresult GetAudioMimeTypeForFormatTypes(const nsAString &aContainer, const nsAString &aCodec, nsAString &aMimeType)
static nsresult GetMediaSettings(sbIDeviceLibrary *aDevLib, PRUint32 aMediaType, sbIDeviceLibraryMediaSyncSettings **aMediaSettings)
static nsresult GetMgmtTypeForMedia(sbIDeviceLibrary *aDevLib, PRUint32 aMediaType, PRUint32 &aMgmtType)
#define SB_PROPERTY_AVAILABILITY
#define min(a, b)
static nsresult DeleteUnavailableItems(sbIMediaList *aMediaList)
#define SB_PROPERTY_CONTENTURL
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
#define SONGBIRD_DEVICECAPSCOMPATIBILITY_CONTRACTID
static bool IsValueInRange(PRInt32 aValue, sbIDevCapRange *aRange)
_getSelectedPageStyle s i
static nsresult GetTranscodingConfigurator(PRUint32 aTranscodeType, sbIDeviceTranscodingConfigurator **aConfigurator)
static nsresult GetContainerFormatAndCodec(nsISupports *aFormatType, PRUint32 aContentType, nsAString &aContainerFormat, nsAString &aVideoType, nsAString &aAudioType, nsAString &aCodec, sbIDevCapRange **aBitRateRange=nsnull, sbIDevCapRange **aSampleRateRange=nsnull)
nsresult GetMainLibraryId(nsAString &aLibraryId)
static nsresult GetDeviceLibrary(nsAString const &aDeviceLibGuid, sbIDevice *aDevice, sbIDeviceLibrary **aDeviceLibrar)
static nsresult AddSupportedFileExtensions(sbIDevice *aDevice, PRUint32 aContentType, nsTArray< nsString > &aFileExtensionList)
static PRInt32 ParseInteger(nsAString const &aValue)
var file
char const * ContainerFormat
Definition: sbDeviceUtils.h:57
function Extension(aItem)
PRBool GetBoolPref(const char *aKey, PRBool aDefault)
Definition: sbPrefBranch.h:109