sbMediaInspector.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-2009 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 
25 // local includes
26 #include "sbMediaInspector.h"
27 
28 // Mozilla includes
29 #include <nsComponentManagerUtils.h>
30 #include <nsISimpleEnumerator.h>
31 #include <nsIWritablePropertyBag2.h>
32 
33 #include <sbArrayUtils.h>
34 #include <sbMemoryUtils.h>
35 
36 #define SB_PROPERTYBAG_CONTRACTID "@songbirdnest.com/moz/xpcom/sbpropertybag;1"
37 
38 /* Implementation file */
42 
43 sbMediaFormatContainer::sbMediaFormatContainer(nsAString const & aContainerType) :
44  mContainerType(aContainerType)
45 {
46  mProperties = do_CreateInstance(SB_PROPERTYBAG_CONTRACTID);
47 }
48 
49 sbMediaFormatContainer::~sbMediaFormatContainer()
50 {
51 }
52 
53 /* readonly attribute AString containerType; */
54 NS_IMETHODIMP
55 sbMediaFormatContainer::GetContainerType(nsAString & aContainerType)
56 {
57  aContainerType = mContainerType;
58  return NS_OK;
59 }
60 
61 /* readonly attribute nsIPropertyBag properties; */
62 NS_IMETHODIMP
63 sbMediaFormatContainer::GetProperties(nsIPropertyBag * *aProperties)
64 {
65  NS_ENSURE_STATE(mProperties);
66 
67  return sbReturnCOMPtr(mProperties, aProperties);
68 }
69 
70 /* void setContainerType (in AString aContainerType); */
71 NS_IMETHODIMP
72 sbMediaFormatContainer::SetContainerType(const nsAString & aContainerType)
73 {
74  mContainerType = aContainerType;
75  return NS_OK;
76 }
77 
78 /* void setProperties (in nsIPropertyBag aProperties); */
79 NS_IMETHODIMP
80 sbMediaFormatContainer::SetProperties(nsIPropertyBag *aProperties)
81 {
82  // MSVC can't figure out the templates, so we have to tell the compiler
83  // explicitly what types to use
84  nsresult rv = CallQueryInterface<nsIPropertyBag, nsIWritablePropertyBag>
85  (aProperties, getter_AddRefs(mProperties));
86  NS_ENSURE_SUCCESS(rv, rv);
87  return NS_OK;
88 }
89 
93 
95  mVideoWidth(0),
96  mVideoHeight(0),
97  mBitRate(0)
98 {
99  mProperties = do_CreateInstance(SB_PROPERTYBAG_CONTRACTID);
100 }
101 
102 sbMediaFormatVideo::~sbMediaFormatVideo()
103 {
104  /* destructor code */
105 }
106 
107 /* readonly attribute AString videoType; */
108 NS_IMETHODIMP
109 sbMediaFormatVideo::GetVideoType(nsAString & aVideoType)
110 {
111  aVideoType = mVideoType;
112 
113  return NS_OK;
114 }
115 
116 /* readonly attribute long videoWidth; */
117 NS_IMETHODIMP
118 sbMediaFormatVideo::GetVideoWidth(PRInt32 *aVideoWidth)
119 {
120  NS_ENSURE_ARG_POINTER(aVideoWidth);
121 
122  *aVideoWidth = mVideoWidth;
123 
124  return NS_OK;
125 }
126 
127 /* readonly attribute long videoHeight; */
128 NS_IMETHODIMP
129 sbMediaFormatVideo::GetVideoHeight(PRInt32 *aVideoHeight)
130 {
131  NS_ENSURE_ARG_POINTER(aVideoHeight);
132 
133  *aVideoHeight = mVideoHeight;
134 
135  return NS_OK;
136 }
137 
138 /* void getVideoPAR (out unsigned long aNumerator, out unsigned long aDenominator); */
139 NS_IMETHODIMP
140 sbMediaFormatVideo::GetVideoPAR(PRUint32 *aNumerator, PRUint32 *aDenominator)
141 {
142  NS_ENSURE_ARG_POINTER(aNumerator);
143  NS_ENSURE_ARG_POINTER(aDenominator);
144 
145  *aNumerator = mVideoPAR.Numerator();
146  *aDenominator = mVideoPAR.Denominator();
147 
148  return NS_OK;
149 }
150 
151 NS_IMETHODIMP
152 sbMediaFormatVideo::GetVideoFrameRate(PRUint32 *aNumerator, PRUint32 *aDenominator)
153 {
154  NS_ENSURE_ARG_POINTER(aNumerator);
155  NS_ENSURE_ARG_POINTER(aDenominator);
156 
157  *aNumerator = mVideoFrameRate.Numerator();
158  *aDenominator = mVideoFrameRate.Denominator();
159 
160  return NS_OK;
161 }
162 
163 NS_IMETHODIMP
164 sbMediaFormatVideo::GetBitRate(PRInt32 *aBitRate)
165 {
166  NS_ENSURE_ARG_POINTER(aBitRate);
167 
168  *aBitRate = mBitRate;
169 
170  return NS_OK;
171 }
172 
173 /* readonly attribute nsIPropertyBag properties; */
174 NS_IMETHODIMP
175 sbMediaFormatVideo::GetProperties(nsIPropertyBag * *aProperties)
176 {
177  NS_ENSURE_STATE(mProperties);
178 
179  return sbReturnCOMPtr(mProperties, aProperties);
180 }
181 
182 /* void setVideoType (in AString aVideoType); */
183 NS_IMETHODIMP
184 sbMediaFormatVideo::SetVideoType(const nsAString & aVideoType)
185 {
186  mVideoType = aVideoType;
187  return NS_OK;
188 }
189 
190 /* void setVideoWidth (in long aVideoWidth); */
191 NS_IMETHODIMP
192 sbMediaFormatVideo::SetVideoWidth(PRInt32 aVideoWidth)
193 {
194  mVideoWidth = aVideoWidth;
195  return NS_OK;
196 }
197 
198 /* void setVideoHeight (in long aVideoHeight); */
199 NS_IMETHODIMP
200 sbMediaFormatVideo::SetVideoHeight(PRInt32 aVideoHeight)
201 {
202  mVideoHeight = aVideoHeight;
203  return NS_OK;
204 }
205 
206 /* void setVideoPAR (in unsigned long aNumerator, in unsigned long aDenominator); */
207 NS_IMETHODIMP
208 sbMediaFormatVideo::SetVideoPAR(PRUint32 aNumerator, PRUint32 aDenominator)
209 {
210  mVideoPAR = sbFraction(aNumerator, aDenominator);
211  return NS_OK;
212 }
213 
214 /* void setVideoFrameRate (in unsigned long aNumerator, in unsigned long aDenominator); */
215 NS_IMETHODIMP
216 sbMediaFormatVideo::SetVideoFrameRate(PRUint32 aNumerator, PRUint32 aDenominator)
217 {
218  mVideoFrameRate = sbFraction(aNumerator, aDenominator);
219  return NS_OK;
220 }
221 
222 /* void setBitRate (in long aBitRate); */
223 NS_IMETHODIMP
224 sbMediaFormatVideo::SetBitRate(PRInt32 aBitRate)
225 {
226  mBitRate = aBitRate;
227  return NS_OK;
228 }
229 
230 /* void setProperties (in nsIPropertyBag aProperties); */
231 NS_IMETHODIMP
232 sbMediaFormatVideo::SetProperties(nsIPropertyBag *aProperties)
233 {
234  // MSVC can't figure out the templates, so we have to tell the compiler
235  // explicitly what types to use
236  nsresult rv = CallQueryInterface<nsIPropertyBag, nsIWritablePropertyBag>
237  (aProperties, getter_AddRefs(mProperties));
238  NS_ENSURE_SUCCESS(rv, rv);
239  return NS_OK;
240 }
241 
245 
247  mBitRate(0),
248  mSampleRate(0),
249  mChannels(0)
250 {
251  mProperties = do_CreateInstance(SB_PROPERTYBAG_CONTRACTID);
252 }
253 
254 sbMediaFormatAudio::~sbMediaFormatAudio()
255 {
256  /* destructor code */
257 }
258 
259 /* readonly attribute string audioType; */
260 NS_IMETHODIMP
261 sbMediaFormatAudio::GetAudioType(nsAString & aAudioType)
262 {
263  aAudioType = mAudioType;
264 
265  return NS_OK;
266 }
267 
268 /* readonly attribute long bitrate; */
269 NS_IMETHODIMP
270 sbMediaFormatAudio::GetBitRate(PRInt32 *aBitRate)
271 {
272  NS_ENSURE_ARG_POINTER(aBitRate);
273 
274  *aBitRate = mBitRate;
275 
276  return NS_OK;
277 }
278 
279 /* readonly attribute long sampleRate; */
280 NS_IMETHODIMP
281 sbMediaFormatAudio::GetSampleRate(PRInt32 *aSampleRate)
282 {
283  NS_ENSURE_ARG_POINTER(aSampleRate);
284 
285  *aSampleRate = mSampleRate;
286 
287  return NS_OK;
288 }
289 
290 /* readonly attribute long channels; */
291 NS_IMETHODIMP
292 sbMediaFormatAudio::GetChannels(PRInt32 *aChannels)
293 {
294  NS_ENSURE_ARG_POINTER(aChannels);
295 
296  *aChannels = mChannels;
297 
298  return NS_OK;
299 }
300 
301 /* readonly attribute nsIPropertyBag properties; */
302 NS_IMETHODIMP
303 sbMediaFormatAudio::GetProperties(nsIPropertyBag * *aProperties)
304 {
305  NS_ENSURE_ARG_POINTER(aProperties);
306 
307  return sbReturnCOMPtr(mProperties, aProperties);
308 }
309 
310 /* void setAudioType (in AString aAudioType); */
311 NS_IMETHODIMP
312 sbMediaFormatAudio::SetAudioType(const nsAString & aAudioType)
313 {
314  mAudioType = aAudioType;
315  return NS_OK;
316 }
317 
318 /* void setBitRate (in long aBitRate); */
319 NS_IMETHODIMP
320 sbMediaFormatAudio::SetBitRate(PRInt32 aBitRate)
321 {
322  mBitRate = aBitRate;
323  return NS_OK;
324 }
325 
326 /* void setSampleRate (in long aSampleRate); */
327 NS_IMETHODIMP
328 sbMediaFormatAudio::SetSampleRate(PRInt32 aSampleRate)
329 {
330  mSampleRate = aSampleRate;
331  return NS_OK;
332 }
333 
334 /* void setChannels (in long aChannels); */
335 NS_IMETHODIMP
336 sbMediaFormatAudio::SetChannels(PRInt32 aChannels)
337 {
338  mChannels = aChannels;
339  return NS_OK;
340 }
341 
342 /* void setProperties (in nsIPropertyBag aProperties); */
343 NS_IMETHODIMP sbMediaFormatAudio::SetProperties(nsIPropertyBag *aProperties)
344 {
345  // MSVC can't figure out the templates, so we have to tell the compiler
346  // explicitly what types to use
347  nsresult rv = CallQueryInterface<nsIPropertyBag, nsIWritablePropertyBag>
348  (aProperties, getter_AddRefs(mProperties));
349  NS_ENSURE_SUCCESS(rv, rv);
350  return NS_OK;
351 }
352 
356 
358  sbIMediaFormatVideo * aVideoStream) :
359  mContainer(aContainer),
360  mVideoStream(aVideoStream)
361 {
362 
363 }
364 
365 sbMediaFormat::~sbMediaFormat()
366 {
367  /* destructor code */
368 }
369 
370 /* readonly attribute sbIMediaFormatContainer container; */
371 NS_IMETHODIMP
372 sbMediaFormat::GetContainer(sbIMediaFormatContainer * *aContainer)
373 {
374  NS_ENSURE_STATE(mContainer);
375 
376  return sbReturnCOMPtr(mContainer, aContainer);
377 }
378 
379 /* readonly attribute sbIMediaFormatVideo videoStream; */
380 NS_IMETHODIMP
381 sbMediaFormat::GetVideoStream(sbIMediaFormatVideo * *aVideoStream)
382 {
383  return sbReturnCOMPtr(mVideoStream, aVideoStream);
384 }
385 
386 /* readonly attribute nsIArray audioStream; */
387 NS_IMETHODIMP
388 sbMediaFormat::GetAudioStream(sbIMediaFormatAudio * *aAudioStream)
389 {
390  return sbReturnCOMPtr(mAudioStream, aAudioStream);
391 }
392 
393 /* void setContainer (in sbIMediaFormatContainer aContainer); */
394 NS_IMETHODIMP
395 sbMediaFormat::SetContainer(sbIMediaFormatContainer *aContainer)
396 {
397  mContainer = aContainer;
398  return NS_OK;
399 }
400 
401 /* void setVideoStream (in sbIMediaFormatVideo aFormat); */
402 NS_IMETHODIMP
403 sbMediaFormat::SetVideoStream(sbIMediaFormatVideo *aFormat)
404 {
405  mVideoStream = aFormat;
406  return NS_OK;
407 }
408 
409 /* void setAudioStream (in sbIMediaFormatAudio aFormat); */
410 NS_IMETHODIMP
411 sbMediaFormat::SetAudioStream(sbIMediaFormatAudio *aFormat)
412 {
413  mAudioStream = aFormat;
414  return NS_OK;
415 }
416 
return NS_OK
nsresult sbReturnCOMPtr(COMPtr &aPtr, ReturnType **aReturn)
nsCOMPtr< nsIArray > mProperties
void SetVideoFrameRate(sbFraction const &aVideoFrameRate)
#define SB_PROPERTYBAG_CONTRACTID
PRUint32 Numerator() const
Definition: sbFraction.h:136
NS_IMPL_THREADSAFE_ISUPPORTS2(sbMediaFormatContainer, sbIMediaFormatContainer, sbIMediaFormatContainerMutable) sbMediaFormatContainer
void SetVideoPAR(sbFraction const &aVideoPar)
PRUint32 Denominator() const
Definition: sbFraction.h:144
nsresult SetProperties(nsIArray *aProperties)