sbDeviceUtils.h
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 #ifndef __SBDEVICEUTILS__H__
27 #define __SBDEVICEUTILS__H__
28 
29 #include <nscore.h>
30 #include <nsCOMPtr.h>
31 #include <nsIMutableArray.h>
32 #include <nsStringGlue.h>
33 #include <prlog.h>
34 
35 #include <sbIMediaListListener.h>
36 #include <sbITranscodingConfigurator.h>
37 
38 #include "sbBaseDevice.h"
39 #include "sbIDeviceStatus.h"
40 
41 // Mozilla forwards
42 class nsIFile;
43 class nsIMutableArray;
44 
45 // Songbird forwards
48 class sbIMediaFormat;
49 
55  char const * Extension;
56  char const * MimeType;
57  char const * ContainerFormat;
58  char const * Codec;
59  char const * VideoType;
60  char const * AudioType;
61  PRUint32 ContentType;
62  PRUint32 TranscodeType;
63 };
64 
69 {
70 public:
80  static nsresult GetOrganizedPath(/* in */ nsIFile *aParent,
81  /* in */ sbIMediaItem *aItem,
82  nsIFile **_retval);
83 
97  static nsresult BulkSetProperty(sbIMediaList *aMediaList,
98  const nsAString& aPropertyId,
99  const nsAString& aPropertyValue,
100  sbIPropertyArray* aPropertyFilter = nsnull,
101  PRInt32 *aAbortFlag = nsnull);
102 
109  static nsresult DeleteByProperty(sbIMediaList *aMediaList,
110  nsAString const & aProperty,
111  nsAString const & aValue);
117  static nsresult DeleteUnavailableItems(/* in */ sbIMediaList *aMediaList);
118 
123  static nsresult GetDeviceLibraryForItem(/* in */ sbIDevice* aDevice,
124  /* in */ sbIMediaItem* aItem,
125  /* out */ sbIDeviceLibrary** _retval);
126 
137  static nsresult NewDeviceLibraryURI(sbIDeviceLibrary* aDeviceLibrary,
138  const nsCString& aSpec,
139  nsIURI** aURI);
140 
145  static nsresult GetDeviceLibraryForLibrary(
146  /* in */ sbIDevice* aDevice,
147  /* in */ sbILibrary* aLibrary,
148  /* out */ sbIDeviceLibrary** _retval);
149 
159  static nsresult GetMediaItemByDevicePersistentId
160  (/* in */ sbILibrary* aLibrary,
161  /* in */ const nsAString& aDevicePersistentId,
162  /* out */ sbIMediaItem** aItem);
163 
175  (/* in */ sbILibrary* aLibrary,
176  /* in */ const nsAString& aDevicePersistentId,
177  /* out */ sbIMediaItem** aItem);
178 
188  static nsresult GetDeviceWriteLength(sbIDeviceLibrary* aDeviceLibrary,
189  sbIMediaItem* aMediaItem,
190  PRUint64* aWriteLength);
191 
206  static nsresult QueryUserSpaceExceeded
207  (/* in */ sbIDevice* aDevice,
208  /* in */ sbIDeviceLibrary* aLibrary,
209  /* in */ PRInt64 aSpaceNeeded,
210  /* in */ PRInt64 aSpaceAvailable,
211  /* out */ PRBool* aAbort);
212 
220  static nsresult QueryUserAbortRip(PRBool* aAbort);
221 
228  static nsresult QueryUserViewErrors(sbIDevice* aDevice);
229 
235  static nsresult ShowDeviceErrors(sbIDevice* aDevice);
236 
243  static nsresult SetLinkedSyncPartner(sbIDevice* aDevice);
244 
248  static bool ArePlaylistsSupported(sbIDevice * aDevice);
249 
254  static nsresult GetFormatTypeForItem(
255  sbIMediaItem * aItem,
256  sbExtensionToContentFormatEntry_t & aFormatType,
257  PRUint32 & aBitRate,
258  PRUint32 & aSampleRate);
259 
264  static nsresult GetFormatTypeForItem(
265  sbIMediaItem * aItem,
266  sbExtensionToContentFormatEntry_t & aFormatType,
267  PRUint32 & aSampleRate,
268  PRUint32 & aChannels,
269  PRUint32 & aBitRate);
270 
275  static nsresult GetFormatTypeForURI
276  (nsIURI* aURI,
277  sbExtensionToContentFormatEntry_t& aFormatType);
278 
283  static nsresult GetFormatTypeForURL
284  (const nsAString& aURL,
285  sbExtensionToContentFormatEntry_t& aFormatType);
286 
291  static nsresult GetFormatTypesForMimeType
292  (const nsAString& aMimeType,
293  const PRUint32 aContentType,
294  nsTArray<sbExtensionToContentFormatEntry_t>& aFormatTypeList);
295 
304  static nsresult GetAudioMimeTypeForFormatTypes(const nsAString& aContainer,
305  const nsAString& aCodec,
306  nsAString& aMimeType);
307 
317  static nsresult
319  PRUint32 & aBitRate,
320  PRUint32 & aSampleRate,
321  sbIDevice * aDevice,
322  bool & aNeedsTranscoding);
323 
333  static nsresult DoesItemNeedTranscoding(PRUint32 aTranscodeType,
334  sbIMediaFormat * aMediaFormat,
335  sbIDevice * aDevice,
336  bool & aNeedsTranscoding);
341  static nsresult GetTranscodeProfiles(PRUint32 aType, nsIArray ** aProfiles);
342 
350  static nsresult GetSupportedTranscodeProfiles(PRUint32 aType,
351  sbIDevice * aDevice,
352  nsIArray ** aProfiles);
353 
358  static nsresult ApplyPropertyPreferencesToProfile(sbIDevice *aDevice,
359  nsIArray *aPropertyArray,
360  nsString aPrefNameBase);
361 
364  static nsresult GetTranscodedFileExtension(sbITranscodeProfile *aProfile,
365  nsCString &aExtension);
366 
370  static nsresult GetCodecAndContainerForMimeType(nsCString aMimeType,
371  nsCString &aContainer,
372  nsCString &aCodec,
373  nsCString &aVideoType,
374  nsCString &aAudioType);
375 
376  /* Get an appropriate transcoding configurator for this type of transcoding */
377  static nsresult GetTranscodingConfigurator(
378  PRUint32 aTranscodeType,
379  sbIDeviceTranscodingConfigurator **aConfigurator);
380 
381 
388  static bool
389  IsItemDRMProtected(sbIMediaItem * aMediaItem);
390 
397  static nsresult
398  GetDeviceCapsTypeFromListContentType(PRUint16 aListContentType,
399  PRUint32 *aContentType,
400  PRUint32 *aFunctionType);
401 
408  static nsresult
410  PRUint32 *aContentType,
411  PRUint32 *aFunctionType);
412 
419  static PRBool
421  sbIMediaItem *aMediaItem);
422 
429  static PRBool
431  PRUint16 aListContentType);
432 
442  static nsresult AddSupportedFileExtensions
443  (sbIDevice* aDevice,
444  PRUint32 aContentType,
445  nsTArray<nsString>& aFileExtensionList);
446 
454  static nsresult GetMediaSettings(
455  sbIDeviceLibrary * aDevLib,
456  PRUint32 aMediaType,
457  sbIDeviceLibraryMediaSyncSettings ** aMediaSettings);
458 
467  static nsresult GetMgmtTypeForMedia(sbIDeviceLibrary * aDevLib,
468  PRUint32 aMediaType,
469  PRUint32 & aMgmtType);
470 
477  static nsresult GetDeviceLibrary(nsAString const & aDeviceLibGuid,
478  sbIDevice * aDevice,
479  sbIDeviceLibrary ** aDeviceLibrar);
480 
487  static nsresult GetDeviceLibrary(nsAString const & aDevLibGuid,
488  nsID const * aDeviceID,
489  sbIDeviceLibrary ** aDeviceLibrary);
490 
498  static nsresult SetOriginIsInMainLibrary(sbIMediaItem * aMediaItem,
499  sbILibrary * aDevLibrary,
500  PRBool aMark);
501 
512 static nsresult GetSyncItemInLibrary(sbIMediaItem* aMediaItem,
513  sbILibrary* aTargetLibrary,
514  sbIMediaItem** aSyncItem);
515 
516 #ifdef PR_LOGGING
517 
520  static nsresult
521  LogDeviceCapabilities(sbIDeviceCapabilities *aDeviceCaps,
522  PRLogModuleInfo *aLogModule);
523 #endif
524 
530  static bool ShouldLogDeviceInfo();
531 
532  static nsCString GetDeviceIdentifier(sbIDevice * aDevice);
533 };
534 
539 {
540 public:
542  {
544  LIBRARY = 2,
545  ALL = 3
546  };
551  PRUint32 aListenerType = ALL) :
552  mDevice(aDevice),
553  mIgnoring(PR_FALSE),
554  mListenerType(aListenerType),
555  mMediaItem(nsnull) {
556 
557  SetIgnore(PR_TRUE);
558  }
563  sbIMediaItem * aItem);
564 
569 
573  void SetIgnore(PRBool aIgnore);
574 private:
575  sbBaseDevice * mDevice; // Non-owning pointer
576  PRBool mIgnoring;
577  PRUint32 mListenerType;
578  sbIMediaItem * mMediaItem; // nsCOMPtr required definition of sbIMediaItem
579 
580  // Prevent copying and assignment
582  sbDeviceListenerIgnore & operator =(sbDeviceListenerIgnore const &);
583 };
584 
587 extern PRUint32 const MAP_FILE_EXTENSION_CONTENT_FORMAT_LENGTH;
588 
589 #endif /* __SBDEVICEUTILS__H__ */
static nsresult GetTranscodeProfiles(PRUint32 aType, nsIArray **aProfiles)
static nsresult GetOriginMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
static nsresult GetTranscodedFileExtension(sbITranscodeProfile *aProfile, nsCString &aExtension)
sbExtensionToContentFormatEntry_t const MAP_FILE_EXTENSION_CONTENT_FORMAT[]
[UNIMPLEMENTED UNTIL AFTER 0.3]
static nsresult ShowDeviceErrors(sbIDevice *aDevice)
onPageChanged aValue
Definition: FeedWriter.js:1395
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)
static nsresult QueryUserAbortRip(PRBool *aAbort)
static nsresult QueryUserViewErrors(sbIDevice *aDevice)
static nsresult SetOriginIsInMainLibrary(sbIMediaItem *aMediaItem, sbILibrary *aDevLibrary, PRBool aMark)
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)
An object defining a transcoding profile.
sbDeviceListenerIgnore(sbBaseDevice *aDevice, PRUint32 aListenerType=ALL)
A brief description of the contents of this interface.
static nsresult QueryUserSpaceExceeded(sbIDevice *aDevice, sbIDeviceLibrary *aLibrary, PRInt64 aSpaceNeeded, PRInt64 aSpaceAvailable, PRBool *aAbort)
static nsresult GetOrganizedPath(nsIFile *aParent, sbIMediaItem *aItem, nsIFile **_retval)
static nsresult ApplyPropertyPreferencesToProfile(sbIDevice *aDevice, nsIArray *aPropertyArray, nsString aPrefNameBase)
char const * Extension
Definition: sbDeviceUtils.h:55
static nsresult GetSupportedTranscodeProfiles(PRUint32 aType, sbIDevice *aDevice, nsIArray **aProfiles)
static nsresult GetDeviceCapsTypeFromMediaItem(sbIMediaItem *aMediaItem, PRUint32 *aContentType, PRUint32 *aFunctionType)
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.
static nsresult GetCodecAndContainerForMimeType(nsCString aMimeType, nsCString &aContainer, nsCString &aCodec, nsCString &aVideoType, nsCString &aAudioType)
static nsresult GetDeviceWriteLength(sbIDeviceLibrary *aDeviceLibrary, sbIMediaItem *aMediaItem, PRUint64 *aWriteLength)
static bool ArePlaylistsSupported(sbIDevice *aDevice)
void SetIgnore(PRBool aIgnore)
static nsresult GetFormatTypeForURI(nsIURI *aURI, sbExtensionToContentFormatEntry_t &aFormatType)
For a URI, get format information describing it (extension, mime type, etc.
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()
static nsresult GetSyncItemInLibrary(sbIMediaItem *aMediaItem, sbILibrary *aTargetLibrary, sbIMediaItem **aSyncItem)
Media library abstraction.
Definition: sbILibrary.idl:82
static nsCString GetDeviceIdentifier(sbIDevice *aDevice)
char const * MimeType
Definition: sbDeviceUtils.h:56
static nsresult GetMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
static nsresult DeleteByProperty(sbIMediaList *aMediaList, nsAString const &aProperty, nsAString const &aValue)
PRUint32 TranscodeType
Definition: sbDeviceUtils.h:62
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.
static nsresult GetDeviceLibraryForLibrary(sbIDevice *aDevice, sbILibrary *aLibrary, sbIDeviceLibrary **_retval)
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)
static nsresult DeleteUnavailableItems(sbIMediaList *aMediaList)
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
static nsresult GetTranscodingConfigurator(PRUint32 aTranscodeType, sbIDeviceTranscodingConfigurator **aConfigurator)
PRUint32 const MAP_FILE_EXTENSION_CONTENT_FORMAT_LENGTH
static nsresult GetDeviceLibrary(nsAString const &aDeviceLibGuid, sbIDevice *aDevice, sbIDeviceLibrary **aDeviceLibrar)
static nsresult AddSupportedFileExtensions(sbIDevice *aDevice, PRUint32 aContentType, nsTArray< nsString > &aFileExtensionList)
char const * ContainerFormat
Definition: sbDeviceUtils.h:57