diff options
| author | Bond_009 <bond.009@outlook.com> | 2021-12-12 02:22:30 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2021-12-18 14:56:10 +0100 |
| commit | f8fcbc88fca8086052d1b3ef37dbd71d85e7dee7 (patch) | |
| tree | dbd523ac44d6178bcedae80e7efbd79a3c566174 /MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | |
| parent | 923720c988ce62ce5c57337252cf981ceeef9a23 (diff) | |
Add tests for ProbeResultNormalizer.GetFrameRate
Diffstat (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 770881149..ed0c8a2e1 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -1027,27 +1027,32 @@ namespace MediaBrowser.MediaEncoding.Probing /// </summary> /// <param name="value">The value.</param> /// <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; } - var parts = value.Split('/'); - - float result; - - if (parts.Length == 2) + int index = value.IndexOf('/'); + if (index == -1) { - 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)) + { + return result; + } + + return null; } - else + + if (!float.TryParse(value[..index], NumberStyles.Integer, CultureInfo.InvariantCulture, out var dividend) + || !float.TryParse(value[(index + 1)..], NumberStyles.Integer, CultureInfo.InvariantCulture, out var divisor)) { - result = float.Parse(parts[0], CultureInfo.InvariantCulture); + return null; } - return float.IsNaN(result) ? null : result; + return divisor == 0f ? 0f : dividend / divisor; } private void SetAudioRuntimeTicks(InternalMediaInfoResult result, MediaInfo data) |
