2020-07-09 11:22:21 +01:00
|
|
|
import $ from 'jQuery';
|
|
|
|
import loading from 'loading';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import dom from 'dom';
|
|
|
|
import libraryMenu from 'libraryMenu';
|
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function loadPage(page, config, systemInfo) {
|
2020-05-04 12:44:12 +02:00
|
|
|
Array.prototype.forEach.call(page.querySelectorAll('.chkDecodeCodec'), function (c) {
|
2020-07-30 16:07:13 +02:00
|
|
|
c.checked = (config.HardwareDecodingCodecs || []).indexOf(c.getAttribute('data-codec')) !== -1;
|
2019-03-07 21:19:21 +00:00
|
|
|
});
|
2020-05-29 14:06:02 -04:00
|
|
|
page.querySelector('#chkDecodingColorDepth10Hevc').checked = config.EnableDecodingColorDepth10Hevc;
|
|
|
|
page.querySelector('#chkDecodingColorDepth10Vp9').checked = config.EnableDecodingColorDepth10Vp9;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('#chkHardwareEncoding').checked = config.EnableHardwareEncoding;
|
|
|
|
$('#selectVideoDecoder', page).val(config.HardwareAccelerationType);
|
|
|
|
$('#selectThreadCount', page).val(config.EncodingThreadCount);
|
|
|
|
$('#txtDownMixAudioBoost', page).val(config.DownMixAudioBoost);
|
|
|
|
page.querySelector('.txtEncoderPath').value = config.EncoderAppPathDisplay || '';
|
|
|
|
$('#txtTranscodingTempPath', page).val(systemInfo.TranscodingTempPath || '');
|
|
|
|
$('#txtVaapiDevice', page).val(config.VaapiDevice || '');
|
|
|
|
page.querySelector('#selectEncoderPreset').value = config.EncoderPreset || '';
|
|
|
|
page.querySelector('#txtH264Crf').value = config.H264Crf || '';
|
|
|
|
page.querySelector('#selectDeinterlaceMethod').value = config.DeinterlaceMethod || '';
|
|
|
|
page.querySelector('#chkEnableSubtitleExtraction').checked = config.EnableSubtitleExtraction || false;
|
|
|
|
page.querySelector('#chkEnableThrottling').checked = config.EnableThrottling || false;
|
|
|
|
page.querySelector('#selectVideoDecoder').dispatchEvent(new CustomEvent('change', {
|
2019-03-08 09:25:45 +00:00
|
|
|
bubbles: true
|
2019-11-06 13:43:39 +03:00
|
|
|
}));
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSaveEncodingPathFailure(response) {
|
|
|
|
loading.hide();
|
2020-07-11 11:56:57 +01:00
|
|
|
let msg = '';
|
2020-05-04 12:44:12 +02:00
|
|
|
msg = globalize.translate('FFmpegSavePathNotFound');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-09 11:22:21 +01:00
|
|
|
import('alert').then(({default: alert}) => {
|
2019-11-06 13:43:39 +03:00
|
|
|
alert(msg);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateEncoder(form) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return ApiClient.getSystemInfo().then(function (systemInfo) {
|
2018-10-23 01:05:09 +03:00
|
|
|
return ApiClient.ajax({
|
2020-05-04 12:44:12 +02:00
|
|
|
url: ApiClient.getUrl('System/MediaEncoder/Path'),
|
|
|
|
type: 'POST',
|
2018-10-23 01:05:09 +03:00
|
|
|
data: {
|
2020-05-04 12:44:12 +02:00
|
|
|
Path: form.querySelector('.txtEncoderPath').value,
|
|
|
|
PathType: 'Custom'
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(Dashboard.processServerConfigurationUpdateResult, onSaveEncodingPathFailure);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSubmit() {
|
2020-07-11 11:56:57 +01:00
|
|
|
const form = this;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-11 11:56:57 +01:00
|
|
|
const onDecoderConfirmed = function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.show();
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getNamedConfiguration('encoding').then(function (config) {
|
|
|
|
config.DownMixAudioBoost = $('#txtDownMixAudioBoost', form).val();
|
|
|
|
config.TranscodingTempPath = $('#txtTranscodingTempPath', form).val();
|
|
|
|
config.EncodingThreadCount = $('#selectThreadCount', form).val();
|
|
|
|
config.HardwareAccelerationType = $('#selectVideoDecoder', form).val();
|
|
|
|
config.VaapiDevice = $('#txtVaapiDevice', form).val();
|
|
|
|
config.EncoderPreset = form.querySelector('#selectEncoderPreset').value;
|
|
|
|
config.H264Crf = parseInt(form.querySelector('#txtH264Crf').value || '0');
|
|
|
|
config.DeinterlaceMethod = form.querySelector('#selectDeinterlaceMethod').value;
|
|
|
|
config.EnableSubtitleExtraction = form.querySelector('#chkEnableSubtitleExtraction').checked;
|
|
|
|
config.EnableThrottling = form.querySelector('#chkEnableThrottling').checked;
|
|
|
|
config.HardwareDecodingCodecs = Array.prototype.map.call(Array.prototype.filter.call(form.querySelectorAll('.chkDecodeCodec'), function (c) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return c.checked;
|
|
|
|
}), function (c) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return c.getAttribute('data-codec');
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2020-05-29 14:06:02 -04:00
|
|
|
config.EnableDecodingColorDepth10Hevc = form.querySelector('#chkDecodingColorDepth10Hevc').checked;
|
|
|
|
config.EnableDecodingColorDepth10Vp9 = form.querySelector('#chkDecodingColorDepth10Vp9').checked;
|
2020-05-04 12:44:12 +02:00
|
|
|
config.EnableHardwareEncoding = form.querySelector('#chkHardwareEncoding').checked;
|
|
|
|
ApiClient.updateNamedConfiguration('encoding', config).then(function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
updateEncoder(form);
|
2020-02-24 22:25:08 +09:00
|
|
|
}, function () {
|
2020-07-09 11:22:21 +01:00
|
|
|
import('alert').then(({default: alert}) => {
|
2020-08-02 01:23:57 +09:00
|
|
|
alert(globalize.translate('ErrorDefault'));
|
2020-02-24 22:25:08 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
Dashboard.processServerConfigurationUpdateResult();
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
if ($('#selectVideoDecoder', form).val()) {
|
2020-07-09 11:22:21 +01:00
|
|
|
import('alert').then(({default: alert}) => {
|
2019-11-06 13:43:39 +03:00
|
|
|
alert({
|
2020-05-04 12:44:12 +02:00
|
|
|
title: globalize.translate('TitleHardwareAcceleration'),
|
|
|
|
text: globalize.translate('HardwareAccelerationWarning')
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(onDecoderConfirmed);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
onDecoderConfirmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setDecodingCodecsVisible(context, value) {
|
2020-05-04 12:44:12 +02:00
|
|
|
value = value || '';
|
2020-07-11 11:56:57 +01:00
|
|
|
let any;
|
2020-05-04 12:44:12 +02:00
|
|
|
Array.prototype.forEach.call(context.querySelectorAll('.chkDecodeCodec'), function (c) {
|
2020-07-30 16:07:13 +02:00
|
|
|
if (c.getAttribute('data-types').split(',').indexOf(value) === -1) {
|
2020-05-04 12:44:12 +02:00
|
|
|
dom.parentWithTag(c, 'LABEL').classList.add('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
dom.parentWithTag(c, 'LABEL').classList.remove('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (any) {
|
2020-05-04 12:44:12 +02:00
|
|
|
context.querySelector('.decodingCodecsList').classList.remove('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
context.querySelector('.decodingCodecsList').classList.add('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-04-03 00:12:02 +01:00
|
|
|
|
2019-08-16 00:25:31 -07:00
|
|
|
function getTabs() {
|
|
|
|
return [{
|
2020-05-04 12:44:12 +02:00
|
|
|
href: 'encodingsettings.html',
|
|
|
|
name: globalize.translate('Transcoding')
|
2019-08-16 00:25:31 -07:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
href: 'playbackconfiguration.html',
|
|
|
|
name: globalize.translate('TabResumeSettings')
|
2019-08-16 00:25:31 -07:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
href: 'streamingsettings.html',
|
|
|
|
name: globalize.translate('TabStreaming')
|
2019-11-06 13:43:39 +03:00
|
|
|
}];
|
2019-08-16 00:25:31 -07:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$(document).on('pageinit', '#encodingSettingsPage', function () {
|
2020-07-11 11:56:57 +01:00
|
|
|
const page = this;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('#selectVideoDecoder').addEventListener('change', function () {
|
2020-07-30 16:07:13 +02:00
|
|
|
if (this.value == 'vaapi') {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldVaapiDevice').classList.remove('hide');
|
|
|
|
page.querySelector('#txtVaapiDevice').setAttribute('required', 'required');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.fldVaapiDevice').classList.add('hide');
|
|
|
|
page.querySelector('#txtVaapiDevice').removeAttribute('required');
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.value) {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.hardwareAccelerationOptions').classList.remove('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.hardwareAccelerationOptions').classList.add('hide');
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
setDecodingCodecsVisible(page, this.value);
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#btnSelectEncoderPath', page).on('click.selectDirectory', function () {
|
2020-07-09 11:22:21 +01:00
|
|
|
import('directorybrowser').then(({default: directoryBrowser}) => {
|
2020-07-11 11:56:57 +01:00
|
|
|
const picker = new directoryBrowser();
|
2018-10-23 01:05:09 +03:00
|
|
|
picker.show({
|
2019-11-06 13:43:39 +03:00
|
|
|
includeFiles: true,
|
|
|
|
callback: function (path) {
|
|
|
|
if (path) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.txtEncoderPath', page).val(path);
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#btnSelectTranscodingTempPath', page).on('click.selectDirectory', function () {
|
2020-07-09 11:22:21 +01:00
|
|
|
import('directorybrowser').then(({default: directoryBrowser}) => {
|
2020-07-11 11:56:57 +01:00
|
|
|
const picker = new directoryBrowser();
|
2018-10-23 01:05:09 +03:00
|
|
|
picker.show({
|
2019-11-06 13:43:39 +03:00
|
|
|
callback: function (path) {
|
|
|
|
if (path) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#txtTranscodingTempPath', page).val(path);
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
},
|
2019-11-06 13:43:39 +03:00
|
|
|
validateWriteable: true,
|
2020-05-04 12:44:12 +02:00
|
|
|
header: globalize.translate('HeaderSelectTranscodingPath'),
|
|
|
|
instruction: globalize.translate('HeaderSelectTranscodingPathHelp')
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.encodingSettingsForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
}).on('pageshow', '#encodingSettingsPage', function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
loading.show();
|
2020-05-04 12:44:12 +02:00
|
|
|
libraryMenu.setTabs('playback', 0, getTabs);
|
2020-07-11 11:56:57 +01:00
|
|
|
const page = this;
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getNamedConfiguration('encoding').then(function (config) {
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.getSystemInfo().then(function (systemInfo) {
|
2019-03-08 09:15:12 +00:00
|
|
|
loadPage(page, config, systemInfo);
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-07-09 11:22:21 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|