Skip to content

Commit

Permalink
update blocked codecs to run by type
Browse files Browse the repository at this point in the history
  • Loading branch information
fgl27 committed Aug 6, 2024
1 parent 6ddf57a commit 7df7955
Showing 1 changed file with 107 additions and 33 deletions.
140 changes: 107 additions & 33 deletions app/specific/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,52 +475,126 @@ function Main_CheckDevice() {
}
}

//Disable googles OMX.google.h264.decoder and c2.android.avc.decoder if another codec is available
if (!Main_values.Codec_is_Check_new) {
var codecs = null;
try {
if (Main_IsOn_OSInterface) {
codecs = JSON.parse(OSInterface_getcodecCapabilities('avc'));
codecs.push.apply(codecs, JSON.parse(OSInterface_getcodecCapabilities('hevc')));
codecs.push.apply(codecs, JSON.parse(OSInterface_getcodecCapabilities('av01')));
}
} catch (e) {}
Main_SetBlockedFirstRun();
}
} else {
if (Main_values.Never_run_new) Settings_ForceEnableAnimations();

//Main_TestSetBlockedFirstRun();
}
}

if (codecs) {
Main_values.Codec_is_Check_new = true;
// function Main_TestSetBlockedFirstRun() {
// var codecs = Main_SetBlockedGetCodecs();
// console.log('Main_SetBlockedGetCodecs', codecs);

if (codecs.length > 1) {
var codecsNames = [];
// console.log(Main_SetBlockedGetToBlock(codecs));
// console.log(
// //only one av1 google
// Main_SetBlockedGetToBlock(
// JSON.parse(
// '[{"instances":32,"maxbitrate":"120 Mbps","maxlevel":"5.2","maxresolution":"3840x2176","name":"OMX.Nvidia.h264.decode","resolutions":"160p : 960 fps | 360p : 960 fps | 480p : 960 fps | 720p : 555 fps | 1080p : 245 fps | 1440p : 138 fps | 2160p : 61 fps","type":"video/avc"},{"instances":32,"maxbitrate":"48 Mbps","maxlevel":"5.2","maxresolution":"4080x4080","name":"OMX.google.h264.decoder","resolutions":"160p : 960 fps | 360p : 960 fps | 480p : 960 fps | 720p : 546 fps | 1080p : 240 fps | 1440p : 136 fps | 2160p : 60 fps","type":"video/avc"},{"instances":-1,"maxbitrate":"48 Mbps","maxlevel":"5.2","maxresolution":"4080x4080","name":"OMX.chico.h264.decoder","resolutions":"160p : 960 fps | 360p : 960 fps | 480p : 960 fps | 720p : 546 fps | 1080p : 240 fps | 1440p : 136 fps | 2160p : 60 fps","type":"video/avc"},{"instances":32,"maxbitrate":"120 Mbps","maxlevel":"High 5.2","maxresolution":"4096x4096","name":"c2.goldfish.hevc.decoder","resolutions":"160p : 480 fps | 360p : 480 fps | 480p : 480 fps | 720p : 480 fps | 900p : 364 fps | 1080p : 254 fps | 1440p : 144 fps | 2160p : 64 fps","type":"video/hevc"},{"instances":32,"maxbitrate":"10 Mbps","maxlevel":"High 5.2","maxresolution":"4096x4096","name":"c2.android.hevc.decoder","resolutions":"160p : 960 fps | 360p : 741 fps | 480p : 417 fps | 720p : 139 fps | 900p : 88 fps | 1080p : 62 fps | 1440p : 35 fps | 2160p : 15 fps","type":"video/hevc"},{"instances":32,"maxbitrate":"10 Mbps","maxlevel":"High 5.2","maxresolution":"4096x4096","name":"OMX.google.hevc.decoder","resolutions":"160p : 960 fps | 360p : 741 fps | 480p : 417 fps | 720p : 139 fps | 900p : 88 fps | 1080p : 62 fps | 1440p : 35 fps | 2160p : 15 fps","type":"video/hevc"},{"instances":32,"maxbitrate":"40 Mbps","maxlevel":"32768","maxresolution":"2048x2048","name":"c2.android.av1.decoder","resolutions":"160p : 960 fps | 360p : 356 fps | 480p : 205 fps | 720p : 68 fps | 900p : 43 fps | 1080p : 30 fps","type":"video/av01"},{"instances":32,"maxbitrate":"40 Mbps","maxlevel":"32768","maxresolution":"2048x2048","name":"c2.google.av1.decoder","resolutions":"160p : 960 fps | 360p : 356 fps | 480p : 205 fps | 720p : 68 fps | 900p : 43 fps | 1080p : 30 fps","type":"video/av01"}]'
// )
// )
// );
// }

var i = 0,
len = codecs.length;
function Main_SetBlockedFirstRun() {
//Disable googles OMX.google.h264.decoder and c2.android.avc.decoder if another codec is available

for (i; i < len; i++) {
var codec = codecs[i].name ? codecs[i].name.toLowerCase() : '';
var codecs = Main_SetBlockedGetCodecs();

if (Main_A_includes_B(codec, 'google') || Main_A_includes_B(codec, 'c2.android')) {
codecsNames.push(codecs[i].name);
}
}
if (codecs && codecs.length > 1) {
var codecsToBlock = Main_SetBlockedGetToBlock(codecs);
//only save if we received codecs
Main_values.Codec_is_Check_new = true;

if (codecsNames.length && codecsNames.length < codecs.length) {
i = 0;
len = codecsNames.length;
if (codecsToBlock.length) {
var i = 0,
len = codecsToBlock.length;

for (i; i < len; i++) {
Main_setItem(codecsNames[i], 1);
}
for (i; i < len; i++) {
Main_setItem(codecsToBlock[i], 1);
}

Main_setItem('Settings_DisableCodecsNames', JSON.stringify(codecsNames));
Main_setItem('Settings_DisableCodecsNames', JSON.stringify(codecsToBlock));

OSInterface_setBlackListMediaCodec(codecsNames.join());
}
}
OSInterface_setBlackListMediaCodec(codecsToBlock.join());
}
}
}

function Main_SetBlockedGetCodecs() {
var codecs = null;
try {
if (Main_IsOn_OSInterface) {
codecs = JSON.parse(OSInterface_getcodecCapabilities('avc'));
codecs.push.apply(codecs, JSON.parse(OSInterface_getcodecCapabilities('hevc')));
codecs.push.apply(codecs, JSON.parse(OSInterface_getcodecCapabilities('av01')));
} else {
codecs = JSON.parse(
'[{"instances":32,"maxbitrate":"120 Mbps","maxlevel":"5.2","maxresolution":"3840x2176","name":"OMX.Nvidia.h264.decode","resolutions":"160p : 960 fps | 360p : 960 fps | 480p : 960 fps | 720p : 555 fps | 1080p : 245 fps | 1440p : 138 fps | 2160p : 61 fps","type":"video/avc"},{"instances":32,"maxbitrate":"48 Mbps","maxlevel":"5.2","maxresolution":"4080x4080","name":"OMX.google.h264.decoder","resolutions":"160p : 960 fps | 360p : 960 fps | 480p : 960 fps | 720p : 546 fps | 1080p : 240 fps | 1440p : 136 fps | 2160p : 60 fps","type":"video/avc"},{"instances":-1,"maxbitrate":"48 Mbps","maxlevel":"5.2","maxresolution":"4080x4080","name":"OMX.chico.h264.decoder","resolutions":"160p : 960 fps | 360p : 960 fps | 480p : 960 fps | 720p : 546 fps | 1080p : 240 fps | 1440p : 136 fps | 2160p : 60 fps","type":"video/avc"},{"instances":32,"maxbitrate":"120 Mbps","maxlevel":"High 5.2","maxresolution":"4096x4096","name":"c2.goldfish.hevc.decoder","resolutions":"160p : 480 fps | 360p : 480 fps | 480p : 480 fps | 720p : 480 fps | 900p : 364 fps | 1080p : 254 fps | 1440p : 144 fps | 2160p : 64 fps","type":"video/hevc"},{"instances":32,"maxbitrate":"10 Mbps","maxlevel":"High 5.2","maxresolution":"4096x4096","name":"c2.android.hevc.decoder","resolutions":"160p : 960 fps | 360p : 741 fps | 480p : 417 fps | 720p : 139 fps | 900p : 88 fps | 1080p : 62 fps | 1440p : 35 fps | 2160p : 15 fps","type":"video/hevc"},{"instances":32,"maxbitrate":"10 Mbps","maxlevel":"High 5.2","maxresolution":"4096x4096","name":"OMX.google.hevc.decoder","resolutions":"160p : 960 fps | 360p : 741 fps | 480p : 417 fps | 720p : 139 fps | 900p : 88 fps | 1080p : 62 fps | 1440p : 35 fps | 2160p : 15 fps","type":"video/hevc"},{"instances":32,"maxbitrate":"40 Mbps","maxlevel":"32768","maxresolution":"2048x2048","name":"c2.android.av1.decoder","resolutions":"160p : 960 fps | 360p : 356 fps | 480p : 205 fps | 720p : 68 fps | 900p : 43 fps | 1080p : 30 fps","type":"video/av01"},{"instances":32,"maxbitrate":"40 Mbps","maxlevel":"32768","maxresolution":"2048x2048","name":"c2.google.av1.decoder","resolutions":"160p : 960 fps | 360p : 356 fps | 480p : 205 fps | 720p : 68 fps | 900p : 43 fps | 1080p : 30 fps","type":"video/av01"},{"instances":32,"maxbitrate":"40 Mbps","maxlevel":"32768","maxresolution":"2048x2048","name":"c2.test.av1.decoder","resolutions":"160p : 960 fps | 360p : 356 fps | 480p : 205 fps | 720p : 68 fps | 900p : 43 fps | 1080p : 30 fps","type":"video/av01"},{"instances":32,"maxbitrate":"40 Mbps","maxlevel":"32768","maxresolution":"2048x2048","name":"c.test2.av1.decoder","resolutions":"160p : 960 fps | 360p : 356 fps | 480p : 205 fps | 720p : 68 fps | 900p : 43 fps | 1080p : 30 fps","type":"video/av01"}]'
);
}
} catch (e) {}

return codecs;
}

function Main_SetBlockedGetToBlock(codecs) {
//creates a map of to block codecs and normal
var codecsMap = {
ToBlock: {},
Normal: {
av1: [],
avc: [],
hevc: []
}
},
codecsToBlock = [],
codec;

var i = 0,
len = codecs.length,
type;

for (i; i < len; i++) {
codec = codecs[i].name ? codecs[i].name.toLowerCase() : '';

type = codecs[i].type;
codecs[i].type = Main_CodecGetType(type);

if (Main_A_includes_B(codec, 'google') || Main_A_includes_B(codec, 'c2.android')) {
codecsMap.ToBlock[codecs[i].name] = codecs[i];
} else if (codecsMap.Normal[codecs[i].type]) {
codecsMap.Normal[codecs[i].type].push(codecs[i]);
}
} else if (Main_values.Never_run_new) {
Settings_ForceEnableAnimations();
}

var ToBlockKeys = Object.keys(codecsMap.ToBlock);

i = 0;
len = ToBlockKeys.length;

//only block if normals codecs are available for the type
for (i; i < len; i++) {
codec = codecsMap.ToBlock[ToBlockKeys[i]];

if (codecsMap.Normal[codec.type].length) {
codecsToBlock.push(codec.name);
}
}

return codecsToBlock;
}

function Main_CodecGetType(type) {
if (Main_A_includes_B(type, 'avc')) return 'avc';
else if (Main_A_includes_B(type, 'hevc')) return 'hevc';
else if (Main_A_includes_B(type, 'av01')) return 'av1';

return null;
}

function Main_SetStringsMain() {
Expand Down

0 comments on commit 7df7955

Please sign in to comment.