Track.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashFunctions.h>
  8. #include <AK/Time.h>
  9. #include <AK/Traits.h>
  10. #include <AK/Types.h>
  11. #include <AK/Variant.h>
  12. namespace Video {
  13. enum class TrackType : u32 {
  14. Video,
  15. Audio,
  16. Subtitles,
  17. };
  18. class Track {
  19. struct VideoData {
  20. Duration duration {};
  21. u64 pixel_width { 0 };
  22. u64 pixel_height { 0 };
  23. };
  24. public:
  25. Track(TrackType type, size_t identifier)
  26. : m_type(type)
  27. , m_identifier(identifier)
  28. {
  29. switch (m_type) {
  30. case TrackType::Video:
  31. m_track_data = VideoData {};
  32. break;
  33. default:
  34. m_track_data = Empty {};
  35. break;
  36. }
  37. }
  38. TrackType type() { return m_type; }
  39. size_t identifier() const { return m_identifier; }
  40. void set_video_data(VideoData data)
  41. {
  42. VERIFY(m_type == TrackType::Video);
  43. m_track_data = data;
  44. }
  45. VideoData const& video_data() const
  46. {
  47. VERIFY(m_type == TrackType::Video);
  48. return m_track_data.get<VideoData>();
  49. }
  50. bool operator==(Track const& other) const
  51. {
  52. return m_type == other.m_type && m_identifier == other.m_identifier;
  53. }
  54. unsigned hash() const
  55. {
  56. return pair_int_hash(to_underlying(m_type), m_identifier);
  57. }
  58. private:
  59. TrackType m_type;
  60. size_t m_identifier;
  61. Variant<Empty, VideoData> m_track_data;
  62. };
  63. }
  64. template<>
  65. struct AK::Traits<Video::Track> : public DefaultTraits<Video::Track> {
  66. static unsigned hash(Video::Track const& t) { return t.hash(); }
  67. };