mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 01:26:49 +08:00
[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:
@@ -17,7 +17,7 @@
|
|||||||
#ifndef __MPP_RUNTIME__
|
#ifndef __MPP_RUNTIME__
|
||||||
#define __MPP_RUNTIME__
|
#define __MPP_RUNTIME__
|
||||||
|
|
||||||
#include "mpp_common.h"
|
#include "rk_mpi.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -27,6 +27,7 @@ extern "C" {
|
|||||||
* Runtime function detection is to support different binary on different
|
* Runtime function detection is to support different binary on different
|
||||||
* runtime environment. This is usefull on product environemnt.
|
* runtime environment. This is usefull on product environemnt.
|
||||||
*/
|
*/
|
||||||
|
RK_U32 mpp_rt_allcator_is_valid(MppBufferType type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -14,8 +14,67 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef RKPLATFORM
|
#define MODULE_TAG "mpp_rt"
|
||||||
#include <dlfcn.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "mpp_log.h"
|
||||||
#include "mpp_runtime.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);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user