2019-11-06 13:43:39 +03:00
|
|
|
define(["jQuery", "loading", "globalize", "dom", "libraryMenu"], function ($, loading, globalize, dom, libraryMenu) {
|
2018-10-23 01:05:09 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function loadPage(page, config, systemInfo) {
|
2019-11-06 13:43:39 +03:00
|
|
|
Array.prototype.forEach.call(page.querySelectorAll(".chkDecodeCodec"), function (c) {
|
|
|
|
c.checked = -1 !== (config.HardwareDecodingCodecs || []).indexOf(c.getAttribute("data-codec"));
|
2019-03-07 21:19:21 +00: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 || "";
|
2019-09-05 11:43:32 -07:00
|
|
|
$("#txtTranscodingTempPath", page).val(systemInfo.TranscodingTempPath || "");
|
2019-03-07 21:19:21 +00:00
|
|
|
$("#txtVaapiDevice", page).val(config.VaapiDevice || "");
|
2020-02-05 17:10:25 +08:00
|
|
|
page.querySelector("#selectEncoderPreset").value = config.EncoderPreset || "";
|
2019-03-07 21:19:21 +00:00
|
|
|
page.querySelector("#txtH264Crf").value = config.H264Crf || "";
|
|
|
|
page.querySelector("#chkEnableSubtitleExtraction").checked = config.EnableSubtitleExtraction || 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();
|
|
|
|
var msg = "";
|
2019-11-06 13:43:39 +03:00
|
|
|
msg = globalize.translate("FFmpegSavePathNotFound");
|
|
|
|
|
|
|
|
require(["alert"], function (alert) {
|
|
|
|
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({
|
|
|
|
url: ApiClient.getUrl("System/MediaEncoder/Path"),
|
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
Path: form.querySelector(".txtEncoderPath").value,
|
|
|
|
PathType: "Custom"
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(Dashboard.processServerConfigurationUpdateResult, onSaveEncodingPathFailure);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSubmit() {
|
2019-11-06 13:43:39 +03:00
|
|
|
var form = this;
|
|
|
|
|
|
|
|
var onDecoderConfirmed = function () {
|
|
|
|
loading.show();
|
|
|
|
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();
|
2020-02-05 17:10:25 +08:00
|
|
|
config.EncoderPreset = form.querySelector("#selectEncoderPreset").value;
|
2019-11-06 13:43:39 +03:00
|
|
|
config.H264Crf = parseInt(form.querySelector("#txtH264Crf").value || "0");
|
|
|
|
config.EnableSubtitleExtraction = form.querySelector("#chkEnableSubtitleExtraction").checked;
|
|
|
|
config.HardwareDecodingCodecs = Array.prototype.map.call(Array.prototype.filter.call(form.querySelectorAll(".chkDecodeCodec"), function (c) {
|
|
|
|
return c.checked;
|
|
|
|
}), function (c) {
|
|
|
|
return c.getAttribute("data-codec");
|
|
|
|
});
|
|
|
|
config.EnableHardwareEncoding = form.querySelector("#chkHardwareEncoding").checked;
|
|
|
|
ApiClient.updateNamedConfiguration("encoding", config).then(function () {
|
|
|
|
updateEncoder(form);
|
2020-02-24 22:25:08 +09:00
|
|
|
}, function () {
|
|
|
|
require(["alert"], function (alert) {
|
|
|
|
alert(globalize.translate("DefaultErrorMessage"));
|
|
|
|
});
|
|
|
|
|
|
|
|
Dashboard.processServerConfigurationUpdateResult();
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($("#selectVideoDecoder", form).val()) {
|
|
|
|
require(["alert"], function (alert) {
|
|
|
|
alert({
|
|
|
|
title: globalize.translate("TitleHardwareAcceleration"),
|
|
|
|
text: globalize.translate("HardwareAccelerationWarning")
|
|
|
|
}).then(onDecoderConfirmed);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
onDecoderConfirmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setDecodingCodecsVisible(context, value) {
|
|
|
|
value = value || "";
|
|
|
|
var any;
|
2019-11-06 13:43:39 +03:00
|
|
|
Array.prototype.forEach.call(context.querySelectorAll(".chkDecodeCodec"), function (c) {
|
|
|
|
if (-1 === c.getAttribute("data-types").split(",").indexOf(value)) {
|
|
|
|
dom.parentWithTag(c, "LABEL").classList.add("hide");
|
|
|
|
} else {
|
|
|
|
dom.parentWithTag(c, "LABEL").classList.remove("hide");
|
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (any) {
|
|
|
|
context.querySelector(".decodingCodecsList").classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
context.querySelector(".decodingCodecsList").classList.add("hide");
|
|
|
|
}
|
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 [{
|
|
|
|
href: "encodingsettings.html",
|
|
|
|
name: Globalize.translate("Transcoding")
|
|
|
|
}, {
|
|
|
|
href: "playbackconfiguration.html",
|
|
|
|
name: Globalize.translate("TabResumeSettings")
|
|
|
|
}, {
|
|
|
|
href: "streamingsettings.html",
|
|
|
|
name: Globalize.translate("TabStreaming")
|
2019-11-06 13:43:39 +03:00
|
|
|
}];
|
2019-08-16 00:25:31 -07:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:43:39 +03:00
|
|
|
$(document).on("pageinit", "#encodingSettingsPage", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2019-11-06 13:43:39 +03:00
|
|
|
page.querySelector("#selectVideoDecoder").addEventListener("change", function () {
|
|
|
|
if ("vaapi" == this.value) {
|
|
|
|
page.querySelector(".fldVaapiDevice").classList.remove("hide");
|
|
|
|
page.querySelector("#txtVaapiDevice").setAttribute("required", "required");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".fldVaapiDevice").classList.add("hide");
|
|
|
|
page.querySelector("#txtVaapiDevice").removeAttribute("required");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.value) {
|
|
|
|
page.querySelector(".hardwareAccelerationOptions").classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
page.querySelector(".hardwareAccelerationOptions").classList.add("hide");
|
|
|
|
}
|
|
|
|
|
|
|
|
setDecodingCodecsVisible(page, this.value);
|
|
|
|
});
|
|
|
|
$("#btnSelectEncoderPath", page).on("click.selectDirectory", function () {
|
|
|
|
require(["directorybrowser"], function (directoryBrowser) {
|
|
|
|
var 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) {
|
|
|
|
$(".txtEncoderPath", page).val(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$("#btnSelectTranscodingTempPath", page).on("click.selectDirectory", function () {
|
|
|
|
require(["directorybrowser"], function (directoryBrowser) {
|
|
|
|
var 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) {
|
|
|
|
$("#txtTranscodingTempPath", page).val(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
},
|
2019-11-06 13:43:39 +03:00
|
|
|
validateWriteable: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
header: globalize.translate("HeaderSelectTranscodingPath"),
|
|
|
|
instruction: globalize.translate("HeaderSelectTranscodingPathHelp")
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(".encodingSettingsForm").off("submit", onSubmit).on("submit", onSubmit);
|
|
|
|
}).on("pageshow", "#encodingSettingsPage", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
loading.show();
|
2019-08-16 00:25:31 -07:00
|
|
|
libraryMenu.setTabs("playback", 0, getTabs);
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.getNamedConfiguration("encoding").then(function (config) {
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-02-08 13:16:30 +00:00
|
|
|
});
|