sbDeviceCapabilities.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 
25 #include "sbDeviceCapabilities.h"
27 
28 #include <algorithm>
29 
30 #include <nsArrayUtils.h>
31 #include <nsComponentManagerUtils.h>
32 #include <nsIClassInfoImpl.h>
33 #include <nsIMutableArray.h>
34 #include <nsIProgrammingLanguage.h>
35 #include <nsServiceManagerUtils.h>
36 
37 #include <sbDeviceUtils.h>
38 #include <sbMemoryUtils.h>
39 
43 
47 
48 NS_DECL_CLASSINFO(sbDeviceCapabilities)
49 NS_IMPL_THREADSAFE_CI(sbDeviceCapabilities)
50 
51 #include <prlog.h>
52 #include <prprf.h>
53 #include <prtime.h>
54 
59 #ifdef PR_LOGGING
60 static PRLogModuleInfo* gDeviceCapabilitiesLog = nsnull;
61 #define TRACE(args) PR_LOG(gDeviceCapabilitiesLog, PR_LOG_DEBUG, args)
62 #define LOG(args) PR_LOG(gDeviceCapabilitiesLog, PR_LOG_WARN, args)
63 #else
64 #define TRACE(args) /* nothing */
65 #define LOG(args) /* nothing */
66 #endif /* PR_LOGGING */
67 
69 isInitialized(false),
70 isConfigured(false)
71 {
72 #ifdef PR_LOGGING
73  if (!gDeviceCapabilitiesLog) {
74  gDeviceCapabilitiesLog = PR_NewLogModule("sbDeviceCapabilities");
75  }
76 #endif
77  TRACE(("sbDeviceCapabilities[0x%.8x] - Constructed", this));
78 }
79 
80 sbDeviceCapabilities::~sbDeviceCapabilities()
81 {
82  TRACE(("sbDeviceCapabilities[0x%.8x] - Destructed", this));
83  // Release all the format types...
84  PRInt32 count = mContentFormatTypes.Count();
85  for(PRInt32 i = 0; i < count; i++) {
86  FormatTypes *formatType =
87  static_cast<FormatTypes *>(mContentFormatTypes.ElementAt(i));
88  delete formatType;
89  }
90  mContentFormatTypes.Clear();
91 
92  count = mContentPreferredFormatTypes.Count();
93  for(PRInt32 i = 0; i < count; i++) {
94  FormatTypes *formatType =
95  static_cast<FormatTypes *>(mContentPreferredFormatTypes.ElementAt(i));
96  delete formatType;
97  }
99 }
100 
101 NS_IMETHODIMP
103 {
104  NS_ENSURE_TRUE(!isInitialized, NS_ERROR_ALREADY_INITIALIZED);
105 
106  nsresult rv = mContentTypes.Init();
107  NS_ENSURE_SUCCESS(rv, rv);
108 
109  rv = mSupportedMimeTypes.Init();
110  NS_ENSURE_SUCCESS(rv, rv);
111 
114  i++)
115  {
116  FormatTypes *newFormatTypes = new FormatTypes;
117  if (!newFormatTypes)
118  NS_ENSURE_SUCCESS(rv, NS_ERROR_OUT_OF_MEMORY);
119  rv = newFormatTypes->Init();
120  NS_ENSURE_SUCCESS(rv, rv);
121  rv = mContentFormatTypes.AppendElement(newFormatTypes) ?
122  NS_OK : NS_ERROR_FAILURE;
123  NS_ENSURE_SUCCESS(rv, rv);
124 
125  FormatTypes *newPreferredFormatTypes = new FormatTypes;
126  if (!newPreferredFormatTypes)
127  NS_ENSURE_SUCCESS(rv, NS_ERROR_OUT_OF_MEMORY);
128  rv = newPreferredFormatTypes->Init();
129  NS_ENSURE_SUCCESS(rv, rv);
130  rv = mContentPreferredFormatTypes.AppendElement(newPreferredFormatTypes) ?
131  NS_OK : NS_ERROR_FAILURE;
132  NS_ENSURE_SUCCESS(rv, rv);
133  }
134  mContentFormatTypes.Compact();
136 
137  isInitialized = PR_TRUE;
138  return NS_OK;
139 }
140 
141 NS_IMETHODIMP
142 sbDeviceCapabilities::ConfigureDone()
143 {
144  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
145  NS_ENSURE_TRUE(!isConfigured, NS_ERROR_ALREADY_INITIALIZED);
146 
147  /* set this so we are not called again */
148  isConfigured = true;
149  return NS_OK;
150 }
151 
152 NS_IMETHODIMP
153 sbDeviceCapabilities::SetFunctionTypes(PRUint32 *aFunctionTypes,
154  PRUint32 aFunctionTypesCount)
155 {
156  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
157  NS_ENSURE_TRUE(!isConfigured, NS_ERROR_ALREADY_INITIALIZED);
158 
159  for (PRUint32 arrayCounter = 0; arrayCounter < aFunctionTypesCount; ++arrayCounter) {
160  if (mFunctionTypes.IndexOf(aFunctionTypes[arrayCounter]) ==
161  mFunctionTypes.NoIndex) {
162  mFunctionTypes.AppendElement(aFunctionTypes[arrayCounter]);
163  }
164  }
165 
166  return NS_OK;
167 }
168 
169 NS_IMETHODIMP
170 sbDeviceCapabilities::SetEventTypes(PRUint32 *aEventTypes,
171  PRUint32 aEventTypesCount)
172 {
173  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
174  NS_ENSURE_TRUE(!isConfigured, NS_ERROR_ALREADY_INITIALIZED);
175 
176  for (PRUint32 arrayCounter = 0; arrayCounter < aEventTypesCount; ++arrayCounter) {
177  if (mSupportedEvents.IndexOf(aEventTypes[arrayCounter]) ==
178  mSupportedEvents.NoIndex) {
179  mSupportedEvents.AppendElement(aEventTypes[arrayCounter]);
180  }
181  }
182 
183  return NS_OK;
184 }
185 
186 
187 NS_IMETHODIMP
188 sbDeviceCapabilities::AddContentTypes(PRUint32 aFunctionType,
189  PRUint32 *aContentTypes,
190  PRUint32 aContentTypesCount)
191 {
192  NS_ENSURE_ARG_POINTER(aContentTypes);
193  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
194  NS_ENSURE_TRUE(!isConfigured, NS_ERROR_ALREADY_INITIALIZED);
195 
196  nsTArray<PRUint32> * nContentTypes = nsnull;
197  PRBool const found = mContentTypes.Get(aFunctionType, &nContentTypes);
198  if (!found) {
199  nContentTypes = new nsTArray<PRUint32>(aContentTypesCount);
200  }
201  NS_ASSERTION(nContentTypes, "nContentTypes should not be null");
202  for (PRUint32 arrayCounter = 0; arrayCounter < aContentTypesCount; ++arrayCounter) {
203  if (nContentTypes->IndexOf(aContentTypes[arrayCounter]) ==
204  nContentTypes->NoIndex) {
205  nContentTypes->AppendElement(aContentTypes[arrayCounter]);
206  }
207  }
208 
209  if (!found) {
210  mContentTypes.Put(aFunctionType, nContentTypes);
211  }
212 
213  return NS_OK;
214 }
215 
216 NS_IMETHODIMP
217 sbDeviceCapabilities::AddMimeTypes(PRUint32 aContentType,
218  const char * *aMimeTypes,
219  PRUint32 aMimeTypesCount)
220 {
221  NS_ENSURE_ARG_POINTER(aMimeTypes);
222  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
223  NS_ENSURE_TRUE(!isConfigured, NS_ERROR_ALREADY_INITIALIZED);
224 
225  nsTArray<nsCString> * nMimeTypes = nsnull;
226  PRBool const found = mSupportedMimeTypes.Get(aContentType, &nMimeTypes);
227  if (!found) {
228  nMimeTypes = new nsTArray<nsCString>(aMimeTypesCount);
229  }
230  NS_ASSERTION(nMimeTypes, "nMimeTypes should not be null");
231  for (PRUint32 arrayCounter = 0; arrayCounter < aMimeTypesCount; ++arrayCounter) {
232  nsCString mimeType(aMimeTypes[arrayCounter]);
233  if (nMimeTypes->IndexOf(mimeType) == nMimeTypes->NoIndex) {
234  nMimeTypes->AppendElement(aMimeTypes[arrayCounter]);
235  }
236  }
237 
238  if (!found) {
239  mSupportedMimeTypes.Put(aContentType, nMimeTypes);
240  }
241 
242  return NS_OK;
243 }
244 
245 NS_IMETHODIMP
246 sbDeviceCapabilities::AddFormatType(PRUint32 aContentType,
247  nsAString const & aMimeType,
248  nsISupports * aFormatType)
249 {
250  NS_ENSURE_ARG_POINTER(aFormatType);
251  NS_ENSURE_ARG_RANGE(aContentType,
253  sbIDeviceCapabilities::CONTENT_MAX_TYPES - 1);
254 
255  FormatTypes *formatType =
256  static_cast<FormatTypes *>(mContentFormatTypes.SafeElementAt(aContentType));
257  if (!formatType)
258  return NS_ERROR_NULL_POINTER;
259 
260  nsTArray<nsCOMPtr<nsISupports> > * formatTypes;
261  PRBool const found = formatType->Get(aMimeType, &formatTypes);
262  if (!found) {
263  formatTypes = new nsTArray<nsCOMPtr<nsISupports> >(1);
264  }
265 
266  formatTypes->AppendElement(aFormatType);
267 
268  if (!found) {
269  PRBool const added = formatType->Put(aMimeType, formatTypes);
270  NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
271  }
272 
273  return NS_OK;
274 }
275 
276 NS_IMETHODIMP
278  nsAString const & aMimeType,
279  nsISupports * aFormatType)
280 {
281  NS_ENSURE_ARG_POINTER(aFormatType);
282  NS_ENSURE_ARG_RANGE(aContentType,
284  sbIDeviceCapabilities::CONTENT_MAX_TYPES - 1);
285 
286  FormatTypes *formatType =
287  static_cast<FormatTypes *>(mContentPreferredFormatTypes.SafeElementAt(
288  aContentType));
289  if (!formatType)
290  return NS_ERROR_NULL_POINTER;
291 
292  nsTArray<nsCOMPtr<nsISupports> > * formatTypes;
293  PRBool const found = formatType->Get(aMimeType, &formatTypes);
294  if (!found) {
295  formatTypes = new nsTArray<nsCOMPtr<nsISupports> >(1);
296  }
297 
298  formatTypes->AppendElement(aFormatType);
299 
300  if (!found) {
301  PRBool const added = formatType->Put(aMimeType, formatTypes);
302  NS_ENSURE_TRUE(added, NS_ERROR_OUT_OF_MEMORY);
303  }
304 
305  return NS_OK;
306 }
307 
308 NS_IMETHODIMP
309 sbDeviceCapabilities::AddCapabilities(sbIDeviceCapabilities *aCapabilities)
310 {
311  NS_ENSURE_ARG_POINTER(aCapabilities);
312  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
313  NS_ENSURE_TRUE(!isConfigured, NS_ERROR_ALREADY_INITIALIZED);
314 
315  nsresult rv;
316 
317  PRUint32* functionTypes;
318  PRUint32 functionTypesCount;
319  rv = aCapabilities->GetSupportedFunctionTypes(&functionTypesCount,
320  &functionTypes);
321  NS_ENSURE_SUCCESS(rv, rv);
322  sbAutoNSMemPtr functionTypesPtr(functionTypes);
323 
324  rv = SetFunctionTypes(functionTypes, functionTypesCount);
325  NS_ENSURE_SUCCESS(rv, rv);
326 
327  for (PRUint32 functionTypeIndex = 0;
328  functionTypeIndex < functionTypesCount;
329  ++functionTypeIndex) {
330  PRUint32 functionType = functionTypes[functionTypeIndex];
331 
332  PRUint32* contentTypes;
333  PRUint32 contentTypesCount;
334  rv = aCapabilities->GetSupportedContentTypes(functionType,
335  &contentTypesCount,
336  &contentTypes);
337  NS_ENSURE_SUCCESS(rv, rv);
338  sbAutoNSMemPtr contentTypesPtr(contentTypes);
339 
340  rv = AddContentTypes(functionType, contentTypes, contentTypesCount);
341  NS_ENSURE_SUCCESS(rv, rv);
342 
343  for (PRUint32 contentTypeIndex = 0;
344  contentTypeIndex < contentTypesCount;
345  ++contentTypeIndex) {
346  PRUint32 contentType = contentTypes[contentTypeIndex];
347 
348  char** mimeTypes;
349  PRUint32 mimeTypesCount;
350  rv = aCapabilities->GetSupportedMimeTypes(contentType,
351  &mimeTypesCount,
352  &mimeTypes);
353  if (rv == NS_ERROR_NOT_AVAILABLE) {
354  continue;
355  }
356  NS_ENSURE_SUCCESS(rv, rv);
357  sbAutoNSArray<char*> autoMimeTypes(mimeTypes, mimeTypesCount);
358 
359  rv = AddMimeTypes(contentType,
360  const_cast<const char**>(mimeTypes),
361  mimeTypesCount);
362  NS_ENSURE_SUCCESS(rv, rv);
363 
364  for (PRUint32 mimeTypeIndex = 0;
365  mimeTypeIndex < mimeTypesCount;
366  ++mimeTypeIndex) {
367  nsAutoString mimeType;
368  mimeType.AssignLiteral(mimeTypes[mimeTypeIndex]);
369 
370  nsISupports** formatTypes;
371  PRUint32 formatTypeCount;
372  rv = aCapabilities->GetFormatTypes(contentType,
373  mimeType,
374  &formatTypeCount,
375  &formatTypes);
376  NS_ENSURE_SUCCESS(rv, rv);
377  sbAutoFreeXPCOMPointerArray<nsISupports> freeFormats(formatTypeCount,
378  formatTypes);
379  for (PRUint32 formatIndex = 0;
380  formatIndex < formatTypeCount;
381  formatIndex++)
382  {
383  nsCOMPtr<nsISupports> formatType = formatTypes[formatIndex];
384  rv = AddFormatType(contentType, mimeType, formatType);
385  NS_ENSURE_SUCCESS(rv, rv);
386  }
387  }
388  }
389  }
390 
391  PRUint32* supportedEvents;
392  PRUint32 supportedEventsCount;
393  rv = aCapabilities->GetSupportedEvents(&supportedEventsCount,
394  &supportedEvents);
395  NS_ENSURE_SUCCESS(rv, rv);
396  SetEventTypes(supportedEvents, supportedEventsCount);
397  NS_ENSURE_SUCCESS(rv, rv);
398 
399  return NS_OK;
400 }
401 
402 NS_IMETHODIMP
403 sbDeviceCapabilities::GetSupportedFunctionTypes(PRUint32 *aArrayCount,
404  PRUint32 **aFunctionTypes)
405 {
406  NS_ENSURE_ARG_POINTER(aArrayCount);
407  NS_ENSURE_ARG_POINTER(aFunctionTypes);
408  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
409  NS_ENSURE_TRUE(isConfigured, NS_ERROR_NOT_INITIALIZED);
410 
411  PRUint32 arrayLen = mFunctionTypes.Length();
412  PRUint32* outArray = (PRUint32*)NS_Alloc(arrayLen * sizeof(PRUint32));
413  NS_ENSURE_TRUE(outArray, NS_ERROR_OUT_OF_MEMORY);
414 
415  for (PRUint32 arrayCounter = 0; arrayCounter < arrayLen; arrayCounter++) {
416  outArray[arrayCounter] = mFunctionTypes[arrayCounter];
417  }
418 
419  *aArrayCount = arrayLen;
420  *aFunctionTypes = outArray;
421  return NS_OK;
422 }
423 
424 NS_IMETHODIMP
425 sbDeviceCapabilities::GetSupportedContentTypes(PRUint32 aFunctionType,
426  PRUint32 *aArrayCount,
427  PRUint32 **aContentTypes)
428 {
429  NS_ENSURE_ARG_POINTER(aArrayCount);
430  NS_ENSURE_ARG_POINTER(aContentTypes);
431  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
432  NS_ENSURE_TRUE(isConfigured, NS_ERROR_NOT_INITIALIZED);
433 
434  nsTArray<PRUint32>* contentTypes;
435 
436  if (!mContentTypes.Get(aFunctionType, &contentTypes)) {
437  NS_WARNING("There are no content types for the requested function type.");
438  return NS_ERROR_NOT_AVAILABLE;
439  }
440 
441  PRUint32 arrayLen = contentTypes->Length();
442  PRUint32* outArray = (PRUint32*)NS_Alloc(arrayLen * sizeof(PRUint32));
443  if (!outArray) {
444  return NS_ERROR_OUT_OF_MEMORY;
445  }
446 
447  for (PRUint32 arrayCounter = 0; arrayCounter < arrayLen; arrayCounter++) {
448  outArray[arrayCounter] = contentTypes->ElementAt(arrayCounter);
449  }
450 
451  *aArrayCount = arrayLen;
452  *aContentTypes = outArray;
453  return NS_OK;
454 }
455 
456 NS_IMETHODIMP
457 sbDeviceCapabilities::GetSupportedMimeTypes(PRUint32 aContentType,
458  PRUint32 *aArrayCount,
459  char ***aSupportedMimeTypes)
460 {
461  NS_ENSURE_ARG_POINTER(aArrayCount);
462  NS_ENSURE_ARG_POINTER(aSupportedMimeTypes);
463  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
464  NS_ENSURE_TRUE(isConfigured, NS_ERROR_NOT_INITIALIZED);
465 
466  nsTArray<nsCString>* supportedMimeTypes;
467 
468  if (!mSupportedMimeTypes.Get(aContentType, &supportedMimeTypes)) {
469  NS_WARNING("Requseted content type is not available for this device.");
470  return NS_ERROR_NOT_AVAILABLE;
471  }
472 
473  PRUint32 arrayLen = supportedMimeTypes->Length();
474  char** outArray = reinterpret_cast<char**>(NS_Alloc(arrayLen * sizeof(char*)));
475  if (!outArray) {
476  return NS_ERROR_OUT_OF_MEMORY;
477  }
478 
479  for (PRUint32 arrayCounter = 0; arrayCounter < arrayLen; arrayCounter++) {
480  nsCString const & mimeType = supportedMimeTypes->ElementAt(arrayCounter);
481  outArray[arrayCounter] = ToNewCString(mimeType);
482  }
483 
484  *aArrayCount = arrayLen;
485  *aSupportedMimeTypes = outArray;
486  return NS_OK;
487 }
488 
489 NS_IMETHODIMP
490 sbDeviceCapabilities::GetSupportedEvents(PRUint32 *aArrayCount,
491  PRUint32 **aSupportedEvents)
492 {
493  NS_ENSURE_ARG_POINTER(aArrayCount);
494  NS_ENSURE_ARG_POINTER(aSupportedEvents);
495  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
496  NS_ENSURE_TRUE(isConfigured, NS_ERROR_NOT_INITIALIZED);
497 
498  PRUint32 arrayLen = mSupportedEvents.Length();
499  PRUint32* outArray = (PRUint32*)NS_Alloc(arrayLen * sizeof(PRUint32));
500  if (!outArray) {
501  return NS_ERROR_OUT_OF_MEMORY;
502  }
503 
504  for (PRUint32 arrayCounter = 0; arrayCounter < arrayLen; arrayCounter++) {
505  outArray[arrayCounter] = mSupportedEvents[arrayCounter];
506  }
507 
508  *aArrayCount = arrayLen;
509  *aSupportedEvents = outArray;
510  return NS_OK;
511 }
512 
513 NS_IMETHODIMP
514 sbDeviceCapabilities::SupportsContent(PRUint32 aFunctionType,
515  PRUint32 aContentType,
516  PRBool *aSupported)
517 {
518  NS_ENSURE_ARG_POINTER(aSupported);
519  NS_ENSURE_TRUE(isInitialized, NS_ERROR_NOT_INITIALIZED);
520  NS_ENSURE_TRUE(isConfigured, NS_ERROR_NOT_INITIALIZED);
521 
522  *aSupported = PR_FALSE;
523 
524  nsresult rv;
525  PRUint32 *functionTypes;
526  PRUint32 functionTypesLength;
527  rv = GetSupportedFunctionTypes(&functionTypesLength,
528  &functionTypes);
529  NS_ENSURE_SUCCESS(rv, rv);
530  sbAutoNSMemPtr functionTypesPtr(functionTypes);
531  PRUint32 *end = functionTypes + functionTypesLength;
532  // function type not available. not supported.
533  if (std::find(functionTypes, end, aFunctionType) == end)
534  return NS_OK;
535 
536  PRUint32 *contentTypes;
537  PRUint32 contentTypesLength;
538  rv = GetSupportedContentTypes(aFunctionType,
539  &contentTypesLength,
540  &contentTypes);
541  NS_ENSURE_SUCCESS(rv, rv);
542  sbAutoNSMemPtr contentTypesPtr(contentTypes);
543  end = contentTypes + contentTypesLength;
544  *aSupported = std::find(contentTypes, end, aContentType) != end;
545 
546  return NS_OK;
547 }
548 
549 NS_IMETHODIMP
550 sbDeviceCapabilities::GetSupportedFileExtensions(sbIDevice *aDevice,
551  PRUint32 aContentType,
552  nsIStringEnumerator **_retval)
553 {
554  // Validate arguments.
555  NS_ENSURE_ARG_POINTER(aDevice);
556 
557  // Function variables.
558  nsresult rv;
559 
560  nsTArray<nsString> allExtensions;
562  aContentType,
563  allExtensions);
564  NS_ENSURE_SUCCESS(rv, rv);
565 
566  nsCOMPtr<nsIStringEnumerator> allExtensionsEnum =
567  new sbTArrayStringEnumerator(&allExtensions);
568 
569  NS_ENSURE_TRUE(allExtensionsEnum, NS_ERROR_OUT_OF_MEMORY);
570 
571  allExtensionsEnum.forget(_retval);
572 
573  return NS_OK;
574 }
575 
579 NS_IMETHODIMP
580 sbDeviceCapabilities::GetFormatTypes(PRUint32 aContentType,
581  nsAString const & aMimeType,
582  PRUint32 *aArrayCount,
583  nsISupports *** aSupportedFormats)
584 {
585  NS_ENSURE_ARG_POINTER(aArrayCount);
586  NS_ENSURE_ARG_POINTER(aSupportedFormats);
587  NS_ENSURE_ARG_RANGE(aContentType,
589  sbIDeviceCapabilities::CONTENT_MAX_TYPES - 1);
590 
591  FormatTypes *formatType =
592  static_cast<FormatTypes *>(mContentFormatTypes.SafeElementAt(aContentType));
593  if (!formatType)
594  return NS_ERROR_NULL_POINTER;
595 
596  nsTArray<nsCOMPtr<nsISupports> > * formats;
597  PRBool const found = formatType->Get(aMimeType, &formats);
598  PRUint32 count = 0;
599  if (found) {
600  count = formats->Length();
601  }
602 
603  nsISupports **formatsArray = static_cast<nsISupports **>(NS_Alloc(
604  sizeof(nsISupports *) * count));
605  NS_ENSURE_TRUE(formatsArray, NS_ERROR_OUT_OF_MEMORY);
606 
607  for (PRUint32 i = 0; i < count; i++) {
608  formatsArray[i] = formats->ElementAt(i);
609  NS_ADDREF(formatsArray[i]);
610  }
611 
612  *aArrayCount = count;
613  *aSupportedFormats = formatsArray;
614 
615  return NS_OK;
616 }
617 
621 NS_IMETHODIMP
622 sbDeviceCapabilities::GetPreferredFormatTypes(PRUint32 aContentType,
623  nsAString const & aMimeType,
624  PRUint32 *aArrayCount,
625  nsISupports *** aPreferredFormats)
626 {
627  NS_ENSURE_ARG_POINTER(aArrayCount);
628  NS_ENSURE_ARG_POINTER(aPreferredFormats);
629  NS_ENSURE_ARG_RANGE(aContentType,
631  sbIDeviceCapabilities::CONTENT_MAX_TYPES - 1);
632 
633  FormatTypes *formatType =
634  static_cast<FormatTypes *>(mContentPreferredFormatTypes.SafeElementAt(
635  aContentType));
636  if (!formatType)
637  return NS_ERROR_NULL_POINTER;
638 
639  nsTArray<nsCOMPtr<nsISupports> > * formats;
640  PRBool const found = formatType->Get(aMimeType, &formats);
641  if (!found) {
642  // If there were no format types found, forward to GetFormatTypes - this
643  // simply means we weren't given any preferred types, and will transcode to
644  // anything supported
645  return GetFormatTypes(aContentType, aMimeType, aArrayCount,
646  aPreferredFormats);
647  }
648 
649  PRUint32 count = formats->Length();
650 
651  nsISupports **formatsArray = static_cast<nsISupports **>(NS_Alloc(
652  sizeof(nsISupports *) * count));
653  NS_ENSURE_TRUE(formatsArray, NS_ERROR_OUT_OF_MEMORY);
654 
655  for (PRUint32 i = 0; i < count; i++) {
656  formatsArray[i] = formats->ElementAt(i);
657  NS_ADDREF(formatsArray[i]);
658  }
659 
660  *aArrayCount = count;
661  *aPreferredFormats = formatsArray;
662 
663  return NS_OK;
664 }
665 
666 /*******************************************************************************
667  * sbImageSize
668  */
669 
672  sbIImageSize,
673  nsIClassInfo)
674 
675 NS_DECL_CLASSINFO(sbImageSize)
676 NS_IMPL_THREADSAFE_CI(sbImageSize)
677 
678 sbImageSize::~sbImageSize()
679 {
680  /* destructor code */
681 }
682 
683 NS_IMETHODIMP
685  PRInt32 aHeight) {
686  mWidth = aWidth;
687  mHeight = aHeight;
688 
689  return NS_OK;
690 }
691 
692 /* readonly attribute long width; */
693 NS_IMETHODIMP
694 sbImageSize::GetWidth(PRInt32 *aWidth)
695 {
696  NS_ENSURE_ARG_POINTER(aWidth);
697 
698  *aWidth = mWidth;
699  return NS_OK;
700 }
701 
702 /* readonly attribute long height; */
703 NS_IMETHODIMP
704 sbImageSize::GetHeight(PRInt32 *aHeight)
705 {
706  NS_ENSURE_ARG_POINTER(aHeight);
707 
708  *aHeight = mHeight;
709  return NS_OK;
710 }
711 
712 /*******************************************************************************
713  * sbDevCapRange
714  */
715 
719  nsIClassInfo)
720 
721 NS_DECL_CLASSINFO(sbDevCapRange)
722 NS_IMPL_THREADSAFE_CI(sbDevCapRange)
723 
724 sbDevCapRange::~sbDevCapRange()
725 {
726  /* destructor code */
727 }
728 
729 NS_IMETHODIMP sbDevCapRange::Initialize(PRInt32 aMin,
730  PRInt32 aMax,
731  PRInt32 aStep) {
732  mMin = aMin;
733  mMax = aMax;
734  mStep = aStep;
735  mValues.Clear();
736  return NS_OK;
737 }
738 
739 /* readonly attribute nsIArray values; */
740 NS_IMETHODIMP
741 sbDevCapRange::GetValue(PRUint32 aIndex, PRInt32 * aValue)
742 {
743  NS_ENSURE_ARG_POINTER(aValue);
744 
745  *aValue = mValues[aIndex];
746  return NS_OK;
747 }
748 
749 NS_IMETHODIMP
751 {
752  if (mValues.IsEmpty()) {
753  mMin = mMax = aValue;
754  }
755  else {
756  if (mMin > aValue)
757  mMin = aValue;
758  if (mMax < aValue)
759  mMax = aValue;
760  }
761  NS_ENSURE_TRUE(mValues.AppendElement(aValue), NS_ERROR_OUT_OF_MEMORY);
762 
763  return NS_OK;
764 }
765 
766 NS_IMETHODIMP
767 sbDevCapRange::GetValueCount(PRUint32 * aCount)
768 {
769  NS_ENSURE_ARG_POINTER(aCount);
770 
771  *aCount = mValues.Length();
772  return NS_OK;
773 }
774 
775 /* readonly attribute long min; */
776 NS_IMETHODIMP
777 sbDevCapRange::GetMin(PRInt32 *aMin)
778 {
779  NS_ENSURE_ARG_POINTER(aMin);
780 
781  *aMin = mMin;
782  return NS_OK;
783 }
784 
785 /* readonly attribute long max; */
786 NS_IMETHODIMP
787 sbDevCapRange::GetMax(PRInt32 *aMax)
788 {
789  NS_ENSURE_ARG_POINTER(aMax);
790 
791  *aMax = mMax;
792  return NS_OK;
793 }
794 
795 /* readonly attribute long step; */
796 NS_IMETHODIMP
797 sbDevCapRange::GetStep(PRInt32 *aStep)
798 {
799  NS_ENSURE_ARG_POINTER(aStep);
800 
801  *aStep = mStep;
802  return NS_OK;
803 }
804 
805 NS_IMETHODIMP
806 sbDevCapRange::IsValueInRange(PRInt32 aValue, PRBool * aInRange) {
807  NS_ENSURE_ARG_POINTER(aInRange);
808 
809  if (mValues.Length() > 0) {
810  *aInRange = mValues.Contains(aValue);
811  }
812  else {
813  *aInRange = aValue <= mMax && aValue >= mMin &&
814  (mStep == 0 || ((aValue - mMin) % mStep == 0));
815  }
816  return NS_OK;
817 }
818 
819 /*******************************************************************************
820  * sbDevCapRange
821  */
822 
825  nsIClassInfo)
828  nsIClassInfo)
829 
830 NS_DECL_CLASSINFO(sbDevCapFraction)
831 NS_IMPL_THREADSAFE_CI(sbDevCapFraction)
832 
833 sbDevCapFraction::~sbDevCapFraction()
834 {
835 }
836 
837 NS_IMETHODIMP
838 sbDevCapFraction::GetNumerator(PRUint32 *aNumerator)
839 {
840  NS_ENSURE_ARG_POINTER(aNumerator);
841  *aNumerator = mNumerator;
842  return NS_OK;
843 }
844 
845 NS_IMETHODIMP
846 sbDevCapFraction::GetDenominator(PRUint32 *aDenominator)
847 {
848  NS_ENSURE_ARG_POINTER(aDenominator);
849  *aDenominator = mDenominator;
850  return NS_OK;
851 }
852 
853 NS_IMETHODIMP
854 sbDevCapFraction::Initialize(PRUint32 aNumerator, PRUint32 aDenominator)
855 {
856  mNumerator = aNumerator;
857  mDenominator = aDenominator;
858  return NS_OK;
859 }
860 
861 /*******************************************************************************
862  * sbFormatTypeConstraint
863  */
864 
867  nsIClassInfo)
870  nsIClassInfo)
871 
872 NS_DECL_CLASSINFO(sbFormatTypeConstraint)
873 NS_IMPL_THREADSAFE_CI(sbFormatTypeConstraint)
874 
875 sbFormatTypeConstraint::~sbFormatTypeConstraint()
876 {
877  /* destructor code */
878 }
879 
880 NS_IMETHODIMP
881 sbFormatTypeConstraint::Initialize(nsAString const & aConstraintName,
882  nsIVariant * aMinValue,
883  nsIVariant * aMaxValue) {
884  NS_ENSURE_ARG_POINTER(aMinValue);
885  NS_ENSURE_ARG_POINTER(aMaxValue);
886 
887  mConstraintName = aConstraintName;
888  mMinValue = aMinValue;
889  mMaxValue = aMaxValue;
890  return NS_OK;
891 }
892 
893 /* readonly attribute AString constraintName; */
894 NS_IMETHODIMP
895 sbFormatTypeConstraint::GetConstraintName(nsAString & aConstraintName)
896 {
897  aConstraintName = mConstraintName;
898  return NS_OK;
899 }
900 
901 /* readonly attribute nsIVariant constraintMinValue; */
902 NS_IMETHODIMP
903 sbFormatTypeConstraint::GetConstraintMinValue(nsIVariant * *aConstraintMinValue)
904 {
905  NS_ENSURE_ARG_POINTER(aConstraintMinValue);
906 
907  *aConstraintMinValue = mMinValue.get();
908  NS_IF_ADDREF(*aConstraintMinValue);
909  return NS_OK;
910 }
911 
912 /* readonly attribute nsIVariant constraintMaxValue; */
913 NS_IMETHODIMP
914 sbFormatTypeConstraint::GetConstraintMaxValue(nsIVariant * *aConstraintMaxValue)
915 {
916  NS_ENSURE_ARG_POINTER(aConstraintMaxValue);
917 
918  *aConstraintMaxValue = mMaxValue.get();
919  NS_IF_ADDREF(*aConstraintMaxValue);
920  return NS_OK;
921 }
922 
923 /*******************************************************************************
924  * Image format type implementation
925  */
926 
927 /* Implementation file */
930  nsIClassInfo)
933  nsIClassInfo)
934 
935 NS_DECL_CLASSINFO(sbImageFormatType)
936 NS_IMPL_THREADSAFE_CI(sbImageFormatType)
937 
938 sbImageFormatType::~sbImageFormatType()
939 {
940  /* destructor code */
941 }
942 
943 NS_IMETHODIMP
944 sbImageFormatType::Initialize(nsACString const & aImageFormat,
945  nsIArray * aSupportedExplicitSizes,
946  sbIDevCapRange * aSupportedWidths,
947  sbIDevCapRange * aSupportedHeights) {
948  NS_ENSURE_ARG_POINTER(aSupportedExplicitSizes);
949 
950  mImageFormat = aImageFormat;
951  mSupportedExplicitSizes = aSupportedExplicitSizes;
952  mSupportedWidths = aSupportedWidths;
953  mSupportedHeights = aSupportedHeights;
954  return NS_OK;
955 }
956 
957 /* readonly attribute ACString imageFormat; */
958 NS_IMETHODIMP
959 sbImageFormatType::GetImageFormat(nsACString & aImageFormat)
960 {
961  aImageFormat = mImageFormat;
962  return NS_OK;
963 }
964 
965 /* readonly attribute nsIArray supportedExplicitSizes; */
966 NS_IMETHODIMP
967 sbImageFormatType::GetSupportedExplicitSizes(nsIArray * *aSupportedExplicitSizes)
968 {
969  NS_ENSURE_ARG_POINTER(aSupportedExplicitSizes);
970 
971  *aSupportedExplicitSizes = mSupportedExplicitSizes;
972  NS_IF_ADDREF(*aSupportedExplicitSizes);
973  return NS_OK;
974 }
975 
976 /* readonly attribute sbIDevCapRange supportedWidths; */
977 NS_IMETHODIMP
978 sbImageFormatType::GetSupportedWidths(sbIDevCapRange * *aSupportedWidths)
979 {
980  NS_ENSURE_ARG_POINTER(aSupportedWidths);
981 
982  *aSupportedWidths = mSupportedWidths;
983  NS_IF_ADDREF(*aSupportedWidths);
984  return NS_OK;
985 }
986 
987 /* readonly attribute sbIDevCapRange supportedHeights; */
988 NS_IMETHODIMP
989 sbImageFormatType::GetSupportedHeights(sbIDevCapRange * *aSupportedHeights)
990 {
991  NS_ENSURE_ARG_POINTER(aSupportedHeights);
992 
993  *aSupportedHeights = mSupportedHeights;
994  NS_IF_ADDREF(*aSupportedHeights);
995  return NS_OK;
996 }
997 
998 /*******************************************************************************
999  * Audio format type
1000  */
1001 
1002 /* Implementation file */
1005  nsIClassInfo)
1008  nsIClassInfo)
1009 
1010 NS_DECL_CLASSINFO(sbAudioFormatType)
1011 NS_IMPL_THREADSAFE_CI(sbAudioFormatType)
1012 
1013 sbAudioFormatType::~sbAudioFormatType()
1014 {
1015  /* destructor code */
1016 }
1017 
1018 NS_IMETHODIMP
1019 sbAudioFormatType::Initialize(nsACString const & aContainerFormat,
1020  nsACString const & aAudioCodec,
1021  sbIDevCapRange * aSupportedBitrates,
1022  sbIDevCapRange * aSupportedSampleRates,
1023  sbIDevCapRange * aSupportedChannels,
1024  nsIArray * aFormatSpecificConstraints) {
1025  mContainerFormat = aContainerFormat;
1026  mAudioCodec = aAudioCodec;
1027  mSupportedBitrates = aSupportedBitrates;
1028  mSupportedSampleRates = aSupportedSampleRates;
1029  mSupportedChannels = aSupportedChannels;
1030  mFormatSpecificConstraints = aFormatSpecificConstraints;
1031 
1032  return NS_OK;
1033 }
1034 
1035 /* readonly attribute ACString containerFormat; */
1036 NS_IMETHODIMP
1037 sbAudioFormatType::GetContainerFormat(nsACString & aContainerFormat)
1038 {
1039  aContainerFormat = mContainerFormat;
1040  return NS_OK;
1041 }
1042 
1043 /* readonly attribute ACString audioCodec; */
1044 NS_IMETHODIMP
1045 sbAudioFormatType::GetAudioCodec(nsACString & aAudioCodec)
1046 {
1047  aAudioCodec = mAudioCodec;
1048  return NS_OK;
1049 }
1050 
1051 /* readonly attribute sbIDevCapRange supportedBitrates; */
1052 NS_IMETHODIMP
1053 sbAudioFormatType::GetSupportedBitrates(sbIDevCapRange * *aSupportedBitrates)
1054 {
1055  NS_ENSURE_ARG_POINTER(aSupportedBitrates);
1056  *aSupportedBitrates = mSupportedBitrates;
1057  NS_IF_ADDREF(*aSupportedBitrates);
1058  return NS_OK;
1059 }
1060 
1061 /* readonly attribute sbIDevCapRange supportedSampleRates; */
1062 NS_IMETHODIMP
1063 sbAudioFormatType::GetSupportedSampleRates(sbIDevCapRange * *aSupportedSampleRates)
1064 {
1065  NS_ENSURE_ARG_POINTER(aSupportedSampleRates);
1066  *aSupportedSampleRates = mSupportedSampleRates;
1067  NS_IF_ADDREF(*aSupportedSampleRates);
1068  return NS_OK;
1069 }
1070 
1071 /* readonly attribute sbIDevCapRange supportedChannels; */
1072 NS_IMETHODIMP
1073 sbAudioFormatType::GetSupportedChannels(sbIDevCapRange * *aSupportedChannels)
1074 {
1075  NS_ENSURE_ARG_POINTER(aSupportedChannels);
1076  *aSupportedChannels = mSupportedChannels;
1077  NS_IF_ADDREF(*aSupportedChannels);
1078  return NS_OK;
1079 }
1080 
1081 /* readonly attribute nsIArray formatSpecificConstraints; */
1082 NS_IMETHODIMP
1083 sbAudioFormatType::GetFormatSpecificConstraints(nsIArray * *aFormatSpecificConstraints)
1084 {
1085  NS_ENSURE_ARG_POINTER(aFormatSpecificConstraints);
1086  *aFormatSpecificConstraints = mFormatSpecificConstraints;
1087  NS_IF_ADDREF(*aFormatSpecificConstraints);
1088  return NS_OK;
1089 }
1090 
1091 /*******************************************************************************
1092  * Video format video stream
1093  */
1094 
1097  nsIClassInfo)
1100  nsIClassInfo)
1101 
1102 NS_DECL_CLASSINFO(sbDevCapVideoStream)
1103 NS_IMPL_THREADSAFE_CI(sbDevCapVideoStream)
1104 
1105 sbDevCapVideoStream::sbDevCapVideoStream()
1106 {
1107 }
1108 
1109 sbDevCapVideoStream::~sbDevCapVideoStream()
1110 {
1111 }
1112 
1113 NS_IMETHODIMP sbDevCapVideoStream::Initialize(const nsACString & aType,
1114  nsIArray *aExplicitSizes,
1115  sbIDevCapRange *aWidths,
1116  sbIDevCapRange *aHeights,
1117  nsIArray *aSupportPARs,
1118  PRBool aIsSupportedPARsRange,
1119  nsIArray *aSupportedFrameRates,
1120  PRBool aIsSupportedFrameratesRange,
1121  sbIDevCapRange *aBitRates)
1122 {
1123  NS_ENSURE_ARG_POINTER(aExplicitSizes);
1124  NS_ENSURE_ARG_POINTER(aSupportedFrameRates);
1125  NS_ENSURE_ARG_POINTER(aBitRates);
1126 
1127  mType = aType;
1128  mExplicitSizes = aExplicitSizes;
1129  mWidths = aWidths;
1130  mHeights = aHeights;
1131  mIsPARRange = aIsSupportedPARsRange;
1132  mVideoPARs = aSupportPARs;
1133  mIsFrameRatesRange = aIsSupportedFrameratesRange;
1134  mVideoFrameRates = aSupportedFrameRates;
1135  mBitRates = aBitRates;
1136 
1137  // Ensure valid PAR and frame rate values.
1138  nsresult rv;
1139  PRUint32 length;
1140  if (mIsPARRange) {
1141  NS_ENSURE_ARG_POINTER(mVideoPARs);
1142  rv = mVideoPARs->GetLength(&length);
1143  NS_ENSURE_SUCCESS(rv, rv);
1144  NS_ENSURE_TRUE(length == 2, NS_ERROR_UNEXPECTED);
1145  }
1146  else {
1147  if (!aSupportPARs) {
1148  // no PARs given, default to 1/1
1149  nsCOMPtr<sbIDevCapFraction> parFraction =
1150  do_CreateInstance("@songbirdnest.com/Songbird/Device/sbfraction;1", &rv);
1151  NS_ENSURE_SUCCESS(rv, rv);
1152 
1153  nsCOMPtr<nsIMutableArray> parArray =
1154  do_CreateInstance("@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1155  NS_ENSURE_SUCCESS(rv, rv);
1156 
1157  rv = parFraction->Initialize(1, 1);
1158  NS_ENSURE_SUCCESS(rv, rv);
1159  rv = parArray->AppendElement(parFraction, PR_FALSE);
1160  NS_ENSURE_SUCCESS(rv, rv);
1161  mVideoPARs = do_QueryInterface(parArray, &rv);
1162  NS_ENSURE_SUCCESS(rv, rv);
1163  }
1164  }
1165  if (mIsFrameRatesRange) {
1166  rv = mVideoFrameRates->GetLength(&length);
1167  NS_ENSURE_SUCCESS(rv, rv);
1168  NS_ENSURE_TRUE(length == 2, NS_ERROR_UNEXPECTED);
1169  }
1170  else {
1171  rv = mVideoFrameRates->GetLength(&length);
1172  NS_ENSURE_SUCCESS(rv, rv);
1173  NS_ENSURE_TRUE(length > 0, NS_ERROR_UNEXPECTED);
1174  }
1175  return NS_OK;
1176 }
1177 
1178 /* readonly attribute ACString type; */
1179 NS_IMETHODIMP sbDevCapVideoStream::GetType(nsACString & aType)
1180 {
1181  aType = mType;
1182  return NS_OK;
1183 }
1184 
1185 /* readonly attribute nsIArray supportedExplicitSizes; */
1186 NS_IMETHODIMP sbDevCapVideoStream::GetSupportedExplicitSizes(nsIArray * *aSupportedExplicitSizes)
1187 {
1188  NS_IF_ADDREF(*aSupportedExplicitSizes = mExplicitSizes);
1189  return NS_OK;
1190 }
1191 
1192 /* readonly attribute sbIDevCapRange supportedWidths; */
1193 NS_IMETHODIMP sbDevCapVideoStream::GetSupportedWidths(sbIDevCapRange * *aSupportedWidths)
1194 {
1195  NS_IF_ADDREF(*aSupportedWidths = mWidths);
1196  return NS_OK;
1197 }
1198 
1199 /* readonly attribute sbIDevCapRange supportedHeights; */
1200 NS_IMETHODIMP sbDevCapVideoStream::GetSupportedHeights(sbIDevCapRange * *aSupportedHeights)
1201 {
1202  NS_IF_ADDREF(*aSupportedHeights = mHeights);
1203  return NS_OK;
1204 }
1205 
1206 /* readonly attribute boolean doesSupportPARRange; */
1207 NS_IMETHODIMP
1208 sbDevCapVideoStream::GetDoesSupportPARRange(PRBool *aDoesSupportPARRange)
1209 {
1210  NS_ENSURE_ARG_POINTER(aDoesSupportPARRange);
1211  *aDoesSupportPARRange = mIsPARRange;
1212  return NS_OK;
1213 }
1214 
1215 /* readonly attribute nsIArray supportedPARs; */
1216 NS_IMETHODIMP
1217 sbDevCapVideoStream::GetSupportedPARs(nsIArray **aSupportedPARs)
1218 {
1219  NS_ENSURE_ARG_POINTER(aSupportedPARs);
1220  NS_IF_ADDREF(*aSupportedPARs = mVideoPARs);
1221  return NS_OK;
1222 }
1223 
1224 /* readonly attribute sbIDevCapFraction minimumSupportedPAR; */
1225 NS_IMETHODIMP
1226 sbDevCapVideoStream::GetMinimumSupportedPAR(
1227  sbIDevCapFraction **aMinimumSupportedPAR)
1228 {
1229  NS_ENSURE_ARG_POINTER(aMinimumSupportedPAR);
1230  NS_ENSURE_TRUE(mIsPARRange, NS_ERROR_NOT_AVAILABLE);
1231 
1232  // The minimum PAR value will be the first value in the par array (if
1233  // supported).
1234  nsresult rv;
1235  nsCOMPtr<sbIDevCapFraction> minPARFraction =
1236  do_QueryElementAt(mVideoPARs, 0, &rv);
1237  NS_ENSURE_SUCCESS(rv, rv);
1238 
1239  minPARFraction.forget(aMinimumSupportedPAR);
1240  return NS_OK;
1241 }
1242 
1243 /* readonly attribute sbIDevCapFraction maximumSupportedPAR; */
1244 NS_IMETHODIMP
1245 sbDevCapVideoStream::GetMaximumSupportedPAR(
1246  sbIDevCapFraction **aMaximumSupportedPAR)
1247 {
1248  NS_ENSURE_ARG_POINTER(aMaximumSupportedPAR);
1249  NS_ENSURE_TRUE(mIsPARRange, NS_ERROR_NOT_AVAILABLE);
1250 
1251  // The maximum PAR value will be the second value in the par array (if
1252  // supported).
1253  nsresult rv;
1254  nsCOMPtr<sbIDevCapFraction> maxPARFraction =
1255  do_QueryElementAt(mVideoPARs, 1, &rv);
1256  NS_ENSURE_SUCCESS(rv, rv);
1257 
1258  maxPARFraction.forget(aMaximumSupportedPAR);
1259  return NS_OK;
1260 }
1261 
1262 /* readonly attribute boolean doesSupportFrameRateRange; */
1263 NS_IMETHODIMP
1264 sbDevCapVideoStream::GetDoesSupportFrameRateRange(
1265  PRBool *aDoesSupportFrameRateRange)
1266 {
1267  NS_ENSURE_ARG_POINTER(aDoesSupportFrameRateRange);
1268  *aDoesSupportFrameRateRange = mIsFrameRatesRange;
1269  return NS_OK;
1270 }
1271 
1272 /* readonly attribute nsIArray supportedFrameRates; */
1273 NS_IMETHODIMP
1274 sbDevCapVideoStream::GetSupportedFrameRates(nsIArray **aSupportedFrameRates)
1275 {
1276  NS_ENSURE_ARG_POINTER(aSupportedFrameRates);
1277  NS_IF_ADDREF(*aSupportedFrameRates = mVideoFrameRates);
1278  return NS_OK;
1279 }
1280 
1281 /* readonly attribute sbIDevCapFraction minimumSupportedFrameRate; */
1282 NS_IMETHODIMP
1283 sbDevCapVideoStream::GetMinimumSupportedFrameRate(
1284  sbIDevCapFraction **aMinimumSupportedFrameRate)
1285 {
1286  NS_ENSURE_ARG_POINTER(aMinimumSupportedFrameRate);
1287  NS_ENSURE_TRUE(mIsFrameRatesRange, NS_ERROR_NOT_AVAILABLE);
1288 
1289  // The minimum frame rate will be the first value in the frame rates array
1290  // (if available).
1291  nsresult rv;
1292  nsCOMPtr<sbIDevCapFraction> minFrameRateFraction =
1293  do_QueryElementAt(mVideoFrameRates, 0, &rv);
1294  NS_ENSURE_SUCCESS(rv, rv);
1295 
1296  minFrameRateFraction.forget(aMinimumSupportedFrameRate);
1297  return NS_OK;
1298 }
1299 
1300 /* readonly attribute sbIDevCapFraction maximumSupportedFrameRate; */
1301 NS_IMETHODIMP
1302 sbDevCapVideoStream::GetMaximumSupportedFrameRate(
1303  sbIDevCapFraction **aMaximumSupportedFrameRate)
1304 {
1305  NS_ENSURE_ARG_POINTER(aMaximumSupportedFrameRate);
1306  NS_ENSURE_TRUE(mIsFrameRatesRange, NS_ERROR_NOT_AVAILABLE);
1307 
1308  // The maximum frame rate will be the second value in the frame rates array
1309  // (if available).
1310  nsresult rv;
1311  nsCOMPtr<sbIDevCapFraction> maxFrameRateFraction =
1312  do_QueryElementAt(mVideoFrameRates, 1, &rv);
1313  NS_ENSURE_SUCCESS(rv, rv);
1314 
1315  maxFrameRateFraction.forget(aMaximumSupportedFrameRate);
1316  return NS_OK;
1317 }
1318 
1319 /* readonly attribute sbIDevCapRange supportedBitRates; */
1320 NS_IMETHODIMP sbDevCapVideoStream::GetSupportedBitRates(sbIDevCapRange * *aSupportedBitRates)
1321 {
1322  NS_IF_ADDREF(*aSupportedBitRates = mBitRates);
1323  return NS_OK;
1324 }
1325 
1326 /*******************************************************************************
1327  * Video format audio stream
1328  */
1329 
1332  nsIClassInfo)
1335  nsIClassInfo)
1336 
1337 NS_DECL_CLASSINFO(sbDevCapAudioStream)
1338 NS_IMPL_THREADSAFE_CI(sbDevCapAudioStream)
1339 
1340 sbDevCapAudioStream::sbDevCapAudioStream()
1341 {
1342 }
1343 
1344 sbDevCapAudioStream::~sbDevCapAudioStream()
1345 {
1346 }
1347 
1348 NS_IMETHODIMP
1349 sbDevCapAudioStream::Initialize(const nsACString & aType,
1350  sbIDevCapRange *aBitRates,
1351  sbIDevCapRange *aSampleRates,
1352  sbIDevCapRange *aChannels)
1353 {
1354  mType = aType;
1355  mBitRates = aBitRates;
1356  mSampleRates = aSampleRates;
1357  mChannels = aChannels;
1358 
1359  return NS_OK;
1360 }
1361 
1362 NS_IMETHODIMP sbDevCapAudioStream::GetType(nsACString & aType)
1363 {
1364  aType = mType;
1365  return NS_OK;
1366 }
1367 
1368 NS_IMETHODIMP
1369 sbDevCapAudioStream::GetSupportedBitRates(sbIDevCapRange * *aBitRates)
1370 {
1371  return sbReturnCOMPtr(mBitRates, aBitRates);
1372 }
1373 
1374 /* readonly attribute sbIDevCapRange supportedSampleRates; */
1375 NS_IMETHODIMP
1376 sbDevCapAudioStream::GetSupportedSampleRates(sbIDevCapRange * *aSampleRates)
1377 {
1378  return sbReturnCOMPtr(mSampleRates, aSampleRates);
1379 }
1380 
1381 /* readonly attribute sbIDevCapRange supportedChannels; */
1382 NS_IMETHODIMP
1383 sbDevCapAudioStream::GetSupportedChannels(sbIDevCapRange * *aChannels)
1384 {
1385  return sbReturnCOMPtr(mChannels, aChannels);
1386 }
1387 
1388 /*******************************************************************************
1389  * Video format type
1390  */
1391 
1394  nsIClassInfo)
1397  nsIClassInfo)
1398 
1399 NS_DECL_CLASSINFO(sbVideoFormatType)
1400 NS_IMPL_THREADSAFE_CI(sbVideoFormatType)
1401 
1402 sbVideoFormatType::sbVideoFormatType()
1403 {
1404  /* member initializers and constructor code */
1405 }
1406 
1407 sbVideoFormatType::~sbVideoFormatType()
1408 {
1409  /* destructor code */
1410 }
1411 
1412 NS_IMETHODIMP
1413 sbVideoFormatType::Initialize(const nsACString & aContainerType,
1414  sbIDevCapVideoStream *aVideoStream,
1415  sbIDevCapAudioStream *aAudioStream)
1416 {
1417  mContainerType = aContainerType;
1418  mVideoStream = aVideoStream;
1419  mAudioStream = aAudioStream;
1420 
1421  return NS_OK;
1422 }
1423 
1424 NS_IMETHODIMP
1425 sbVideoFormatType::GetContainerType(nsACString & aContainerType)
1426 {
1427  aContainerType = mContainerType;
1428  return NS_OK;
1429 }
1430 
1431 NS_IMETHODIMP
1432 sbVideoFormatType::GetVideoStream(sbIDevCapVideoStream * *aVideoStream)
1433 {
1434  return sbReturnCOMPtr(mVideoStream, aVideoStream);
1435 }
1436 
1437 NS_IMETHODIMP
1438 sbVideoFormatType::GetAudioStream(sbIDevCapAudioStream * *aAudioStream)
1439 {
1440  return sbReturnCOMPtr(mAudioStream, aAudioStream);
1441 }
1442 
1443 /*******************************************************************************
1444  * Playlist format type
1445  */
1446 
1449  nsIClassInfo)
1452  nsIClassInfo)
1453 
1454 NS_DECL_CLASSINFO(sbPlaylistFormatType)
1455 NS_IMPL_THREADSAFE_CI(sbPlaylistFormatType)
1456 
1457 sbPlaylistFormatType::sbPlaylistFormatType()
1458 {
1459 }
1460 
1461 sbPlaylistFormatType::~sbPlaylistFormatType()
1462 {
1463 }
1464 
1465 NS_IMETHODIMP
1466 sbPlaylistFormatType::Initialize(const nsACString & aPathSeparator)
1467 {
1468  mPathSeparator = aPathSeparator;
1469  return NS_OK;
1470 }
1471 
1472 NS_IMETHODIMP
1473 sbPlaylistFormatType::GetPathSeparator(nsACString & aPathSeparator)
1474 {
1475  aPathSeparator = mPathSeparator;
1476  return NS_OK;
1477 }
nsTArray< PRUint32 > mSupportedEvents
return NS_OK
void Initialize(in ACString aFormat, in ACString aCodec, in sbIDevCapRange aBitRates, in sbIDevCapRange aSampleRates, in sbIDevCapRange aChannels, in nsIArray aFormatSpecificConstraints)
[UNIMPLEMENTED UNTIL AFTER 0.3]
nsresult sbReturnCOMPtr(COMPtr &aPtr, ReturnType **aReturn)
void Initialize(in long aMin, in long aMax, in long aStep)
onPageChanged aValue
Definition: FeedWriter.js:1395
restoreDimensions aWidth
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICECAPABILITIES NS_DECL_NSICLASSINFO sbDeviceCapabilities()
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
void Initialize(in AString aConstraintName, in nsIVariant aMinValue, in nsIVariant aMaxValue)
void AddPreferredFormatType(in PRUint32 aContentType, in AString aMimeType, in nsISupports aFormatType)
Add a preferred constraint to a mime type (these are used for target formats when transcoding...
void Initialize(in long width, in long height)
void AddFormatType(in PRUint32 aContentType, in AString aMimeType, in nsISupports aFormatType)
Add a constraint to a mime type.
restoreDimensions aHeight
nsVoidArray mContentPreferredFormatTypes
var count
Definition: test_bug7406.js:32
function Init()
this _document false
Definition: FeedWriter.js:1085
void Initialize(in ACString aImageFormat, in nsIArray aSupportedExplicitSizes, in sbIDevCapRange aSupportedWidths, in sbIDevCapRange aSupportedHeights)
NS_IMPL_THREADSAFE_ISUPPORTS2(sbDeviceCapabilities, sbIDeviceCapabilities, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER2(sbDeviceCapabilities
NS_IMPL_CI_INTERFACE_GETTER2(sbImageSize, sbIImageSize, nsIClassInfo) sbImageSize
sbIJobCancelable NS_DECL_CLASSINFO(sbGstreamerMediaInspector)
nsClassHashtable< nsStringHashKey, nsTArray< nsCOMPtr< nsISupports > > > FormatTypes
boolean IsValueInRange(in long aValue)
void AddValue(in long aValue)
long GetValue(in unsigned long aIndex)
#define TRACE(args)
restoreHistoryPrecursor aCount
SupportedMimeTypes mSupportedMimeTypes
_getSelectedPageStyle s i
nsTArray< PRUint32 > mFunctionTypes
static nsresult AddSupportedFileExtensions(sbIDevice *aDevice, PRUint32 aContentType, nsTArray< nsString > &aFileExtensionList)
Interface for storing a fractional value.