< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Entities.MediaStream
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Entities/MediaStream.cs
Line coverage
71%
Covered lines: 175
Uncovered lines: 71
Coverable lines: 246
Total lines: 880
Line coverage: 71.1%
Branch coverage
65%
Covered branches: 203
Total branches: 308
Branch coverage: 65.9%
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()54.44%9689052.32%
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, zh-Hans -> Chinese (Simplified).
 3277                            var cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
 3278                            CultureInfo match = null;
 3279                            if (Language.Contains('-', StringComparison.OrdinalIgnoreCase))
 280                            {
 0281                                match = cultures.FirstOrDefault(r =>
 0282                                    r.Name.Equals(Language, StringComparison.OrdinalIgnoreCase));
 283
 0284                                if (match is null)
 285                                {
 0286                                    string baseLang = Language.AsSpan().LeftPart('-').ToString();
 0287                                    match = cultures.FirstOrDefault(r =>
 0288                                        r.TwoLetterISOLanguageName.Equals(baseLang, StringComparison.OrdinalIgnoreCase))
 289                                }
 290                            }
 291                            else
 292                            {
 3293                                match = cultures.FirstOrDefault(r =>
 3294                                    r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.OrdinalIgnoreCase));
 295                            }
 296
 3297                            string fullLanguage = match?.DisplayName;
 3298                            attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
 299                        }
 300
 14301                        if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgno
 302                        {
 0303                            attributes.Add(Profile);
 304                        }
 14305                        else if (!string.IsNullOrEmpty(Codec))
 306                        {
 2307                            attributes.Add(AudioCodec.GetFriendlyName(Codec));
 308                        }
 309
 14310                        if (!string.IsNullOrEmpty(ChannelLayout))
 311                        {
 0312                            attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
 313                        }
 14314                        else if (Channels.HasValue)
 315                        {
 0316                            attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
 317                        }
 318
 14319                        if (IsDefault)
 320                        {
 4321                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 322                        }
 323
 14324                        if (IsExternal)
 325                        {
 8326                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 327                        }
 328
 14329                        if (!string.IsNullOrEmpty(Title))
 330                        {
 2331                            var result = new StringBuilder(Title);
 16332                            foreach (var tag in attributes)
 333                            {
 334                                // Keep Tags that are not already in Title.
 6335                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 336                                {
 6337                                    result.Append(" - ").Append(tag);
 338                                }
 339                            }
 340
 2341                            return result.ToString();
 342                        }
 343
 12344                        return string.Join(" - ", attributes);
 345                    }
 346
 347                    case MediaStreamType.Video:
 348                    {
 0349                        var attributes = new List<string>();
 350
 0351                        var resolutionText = GetResolutionText();
 352
 0353                        if (!string.IsNullOrEmpty(resolutionText))
 354                        {
 0355                            attributes.Add(resolutionText);
 356                        }
 357
 0358                        if (!string.IsNullOrEmpty(Codec))
 359                        {
 0360                            attributes.Add(Codec.ToUpperInvariant());
 361                        }
 362
 0363                        if (VideoDoViTitle is not null)
 364                        {
 0365                            attributes.Add(VideoDoViTitle);
 366                        }
 0367                        else if (VideoRange != VideoRange.Unknown)
 368                        {
 0369                            attributes.Add(VideoRange.ToString());
 370                        }
 371
 0372                        if (!string.IsNullOrEmpty(Title))
 373                        {
 0374                            var result = new StringBuilder(Title);
 0375                            foreach (var tag in attributes)
 376                            {
 377                                // Keep Tags that are not already in Title.
 0378                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 379                                {
 0380                                    result.Append(" - ").Append(tag);
 381                                }
 382                            }
 383
 0384                            return result.ToString();
 385                        }
 386
 0387                        return string.Join(' ', attributes);
 388                    }
 389
 390                    case MediaStreamType.Subtitle:
 391                    {
 26392                        var attributes = new List<string>();
 393
 26394                        if (!string.IsNullOrEmpty(Language))
 395                        {
 396                            // Get full language string i.e. eng -> English, zh-Hans -> Chinese (Simplified).
 16397                            var cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
 16398                            CultureInfo match = null;
 16399                            if (Language.Contains('-', StringComparison.OrdinalIgnoreCase))
 400                            {
 0401                                match = cultures.FirstOrDefault(r =>
 0402                                    r.Name.Equals(Language, StringComparison.OrdinalIgnoreCase));
 403
 0404                                if (match is null)
 405                                {
 0406                                    string baseLang = Language.AsSpan().LeftPart('-').ToString();
 0407                                    match = cultures.FirstOrDefault(r =>
 0408                                        r.TwoLetterISOLanguageName.Equals(baseLang, StringComparison.OrdinalIgnoreCase))
 409                                }
 410                            }
 411                            else
 412                            {
 16413                                match = cultures.FirstOrDefault(r =>
 16414                                    r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.OrdinalIgnoreCase));
 415                            }
 416
 16417                            string fullLanguage = match?.DisplayName;
 16418                            attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
 419                        }
 420                        else
 421                        {
 10422                            attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
 423                        }
 424
 26425                        if (IsHearingImpaired == true)
 426                        {
 6427                            attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : Localiz
 428                        }
 429
 26430                        if (IsDefault)
 431                        {
 11432                            attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
 433                        }
 434
 26435                        if (IsForced)
 436                        {
 12437                            attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
 438                        }
 439
 26440                        if (!string.IsNullOrEmpty(Codec))
 441                        {
 8442                            attributes.Add(Codec.ToUpperInvariant());
 443                        }
 444
 26445                        if (IsExternal)
 446                        {
 2447                            attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
 448                        }
 449
 26450                        if (!string.IsNullOrEmpty(Title))
 451                        {
 20452                            var result = new StringBuilder(Title);
 154453                            foreach (var tag in attributes)
 454                            {
 455                                // Keep Tags that are not already in Title.
 57456                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
 457                                {
 53458                                    result.Append(" - ").Append(tag);
 459                                }
 460                            }
 461
 20462                            return result.ToString();
 463                        }
 464
 6465                        return string.Join(" - ", attributes);
 466                    }
 467
 468                    default:
 0469                        return null;
 470                }
 471            }
 472        }
 473
 474        public string NalLengthSize { get; set; }
 475
 476        /// <summary>
 477        /// Gets or sets a value indicating whether this instance is interlaced.
 478        /// </summary>
 479        /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
 480        public bool IsInterlaced { get; set; }
 481
 482        public bool? IsAVC { get; set; }
 483
 484        /// <summary>
 485        /// Gets or sets the channel layout.
 486        /// </summary>
 487        /// <value>The channel layout.</value>
 488        public string ChannelLayout { get; set; }
 489
 490        /// <summary>
 491        /// Gets or sets the bit rate.
 492        /// </summary>
 493        /// <value>The bit rate.</value>
 494        public int? BitRate { get; set; }
 495
 496        /// <summary>
 497        /// Gets or sets the bit depth.
 498        /// </summary>
 499        /// <value>The bit depth.</value>
 500        public int? BitDepth { get; set; }
 501
 502        /// <summary>
 503        /// Gets or sets the reference frames.
 504        /// </summary>
 505        /// <value>The reference frames.</value>
 506        public int? RefFrames { get; set; }
 507
 508        /// <summary>
 509        /// Gets or sets the length of the packet.
 510        /// </summary>
 511        /// <value>The length of the packet.</value>
 512        public int? PacketLength { get; set; }
 513
 514        /// <summary>
 515        /// Gets or sets the channels.
 516        /// </summary>
 517        /// <value>The channels.</value>
 518        public int? Channels { get; set; }
 519
 520        /// <summary>
 521        /// Gets or sets the sample rate.
 522        /// </summary>
 523        /// <value>The sample rate.</value>
 524        public int? SampleRate { get; set; }
 525
 526        /// <summary>
 527        /// Gets or sets a value indicating whether this instance is default.
 528        /// </summary>
 529        /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
 530        public bool IsDefault { get; set; }
 531
 532        /// <summary>
 533        /// Gets or sets a value indicating whether this instance is forced.
 534        /// </summary>
 535        /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
 536        public bool IsForced { get; set; }
 537
 538        /// <summary>
 539        /// Gets or sets a value indicating whether this instance is for the hearing impaired.
 540        /// </summary>
 541        /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value>
 542        public bool IsHearingImpaired { get; set; }
 543
 544        /// <summary>
 545        /// Gets or sets the height.
 546        /// </summary>
 547        /// <value>The height.</value>
 548        public int? Height { get; set; }
 549
 550        /// <summary>
 551        /// Gets or sets the width.
 552        /// </summary>
 553        /// <value>The width.</value>
 554        public int? Width { get; set; }
 555
 556        /// <summary>
 557        /// Gets or sets the average frame rate.
 558        /// </summary>
 559        /// <value>The average frame rate.</value>
 560        public float? AverageFrameRate { get; set; }
 561
 562        /// <summary>
 563        /// Gets or sets the real frame rate.
 564        /// </summary>
 565        /// <value>The real frame rate.</value>
 566        public float? RealFrameRate { get; set; }
 567
 568        /// <summary>
 569        /// Gets the framerate used as reference.
 570        /// Prefer AverageFrameRate, if that is null or an unrealistic value
 571        /// then fallback to RealFrameRate.
 572        /// </summary>
 573        /// <value>The reference frame rate.</value>
 574        public float? ReferenceFrameRate
 575        {
 576            get
 577            {
 578                // In some cases AverageFrameRate for videos will be read as 1000fps even if it is not.
 579                // This is probably due to a library compatibility issue.
 580                // See https://github.com/jellyfin/jellyfin/pull/12603#discussion_r1748044018 for more info.
 1051581                return AverageFrameRate < 1000 ? AverageFrameRate : RealFrameRate;
 582            }
 583        }
 584
 585        /// <summary>
 586        /// Gets or sets the profile.
 587        /// </summary>
 588        /// <value>The profile.</value>
 589        public string Profile { get; set; }
 590
 591        /// <summary>
 592        /// Gets or sets the type.
 593        /// </summary>
 594        /// <value>The type.</value>
 595        public MediaStreamType Type { get; set; }
 596
 597        /// <summary>
 598        /// Gets or sets the aspect ratio.
 599        /// </summary>
 600        /// <value>The aspect ratio.</value>
 601        public string AspectRatio { get; set; }
 602
 603        /// <summary>
 604        /// Gets or sets the index.
 605        /// </summary>
 606        /// <value>The index.</value>
 607        public int Index { get; set; }
 608
 609        /// <summary>
 610        /// Gets or sets the score.
 611        /// </summary>
 612        /// <value>The score.</value>
 613        public int? Score { get; set; }
 614
 615        /// <summary>
 616        /// Gets or sets a value indicating whether this instance is external.
 617        /// </summary>
 618        /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
 619        public bool IsExternal { get; set; }
 620
 621        /// <summary>
 622        /// Gets or sets the method.
 623        /// </summary>
 624        /// <value>The method.</value>
 625        public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
 626
 627        /// <summary>
 628        /// Gets or sets the delivery URL.
 629        /// </summary>
 630        /// <value>The delivery URL.</value>
 631        public string DeliveryUrl { get; set; }
 632
 633        /// <summary>
 634        /// Gets or sets a value indicating whether this instance is external URL.
 635        /// </summary>
 636        /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>f
 637        public bool? IsExternalUrl { get; set; }
 638
 639        public bool IsTextSubtitleStream
 640        {
 641            get
 642            {
 2041643                if (Type != MediaStreamType.Subtitle)
 644                {
 49645                    return false;
 646                }
 647
 1992648                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 649                {
 30650                    return false;
 651                }
 652
 1962653                return IsTextFormat(Codec);
 654            }
 655        }
 656
 657        [JsonIgnore]
 658        public bool IsPgsSubtitleStream
 659        {
 660            get
 661            {
 60662                if (Type != MediaStreamType.Subtitle)
 663                {
 26664                    return false;
 665                }
 666
 34667                if (string.IsNullOrEmpty(Codec) && !IsExternal)
 668                {
 30669                    return false;
 670                }
 671
 4672                return IsPgsFormat(Codec);
 673            }
 674        }
 675
 676        /// <summary>
 677        /// Gets a value indicating whether this is a subtitle steam that is extractable by ffmpeg.
 678        /// All text-based and pgs subtitles can be extracted.
 679        /// </summary>
 680        /// <value><c>true</c> if this is a extractable subtitle steam otherwise, <c>false</c>.</value>
 681        [JsonIgnore]
 32682        public bool IsExtractableSubtitleStream => IsTextSubtitleStream || IsPgsSubtitleStream;
 683
 684        /// <summary>
 685        /// Gets or sets a value indicating whether [supports external stream].
 686        /// </summary>
 687        /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
 688        public bool SupportsExternalStream { get; set; }
 689
 690        /// <summary>
 691        /// Gets or sets the filename.
 692        /// </summary>
 693        /// <value>The filename.</value>
 694        public string Path { get; set; }
 695
 696        /// <summary>
 697        /// Gets or sets the pixel format.
 698        /// </summary>
 699        /// <value>The pixel format.</value>
 700        public string PixelFormat { get; set; }
 701
 702        /// <summary>
 703        /// Gets or sets the level.
 704        /// </summary>
 705        /// <value>The level.</value>
 706        public double? Level { get; set; }
 707
 708        /// <summary>
 709        /// Gets or sets whether this instance is anamorphic.
 710        /// </summary>
 711        /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
 712        public bool? IsAnamorphic { get; set; }
 713
 714        internal string GetResolutionText()
 715        {
 73716            if (!Width.HasValue || !Height.HasValue)
 717            {
 3718                return null;
 719            }
 720
 70721            return Width switch
 70722            {
 70723                // 256x144 (16:9 square pixel format)
 4724                <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
 70725                // 426x240 (16:9 square pixel format)
 4726                <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
 70727                // 640x360 (16:9 square pixel format)
 14728                <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
 70729                // 682x384 (16:9 square pixel format)
 3730                <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
 70731                // 720x404 (16:9 square pixel format)
 7732                <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
 70733                // 854x480 (16:9 square pixel format)
 10734                <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
 70735                // 960x544 (16:9 square pixel format)
 11736                <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
 70737                // 1024x576 (16:9 square pixel format)
 9738                <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
 70739                // 1280x720
 26740                <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
 70741                // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
 46742                <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
 70743                // 4K
 12744                <= 4096 when Height <= 3072 => "4K",
 70745                // 8K
 6746                <= 8192 when Height <= 6144 => "8K",
 0747                _ => null
 70748            };
 749        }
 750
 751        public static bool IsTextFormat(string format)
 752        {
 3344753            string codec = format ?? string.Empty;
 754
 755            // microdvd and dvdsub/vobsub share the ".sub" file extension, but it's text-based.
 756
 3344757            return codec.Contains("microdvd", StringComparison.OrdinalIgnoreCase)
 3344758                   || (!codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 3344759                       && !codec.Contains("dvdsub", StringComparison.OrdinalIgnoreCase)
 3344760                       && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
 3344761                       && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
 3344762                       && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase));
 763        }
 764
 765        public static bool IsPgsFormat(string format)
 766        {
 8767            string codec = format ?? string.Empty;
 768
 8769            return codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
 8770                   || string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase);
 771        }
 772
 773        public bool SupportsSubtitleConversionTo(string toCodec)
 774        {
 286775            if (!IsTextSubtitleStream)
 776            {
 0777                return false;
 778            }
 779
 286780            var fromCodec = Codec;
 781
 782            // Can't convert from this
 286783            if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
 784            {
 0785                return false;
 786            }
 787
 286788            if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 789            {
 0790                return false;
 791            }
 792
 793            // Can't convert to this
 286794            if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
 795            {
 0796                return false;
 797            }
 798
 286799            if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
 800            {
 0801                return false;
 802            }
 803
 286804            return true;
 805        }
 806
 807        public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
 808        {
 938809            if (Type != MediaStreamType.Video)
 810            {
 64811                return (VideoRange.Unknown, VideoRangeType.Unknown);
 812            }
 813
 874814            var codecTag = CodecTag;
 874815            var dvProfile = DvProfile;
 874816            var rpuPresentFlag = RpuPresentFlag == 1;
 874817            var blPresentFlag = BlPresentFlag == 1;
 874818            var dvBlCompatId = DvBlSignalCompatibilityId;
 819
 874820            var isDoViProfile = dvProfile is 5 or 7 or 8 or 10;
 874821            var isDoViFlag = rpuPresentFlag && blPresentFlag && dvBlCompatId is 0 or 1 or 4 or 2 or 6;
 822
 874823            if ((isDoViProfile && isDoViFlag)
 874824                || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
 874825                || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
 874826                || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
 874827                || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
 828            {
 115829                var dvRangeSet = dvProfile switch
 115830                {
 64831                    5 => (VideoRange.HDR, VideoRangeType.DOVI),
 51832                    8 => dvBlCompatId switch
 51833                    {
 51834                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0835                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0836                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 51837                        // Out of Dolby Spec files should be marked as invalid
 0838                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 51839                    },
 0840                    7 => (VideoRange.HDR, VideoRangeType.DOVIWithEL),
 0841                    10 => dvBlCompatId switch
 0842                    {
 0843                        0 => (VideoRange.HDR, VideoRangeType.DOVI),
 0844                        1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
 0845                        2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
 0846                        4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
 0847                        // Out of Dolby Spec files should be marked as invalid
 0848                        _ => (VideoRange.HDR, VideoRangeType.DOVIInvalid)
 0849                    },
 0850                    _ => (VideoRange.SDR, VideoRangeType.SDR)
 115851                };
 852
 115853                if (Hdr10PlusPresentFlag == true)
 854                {
 0855                    return dvRangeSet.Item2 switch
 0856                    {
 0857                        VideoRangeType.DOVIWithHDR10 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10Plus),
 0858                        VideoRangeType.DOVIWithEL => (VideoRange.HDR, VideoRangeType.DOVIWithELHDR10Plus),
 0859                        _ => dvRangeSet
 0860                    };
 861                }
 862
 115863                return dvRangeSet;
 864            }
 865
 759866            var colorTransfer = ColorTransfer;
 867
 759868            if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
 869            {
 198870                return Hdr10PlusPresentFlag == true ? (VideoRange.HDR, VideoRangeType.HDR10Plus) : (VideoRange.HDR, Vide
 871            }
 561872            else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
 873            {
 0874                return (VideoRange.HDR, VideoRangeType.HLG);
 875            }
 876
 561877            return (VideoRange.SDR, VideoRangeType.SDR);
 878        }
 879    }
 880}