From 5f730f93df3716fc3cefcdaabd8801731f67d05b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 25 Oct 2012 18:59:45 -0700 Subject: [PATCH] Perform video codec checks. --- .../src/main/webapp/scripts/interface.js | 87 ++++++++++++++----- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/guacamole/src/main/webapp/scripts/interface.js b/guacamole/src/main/webapp/scripts/interface.js index 48b0abb94..b1df3a810 100644 --- a/guacamole/src/main/webapp/scripts/interface.js +++ b/guacamole/src/main/webapp/scripts/interface.js @@ -67,6 +67,12 @@ var GuacamoleUI = { */ GuacamoleUI.supportedAudio = []; +/** + * Array of all supported video mimetypes, populated when this script is + * loaded. + */ +GuacamoleUI.supportedVideo = []; + // Constant UI initialization and behavior (function() { @@ -490,34 +496,71 @@ GuacamoleUI.supportedAudio = []; GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px"; }); - var probably_supported = []; - var maybe_supported = []; + // Query audio support + (function () { + var probably_supported = []; + var maybe_supported = []; - // Build array of supported audio formats - [ - 'audio/ogg; codecs="vorbis"', - 'audio/mpeg; codecs="mp3"', - 'audio/wav' - ].forEach(function(mimetype) { + // Build array of supported audio formats + [ + 'audio/ogg; codecs="vorbis"', + 'audio/mp4; codecs="mp4a.40.5"', + 'audio/mpeg; codecs="mp3"', + 'audio/webm; codecs="vorbis"', + 'audio/wav; codecs=1' + ].forEach(function(mimetype) { - var audio = new Audio(); - var support_level = audio.canPlayType(mimetype); + var audio = new Audio(); + var support_level = audio.canPlayType(mimetype); - // Trim semicolon and trailer - var semicolon = mimetype.indexOf(";"); - if (semicolon != -1) - mimetype = mimetype.substring(0, semicolon); + // Trim semicolon and trailer + var semicolon = mimetype.indexOf(";"); + if (semicolon != -1) + mimetype = mimetype.substring(0, semicolon); - // Partition by probably/maybe - if (support_level == "probably") - probably_supported.push(mimetype); - else if (support_level == "maybe") - maybe_supported.push(mimetype); + // Partition by probably/maybe + if (support_level == "probably") + probably_supported.push(mimetype); + else if (support_level == "maybe") + maybe_supported.push(mimetype); - }); + }); - Array.prototype.push.apply(GuacamoleUI.supportedAudio, probably_supported); - Array.prototype.push.apply(GuacamoleUI.supportedAudio, maybe_supported); + Array.prototype.push.apply(GuacamoleUI.supportedAudio, probably_supported); + Array.prototype.push.apply(GuacamoleUI.supportedAudio, maybe_supported); + })(); + + // Query video support + (function () { + var probably_supported = []; + var maybe_supported = []; + + // Build array of supported video formats + [ + 'video/ogg; codecs="theora, vorbis"', + 'video/mp4; codecs="avc1.4D401E, mp4a.40.5"', + 'video/webm; codecs="vp8.0, vorbis"' + ].forEach(function(mimetype) { + + var video = document.createElement("video"); + var support_level = video.canPlayType(mimetype); + + // Trim semicolon and trailer + var semicolon = mimetype.indexOf(";"); + if (semicolon != -1) + mimetype = mimetype.substring(0, semicolon); + + // Partition by probably/maybe + if (support_level == "probably") + probably_supported.push(mimetype); + else if (support_level == "maybe") + maybe_supported.push(mimetype); + + }); + + Array.prototype.push.apply(GuacamoleUI.supportedVideo, probably_supported); + Array.prototype.push.apply(GuacamoleUI.supportedVideo, maybe_supported); + })(); })();