Support trackrenderer_set_resource_allocate_policy() API. 60/320260/1
authorGilbok Lee <gilbok.lee@samsung.com>
Tue, 15 Oct 2024 07:35:14 +0000 (16:35 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Tue, 12 Nov 2024 01:06:41 +0000 (01:06 +0000)
- Support for kTrackRendererRscAllocExclusive,
kTrackRendererRscAllocConditional RscAllocPolicy types
- Fix svace issue (SEC_DO_NOT_USE_POINTER_WITH_INT_IN_UNION)

[Version] 0.1.4
[Issue Type] Add features

Change-Id: I807264d3ff7e8954434e04f172e75b772b860fcc
(cherry picked from commit 619ef13af1b0adffd9ec6a65014d461f02206156)

include/trackrenderer_capi/track.h
src/include_internal/trackrenderer/resource.h
src/include_internal/trackrenderer/trackrenderer.h
src/include_internal/trackrenderer/trackrenderer_capi_utils.h
src/resourcemanager.cpp
src/trackrenderer.cpp
src/trackrenderer_capi.cpp
src/trackrenderer_capi_utils.cpp

index d3906b802531c41f71311b10aa67f3c3e8ab8f0c..fb1ba38c4f78887e39356ebe1e80f031213469d4 100644 (file)
@@ -329,7 +329,7 @@ typedef struct _TrackRendererSubtitleAttr {
      *                kSubAttrWebvttCueAlign \n
      *                kSubAttrWebvttC
      */
-    int32_t i32;
+    intptr_t i32;
 
     /**
      * @description   String type subtitle atribute value.
@@ -341,7 +341,7 @@ typedef struct _TrackRendererSubtitleAttr {
     /**
      * @description   Unsigned 32bit integer type subtitle attribute value.
      */
-    uint32_t ui32;
+    uintptr_t ui32;
 
     /**
      * @description   Unsigned 64bit integer type subtitle attribute value.
index 3d46fe01c7205435e5cd70838e9099106c28db28..d23d75d964d510699659d8c9d9111d6271d947bf 100644 (file)
@@ -29,9 +29,17 @@ enum class ResourceCategory {
   kVideoRenderer,
 };
 
+enum class RscAllocPolicy {
+  kRscAllocExclusive,
+  kRscAllocConditional,
+  kRscAllocInAppMultiview,
+  kRscAllocExclusiveMfcForced
+};
+
 struct ResourceProperty {
   ResourceCategory category;
   Track track;
+  RscAllocPolicy rsc_alloc_policy;
 };
 
 class Resource {
index 60bbeed386c8d5d5fb111a2346096cd538cb2256..f7cde8a9ece2e5c86f50fd835d1ff92f3c21b871 100644 (file)
@@ -154,6 +154,7 @@ class TrackRenderer : public ResourceConflictListener,
   void SetVideoFrameBufferType(DecodedVideoFrameBufferType type) {
     decoded_buffer_type_ = type;
   }
+  void SetResourceAllocatePolicy(const RscAllocPolicy& policy) { rsc_alloc_policy_ = policy; };
   GetDecodedVideoFrameState GetDecodedPacket(DecodedVideoPacket& packet);
   bool ReturnDecodedPacket(const DecodedVideoPacket& packet);
   bool EnableVideoHole(bool value);
@@ -389,6 +390,7 @@ class TrackRenderer : public ResourceConflictListener,
 
   std::unique_ptr<ResourceManager> resource_manager_;
   std::unique_ptr<Display> display_;
+  RscAllocPolicy rsc_alloc_policy_ = RscAllocPolicy::kRscAllocExclusive;
 
   GstCapsBuilder caps_builder_;
   std::map<std::string, bool> properties_;
index aeb5132b204f6276cdbe739f5b82dd5f62fe8b5b..1ec2ec990e69c0985808977ad7a4ad63b1ff44c8 100644 (file)
@@ -28,6 +28,7 @@
 #include "trackrenderer/core/error.h"
 #include "trackrenderer/core/event.h"
 #include "trackrenderer/core/track.h"
+#include "trackrenderer/resource.h"
 #include "trackrenderer_capi/buffer.h"
 #include "trackrenderer_capi/decoderinputbuffer.h"
 #include "trackrenderer_capi/display.h"
@@ -96,6 +97,8 @@ DecodedVideoFrameBufferType ConvertToVideoFrameBufferType(
     const TrackRendererDecodedVideoFrameBufferType& type);
 TrackRendererGetDecodedVideoFrameState ConverToGetDecodedVideoFrameState(
     const GetDecodedVideoFrameState state);
+RscAllocPolicy ConvertToRscAllocPolicy
+    (const TrackRendererRscAllocPolicy& policy);
 }  // namespace capi_utils
 
 }  // namespace trackrenderer
index c4d21c68c84e818b2e072c8f783fc7c570ac4d30..7cd411950141d60a5219c376678784460be0719e 100644 (file)
@@ -36,6 +36,13 @@ const std::map<ResourceCategory, rm_rsc_category_e> TypeToCategoryConverter = {
     {ResourceCategory::kVideoDecoder, RM_CATEGORY_VIDEO_DECODER},
     {ResourceCategory::kVideoRenderer, RM_CATEGORY_SCALER}};
 
+const std::map<RscAllocPolicy, rm_requests_resource_state_e>
+    TypeToResourceStateConverter = {
+        {RscAllocPolicy::kRscAllocExclusive, RM_STATE_EXCLUSIVE},
+        {RscAllocPolicy::kRscAllocConditional, RM_STATE_EXCLUSIVE_CONDITIONAL},
+        {RscAllocPolicy::kRscAllocInAppMultiview, RM_STATE_EXCLUSIVE},
+        {RscAllocPolicy::kRscAllocExclusiveMfcForced, RM_STATE_EXCLUSIVE}};
+
 void AddRMHandle(ResourceManager *handle) {
   TRACKRENDERER_INFO("Resource manager handle[%p]", handle);
   std::lock_guard<std::mutex> lock(rsc_lock);
@@ -159,13 +166,13 @@ bool ResourceManager::Acquire_(const ResourceProperty& property) {
   memset(&devices, 0, sizeof(rm_device_return_s));
 
   req.request_num = 1;
-  req.state[0] = RM_STATE_EXCLUSIVE;
+  req.state[0] = internal::TypeToResourceStateConverter.at(property.rsc_alloc_policy);
   req.category_id[0] = internal::GetCategoryID(property);
   req.category_option[0] = rc_get_capable_category_id(resourcemanager_handle_, app_id_.c_str(),category_id);
 
   int rm_ret = rm_allocate_resources(resourcemanager_handle_, &req, &devices);
-  if (rm_ret == RM_ERROR) {
-    TRACKRENDERER_ERROR("[RM_ERROR] rm_allocate_resources fail");
+  if (rm_ret != RM_OK) {
+    TRACKRENDERER_ERROR("[RM_ERROR] rm_allocate_resources fail[%d] error type[%d]", rm_ret, devices.error_type);
     return false;
   }
 
index 69d6efc13af1f054e7e3c73999cf0cd7cf14cbc2..36dea8be0911be58f061910808b745020b7b0ad2 100644 (file)
@@ -899,7 +899,7 @@ bool TrackRenderer::CreateDecoder_(const Track* track, const GstCaps* caps) {
   if (track->type == kTrackTypeVideo) {
     element = Elements::kDecVideo;
     if (factory_type & GST_ELEMENT_FACTORY_TYPE_HARDWARE) {
-      std::list<ResourceProperty> properties {{ ResourceCategory::kVideoDecoder, *track }};
+      std::list<ResourceProperty> properties {{ ResourceCategory::kVideoDecoder, *track, rsc_alloc_policy_ }, };
       if (!resource_manager_->Acquire(properties)) {
         TRACKRENDERER_ERROR("Failed to acquire video hw decoder resource");
         return false;
@@ -939,7 +939,7 @@ bool TrackRenderer::CreateVideoSink_(const Track* track) {
   const char* videosink_name = kFakeSinkName;
   if (internal::IsDisplayNeeded(display_type)) {
     videosink_name = kVideoSinkName;
-    std::list<ResourceProperty> properties {{ ResourceCategory::kVideoRenderer, {} }};
+    std::list<ResourceProperty> properties {{ ResourceCategory::kVideoRenderer, {}, rsc_alloc_policy_ }};
     if (!resource_manager_->Acquire(properties)) {
       TRACKRENDERER_ERROR("Failed to acquire video hw renderer resource");
       return false;
index e530a168282ebcb96afced647117adf08111a9dc..9679984ac30bd56e00a92ee93d68588b97ef6b4e 100644 (file)
@@ -1519,7 +1519,18 @@ int trackrenderer_set_advanced_picture_quality_type(
 
 int trackrenderer_set_resource_allocate_policy(
     TrackRendererHandle handle, TrackRendererRscAllocPolicy policy) {
-  TRACKRENDERER_WARN("Not supported on Public");
+  auto priv = static_cast<TrackRendererPrivPtr>(handle);
+  if (!priv) return kFailed;
+
+  if (policy == kTrackRendererRscAllocInAppMultiview
+      || policy == kTrackRendererRscAllocExclusiveMfcForced) {
+    TRACKRENDERER_WARN("Not supported policy (%d) on Public", policy);
+    return kSuccess;
+  }
+
+  priv->renderer->SetResourceAllocatePolicy(
+        plusplayer::trackrenderer::capi_utils::ConvertToRscAllocPolicy(policy));
+
   return kSuccess;
 }
 
index fdd3b94d5dd65071b36d28306211aa4dc89826bc..acbb1fe71632aaeb72051e56f39a0cc439737fe9 100644 (file)
@@ -796,6 +796,23 @@ TrackRendererGetDecodedVideoFrameState ConverToGetDecodedVideoFrameState(
   }
 }
 
+RscAllocPolicy ConvertToRscAllocPolicy(
+  const TrackRendererRscAllocPolicy& policy) {
+  switch (policy) {
+    case kTrackRendererRscAllocExclusive:
+      return RscAllocPolicy::kRscAllocExclusive;
+    case kTrackRendererRscAllocConditional:
+      return RscAllocPolicy::kRscAllocConditional;
+    case kTrackRendererRscAllocInAppMultiview:
+      return RscAllocPolicy::kRscAllocInAppMultiview;
+    case kTrackRendererRscAllocExclusiveMfcForced:
+      return RscAllocPolicy::kRscAllocExclusiveMfcForced;
+    default:
+      TRACKRENDERER_ERROR("unknown policy");
+      return RscAllocPolicy::kRscAllocExclusive;
+  }
+}
+
 }  // namespace capi_utils
 
 }  // namespace trackrenderer