< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Entities.MediaStream
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Entities/MediaStream.cs
Line coverage
74%
Covered lines: 171
Uncovered lines: 59
Coverable lines: 230
Total lines: 846
Line coverage: 74.3%
Branch coverage
66%
Covered branches: 199
Total branches: 300
Branch coverage: 66.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_VideoRange()100%11100%
get_VideoRangeType()100%11100%
get_VideoDoViTitle()8%852554.16%
get_AudioSpatialFormat()87.5%88100%
get_DisplayTitle()57.31%4688261.42%
get_ReferenceFrameRate()100%22100%
get_IsTextSubtitleStream()100%66100%
get_IsPgsSubtitleStream()100%66100%
get_IsExtractableSubtitleStream()100%22100%
GetResolutionText()93.24%747496.66%
IsTextFormat(...)50%1212100%
IsPgsFormat(...)50%44100%
SupportsSubtitleConversionTo(...)50%171058.33%
GetVideoColorRange()56.52%4016958.82%

File(s)

/srv/git/jellyfin/MediaBrowser.Model/Entities/MediaStream.cs

#LineLine coverage
 1#nullable disable
 2#pragma warning disable CS1591
 3
 4using System;
 5using System.Collections.Frozen;
 6using System.Collections.Generic;
 7using System.ComponentModel;
 8using System.Globalization;
 9using System.Linq;
 10using System.Text;
 11using System.Text.Json.Serialization;
 12using Jellyfin.Data.Enums;
 13using Jellyfin.Extensions;
 14using MediaBrowser.Model.Dlna;
 15using MediaBrowser.Model.Extensions;
 16using MediaBrowser.Model.MediaInfo;
 17
 18namespace MediaBrowser.Model.Entities
 19{
 20    /// <summary>
 21    /// Class MediaStream.
 22    /// </summary>
 23    public class MediaStream
 24    {
 125        private static readonly string[] _specialCodes =
 126        {
 127            // Uncoded languages.
 128            "mis",
 129            // Multiple languages.
 130            "mul",
 131            // Undetermined.
 132            "und",
 133            // No linguistic content; not applicable.
 134            "zxx"
 135        };
 36
 37        /// <summary>
 38        /// Gets or sets the codec.
 39        /// </summary>
 40        /// <value>The codec.</value>
 41        public string Codec { get; set; }
 42
 43        /// <summary>
 44        /// Gets or sets the codec tag.
 45        /// </summary>
 46        /// <value>The codec tag.</value>
 47        public string CodecTag { get; set; }
 48
 49        /// <summary>
 50        /// Gets or sets the language.
 51        /// </summary>
 52        /// <value>The language.</value>
 53        public string Language { get; set; }
 54
 55        /// <summary>
 56        /// Gets or sets the color range.
 57        /// </summary>
 58        /// <value>The color range.</value>
 59        public string ColorRange { get; set; }
 60
 61        /// <summary>
 62        /// Gets or sets the color space.
 63        /// </summary>
 64        /// <value>The color space.</value>
 65        public string ColorSpace { get; set; }
 66
 67        /// <summary>
 68        /// Gets or sets the color transfer.
 69        /// </summary>
 70        /// <value>The color transfer.</value>
 71        public string ColorTransfer { get; set; }
 72
 73        /// <summary>
 74        /// Gets or sets the color primaries.
 75        /// </summary>
 76        /// <value>The color primaries.</value>
 77        public string ColorPrimaries { get; set; }
 78
 79        /// <summary>
 80        /// Gets or sets the Dolby Vision version major.
 81        /// </summary>
 82        /// <value>The Dolby Vision version major.</value>
 83        public int? DvVersionMajor { get; set; }
 84
 85        /// <summary>
 86        /// Gets or sets the Dolby Vision version minor.
 87        /// </summary>
 88        /// <value>The Dolby Vision version minor.</value>
 89        public int? DvVersionMinor { get; set; }
 90
 91        /// <summary>
 92        /// Gets or sets the Dolby Vision profile.
 93        /// </summary>
 94        /// <value>The Dolby Vision profile.</value>
 95        public int? DvProfile { get; set; }
 96
 97        /// <summary>
 98        /// Gets or sets the Dolby Vision level.
 99        /// </summary>
 100        /// <value>The Dolby Vision level.</value>
 101        public int? DvLevel { get; set; }
 102
 103        /// <summary>
 104        /// Gets or sets the Dolby Vision rpu present flag.
 105        /// </summary>
 106        /// <value>The Dolby Vision rpu present flag.</value>
 107        public int? RpuPresentFlag { get; set; }
 108
 109        /// <summary>
 110        /// Gets or sets the Dolby Vision el present flag.
 111        /// </summary>
 112        /// <value>The Dolby Vision el present flag.</value>
 113        public int? ElPresentFlag { get; set; }
 114
 115        /// <summary>
 116        /// Gets or sets the Dolby Vision bl present flag.
 117        /// </summary>
 118        /// <value>The Dolby Vision bl present flag.</value>
 119        public int? BlPresentFlag { get; set; }
 120
 121        /// <summary>
 122        /// Gets or sets the Dolby Vision bl signal compatibility id.
 123        /// </summary>
 124        /// <value>The Dolby Vision bl signal compatibility id.</value>
 125        public int? DvBlSignalCompatibilityId { get; set; }
 126
 127        /// <summary>
 128        /// Gets or sets the Rotation in degrees.
 129        /// </summary>
 130        /// <value>The video rotation.</value>
 131        public int? Rotation { get; set; }
 132
 133        /// <summary>
 134        /// Gets or sets the comment.
 135        /// </summary>
 136        /// <value>The comment.</value>
 137        public string Comment { get; set; }
 138
 139        /// <summary>
 140        /// Gets or sets the time base.
 141        /// </summary>
 142        /// <value>The time base.</value>
 143        public string TimeBase { get; set; }
 144
 145        /// <summary>
 146        /// Gets or sets the codec time base.
 147        /// </summary>
 148        /// <value>The codec time base.</value>
 149        public string CodecTimeBase { get; set; }
 150
 151        /// <summary>
 152        /// Gets or sets the title.
 153        /// </summary>
 154        /// <value>The title.</value>
 155        public string Title { get; set; }
 156
 157        public bool? Hdr10PlusPresentFlag { get; set; }
 158
 159        /// <summary>
 160        /// Gets the video range.
 161        /// </summary>
 162        /// <value>The video range.</value>
 163        [DefaultValue(VideoRange.Unknown)]
 164        public VideoRange VideoRange
 165        {
 166            get
 167            {
 32168                var (videoRange, _) = GetVideoColorRange();
 169
 32170                return videoRange;
 171            }
 172        }
 173
 174        /// <summary>
 175        /// Gets the video range type.
 176        /// </summary>
 177        /// <value>The video range type.</value>
 178        [DefaultValue(VideoRangeType.Unknown)]
 179        public VideoRangeType VideoRangeType
 180        {
 181            get
 182            {
 906183                var (_, videoRangeType) = GetVideoColorRange();
 184
 906185                return videoRangeType;
 186            }
 187        }
 188
 189        /// <summary>
 190        /// Gets the video dovi title.
 191        /// </summary>
 192        /// <value>The video dovi title.</value>
 193        public string VideoDoViTitle
 194        {
 195            get
 196            {
 32197                var dvProfile = DvProfile;
 32198                var rpuPresentFlag = RpuPresentFlag == 1;
 32199                var blPresentFlag = BlPresentFlag == 1;
 32200                var dvBlCompatId = DvBlSignalCompatibilityId;
 201
 32202                if (rpuPresentFlag
 32203                    && blPresentFlag
 32204                    && (dvProfile == 4
 32205                        || dvProfile == 5
 32206                        || dvProfile == 7
 32207                        || dvProfile == 8
 32208                        || dvProfile == 9
 32209                        || dvProfile == 10))
 210                {
 0211                    var title = "Dolby Vision Profile " + dvProfile;
 212
 0213                    if (dvBlCompatId > 0)
 214                    {
 0215                        title += "." + dvBlCompatId;
 216                    }
 217
 0218                    return dvBlCompatId switch
 0219                    {
 0220                        1 => title + " (HDR10)",
 0221                        2 => title + " (SDR)",
 0222                        4 => title + " (HLG)",
 0223                        6 => title + " (HDR10)", // Technically means Blu-ray, but practically always HDR10
 0224                        _ => title
 0225                    };
 226                }
 227
 32228                return null;
 229            }
 230        }
 231
 232        /// <summary>
 233        /// Gets the audio spatial format.
 234        /// </summary>
 235        /// <value>The audio spatial format.</value>
 236        [DefaultValue(AudioSpatialFormat.None)]
 237        public AudioSpatialFormat AudioSpatialFormat
 238        {
 239            get
 240            {
 34241                if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile))
 242                {
 32243                    return AudioSpatialFormat.None;
 244                }
 245
 2246                return
 2247                    Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos 
 2248                    Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX :
 2249                    AudioSpatialFormat.None;
 250            }
 251        }
 252
 253        public string LocalizedUndefined { get; set; }
 254
 255        public string LocalizedDefault { get; set; }
 256
 257        public string LocalizedForced { get; set; }
 258
 259        public string LocalizedExternal { get; set; }
 260
 261        public string LocalizedHearingImpaired { get; set; }
 262
 263        public string DisplayTitle
 264        {
 265            get
 266            {
 40267                switch (Type)
 268                {
 269                    case MediaStreamType.Audio:
 270                    {
 14271                        var attributes = new List<string>();
 272
 273                        // Do not display the language code in display titles if unset or set to a special code. Show it
 14274                        if (!string.IsNullOrEmpty(Language) && !_specialCodes.Contains(Language, StringComparison.Ordina
 275                        {
 276                            // Get full language string i.e. eng -> English.
 3277                            string fullLanguage = CultureInfo
 3278                                .GetCultures(CultureTypes.NeutralCultures)
 3279                                .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.Ordi
 3280                                ?.DisplayName;
 3281                            attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
 282                        }
 283
 14284                        if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno
 285                        {
 0286                            attributes.Add(Profile);
 287                        }
 14288                        else if (!string.IsNullOrEmpty(Codec))
 289                        {
 2290                            attributes.Add(AudioCodec.GetFriendlyName(Codec));
 291                        }
 292
 14293                        if (!string.IsNullOrEmpty(ChannelLayout))
 294                        {
 0295                            attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
 296                        }
 14297                        else if (Channels.HasValue)
 298                        {
 0299                            attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
 300                        }
 301
 14302                        if (IsDefault)
 303                        {
 4304                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 305                        }
 306
 14307                        if (IsExternal)
 308                        {
 8309                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 310                        }
 311
 14312                        if (!string.IsNullOrEmpty(Title))
 313                        {
 2314                            var result = new StringBuilder(Title);
 16315                            foreach (var tag in attributes)
 316                            {
 317                                // Keep Tags that are not already in Title.
 6318                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 319                                {
 6320                                    result.Append(" - ").Append(tag);
 321                                }
 322                            }
 323
 2324                            return result.ToString();
 325                        }
 326
 12327                        return string.Join(" - ", attributes);
 328                    }
 329
 330                    case MediaStreamType.Video:
 331                    {
 0332                        var attributes = new List<string>();
 333
 0334                        var resolutionText = GetResolutionText();
 335
 0336                        if (!string.IsNullOrEmpty(resolutionText))
 337                        {
 0338                            attributes.Add(resolutionText);
 339                        }
 340
 0341                        if (!string.IsNullOrEmpty(Codec))
 342                        {
 0343                            attributes.Add(Codec.ToUpperInvariant());
 344                        }
 345
 0346                        if (VideoDoViTitle is not null)
 347                        {
 0348                            attributes.Add(VideoDoViTitle);
 349                        }
 0350                        else if (VideoRange != VideoRange.Unknown)
 351                        {
 0352                            attributes.Add(VideoRange.ToString());
 353                        }
 354
 0355                        if (!string.IsNullOrEmpty(Title))
 356                        {
 0357                            var result = new StringBuilder(Title);
 0358                            foreach (var tag in attributes)
 359                            {
 360                                // Keep Tags that are not already in Title.
 0361                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 362                                {
 0363                                    result.Append(" - ").Append(tag);
 364                                }
 365                            }
 366
 0367                            return result.ToString();
 368                        }
 369
 0370                        return string.Join(' ', attributes);
 371                    }
 372
 373                    case MediaStreamType.Subtitle:
 374                    {
 26375                        var attributes = new List<string>();
 376
 26377                        if (!string.IsNullOrEmpty(Language))
 378                        {
 379                            // Get full language string i.e. eng -> English.
 16380                            string fullLanguage = CultureInfo
 16381                                .GetCultures(CultureTypes.NeutralCultures)
 16382                                .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.Ordi
 16383                                ?.DisplayName;
 16384                            attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
 385                        }
 386                        else
 387                        {
 10388                            attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
 389                        }
 390
 26391                        if (IsHearingImpaired == true)
 392                        {
 6393                            attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz
 394                        }
 395
 26396                        if (IsDefault)
 397                        {
 11398                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 399                        }
 400
 26401                        if (IsForced)
 402                        {
 12403                            attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
 404                        }
 405
 26406                        if (!string.IsNullOrEmpty(Codec))
 407                        {
 8408                            attributes.Add(Codec.ToUpperInvariant());
 409                        }
 410
 26411                        if (IsExternal)
 412                        {
 2413                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 414                        }
 415
 26416                        if (!string.IsNullOrEmpty(Title))
 417                        {
 20418                            var result = new StringBuilder(Title);
 154419                            foreach (var tag in attributes)
 420                            {
 421                                // Keep Tags that are not already in Title.
 57422                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 423                                {
 53424                                    result.Append(" - ").Append(tag);
 425                                }
 426                            }
 427
 20428                            return result.ToString();
 429                        }
 430
 6431                        return string.Join(" - ", attributes);
 432                    }
 433
 434                    default:
 0435                        return null;
 436                }
 437            }
 438        }
 439
 440        public string NalLengthSize { get; set; }
 441
 442        /// <summary>
 443        /// Gets or sets a value indicating whether this instance is interlaced.
 444        /// </summary>
 445        /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
 446        public bool IsInterlaced { get; set; }
 447
 448        public bool? IsAVC { get; set; }
 449
 450        /// <summary>
 451        /// Gets or sets the channel layout.
 452        /// </summary>
 453        /// <value>The channel layout.</value>
 454        public string ChannelLayout { get; set; }
 455
 456        /// <summary>
 457        /// Gets or sets the bit rate.
 458        /// </summary>
 459        /// <value>The bit rate.</value>
 460        public int? BitRate { get; set; }
 461
 462        /// <summary>
 463        /// Gets or sets the bit depth.
 464        /// </summary>
 465        /// <value>The bit depth.</value>
 466        public int? BitDepth { get; set; }
 467
 468        /// <summary>
 469        /// Gets or sets the reference frames.
 470        /// </summary>
 471        /// <value>The reference frames.</value>
 472        public int? RefFrames { get; set; }
 473
 474        /// <summary>
 475        /// Gets or sets the length of the packet.
 476        /// </summary>
 477        /// <value>The length of the packet.</value>
 478        public int? PacketLength { get; set; }
 479
 480        /// <summary>
 481        /// Gets or sets the channels.
 482        /// </summary>
 483        /// <value>The channels.</value>
 484        public int? Channels { get; set; }
 485
 486        /// <summary>
 487        /// Gets or sets the sample rate.
 488        /// </summary>
 489        /// <value>The sample rate.</value>
 490        public int? SampleRate { get; set; }
 491
 492        /// <summary>
 493        /// Gets or sets a value indicating whether this instance is default.
 494        /// </summary>
 495        /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
 496        public bool IsDefault { get; set; }
 497
 498        /// <summary>
 499        /// Gets or sets a value indicating whether this instance is forced.
 500        /// </summary>
 501        /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
 502        public bool IsForced { get; set; }
 503
 504        /// <summary>
 505        /// Gets or sets a value indicating whether this instance is for the hearing impaired.
 506        /// </summary>
 507        /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value>
 508        public bool IsHearingImpaired { get; set; }
 509
 510        /// <summary>
 511        /// Gets or sets the height.
 512        /// </summary>
 513        /// <value>The height.</value>
 514        public int? Height { get; set; }
 515
 516        /// <summary>
 517        /// Gets or sets the width.
 518        /// </summary>
 519        /// <value>The width.</value>
 520        public int? Width { get; set; }
 521
 522        /// <summary>
 523        /// Gets or sets the average frame rate.
 524        /// </summary>
 525        /// <value>The average frame rate.</value>
 526        public float? AverageFrameRate { get; set; }
 527
 528        /// <summary>
 529        /// Gets or sets the real frame rate.
 530        /// </summary>
 531        /// <value>The real frame rate.</value>
 532        public float? RealFrameRate { get; set; }
 533
 534        /// <summary>
 535        /// Gets the framerate used as reference.
 536        /// Prefer AverageFrameRate, if that is null or an unrealistic value
 537        /// then fallback to RealFrameRate.
 538        /// </summary>
 539        /// <value>The reference frame rate.</value>
 540        public float? ReferenceFrameRate
 541        {
 542            get
 543            {
 544                // In some cases AverageFrameRate for videos will be read as 1000fps even if it is not.
 545                // This is probably due to a library compatibility issue.
 546                // See https://github.com/jellyfin/jellyfin/pull/12603#discussion_r1748044018 for more info.
 1051547                return AverageFrameRate < 1000 ? AverageFrameRate : RealFrameRate;
 548            }
 549        }
 550
 551        /// <summary>
 552        /// Gets or sets the profile.
 553        /// </summary>
 554        /// <value>The profile.</value>
 555        public string Profile { get; set; }
 556
 557        /// <summary>
 558        /// Gets or sets the type.
 559        /// </summary>
 560        /// <value>The type.</value>
 561        public MediaStreamType Type { get; set; }
 562
 563        /// <summary>
 564        /// Gets or sets the aspect ratio.
 565        /// </summary>
 566        /// <value>The aspect ratio.</value>
 567        public string AspectRatio { get; set; }
 568
 569        /// <summary>
 570        /// Gets or sets the index.
 571        /// </summary>
 572        /// <value>The index.</value>
 573        public int Index { get; set; }
 574
 575        /// <summary>
 576        /// Gets or sets the score.
 577        /// </summary>
 578        /// <value>The score.</value>
 579        public int? Score { get; set; }
 580
 581        /// <summary>
 582        /// Gets or sets a value indicating whether this instance is external.
 583        /// </summary>
 584        /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
 585        public bool IsExternal { get; set; }
 586
 587        /// <summary>
 588        /// Gets or sets the method.
 589        /// </summary>
 590        /// <value>The method.</value>
 591        public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
 592
 593        /// <summary>
 594        /// Gets or sets the delivery URL.
 595        /// </summary>
 596        /// <value>The delivery URL.</value>
 597        public string DeliveryUrl { get; set; }
 598
 599        /// <summary>
 600        /// Gets or sets a value indicating whether this instance is external URL.
 601        /// </summary>
 602        /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>f
 603        public bool? IsExternalUrl { get; set; }
 604
 605        public bool IsTextSubtitleStream
 606        {
 607            get
 608            {
 2041609                if (Type != MediaStreamType.Subtitle)
 610                {
 49611                    return false;
 612                }
 613
 1992614                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 615                {
 30616                    return false;
 617                }
 618
 1962619                return IsTextFormat(Codec);
 620            }
 621        }
 622
 623        [JsonIgnore]
 624        public bool IsPgsSubtitleStream
 625        {
 626            get
 627            {
 60628                if (Type != MediaStreamType.Subtitle)
 629                {
 26630                    return false;
 631                }
 632
 34633                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 634                {
 30635                    return false;
 636                }
 637
 4638                return IsPgsFormat(Codec);
 639            }
 640        }
 641
 642        /// <summary>
 643        /// Gets a value indicating whether this is a subtitle steam that is extractable by ffmpeg.
 644        /// All text-based and pgs subtitles can be extracted.
 645        /// </summary>
 646        /// <value><c>true</c> if this is a extractable subtitle steam otherwise, <c>false</c>.</value>
 647        [JsonIgnore]
 32648        public bool IsExtractableSubtitleStream => IsTextSubtitleStream || IsPgsSubtitleStream;
 649
 650        /// <summary>
 651        /// Gets or sets a value indicating whether [supports external stream].
 652        /// </summary>
 653        /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
 654        public bool SupportsExternalStream { get; set; }
 655
 656        /// <summary>
 657        /// Gets or sets the filename.
 658        /// </summary>
 659        /// <value>The filename.</value>
 660        public string Path { get; set; }
 661
 662        /// <summary>
 663        /// Gets or sets the pixel format.
 664        /// </summary>
 665        /// <value>The pixel format.</value>
 666        public string PixelFormat { get; set; }
 667
 668        /// <summary>
 669        /// Gets or sets the level.
 670        /// </summary>
 671        /// <value>The level.</value>
 672        public double? Level { get; set; }
 673
 674        /// <summary>
 675        /// Gets or sets whether this instance is anamorphic.
 676        /// </summary>
 677        /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
 678        public bool? IsAnamorphic { get; set; }
 679
 680        internal string GetResolutionText()
 681        {
 73682            if (!Width.HasValue || !Height.HasValue)
 683            {
 3684                return null;
 685            }
 686
 70687            return Width switch
 70688            {
 70689                // 256x144 (16:9 square pixel format)
 4690                <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
 70691                // 426x240 (16:9 square pixel format)
 4692                <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
 70693                // 640x360 (16:9 square pixel format)
 14694                <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
 70695                // 682x384 (16:9 square pixel format)
 3696                <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
 70697                // 720x404 (16:9 square pixel format)
 7698                <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
 70699                // 854x480 (16:9 square pixel format)
 10700                <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
 70701                // 960x544 (16:9 square pixel format)
 11702                <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
 70703                // 1024x576 (16:9 square pixel format)
 9704                <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
 70705                // 1280x720
 26706                <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
 70707                // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
 46708                <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
 70709                // 4K
 12710                <= 4096 when Height <= 3072 => "4K",
 70711                // 8K
 6712                <= 8192 when Height <= 6144 => "8K",
 0713                _ => null
 70714            };
 715        }
 716
 717        public static bool IsTextFormat(string format)
 718        {
 3344719            string codec = format ?? string.Empty;
 720
 721            // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based.
 722
 3344723            return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase)
 3344724                   || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 3344725                       && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase)
 3344726                       && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
 3344727                       && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
 3344728                       && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase));
 729        }
 730
 731        public static bool IsPgsFormat(string format)
 732        {
 8733            string codec = format ?? string.Empty;
 734
 8735            return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 8736                   || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase);
 737        }
 738
 739        public bool SupportsSubtitleConversionTo(string toCodec)
 740        {
 286741            if (!IsTextSubtitleStream)
 742            {
 0743                return false;
 744            }
 745
 286746            var fromCodec = Codec;
 747
 748            // Can't convert from this
 286749            if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
 750            {
 0751                return false;
 752            }
 753
 286754            if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 755            {
 0756                return false;
 757            }
 758
 759            // Can't convert to this
 286760            if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
 761            {
 0762                return false;
 763            }
 764
 286765            if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 766            {
 0767                return false;
 768            }
 769
 286770            return true;
 771        }
 772
 773        public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
 774        {
 938775            if (Type != MediaStreamType.Video)
 776            {
 64777                return (VideoRange.Unknown, VideoRangeType.Unknown);
 778            }
 779
 874780            var codecTag = CodecTag;
 874781            var dvProfile = DvProfile;
 874782            var rpuPresentFlag = RpuPresentFlag == 1;
 874783            var blPresentFlag = BlPresentFlag == 1;
 874784            var dvBlCompatId = DvBlSignalCompatibilityId;
 785
 874786            var isDoViProfile = dvProfile is 5 or 7 or 8 or 10;
 874787            var isDoViFlag = rpuPresentFlag && blPresentFlag && dvBlCompatId is 0 or 1 or 4 or 2 or 6;
 788
 874789            if ((isDoViProfile && isDoViFlag)
 874790                || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
 874791                || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
 874792                || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
 874793                || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
 794            {
 115795                var dvRangeSet = dvProfile switch
 115796                {
 64797                    5 => (VideoRange.HDR, VideoRangeType.DOVI),
 51798                    8 => dvBlCompatId switch
 51799                    {
 51800                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0801                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0802                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 51803                        // Out of Dolby Spec files should be marked as invalid
 0804                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 51805                    },
 0806                    7 => (VideoRange.HDR, VideoRangeType.DOVIWithEL),
 0807                    10 => dvBlCompatId switch
 0808                    {
 0809                        0 => (VideoRange.HDR, VideoRangeType.DOVI),
 0810                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0811                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 0812                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0813                        // Out of Dolby Spec files should be marked as invalid
 0814                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 0815                    },
 0816                    _ => (VideoRange.SDR, VideoRangeType.SDR)
 115817                };
 818
 115819                if (Hdr10PlusPresentFlag == true)
 820                {
 0821                    return dvRangeSet.Item2 switch
 0822                    {
 0823                        VideoRangeType.DOVIWithHDR10 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10Plus),
 0824                        VideoRangeType.DOVIWithEL => (VideoRange.HDR, VideoRangeType.DOVIWithELHDR10Plus),
 0825                        _ => dvRangeSet
 0826                    };
 827                }
 828
 115829                return dvRangeSet;
 830            }
 831
 759832            var colorTransfer = ColorTransfer;
 833
 759834            if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
 835            {
 198836                return Hdr10PlusPresentFlag == true ? (VideoRange.HDR, VideoRangeType.HDR10Plus) : (VideoRange.HDR, Vide
 837            }
 561838            else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
 839            {
 0840                return (VideoRange.HDR, VideoRangeType.HLG);
 841            }
 842
 561843            return (VideoRange.SDR, VideoRangeType.SDR);
 844        }
 845    }
 846}