diff --git a/osal/inc/mpp_platform.h b/osal/inc/mpp_platform.h index 056b2cf6..81951bae 100644 --- a/osal/inc/mpp_platform.h +++ b/osal/inc/mpp_platform.h @@ -30,12 +30,18 @@ extern "C" { /* * Platform video codec hardware feature */ +/* RK combined codec */ #define HAVE_VPU1 (0x00000001) #define HAVE_VPU2 (0x00000002) -#define HAVE_HEVC_DEC (0x00000010) -#define HAVE_RKVDEC (0x00000020) -#define HAVE_RKVENC (0x00000100) -#define HAVE_H265E (0x00010000) +/* RK standalone decoder */ +#define HAVE_HEVC_DEC (0x00000100) +#define HAVE_RKVDEC (0x00000200) +#define HAVE_AVSDEC (0x00001000) +/* RK standalone encoder */ +#define HAVE_RKVENC (0x00010000) +#define HAVE_VEPU (0x00020000) +/* External encoder */ +#define HAVE_H265E (0x01000000) RK_U32 mpp_get_vcodec_hw_flag(void); diff --git a/osal/mpp_platform.cpp b/osal/mpp_platform.cpp index da1ee3af..4a219d31 100644 --- a/osal/mpp_platform.cpp +++ b/osal/mpp_platform.cpp @@ -14,29 +14,76 @@ * limitations under the License. */ +#ifdef RKPLATFORM +#include +#endif +#include "mpp_log.h" #include "mpp_common.h" #include "mpp_platform.h" +typedef struct { + const char *compatible; + RK_U32 flag; +} MppVpuType; + +static const MppVpuType mpp_vpu_version[] = { + { "rk3066", HAVE_VPU1, }, + { "rk312x", HAVE_VPU1, }, + { "rk3288", HAVE_VPU1, }, + { "rk3368", HAVE_VPU1, }, + { "rk3399", HAVE_VPU2, }, + { "rk322x", HAVE_VPU2, }, + { "rk322xh", HAVE_VPU2, }, + { "rk1108", HAVE_VPU2, }, + { "rv1108", HAVE_VPU2, }, +}; + RK_U32 mpp_get_vcodec_hw_flag(void) { - RK_U32 flag = 0; + static RK_U32 flag = 0; + + if (flag) + return flag; #ifdef RKPLATFORM - /* NOTE: current only support vpu2 */ - if (!access("/dev/vpu_service", F_OK)) - flag |= HAVE_VPU2; - - /* for rk3288 / rk3368 /rk312x hevc decoder */ - if (!access("/dev/hevc_service", F_OK)) - flag |= HAVE_HEVC_DEC; - - /* for rk3228 / rk3229 / rk3399 decoder */ - if (!access("/dev/rkvdec", F_OK)) - flag |= HAVE_RKVDEC; - - /* for rk1108 encoder */ - if (!access("/dev/rkvenc", F_OK)) - flag |= HAVE_RKVENC; + { + /* judge vdpu support version */ + RK_S32 fd = -1; + /* set vpu1 defalut for old chip without dts */ + flag = HAVE_VPU1; + fd = open("/proc/device-tree/compatible", O_RDONLY); + if (fd < 0) { + mpp_err("open /proc/device-tree/compatible error.\n"); + } else { + RK_U32 i = 0; + char temp[256]; + if (read(fd, temp, sizeof(temp) - 1) > 0) { + for (i = 0; i < MPP_ARRAY_ELEMS(mpp_vpu_version); i++) { + if (strstr(temp, mpp_vpu_version[i].compatible)) { + flag = mpp_vpu_version[i].flag; + break; + } + } + } + close(fd); + } + /* for rk3288 / rk3368 /rk312x hevc decoder */ + if (!access("/dev/hevc_service", F_OK)) { + flag |= HAVE_HEVC_DEC; + } + /* for rk3228 / rk3229 / rk3399 decoder */ + if (!access("/dev/rkvdec", F_OK)) { + flag |= HAVE_RKVDEC; + } + /* for rk1108 encoder */ + if (!access("/dev/rkvenc", F_OK)) { + flag |= HAVE_RKVENC; + } + /* for avs decoder */ + if (!access("/dev/avsd", F_OK)) { + flag |= HAVE_AVSDEC; + } + } #endif return flag;