xbmc
DVDVideoCodecStarfish.h
1 /*
2  * Copyright (C) 2023 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "DVDStreamInfo.h"
12 #include "DVDVideoCodec.h"
13 #include "cores/VideoPlayer/Buffers/VideoBuffer.h"
14 #include "threads/SingleLock.h"
15 #include "threads/Thread.h"
16 #include "utils/Geometry.h"
17 
18 #include <fmt/format.h>
19 #include <starfish-media-pipeline/StarfishMediaAPIs.h>
20 
22 
24 {
25 public:
26  explicit CStarfishVideoBuffer(int id) : CVideoBuffer(id) {}
27  AVPixelFormat GetFormat() override { return AV_PIX_FMT_NONE; }
28  long m_acbId{0};
29 };
30 
31 enum class StarfishState
32 {
33  RESET,
34  FLUSHED,
35  RUNNING,
36  EOS,
37  ERROR,
38  MAX,
39 };
40 
41 template<>
42 struct fmt::formatter<StarfishState> : fmt::formatter<std::string_view>
43 {
44 public:
45  template<typename FormatContext>
46  constexpr auto format(const StarfishState& state, FormatContext& ctx)
47  {
48  const auto it = ms_stateMap.find(state);
49  if (it == ms_stateMap.cend())
50  throw std::range_error("no starfish state string found");
51 
52  return fmt::formatter<string_view>::format(it->second, ctx);
53  }
54 
55 private:
56  static constexpr auto ms_stateMap = make_map<StarfishState, std::string_view>({
57  {StarfishState::RESET, "Reset"},
58  {StarfishState::FLUSHED, "Flushed"},
59  {StarfishState::RUNNING, "Running"},
60  {StarfishState::EOS, "EOS"},
61  {StarfishState::ERROR, "Error"},
62  });
63  static_assert(static_cast<size_t>(StarfishState::MAX) == ms_stateMap.size(),
64  "ms_stateMap doesn't match the size of StarfishState, did you forget to "
65  "add/remove a mapping?");
66 };
67 
69 {
70 public:
71  explicit CDVDVideoCodecStarfish(CProcessInfo& processInfo);
72  ~CDVDVideoCodecStarfish() override;
73 
74  // registration
75  static std::unique_ptr<CDVDVideoCodec> Create(CProcessInfo& processInfo);
76  static bool Register();
77 
78  // required overrides
79  bool Open(CDVDStreamInfo& hints, CDVDCodecOptions& options) override;
80  bool AddData(const DemuxPacket& packet) override;
81  void Reset() override;
82  bool Reconfigure(CDVDStreamInfo& hints) override;
83  VCReturn GetPicture(VideoPicture* pVideoPicture) override;
84  const char* GetName() override { return m_formatname.c_str(); }
85  void SetCodecControl(int flags) override;
86  void SetSpeed(int iSpeed) override;
87 
88 private:
89  void Dispose();
90  void SetHDR();
91  void UpdateFpsDuration();
92  bool OpenInternal(CDVDStreamInfo& hints, CDVDCodecOptions& options);
93 
94  void PlayerCallback(const int32_t type, const int64_t numValue, const char* strValue);
95  static void PlayerCallback(const int32_t type,
96  const int64_t numValue,
97  const char* strValue,
98  void* data);
99  static void AcbCallback(
100  long acbId, long taskId, long eventType, long appState, long playState, const char* reply);
101  std::unique_ptr<StarfishMediaAPIs> m_starfishMediaAPI;
102  long m_acbId{0};
103 
104  CDVDStreamInfo m_hints;
105  std::string m_codecname;
106  std::string m_formatname{"starfish"};
107  bool m_opened{false};
108  int m_codecControlFlags;
109  std::chrono::nanoseconds m_currentPlaytime{0};
110  bool m_newFrame{false};
111 
112  StarfishState m_state{StarfishState::FLUSHED};
113 
114  VideoPicture m_videobuffer;
115  std::unique_ptr<CBitstreamConverter> m_bitstream;
116 
117  static constexpr auto ms_codecMap = make_map<AVCodecID, std::string_view>({
118  {AV_CODEC_ID_VP8, "VP8"},
119  {AV_CODEC_ID_VP9, "VP9"},
120  {AV_CODEC_ID_AVS, "H264"},
121  {AV_CODEC_ID_CAVS, "H264"},
122  {AV_CODEC_ID_H264, "H264"},
123  {AV_CODEC_ID_HEVC, "H265"},
124  {AV_CODEC_ID_AV1, "AV1"},
125  });
126 
127  static constexpr auto ms_formatInfoMap = make_map<AVCodecID, std::string_view>({
128  {AV_CODEC_ID_VP8, "starfish-vp8"},
129  {AV_CODEC_ID_VP9, "starfish-vp9"},
130  {AV_CODEC_ID_AVS, "starfish-h264"},
131  {AV_CODEC_ID_CAVS, "starfish-h264"},
132  {AV_CODEC_ID_H264, "starfish-h264"},
133  {AV_CODEC_ID_HEVC, "starfish-h265"},
134  {AV_CODEC_ID_AV1, "starfish-av1"},
135  });
136 
137  static constexpr auto ms_hdrInfoMap = make_map<AVColorTransferCharacteristic, std::string_view>({
138  {AVCOL_TRC_SMPTE2084, "HDR10"},
139  {AVCOL_TRC_ARIB_STD_B67, "HLG"},
140  });
141 
142  static std::atomic<bool> ms_instanceGuard;
143 };
Definition: DVDStreamInfo.h:25
Definition: VideoBuffer.h:85
Definition: DVDVideoCodecStarfish.h:68
Definition: DVDCodecs.h:23
Definition: BitstreamConverter.h:85
Definition: ProcessInfo.h:26
Definition: DVDVideoCodec.h:36
Definition: DemuxPacket.h:22
const char * GetName() override
should return codecs name
Definition: DVDVideoCodecStarfish.h:84
Definition: DVDVideoCodec.h:107
Definition: DVDVideoCodecStarfish.h:23