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