mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-31 12:14:21 -04:00
Add tests for ProbeResultNormalizer.GetFrameRate
This commit is contained in:
parent
923720c988
commit
f8fcbc88fc
@ -1027,27 +1027,32 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
/// <returns>System.Nullable{System.Single}.</returns>
|
/// <returns>System.Nullable{System.Single}.</returns>
|
||||||
private float? GetFrameRate(string value)
|
internal static float? GetFrameRate(ReadOnlySpan<char> value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value))
|
if (value.IsEmpty)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parts = value.Split('/');
|
int index = value.IndexOf('/');
|
||||||
|
if (index == -1)
|
||||||
float result;
|
|
||||||
|
|
||||||
if (parts.Length == 2)
|
|
||||||
{
|
{
|
||||||
result = float.Parse(parts[0], CultureInfo.InvariantCulture) / float.Parse(parts[1], CultureInfo.InvariantCulture);
|
// REVIEW: is this branch actually required? (i.e. does ffprobe ever output something other than a fraction?)
|
||||||
}
|
if (float.TryParse(value, NumberStyles.AllowThousands | NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
|
||||||
else
|
{
|
||||||
{
|
return result;
|
||||||
result = float.Parse(parts[0], CultureInfo.InvariantCulture);
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return float.IsNaN(result) ? null : result;
|
if (!float.TryParse(value[..index], NumberStyles.Integer, CultureInfo.InvariantCulture, out var dividend)
|
||||||
|
|| !float.TryParse(value[(index + 1)..], NumberStyles.Integer, CultureInfo.InvariantCulture, out var divisor))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return divisor == 0f ? 0f : dividend / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetAudioRuntimeTicks(InternalMediaInfoResult result, MediaInfo data)
|
private void SetAudioRuntimeTicks(InternalMediaInfoResult result, MediaInfo data)
|
||||||
|
@ -18,6 +18,19 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
|
|||||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
||||||
private readonly ProbeResultNormalizer _probeResultNormalizer = new ProbeResultNormalizer(new NullLogger<EncoderValidatorTests>(), null);
|
private readonly ProbeResultNormalizer _probeResultNormalizer = new ProbeResultNormalizer(new NullLogger<EncoderValidatorTests>(), null);
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("2997/125", 23.976f)]
|
||||||
|
[InlineData("1/50", 0.02f)]
|
||||||
|
[InlineData("25/1", 25f)]
|
||||||
|
[InlineData("120/1", 120f)]
|
||||||
|
[InlineData("1704753000/71073479", 23.98578237601117f)]
|
||||||
|
[InlineData("0/0", 0f)]
|
||||||
|
[InlineData("1/1000", 0.001f)]
|
||||||
|
[InlineData("1/90000", 1.1111111E-05f)]
|
||||||
|
[InlineData("1/48000", 2.0833333E-05f)]
|
||||||
|
public void GetFrameRate_Success(string value, float? expected)
|
||||||
|
=> Assert.Equal(expected, ProbeResultNormalizer.GetFrameRate(value));
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetMediaInfo_MetaData_Success()
|
public void GetMediaInfo_MetaData_Success()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user