MediaStream.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Text;
  9. using Jellyfin.Data.Enums;
  10. using Jellyfin.Extensions;
  11. using MediaBrowser.Model.Dlna;
  12. using MediaBrowser.Model.Extensions;
  13. using MediaBrowser.Model.MediaInfo;
  14. namespace MediaBrowser.Model.Entities
  15. {
  16. /// <summary>
  17. /// Class MediaStream.
  18. /// </summary>
  19. public class MediaStream
  20. {
  21. private static readonly string[] _specialCodes =
  22. {
  23. // Uncoded languages.
  24. "mis",
  25. // Multiple languages.
  26. "mul",
  27. // Undetermined.
  28. "und",
  29. // No linguistic content; not applicable.
  30. "zxx"
  31. };
  32. /// <summary>
  33. /// Gets or sets the codec.
  34. /// </summary>
  35. /// <value>The codec.</value>
  36. public string Codec { get; set; }
  37. /// <summary>
  38. /// Gets or sets the codec tag.
  39. /// </summary>
  40. /// <value>The codec tag.</value>
  41. public string CodecTag { get; set; }
  42. /// <summary>
  43. /// Gets or sets the language.
  44. /// </summary>
  45. /// <value>The language.</value>
  46. public string Language { get; set; }
  47. /// <summary>
  48. /// Gets or sets the color range.
  49. /// </summary>
  50. /// <value>The color range.</value>
  51. public string ColorRange { get; set; }
  52. /// <summary>
  53. /// Gets or sets the color space.
  54. /// </summary>
  55. /// <value>The color space.</value>
  56. public string ColorSpace { get; set; }
  57. /// <summary>
  58. /// Gets or sets the color transfer.
  59. /// </summary>
  60. /// <value>The color transfer.</value>
  61. public string ColorTransfer { get; set; }
  62. /// <summary>
  63. /// Gets or sets the color primaries.
  64. /// </summary>
  65. /// <value>The color primaries.</value>
  66. public string ColorPrimaries { get; set; }
  67. /// <summary>
  68. /// Gets or sets the Dolby Vision version major.
  69. /// </summary>
  70. /// <value>The Dolby Vision version major.</value>
  71. public int? DvVersionMajor { get; set; }
  72. /// <summary>
  73. /// Gets or sets the Dolby Vision version minor.
  74. /// </summary>
  75. /// <value>The Dolby Vision version minor.</value>
  76. public int? DvVersionMinor { get; set; }
  77. /// <summary>
  78. /// Gets or sets the Dolby Vision profile.
  79. /// </summary>
  80. /// <value>The Dolby Vision profile.</value>
  81. public int? DvProfile { get; set; }
  82. /// <summary>
  83. /// Gets or sets the Dolby Vision level.
  84. /// </summary>
  85. /// <value>The Dolby Vision level.</value>
  86. public int? DvLevel { get; set; }
  87. /// <summary>
  88. /// Gets or sets the Dolby Vision rpu present flag.
  89. /// </summary>
  90. /// <value>The Dolby Vision rpu present flag.</value>
  91. public int? RpuPresentFlag { get; set; }
  92. /// <summary>
  93. /// Gets or sets the Dolby Vision el present flag.
  94. /// </summary>
  95. /// <value>The Dolby Vision el present flag.</value>
  96. public int? ElPresentFlag { get; set; }
  97. /// <summary>
  98. /// Gets or sets the Dolby Vision bl present flag.
  99. /// </summary>
  100. /// <value>The Dolby Vision bl present flag.</value>
  101. public int? BlPresentFlag { get; set; }
  102. /// <summary>
  103. /// Gets or sets the Dolby Vision bl signal compatibility id.
  104. /// </summary>
  105. /// <value>The Dolby Vision bl signal compatibility id.</value>
  106. public int? DvBlSignalCompatibilityId { get; set; }
  107. /// <summary>
  108. /// Gets or sets the comment.
  109. /// </summary>
  110. /// <value>The comment.</value>
  111. public string Comment { get; set; }
  112. /// <summary>
  113. /// Gets or sets the time base.
  114. /// </summary>
  115. /// <value>The time base.</value>
  116. public string TimeBase { get; set; }
  117. /// <summary>
  118. /// Gets or sets the codec time base.
  119. /// </summary>
  120. /// <value>The codec time base.</value>
  121. public string CodecTimeBase { get; set; }
  122. /// <summary>
  123. /// Gets or sets the title.
  124. /// </summary>
  125. /// <value>The title.</value>
  126. public string Title { get; set; }
  127. /// <summary>
  128. /// Gets the video range.
  129. /// </summary>
  130. /// <value>The video range.</value>
  131. public VideoRange VideoRange
  132. {
  133. get
  134. {
  135. var (videoRange, _) = GetVideoColorRange();
  136. return videoRange;
  137. }
  138. }
  139. /// <summary>
  140. /// Gets the video range type.
  141. /// </summary>
  142. /// <value>The video range type.</value>
  143. public VideoRangeType VideoRangeType
  144. {
  145. get
  146. {
  147. var (_, videoRangeType) = GetVideoColorRange();
  148. return videoRangeType;
  149. }
  150. }
  151. /// <summary>
  152. /// Gets the video dovi title.
  153. /// </summary>
  154. /// <value>The video dovi title.</value>
  155. public string VideoDoViTitle
  156. {
  157. get
  158. {
  159. var dvProfile = DvProfile;
  160. var rpuPresentFlag = RpuPresentFlag == 1;
  161. var blPresentFlag = BlPresentFlag == 1;
  162. var dvBlCompatId = DvBlSignalCompatibilityId;
  163. if (rpuPresentFlag
  164. && blPresentFlag
  165. && (dvProfile == 4
  166. || dvProfile == 5
  167. || dvProfile == 7
  168. || dvProfile == 8
  169. || dvProfile == 9))
  170. {
  171. var title = "DV Profile " + dvProfile;
  172. if (dvBlCompatId > 0)
  173. {
  174. title += "." + dvBlCompatId;
  175. }
  176. return dvBlCompatId switch
  177. {
  178. 1 => title + " (HDR10)",
  179. 2 => title + " (SDR)",
  180. 4 => title + " (HLG)",
  181. _ => title
  182. };
  183. }
  184. return null;
  185. }
  186. }
  187. /// <summary>
  188. /// Gets the audio spatial format.
  189. /// </summary>
  190. /// <value>The audio spatial format.</value>
  191. [DefaultValue(AudioSpatialFormat.None)]
  192. public AudioSpatialFormat AudioSpatialFormat
  193. {
  194. get
  195. {
  196. if (Type != MediaStreamType.Audio || string.IsNullOrEmpty(Profile))
  197. {
  198. return AudioSpatialFormat.None;
  199. }
  200. return
  201. Profile.Contains("Dolby Atmos", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DolbyAtmos :
  202. Profile.Contains("DTS:X", StringComparison.OrdinalIgnoreCase) ? AudioSpatialFormat.DTSX :
  203. AudioSpatialFormat.None;
  204. }
  205. }
  206. public string LocalizedUndefined { get; set; }
  207. public string LocalizedDefault { get; set; }
  208. public string LocalizedForced { get; set; }
  209. public string LocalizedExternal { get; set; }
  210. public string LocalizedHearingImpaired { get; set; }
  211. public string DisplayTitle
  212. {
  213. get
  214. {
  215. switch (Type)
  216. {
  217. case MediaStreamType.Audio:
  218. {
  219. var attributes = new List<string>();
  220. // Do not display the language code in display titles if unset or set to a special code. Show it in all other cases (possibly expanded).
  221. if (!string.IsNullOrEmpty(Language) && !_specialCodes.Contains(Language, StringComparison.OrdinalIgnoreCase))
  222. {
  223. // Get full language string i.e. eng -> English. Will not work for some languages which use ISO 639-2/B instead of /T codes.
  224. string fullLanguage = CultureInfo
  225. .GetCultures(CultureTypes.NeutralCultures)
  226. .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.OrdinalIgnoreCase))
  227. ?.DisplayName;
  228. attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
  229. }
  230. if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgnoreCase))
  231. {
  232. attributes.Add(Profile);
  233. }
  234. else if (!string.IsNullOrEmpty(Codec))
  235. {
  236. attributes.Add(AudioCodec.GetFriendlyName(Codec));
  237. }
  238. if (!string.IsNullOrEmpty(ChannelLayout))
  239. {
  240. attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
  241. }
  242. else if (Channels.HasValue)
  243. {
  244. attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
  245. }
  246. if (IsDefault)
  247. {
  248. attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
  249. }
  250. if (IsExternal)
  251. {
  252. attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
  253. }
  254. if (!string.IsNullOrEmpty(Title))
  255. {
  256. var result = new StringBuilder(Title);
  257. foreach (var tag in attributes)
  258. {
  259. // Keep Tags that are not already in Title.
  260. if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
  261. {
  262. result.Append(" - ").Append(tag);
  263. }
  264. }
  265. return result.ToString();
  266. }
  267. return string.Join(" - ", attributes);
  268. }
  269. case MediaStreamType.Video:
  270. {
  271. var attributes = new List<string>();
  272. var resolutionText = GetResolutionText();
  273. if (!string.IsNullOrEmpty(resolutionText))
  274. {
  275. attributes.Add(resolutionText);
  276. }
  277. if (!string.IsNullOrEmpty(Codec))
  278. {
  279. attributes.Add(Codec.ToUpperInvariant());
  280. }
  281. if (VideoRange != VideoRange.Unknown)
  282. {
  283. attributes.Add(VideoRange.ToString());
  284. }
  285. if (!string.IsNullOrEmpty(Title))
  286. {
  287. var result = new StringBuilder(Title);
  288. foreach (var tag in attributes)
  289. {
  290. // Keep Tags that are not already in Title.
  291. if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
  292. {
  293. result.Append(" - ").Append(tag);
  294. }
  295. }
  296. return result.ToString();
  297. }
  298. return string.Join(' ', attributes);
  299. }
  300. case MediaStreamType.Subtitle:
  301. {
  302. var attributes = new List<string>();
  303. if (!string.IsNullOrEmpty(Language))
  304. {
  305. // Get full language string i.e. eng -> English. Will not work for some languages which use ISO 639-2/B instead of /T codes.
  306. string fullLanguage = CultureInfo
  307. .GetCultures(CultureTypes.NeutralCultures)
  308. .FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.OrdinalIgnoreCase))
  309. ?.DisplayName;
  310. attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
  311. }
  312. else
  313. {
  314. attributes.Add(string.IsNullOrEmpty(LocalizedUndefined) ? "Und" : LocalizedUndefined);
  315. }
  316. if (IsHearingImpaired)
  317. {
  318. attributes.Add(string.IsNullOrEmpty(LocalizedHearingImpaired) ? "Hearing Impaired" : LocalizedHearingImpaired);
  319. }
  320. if (IsDefault)
  321. {
  322. attributes.Add(string.IsNullOrEmpty(LocalizedDefault) ? "Default" : LocalizedDefault);
  323. }
  324. if (IsForced)
  325. {
  326. attributes.Add(string.IsNullOrEmpty(LocalizedForced) ? "Forced" : LocalizedForced);
  327. }
  328. if (!string.IsNullOrEmpty(Codec))
  329. {
  330. attributes.Add(Codec.ToUpperInvariant());
  331. }
  332. if (IsExternal)
  333. {
  334. attributes.Add(string.IsNullOrEmpty(LocalizedExternal) ? "External" : LocalizedExternal);
  335. }
  336. if (!string.IsNullOrEmpty(Title))
  337. {
  338. var result = new StringBuilder(Title);
  339. foreach (var tag in attributes)
  340. {
  341. // Keep Tags that are not already in Title.
  342. if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
  343. {
  344. result.Append(" - ").Append(tag);
  345. }
  346. }
  347. return result.ToString();
  348. }
  349. return string.Join(" - ", attributes);
  350. }
  351. default:
  352. return null;
  353. }
  354. }
  355. }
  356. public string NalLengthSize { get; set; }
  357. /// <summary>
  358. /// Gets or sets a value indicating whether this instance is interlaced.
  359. /// </summary>
  360. /// <value><c>true</c> if this instance is interlaced; otherwise, <c>false</c>.</value>
  361. public bool IsInterlaced { get; set; }
  362. public bool? IsAVC { get; set; }
  363. /// <summary>
  364. /// Gets or sets the channel layout.
  365. /// </summary>
  366. /// <value>The channel layout.</value>
  367. public string ChannelLayout { get; set; }
  368. /// <summary>
  369. /// Gets or sets the bit rate.
  370. /// </summary>
  371. /// <value>The bit rate.</value>
  372. public int? BitRate { get; set; }
  373. /// <summary>
  374. /// Gets or sets the bit depth.
  375. /// </summary>
  376. /// <value>The bit depth.</value>
  377. public int? BitDepth { get; set; }
  378. /// <summary>
  379. /// Gets or sets the reference frames.
  380. /// </summary>
  381. /// <value>The reference frames.</value>
  382. public int? RefFrames { get; set; }
  383. /// <summary>
  384. /// Gets or sets the length of the packet.
  385. /// </summary>
  386. /// <value>The length of the packet.</value>
  387. public int? PacketLength { get; set; }
  388. /// <summary>
  389. /// Gets or sets the channels.
  390. /// </summary>
  391. /// <value>The channels.</value>
  392. public int? Channels { get; set; }
  393. /// <summary>
  394. /// Gets or sets the sample rate.
  395. /// </summary>
  396. /// <value>The sample rate.</value>
  397. public int? SampleRate { get; set; }
  398. /// <summary>
  399. /// Gets or sets a value indicating whether this instance is default.
  400. /// </summary>
  401. /// <value><c>true</c> if this instance is default; otherwise, <c>false</c>.</value>
  402. public bool IsDefault { get; set; }
  403. /// <summary>
  404. /// Gets or sets a value indicating whether this instance is forced.
  405. /// </summary>
  406. /// <value><c>true</c> if this instance is forced; otherwise, <c>false</c>.</value>
  407. public bool IsForced { get; set; }
  408. /// <summary>
  409. /// Gets or sets a value indicating whether this instance is for the hearing impaired.
  410. /// </summary>
  411. /// <value><c>true</c> if this instance is for the hearing impaired; otherwise, <c>false</c>.</value>
  412. public bool IsHearingImpaired { get; set; }
  413. /// <summary>
  414. /// Gets or sets the height.
  415. /// </summary>
  416. /// <value>The height.</value>
  417. public int? Height { get; set; }
  418. /// <summary>
  419. /// Gets or sets the width.
  420. /// </summary>
  421. /// <value>The width.</value>
  422. public int? Width { get; set; }
  423. /// <summary>
  424. /// Gets or sets the average frame rate.
  425. /// </summary>
  426. /// <value>The average frame rate.</value>
  427. public float? AverageFrameRate { get; set; }
  428. /// <summary>
  429. /// Gets or sets the real frame rate.
  430. /// </summary>
  431. /// <value>The real frame rate.</value>
  432. public float? RealFrameRate { get; set; }
  433. /// <summary>
  434. /// Gets or sets the profile.
  435. /// </summary>
  436. /// <value>The profile.</value>
  437. public string Profile { get; set; }
  438. /// <summary>
  439. /// Gets or sets the type.
  440. /// </summary>
  441. /// <value>The type.</value>
  442. public MediaStreamType Type { get; set; }
  443. /// <summary>
  444. /// Gets or sets the aspect ratio.
  445. /// </summary>
  446. /// <value>The aspect ratio.</value>
  447. public string AspectRatio { get; set; }
  448. /// <summary>
  449. /// Gets or sets the index.
  450. /// </summary>
  451. /// <value>The index.</value>
  452. public int Index { get; set; }
  453. /// <summary>
  454. /// Gets or sets the score.
  455. /// </summary>
  456. /// <value>The score.</value>
  457. public int? Score { get; set; }
  458. /// <summary>
  459. /// Gets or sets a value indicating whether this instance is external.
  460. /// </summary>
  461. /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
  462. public bool IsExternal { get; set; }
  463. /// <summary>
  464. /// Gets or sets the method.
  465. /// </summary>
  466. /// <value>The method.</value>
  467. public SubtitleDeliveryMethod? DeliveryMethod { get; set; }
  468. /// <summary>
  469. /// Gets or sets the delivery URL.
  470. /// </summary>
  471. /// <value>The delivery URL.</value>
  472. public string DeliveryUrl { get; set; }
  473. /// <summary>
  474. /// Gets or sets a value indicating whether this instance is external URL.
  475. /// </summary>
  476. /// <value><c>null</c> if [is external URL] contains no value, <c>true</c> if [is external URL]; otherwise, <c>false</c>.</value>
  477. public bool? IsExternalUrl { get; set; }
  478. public bool IsTextSubtitleStream
  479. {
  480. get
  481. {
  482. if (Type != MediaStreamType.Subtitle)
  483. {
  484. return false;
  485. }
  486. if (string.IsNullOrEmpty(Codec) && !IsExternal)
  487. {
  488. return false;
  489. }
  490. return IsTextFormat(Codec);
  491. }
  492. }
  493. /// <summary>
  494. /// Gets or sets a value indicating whether [supports external stream].
  495. /// </summary>
  496. /// <value><c>true</c> if [supports external stream]; otherwise, <c>false</c>.</value>
  497. public bool SupportsExternalStream { get; set; }
  498. /// <summary>
  499. /// Gets or sets the filename.
  500. /// </summary>
  501. /// <value>The filename.</value>
  502. public string Path { get; set; }
  503. /// <summary>
  504. /// Gets or sets the pixel format.
  505. /// </summary>
  506. /// <value>The pixel format.</value>
  507. public string PixelFormat { get; set; }
  508. /// <summary>
  509. /// Gets or sets the level.
  510. /// </summary>
  511. /// <value>The level.</value>
  512. public double? Level { get; set; }
  513. /// <summary>
  514. /// Gets or sets whether this instance is anamorphic.
  515. /// </summary>
  516. /// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
  517. public bool? IsAnamorphic { get; set; }
  518. internal string GetResolutionText()
  519. {
  520. if (!Width.HasValue || !Height.HasValue)
  521. {
  522. return null;
  523. }
  524. return Width switch
  525. {
  526. // 256x144 (16:9 square pixel format)
  527. <= 256 when Height <= 144 => IsInterlaced ? "144i" : "144p",
  528. // 426x240 (16:9 square pixel format)
  529. <= 426 when Height <= 240 => IsInterlaced ? "240i" : "240p",
  530. // 640x360 (16:9 square pixel format)
  531. <= 640 when Height <= 360 => IsInterlaced ? "360i" : "360p",
  532. // 682x384 (16:9 square pixel format)
  533. <= 682 when Height <= 384 => IsInterlaced ? "384i" : "384p",
  534. // 720x404 (16:9 square pixel format)
  535. <= 720 when Height <= 404 => IsInterlaced ? "404i" : "404p",
  536. // 854x480 (16:9 square pixel format)
  537. <= 854 when Height <= 480 => IsInterlaced ? "480i" : "480p",
  538. // 960x544 (16:9 square pixel format)
  539. <= 960 when Height <= 544 => IsInterlaced ? "540i" : "540p",
  540. // 1024x576 (16:9 square pixel format)
  541. <= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
  542. // 1280x720
  543. <= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
  544. // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
  545. <= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
  546. // 4K
  547. <= 4096 when Height <= 3072 => "4K",
  548. // 8K
  549. <= 8192 when Height <= 6144 => "8K",
  550. _ => null
  551. };
  552. }
  553. public static bool IsTextFormat(string format)
  554. {
  555. string codec = format ?? string.Empty;
  556. // sub = external .sub file
  557. return !codec.Contains("pgs", StringComparison.OrdinalIgnoreCase)
  558. && !codec.Contains("dvd", StringComparison.OrdinalIgnoreCase)
  559. && !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase)
  560. && !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase)
  561. && !string.Equals(codec, "sup", StringComparison.OrdinalIgnoreCase)
  562. && !string.Equals(codec, "dvb_subtitle", StringComparison.OrdinalIgnoreCase);
  563. }
  564. public bool SupportsSubtitleConversionTo(string toCodec)
  565. {
  566. if (!IsTextSubtitleStream)
  567. {
  568. return false;
  569. }
  570. var fromCodec = Codec;
  571. // Can't convert from this
  572. if (string.Equals(fromCodec, "ass", StringComparison.OrdinalIgnoreCase))
  573. {
  574. return false;
  575. }
  576. if (string.Equals(fromCodec, "ssa", StringComparison.OrdinalIgnoreCase))
  577. {
  578. return false;
  579. }
  580. // Can't convert to this
  581. if (string.Equals(toCodec, "ass", StringComparison.OrdinalIgnoreCase))
  582. {
  583. return false;
  584. }
  585. if (string.Equals(toCodec, "ssa", StringComparison.OrdinalIgnoreCase))
  586. {
  587. return false;
  588. }
  589. return true;
  590. }
  591. public (VideoRange VideoRange, VideoRangeType VideoRangeType) GetVideoColorRange()
  592. {
  593. if (Type != MediaStreamType.Video)
  594. {
  595. return (VideoRange.Unknown, VideoRangeType.Unknown);
  596. }
  597. var codecTag = CodecTag;
  598. var dvProfile = DvProfile;
  599. var rpuPresentFlag = RpuPresentFlag == 1;
  600. var blPresentFlag = BlPresentFlag == 1;
  601. var dvBlCompatId = DvBlSignalCompatibilityId;
  602. var isDoViProfile = dvProfile == 5 || dvProfile == 7 || dvProfile == 8;
  603. var isDoViFlag = rpuPresentFlag && blPresentFlag && (dvBlCompatId == 0 || dvBlCompatId == 1 || dvBlCompatId == 4 || dvBlCompatId == 2 || dvBlCompatId == 6);
  604. if ((isDoViProfile && isDoViFlag)
  605. || string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
  606. || string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
  607. || string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
  608. || string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
  609. {
  610. return dvProfile switch
  611. {
  612. 5 => (VideoRange.HDR, VideoRangeType.DOVI),
  613. 8 => dvBlCompatId switch
  614. {
  615. 1 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
  616. 4 => (VideoRange.HDR, VideoRangeType.DOVIWithHLG),
  617. 2 => (VideoRange.SDR, VideoRangeType.DOVIWithSDR),
  618. // While not in Dolby Spec, Profile 8 CCid 6 media are possible to create, and since CCid 6 stems from Bluray (Profile 7 originally) an HDR10 base layer is guaranteed to exist.
  619. 6 => (VideoRange.HDR, VideoRangeType.DOVIWithHDR10),
  620. // There is no other case to handle here as per Dolby Spec. Default case included for completeness and linting purposes
  621. _ => (VideoRange.SDR, VideoRangeType.SDR)
  622. },
  623. 7 => (VideoRange.HDR, VideoRangeType.HDR10),
  624. _ => (VideoRange.SDR, VideoRangeType.SDR)
  625. };
  626. }
  627. var colorTransfer = ColorTransfer;
  628. if (string.Equals(colorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase))
  629. {
  630. return (VideoRange.HDR, VideoRangeType.HDR10);
  631. }
  632. else if (string.Equals(colorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase))
  633. {
  634. return (VideoRange.HDR, VideoRangeType.HLG);
  635. }
  636. return (VideoRange.SDR, VideoRangeType.SDR);
  637. }
  638. }
  639. }