(VideoPlayer) Increase tbm_surface_h refcount what we hold + minor fix 70/318670/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 22 Jan 2025 03:12:05 +0000 (12:12 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 22 Jan 2025 03:16:49 +0000 (12:16 +0900)
Since we only got tbm_surface_h from packet and don't do anything,
the reference of tbm might not valid when we want to really use it.

To avoid this case, let's keep the reference count of tbm_surface_h
at SetInfo.

Note that SetSource will increase and decrease refcount automatically.
We don't need to worry after SetSource

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

index c539e6877c10657744552dff8e007c7835801839..304d0e8dcd484e1b61f0d3bdc3cbc297314f3e38 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // CLASS HEADER
 #include "tizen-video-constraint-helper.h"
 
+// EXTERNAL INCLUDES
+#include <tbm_surface_internal.h>
+
 namespace Dali
 {
 namespace Plugin
 {
-
 VideoConstraintHelperPtr VideoConstraintHelper::New(Dali::NativeImageSourcePtr nativeImageSourcePtr)
 {
   VideoConstraintHelperPtr ptr = new VideoConstraintHelper(nativeImageSourcePtr);
@@ -39,7 +41,6 @@ VideoConstraintHelper::VideoConstraintHelper(Dali::NativeImageSourcePtr nativeIm
   mIsAutoRotationEnabled(false),
   mIsLetterBoxEnabled(false)
 {
-
 }
 
 VideoConstraintHelper::~VideoConstraintHelper()
@@ -50,12 +51,23 @@ void VideoConstraintHelper::SetInfo(tbm_surface_h surface, int orientation, int
 {
   Dali::Mutex::ScopedLock lock(mConstraintMutex);
   mIsSetInfo = true;
+  if(mSurface != NULL)
+  {
+    tbm_surface_internal_unref(mSurface);
+  }
+
   mSurface = surface;
+
+  if(mSurface != NULL)
+  {
+    tbm_surface_internal_ref(mSurface);
+  }
+
   // Orientation should be set to zero when auto rotation is disabled.
   mOrientation = mIsAutoRotationEnabled ? orientation : 0;
-  if (mIsLetterBoxEnabled)
+  if(mIsLetterBoxEnabled)
   {
-    mWidth = width;
+    mWidth  = width;
     mHeight = height;
   }
 }
@@ -67,6 +79,11 @@ void VideoConstraintHelper::UpdateVideo()
     if(mIsSetInfo && mNativeImageSourcePtr)
     {
       mNativeImageSourcePtr->SetSource(mSurface);
+      if(mSurface != NULL)
+      {
+        tbm_surface_internal_unref(mSurface);
+      }
+      mSurface   = NULL;
       mIsSetInfo = false;
     }
   }
@@ -75,18 +92,28 @@ void VideoConstraintHelper::UpdateVideo()
 Dali::Vector4 VideoConstraintHelper::GetOrientationMatrix()
 {
   Dali::Mutex::ScopedLock lock(mConstraintMutex);
-  switch (mOrientation)
+  switch(mOrientation)
   {
     case 0:
+    {
       return Dali::Vector4(1.0f, 0.0f, 0.0f, 1.0f);
+    }
     case 90:
+    {
       return Dali::Vector4(0.0f, -1.0f, 1.0f, 0.0f);
+    }
     case 180:
+    {
       return Dali::Vector4(-1.0f, 0.0f, 0.0f, -1.0f);
+    }
     case 270:
+    {
       return Dali::Vector4(0.0f, 1.0f, -1.0f, 0.0f);
+    }
     default:
+    {
       return Dali::Vector4(1.0f, 0.0f, 0.0f, 1.0f);
+    }
   }
 }
 
@@ -107,7 +134,7 @@ void VideoConstraintHelper::SetAutoRotationEnabled(bool enable)
 {
   Dali::Mutex::ScopedLock lock(mConstraintMutex);
   mIsAutoRotationEnabled = enable;
-  if (!mIsAutoRotationEnabled)
+  if(!mIsAutoRotationEnabled)
   {
     mOrientation = 0;
   }
@@ -122,9 +149,9 @@ void VideoConstraintHelper::SetLetterBoxEnabled(bool enable)
 {
   Dali::Mutex::ScopedLock lock(mConstraintMutex);
   mIsLetterBoxEnabled = enable;
-  if (!mIsLetterBoxEnabled)
+  if(!mIsLetterBoxEnabled)
   {
-    mWidth = 0;
+    mWidth  = 0;
     mHeight = 0;
   }
 }
@@ -134,5 +161,5 @@ bool VideoConstraintHelper::IsLetterBoxEnabled() const
   return mIsLetterBoxEnabled;
 }
 
-}
-}
+} // namespace Plugin
+} // namespace Dali
index 72e837919385024685ab6e306172278451103cb6..a28d9fd438a1bf8d274c2a05b246593bafa4c925 100644 (file)
@@ -1,9 +1,8 @@
 #ifndef __DALI_TIZEN_VIDEO_CONSTRAINT_HELPER_H__
 #define __DALI_TIZEN_VIDEO_CONSTRAINT_HELPER_H__
 
-
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // INTERNAL INCLUDES
 
-
 // EXTERNAL INCLUDES
-#include <dali/public-api/object/ref-object.h>
 #include <dali/devel-api/threading/mutex.h>
-#include <tbm_surface.h>
-#include <dali/public-api/common/intrusive-ptr.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali/public-api/common/intrusive-ptr.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector4.h>
-
+#include <dali/public-api/object/ref-object.h>
+#include <tbm_surface.h>
 
 namespace Dali
 {
 namespace Plugin
 {
-
 class VideoConstraintHelper;
 typedef Dali::IntrusivePtr<VideoConstraintHelper> VideoConstraintHelperPtr;
 
-class VideoConstraintHelper: public Dali::RefObject
+class VideoConstraintHelper : public Dali::RefObject
 {
 public:
-
   /**
    * @brief Creates a new instance of VideoConstraintHelper
    * @param[in] nativeImageSourcePtr Native image source pointer
@@ -108,14 +103,17 @@ private:
 
 private:
   Dali::NativeImageSourcePtr mNativeImageSourcePtr;
-  Dali::Mutex mConstraintMutex;
+
+  Dali::Mutex   mConstraintMutex;
   tbm_surface_h mSurface;
+
   int mOrientation;
   int mWidth;
   int mHeight;
-  bool mIsSetInfo : 1;
-  bool mIsAutoRotationEnabled : 1;
-  bool mIsLetterBoxEnabled : 1;
+
+  bool mIsSetInfo;
+  bool mIsAutoRotationEnabled;
+  bool mIsLetterBoxEnabled;
 };
 
 } // namespace Plugin
index 7b853f087ad6ba03a09d2d55e32d286549fbb379..3646ced734fad8138a92ae3377ae48c259157734 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -344,17 +344,15 @@ private:
 
 struct VideoPlayerRotationConstraint
 {
-  public:
+public:
   VideoPlayerRotationConstraint(Dali::IntrusivePtr<VideoConstraintHelper> handler)
-    : mVideoHandler(handler)
+  : mVideoHandler(handler)
   {
   }
 
-  void operator()(Dali::Vector4& current, const Dali::PropertyInputContainer& inputs)
+  void operator()(Dali::Vector4& current, const Dali::PropertyInputContainer& /* unused */)
   {
-    if(inputs.Size() > 0) { // to avoid build warning
-    }
-    if (mVideoHandler)
+    if(DALI_LIKELY(mVideoHandler))
     {
       current = mVideoHandler->GetOrientationMatrix();
       mVideoHandler->UpdateVideo();
@@ -367,17 +365,15 @@ private:
 
 struct VideoPlayerRatioConstraint
 {
-  public:
+public:
   VideoPlayerRatioConstraint(Dali::IntrusivePtr<VideoConstraintHelper> handler)
-    : mVideoHandler(handler)
+  : mVideoHandler(handler)
   {
   }
 
-  void operator()(Dali::Vector2& current, const Dali::PropertyInputContainer& inputs)
+  void operator()(Dali::Vector2& current, const Dali::PropertyInputContainer& /* unused */)
   {
-    if(inputs.Size() > 0) { // to avoid build warning
-    }
-    if (mVideoHandler)
+    if(DALI_LIKELY(mVideoHandler))
     {
       current = mVideoHandler->RetriveSize();
     }
@@ -401,7 +397,6 @@ TizenVideoPlayer::TizenVideoPlayer(Dali::Actor actor, Dali::VideoSyncMode syncMo
 : mUrl(),
   mPlayer(NULL),
   mPlayerState(PLAYER_STATE_NONE),
-  mTbmSurface(NULL),
   mPacket(NULL),
   mNativeImageSourcePtr(NULL),
   mBackgroundColor(Dali::Vector4(1.0f, 1.0f, 1.0f, 0.0f)),
@@ -565,6 +560,7 @@ void TizenVideoPlayer::SetRenderingTarget(Any target)
 
     Dali::NativeImageSourcePtr nativeImageSourcePtr = AnyCast<Dali::NativeImageSourcePtr>(target);
 
+    DALI_LOG_RELEASE_INFO("target is not underlay mode\n");
     InitializeTextureStreamMode(nativeImageSourcePtr);
 
     CreateVideoConstraint(nativeImageSourcePtr);
@@ -911,7 +907,6 @@ void TizenVideoPlayer::InitializeTextureStreamMode(Dali::NativeImageSourcePtr na
     {
       DALI_LOG_ERROR("InitializeTextureStreamMode, player_set_display_visible() is failed\n");
     }
-
   }
 }
 
@@ -1056,8 +1051,8 @@ void TizenVideoPlayer::Update()
   {
     return;
   }
-
-  error = media_packet_get_tbm_surface(mPacket, &mTbmSurface);
+  tbm_surface_h tbmSurface = NULL;
+  error                    = media_packet_get_tbm_surface(mPacket, &tbmSurface);
   if(error != MEDIA_PACKET_ERROR_NONE)
   {
     media_packet_destroy(mPacket);
@@ -1066,37 +1061,48 @@ void TizenVideoPlayer::Update()
     return;
   }
 
-  media_packet_rotate_method_e org_orient;
-  media_packet_get_rotate_method(mPacket, &org_orient);
+  media_packet_rotate_method_e orginalOrientation;
+  media_packet_get_rotate_method(mPacket, &orginalOrientation);
   int orientation = 0;
 
-  switch (org_orient) {
+  switch(orginalOrientation)
+  {
     case MEDIA_PACKET_ROTATE_IDENTITY: //0
+    {
       orientation = 0;
       break;
+    }
     case MEDIA_PACKET_ROTATE_90: //1
+    {
       orientation = 270;
       break;
+    }
     case MEDIA_PACKET_ROTATE_180: //2
+    {
       orientation = 180;
       break;
+    }
     case MEDIA_PACKET_ROTATE_270: //3
+    {
       orientation = 90;
       break;
+    }
     default:
-      DALI_LOG_ERROR("wrong angle type : %d", org_orient);
+    {
+      DALI_LOG_ERROR("wrong angle type : %d", orginalOrientation);
       break;
+    }
   }
 
   media_format_h format;
-  int width, height;
-  if (media_packet_get_format(mPacket, &format) != MEDIA_PACKET_ERROR_NONE)
+  int            width, height;
+  if(media_packet_get_format(mPacket, &format) != MEDIA_PACKET_ERROR_NONE)
   {
     DALI_LOG_ERROR("failed to media_packet_get_format\n");
     return;
   }
 
-  if (media_format_get_video_info(format, NULL, &width, &height, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE)
+  if(media_format_get_video_info(format, NULL, &width, &height, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE)
   {
     DALI_LOG_ERROR("failed to media_format_get_video_info\n");
     media_format_unref(format);
@@ -1105,7 +1111,7 @@ void TizenVideoPlayer::Update()
 
   media_format_unref(format);
 
-  mVideoConstraintHelper->SetInfo(mTbmSurface, orientation, width, height);
+  mVideoConstraintHelper->SetInfo(tbmSurface, orientation, width, height);
 }
 
 void TizenVideoPlayer::DestroyPackets()
@@ -1277,15 +1283,19 @@ void TizenVideoPlayer::DestroyPlayer()
     }
   }
 
-  error = sound_manager_destroy_stream_information(mStreamInfo);
-  ret   = LogPlayerError(error);
-  if(ret)
+  if(mStreamInfo != NULL)
   {
-    DALI_LOG_ERROR("DestroyPlayer, sound_manager_destroy_stream_information() is failed\n");
+    error = sound_manager_destroy_stream_information(mStreamInfo);
+    ret   = LogPlayerError(error);
+    if(ret)
+    {
+      DALI_LOG_ERROR("DestroyPlayer, sound_manager_destroy_stream_information() is failed\n");
+    }
   }
 
   mPlayerState = PLAYER_STATE_NONE;
   mPlayer      = NULL;
+  mStreamInfo  = NULL;
 }
 
 void TizenVideoPlayer::SetCodecType(Dali::VideoPlayerPlugin::CodecType type)
@@ -1541,9 +1551,9 @@ void TizenVideoPlayer::CreateVideoConstraint(Dali::NativeImageSourcePtr nativeIm
   if(syncActor)
   {
     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)));
+    mVideoRatioPropertyIndex    = syncActor.RegisterProperty("uSizeRatio", Property::Value(Vector2(0.0f, 0.0f)));
 
-    mVideoConstraintHelper = VideoConstraintHelper::New(nativeImageSourcePtr);
+    mVideoConstraintHelper   = VideoConstraintHelper::New(nativeImageSourcePtr);
     mVideoRotationConstraint = Constraint::New<Vector4>(syncActor, mVideoRotationPropertyIndex, VideoPlayerRotationConstraint(mVideoConstraintHelper));
     mVideoRotationConstraint.Apply();
 
index 11125bbde3949c1169327cd6fea4f7cc22c9029f..e5f09cb63e89afec4540a694631d59ed68ecc2bb 100644 (file)
@@ -272,7 +272,6 @@ public:
   void SceneDisconnection();
 
 private:
-
   /**
    * @brief Update video frame image to native image source
    */
@@ -332,7 +331,6 @@ private:
   std::string                mUrl;                  ///< The video file path
   player_h                   mPlayer;               ///< Tizen player handle
   player_state_e             mPlayerState;          ///< Tizen player state
-  tbm_surface_h              mTbmSurface;           ///< tbm surface handle
   media_packet_h             mPacket;               ///< Media packet handle with tbm surface of current video frame image
   Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< native image source for video rendering
   Dali::Vector4              mBackgroundColor;      ///< Current background color, which texturestream mode needs.
@@ -363,8 +361,8 @@ private:
 #ifdef OVER_TIZEN_VERSION_9
   Ecore_Wl2_VideoShell_Surface* mEcoreVideoShellSurface;
 #endif
-  Constraint      mVideoShellSizePropertyConstraint;
-  Property::Index mVideoShellSizePropertyIndex;
+  Constraint                                mVideoShellSizePropertyConstraint;
+  Property::Index                           mVideoShellSizePropertyIndex;
   Dali::IntrusivePtr<VideoConstraintHelper> mVideoConstraintHelper;
 
 public: