MediaStream.cs 28 KB

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