2 // @ Copyright [2018] <S/W Platform, Visual Display, Samsung Electronics>
5 #ifndef __ESPLUSPLAYER_SRC_ESPLAYER_ESPLAYER__H__
6 #define __ESPLUSPLAYER_SRC_ESPLAYER_ESPLAYER__H__
8 #include <boost/core/noncopyable.hpp>
19 #include "core/decoderinputbuffer.h"
21 #include "core/trackrendereradapter.h"
23 #include "mixer/mixerticket.h"
24 #include "mixer/mixerticket_eventlistener.h"
26 #include "esplayer/espacket_logger.h"
27 #include "esplayer/message.hpp"
28 #include "esplayer/state_manager.hpp"
29 #include "esplusplayer/drm.h"
30 #include "esplusplayer/esplusplayer.h"
31 #include "esplusplayer/track.h"
32 #include "esplusplayer/types/buffer.h"
33 #include "esplusplayer/types/display.h"
34 #include "esplusplayer/types/error.h"
35 #include "esplusplayer/types/stream.h"
37 namespace esplusplayer {
43 kAllEos = (kAudioEos | kVideoEos)
46 static constexpr unsigned long kNeedDataMaskNone = 0x00;
47 static constexpr unsigned long kNeedDataMaskBySeek = 0x01;
48 static constexpr unsigned long kNeedDataMaskByPrepare = 0x02;
50 class EsPlayer : public EsPlusPlayer {
56 bool Close() override;
57 bool PrepareAsync() override;
58 bool Deactivate(const StreamType type) override;
59 bool Activate(const StreamType type) override;
60 bool DeactivateAudio() override;
61 bool ActivateAudio() override;
62 bool Start() override;
64 bool Pause() override;
65 bool Resume() override;
66 bool Seek(const uint64_t time) override;
67 void SetAppInfo(const PlayerAppInfo& app_info) override;
68 void SetAppInfoEx(const PlayerAppInfoEx& app_info) override;
69 bool SetPlaybackRate(const double rate, const bool audio_mute) override;
70 bool SetDisplay(const DisplayType& type, void* obj) override;
72 bool SetDisplay(const DisplayType& type, MixerTicket* handle) override;
74 bool SetDisplay(const DisplayType& type, void* ecore_wl2_window, const int x,
75 const int y, const int w, const int h) override;
76 bool SetDisplaySubsurface(const DisplayType& type, void* ecore_wl2_subsurface,
77 const int x, const int y, const int w,
78 const int h) override;
79 bool SetDisplay(const DisplayType& type, unsigned int surface_id, const int x,
80 const int y, const int w, const int h) override;
81 bool SetDisplayMode(const DisplayMode& mode) override;
82 bool SetStretchMode(const int& mode) override;
83 bool SetDisplayRoi(const Geometry& roi) override;
84 bool SetVideoRoi(const CropArea& area) override;
85 bool ResizeRenderRect(const RenderRect& rect) override;
86 bool SetDisplayRotate(const DisplayRotation& rotate) override;
87 bool GetDisplayRotate(DisplayRotation* rotate) override;
88 bool SetDisplayVisible(bool is_visible) override;
89 bool SetTrustZoneUse(bool is_using_tz) override;
90 bool SetSubmitDataType(SubmitDataType type) override;
91 bool SetStream(const AudioStreamPtr& stream) override;
92 bool SetStream(const VideoStreamPtr& stream) override;
93 PacketSubmitStatus SubmitPacket(const EsPacketPtr& packet) override;
94 PacketSubmitStatus SubmitTrustZonePacket(const EsPacketPtr& packet,
95 uint32_t tz_handle = 0) override;
96 PacketSubmitStatus SubmitEncryptedPacket(
97 const EsPacketPtr& packet,
98 const drm::EsPlayerEncryptedInfo& drm_info) override;
99 EsState GetState() override;
100 bool GetPlayingTime(uint64_t* time) override;
101 bool SetAudioMute(bool is_mute) override;
102 bool SetVideoFrameBufferType(DecodedVideoFrameBufferType type) override;
103 bool SetVideoFrameBufferScaleResolution(
104 const uint32_t& target_width, const uint32_t& target_height) override;
105 bool SetDecodedVideoFrameRate(const Rational& request_framerate) override;
106 void RegisterListener(EsEventListener* listener,
107 EsEventListener::UserData userdata) override;
108 bool GetAdaptiveInfo(void* padaptive_info,
109 const PlayerAdaptiveInfo& adaptive_type) override;
110 bool SetVolume(const int& volume) override;
111 bool GetVolume(int* volume) override;
112 bool Flush(const StreamType& type) override;
113 bool SetBufferSize(const BufferOption& option, uint64_t size) override;
114 bool SetLowLatencyMode(const PlayerLowLatencyMode& mode) override;
115 bool SetVideoFramePeekMode() override;
116 bool RenderVideoFrame() override;
117 bool SetUnlimitedMaxBufferMode() override;
118 ErrorType SetFmmMode() override;
119 bool SetAudioCodecType(const PlayerAudioCodecType& type) override;
120 bool SetVideoCodecType(const PlayerVideoCodecType& type) override;
121 bool SetRenderTimeOffset(const StreamType type, int64_t offset) override;
122 bool GetRenderTimeOffset(const StreamType type, int64_t* offset) override;
123 bool SetAlternativeVideoResource(unsigned int rsc_type) override;
124 bool SetAlternativeAudioResource(
125 const PlayerAudioResourceType rsc_type) override;
126 bool SwitchAudioStreamOnTheFly(const AudioStreamPtr& stream) override;
127 bool SetAiFilter(void* aifilter) override;
128 bool SetCatchUpSpeed(const CatchUpSpeed& level) override;
129 bool GetVideoLatencyStatus(LatencyStatus* status) override;
130 bool GetAudioLatencyStatus(LatencyStatus* status) override;
131 bool SetVideoMidLatencyThreshold(const unsigned int threshold) override;
132 bool SetAudioMidLatencyThreshold(const unsigned int threshold) override;
133 bool SetVideoHighLatencyThreshold(const unsigned int threshold) override;
134 bool SetAudioHighLatencyThreshold(const unsigned int threshold) override;
135 bool GetLowLatencyPcmBufferSize(uint64_t* frame_count) override;
136 bool GetLowLatencyPcmCurrentBufferLevel(uint64_t* frame_count) override;
137 bool GetLowLatencyPcmUnderrunCount(uint64_t* underrun_count) override;
138 bool InitAudioEasingInfo(const uint32_t init_volume,
139 const uint32_t init_elapsed_time,
140 const AudioEasingInfo& easing_info) override;
141 bool UpdateAudioEasingInfo(const AudioEasingInfo& easing_info) override;
142 bool GetAudioEasingInfo(uint32_t* current_volume, uint32_t* elapsed_time,
143 AudioEasingInfo* easing_info) override;
144 bool StartAudioEasing() override;
145 bool StopAudioEasing() override;
146 bool GetVirtualRscId(const RscType type, int* virtual_id) override;
147 bool SetAdvancedPictureQualityType(const AdvPictureQualityType type) override;
148 bool SetResourceAllocatePolicy(const RscAllocPolicy policy) override;
149 GetDecodedVideoFrameStatus GetDecodedPacket(
150 DecodedVideoPacket& packet) override;
151 bool ReturnDecodedPacket(const DecodedVideoPacket& packet) override;
152 bool SetAudioPreloading() override;
153 bool SetVideoScanType(const PlayerVideoScanType type) override;
154 bool SetTimeUnitType(const PlayerTimeUnitType type) override;
155 bool GetDecodingTime(StreamType type, int32_t* time_in_milliseconds) override;
156 bool SetVideoStreamRotationInfo(const VideoRotation& rotation) override;
157 bool GetVideoStreamRotationInfo(VideoRotation* rotation) override;
158 bool SetSimpleMixOutBufferLevel(
159 const PlayerSimpleMixOutBufferLevel level) override;
162 using SubmitPacketOperator =
163 std::function<PacketSubmitStatus(GstBuffer* buffer)>;
166 std::bitset<2> mask = kNeedDataMaskNone;
167 uint64_t seek_offset = 0;
175 enum class MakeBufferStatus {
177 kOutOfMemory, // out of memory
180 struct SrcQueueSize {
181 std::uint64_t kMaxByteOfVideoSrcQueue = 70 * 1024 * 1024; // 70 MB
182 std::uint64_t kMaxByteOfAudioSrcQueue = 10 * 1024 * 1024; // 10 MB
183 std::uint32_t kMinByteThresholdOfVideoSrcQueue = 0;
184 std::uint32_t kMinByteThresholdOfAudioSrcQueue = 0;
186 std::uint64_t kMaxTimeOfVideoSrcQueue = 0;
187 std::uint64_t kMaxTimeOfAudioSrcQueue = 0;
188 std::uint32_t kMinTimeThresholdOfVideoSrcQueue = 0;
189 std::uint32_t kMinTimeThresholdOfAudioSrcQueue = 0;
197 void SetTrackRendererAttributes_();
198 GstBuffer* GetGstBuffer_(const EsPacketPtr& packet, MakeBufferStatus* status);
199 void UnsetTzQdata_(const DecoderInputBufferPtr& buffer);
200 void MakeGstBufferForTzHandle_(GstBuffer* gstbuffer, const TrackType& type,
201 const uint32_t& tz_handle,
202 const uint32_t& packet_size);
203 void MakeGstBufferForEncryptedPacket_(
204 GstBuffer* gstbuffer, const EsPacketPtr& packet,
205 const drm::EsPlayerEncryptedInfo& drm_info);
206 PacketSubmitStatus SubmitPacketCommon_(const EsPacketPtr& packet,
207 SubmitPacketOperator op);
208 PacketSubmitStatus SubmitEosPacket_(const TrackType& type);
209 PacketSubmitStatus SubmitDecoderInputBuffer_(
210 const DecoderInputBufferPtr& buffer);
211 bool SetTrack_(const Track& track);
212 bool ChangeStream_(const Track& track);
213 bool SetStream_(const Track& track);
214 void ResetContextForClose_();
215 void ResetContextForStop_();
216 void GetSrcQueueCurrentSize_(const TrackType& type, uint64_t* byte_size,
217 uint64_t* time_size);
218 kpi::EsCodecLoggerKeys MakeKpiKeys_();
220 bool PrepareVideoMixingMode_(std::vector<Track>* tracks);
222 void InitValuesFromIni_();
224 private: // private types
225 class TrackRendererEventListener
226 : public TrackRendererAdapter::EventListener {
228 explicit TrackRendererEventListener(EsPlayer* handler) : handler_(handler) {
231 void OnError(const ErrorType& error_code) override;
232 void OnErrorMsg(const ErrorType& error_code, char* error_msg) override;
233 void OnResourceConflicted() override;
234 void OnEos() override;
235 void OnSeekDone() override;
236 void OnBufferStatus(const TrackType& type,
237 const BufferStatus& status) override;
238 void OnSeekData(const TrackType& type, const uint64_t offset) override;
239 void OnClosedCaptionData(const char* data, const int size) override;
240 void OnFlushDone() override;
241 void OnEvent(const EventType& event_type,
242 const EventMsg& msg_data) override;
243 void OnFirstDecodingDone() override;
244 void OnVideoDecoderUnderrun() override;
245 void OnVideoLatencyStatus(const LatencyStatus& latency_status) override;
246 void OnAudioLatencyStatus(const LatencyStatus& latency_status) override;
247 void OnVideoHighLatency() override;
248 void OnAudioHighLatency() override;
249 void OnVideoFrameDropped(const uint64_t& count) override;
251 void OnMediaPacketVideoRawDecoded(
252 const DecodedVideoRawModePacket& packet) override;
256 void ReadyToPrepare_(const TrackType& type);
257 void ReadyToSeek_(const TrackType& type);
258 void BufferStatus_(const TrackType& type, const BufferStatus& status);
259 void OnMediaPacketVideoDecoded(const DecodedVideoPacket& packet);
260 void OnMediaPacketGetTbmBufPtr(void** ptr, bool is_scale_change);
261 void OnDecoderInputBufferTime(const TrackType& type,
262 const DecoderBufferTime& time);
263 void OnDecoderOutputBufferTime(const TrackType& type,
264 const DecoderBufferTime& time);
267 EsPlayer* handler_ = nullptr;
268 }; // class TrackRendererEventListener
271 class MixerListener : public MixerTicketEventListener {
273 explicit MixerListener(EsPlayer* handler) : handler_(handler) {
276 bool OnAudioFocusChanged(bool active) override;
277 bool OnUpdateDisplayInfo(const DisplayInfo& cur_info,
278 DisplayInfo* new_info) override;
281 EsPlayer* handler_{nullptr};
286 std::vector<Track> track_;
287 NeedData need_data_[kTrackTypeMax];
288 int eos_status_ = EosStatus::kAllEos;
289 std::mutex eos_mutex_;
290 EsEventListener* eventlistener_ = nullptr;
291 EsEventListener::UserData eventlistener_userdata_ = nullptr;
292 bool is_audio_stream_info_frozen_ = false;
294 EsStateManager state_manager_;
296 SubmitDataType submit_data_type_ = SubmitDataType::kCleanData;
297 std::string key_system_;
298 bool key_system_acquired_ = false;
299 drm::Property drm_property_;
300 std::uint32_t low_latency_mode_ = 0;
301 std::uint32_t video_frame_peek_mode_ = 0;
302 std::uint32_t unlimited_max_buffer_mode_ = 0;
303 std::uint32_t accurate_seek_mode_ = 1;
304 std::uint32_t video_pre_display_mode_ = 1;
305 std::uint32_t fmm_mode_ = 0;
306 PlayerAudioCodecType audio_codec_type_ = kPlayerAudioCodecTypeHW;
307 PlayerVideoCodecType video_codec_type_ = kPlayerVideoCodecTypeHW;
308 bool force_audio_swdecoder_use_ = false;
309 bool force_video_swdecoder_use_ = false;
310 std::uint32_t video_decoding_mode_ = 0x02; // seamless mode
311 std::uint32_t alternative_video_resource_ = 0;
312 RscAllocPolicy resource_alloc_policy_ = RscAllocPolicy::kRscAllocExclusive;
313 std::uint32_t set_video_progressive_ = 0;
314 ResumeTime resume_time_;
316 bool is_msg_task_stop_ = false;
317 std::mutex msg_task_mutex_;
318 std::mutex submit_mutex_;
319 std::condition_variable msg_task_cv_;
320 std::queue<es_msg::Base::Ptr> msg_queue_;
321 std::future<void> msg_handler_task_;
323 std::unique_ptr<TrackRendererEventListener> trackrenderer_event_listener_{
324 new TrackRendererEventListener(this)};
326 std::unique_ptr<MixerListener> mixer_event_listener_{new MixerListener(this)};
328 std::unique_ptr<TrackRendererAdapter> trackrenderer_;
329 std::future<void> preparetask_;
330 PlayerAppInfo app_info_;
331 double current_playback_rate_ = 1.0;
332 bool current_audio_mute_ = false;
333 bool is_resource_conflicted_ = false;
334 bool is_stopped_ = false;
335 bool is_preparing_ = false;
336 bool is_seek_done_need_drop = false;
337 SrcQueueSize src_queue_size_;
339 std::string caf_unique_number;
341 std::unique_ptr<MixerTicket> mixer_ticket_;
342 bool is_audio_focused_ = true;
343 Geometry mixerticket_roi_;
344 bool is_visible_ = true;
345 std::mutex audio_focus_m_;
346 bool enable_audio_pipeline_handle_ = true;
347 bool enable_rsc_alloc_handle_ = true;
349 DecodedVideoFrameBufferType vidoe_frame_buffer_type_ =
350 DecodedVideoFrameBufferType::kNone;
352 EsPacketLogger es_packet_logger_;
353 PlayerTimeUnitType time_unit_type = kPlayerTimeUnitTypeMs;
354 VideoRotation video_rotate_ = VideoRotation::kVideoRotateNone;
357 } // namespace esplusplayer
358 #endif // __ESPLUSPLAYER_SRC_ESPLAYER_ESPLAYER__H__