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