encodingInfo-webrtc.any.js (8422B)
1 // META: timeout=long 2 'use strict'; 3 4 const isWorkerEnvironment = typeof self.WorkerGlobalScope !== 'undefined'; 5 6 // Minimal VideoConfiguration that will be allowed per spec. All optional 7 // properties are missing. 8 const minimalVideoConfiguration = { 9 contentType: 'video/VP9; profile-level="0"', 10 width: 800, 11 height: 600, 12 bitrate: 3000, 13 framerate: 24, 14 }; 15 16 // Minimal AudioConfiguration that will be allowed per spec. All optional 17 // properties are missing. 18 const minimalAudioConfiguration = { 19 contentType: 'audio/opus', 20 }; 21 22 promise_test(t => { 23 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 24 type: 'webrtc', 25 })); 26 }, "Test that encodingInfo rejects if the configuration doesn't have an audio or video field"); 27 28 promise_test(t => { 29 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 30 type: 'webrtc', 31 video: { 32 contentType: 'video/VP9', 33 width: 800, 34 height: 600, 35 bitrate: 3000, 36 framerate: -1, 37 }, 38 })); 39 }, "Test that encodingInfo rejects if the video configuration has a negative framerate"); 40 41 promise_test(t => { 42 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 43 type: 'webrtc', 44 video: { 45 contentType: 'video/VP9"', 46 width: 800, 47 height: 600, 48 bitrate: 3000, 49 framerate: 0, 50 }, 51 })); 52 }, "Test that encodingInfo rejects if the video configuration has a framerate set to 0"); 53 54 promise_test(t => { 55 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 56 type: 'webrtc', 57 video: { 58 contentType: 'video/VP9"', 59 width: 800, 60 height: 600, 61 bitrate: 3000, 62 framerate: Infinity, 63 }, 64 })); 65 }, "Test that encodingInfo rejects if the video configuration has a framerate set to Infinity"); 66 67 promise_test(t => { 68 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 69 type: 'webrtc', 70 video: { 71 contentType: 'fgeoa', 72 width: 800, 73 height: 600, 74 bitrate: 3000, 75 framerate: 24, 76 }, 77 })); 78 }, "Test that encodingInfo rejects if the video configuration contentType doesn't parse"); 79 80 promise_test(t => { 81 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 82 type: 'webrtc', 83 video: { 84 contentType: 'audio/fgeoa', 85 width: 800, 86 height: 600, 87 bitrate: 3000, 88 framerate: 24, 89 }, 90 })); 91 }, "Test that encodingInfo rejects if the video configuration contentType isn't of type video"); 92 93 promise_test(t => { 94 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 95 type: 'webrtc', 96 audio: { contentType: 'fgeoa' }, 97 })); 98 }, "Test that encodingInfo rejects if the audio configuration contentType doesn't parse"); 99 100 promise_test(t => { 101 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 102 type: 'webrtc', 103 video: { 104 contentType: 'video/webm; codecs="vp09.00.10.08"; foo="bar"', 105 width: 800, 106 height: 600, 107 bitrate: 3000, 108 framerate: 24, 109 }, 110 })); 111 }, "Test that encodingInfo rejects if the video configuration contentType has more than one parameter"); 112 113 promise_test(t => { 114 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 115 type: 'webrtc', 116 video: { 117 contentType: 'video/webm; foo="bar"', 118 width: 800, 119 height: 600, 120 bitrate: 3000, 121 framerate: 24, 122 }, 123 })); 124 }, "Test that encodingInfo rejects if the video configuration contentType has one parameter that isn't codecs"); 125 126 promise_test(t => { 127 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 128 type: 'webrtc', 129 audio: { contentType: 'video/fgeoa' }, 130 })); 131 }, "Test that encodingInfo rejects if the audio configuration contentType isn't of type audio"); 132 133 promise_test(t => { 134 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 135 type: 'webrtc', 136 audio: { contentType: 'audio/webm; codecs="opus"; foo="bar"' }, 137 })); 138 }, "Test that encodingInfo rejects if the audio configuration contentType has more than one parameters"); 139 140 promise_test(t => { 141 return promise_rejects_js(t, TypeError, navigator.mediaCapabilities.encodingInfo({ 142 type: 'webrtc', 143 audio: { contentType: 'audio/webm; foo="bar"' }, 144 })); 145 }, "Test that encodingInfo rejects if the audio configuration contentType has one parameter that isn't codecs"); 146 147 promise_test(t => { 148 return navigator.mediaCapabilities.encodingInfo({ 149 type: 'webrtc', 150 video: minimalVideoConfiguration, 151 audio: minimalAudioConfiguration, 152 }).then(ability => { 153 assert_equals(typeof ability.supported, "boolean"); 154 assert_equals(typeof ability.smooth, "boolean"); 155 assert_equals(typeof ability.powerEfficient, "boolean"); 156 }); 157 }, "Test that encodingInfo returns a valid MediaCapabilitiesInfo objects"); 158 159 promise_test(t => { 160 return navigator.mediaCapabilities.encodingInfo({ 161 type: 'webrtc', 162 video: { 163 contentType: 'video/webm; codecs="vp09.00.10.08"', 164 width: 800, 165 height: 600, 166 bitrate: 3000, 167 framerate: 24, 168 }, 169 audio: minimalAudioConfiguration, 170 }).then(ability => { 171 assert_false(ability.supported); 172 assert_false(ability.smooth); 173 assert_false(ability.powerEfficient); 174 }); 175 }, "Test that encodingInfo returns supported, smooth, and powerEfficient set to false for non-webrtc video content type."); 176 177 promise_test(t => { 178 return navigator.mediaCapabilities.encodingInfo({ 179 type: 'webrtc', 180 video: minimalVideoConfiguration, 181 audio: { 182 contentType: 'audio/webm; codecs="opus"', 183 }, 184 }).then(ability => { 185 assert_false(ability.supported); 186 assert_false(ability.smooth); 187 assert_false(ability.powerEfficient); 188 }); 189 }, "Test that encodingInfo returns supported, smooth, and powerEfficient set to false for non-webrtc audio content type."); 190 191 const validAudioCodecs = (() => { 192 // Some codecs that are returned by getCapabilities() are not real codecs, 193 // exclude these from the test. 194 const excludeList = [ 'audio/CN', 'audio/telephone-event', 'audio/red' ]; 195 const audioCodecs = []; 196 197 if (isWorkerEnvironment) { 198 // Test with one specific codec since RTCRtpSender is not exposed to workers. 199 audioCodecs.push(minimalAudioConfiguration.contentType); 200 } 201 else { 202 RTCRtpSender.getCapabilities("audio")['codecs'].forEach(codec => { 203 if (excludeList.indexOf(codec.mimeType) < 0 && 204 audioCodecs.indexOf(codec.mimeType) < 0) { 205 audioCodecs.push(codec.mimeType); 206 } 207 }); 208 } 209 return audioCodecs; 210 })(); 211 212 validAudioCodecs.forEach(codec => { 213 promise_test(t => { 214 return navigator.mediaCapabilities.encodingInfo({ 215 type: 'webrtc', 216 audio: { 217 contentType: codec 218 } 219 }).then(ability => { 220 assert_true(ability.supported); 221 }); 222 }, "Test that encodingInfo returns supported true for the codec " + codec + (isWorkerEnvironment ? "" : " returned by RTCRtpSender.getCapabilities()"))} 223 ); 224 225 const validVideoCodecs = (() => { 226 // Some codecs that are returned by getCapabilities() are not real codecs but 227 // only used for error correction, exclude these from the test. 228 const excludeList = [ 'video/rtx', 'video/red', 'video/ulpfec', 229 'video/flexfec-03' ]; 230 const videoCodecs = []; 231 232 if (isWorkerEnvironment) { 233 // Test with one specific codec since RTCRtpSender is not exposed to workers. 234 videoCodecs.push(minimalVideoConfiguration.contentType); 235 } 236 else { 237 RTCRtpSender.getCapabilities("video")['codecs'].forEach(codec => { 238 if (excludeList.indexOf(codec.mimeType) < 0) { 239 let mimeType = codec.mimeType; 240 if ('sdpFmtpLine' in codec) { 241 mimeType += "; " + codec.sdpFmtpLine; 242 } 243 if (!(mimeType in videoCodecs)) { 244 videoCodecs.push(mimeType); 245 } 246 } 247 }); 248 } 249 return videoCodecs; 250 })(); 251 252 validVideoCodecs.forEach(codec => { 253 promise_test(t => { 254 return navigator.mediaCapabilities.encodingInfo({ 255 type: 'webrtc', 256 video: { 257 contentType: codec, 258 width: 800, 259 height: 600, 260 bitrate: 3000, 261 framerate: 24, 262 } 263 }).then(ability => { 264 assert_true(ability.supported); 265 }); 266 }, "Test that encodingInfo returns supported true for the codec " + codec + (isWorkerEnvironment ? "" : " returned by RTCRtpSender.getCapabilities()"))} 267 );