28 #include <nsArrayUtils.h>
31 #include <sbIDeviceCapabilities.h>
32 #include <sbIMediaInspector.h>
40 static PRLogModuleInfo* gDeviceCapsCompatibilityLog =
41 PR_NewLogModule(
"sbDeviceCapsCompatibility");
42 #define LOG(args) PR_LOG(gDeviceCapsCompatibilityLog, PR_LOG_WARNING, args)
43 #define TRACE(args) PR_LOG(gDeviceCapsCompatibilityLog, PR_LOG_DEBUG, args)
53 : mDeviceCapabilities(nsnull),
55 mMediaVideoStream(nsnull),
56 mMediaAudioStream(nsnull),
59 mMediaVideoBitRate(0),
60 mMediaVideoSampleRate(0),
61 mMediaVideoPARNumerator(0),
62 mMediaVideoPARDenominator(0),
63 mMediaVideoFRNumerator(0),
64 mMediaVideoFRDenominator(0),
65 mMediaAudioBitRate(0),
66 mMediaAudioSampleRate(0),
67 mMediaAudioChannels(0),
70 TRACE((
"%s[%p]", __FUNCTION__,
this));
73 sbDeviceCapsCompatibility::~sbDeviceCapsCompatibility()
75 TRACE((
"%s[%p]", __FUNCTION__,
this));
83 return string1.Equals(NS_ConvertUTF8toUTF16(string2).BeginReading());
89 sbDeviceCapsCompatibility::Initialize(
92 PRUint32 aContentType)
94 TRACE((
"%s[%p]", __FUNCTION__,
this));
95 NS_ENSURE_ARG_POINTER(aDeviceCapabilities);
96 NS_ENSURE_ARG_POINTER(aMediaFormat);
100 mDeviceCapabilities = aDeviceCapabilities;
101 mMediaFormat = aMediaFormat;
102 mContentType = aContentType;
105 rv = mMediaFormat->GetVideoStream(getter_AddRefs(mMediaVideoStream));
106 NS_ENSURE_SUCCESS(rv, rv);
108 rv = mMediaFormat->GetAudioStream(getter_AddRefs(mMediaAudioStream));
109 NS_ENSURE_SUCCESS(rv, rv);
115 sbDeviceCapsCompatibility::Compare(PRBool* aCompatible)
117 TRACE((
"%s[%p]", __FUNCTION__,
this));
118 NS_ENSURE_ARG_POINTER(aCompatible);
119 NS_ENSURE_TRUE(mDeviceCapabilities, NS_ERROR_NOT_INITIALIZED);
120 NS_ENSURE_TRUE(mMediaFormat, NS_ERROR_NOT_INITIALIZED);
123 *aCompatible = PR_FALSE;
125 switch (mContentType) {
127 rv = CompareAudioFormat(aCompatible);
128 NS_ENSURE_SUCCESS(rv, rv);
131 rv = CompareVideoFormat(aCompatible);
132 NS_ENSURE_SUCCESS(rv, rv);
135 rv = CompareImageFormat(aCompatible);
136 NS_ENSURE_SUCCESS(rv, rv);
139 NS_WARNING(
"sbDeviceCapsCompatibility::Compare: "
140 "unknown content type for comparison");
148 sbDeviceCapsCompatibility::CompareAudioFormat(PRBool* aCompatible)
150 TRACE((
"%s[%p]", __FUNCTION__,
this));
151 NS_ENSURE_ARG_POINTER(aCompatible);
152 NS_ENSURE_TRUE(mDeviceCapabilities, NS_ERROR_NOT_INITIALIZED);
153 NS_ENSURE_TRUE(mMediaFormat, NS_ERROR_NOT_INITIALIZED);
156 *aCompatible = PR_FALSE;
160 nsCOMPtr<sbIMediaFormatContainer> mediaContainer;
161 rv = mMediaFormat->GetContainer(getter_AddRefs(mediaContainer));
162 NS_ENSURE_SUCCESS(rv, rv);
163 NS_ENSURE_TRUE(mediaContainer,
NS_OK);
165 rv = mediaContainer->GetContainerType(mMediaContainerType);
166 NS_ENSURE_SUCCESS(rv, rv);
168 if (!mMediaAudioStream) {
175 rv = mMediaAudioStream->GetAudioType(mMediaAudioType);
176 NS_ENSURE_SUCCESS(rv, rv);
179 rv = mMediaAudioStream->GetBitRate(&mMediaAudioBitRate);
180 NS_ENSURE_SUCCESS(rv, rv);
183 rv = mMediaAudioStream->GetSampleRate(&mMediaAudioSampleRate);
184 NS_ENSURE_SUCCESS(rv, rv);
187 rv = mMediaAudioStream->GetChannels(&mMediaAudioChannels);
188 NS_ENSURE_SUCCESS(rv, rv);
193 PRUint32 mimeTypesLength;
195 rv = mDeviceCapabilities->GetSupportedMimeTypes(mContentType,
199 if (NS_SUCCEEDED(rv) && mimeTypesLength > 0) {
201 for (PRUint32 mimeTypeIndex = 0;
202 mimeTypeIndex < mimeTypesLength;
205 NS_ConvertASCIItoUTF16 mimeType(mimeTypes[mimeTypeIndex]);
208 PRUint32 formatTypeCount;
209 rv = mDeviceCapabilities->GetFormatTypes(mContentType,
213 NS_ENSURE_SUCCESS(rv, rv);
217 for (PRUint32 formatIndex = 0;
218 formatIndex < formatTypeCount;
221 nsCOMPtr<sbIAudioFormatType> audioFormat =
222 do_QueryInterface(formatTypes[formatIndex], &rv);
223 if (NS_SUCCEEDED(rv) && audioFormat) {
225 nsCString deviceContainerType;
226 rv = audioFormat->GetContainerFormat(deviceContainerType);
227 NS_ENSURE_SUCCESS(rv, rv);
231 LOG((
"Not match! media container type: %s, device container type: %s",
232 NS_ConvertUTF16toUTF8(mMediaContainerType).BeginReading(),
233 deviceContainerType.BeginReading()));
238 nsCString deviceAudioCodec;
239 rv = audioFormat->GetAudioCodec(deviceAudioCodec);
240 NS_ENSURE_SUCCESS(rv, rv);
244 LOG((
"Not match! media audio type: %s, device audio type: %s",
245 NS_ConvertUTF16toUTF8(mMediaAudioType).BeginReading(),
246 deviceAudioCodec.BeginReading()));
251 if (mMediaAudioBitRate) {
252 nsCOMPtr<sbIDevCapRange> deviceSupportedBitRates;
253 rv = audioFormat->GetSupportedBitrates(
254 getter_AddRefs(deviceSupportedBitRates));
255 NS_ENSURE_SUCCESS(rv, rv);
257 rv = deviceSupportedBitRates->IsValueInRange(mMediaAudioBitRate,
259 NS_ENSURE_SUCCESS(rv, rv);
265 nsCOMPtr<sbIDevCapRange> deviceSupportedSampleRates;
266 rv = audioFormat->GetSupportedSampleRates(
267 getter_AddRefs(deviceSupportedSampleRates));
268 NS_ENSURE_SUCCESS(rv, rv);
270 rv = deviceSupportedSampleRates->IsValueInRange(mMediaAudioSampleRate,
272 NS_ENSURE_SUCCESS(rv, rv);
277 nsCOMPtr<sbIDevCapRange> deviceSupportedChannels;
278 rv = audioFormat->GetSupportedChannels(
279 getter_AddRefs(deviceSupportedChannels));
280 NS_ENSURE_SUCCESS(rv, rv);
282 rv = deviceSupportedChannels->IsValueInRange(mMediaAudioChannels,
284 NS_ENSURE_SUCCESS(rv, rv);
299 sbDeviceCapsCompatibility::CompareImageFormat(PRBool* aCompatible)
301 return NS_ERROR_NOT_IMPLEMENTED;
305 sbDeviceCapsCompatibility::CompareVideoFormat(PRBool* aCompatible)
307 TRACE((
"%s[%p]", __FUNCTION__,
this));
308 NS_ENSURE_ARG_POINTER(aCompatible);
309 NS_ENSURE_TRUE(mDeviceCapabilities, NS_ERROR_NOT_INITIALIZED);
310 NS_ENSURE_TRUE(mMediaFormat, NS_ERROR_NOT_INITIALIZED);
311 NS_ENSURE_TRUE(mMediaVideoStream, NS_ERROR_NOT_INITIALIZED);
314 *aCompatible = PR_FALSE;
318 nsCOMPtr<sbIMediaFormatContainer> mediaContainer;
319 rv = mMediaFormat->GetContainer(getter_AddRefs(mediaContainer));
320 NS_ENSURE_SUCCESS(rv, rv);
321 NS_ENSURE_TRUE(mediaContainer,
NS_OK);
323 rv = mediaContainer->GetContainerType(mMediaContainerType);
324 NS_ENSURE_SUCCESS(rv, rv);
327 rv = mMediaVideoStream->GetVideoType(mMediaVideoType);
328 NS_ENSURE_SUCCESS(rv, rv);
331 rv = mMediaVideoStream->GetVideoWidth(&mMediaVideoWidth);
332 NS_ENSURE_SUCCESS(rv, rv);
334 rv = mMediaVideoStream->GetVideoHeight(&mMediaVideoHeight);
335 NS_ENSURE_SUCCESS(rv, rv);
338 rv = mMediaVideoStream->GetBitRate(&mMediaVideoBitRate);
339 NS_ENSURE_SUCCESS(rv, rv);
342 rv = mMediaVideoStream->GetVideoPAR(&mMediaVideoPARNumerator,
343 &mMediaVideoPARDenominator);
344 NS_ENSURE_SUCCESS(rv, rv);
347 rv = mMediaVideoStream->GetVideoFrameRate(&mMediaVideoFRNumerator,
348 &mMediaVideoFRDenominator);
349 NS_ENSURE_SUCCESS(rv, rv);
354 if (mMediaAudioStream) {
356 rv = mMediaAudioStream->GetAudioType(mMediaAudioType);
357 NS_ENSURE_SUCCESS(rv, rv);
360 rv = mMediaAudioStream->GetBitRate(&mMediaAudioBitRate);
361 NS_ENSURE_SUCCESS(rv, rv);
364 rv = mMediaAudioStream->GetSampleRate(&mMediaAudioSampleRate);
365 NS_ENSURE_SUCCESS(rv, rv);
368 rv = mMediaAudioStream->GetChannels(&mMediaAudioChannels);
369 NS_ENSURE_SUCCESS(rv, rv);
375 PRUint32 mimeTypesLength;
377 rv = mDeviceCapabilities->GetSupportedMimeTypes(mContentType,
381 if (NS_SUCCEEDED(rv) && mimeTypesLength > 0) {
383 for (PRUint32 mimeTypeIndex = 0;
384 mimeTypeIndex < mimeTypesLength;
386 NS_ConvertASCIItoUTF16 mimeType(mimeTypes[mimeTypeIndex]);
389 PRUint32 formatTypeCount;
390 rv = mDeviceCapabilities->GetFormatTypes(mContentType,
394 NS_ENSURE_SUCCESS(rv, rv);
398 for (PRUint32 formatIndex = 0;
399 formatIndex < formatTypeCount;
402 nsCOMPtr<sbIVideoFormatType> videoFormat = do_QueryInterface(
403 formatTypes[formatIndex], &rv);
404 if (NS_SUCCEEDED(rv) && videoFormat) {
406 nsCString deviceContainerType;
407 rv = videoFormat->GetContainerType(deviceContainerType);
408 NS_ENSURE_SUCCESS(rv, rv);
412 LOG((
"Not match! media container type: %s, device container type: %s",
413 NS_ConvertUTF16toUTF8(mMediaContainerType).BeginReading(),
414 deviceContainerType.BeginReading()));
419 nsCOMPtr<sbIDevCapVideoStream> videoStream;
420 rv = videoFormat->GetVideoStream(getter_AddRefs(videoStream));
421 NS_ENSURE_SUCCESS(rv, rv);
425 LOG((
"%s[%p] -- Empty video stream for supported video format",
426 __FUNCTION__,
this));
430 rv = CompareVideoStream(videoStream, aCompatible);
431 NS_ENSURE_SUCCESS(rv, rv);
432 if (!(*aCompatible)) {
433 LOG((
"%s[%p] Video stream incompatible", __FUNCTION__,
this));
437 if (mMediaAudioStream) {
439 nsCOMPtr<sbIDevCapAudioStream> audioStream;
440 rv = videoFormat->GetAudioStream(getter_AddRefs(audioStream));
441 NS_ENSURE_SUCCESS(rv, rv);
445 LOG((
"%s[%p] -- Empty audio stream for supported video format",
446 __FUNCTION__,
this));
450 rv = CompareAudioStream(audioStream, aCompatible);
451 NS_ENSURE_SUCCESS(rv, rv);
452 if (!(*aCompatible)) {
453 LOG((
"%s[%p] Audio stream incompatible", __FUNCTION__,
this));
459 LOG((
"%s[%p] Stream is compatible", __FUNCTION__,
this));
470 sbDeviceCapsCompatibility::CompareVideoStream(
474 TRACE((
"%s[%p]", __FUNCTION__,
this));
475 NS_ENSURE_ARG_POINTER(aVideoStream);
476 NS_ENSURE_ARG_POINTER(aCompatible);
477 NS_ENSURE_TRUE(mMediaVideoStream, NS_ERROR_NOT_INITIALIZED);
480 *aCompatible = PR_FALSE;
483 nsCString deviceVideoType;
484 rv = aVideoStream->GetType(deviceVideoType);
485 NS_ENSURE_SUCCESS(rv, rv);
489 LOG((
"Not match! media video type: %s, device video type: %s",
490 NS_ConvertUTF16toUTF8(mMediaVideoType).BeginReading(),
491 deviceVideoType.BeginReading()));
495 rv = CompareVideoWidthAndHeight(aVideoStream, aCompatible);
496 NS_ENSURE_SUCCESS(rv, rv);
501 if (mMediaVideoBitRate) {
502 rv = CompareVideoBitRate(aVideoStream, aCompatible);
503 NS_ENSURE_SUCCESS(rv, rv);
508 rv = CompareVideoPAR(aVideoStream, aCompatible);
509 NS_ENSURE_SUCCESS(rv, rv);
513 rv = CompareVideoFrameRate(aVideoStream, aCompatible);
514 NS_ENSURE_SUCCESS(rv, rv);
525 sbDeviceCapsCompatibility::CompareAudioStream(
529 TRACE((
"%s[%p]", __FUNCTION__,
this));
530 NS_ENSURE_ARG_POINTER(aAudioStream);
531 NS_ENSURE_ARG_POINTER(aCompatible);
532 NS_ENSURE_TRUE(mMediaAudioStream, NS_ERROR_NOT_INITIALIZED);
535 *aCompatible = PR_FALSE;
538 nsCString deviceAudioType;
539 rv = aAudioStream->GetType(deviceAudioType);
540 NS_ENSURE_SUCCESS(rv, rv);
544 LOG((
"Not match! media audio type: %s, device audio type: %s",
545 NS_ConvertUTF16toUTF8(mMediaAudioType).BeginReading(),
546 deviceAudioType.BeginReading()));
551 if (mMediaAudioBitRate) {
552 rv = CompareAudioBitRate(aAudioStream, aCompatible);
553 NS_ENSURE_SUCCESS(rv, rv);
558 rv = CompareAudioSampleRate(aAudioStream, aCompatible);
559 NS_ENSURE_SUCCESS(rv, rv);
563 rv = CompareAudioChannels(aAudioStream, aCompatible);
564 NS_ENSURE_SUCCESS(rv, rv);
580 NS_ENSURE_ARG_POINTER(aCapRange);
581 NS_ENSURE_ARG_POINTER(aMin);
582 NS_ENSURE_ARG_POINTER(aMax);
583 NS_ENSURE_ARG_POINTER(aStep);
585 nsresult rv = aCapRange->GetMin(aMin);
586 NS_ENSURE_SUCCESS(rv, rv);
588 rv = aCapRange->GetMax(aMax);
589 NS_ENSURE_SUCCESS(rv, rv);
591 rv = aCapRange->GetStep(aStep);
592 NS_ENSURE_SUCCESS(rv, rv);
599 sbDeviceCapsCompatibility::CompareVideoWidthAndHeight(
603 TRACE((
"%s[%p]", __FUNCTION__,
this));
604 NS_ENSURE_ARG_POINTER(aVideoStream);
605 NS_ENSURE_ARG_POINTER(aCompatible);
610 nsCOMPtr<sbIDevCapRange> deviceSupportedWidths;
611 rv = aVideoStream->GetSupportedWidths(
612 getter_AddRefs(deviceSupportedWidths));
613 NS_ENSURE_SUCCESS(rv, rv);
615 nsCOMPtr<sbIDevCapRange> deviceSupportedHeights;
616 rv = aVideoStream->GetSupportedHeights(
617 getter_AddRefs(deviceSupportedHeights));
618 NS_ENSURE_SUCCESS(rv, rv);
621 if (deviceSupportedWidths && deviceSupportedHeights) {
622 PRBool inRange = PR_FALSE;
623 rv = deviceSupportedWidths->IsValueInRange(mMediaVideoWidth, &inRange);
624 NS_ENSURE_SUCCESS(rv, rv);
629 PRInt32
min, max, step;
630 rv = GetDevCapRangeValues(deviceSupportedWidths, &min, &max, &step);
631 NS_ENSURE_SUCCESS(rv, rv);
632 LOG((
"media video width (%d) not in supported range "
633 "(min: %d, max: %d, step: %d)",
634 mMediaVideoWidth, min, max, step));
639 rv = deviceSupportedHeights->IsValueInRange(mMediaVideoHeight, &inRange);
640 NS_ENSURE_SUCCESS(rv, rv);
644 PRInt32
min, max, step;
645 rv = GetDevCapRangeValues(deviceSupportedHeights, &min, &max, &step);
646 NS_ENSURE_SUCCESS(rv, rv);
647 LOG((
"media video height (%d) not in supported range "
648 "(min: %d, max: %d, step: %d)",
649 mMediaVideoWidth, min, max, step));
654 *aCompatible = inRange;
658 nsCOMPtr<nsIArray> deviceSupportedExplicitSizes;
659 rv = aVideoStream->GetSupportedExplicitSizes(
660 getter_AddRefs(deviceSupportedExplicitSizes));
661 NS_ENSURE_SUCCESS(rv, rv);
664 rv = deviceSupportedExplicitSizes->GetLength(&length);
665 NS_ENSURE_SUCCESS(rv, rv);
666 NS_ASSERTION(length > 0,
"supported sizes must not be empty!");
669 PRBool
match = PR_FALSE;
670 for (PRUint32 index = 0; index < length; ++index) {
671 nsCOMPtr<sbIImageSize> supportedSize =
672 do_QueryElementAt(deviceSupportedExplicitSizes, index, &rv);
673 NS_ENSURE_SUCCESS(rv, rv);
676 rv = supportedSize->GetWidth(&width);
677 NS_ENSURE_SUCCESS(rv, rv);
678 rv = supportedSize->GetHeight(&height);
679 NS_ENSURE_SUCCESS(rv, rv);
682 if (mMediaVideoWidth == width && mMediaVideoHeight == height) {
687 LOG((
"media video width/height (%d/%d) not equal to explicit "
688 "size item[%d] (width: %d, height: %d)",
689 mMediaVideoWidth, mMediaVideoHeight, index, width, height));
693 LOG((
"media video width/height not in device explicit size array!"));
697 *aCompatible =
match;
701 else if (length == 1)
702 *aCompatible = PR_TRUE;
708 sbDeviceCapsCompatibility::CompareVideoBitRate(
712 TRACE((
"%s[%p]", __FUNCTION__,
this));
713 NS_ENSURE_ARG_POINTER(aVideoStream);
714 NS_ENSURE_ARG_POINTER(aCompatible);
717 *aCompatible = PR_FALSE;
720 nsCOMPtr<sbIDevCapRange> deviceSupportedBitRates;
721 rv = aVideoStream->GetSupportedBitRates(
722 getter_AddRefs(deviceSupportedBitRates));
723 NS_ENSURE_SUCCESS(rv, rv);
725 rv = deviceSupportedBitRates->IsValueInRange(mMediaVideoBitRate, aCompatible);
726 NS_ENSURE_SUCCESS(rv, rv);
729 if (!(*aCompatible)) {
730 PRInt32
min, max, step;
731 rv = GetDevCapRangeValues(deviceSupportedBitRates, &min, &max, &step);
732 NS_ENSURE_SUCCESS(rv, rv);
733 LOG((
"media video bit rate (%d) not in supported range "
734 "(min: %d, max: %d, step: %d)",
735 mMediaVideoBitRate, min, max, step));
746 TRACE((
"%s[%p]", __FUNCTION__,
this));
747 NS_ENSURE_ARG_POINTER(aVideoStream);
748 NS_ENSURE_ARG_POINTER(aCompatible);
751 *aCompatible = PR_FALSE;
754 PRBool isRange = PR_FALSE;
755 rv = aVideoStream->GetDoesSupportPARRange(&isRange);
756 NS_ENSURE_SUCCESS(rv, rv);
758 PRUint32 numerator, denominator;
759 sbFraction videoParFraction(mMediaVideoPARNumerator,
760 mMediaVideoPARDenominator);
764 nsCOMPtr<sbIDevCapFraction> minSupportedPAR;
765 rv = aVideoStream->GetMinimumSupportedPAR(getter_AddRefs(minSupportedPAR));
766 NS_ENSURE_SUCCESS(rv, rv);
767 rv = minSupportedPAR->GetNumerator(&numerator);
768 NS_ENSURE_SUCCESS(rv, rv);
769 rv = minSupportedPAR->GetDenominator(&denominator);
770 NS_ENSURE_SUCCESS(rv, rv);
771 sbFraction minPARFraction(numerator, denominator);
773 nsCOMPtr<sbIDevCapFraction> maxSupportedPAR;
774 rv = aVideoStream->GetMaximumSupportedPAR(getter_AddRefs(maxSupportedPAR));
775 NS_ENSURE_SUCCESS(rv, rv);
776 rv = maxSupportedPAR->GetNumerator(&numerator);
777 NS_ENSURE_SUCCESS(rv, rv);
778 rv = maxSupportedPAR->GetDenominator(&denominator);
779 NS_ENSURE_SUCCESS(rv, rv);
780 sbFraction maxPARFraction(numerator, denominator);
782 if (videoParFraction >= minPARFraction &&
783 videoParFraction <= maxPARFraction)
785 *aCompatible = PR_TRUE;
788 LOG((
"media video PAR (%d/%d) not in min/max range of supported PARS!"
789 "min=(%d/%d) max=(%d/%d)",
790 mMediaVideoPARNumerator, mMediaVideoPARDenominator,
791 minPARFraction.Numerator(), minPARFraction.Denominator(),
792 maxPARFraction.Numerator(), maxPARFraction.Denominator()));
796 nsCOMPtr<nsIArray> supportedPARsArray;
797 rv = aVideoStream->GetSupportedPARs(getter_AddRefs(supportedPARsArray));
798 NS_ENSURE_SUCCESS(rv, rv);
801 rv = supportedPARsArray->GetLength(&length);
802 NS_ENSURE_SUCCESS(rv, rv);
804 for (PRUint32
i = 0;
i < length;
i++) {
805 nsCOMPtr<sbIDevCapFraction> curPARFraction =
806 do_QueryElementAt(supportedPARsArray,
i, &rv);
807 NS_ENSURE_SUCCESS(rv, rv);
809 rv = curPARFraction->GetNumerator(&numerator);
810 NS_ENSURE_SUCCESS(rv, rv);
811 rv = curPARFraction->GetDenominator(&denominator);
812 NS_ENSURE_SUCCESS(rv, rv);
815 if (videoParFraction ==
sbFraction(numerator, denominator)) {
816 *aCompatible = PR_TRUE;
820 LOG((
"media video PAR (%d/%d) not equal to supported PAR item[%d] (%d/%d)",
821 mMediaVideoPARNumerator, mMediaVideoPARDenominator,
i,
822 numerator, denominator));
827 if (!(*aCompatible)) {
828 LOG((
"media video PAR not in device supported array!"));
836 sbDeviceCapsCompatibility::CompareVideoFrameRate(
840 TRACE((
"%s[%p]", __FUNCTION__,
this));
841 NS_ENSURE_ARG_POINTER(aVideoStream);
842 NS_ENSURE_ARG_POINTER(aCompatible);
845 *aCompatible = PR_FALSE;
848 PRBool isRange = PR_FALSE;
849 rv = aVideoStream->GetDoesSupportFrameRateRange(&isRange);
850 NS_ENSURE_SUCCESS(rv, rv);
852 PRUint32 numerator, denominator;
853 sbFraction videoFrameRateFraction(mMediaVideoFRNumerator,
854 mMediaVideoFRDenominator);
858 nsCOMPtr<sbIDevCapFraction> minSupportedFR;
859 rv = aVideoStream->GetMinimumSupportedFrameRate(
860 getter_AddRefs(minSupportedFR));
861 NS_ENSURE_SUCCESS(rv, rv);
862 rv = minSupportedFR->GetNumerator(&numerator);
863 NS_ENSURE_SUCCESS(rv, rv);
864 rv = minSupportedFR->GetDenominator(&denominator);
865 NS_ENSURE_SUCCESS(rv, rv);
866 sbFraction minFRFraction(numerator, denominator);
868 nsCOMPtr<sbIDevCapFraction> maxSupportedFR;
869 rv = aVideoStream->GetMaximumSupportedFrameRate(
870 getter_AddRefs(maxSupportedFR));
871 NS_ENSURE_SUCCESS(rv, rv);
872 rv = maxSupportedFR->GetNumerator(&numerator);
873 NS_ENSURE_SUCCESS(rv, rv);
874 rv = maxSupportedFR->GetDenominator(&denominator);
875 NS_ENSURE_SUCCESS(rv, rv);
876 sbFraction maxFRFraction(numerator, denominator);
878 if (videoFrameRateFraction >= minFRFraction &&
879 videoFrameRateFraction <= maxFRFraction)
881 *aCompatible = PR_TRUE;
884 LOG((
"media video frame rate (%d/%d) not in min/max range of "
885 "supported frame rates! min=(%d/%d) max=(%d/%d)",
886 mMediaVideoPARNumerator, mMediaVideoPARDenominator,
887 minFRFraction.Numerator(), minFRFraction.Denominator(),
888 maxFRFraction.Numerator(), maxFRFraction.Denominator()));
892 nsCOMPtr<nsIArray> supportedFrameRatesFraction;
893 rv = aVideoStream->GetSupportedFrameRates(
894 getter_AddRefs(supportedFrameRatesFraction));
895 NS_ENSURE_SUCCESS(rv, rv);
898 rv = supportedFrameRatesFraction->GetLength(&length);
899 NS_ENSURE_SUCCESS(rv, rv);
901 for (PRUint32
i = 0;
i < length;
i++) {
902 nsCOMPtr<sbIDevCapFraction> curFrameRateFraction =
903 do_QueryElementAt(supportedFrameRatesFraction,
i, &rv);
904 NS_ENSURE_SUCCESS(rv, rv);
906 rv = curFrameRateFraction->GetNumerator(&numerator);
907 NS_ENSURE_SUCCESS(rv, rv);
908 rv = curFrameRateFraction->GetDenominator(&denominator);
909 NS_ENSURE_SUCCESS(rv, rv);
912 if (videoFrameRateFraction ==
sbFraction(numerator, denominator)) {
913 *aCompatible = PR_TRUE;
917 LOG((
"media video frame rate (%d/%d) not equal to supported "
918 "frame rate item[%d] (%d/%d)",
919 mMediaVideoPARNumerator, mMediaVideoPARDenominator,
i,
920 numerator, denominator));
925 if (!(*aCompatible)) {
926 LOG((
"media video frame rate not in device supported array!"));
934 sbDeviceCapsCompatibility::CompareAudioBitRate(
938 TRACE((
"%s[%p]", __FUNCTION__,
this));
939 NS_ENSURE_ARG_POINTER(aAudioStream);
940 NS_ENSURE_ARG_POINTER(aCompatible);
943 *aCompatible = PR_FALSE;
946 nsCOMPtr<sbIDevCapRange> deviceSupportedBitRates;
947 rv = aAudioStream->GetSupportedBitRates(
948 getter_AddRefs(deviceSupportedBitRates));
949 NS_ENSURE_SUCCESS(rv, rv);
951 rv = deviceSupportedBitRates->IsValueInRange(mMediaAudioBitRate, aCompatible);
952 NS_ENSURE_SUCCESS(rv, rv);
955 if (!(*aCompatible)) {
956 PRInt32
min, max, step;
957 rv = GetDevCapRangeValues(deviceSupportedBitRates, &min, &max, &step);
958 NS_ENSURE_SUCCESS(rv, rv);
959 LOG((
"media audio bit rate (%d) not in supported range "
960 "(min: %d, max: %d, step: %d)",
961 mMediaAudioBitRate, min, max, step));
969 sbDeviceCapsCompatibility::CompareAudioSampleRate(
973 TRACE((
"%s[%p]", __FUNCTION__,
this));
974 NS_ENSURE_ARG_POINTER(aAudioStream);
975 NS_ENSURE_ARG_POINTER(aCompatible);
978 *aCompatible = PR_FALSE;
981 nsCOMPtr<sbIDevCapRange> deviceSupportedSampleRates;
982 rv = aAudioStream->GetSupportedSampleRates(
983 getter_AddRefs(deviceSupportedSampleRates));
984 NS_ENSURE_SUCCESS(rv, rv);
986 rv = deviceSupportedSampleRates->IsValueInRange(mMediaAudioSampleRate,
988 NS_ENSURE_SUCCESS(rv, rv);
991 if (!(*aCompatible)) {
992 PRInt32
min, max, step;
993 rv = GetDevCapRangeValues(deviceSupportedSampleRates, &min, &max, &step);
994 NS_ENSURE_SUCCESS(rv, rv);
995 LOG((
"media audio sample rate (%d) not in supported range "
996 "(min: %d, max: %d, step: %d)",
997 mMediaAudioSampleRate, min, max, step));
1005 sbDeviceCapsCompatibility::CompareAudioChannels(
1007 PRBool* aCompatible)
1009 TRACE((
"%s[%p]", __FUNCTION__,
this));
1010 NS_ENSURE_ARG_POINTER(aAudioStream);
1011 NS_ENSURE_ARG_POINTER(aCompatible);
1014 *aCompatible = PR_FALSE;
1017 nsCOMPtr<sbIDevCapRange> deviceSupportedChannels;
1018 rv = aAudioStream->GetSupportedChannels(
1019 getter_AddRefs(deviceSupportedChannels));
1020 NS_ENSURE_SUCCESS(rv, rv);
1022 rv = deviceSupportedChannels->IsValueInRange(mMediaAudioChannels,
1024 NS_ENSURE_SUCCESS(rv, rv);
1027 if (!(*aCompatible)) {
1028 PRInt32
min, max, step;
1029 rv = GetDevCapRangeValues(deviceSupportedChannels, &min, &max, &step);
1030 NS_ENSURE_SUCCESS(rv, rv);
1031 LOG((
"media audio channel (%d) not in supported range "
1032 "(min: %d, max: %d, step: %d)",
1033 mMediaAudioChannels, min, max, step));
[UNIMPLEMENTED UNTIL AFTER 0.3]
const PRUint32 CONTENT_IMAGE
const PRUint32 CONTENT_VIDEO
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceCapsCompatibility, sbIDeviceCapsCompatibility) sbDeviceCapsCompatibility
ExtensionSchemeMatcher prototype match
static PRBool StringEqualsToCString(nsAString &string1, nsACString &string2)
This service determines if a media file is compatible with a particular device.
const PRUint32 CONTENT_AUDIO
_getSelectedPageStyle s i