deviceCapsDump.js
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 var Cc = Components.classes;
26 var Ci = Components.interfaces;
27 var Cu = Components.utils;
28 
29 
31 {
32  _output: "",
33 
34  onDialogLoad: function()
35  {
36  this._clearDeviceMenupopup();
37 
38  // Fill out the devices menupopup.
39  var menupopup = document.getElementById("devices-menupopup");
40  var deviceRegistrar = Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
41  .getService(Ci.sbIDeviceRegistrar);
42  var devicesArray = deviceRegistrar.devices;
43  for (var i = 0; i < devicesArray.length; i++) {
44  var curDevice = devicesArray.queryElementAt(i, Ci.sbIDevice);
45 
46  var deviceNode = document.createElement("menuitem");
47  deviceNode.setAttribute("label", curDevice.name);
48  deviceNode.setAttribute("device_id", curDevice.id);
49 
50  menupopup.appendChild(deviceNode);
51  }
52 
53  var self = this;
54  this._commandHandler = function() {
55  self._onDeviceSelected();
56  };
57  menupopup.addEventListener("command", self._commandHandler, false);
58  },
59 
60  _onDeviceSelected: function()
61  {
62  var selectedItem =
63  document.getElementById("devices-menulist").selectedItem;
64 
65  // Same device selected, continue on.
66  var deviceID = selectedItem.getAttribute("device_id");
67  if (deviceID == this._curSelectedDeviceId) {
68  return;
69  }
70 
71  // Lookup the device in the device registrar.
72  var deviceRegistrar = Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
73  .getService(Ci.sbIDeviceRegistrar);
74  var device = deviceRegistrar.getDevice(Components.ID(deviceID));
75  if (!device) {
76  // Device no longer exists.
77  return;
78  }
79 
80  this._output = "";
81  this._clearDescField();
82 
83  var caps = device.capabilities;
84  var retFormats = caps.getSupportedFunctionTypes({});
85 
86  var formatIndex;
87  for (formatIndex in retFormats) {
88  var contentArray =
89  caps.getSupportedContentTypes(retFormats[formatIndex], {});
90 
91  for (var contentCount = 0;
92  contentCount < contentArray.length;
93  contentCount++)
94  {
95  var formatArray =
96  caps.getSupportedMimeTypes(contentArray[contentCount], {});
97 
98  for (var formatIndex = 0;
99  formatIndex < formatArray.length;
100  formatIndex++)
101  {
102  try {
103  var formats = caps.getFormatTypes(contentArray[contentCount],
104  formatArray[formatIndex],
105  {});
106 
107  for each (format in formats) {
108  // Pass on logging depending on what type the format is.
109  if (format instanceof Ci.sbIAudioFormatType) {
110  format.QueryInterface(Ci.sbIAudioFormatType);
111  this._logAudioFormatType(format, formatArray[formatIndex]);
112  }
113  else if (format instanceof Ci.sbIVideoFormatType) {
114  format.QueryInterface(Ci.sbIVideoFormatType);
115  this._logVideoFormatType(format, formatArray[formatIndex]);
116  }
117  else if (format instanceof Ci.sbIImageFormatType) {
118  format.QueryInterface(Ci.sbIImageFormatType);
119  this._logImageFormatType(format, formatArray[formatIndex]);
120  }
121  }
122  }
123  catch (e) {
124  // If a format type isn't available, it's most likely a device
125  // function type.
126  this._logGenericFormatType(contentArray[contentCount],
127  formatArray[formatIndex]);
128  }
129  }
130  }
131  }
132 
133  document.getElementById("devicecaps-desc").appendChild(
134  document.createTextNode(this._output));
135  },
136 
137  _logGenericFormatType: function(aContentType, aFormat)
138  {
139  var contentType = "";
140  var sbIDC = Ci.sbIDeviceCapabilities;
141  switch (aContentType) {
142  case sbIDC.CONTENT_UNKNOWN:
143  contentType = "UNKNOWN";
144  break;
145 
146  case sbIDC.CONTENT_FILE:
147  contentType = "FILE";
148  break;
149 
150  case sbIDC.CONTENT_FOLDER:
151  contentType = "FOLDER";
152  break;
153 
154  case sbIDC.CONTENT_AUDIO:
155  contentType = "AUDIO";
156  break;
157 
158  case sbIDC.CONTENT_IMAGE:
159  contentType = "IMAGE";
160  break;
161 
162  case sbIDC.CONTENT_VIDEO:
163  contentType = "VIDEO";
164  break;
165 
166  case sbIDC.CONTENT_PLAYLIST:
167  contentType = "PLAYLIST";
168  break;
169 
170  case sbIDC.CONTENT_ALBUM:
171  contentType = "ALBUM";
172  break;
173 
174  case sbIDC.CONTENT_MAX_TYPES:
175  contentType = "MAX_TYPES";
176  break;
177  }
178 
179  this._output +=
180  " *** " + contentType + " FORMAT '" + aFormat + "' ***\n\n";
181  },
182 
183  _logAudioFormatType: function(aAudioFormat, aFormat)
184  {
185  var codec = aAudioFormat.audioCodec;
186  var containerFormat = aAudioFormat.containerFormat;
187  var bitrates = aAudioFormat.supportedBitrates;
188  var sampleRates = aAudioFormat.supportedSampleRates;
189  var channels = aAudioFormat.supportedChannels;
190 
191  this._output +=
192  " *** AUDIO FORMAT TYPE '" + aFormat + "' ***\n" +
193  " * codec: " + codec + "\n" +
194  " * container format: " + containerFormat + "\n" +
195  " * bitrates: \n" + this._logRange(bitrates, true) +
196  " * samplerates: \n" + this._logRange(sampleRates, false) +
197  " * channels: \n" + this._logRange(channels, true) + "\n";
198  },
199 
200  _logVideoFormatType: function(aVideoFormat, aFormat)
201  {
202  var containerType = aVideoFormat.containerType;
203 
204  var videoStreamType = aVideoFormat.videoStream.type;
205  var videoStreamSizes = aVideoFormat.videoStream.supportedExplicitSizes;
206  var videoStreamWidths = aVideoFormat.videoStream.supportedWidths;
207  var videoStreamHeights = aVideoFormat.videoStream.supportedHeights;
208  var videoStreamBitrates = aVideoFormat.videoStream.supportedBitRates;
209  var videoStreamPars = aVideoFormat.videoStream.supportedPARs;
210  var videoStreamParsIsRange = aVideoFormat.videoStream.doesSupportPARRange;
211  var videoStreamFrameRates = aVideoFormat.videoStream.supportedFrameRates;
212  var videoStreamFrameratesIsRange = aVideoFormat.videoStream.doesSupportFrameRateRange;
213 
214  var audioStreamType = aVideoFormat.audioStream.type;
215  var audioStreamBitrates = aVideoFormat.audioStream.supportedBitRates;
216  var audioStreamSampleRates = aVideoFormat.audioStream.supportedSampleRates;
217  var audioStreamChannels = aVideoFormat.audioStream.supportedChannels;
218 
219  this._output +=
220  " *** VIDEO FORMAT TYPE '" + aFormat + "' ***\n" +
221  " * video format container type: " + containerType + "\n" +
222  " * videostream type: " + videoStreamType + "\n" +
223  " * videostream supported widths: \n" +
224  this._logRange(videoStreamWidths, true) +
225  " * videostream supported heights: \n" +
226  this._logRange(videoStreamHeights, true) +
227  " * videostream bitrates: \n" +
228  this._logRange(videoStreamBitrates, true) +
229  " * videostream PARs: \n" + this._logFractionRange(videoStreamPars, videoStreamParsIsRange) +
230  " * videostream frame rates: \n" + this._logFractionRange(videoStreamFrameRates, videoStreamFrameratesIsRange) +
231  " * audiostream type: " + audioStreamType + "\n" +
232  " * audiostream bitrates: \n" +
233  this._logRange(audioStreamBitrates, true) +
234  " * audiostream samplerates: \n" +
235  this._logRange(audioStreamSampleRates, false) +
236  " * audiostream channels: \n" +
237  this._logRange(audioStreamChannels, true) + "\n";
238  },
239 
240  _logImageFormatType: function(aImageFormat, aFormat)
241  {
242  var imgFormat = aImageFormat.imageFormat;
243  var widths = aImageFormat.supportedWidths;
244  var heights = aImageFormat.supportedHeights;
245  var sizes = aImageFormat.supportedExplicitSizes;
246 
247  this._output +=
248  " *** IMAGE FORMAT TYPE '" + aFormat + "' ***\n" +
249  " * image format: " + imgFormat + "\n" +
250  " * image widths: \n" + this._logRange(widths, true) +
251  " * image heights: \n" + this._logRange(heights, true) +
252  " * image supported sizes: \n" + this._logSizesArray(sizes) + "\n";
253  },
254 
255  _fractionToString: function(aFrac)
256  {
257  return "" + aFrac.numerator + "/" + aFrac.denominator;
258  },
259 
260  _logFractionRange: function(aRange, aIsRange)
261  {
262  var output = "";
263 
264  if (aRange) {
265  if (aIsRange && aRange.length == 2) {
266  output += " - min: " + this._fractionToString(aRange.queryElementAt(
267  0, Ci.sbIDevCapFraction)) + "\n" +
268  " - max: " + this._fractionToString(aRange.queryElementAt(
269  1, Ci.sbIDevCapFraction)) + "\n";
270  }
271  else {
272  for (var i = 0; i < aRange.length; i++) {
273  output += " - " + this._fractionToString(aRange.queryElementAt(
274  i, Ci.sbIDevCapFraction)) + "\n";
275  }
276  }
277  }
278  return output;
279  },
280 
281  _logRange: function(aRange, aIsMinMax)
282  {
283  var output = "";
284 
285  if (aRange) {
286  if (aIsMinMax) {
287  output += " - min: " + aRange.min + "\n" +
288  " - max: " + aRange.max + "\n" +
289  " - step: " + aRange.step + "\n";
290  }
291  else {
292  for (var i = 0; i < aRange.valueCount; i++) {
293  output += " - " + aRange.GetValue(i) + "\n";
294  }
295  }
296  }
297 
298  return output;
299  },
300 
301  _logSizesArray: function(aSizesArray)
302  {
303  var output = "";
304 
305  if (aSizesArray) {
306  for (var i = 0; i < aSizesArray.length; i++) {
307  var imageSize = aSizesArray.queryElementAt(i, Ci.sbIImageSize);
308  output += " - " + imageSize.width +
309  " x " + imageSize.height + "\n";
310  }
311  }
312 
313  return output;
314  },
315 
316  _logArray: function(aArray)
317  {
318  var output = "";
319 
320  if (aArray) {
321  for (var i = 0; i < aArray.length; i++) {
322  output += " - " + aArray[i] + "\n";
323  }
324  }
325 
326  return output;
327  },
328 
329  _clearDeviceMenupopup: function()
330  {
331  var menupopup = document.getElementById("devices-menupopup");
332  while (menupopup.firstChild) {
333  menupopup.removeChild(menupopup.firstChild);
334  }
335  },
336 
337  _clearDescField: function()
338  {
339  var desc = document.getElementById("devicecaps-desc");
340  while (desc.firstChild) {
341  desc.removeChild(desc.firstChild);
342  }
343  },
344 };
345 
var Cc
var selectedItem
Definition: FeedWriter.js:1261
var Ci
var imageSize
Definition: pageInfo.js:959
_getSelectedPageStyle s i
var Cu
var DialogController