Advertisement
Guest User

MediaCapabilities codecTransitionsSupported Example

a guest
Jun 18th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // SITE OBJECTIVE
  2. // This site has a variety of codecs. It will prefer hw-secure CDM, but it's main
  3. // priority is being able to transition between codecs. Not sure if this is realistic,
  4. // but it helps exercise all the code.
  5.  
  6.  
  7. function allTransitionSupported(info_list) {
  8.   return info_list.every((info) => info.codec_transitions_supported);
  9. }
  10.  
  11. (async _ => {
  12.  
  13.   // First try to setup hw-secure with transitions
  14.  
  15.   let hw_secure_configs = [ VP9_OPUS_HW_SECURE, H264_AAC_HW_SECURE ];
  16.   let hw_secure_infos = await Promise.all(hw_secure_configs.map(config => decodingInfo(config)));
  17.   let hw_secure_supported = allSupported(hw_secure_infos);
  18.   if (hw_secure_supported && allTransitionsSupported(hw_secure_infos)) {
  19.     setupPlayback(hw_secure_infos);
  20.     return;
  21.   }
  22.  
  23.   // HW-secure either wasn't supported, or couldn't transition. Let's see about sw-secure.
  24.  
  25.   let sw_secure_configs = [ VP9_OPUS_SW_SECURE, H264_AAC_SW_SECURE ];
  26.   let sw_secure_infos = await Promise.all(sw_secure_configs.map(config => decodingInfo(config)));
  27.   let sw_secure_supported = allSupported(sw_secure_infos);
  28.   if (sw_secure_supported && allTransitionsSupported(sw_secure_infos)) {
  29.       setupPlayback(sw_secure_infos);
  30.       return;
  31.     }
  32.   }
  33.  
  34.   // Didn't get transitions with either. Fall back to h264+aac using the highest security available
  35.  
  36.   if (hw_secure_supported) {
  37.     setupPlayback(hw_secure_infos.slice(1));
  38.   } else if (sw_secure_supported) {
  39.     setupPlayback(sw_secure_infos.slice(1));
  40.   } else {
  41.     alert('no supported configurations');
  42.   }
  43.  
  44. })(); // End async wrapper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement