From 7d29f32280c346a936e57f79837764d6472593d5 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Wed, 13 Dec 2017 15:23:52 +0800 Subject: [PATCH] [osal]: Add runtime allocator detection function Due to complexity of different kernel and usespace combination we have to detect drm and ion allocator on runtime. The HAVE_DRM flag may not be trust at all time. So we add a simple detection function on first run. Change-Id: Id4f6b2278ee0fe50ffc9806fffc5b01267f723da Signed-off-by: Herman Chen --- osal/inc/mpp_runtime.h | 3 +- osal/mpp_runtime.cpp | 65 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/osal/inc/mpp_runtime.h b/osal/inc/mpp_runtime.h index 53670543..7606f364 100644 --- a/osal/inc/mpp_runtime.h +++ b/osal/inc/mpp_runtime.h @@ -17,7 +17,7 @@ #ifndef __MPP_RUNTIME__ #define __MPP_RUNTIME__ -#include "mpp_common.h" +#include "rk_mpi.h" #ifdef __cplusplus extern "C" { @@ -27,6 +27,7 @@ extern "C" { * Runtime function detection is to support different binary on different * runtime environment. This is usefull on product environemnt. */ +RK_U32 mpp_rt_allcator_is_valid(MppBufferType type); #ifdef __cplusplus } diff --git a/osal/mpp_runtime.cpp b/osal/mpp_runtime.cpp index 8442120a..c2056015 100644 --- a/osal/mpp_runtime.cpp +++ b/osal/mpp_runtime.cpp @@ -14,8 +14,67 @@ * limitations under the License. */ -#ifdef RKPLATFORM -#include -#endif +#define MODULE_TAG "mpp_rt" +#include +#include + +#include "mpp_log.h" #include "mpp_runtime.h" + +class MppRuntimeService +{ +private: + // avoid any unwanted function + MppRuntimeService(); + ~MppRuntimeService() {}; + MppRuntimeService(const MppRuntimeService &); + MppRuntimeService &operator=(const MppRuntimeService &); + + RK_U32 allocator_valid[MPP_BUFFER_TYPE_BUTT]; + +public: + static MppRuntimeService *get_instance() { + static MppRuntimeService instance; + return &instance; + } + + RK_U32 get_allocator_valid(MppBufferType type); +}; + +RK_U32 MppRuntimeService::get_allocator_valid(MppBufferType type) +{ + return (type < MPP_BUFFER_TYPE_BUTT) ? allocator_valid[type] : (0); +}; + +MppRuntimeService::MppRuntimeService() +{ + int fd = -1; + allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1; + allocator_valid[MPP_BUFFER_TYPE_V4L2] = 0; + + fd = open("/dev/ion", O_RDWR); + if (fd < 0) { + allocator_valid[MPP_BUFFER_TYPE_ION] = 0; + mpp_log("NOT found ion allocator\n"); + } else { + allocator_valid[MPP_BUFFER_TYPE_ION] = 1; + mpp_log("found ion allocator\n"); + close(fd); + } + + fd = open("/dev/dri/card0", O_RDWR); + if (fd < 0) { + allocator_valid[MPP_BUFFER_TYPE_DRM] = 0; + mpp_log("NOT found drm allocator\n"); + } else { + allocator_valid[MPP_BUFFER_TYPE_DRM] = 1; + mpp_log("found drm allocator\n"); + close(fd); + } +} + +RK_U32 mpp_rt_allcator_is_valid(MppBufferType type) +{ + return MppRuntimeService::get_instance()->get_allocator_valid(type); +}