sbDeviceSupportsItemHelper.cpp
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
26 
27 #include <sbIDevice.h>
28 #include <sbIMediaInspector.h>
29 #include <sbIMediaItem.h>
30 
31 #include <nsNetError.h> // for NS_ERROR_IN_PROGRESS
32 
33 #include "sbDeviceUtils.h"
34 
37 
39  : mDevice(nsnull)
40 {
41  /* member initializers and constructor code */
42 }
43 
44 sbDeviceSupportsItemHelper::~sbDeviceSupportsItemHelper()
45 {
46  if (mDevice) {
47  NS_ISUPPORTS_CAST(sbIDevice*, mDevice)->Release();
48  mDevice = nsnull;
49  }
50 }
51 
52 /***** sbIJobProgressListener *****/
53 /* void onJobProgress (in sbIJobProgress aJobProgress); */
54 NS_IMETHODIMP
55 sbDeviceSupportsItemHelper::OnJobProgress(sbIJobProgress *aJobProgress)
56 {
57  nsresult rv;
58 
59  NS_ENSURE_ARG_POINTER(aJobProgress);
60  NS_ENSURE_STATE(mCallback);
61 
62  PRBool supported = PR_FALSE;
63 
64  PRUint16 status;
65  rv = aJobProgress->GetStatus(&status);
66  NS_ENSURE_SUCCESS(rv, rv);
67 
68  switch (status) {
70  nsCOMPtr<sbIMediaFormat> mediaFormat;
71  rv = mInspector->GetMediaFormat(getter_AddRefs(mediaFormat));
72  NS_ENSURE_SUCCESS(rv, rv);
73  bool needsTranscoding;
75  mediaFormat,
76  mDevice,
77  needsTranscoding);
78 
79  supported = (NS_SUCCEEDED(rv) && !needsTranscoding);
80  mCallback->OnSupportsMediaItem(mItem, supported); // ignore results
81  break;
82  }
84  // failed to get the format for the item; assume not supported
85  mCallback->OnSupportsMediaItem(mItem, supported); // ignore results
86  break;
87  default:
88  // incomplete, keep going
89  return NS_OK;
90  }
91 
92  // cache transcoding support by transcode type
95  (supported == PR_TRUE) ?
97  }
100  (supported == PR_TRUE) ?
102  }
103 
104  // cleanup
105  rv = aJobProgress->RemoveJobProgressListener(this);
106  NS_ENSURE_SUCCESS(rv, rv);
107 
108  return NS_OK;
109 }
110 
111 /***** sbDeviceSupportsItemHelper *****/
112 nsresult
114  sbBaseDevice* aDevice,
116 {
117  NS_ENSURE_ARG_POINTER(aItem);
118  NS_ENSURE_ARG_POINTER(aDevice);
119  NS_ENSURE_ARG_POINTER(aCallback);
120 
121  mItem = aItem;
122  mCallback = aCallback;
123  mDevice = aDevice;
124  NS_ISUPPORTS_CAST(sbIDevice*, mDevice)->AddRef();
125  return NS_OK;
126 }
127 
128 
129 nsresult
131  PRUint32 aTranscodeType)
132 {
133  NS_ENSURE_ARG_POINTER(aInspector);
134 
135  nsresult rv;
136 
137  mInspector = aInspector;
138  mTranscodeType = aTranscodeType;
139 
140  nsCOMPtr<sbIJobProgress> progress = do_QueryInterface(aInspector, &rv);
141  NS_ENSURE_SUCCESS(rv, rv);
142  rv = progress->AddJobProgressListener(this);
143  NS_ENSURE_SUCCESS(rv, rv);
144  return NS_OK;
145 }
146 
147 void
149 {
150  nsresult rv;
151  PRBool result;
152  rv = mDevice->SupportsMediaItem(mItem, this, PR_FALSE, &result);
153  if (rv != NS_ERROR_IN_PROGRESS) {
154  // this was synchronous, notify the callback
155  if (NS_FAILED(rv)) {
156  result = PR_FALSE;
157  }
158  mCallback->OnSupportsMediaItem(mItem, result);
159  }
160 }
161 
return NS_OK
Generic interface for exposing long running jobs to the UI.
nsresult InitJobProgress(sbIMediaInspector *aInspector, PRUint32 aTranscodeType)
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceSupportsItemHelper, sbIJobProgressListener) sbDeviceSupportsItemHelper
const unsigned long TRANSCODE_TYPE_AUDIO
PRUint32 mCanTranscodeAudio
Definition: sbBaseDevice.h:709
const unsigned short STATUS_SUCCEEDED
Constant indicating that the job has completed.
nsCOMPtr< sbIDeviceSupportsItemCallback > mCallback
const unsigned long TRANSCODE_TYPE_AUDIO_VIDEO
NS_IMETHOD SupportsMediaItem(sbIMediaItem *aMediaItem, sbIDeviceSupportsItemCallback *aCallback)
nsCOMPtr< sbIMediaInspector > mInspector
static nsresult DoesItemNeedTranscoding(sbExtensionToContentFormatEntry_t &aFormatType, PRUint32 &aBitRate, PRUint32 &aSampleRate, sbIDevice *aDevice, bool &aNeedsTranscoding)
Determine if an item needs transcoding.
nsresult Init(sbIMediaItem *aItem, sbBaseDevice *aDevice, sbIDeviceSupportsItemCallback *aCallback)
Implemented to receive notifications from sbIJobProgress interfaces.
Interface that defines a single item of media in the system.
const unsigned short STATUS_FAILED
Constant indicating that the job has completed with errors.
PRUint32 mCanTranscodeVideo
Definition: sbBaseDevice.h:710