(VideoView) Keep Rotaion + Ratio constraint as fuctor + minor fix 15/318715/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 22 Jan 2025 12:46:29 +0000 (21:46 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 22 Jan 2025 12:55:46 +0000 (21:55 +0900)
Since we use constraint function as struct, The lifecycle of
fuctor struct be broken.

To avoid those kind of issue, let we keep helper as global map,
and static constraint functor can access their.

To specify the helper, let we register id to syncActor.

Change-Id: I3e026c6926f147b67c04c75d66ac74b59bc839a4
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-extension/video-player/ecore-wl2/tizen-video-player-ecore-wl2.cpp
dali-extension/video-player/ecore-wl2/tizen-video-player.h

index 3646ced734fad8138a92ae3377ae48c259157734..f5850757cfa48049b1621e74c16e6a4f650bea6c 100644 (file)
@@ -27,6 +27,9 @@
 #include <dali/integration-api/debug.h>
 #include <system_info.h>
 
+#include <mutex>
+#include <unordered_map>
+
 #ifdef OVER_TIZEN_VERSION_9
 #include <wayland-egl-tizen.h>
 #endif
@@ -342,46 +345,65 @@ private:
 };
 #endif
 
-struct VideoPlayerRotationConstraint
+// Global map to store and get constraint helper from multiple thread safely.
+static std::mutex gHelperMutex;
+static int32_t    gHelperId = 0;
+
+static std::unordered_map<int32_t, IntrusivePtr<VideoConstraintHelper>> gHelperMap;
+
+void AddConstraintHelper(int32_t helperId, IntrusivePtr<VideoConstraintHelper> helper)
 {
-public:
-  VideoPlayerRotationConstraint(Dali::IntrusivePtr<VideoConstraintHelper> handler)
-  : mVideoHandler(handler)
-  {
-  }
+  std::scoped_lock lock(gHelperMutex);
+  DALI_LOG_DEBUG_INFO("Add helper for id[%d], helper[%p]\n", helperId, helper.Get());
+  gHelperMap.insert({helperId, helper});
+}
+void RemoveConstraintHelper(int32_t helperId)
+{
+  std::scoped_lock lock(gHelperMutex);
+  DALI_LOG_DEBUG_INFO("Remove helper for id[%d]\n", helperId);
+  gHelperMap.erase(helperId);
+}
 
-  void operator()(Dali::Vector4& current, const Dali::PropertyInputContainer& /* unused */)
+void VideoPlayerRotationConstraint(Dali::Vector4& current, const Dali::PropertyInputContainer& inputs)
+{
+  IntrusivePtr<VideoConstraintHelper> mVideoHandler;
   {
-    if(DALI_LIKELY(mVideoHandler))
+    std::scoped_lock lock(gHelperMutex);
+
+    int32_t helperId = inputs[0]->GetInteger();
+
+    auto iter = gHelperMap.find(helperId);
+    if(iter != gHelperMap.end())
     {
-      current = mVideoHandler->GetOrientationMatrix();
-      mVideoHandler->UpdateVideo();
+      mVideoHandler = iter->second;
     }
   }
-
-private:
-  Dali::IntrusivePtr<VideoConstraintHelper> mVideoHandler;
-};
-
-struct VideoPlayerRatioConstraint
-{
-public:
-  VideoPlayerRatioConstraint(Dali::IntrusivePtr<VideoConstraintHelper> handler)
-  : mVideoHandler(handler)
+  if(DALI_LIKELY(mVideoHandler))
   {
+    current = mVideoHandler->GetOrientationMatrix();
+    mVideoHandler->UpdateVideo();
   }
+}
 
-  void operator()(Dali::Vector2& current, const Dali::PropertyInputContainer& /* unused */)
+void VideoPlayerRatioConstraint(Dali::Vector2& current, const Dali::PropertyInputContainer& inputs)
+{
+  IntrusivePtr<VideoConstraintHelper> mVideoHandler;
   {
-    if(DALI_LIKELY(mVideoHandler))
+    std::scoped_lock lock(gHelperMutex);
+
+    int32_t helperId = inputs[0]->GetInteger();
+
+    auto iter = gHelperMap.find(helperId);
+    if(iter != gHelperMap.end())
     {
-      current = mVideoHandler->RetriveSize();
+      mVideoHandler = iter->second;
     }
   }
-
-private:
-  Dali::IntrusivePtr<VideoConstraintHelper> mVideoHandler;
-};
+  if(DALI_LIKELY(mVideoHandler))
+  {
+    current = mVideoHandler->RetriveSize();
+  }
+}
 
 /**
  * @brief Whether set play positoin accurately or not.
@@ -1053,6 +1075,7 @@ void TizenVideoPlayer::Update()
   }
   tbm_surface_h tbmSurface = NULL;
   error                    = media_packet_get_tbm_surface(mPacket, &tbmSurface);
+
   if(error != MEDIA_PACKET_ERROR_NONE)
   {
     media_packet_destroy(mPacket);
@@ -1266,6 +1289,16 @@ void TizenVideoPlayer::DestroyPlayer()
 
     if(mPlayerState != PLAYER_STATE_IDLE)
     {
+      if(mNativeImageSourcePtr)
+      {
+        error = player_unset_media_packet_video_frame_decoded_cb(mPlayer);
+        ret   = LogPlayerError(error);
+        if(ret)
+        {
+          DALI_LOG_ERROR("DestroyPlayer, player_unset_media_packet_video_frame_decoded_cb() is failed\n");
+        }
+      }
+
       Stop();
       error = player_unprepare(mPlayer);
       ret   = LogPlayerError(error);
@@ -1553,11 +1586,24 @@ void TizenVideoPlayer::CreateVideoConstraint(Dali::NativeImageSourcePtr nativeIm
     mVideoRotationPropertyIndex = syncActor.RegisterProperty("uRotationMatrix", Property::Value(Vector4(1.0f, 0.0f, 0.0f, 1.0f)));
     mVideoRatioPropertyIndex    = syncActor.RegisterProperty("uSizeRatio", Property::Value(Vector2(0.0f, 0.0f)));
 
-    mVideoConstraintHelper   = VideoConstraintHelper::New(nativeImageSourcePtr);
-    mVideoRotationConstraint = Constraint::New<Vector4>(syncActor, mVideoRotationPropertyIndex, VideoPlayerRotationConstraint(mVideoConstraintHelper));
+    if(mVideoConstraintHelper)
+    {
+      RemoveConstraintHelper(mVideoConstraintHelperId);
+    }
+
+    mVideoConstraintHelperId = gHelperId++;
+    auto idIndex             = syncActor.RegisterProperty("helperId", Property::Value(mVideoConstraintHelperId));
+
+    mVideoConstraintHelper = VideoConstraintHelper::New(nativeImageSourcePtr);
+
+    AddConstraintHelper(mVideoConstraintHelperId, mVideoConstraintHelper);
+
+    mVideoRotationConstraint = Constraint::New<Vector4>(syncActor, mVideoRotationPropertyIndex, VideoPlayerRotationConstraint);
+    mVideoRotationConstraint.AddSource(LocalSource(idIndex));
     mVideoRotationConstraint.Apply();
 
-    mVideoLetterBoxConstraint = Constraint::New<Vector2>(syncActor, mVideoRatioPropertyIndex, VideoPlayerRatioConstraint(mVideoConstraintHelper));
+    mVideoLetterBoxConstraint = Constraint::New<Vector2>(syncActor, mVideoRatioPropertyIndex, VideoPlayerRatioConstraint);
+    mVideoLetterBoxConstraint.AddSource(LocalSource(idIndex));
     mVideoLetterBoxConstraint.Apply();
   }
 }
@@ -1575,6 +1621,12 @@ void TizenVideoPlayer::DestroyVideoConstraint()
     mVideoLetterBoxConstraint.Remove();
     mVideoRatioPropertyIndex = Property::INVALID_INDEX;
   }
+
+  if(mVideoConstraintHelper)
+  {
+    RemoveConstraintHelper(mVideoConstraintHelperId);
+    mVideoConstraintHelper.Reset();
+  }
 }
 
 void TizenVideoPlayer::SetAutoRotationEnabled(bool enable)
index e5f09cb63e89afec4540a694631d59ed68ecc2bb..cdf26d36671f8836236549e228aed6d233e7ec8b 100644 (file)
@@ -355,6 +355,8 @@ private:
   Property::Index               mVideoRatioPropertyIndex;
   Dali::VideoSyncMode           mSyncMode;
 
+  int32_t mVideoConstraintHelperId; ///< unique id for Rotation and Ratio constraint helper
+
   bool mIsMovedHandle; ///< the flag for moved the handle
   bool mIsSceneConnected;