2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <tizen-video-player.h>
22 #include <dali/devel-api/common/stage.h>
23 #include <dali/devel-api/threading/mutex.h>
24 #include <dali/integration-api/debug.h>
25 #include <system_info.h>
29 // The plugin factories
30 extern "C" DALI_EXPORT_API Dali::VideoPlayerPlugin* CreateVideoPlayerPlugin(Dali::Actor actor, Dali::VideoSyncMode syncMode)
32 return new Dali::Plugin::TizenVideoPlayer(actor, syncMode);
35 extern "C" DALI_EXPORT_API void DestroyVideoPlayerPlugin(Dali::VideoPlayerPlugin* plugin)
49 const int TIMER_INTERVAL(20);
51 static void MediaPacketVideoDecodedCb(media_packet_h packet, void* user_data)
53 TizenVideoPlayer* player = static_cast<TizenVideoPlayer*>(user_data);
57 DALI_LOG_ERROR("Decoded callback got Null pointer as user_data.\n");
61 player->PushPacket(packet);
64 static GMainContext* GetTizenGlibContext()
66 static GMainContext* context = nullptr;
70 const char* env = getenv("TIZEN_GLIB_CONTEXT");
73 context = (GMainContext*)strtoul(env, nullptr, 10);
80 static void EmitPlaybackFinishedSignal(void* user_data)
82 TizenVideoPlayer* player = static_cast<TizenVideoPlayer*>(user_data);
86 DALI_LOG_ERROR("Decoded callback got Null pointer as user_data.\n");
90 if(!player->mFinishedSignal.Empty())
92 DALI_LOG_ERROR("EmitPlaybackFinishedSignal.\n");
94 // This function is invoked on the main thread from MMFW.
95 // So the FinishedSignal has to be posted to UIThread when UIThread is enabled.
96 // If not, it causes an assertion in the timer.
97 // The timer has to run on the same thread as the adaptor's
98 GMainContext* context = GetTizenGlibContext();
101 GSource* source = g_idle_source_new();
102 g_source_set_callback(
104 [](gpointer userData) -> gboolean
106 auto* player = static_cast<TizenVideoPlayer*>(userData);
107 player->mFinishedSignal.Emit();
109 return G_SOURCE_REMOVE;
113 g_source_attach(source, context);
114 g_source_unref(source);
118 player->mFinishedSignal.Emit();
124 // ToDo: VD player_set_play_position() doesn't work when callback pointer is NULL.
125 // We should check whether this callback is needed in platform.
126 static void PlayerSeekCompletedCb(void* data)
130 int LogPlayerError(int error)
133 if(error != PLAYER_ERROR_NONE)
138 case PLAYER_ERROR_OUT_OF_MEMORY:
140 DALI_LOG_ERROR("Player error: Out of memory\n");
143 case PLAYER_ERROR_INVALID_PARAMETER:
145 DALI_LOG_ERROR("Player error: Invalid parameter\n");
148 case PLAYER_ERROR_NO_SUCH_FILE:
150 DALI_LOG_ERROR("Player error: No such file\n");
153 case PLAYER_ERROR_INVALID_OPERATION:
155 DALI_LOG_ERROR("Player error: Invalid operation\n");
158 case PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE:
160 DALI_LOG_ERROR("Player error: No space on device\n");
163 case PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE:
165 DALI_LOG_ERROR("Player error: Not supported feature on device\n");
168 case PLAYER_ERROR_SEEK_FAILED:
170 DALI_LOG_ERROR("Player error: Seek failed\n");
173 case PLAYER_ERROR_INVALID_STATE:
175 DALI_LOG_ERROR("Player error: Invalid state\n");
178 case PLAYER_ERROR_NOT_SUPPORTED_FILE:
180 DALI_LOG_ERROR("Player error: Not supported file\n");
183 case PLAYER_ERROR_INVALID_URI:
185 DALI_LOG_ERROR("Player error: Invalid uri\n");
188 case PLAYER_ERROR_SOUND_POLICY:
190 DALI_LOG_ERROR("Player error: Sound policy\n");
193 case PLAYER_ERROR_CONNECTION_FAILED:
195 DALI_LOG_ERROR("Player error: Connection failed\n");
198 case PLAYER_ERROR_VIDEO_CAPTURE_FAILED:
200 DALI_LOG_ERROR("Player error: Video capture failed\n");
203 case PLAYER_ERROR_DRM_EXPIRED:
205 DALI_LOG_ERROR("Player error: DRM expired\n");
208 case PLAYER_ERROR_DRM_NO_LICENSE:
210 DALI_LOG_ERROR("Player error: No license\n");
213 case PLAYER_ERROR_DRM_FUTURE_USE:
215 DALI_LOG_ERROR("Player error: License for future use\n");
218 case PLAYER_ERROR_DRM_NOT_PERMITTED:
220 DALI_LOG_ERROR("Player error: Format not permitted\n");
223 case PLAYER_ERROR_RESOURCE_LIMIT:
225 DALI_LOG_ERROR("Player error: Resource limit\n");
228 case PLAYER_ERROR_PERMISSION_DENIED:
230 DALI_LOG_ERROR("Player error: Permission denied\n");
233 case PLAYER_ERROR_SERVICE_DISCONNECTED:
235 DALI_LOG_ERROR("Player error: Service disconnected\n");
238 case PLAYER_ERROR_BUFFER_SPACE:
240 DALI_LOG_ERROR("Player error: Buffer space\n");
243 case PLAYER_ERROR_NOT_SUPPORTED_VIDEO_CODEC:
245 DALI_LOG_ERROR("Player error: The target should not support the codec type\n");
250 DALI_LOG_ERROR("Player error: Unknown error code ( %d ) \n", error);
258 const char* const VIDEO_PLAYER_SIZE_NAME("videoPlayerSize");
260 struct VideoPlayerSyncConstraint
263 VideoPlayerSyncConstraint(Ecore_Wl2_Subsurface* ecoreSubVideoWindow, int screenWidth, int screenHeight)
265 mEcoreSubVideoWindow = ecoreSubVideoWindow;
266 mHalfScreenWidth = static_cast<float>(screenWidth) / 2;
267 mHalfScreenHeight = static_cast<float>(screenHeight) / 2;
270 void operator()(Vector3& current, const PropertyInputContainer& inputs)
272 const Vector3& size = inputs[0]->GetVector3();
273 const Vector3& worldScale = inputs[1]->GetVector3();
274 const Vector3& worldPosition = inputs[2]->GetVector3();
276 Vector3 actorSize = size * worldScale;
277 Vector2 screenPosition(mHalfScreenWidth + worldPosition.x, mHalfScreenHeight + worldPosition.y);
280 area.x = screenPosition.x - actorSize.x / 2;
281 area.y = screenPosition.y - actorSize.y / 2;
282 area.width = actorSize.x;
283 area.height = actorSize.y;
285 if(mEcoreSubVideoWindow)
287 ecore_wl2_subsurface_video_surface_destination_set(mEcoreSubVideoWindow, area.x, area.y, area.width, area.height);
292 Ecore_Wl2_Subsurface* mEcoreSubVideoWindow;
293 float mHalfScreenWidth;
294 float mHalfScreenHeight;
298 * @brief Whether set play positoin accurately or not.
299 * If true, we set play position to the nearest frame position. but this might be considerably slow, accurately.
300 * If false, we set play position to the nearest key frame position. this might be faster but less accurate.
301 * see player_set_play_position()
303 constexpr bool ACCURATE_PLAY_POSITION_SET = true;
305 } // unnamed namespace
307 TizenVideoPlayer::TizenVideoPlayer(Dali::Actor actor, Dali::VideoSyncMode syncMode)
310 mPlayerState(PLAYER_STATE_NONE),
313 mNativeImageSourcePtr(NULL),
315 mBackgroundColor(Dali::Vector4(1.0f, 1.0f, 1.0f, 0.0f)),
316 mTargetType(NATIVE_IMAGE),
320 mStreamType(SOUND_STREAM_TYPE_MEDIA),
321 mCodecType(PLAYER_VIDEO_CODEC_TYPE_EX_DEFAULT),
322 mEcoreWlWindow(nullptr),
323 mEcoreSubVideoWindow(nullptr),
325 mVideoSizePropertyIndex(Property::INVALID_INDEX),
327 mIsInitForSyncMode(false)
331 TizenVideoPlayer::~TizenVideoPlayer()
334 if(mEcoreSubVideoWindow)
336 ecore_wl2_subsurface_del(mEcoreSubVideoWindow);
337 mEcoreSubVideoWindow = nullptr;
343 void TizenVideoPlayer::GetPlayerState(player_state_e* state) const
345 if(mPlayer != NULL && player_get_state(mPlayer, state) != PLAYER_ERROR_NONE)
347 DALI_LOG_ERROR("player_get_state error: Invalid parameter\n");
348 *state = PLAYER_STATE_NONE;
352 void TizenVideoPlayer::SetUrl(const std::string& url)
357 int error = PLAYER_ERROR_NONE;
361 GetPlayerState(&mPlayerState);
363 if(mPlayerState != PLAYER_STATE_NONE && mPlayerState != PLAYER_STATE_IDLE)
365 if(mNativeImageSourcePtr)
367 error = player_unset_media_packet_video_frame_decoded_cb(mPlayer);
368 ret = LogPlayerError(error);
371 DALI_LOG_ERROR("SetUrl, player_unset_media_packet_video_frame_decoded_cb() is failed\n");
376 error = player_unprepare(mPlayer);
377 ret = LogPlayerError(error);
380 DALI_LOG_ERROR("SetUrl, player_unprepare() is failed\n");
383 if(mNativeImageSourcePtr)
385 error = player_set_media_packet_video_frame_decoded_cb(mPlayer, MediaPacketVideoDecodedCb, this);
386 ret = LogPlayerError(error);
389 DALI_LOG_ERROR("SetUrl, player_set_media_packet_video_frame_decoded_cb() is failed\n");
395 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
396 ecore_wl2_display_screen_size_get(wl2_display, &width, &height);
398 if(mSyncMode == Dali::VideoSyncMode::ENABLED)
400 if(mIsInitForSyncMode)
402 InitializeEnableSyncMode(mEcoreWlWindow);
406 if(!ecore_wl2_subsurface_video_surface_destination_set(mEcoreSubVideoWindow, 0, 0, width, height))
408 DALI_LOG_ERROR("SetUrl, ecore_wl2_subsurface_video_surface_destination_set() is failed\n");
414 error = player_set_ecore_wl_display(mPlayer, PLAYER_DISPLAY_TYPE_OVERLAY, mEcoreWlWindow, 0, 0, width, height);
415 ret = LogPlayerError(error);
418 DALI_LOG_ERROR("SetUrl, player_set_ecore_wl_display() is failed\n");
422 GetPlayerState(&mPlayerState);
423 ret = LogPlayerError(error);
426 DALI_LOG_ERROR("SetUrl, GetPlayerState() is failed\n");
430 if(mPlayerState == PLAYER_STATE_IDLE)
432 error = player_set_uri(mPlayer, mUrl.c_str());
433 ret = LogPlayerError(error);
436 DALI_LOG_ERROR("SetUrl, player_set_uri() is failed\n");
439 error = player_prepare(mPlayer);
440 ret = LogPlayerError(error);
443 DALI_LOG_ERROR("SetUrl, player_prepare() is failed\n");
449 std::string TizenVideoPlayer::GetUrl()
454 void TizenVideoPlayer::SetRenderingTarget(Any target)
458 mNativeImageSourcePtr = NULL;
460 if(target.GetType() == typeid(Dali::NativeImageSourcePtr))
462 if(mSyncMode == Dali::VideoSyncMode::ENABLED)
466 mTargetType = TizenVideoPlayer::NATIVE_IMAGE;
468 Dali::NativeImageSourcePtr nativeImageSourcePtr = AnyCast<Dali::NativeImageSourcePtr>(target);
470 InitializeTextureStreamMode(nativeImageSourcePtr);
472 else if(target.GetType() == typeid(Ecore_Wl2_Window*))
474 mTargetType = TizenVideoPlayer::WINDOW_SURFACE;
476 InitializeUnderlayMode(Dali::AnyCast<Ecore_Wl2_Window*>(target));
478 if(mSyncMode == Dali::VideoSyncMode::ENABLED)
485 DALI_LOG_ERROR("SetRenderingTarget, Video rendering target is unknown\n");
489 void TizenVideoPlayer::SetLooping(bool looping)
491 GetPlayerState(&mPlayerState);
493 if(mPlayerState != PLAYER_STATE_NONE)
495 int error = player_set_looping(mPlayer, looping);
496 int ret = LogPlayerError(error);
499 DALI_LOG_ERROR("SetLooping, player_set_looping() is failed\n");
504 bool TizenVideoPlayer::IsLooping()
506 GetPlayerState(&mPlayerState);
508 bool looping = false;
509 if(mPlayerState != PLAYER_STATE_NONE)
511 int error = player_is_looping(mPlayer, &looping);
512 int ret = LogPlayerError(error);
515 DALI_LOG_ERROR("IsLooping, player_is_looping() is failed\n");
522 void TizenVideoPlayer::Play()
524 GetPlayerState(&mPlayerState);
526 if(mPlayerState == PLAYER_STATE_READY || mPlayerState == PLAYER_STATE_PAUSED)
528 if(mNativeImageSourcePtr && mTimer)
533 int error = player_start(mPlayer);
534 int ret = LogPlayerError(error);
537 DALI_LOG_ERROR("Play, player_start() is failed\n");
542 void TizenVideoPlayer::Pause()
544 GetPlayerState(&mPlayerState);
546 if(mPlayerState == PLAYER_STATE_PLAYING)
548 int error = player_pause(mPlayer);
549 ret = LogPlayerError(error);
552 DALI_LOG_ERROR("Pause, player_pause() is failed\n");
555 if(mNativeImageSourcePtr && mTimer)
563 void TizenVideoPlayer::Stop()
565 GetPlayerState(&mPlayerState);
567 if(mPlayerState == PLAYER_STATE_PLAYING || mPlayerState == PLAYER_STATE_PAUSED)
569 int error = player_stop(mPlayer);
570 int ret = LogPlayerError(error);
573 DALI_LOG_ERROR("Stop, player_stop() is failed\n");
576 if(mNativeImageSourcePtr && mTimer)
584 void TizenVideoPlayer::SetMute(bool muted)
586 GetPlayerState(&mPlayerState);
588 if(mPlayerState == PLAYER_STATE_IDLE ||
589 mPlayerState == PLAYER_STATE_READY ||
590 mPlayerState == PLAYER_STATE_PLAYING ||
591 mPlayerState == PLAYER_STATE_PAUSED)
593 int error = player_set_mute(mPlayer, muted);
594 int ret = LogPlayerError(error);
597 DALI_LOG_ERROR("SetMute, player_set_mute() is failed\n");
602 bool TizenVideoPlayer::IsMuted()
604 GetPlayerState(&mPlayerState);
607 if(mPlayerState == PLAYER_STATE_IDLE ||
608 mPlayerState == PLAYER_STATE_READY ||
609 mPlayerState == PLAYER_STATE_PLAYING ||
610 mPlayerState == PLAYER_STATE_PAUSED)
612 int error = player_is_muted(mPlayer, &muted);
613 int ret = LogPlayerError(error);
616 DALI_LOG_ERROR("IsMuted, player_is_muted() is failed\n");
623 void TizenVideoPlayer::SetVolume(float left, float right)
625 GetPlayerState(&mPlayerState);
627 int error = player_set_volume(mPlayer, left, right);
628 int ret = LogPlayerError(error);
631 DALI_LOG_ERROR("SetVolume, player_set_volume() is failed\n");
635 void TizenVideoPlayer::GetVolume(float& left, float& right)
637 GetPlayerState(&mPlayerState);
639 int error = player_get_volume(mPlayer, &left, &right);
640 int ret = LogPlayerError(error);
643 DALI_LOG_ERROR("GetVolume, player_get_volume() is failed\n");
647 void TizenVideoPlayer::SetPlayPosition(int millisecond)
652 GetPlayerState(&mPlayerState);
654 if(mPlayerState == PLAYER_STATE_IDLE)
656 error = player_prepare(mPlayer);
657 ret = LogPlayerError(error);
660 DALI_LOG_ERROR("SetPlayPosition, player_prepare() is failed\n");
663 GetPlayerState(&mPlayerState); // Check the status again.
666 if(mPlayerState == PLAYER_STATE_READY ||
667 mPlayerState == PLAYER_STATE_PLAYING ||
668 mPlayerState == PLAYER_STATE_PAUSED)
670 error = player_set_play_position(mPlayer, millisecond, ACCURATE_PLAY_POSITION_SET, PlayerSeekCompletedCb, NULL);
671 ret = LogPlayerError(error);
674 DALI_LOG_ERROR("SetPlayPosition, player_set_play_position() is failed\n");
679 int TizenVideoPlayer::GetPlayPosition()
684 GetPlayerState(&mPlayerState);
686 if(mPlayerState == PLAYER_STATE_IDLE ||
687 mPlayerState == PLAYER_STATE_READY ||
688 mPlayerState == PLAYER_STATE_PLAYING ||
689 mPlayerState == PLAYER_STATE_PAUSED)
691 error = player_get_play_position(mPlayer, &millisecond);
692 int ret = LogPlayerError(error);
695 DALI_LOG_ERROR("GetPlayPosition, player_get_play_position() is failed\n");
702 void TizenVideoPlayer::SetDisplayRotation(Dali::VideoPlayerPlugin::DisplayRotation rotation)
704 if(mNativeImageSourcePtr)
706 DALI_LOG_ERROR("SetDisplayRotation is only for window rendering target.\n");
711 if(mPlayerState != PLAYER_STATE_NONE)
713 error = player_set_display_rotation(mPlayer, static_cast<player_display_rotation_e>(rotation));
714 int ret = LogPlayerError(error);
717 DALI_LOG_ERROR("SetDisplayRotation, player_set_display_rotation() is failed\n");
722 Dali::VideoPlayerPlugin::DisplayRotation TizenVideoPlayer::GetDisplayRotation()
724 if(mNativeImageSourcePtr)
726 DALI_LOG_ERROR("GetDisplayRotation is only for window rendering target.\n");
727 return Dali::VideoPlayerPlugin::ROTATION_NONE;
731 player_display_rotation_e rotation = PLAYER_DISPLAY_ROTATION_NONE;
732 if(mPlayerState != PLAYER_STATE_NONE)
734 error = player_get_display_rotation(mPlayer, &rotation);
735 int ret = LogPlayerError(error);
738 DALI_LOG_ERROR("GetDisplayRotation, player_get_display_rotation() is failed\n");
741 return static_cast<Dali::VideoPlayerPlugin::DisplayRotation>(rotation);
744 Dali::VideoPlayerPlugin::VideoPlayerSignalType& TizenVideoPlayer::FinishedSignal()
746 return mFinishedSignal;
749 void TizenVideoPlayer::InitializeTextureStreamMode(Dali::NativeImageSourcePtr nativeImageSourcePtr)
754 mNativeImageSourcePtr = nativeImageSourcePtr;
756 if(mPlayerState == PLAYER_STATE_NONE)
758 error = player_create(&mPlayer);
759 ret = LogPlayerError(error);
762 DALI_LOG_ERROR("InitializeTextureStreamMode, player_create() is failed\n");
766 GetPlayerState(&mPlayerState);
768 if(mPlayerState == PLAYER_STATE_IDLE)
770 error = player_set_completed_cb(mPlayer, EmitPlaybackFinishedSignal, this);
771 ret = LogPlayerError(error);
774 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_completed_cb() is failed\n");
777 error = player_set_media_packet_video_frame_decoded_cb(mPlayer, MediaPacketVideoDecodedCb, this);
778 ret = LogPlayerError(error);
781 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_media_packet_video_frame_decoded_cb() is failed\n");
784 error = sound_manager_create_stream_information(mStreamType, NULL, NULL, &mStreamInfo);
785 ret = LogPlayerError(error);
788 DALI_LOG_ERROR("InitializeTextureStreamMode, sound_manager_create_stream_information() is failed\n");
791 error = player_set_sound_stream_info(mPlayer, mStreamInfo);
792 ret = LogPlayerError(error);
795 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_sound_stream_info() is failed\n");
798 error = player_set_display_mode(mPlayer, PLAYER_DISPLAY_MODE_FULL_SCREEN);
799 ret = LogPlayerError(error);
802 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_display_mode() is failed\n");
805 error = player_set_display(mPlayer, PLAYER_DISPLAY_TYPE_NONE, NULL);
806 ret = LogPlayerError(error);
809 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_display() is failed\n");
812 error = player_set_video_codec_type_ex(mPlayer, mCodecType);
813 ret = LogPlayerError(error);
816 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_video_codec_type_ex() is failed\n");
818 error = player_set_display_visible(mPlayer, true);
819 ret = LogPlayerError(error);
822 DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_display_visible() is failed\n");
825 mTimer = Dali::Timer::New(TIMER_INTERVAL);
826 mTimer.TickSignal().Connect(this, &TizenVideoPlayer::Update);
830 void TizenVideoPlayer::InitializeEnableSyncMode(Ecore_Wl2_Window* ecoreWlWindow)
835 if(mEcoreWlWindow != ecoreWlWindow)
837 mEcoreWlWindow = ecoreWlWindow;
838 // check previous video subsurface and destroy
839 if(mEcoreSubVideoWindow)
841 ecore_wl2_subsurface_del(mEcoreSubVideoWindow);
844 // Crate ecore_wl2 sursurface
845 mEcoreSubVideoWindow = ecore_wl2_subsurface_new(mEcoreWlWindow);
846 if(!mEcoreSubVideoWindow)
848 DALI_LOG_ERROR("InitializeEnableSyncMode, ecore_wl2_subsurface_new() is failed\n");
852 // ecore_wl2_subsurface_video_surface_prepare
853 if(!ecore_wl2_subsurface_video_surface_prepare(mEcoreSubVideoWindow))
855 ecore_wl2_subsurface_del(mEcoreSubVideoWindow);
856 DALI_LOG_ERROR("InitializeEnableSyncMode, : ecore_wl2_subsurface_video_surface_prepare() is failed\n");
860 DALI_LOG_RELEASE_INFO("InitializeEnableSyncMode, desync VideoPlayer\n");
861 ecore_wl2_subsurface_sync_set(mEcoreSubVideoWindow, EINA_FALSE);
864 if(mPlayerState == PLAYER_STATE_NONE)
866 error = player_create(&mPlayer);
867 ret = LogPlayerError(error);
870 DALI_LOG_ERROR("InitializeEnableSyncMode, player_create() is failed\n");
874 GetPlayerState(&mPlayerState);
875 if(mPlayerState == PLAYER_STATE_IDLE)
877 error = player_set_completed_cb(mPlayer, EmitPlaybackFinishedSignal, this);
878 ret = LogPlayerError(error);
881 DALI_LOG_ERROR("InitializeEnableSyncMode, player_set_completed_cb() is failed\n");
884 error = sound_manager_create_stream_information(mStreamType, NULL, NULL, &mStreamInfo);
885 ret = LogPlayerError(error);
888 DALI_LOG_ERROR("InitializeEnableSyncMode, sound_manager_create_stream_information() is failed\n");
891 error = player_set_sound_stream_info(mPlayer, mStreamInfo);
892 ret = LogPlayerError(error);
895 DALI_LOG_ERROR("InitializeEnableSyncMode, player_set_sound_stream_info() is failed\n");
898 error = player_set_video_codec_type_ex(mPlayer, mCodecType);
899 ret = LogPlayerError(error);
902 DALI_LOG_ERROR("InitializeEnableSyncMode, player_set_video_codec_type_ex() is failed\n");
906 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
907 ecore_wl2_display_screen_size_get(wl2_display, &width, &height);
908 ecore_wl2_window_alpha_set(mEcoreWlWindow, false);
910 if(!ecore_wl2_subsurface_video_surface_destination_set(mEcoreSubVideoWindow, 0, 0, width, height))
912 DALI_LOG_ERROR("InitializeEnableSyncMode, ecore_wl2_subsurface_video_surface_destination_set() is failed\n");
914 error = player_set_display(mPlayer, PLAYER_DISPLAY_TYPE_OVERLAY, mEcoreWlWindow);
915 ret = LogPlayerError(error);
918 DALI_LOG_ERROR("InitializeEnableSyncMode, player_set_display() is failed\n");
921 mIsInitForSyncMode = true;
925 void TizenVideoPlayer::InitializeUnderlayMode(Ecore_Wl2_Window* ecoreWlWindow)
930 if(mSyncMode == Dali::VideoSyncMode::ENABLED)
932 DALI_LOG_RELEASE_INFO("InitializeUnderlayMode, \n");
933 InitializeEnableSyncMode(ecoreWlWindow);
937 mEcoreWlWindow = ecoreWlWindow;
939 if(mPlayerState == PLAYER_STATE_NONE)
941 error = player_create(&mPlayer);
942 ret = LogPlayerError(error);
945 DALI_LOG_ERROR("InitializeUnderlayMode, player_create() is failed\n");
949 GetPlayerState(&mPlayerState);
950 if(mPlayerState == PLAYER_STATE_IDLE)
952 error = player_set_completed_cb(mPlayer, EmitPlaybackFinishedSignal, this);
953 ret = LogPlayerError(error);
956 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_completed_cb() is failed\n");
959 error = sound_manager_create_stream_information(mStreamType, NULL, NULL, &mStreamInfo);
960 ret = LogPlayerError(error);
963 DALI_LOG_ERROR("InitializeUnderlayMode, sound_manager_create_stream_information() is failed\n");
966 error = player_set_sound_stream_info(mPlayer, mStreamInfo);
967 ret = LogPlayerError(error);
970 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_sound_stream_info() is failed\n");
973 error = player_set_video_codec_type_ex(mPlayer, mCodecType);
974 ret = LogPlayerError(error);
977 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_video_codec_type_ex() is failed\n");
981 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
982 ecore_wl2_display_screen_size_get(wl2_display, &width, &height);
983 ecore_wl2_window_alpha_set(mEcoreWlWindow, false);
985 error = player_set_display_mode(mPlayer, PLAYER_DISPLAY_MODE_DST_ROI);
986 ret = LogPlayerError(error);
989 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_display_mode() is failed\n");
992 error = player_set_display_roi_area(mPlayer, 0, 0, 1, 1);
993 ret = LogPlayerError(error);
996 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_display_roi_area() is failed\n");
999 error = player_set_ecore_wl_display(mPlayer, PLAYER_DISPLAY_TYPE_OVERLAY, mEcoreWlWindow, 0, 0, width, height);
1000 ret = LogPlayerError(error);
1003 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_ecore_wl_display() is failed\n");
1006 error = player_set_display_visible(mPlayer, true);
1007 ret = LogPlayerError(error);
1010 DALI_LOG_ERROR("InitializeUnderlayMode, player_set_display_visible() is failed\n");
1015 bool TizenVideoPlayer::Update()
1017 Dali::Mutex::ScopedLock lock(mPacketMutex);
1023 error = media_packet_destroy(mPacket);
1024 if(error != MEDIA_PACKET_ERROR_NONE)
1026 DALI_LOG_ERROR("Update, media_packet_destroy() is failed\n");
1031 if(!mPacketList.empty())
1033 mPacket = static_cast< media_packet_h >( mPacketList.front() );
1034 mPacketList.pop_front();
1042 error = media_packet_get_tbm_surface(mPacket, &mTbmSurface);
1043 if(error != MEDIA_PACKET_ERROR_NONE)
1045 media_packet_destroy(mPacket);
1047 DALI_LOG_ERROR(" error: %d\n", error);
1051 Any source(mTbmSurface);
1052 mNativeImageSourcePtr->SetSource(source);
1053 Dali::Stage::GetCurrent().KeepRendering(0.0f);
1058 void TizenVideoPlayer::DestroyPackets()
1063 error = media_packet_destroy(mPacket);
1064 DALI_LOG_ERROR("Media packet destroy error: %d\n", error);
1068 std::list<media_packet_h>::iterator iter = mPacketList.begin();
1069 for (; iter != mPacketList.end(); ++iter)
1072 error = media_packet_destroy( mPacket );
1073 DALI_LOG_ERROR( "Media packet destroy error: %d\n", error );
1076 mPacketList.clear();
1079 void TizenVideoPlayer::PushPacket(media_packet_h packet)
1081 Dali::Mutex::ScopedLock lock(mPacketMutex);
1082 mPacketList.push_back(packet);
1085 void TizenVideoPlayer::SetDisplayArea(DisplayArea area)
1088 GetPlayerState(&mPlayerState);
1090 if(mNativeImageSourcePtr)
1092 DALI_LOG_ERROR("SetDisplayArea is only for window surface target.\n");
1096 if(mPlayerState == PLAYER_STATE_IDLE ||
1097 mPlayerState == PLAYER_STATE_READY ||
1098 mPlayerState == PLAYER_STATE_PLAYING ||
1099 mPlayerState == PLAYER_STATE_PAUSED)
1101 area.x = (area.x < 0) ? 0 : area.x;
1102 area.y = (area.y < 0) ? 0 : area.y;
1103 if(mSyncMode == Dali::VideoSyncMode::ENABLED)
1105 if(!ecore_wl2_subsurface_video_surface_destination_set(mEcoreSubVideoWindow, area.x, area.y, area.width, area.height))
1107 DALI_LOG_ERROR("SetDisplayArea, ecore_wl2_subsurface_video_surface_destination_set() is failed\n");
1112 int error = player_set_display_roi_area(mPlayer, area.x, area.y, area.width, area.height);
1113 ret = LogPlayerError(error);
1116 DALI_LOG_ERROR("SetDisplayArea, player_set_display_roi_area() is failed\n");
1122 void TizenVideoPlayer::Forward(int millisecond)
1127 GetPlayerState(&mPlayerState);
1129 if(mPlayerState == PLAYER_STATE_READY ||
1130 mPlayerState == PLAYER_STATE_PLAYING ||
1131 mPlayerState == PLAYER_STATE_PAUSED)
1133 int currentPosition = 0;
1134 int nextPosition = 0;
1136 error = player_get_play_position(mPlayer, ¤tPosition);
1137 ret = LogPlayerError(error);
1140 DALI_LOG_ERROR("Forward, player_get_play_position() is failed\n");
1143 nextPosition = currentPosition + millisecond;
1145 error = player_set_play_position(mPlayer, nextPosition, ACCURATE_PLAY_POSITION_SET, PlayerSeekCompletedCb, NULL);
1146 ret = LogPlayerError(error);
1149 DALI_LOG_ERROR("Forward, player_set_play_position() is failed\n");
1154 void TizenVideoPlayer::Backward(int millisecond)
1159 GetPlayerState(&mPlayerState);
1161 if(mPlayerState == PLAYER_STATE_READY ||
1162 mPlayerState == PLAYER_STATE_PLAYING ||
1163 mPlayerState == PLAYER_STATE_PAUSED)
1165 int currentPosition = 0;
1166 int nextPosition = 0;
1168 error = player_get_play_position(mPlayer, ¤tPosition);
1169 ret = LogPlayerError(error);
1172 DALI_LOG_ERROR("Backward, player_get_play_position() is failed\n");
1175 nextPosition = currentPosition - millisecond;
1176 nextPosition = (nextPosition < 0) ? 0 : nextPosition;
1178 error = player_set_play_position(mPlayer, nextPosition, ACCURATE_PLAY_POSITION_SET, PlayerSeekCompletedCb, NULL);
1179 ret = LogPlayerError(error);
1182 DALI_LOG_ERROR("Backward, player_set_play_position() is failed\n");
1187 bool TizenVideoPlayer::IsVideoTextureSupported()
1189 bool featureFlag = true;
1190 int error = SYSTEM_INFO_ERROR_NONE;
1192 error = system_info_get_platform_bool("tizen.org/feature/multimedia.raw_video", &featureFlag);
1194 if(error != SYSTEM_INFO_ERROR_NONE)
1196 DALI_LOG_ERROR("Plugin can't check platform feature\n");
1203 void TizenVideoPlayer::DestroyPlayer()
1209 if(mPlayerState != PLAYER_STATE_NONE)
1211 GetPlayerState(&mPlayerState);
1213 if(mPlayerState != PLAYER_STATE_IDLE)
1216 error = player_unprepare(mPlayer);
1217 ret = LogPlayerError(error);
1220 DALI_LOG_ERROR("DestroyPlayer, player_unprepare() is failed\n");
1224 error = player_destroy(mPlayer);
1225 ret = LogPlayerError(error);
1228 DALI_LOG_ERROR("DestroyPlayer, player_destroy() is failed\n");
1231 error = sound_manager_destroy_stream_information(mStreamInfo);
1232 ret = LogPlayerError(error);
1235 DALI_LOG_ERROR("DestroyPlayer, sound_manager_destroy_stream_information() is failed\n");
1238 mPlayerState = PLAYER_STATE_NONE;
1243 void TizenVideoPlayer::SetCodecType(Dali::VideoPlayerPlugin::CodecType type)
1249 case Dali::VideoPlayerPlugin::CodecType::DEFAULT:
1251 mCodecType = PLAYER_VIDEO_CODEC_TYPE_EX_DEFAULT;
1254 case Dali::VideoPlayerPlugin::CodecType::HW:
1256 mCodecType = PLAYER_VIDEO_CODEC_TYPE_EX_HW;
1259 case Dali::VideoPlayerPlugin::CodecType::SW:
1261 mCodecType = PLAYER_VIDEO_CODEC_TYPE_EX_SW;
1266 if(mPlayerState != PLAYER_STATE_NONE)
1268 GetPlayerState(&mPlayerState);
1270 if(mPlayerState == PLAYER_STATE_IDLE)
1272 error = player_set_video_codec_type_ex(mPlayer, mCodecType);
1273 ret = LogPlayerError(error);
1276 DALI_LOG_ERROR("SetCodecType, player_set_video_codec_type_ex() is failed\n");
1282 Dali::VideoPlayerPlugin::CodecType TizenVideoPlayer::GetCodecType() const
1284 Dali::VideoPlayerPlugin::CodecType type = Dali::VideoPlayerPlugin::CodecType::DEFAULT;
1286 if(mPlayerState != PLAYER_STATE_NONE)
1288 player_video_codec_type_ex_e codecType = PLAYER_VIDEO_CODEC_TYPE_EX_DEFAULT;
1289 int error = player_get_video_codec_type_ex(mPlayer, &codecType);
1290 if(error != PLAYER_ERROR_NONE)
1292 ret = LogPlayerError(error);
1295 DALI_LOG_ERROR("GetCodecType, player_get_video_codec_type_ex() is failed\n");
1302 case PLAYER_VIDEO_CODEC_TYPE_EX_DEFAULT:
1304 type = Dali::VideoPlayerPlugin::CodecType::DEFAULT;
1307 case PLAYER_VIDEO_CODEC_TYPE_EX_HW:
1309 type = Dali::VideoPlayerPlugin::CodecType::HW;
1312 case PLAYER_VIDEO_CODEC_TYPE_EX_SW:
1314 type = Dali::VideoPlayerPlugin::CodecType::SW;
1322 void TizenVideoPlayer::SetDisplayMode(Dali::VideoPlayerPlugin::DisplayMode::Type mode)
1325 error = player_set_display_mode(mPlayer, static_cast<player_display_mode_e>(mode));
1326 int ret = LogPlayerError(error);
1329 DALI_LOG_ERROR("SetDisplayMode, player_set_display_mode() is failed\n");
1333 Dali::VideoPlayerPlugin::DisplayMode::Type TizenVideoPlayer::GetDisplayMode() const
1335 player_display_mode_e mode;
1336 player_get_display_mode(mPlayer, &mode);
1337 return static_cast<Dali::VideoPlayerPlugin::DisplayMode::Type>(mode);
1340 Any TizenVideoPlayer::GetMediaPlayer()
1342 return Any((void*)mPlayer);
1345 void TizenVideoPlayer::StartSynchronization()
1347 DALI_LOG_RELEASE_INFO("sync VideoPlayer\n");
1348 ecore_wl2_subsurface_sync_set(mEcoreSubVideoWindow, EINA_TRUE);
1351 void TizenVideoPlayer::FinishSynchronization()
1354 DALI_LOG_RELEASE_INFO("desync VideoPlayer\n");
1355 ecore_wl2_subsurface_sync_set(mEcoreSubVideoWindow, EINA_FALSE);
1358 void TizenVideoPlayer::CreateConstraint()
1360 if(mVideoSizePropertyIndex == Property::INVALID_INDEX)
1362 if(mVideoSizePropertyConstraint)
1364 mVideoSizePropertyConstraint.Remove();
1367 Actor syncActor = mSyncActor.GetHandle();
1370 mVideoSizePropertyIndex = syncActor.RegisterProperty(VIDEO_PLAYER_SIZE_NAME, Vector3::ZERO);
1373 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
1374 ecore_wl2_display_screen_size_get(wl2_display, &width, &height);
1376 mVideoSizePropertyConstraint = Constraint::New<Vector3>(syncActor,
1377 mVideoSizePropertyIndex,
1378 VideoPlayerSyncConstraint(mEcoreSubVideoWindow, width, height));
1380 mVideoSizePropertyConstraint.AddSource(LocalSource(Actor::Property::SIZE));
1381 mVideoSizePropertyConstraint.AddSource(LocalSource(Actor::Property::WORLD_SCALE));
1382 mVideoSizePropertyConstraint.AddSource(LocalSource(Actor::Property::WORLD_POSITION));
1384 mVideoSizePropertyConstraint.Apply();
1389 void TizenVideoPlayer::DestroyConstraint()
1391 if(mVideoSizePropertyIndex != Property::INVALID_INDEX)
1393 mVideoSizePropertyConstraint.Remove();
1394 mVideoSizePropertyIndex = Property::INVALID_INDEX;
1398 void TizenVideoPlayer::RaiseAbove(Any videoSurface)
1400 Ecore_Wl2_Subsurface* surface = AnyCast<Ecore_Wl2_Subsurface*>(videoSurface);
1401 ecore_wl2_subsurface_place_surface_above(mEcoreSubVideoWindow, surface);
1404 void TizenVideoPlayer::LowerBelow(Any videoSurface)
1406 Ecore_Wl2_Subsurface* surface = AnyCast<Ecore_Wl2_Subsurface*>(videoSurface);
1407 ecore_wl2_subsurface_place_surface_below(mEcoreSubVideoWindow, surface);
1410 void TizenVideoPlayer::RaiseToTop()
1412 ecore_wl2_subsurface_place_surface_above(mEcoreSubVideoWindow, NULL);
1415 void TizenVideoPlayer::LowerToBottom()
1417 ecore_wl2_subsurface_place_surface_below(mEcoreSubVideoWindow, NULL);
1420 Any TizenVideoPlayer::GetVideoPlayerSurface()
1422 return mEcoreSubVideoWindow;
1425 } // namespace Plugin