[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 <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2017-12-13 15:23:52 +08:00
parent 785b0f220d
commit 7d29f32280
2 changed files with 64 additions and 4 deletions

View File

@@ -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
}

View File

@@ -14,8 +14,67 @@
* limitations under the License.
*/
#ifdef RKPLATFORM
#include <dlfcn.h>
#endif
#define MODULE_TAG "mpp_rt"
#include <fcntl.h>
#include <unistd.h>
#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);
}