29 #include <sbIDeviceCapabilities.h>
30 #include <sbIDeviceProperties.h>
38 #include <nsComponentManagerUtils.h>
40 #include <nsIDOMDocument.h>
41 #include <nsIDOMElement.h>
42 #include <nsIDOMNamedNodeMap.h>
43 #include <nsIDOMNode.h>
44 #include <nsIDOMNodeList.h>
45 #include <nsIMutableArray.h>
46 #include <nsIScriptSecurityManager.h>
47 #include <nsIPropertyBag2.h>
48 #include <nsIXMLHttpRequest.h>
50 #include <nsServiceManagerUtils.h>
52 #include <nsThreadUtils.h>
54 #define SB_DEVICE_CAPS_ELEMENT "devicecaps"
55 #define SB_DEVICE_CAPS_NS "http://songbirdnest.com/devicecaps/1.0"
61 mRootElement(aRootElement),
62 mHasCapabilities(PR_FALSE)
64 NS_ASSERTION(mRootElement,
"no device capabilities element provided");
72 sbDeviceXMLCapabilities::AddFunctionType(PRUint32 aFunctionType)
74 return mDeviceCaps->SetFunctionTypes(&aFunctionType, 1);
78 sbDeviceXMLCapabilities::AddContentType(PRUint32 aFunctionType,
79 PRUint32 aContentType)
81 return mDeviceCaps->AddContentTypes(aFunctionType, &aContentType, 1);
85 sbDeviceXMLCapabilities::AddMimeType(PRUint32 aContentType,
86 nsAString
const & aMimeType)
88 nsCString
const & mimeTypeString = NS_LossyConvertUTF16toASCII(aMimeType);
89 char const * mimeType = mimeTypeString.BeginReading();
90 return mDeviceCaps->AddMimeTypes(aContentType, &mimeType, 1);
96 NS_ASSERTION(NS_IsMainThread(),
"not on main thread");
100 mDeviceCaps = aCapabilities;
102 rv = ProcessCapabilities(mRootElement);
103 NS_ENSURE_SUCCESS(rv, rv);
114 NS_ENSURE_ARG_POINTER(aCapabilities);
115 NS_ENSURE_ARG_POINTER(aDocument);
121 *aCapabilities = nsnull;
124 nsCOMPtr<nsIDOMElement> documentElem;
125 rv = aDocument->GetDocumentElement(getter_AddRefs(documentElem));
126 NS_ENSURE_SUCCESS(rv, rv);
129 rv = GetCapabilities(aCapabilities, documentElem, aDevice);
130 NS_ENSURE_SUCCESS(rv, rv);
138 nsIDOMNode* aDeviceCapsRootNode,
142 NS_ENSURE_ARG_POINTER(aCapabilities);
143 NS_ENSURE_ARG_POINTER(aDeviceCapsRootNode);
149 *aCapabilities = nsnull;
153 nsCOMPtr<nsIDOMElement>
154 deviceCapsRootElem = do_QueryInterface(aDeviceCapsRootNode, &rv);
159 nsCOMPtr<sbIDeviceCapabilities> deviceCapabilities =
161 NS_ENSURE_SUCCESS(rv, rv);
162 rv = deviceCapabilities->Init();
163 NS_ENSURE_SUCCESS(rv, rv);
165 rv = xmlCapabilities.
Read(deviceCapabilities);
166 NS_ENSURE_SUCCESS(rv, rv);
167 rv = deviceCapabilities->ConfigureDone();
168 NS_ENSURE_SUCCESS(rv, rv);
172 deviceCapabilities.forget(aCapabilities);
180 const char* aXMLCapabilitiesSpec,
181 PRBool* aAddedCapabilities,
185 NS_ENSURE_ARG_POINTER(aCapabilities);
186 NS_ENSURE_ARG_POINTER(aXMLCapabilitiesSpec);
192 if (aAddedCapabilities)
193 *aAddedCapabilities = PR_FALSE;
196 nsCOMPtr<nsIXMLHttpRequest>
197 xmlHttpRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
198 NS_ENSURE_SUCCESS(rv, rv);
199 nsCOMPtr<nsIScriptSecurityManager> ssm =
200 do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
201 NS_ENSURE_SUCCESS(rv, rv);
202 nsCOMPtr<nsIPrincipal> principal;
203 rv = ssm->GetSystemPrincipal(getter_AddRefs(principal));
204 NS_ENSURE_SUCCESS(rv, rv);
205 rv = xmlHttpRequest->Init(principal, nsnull, nsnull, nsnull);
206 NS_ENSURE_SUCCESS(rv, rv);
209 rv = xmlHttpRequest->OpenRequest(NS_LITERAL_CSTRING(
"GET"),
210 nsCString(aXMLCapabilitiesSpec),
214 NS_ENSURE_SUCCESS(rv, rv);
215 rv = xmlHttpRequest->Send(nsnull);
216 NS_ENSURE_SUCCESS(rv, rv);
219 nsCOMPtr<nsIDOMElement> deviceCapsElem;
220 nsCOMPtr<nsIDOMDocument> deviceCapabilitiesDocument;
221 rv = xmlHttpRequest->GetResponseXML
222 (getter_AddRefs(deviceCapabilitiesDocument));
223 NS_ENSURE_SUCCESS(rv, rv);
224 rv = deviceCapabilitiesDocument->GetDocumentElement
225 (getter_AddRefs(deviceCapsElem));
226 NS_ENSURE_SUCCESS(rv, rv);
229 rv = AddCapabilities(aCapabilities,
233 NS_ENSURE_SUCCESS(rv, rv);
241 nsIDOMNode* aDeviceCapsRootNode,
242 PRBool* aAddedCapabilities,
246 NS_ENSURE_ARG_POINTER(aCapabilities);
247 NS_ENSURE_ARG_POINTER(aDeviceCapsRootNode);
253 if (aAddedCapabilities)
254 *aAddedCapabilities = PR_FALSE;
257 nsCOMPtr<sbIDeviceCapabilities> deviceCapabilities;
258 rv = GetCapabilities(getter_AddRefs(deviceCapabilities),
261 NS_ENSURE_SUCCESS(rv, rv);
264 if (deviceCapabilities) {
265 rv = aCapabilities->AddCapabilities(deviceCapabilities);
266 NS_ENSURE_SUCCESS(rv, rv);
267 if (aAddedCapabilities)
268 *aAddedCapabilities = PR_TRUE;
275 sbDeviceXMLCapabilities::ProcessCapabilities(nsIDOMNode* aRootNode)
278 NS_ENSURE_ARG_POINTER(aRootNode);
285 nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(aRootNode, &rv);
288 nsCOMPtr<nsIDOMNodeList> deviceCapsNodeList;
289 rv = rootElement->GetElementsByTagNameNS
292 getter_AddRefs(deviceCapsNodeList));
293 if (NS_FAILED(rv) || !deviceCapsNodeList)
298 rv = deviceCapsNodeList->GetLength(&nodeCount);
299 NS_ENSURE_SUCCESS(rv, rv);
300 for (PRUint32
i = 0;
i < nodeCount;
i++) {
302 nsCOMPtr<nsIDOMNode> deviceCapsNode;
303 rv = deviceCapsNodeList->Item(
i, getter_AddRefs(deviceCapsNode));
304 NS_ENSURE_SUCCESS(rv, rv);
307 PRBool deviceMatches;
308 rv = DeviceMatchesCapabilitiesNode(deviceCapsNode, &deviceMatches);
309 NS_ENSURE_SUCCESS(rv, rv);
311 rv = ProcessDeviceCaps(deviceCapsNode);
312 NS_ENSURE_SUCCESS(rv, rv);
313 mHasCapabilities = PR_TRUE;
321 sbDeviceXMLCapabilities::ProcessDeviceCaps(nsIDOMNode * aDevCapNode)
323 nsCOMPtr<nsIDOMNodeList> nodes;
324 nsresult rv = aDevCapNode->GetChildNodes(getter_AddRefs(nodes));
327 rv = nodes->GetLength(&nodeCount);
328 NS_ENSURE_SUCCESS(rv, rv);
329 nsCOMPtr<nsIDOMNode> domNode;
330 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
331 rv = nodes->Item(nodeIndex, getter_AddRefs(domNode));
332 NS_ENSURE_SUCCESS(rv, rv);
335 rv = domNode->GetNodeName(name);
336 NS_ENSURE_SUCCESS(rv, rv);
338 if (name.Equals(NS_LITERAL_STRING(
"audio"))) {
339 rv = ProcessAudio(domNode);
340 NS_ENSURE_SUCCESS(rv, rv);
342 else if (name.Equals(NS_LITERAL_STRING(
"image"))) {
343 rv = ProcessImage(domNode);
344 NS_ENSURE_SUCCESS(rv, rv);
346 else if (name.Equals(NS_LITERAL_STRING(
"video"))) {
347 rv = ProcessVideo(domNode);
348 NS_ENSURE_SUCCESS(rv, rv);
350 else if (name.Equals(NS_LITERAL_STRING(
"playlist"))) {
351 rv = ProcessPlaylist(domNode);
352 NS_ENSURE_SUCCESS(rv, rv);
371 aNode->GetAttributes(getter_AddRefs(mAttributes));
383 NS_ENSURE_TRUE(mAttributes, NS_ERROR_FAILURE);
384 nsCOMPtr<nsIDOMNode>
node;
385 nsresult rv = mAttributes->GetNamedItem(aName, getter_AddRefs(node));
386 NS_ENSURE_SUCCESS(rv, rv);
389 rv = node->GetNodeValue(aValue);
390 NS_ENSURE_SUCCESS(rv, rv);
394 return NS_ERROR_NOT_AVAILABLE;
407 nsresult rv =
GetValue(aName, value);
409 if (rv == NS_ERROR_NOT_AVAILABLE) {
412 NS_ENSURE_SUCCESS(rv, rv);
414 aValue = value.ToInteger(&rv, 10);
415 NS_ENSURE_SUCCESS(rv, rv);
420 nsCOMPtr<nsIDOMNamedNodeMap> mAttributes;
431 NS_ENSURE_ARG_POINTER(aValueNode);
433 nsCOMPtr<nsIDOMNodeList> nodes;
434 nsresult rv = aValueNode->GetChildNodes(getter_AddRefs(nodes));
435 NS_ENSURE_SUCCESS(rv, rv);
438 rv = nodes->GetLength(&nodeCount);
439 NS_ENSURE_SUCCESS(rv, rv);
442 nsCOMPtr<nsIDOMNode>
node;
443 rv = nodes->Item(0, getter_AddRefs(node));
444 NS_ENSURE_SUCCESS(rv, rv);
445 rv = node->GetNodeValue(aValue);
446 NS_ENSURE_SUCCESS(rv, rv);
459 NS_ENSURE_ARG_POINTER(aRangeNode);
460 NS_ENSURE_ARG_POINTER(aRange);
463 nsCOMPtr<sbIDevCapRange>
range =
465 NS_ENSURE_SUCCESS(rv, rv);
467 nsCOMPtr<nsIDOMNodeList> nodes;
468 rv = aRangeNode->GetChildNodes(getter_AddRefs(nodes));
469 NS_ENSURE_SUCCESS(rv, rv);
472 rv = nodes->GetLength(&nodeCount);
473 NS_ENSURE_SUCCESS(rv, rv);
475 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
476 nsCOMPtr<nsIDOMNode>
node;
477 rv = nodes->Item(nodeIndex, getter_AddRefs(node));
478 NS_ENSURE_SUCCESS(rv, rv);
481 rv = node->GetNodeName(name);
482 NS_ENSURE_SUCCESS(rv, rv);
484 if (name.EqualsLiteral(
"value")) {
487 NS_ENSURE_SUCCESS(rv, rv);
488 PRInt32 bitRateValue = bitRate.ToInteger(&rv, 10);
489 if (NS_SUCCEEDED(rv)) {
490 rv = range->AddValue(bitRateValue);
491 NS_ENSURE_SUCCESS(rv, rv);
494 else if (name.EqualsLiteral(
"range")) {
497 rv = attributes.
GetValue(NS_LITERAL_STRING(
"min"), min);
498 if (rv != NS_ERROR_NOT_AVAILABLE) {
499 NS_ENSURE_SUCCESS(rv, rv);
503 rv = attributes.
GetValue(NS_LITERAL_STRING(
"max"), max);
504 if (rv != NS_ERROR_NOT_AVAILABLE) {
505 NS_ENSURE_SUCCESS(rv, rv);
509 rv = attributes.
GetValue(NS_LITERAL_STRING(
"step"), step);
510 if (rv != NS_ERROR_NOT_AVAILABLE) {
511 NS_ENSURE_SUCCESS(rv, rv);
514 rv = range->Initialize(min, max, step);
515 NS_ENSURE_SUCCESS(rv, rv);
519 range.forget(aRange);
531 PRUint32 *aOutNumerator,
532 PRUint32 *aOutDenominator)
534 NS_ENSURE_ARG_POINTER(aOutNumerator);
535 NS_ENSURE_ARG_POINTER(aOutDenominator);
538 nsTArray<nsString> splitResultArray;
539 nsString_Split(aString, NS_LITERAL_STRING(
"/"), splitResultArray);
540 NS_ENSURE_TRUE(splitResultArray.Length() > 0, NS_ERROR_UNEXPECTED);
542 *aOutNumerator = splitResultArray[0].ToInteger(&rv);
543 NS_ENSURE_SUCCESS(rv, rv);
545 if (splitResultArray.Length() == 2) {
546 *aOutDenominator = splitResultArray[1].ToInteger(&rv);
547 NS_ENSURE_SUCCESS(rv, rv);
550 *aOutDenominator = 1;
565 nsIArray **aOutCapRangeArray,
568 NS_ENSURE_ARG_POINTER(aDOMNode);
569 NS_ENSURE_ARG_POINTER(aOutCapRangeArray);
570 NS_ENSURE_ARG_POINTER(aOutIsRange);
572 nsCOMPtr<nsIDOMNodeList> domNodes;
573 nsresult rv = aDOMNode->GetChildNodes(getter_AddRefs(domNodes));
574 NS_ENSURE_SUCCESS(rv, rv);
580 rv = domNodes->GetLength(&nodeCount);
581 NS_ENSURE_SUCCESS(rv, rv);
583 if (nodeCount == 0) {
587 nsCOMPtr<nsIMutableArray> fractionArray =
588 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
589 NS_ENSURE_SUCCESS(rv, rv);
591 nsString minValue, maxValue;
593 nsCOMPtr<nsIDOMNode> domNode;
594 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
595 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
596 NS_ENSURE_SUCCESS(rv, rv);
599 rv = domNode->GetNodeName(name);
600 NS_ENSURE_SUCCESS(rv, rv);
608 if (name.EqualsLiteral(
"value")) {
609 NS_ENSURE_TRUE(strings.AppendElement(value), NS_ERROR_OUT_OF_MEMORY);
611 else if (name.EqualsLiteral(
"min")) {
612 minValue.Assign(value);
614 else if (name.EqualsLiteral(
"max")) {
615 maxValue.Assign(value);
622 PRUint32 numerator, denominator;
623 if (!minValue.Equals(EmptyString()) || !maxValue.Equals(EmptyString())) {
624 nsCOMPtr<sbIDevCapFraction> minCapFraction =
625 do_CreateInstance(
"@songbirdnest.com/Songbird/Device/sbfraction;1", &rv);
626 NS_ENSURE_SUCCESS(rv, rv);
629 NS_ENSURE_SUCCESS(rv, rv);
631 rv = minCapFraction->Initialize(numerator, denominator);
632 NS_ENSURE_SUCCESS(rv, rv);
634 nsCOMPtr<sbIDevCapFraction> maxCapFraction =
635 do_CreateInstance(
"@songbirdnest.com/Songbird/Device/sbfraction;1", &rv);
636 NS_ENSURE_SUCCESS(rv, rv);
639 NS_ENSURE_SUCCESS(rv, rv);
641 rv = maxCapFraction->Initialize(numerator, denominator);
642 NS_ENSURE_SUCCESS(rv, rv);
646 rv = fractionArray->AppendElement(minCapFraction, PR_FALSE);
647 NS_ENSURE_SUCCESS(rv, rv);
649 rv = fractionArray->AppendElement(maxCapFraction, PR_FALSE);
650 NS_ENSURE_SUCCESS(rv, rv);
652 *aOutIsRange = PR_TRUE;
656 *aOutIsRange = PR_FALSE;
658 for (PRUint32
i = 0;
i < strings.Length();
i++) {
664 nsCOMPtr<sbIDevCapFraction> curFraction =
665 do_CreateInstance(
"@songbirdnest.com/Songbird/Device/sbfraction;1", &rv);
666 NS_ENSURE_SUCCESS(rv, rv);
668 rv = curFraction->Initialize(numerator, denominator);
669 NS_ENSURE_SUCCESS(rv, rv);
671 rv = fractionArray->AppendElement(curFraction, PR_FALSE);
672 NS_ENSURE_SUCCESS(rv, rv);
676 return CallQueryInterface(fractionArray.get(), aOutCapRangeArray);
680 sbDeviceXMLCapabilities::ProcessAudio(nsIDOMNode * aAudioNode)
682 NS_ENSURE_ARG_POINTER(aAudioNode);
684 nsCOMPtr<nsIDOMNodeList> domNodes;
685 nsresult rv = aAudioNode->GetChildNodes(getter_AddRefs(domNodes));
686 NS_ENSURE_SUCCESS(rv, rv);
692 rv = domNodes->GetLength(&nodeCount);
693 NS_ENSURE_SUCCESS(rv, rv);
695 if (nodeCount == 0) {
699 NS_ENSURE_SUCCESS(rv, rv);
703 NS_ENSURE_SUCCESS(rv, rv);
705 nsCOMPtr<nsIDOMNode> domNode;
706 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
707 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
708 NS_ENSURE_SUCCESS(rv, rv);
711 rv = domNode->GetNodeName(name);
712 NS_ENSURE_SUCCESS(rv, rv);
714 if (!name.EqualsLiteral(
"format")) {
721 rv =
attributes.GetValue(NS_LITERAL_STRING(
"mime"),
723 NS_ENSURE_SUCCESS(rv, rv);
726 rv =
attributes.GetValue(NS_LITERAL_STRING(
"container"),
728 if (rv != NS_ERROR_NOT_AVAILABLE) {
729 NS_ENSURE_SUCCESS(rv, rv);
733 rv =
attributes.GetValue(NS_LITERAL_STRING(
"codec"),
735 if (rv != NS_ERROR_NOT_AVAILABLE) {
736 NS_ENSURE_SUCCESS(rv, rv);
739 nsString isPreferredString;
740 rv =
attributes.GetValue(NS_LITERAL_STRING(
"preferred"),
742 if (rv != NS_ERROR_NOT_AVAILABLE) {
743 NS_ENSURE_SUCCESS(rv, rv);
745 PRBool isPreferred = isPreferredString.EqualsLiteral(
"true");
747 nsCOMPtr<nsIDOMNodeList> ranges;
748 rv = domNode->GetChildNodes(getter_AddRefs(ranges));
749 NS_ENSURE_SUCCESS(rv, rv);
752 rv = ranges->GetLength(&rangeCount);
753 NS_ENSURE_SUCCESS(rv, rv);
755 nsCOMPtr<sbIDevCapRange> bitRates;
756 nsCOMPtr<sbIDevCapRange> sampleRates;
757 nsCOMPtr<sbIDevCapRange> channels;
758 for (PRUint32 rangeIndex = 0; rangeIndex < rangeCount; ++rangeIndex) {
759 nsCOMPtr<nsIDOMNode>
range;
760 rv = ranges->Item(rangeIndex, getter_AddRefs(range));
761 NS_ENSURE_SUCCESS(rv, rv);
764 rv = range->GetNodeName(rangeName);
765 NS_ENSURE_SUCCESS(rv, rv);
767 if (rangeName.EqualsLiteral(
"bitrates")) {
768 rv =
BuildRange(range, getter_AddRefs(bitRates));
769 NS_ENSURE_SUCCESS(rv, rv);
771 else if (rangeName.EqualsLiteral(
"samplerates")) {
772 rv =
BuildRange(range, getter_AddRefs(sampleRates));
773 NS_ENSURE_SUCCESS(rv, rv);
775 else if (rangeName.EqualsLiteral(
"channels")) {
776 rv =
BuildRange(range, getter_AddRefs(channels));
777 NS_ENSURE_SUCCESS(rv, rv);
781 nsCOMPtr<sbIAudioFormatType> formatType =
783 NS_ENSURE_SUCCESS(rv, rv);
785 rv = formatType->Initialize(NS_ConvertUTF16toUTF8(container),
786 NS_ConvertUTF16toUTF8(codec),
791 NS_ENSURE_SUCCESS(rv, rv);
794 NS_ENSURE_SUCCESS(rv, rv);
801 NS_ENSURE_SUCCESS(rv, rv);
807 NS_ENSURE_SUCCESS(rv, rv);
814 sbDeviceXMLCapabilities::ProcessImageSizes(
815 nsIDOMNode * aImageSizeNode,
816 nsIMutableArray * aImageSizes)
818 NS_ENSURE_ARG_POINTER(aImageSizeNode);
819 NS_ENSURE_ARG_POINTER(aImageSizes);
823 nsCOMPtr<nsIDOMNodeList> nodes;
824 rv = aImageSizeNode->GetChildNodes(getter_AddRefs(nodes));
825 NS_ENSURE_SUCCESS(rv, rv);
828 rv = nodes->GetLength(&nodeCount);
829 NS_ENSURE_SUCCESS(rv, rv);
831 NS_NAMED_LITERAL_STRING(WIDTH,
"width");
832 NS_NAMED_LITERAL_STRING(HEIGHT,
"height");
834 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
835 nsCOMPtr<nsIDOMNode>
node;
836 rv = nodes->Item(nodeIndex, getter_AddRefs(node));
837 NS_ENSURE_SUCCESS(rv, rv);
840 rv = node->GetNodeName(name);
841 NS_ENSURE_SUCCESS(rv, rv);
843 if (!name.EqualsLiteral(
"size")) {
850 NS_ENSURE_SUCCESS(rv, rv);
855 NS_WARNING(
"Invalid width found in device settings file");
864 rv = imageSize->Initialize(width, height);
865 NS_ENSURE_SUCCESS(rv, rv);
866 rv = aImageSizes->AppendElement(imageSize, PR_FALSE);
867 NS_ENSURE_SUCCESS(rv, rv);
874 sbDeviceXMLCapabilities::ProcessImage(nsIDOMNode * aImageNode)
876 NS_ENSURE_ARG_POINTER(aImageNode);
878 nsCOMPtr<nsIDOMNodeList> domNodes;
879 nsresult rv = aImageNode->GetChildNodes(getter_AddRefs(domNodes));
880 NS_ENSURE_SUCCESS(rv, rv);
886 rv = domNodes->GetLength(&nodeCount);
887 NS_ENSURE_SUCCESS(rv, rv);
889 if (nodeCount == 0) {
893 NS_ENSURE_SUCCESS(rv, rv);
897 NS_ENSURE_SUCCESS(rv, rv);
899 nsCOMPtr<nsIDOMNode> domNode;
900 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
901 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
902 NS_ENSURE_SUCCESS(rv, rv);
905 rv = domNode->GetNodeName(name);
906 NS_ENSURE_SUCCESS(rv, rv);
908 if (!name.EqualsLiteral(
"format")) {
915 rv =
attributes.GetValue(NS_LITERAL_STRING(
"mime"),
917 NS_ENSURE_SUCCESS(rv, rv);
919 nsCOMPtr<nsIMutableArray> imageSizes =
920 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1",
922 NS_ENSURE_SUCCESS(rv, rv);
924 nsCOMPtr<sbIDevCapRange> widths;
925 nsCOMPtr<sbIDevCapRange> heights;
927 nsCOMPtr<nsIDOMNodeList> sections;
928 rv = domNode->GetChildNodes(getter_AddRefs(sections));
929 NS_ENSURE_SUCCESS(rv, rv);
931 PRUint32 sectionCount;
932 rv = sections->GetLength(§ionCount);
933 NS_ENSURE_SUCCESS(rv, rv);
935 for (PRUint32 sectionIndex = 0;
936 sectionIndex < sectionCount;
938 nsCOMPtr<nsIDOMNode> section;
939 rv = sections->Item(sectionIndex, getter_AddRefs(section));
940 NS_ENSURE_SUCCESS(rv, rv);
942 nsString sectionName;
943 rv = section->GetNodeName(sectionName);
944 NS_ENSURE_SUCCESS(rv, rv);
946 if (sectionName.EqualsLiteral(
"explicit-sizes")) {
947 rv = ProcessImageSizes(section, imageSizes);
948 NS_ENSURE_SUCCESS(rv, rv);
950 else if (sectionName.EqualsLiteral(
"widths")) {
951 rv =
BuildRange(section, getter_AddRefs(widths));
952 NS_ENSURE_SUCCESS(rv, rv);
954 else if (sectionName.EqualsLiteral(
"heights")) {
955 rv =
BuildRange(section, getter_AddRefs(heights));
956 NS_ENSURE_SUCCESS(rv, rv);
959 nsCOMPtr<sbIImageFormatType> imageFormatType =
961 NS_ENSURE_SUCCESS(rv, rv);
963 rv = imageFormatType->Initialize(NS_ConvertUTF16toUTF8(mimeType),
967 NS_ENSURE_SUCCESS(rv, rv);
970 NS_ENSURE_SUCCESS(rv, rv);
975 NS_ENSURE_SUCCESS(rv, rv);
985 sbDeviceXMLCapabilities::ProcessVideoStream(nsIDOMNode* aVideoStreamNode,
989 nsCOMPtr<nsIDOMNodeList> domNodes;
990 nsresult rv = aVideoStreamNode->GetChildNodes(getter_AddRefs(domNodes));
991 NS_ENSURE_SUCCESS(rv, rv);
998 rv = domNodes->GetLength(&nodeCount);
999 NS_ENSURE_SUCCESS(rv, rv);
1000 if (nodeCount == 0) {
1008 attributes.
GetValue(NS_LITERAL_STRING(
"type"), type);
1010 nsCOMPtr<nsIMutableArray> sizes =
1011 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1",
1013 NS_ENSURE_SUCCESS(rv, rv);
1014 nsCOMPtr<sbIDevCapRange> widths;
1015 nsCOMPtr<sbIDevCapRange> heights;
1016 nsCOMPtr<sbIDevCapRange> bitRates;
1018 PRBool parValuesAreRange = PR_TRUE;
1019 nsCOMPtr<nsIArray> parValueArray;
1021 PRBool frameRateValuesAreRange = PR_TRUE;
1022 nsCOMPtr<nsIArray> frameRateValuesArray;
1024 nsCOMPtr<nsIDOMNode> domNode;
1025 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1026 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
1027 NS_ENSURE_SUCCESS(rv, rv);
1029 rv = domNode->GetNodeName(name);
1030 if (NS_FAILED(rv)) {
1033 if (name.Equals(NS_LITERAL_STRING(
"explicit-sizes"))) {
1034 rv = ProcessImageSizes(domNode, sizes);
1035 NS_ENSURE_SUCCESS(rv, rv);
1037 else if (name.Equals(NS_LITERAL_STRING(
"widths"))) {
1038 rv =
BuildRange(domNode, getter_AddRefs(widths));
1039 NS_ENSURE_SUCCESS(rv, rv);
1041 else if (name.Equals(NS_LITERAL_STRING(
"heights"))) {
1042 rv =
BuildRange(domNode, getter_AddRefs(heights));
1043 NS_ENSURE_SUCCESS(rv, rv);
1045 else if (name.Equals(NS_LITERAL_STRING(
"videoPARs")) ||
1046 name.Equals(NS_LITERAL_STRING(
"videoPAR")))
1049 getter_AddRefs(parValueArray),
1050 &parValuesAreRange);
1051 NS_ENSURE_SUCCESS(rv, rv);
1053 else if (name.Equals(NS_LITERAL_STRING(
"frame-rates"))) {
1055 getter_AddRefs(frameRateValuesArray),
1056 &frameRateValuesAreRange);
1057 NS_ENSURE_SUCCESS(rv, rv);
1059 else if (name.Equals(NS_LITERAL_STRING(
"bit-rates"))) {
1060 rv =
BuildRange(domNode, getter_AddRefs(bitRates));
1061 NS_ENSURE_SUCCESS(rv, rv);
1065 nsCOMPtr<sbIDevCapVideoStream> videoStream =
1067 NS_ENSURE_SUCCESS(rv, rv);
1069 rv = videoStream->Initialize(NS_ConvertUTF16toUTF8(type),
1075 frameRateValuesArray,
1076 frameRateValuesAreRange,
1078 NS_ENSURE_SUCCESS(rv, rv);
1080 videoStream.forget(aVideoStream);
1086 sbDeviceXMLCapabilities::ProcessAudioStream(nsIDOMNode* aAudioStreamNode,
1090 nsCOMPtr<nsIDOMNodeList> domNodes;
1091 nsresult rv = aAudioStreamNode->GetChildNodes(getter_AddRefs(domNodes));
1092 NS_ENSURE_SUCCESS(rv, rv);
1099 rv = domNodes->GetLength(&nodeCount);
1100 NS_ENSURE_SUCCESS(rv, rv);
1101 if (nodeCount == 0) {
1109 attributes.GetValue(NS_LITERAL_STRING(
"type"), type);
1111 nsCOMPtr<sbIDevCapRange> bitRates;
1112 nsCOMPtr<sbIDevCapRange> sampleRates;
1113 nsCOMPtr<sbIDevCapRange> channels;
1115 nsCOMPtr<nsIDOMNode> domNode;
1116 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1117 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
1118 NS_ENSURE_SUCCESS(rv, rv);
1120 rv = domNode->GetNodeName(name);
1121 if (NS_FAILED(rv)) {
1124 if (name.Equals(NS_LITERAL_STRING(
"bit-rates"))) {
1125 rv =
BuildRange(domNode, getter_AddRefs(bitRates));
1126 NS_ENSURE_SUCCESS(rv, rv);
1128 else if (name.Equals(NS_LITERAL_STRING(
"sample-rates"))) {
1129 rv =
BuildRange(domNode, getter_AddRefs(sampleRates));
1130 NS_ENSURE_SUCCESS(rv, rv);
1132 else if (name.Equals(NS_LITERAL_STRING(
"channels"))) {
1133 rv =
BuildRange(domNode, getter_AddRefs(channels));
1134 NS_ENSURE_SUCCESS(rv, rv);
1138 nsCOMPtr<sbIDevCapAudioStream> audioStream =
1140 NS_ENSURE_SUCCESS(rv, rv);
1142 rv = audioStream->Initialize(NS_ConvertUTF16toUTF8(type),
1146 NS_ENSURE_SUCCESS(rv, rv);
1148 audioStream.forget(aAudioStream);
1154 sbDeviceXMLCapabilities::ProcessVideoFormat(nsIDOMNode* aVideoFormatNode)
1160 nsString containerType;
1161 rv =
attributes.GetValue(NS_LITERAL_STRING(
"container-type"),
1163 if (NS_FAILED(rv)) {
1167 nsString isPreferredString;
1168 rv =
attributes.GetValue(NS_LITERAL_STRING(
"preferred"),
1170 if (rv != NS_ERROR_NOT_AVAILABLE) {
1171 NS_ENSURE_SUCCESS(rv, rv);
1173 PRBool isPreferred = isPreferredString.EqualsLiteral(
"true");
1176 nsCOMPtr<nsIDOMNodeList> domNodes;
1177 rv = aVideoFormatNode->GetChildNodes(getter_AddRefs(domNodes));
1178 NS_ENSURE_SUCCESS(rv, rv);
1185 rv = domNodes->GetLength(&nodeCount);
1186 NS_ENSURE_SUCCESS(rv, rv);
1188 nsCOMPtr<sbIDevCapVideoStream> videoStream;
1189 nsCOMPtr<sbIDevCapAudioStream> audioStream;
1190 nsCOMPtr<nsIDOMNode> domNode;
1191 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1192 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
1193 NS_ENSURE_SUCCESS(rv, rv);
1196 rv = domNode->GetNodeName(name);
1197 if (NS_FAILED(rv)) {
1200 if (name.Equals(NS_LITERAL_STRING(
"video-stream"))) {
1201 ProcessVideoStream(domNode, getter_AddRefs(videoStream));
1203 else if (name.Equals(NS_LITERAL_STRING(
"audio-stream"))) {
1204 ProcessAudioStream(domNode, getter_AddRefs(audioStream));
1208 nsCOMPtr<sbIVideoFormatType> videoFormat =
1210 NS_ENSURE_SUCCESS(rv, rv);
1212 rv = videoFormat->Initialize(NS_ConvertUTF16toUTF8(containerType),
1215 NS_ENSURE_SUCCESS(rv, rv);
1218 NS_ENSURE_SUCCESS(rv, rv);
1225 NS_ENSURE_SUCCESS(rv, rv);
1231 NS_ENSURE_SUCCESS(rv, rv);
1238 sbDeviceXMLCapabilities::ProcessVideo(nsIDOMNode * aVideoNode)
1240 NS_ENSURE_ARG_POINTER(aVideoNode);
1243 nsCOMPtr<nsIDOMNodeList> domNodes;
1244 nsresult rv = aVideoNode->GetChildNodes(getter_AddRefs(domNodes));
1245 NS_ENSURE_SUCCESS(rv, rv);
1252 rv = domNodes->GetLength(&nodeCount);
1253 NS_ENSURE_SUCCESS(rv, rv);
1254 if (nodeCount == 0) {
1259 NS_ENSURE_SUCCESS(rv, rv);
1263 NS_ENSURE_SUCCESS(rv, rv);
1265 nsCOMPtr<nsIDOMNode> domNode;
1266 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1267 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
1268 NS_ENSURE_SUCCESS(rv, rv);
1271 rv = domNode->GetNodeName(name);
1272 if (NS_FAILED(rv)) {
1277 if (!name.EqualsLiteral(
"format")) {
1281 ProcessVideoFormat(domNode);
1287 sbDeviceXMLCapabilities::ProcessPlaylist(nsIDOMNode * aPlaylistNode)
1289 NS_ENSURE_ARG_POINTER(aPlaylistNode);
1291 nsCOMPtr<nsIDOMNodeList> domNodes;
1292 nsresult rv = aPlaylistNode->GetChildNodes(getter_AddRefs(domNodes));
1293 NS_ENSURE_SUCCESS(rv, rv);
1299 rv = domNodes->GetLength(&nodeCount);
1300 NS_ENSURE_SUCCESS(rv, rv);
1302 if (nodeCount == 0) {
1307 NS_ENSURE_SUCCESS(rv, rv);
1311 NS_ENSURE_SUCCESS(rv, rv);
1313 nsCOMPtr<nsIDOMNode> domNode;
1314 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1315 rv = domNodes->Item(nodeIndex, getter_AddRefs(domNode));
1316 NS_ENSURE_SUCCESS(rv, rv);
1319 rv = domNode->GetNodeName(name);
1320 NS_ENSURE_SUCCESS(rv, rv);
1322 if (!name.EqualsLiteral(
"format")) {
1329 rv =
attributes.GetValue(NS_LITERAL_STRING(
"mime"),
1331 NS_ENSURE_SUCCESS(rv, rv);
1333 nsString pathSeparator;
1334 rv =
attributes.GetValue(NS_LITERAL_STRING(
"pathSeparator"), pathSeparator);
1336 if (rv == NS_ERROR_NOT_AVAILABLE) {
1337 pathSeparator.SetIsVoid(PR_TRUE);
1339 NS_ENSURE_SUCCESS(rv, rv);
1343 NS_ENSURE_SUCCESS(rv, rv);
1345 nsCOMPtr<sbIPlaylistFormatType> formatType =
1347 NS_ENSURE_SUCCESS(rv, rv);
1349 rv = formatType->Initialize(NS_ConvertUTF16toUTF8(pathSeparator));
1350 NS_ENSURE_SUCCESS(rv, rv);
1355 NS_ENSURE_SUCCESS(rv, rv);
1362 sbDeviceXMLCapabilities::DeviceMatchesCapabilitiesNode
1363 (nsIDOMNode * aCapabilitiesNode,
1364 PRBool * aDeviceMatches)
1366 NS_ENSURE_ARG_POINTER(aCapabilitiesNode);
1367 NS_ENSURE_ARG_POINTER(aDeviceMatches);
1374 nsCOMPtr<nsIDOMNode> devicesNode;
1375 rv = GetFirstChildByTagName(aCapabilitiesNode,
1377 getter_AddRefs(devicesNode));
1378 NS_ENSURE_SUCCESS(rv, rv);
1380 *aDeviceMatches = PR_TRUE;
1386 *aDeviceMatches = PR_FALSE;
1391 nsCOMPtr<sbIDeviceProperties> deviceProperties;
1392 rv = mDevice->GetProperties(getter_AddRefs(deviceProperties));
1393 NS_ENSURE_SUCCESS(rv, rv);
1394 nsCOMPtr<nsIPropertyBag2> properties;
1395 rv = deviceProperties->GetProperties(getter_AddRefs(properties));
1396 NS_ENSURE_SUCCESS(rv, rv);
1399 nsCOMPtr<nsIDOMNodeList> childNodeList;
1400 rv = devicesNode->GetChildNodes(getter_AddRefs(childNodeList));
1401 NS_ENSURE_SUCCESS(rv, rv);
1402 if (!childNodeList) {
1403 *aDeviceMatches = PR_FALSE;
1408 rv = childNodeList->GetLength(&nodeCount);
1409 NS_ENSURE_SUCCESS(rv, rv);
1410 for (PRUint32 nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) {
1412 nsCOMPtr<nsIDOMNode> childNode;
1413 rv = childNodeList->Item(nodeIndex, getter_AddRefs(childNode));
1414 NS_ENSURE_SUCCESS(rv, rv);
1418 rv = childNode->GetNodeName(nodeName);
1419 NS_ENSURE_SUCCESS(rv, rv);
1420 if (!nodeName.EqualsLiteral(
"device")) {
1426 rv = DeviceMatchesDeviceNode(childNode, properties, &matches);
1427 NS_ENSURE_SUCCESS(rv, rv);
1429 *aDeviceMatches = PR_TRUE;
1435 *aDeviceMatches = PR_FALSE;
1441 sbDeviceXMLCapabilities::DeviceMatchesDeviceNode
1442 (nsIDOMNode * aDeviceNode,
1443 nsIPropertyBag2 * aDeviceProperties,
1444 PRBool * aDeviceMatches)
1446 NS_ENSURE_ARG_POINTER(aDeviceNode);
1447 NS_ENSURE_ARG_POINTER(aDeviceProperties);
1448 NS_ENSURE_ARG_POINTER(aDeviceMatches);
1454 rv = aDeviceNode->GetAttributes(getter_AddRefs(attributes));
1455 NS_ENSURE_SUCCESS(rv, rv);
1458 PRBool matches = PR_TRUE;
1459 PRUint32 attributeCount;
1460 rv = attributes->GetLength(&attributeCount);
1461 NS_ENSURE_SUCCESS(rv, rv);
1462 for (PRUint32 attributeIndex = 0;
1463 attributeIndex < attributeCount;
1466 nsCOMPtr<nsIDOMNode> attribute;
1467 rv = attributes->Item(attributeIndex, getter_AddRefs(attribute));
1468 NS_ENSURE_SUCCESS(rv, rv);
1471 nsAutoString attributeName;
1472 rv = attribute->GetNodeName(attributeName);
1473 NS_ENSURE_SUCCESS(rv, rv);
1476 nsAutoString attributeValue;
1477 rv = attribute->GetNodeValue(attributeValue);
1478 NS_ENSURE_SUCCESS(rv, rv);
1482 deviceKey.Append(attributeName);
1486 rv = aDeviceProperties->HasKey(deviceKey, &hasKey);
1487 NS_ENSURE_SUCCESS(rv, rv);
1494 nsCOMPtr<nsIVariant> deviceValue;
1495 rv = aDeviceProperties->Get(deviceKey, getter_AddRefs(deviceValue));
1496 NS_ENSURE_SUCCESS(rv, rv);
1502 NS_ENSURE_SUCCESS(rv, rv);
1510 *aDeviceMatches = matches;
1516 sbDeviceXMLCapabilities::GetFirstChildByTagName(nsIDOMNode* aNode,
1517 const char* aTagName,
1518 nsIDOMNode** aChildNode)
1520 NS_ENSURE_ARG_POINTER(aTagName);
1521 NS_ENSURE_ARG_POINTER(aChildNode);
1526 nsCOMPtr<nsIDOMNodeList> childNodeList;
1527 rv = aNode->GetChildNodes(getter_AddRefs(childNodeList));
1528 NS_ENSURE_SUCCESS(rv, rv);
1531 nsAutoString tagName;
1532 tagName.AssignLiteral(aTagName);
1533 PRUint32 childNodeCount;
1534 rv = childNodeList->GetLength(&childNodeCount);
1535 NS_ENSURE_SUCCESS(rv, rv);
1536 for (PRUint32 nodeIndex = 0; nodeIndex < childNodeCount; ++nodeIndex) {
1538 nsCOMPtr<nsIDOMNode> childNode;
1539 rv = childNodeList->Item(nodeIndex, getter_AddRefs(childNode));
1540 NS_ENSURE_SUCCESS(rv, rv);
1544 rv = childNode->GetNodeName(nodeName);
1545 NS_ENSURE_SUCCESS(rv, rv);
1548 if (nodeName.Equals(tagName)) {
1549 childNode.forget(aChildNode);
1555 *aChildNode = nsnull;
nsresult sbVariantsEqual(nsIVariant *aVariant1, nsIVariant *aVariant2, PRBool *aEqual)
#define SB_IAUDIOFORMATTYPE_CONTRACTID
static nsresult GetStringFractionValues(const nsAString &aString, PRUint32 *aOutNumerator, PRUint32 *aOutDenominator)
const PRUint32 FUNCTION_AUDIO_PLAYBACK
sbDOMNodeAttributes(nsIDOMNode *aNode)
const PRUint32 FUNCTION_VIDEO_PLAYBACK
#define SB_IMAGESIZE_CONTRACTID
[UNIMPLEMENTED UNTIL AFTER 0.3]
Songbird Variant Utility Definitions.
const PRUint32 CONTENT_IMAGE
nsresult Read(sbIDeviceCapabilities *aCapabilities)
~sbDeviceXMLCapabilities()
#define SB_DEVICE_CAPS_ELEMENT
Songbird Variant Utility Definitions.
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...
#define SB_IIMAGEFORMATTYPE_CONTRACTID
#define SB_IDEVCAPAUDIOSTREAM_CONTRACTID
const PRUint32 CONTENT_PLAYLIST
void AddFormatType(in PRUint32 aContentType, in AString aMimeType, in nsISupports aFormatType)
Add a constraint to a mime type.
#define SB_IDEVCAPVIDEOSTREAM_CONTRACTID
const PRUint32 CONTENT_VIDEO
#define SONGBIRD_DEVICECAPABILITIES_CONTRACTID
static nsresult GetFractionRangeValues(nsIDOMNode *aDOMNode, nsIArray **aOutCapRangeArray, PRBool *aOutIsRange)
_collectFormDataForFrame aDocument
void nsString_Split(const nsAString &aString, const nsAString &aDelimiter, nsTArray< nsString > &aSubStringArray)
#define SB_DEVICE_PROPERTY_BASE
nsresult GetValue(nsAString const &aName, PRInt32 &aValue)
sbDeviceXMLCapabilities(nsIDOMElement *aRootElement, sbIDevice *aDevice=nsnull)
static nsresult AddCapabilities(sbIDeviceCapabilities *aCapabilities, const char *aXMLCapabilitiesSpec, PRBool *aAddedCapabilities=nsnull, sbIDevice *aDevice=nsnull)
#define SB_IDEVCAPRANGE_CONTRACTID
static nsresult GetNodeValue(nsIDOMNode *aValueNode, nsAString &aValue)
const PRUint32 FUNCTION_IMAGE_DISPLAY
nsresult GetValue(nsAString const &aName, nsAString &aValue)
#define SB_IVIDEOFORMATTYPE_CONTRACTID
const PRUint32 CONTENT_AUDIO
static nsresult BuildRange(nsIDOMNode *aRangeNode, sbIDevCapRange **aRange)
#define SB_IPLAYLISTFORMATTYPE_CONTRACTID
static nsresult GetCapabilities(sbIDeviceCapabilities **aCapabilities, nsIDOMDocument *aDocument, sbIDevice *aDevice=nsnull)
_getSelectedPageStyle s i
#define SB_DEVICE_CAPS_NS
sbAutoFreeXPCOMArrayByRef< char ** > sbAutoStringArray