Apply review suggestions

This commit is contained in:
Shadowghost 2023-02-27 16:03:12 +01:00
parent 9880a2b3e1
commit c760a50d59
2 changed files with 17 additions and 17 deletions

View File

@ -2130,7 +2130,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var inputChannels = audioStream.Channels ?? 0;
var outputChannels = outputAudioChannels ?? 0;
var bitrate = audioBitRate.HasValue ? audioBitRate.Value : int.MaxValue;
var bitrate = audioBitRate ?? int.MaxValue;
if (string.IsNullOrEmpty(audioCodec)
|| string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase)
@ -2190,7 +2190,7 @@ namespace MediaBrowser.Controller.MediaEncoding
public string GetAudioVbrModeParam(string encoder, int bitratePerChannel)
{
if (encoder == "libfdk_aac")
if (string.Equals(encoder, "libfdk_aac", StringComparison.OrdinalIgnoreCase))
{
return " -vbr:a " + bitratePerChannel switch
{
@ -2202,7 +2202,7 @@ namespace MediaBrowser.Controller.MediaEncoding
};
}
if (encoder == "libmp3lame")
if (string.Equals(encoder, "libmp3lame", StringComparison.OrdinalIgnoreCase))
{
return " -qscale:a " + bitratePerChannel switch
{
@ -2214,7 +2214,7 @@ namespace MediaBrowser.Controller.MediaEncoding
};
}
if (encoder == "libvorbis")
if (string.Equals(encoder, "libvorbis", StringComparison.OrdinalIgnoreCase))
{
return " -qscale:a " + bitratePerChannel switch
{
@ -5870,8 +5870,8 @@ namespace MediaBrowser.Controller.MediaEncoding
if (bitrate.HasValue)
{
string vbrParam;
if (encodingOptions.EnableAudioVbr && (vbrParam = GetAudioVbrModeParam(codec, bitrate.Value / channels ?? 2)) != null)
var vbrParam = GetAudioVbrModeParam(codec, bitrate.Value / (channels ?? 2));
if (encodingOptions.EnableAudioVbr && vbrParam is not null)
{
args += vbrParam;
}
@ -5900,8 +5900,8 @@ namespace MediaBrowser.Controller.MediaEncoding
if (bitrate.HasValue)
{
string vbrParam;
if (encodingOptions.EnableAudioVbr && (vbrParam = GetAudioVbrModeParam(state.OutputAudioCodec, bitrate.Value / channels ?? 2)) != null)
var vbrParam = GetAudioVbrModeParam(state.OutputAudioCodec, bitrate.Value / (channels ?? 2));
if (encodingOptions.EnableAudioVbr && vbrParam is not null)
{
audioTranscodeParams.Add(vbrParam);
}

View File

@ -25,6 +25,9 @@ namespace MediaBrowser.Model.Dlna
private readonly ILogger _logger;
private readonly ITranscoderSupport _transcoderSupport;
private static readonly string[] _supportedHlsVideoCodecs = new string[] { "h264", "hevc" };
private static readonly string[] _supportedHlsAudioCodecsTs = new string[] { "aac", "ac3", "eac3", "mp3" };
private static readonly string[] _supportedHlsAudioCodecsMp4 = new string[] { "aac", "ac3", "eac3", "mp3", "alac", "flac", "opus" };
/// <summary>
/// Initializes a new instance of the <see cref="StreamBuilder"/> class.
@ -803,8 +806,7 @@ namespace MediaBrowser.Model.Dlna
// Enforce HLS video codec restrictions
if (string.Equals(playlistItem.SubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
{
var supportedHlsVideoCodecs = new List<string> { "h264", "hevc" };
videoCodecs = videoCodecs.Where(codec => supportedHlsVideoCodecs.Contains(codec)).ToArray();
videoCodecs = videoCodecs.Where(codec => _supportedHlsVideoCodecs.Contains(codec)).ToArray();
}
var directVideoCodec = ContainerProfile.ContainsContainer(videoCodecs, videoStream?.Codec) ? videoStream?.Codec : null;
@ -846,16 +848,14 @@ namespace MediaBrowser.Model.Dlna
// Enforce HLS audio codec restrictions
if (string.Equals(playlistItem.SubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
{
var supportedHlsAudioCodecs = new List<string> { "aac", "ac3", "eac3", "mp3" };
if (string.Equals(playlistItem.Container, "mp4", StringComparison.OrdinalIgnoreCase))
{
// fMP4 supports more codecs than TS
supportedHlsAudioCodecs.Add("alac");
supportedHlsAudioCodecs.Add("flac");
supportedHlsAudioCodecs.Add("opus");
audioCodecs = audioCodecs.Where(codec => _supportedHlsAudioCodecsMp4.Contains(codec)).ToArray();
}
else
{
audioCodecs = audioCodecs.Where(codec => _supportedHlsAudioCodecsTs.Contains(codec)).ToArray();
}
audioCodecs = audioCodecs.Where(codec => supportedHlsAudioCodecs.Contains(codec)).ToArray();
}
var directAudioStream = candidateAudioStreams.FirstOrDefault(stream => ContainerProfile.ContainsContainer(audioCodecs, stream.Codec));