Skip to content

Commit

Permalink
mm-video-v4l2: Interface with new video hypervisor FE
Browse files Browse the repository at this point in the history
Update video hypervisor intercept library to interface
with the new video hypervisor FE and other minor cleanups.

Change-Id: Ib5d17f26bd047b58e334aa2b75f1fb42ae4b17ec
  • Loading branch information
Shiju Mathew authored and Gerrit - the friendly Code Review server committed Jul 6, 2017
1 parent dc82d85 commit c280c12
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 101 deletions.
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ ifeq ($(BOARD_USES_ADRENO), true)
include $(QCOM_MEDIA_ROOT)/libc2dcolorconvert/Android.mk
endif

include $(QCOM_MEDIA_ROOT)/hypv-intercept/Android.mk

endif
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
ACLOCAL_AMFLAGS = -I m4

BUILD_COMPONENTS := mm-core hyp-intercept
BUILD_COMPONENTS := mm-core hypv-intercept

if BUILD_MM_VIDEO
BUILD_COMPONENTS += mm-video-v4l2
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ AC_SUBST([CFLAGS])

AC_CONFIG_FILES([ \
Makefile \
hyp-intercept/Makefile \
hypv-intercept/Makefile \
mm-core/Makefile
mm-video-v4l2/Makefile \
mm-video-v4l2/vidc/Makefile \
Expand Down
2 changes: 1 addition & 1 deletion hyp-intercept/Android.mk → hypv-intercept/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LOCAL_SHARED_LIBRARIES := liblog libdl

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE := libhypintercept
LOCAL_MODULE := libhypv_intercept

LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib
LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64
Expand Down
12 changes: 6 additions & 6 deletions hyp-intercept/Makefile.am → hypv-intercept/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ AM_CPPFLAGS = -D_LINUX_
AM_CPPFLAGS += -I$(top_srcdir)/mm-video-v4l2/vidc/common/inc

# -----------------------------------------------------------------------------
# Make the Shared library (libgioctl)
# Make the Shared library (libhypv_intercept)
# -----------------------------------------------------------------------------
h_sources = hypv_intercept.h
c_sources = hypv_intercept.cpp

include_HEADERS = $(h_source)
lib_LTLIBRARIES = libhypintercept.la
libhypintercept_la_SOURCES = $(c_sources)
libhypintercept_la_CFLAGS = $(AM_CFLAGS) -fPIC
libhypintercept_la_CPPFLAGS = $(AM_CPPFLAGS)
libhypintercept_la_LDFLAGS = -shared -llog -ldl
lib_LTLIBRARIES = libhypv_intercept.la
libhypv_intercept_la_SOURCES = $(c_sources)
libhypv_intercept_la_CFLAGS = $(AM_CFLAGS) -fPIC
libhypv_intercept_la_CPPFLAGS = $(AM_CPPFLAGS)
libhypv_intercept_la_LDFLAGS = -shared -llog -ldl
121 changes: 57 additions & 64 deletions hyp-intercept/hypv_intercept.cpp → hypv-intercept/hypv_intercept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/ioctl.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>

#include "hypv_intercept.h"
#include "vidc_debug.h"
#ifdef _ANDROID_
#define LOG_TAG "HYPV-INTERCEPT"
extern "C" {
#include<utils/Log.h>
}
#else
#define ALOGE(fmt, args...) fprintf(stderr, fmt, ##args)
#endif /* _ANDROID_ */

typedef V4L2FE_HANDLE (*v4l2fe_open_func)(const char*, int, v4l2fe_callback_t*);
typedef int (*v4l2fe_ioctl_func)(V4L2FE_HANDLE, int, void*);
typedef int (*v4l2fe_close_func)(V4L2FE_HANDLE);
typedef HVFE_HANDLE (*video_fe_open_func)(const char*, int, hvfe_callback_t*);
typedef int (*video_fe_ioctl_func)(HVFE_HANDLE, int, void*);
typedef int (*video_fe_close_func)(HVFE_HANDLE);

#define MAX_V4L2_HANDLE_STORAGE 16
#define MAX_HVFE_HANDLE_STORAGE 16
#define HYPV_HANDLE_SIGNATURE 0x2bcd0000
#define HYPV_HANDLE_SIGNATURE_MASK 0xffff0000
#define HYPV_HANDLE_MASK 0x0000ffff
Expand All @@ -64,44 +58,44 @@ enum hypv_which_build_t
};

static void *glib_handle = NULL;
static v4l2fe_open_func v4l2fe_open = NULL;
static v4l2fe_ioctl_func v4l2fe_ioctl = NULL;
static v4l2fe_close_func v4l2fe_close = NULL;
static video_fe_open_func video_fe_open = NULL;
static video_fe_ioctl_func video_fe_ioctl = NULL;
static video_fe_close_func video_fe_close = NULL;
static hypv_which_build_t ghypv_which_build = HYPV_NOT_INITIAILIZED;
static pthread_mutex_t g_v4l2_handle_storage_lock = PTHREAD_MUTEX_INITIALIZER;
static V4L2FE_HANDLE g_v4l2_handle_storage[MAX_V4L2_HANDLE_STORAGE];
static int g_v4l2_handle_count = 0;
static pthread_mutex_t g_hvfe_handle_storage_lock = PTHREAD_MUTEX_INITIALIZER;
static HVFE_HANDLE g_hvfe_handle_storage[MAX_HVFE_HANDLE_STORAGE];
static int g_hvfe_handle_count = 0;
static int g_hypv_init_count = 0;

#define IS_HYPERVISOR_VIDEO(fd) ((ghypv_which_build == HYPV_HYPERVISOR_BUILD) &&\
((fd & HYPV_HANDLE_SIGNATURE_MASK)==HYPV_HANDLE_SIGNATURE))

static int add_to_v4l2_handle_storage(V4L2FE_HANDLE handle_to_store)
static int add_to_hvfe_handle_storage(HVFE_HANDLE handle_to_store)
{
int rc = 0;

pthread_mutex_lock(&g_v4l2_handle_storage_lock);
if (g_v4l2_handle_count >= MAX_V4L2_HANDLE_STORAGE) {
pthread_mutex_lock(&g_hvfe_handle_storage_lock);
if (g_hvfe_handle_count >= MAX_HVFE_HANDLE_STORAGE) {
DEBUG_PRINT_ERROR("reached max handle count");
rc = -1;
} else {
int i;

for(i = 0; i < MAX_V4L2_HANDLE_STORAGE; i++) {
if (g_v4l2_handle_storage[i] == 0) {
g_v4l2_handle_storage[i] = handle_to_store;
for(i = 0; i < MAX_HVFE_HANDLE_STORAGE; i++) {
if (g_hvfe_handle_storage[i] == 0) {
g_hvfe_handle_storage[i] = handle_to_store;
rc = i;
g_v4l2_handle_count++;
g_hvfe_handle_count++;
break;
}
}
if (i >= MAX_V4L2_HANDLE_STORAGE) {
if (i >= MAX_HVFE_HANDLE_STORAGE) {
DEBUG_PRINT_ERROR("failed to find empty slot");
rc = -1;
}
}

pthread_mutex_unlock(&g_v4l2_handle_storage_lock);
pthread_mutex_unlock(&g_hvfe_handle_storage_lock);

return rc;
}
Expand All @@ -110,65 +104,65 @@ int hypv_init(void)
{
int rc = 0;

pthread_mutex_lock(&g_v4l2_handle_storage_lock);
pthread_mutex_lock(&g_hvfe_handle_storage_lock);

if (ghypv_which_build == HYPV_NOT_INITIAILIZED) {
glib_handle = dlopen("libgioctl.so", RTLD_NOW);
glib_handle = dlopen("libhyp_video_fe.so", RTLD_NOW);
if (glib_handle == NULL) {
DEBUG_PRINT_ERROR("failed to open gioctl lib");
DEBUG_PRINT_ERROR("failed to open libhyp_video_fe");
rc = -1;
} else {
ghypv_which_build = HYPV_HYPERVISOR_BUILD;
g_v4l2_handle_count = 0;
memset(g_v4l2_handle_storage, 0, sizeof(V4L2FE_HANDLE)*MAX_V4L2_HANDLE_STORAGE);
v4l2fe_open = (v4l2fe_open_func)dlsym(glib_handle, "v4l2fe_open");
if (v4l2fe_open == NULL) {
DEBUG_PRINT_ERROR("failed to get v4l2fe_open handle");
g_hvfe_handle_count = 0;
memset(g_hvfe_handle_storage, 0, sizeof(HVFE_HANDLE)*MAX_HVFE_HANDLE_STORAGE);
video_fe_open = (video_fe_open_func)dlsym(glib_handle, "video_fe_open");
if (video_fe_open == NULL) {
DEBUG_PRINT_ERROR("failed to get video_fe_open handle");
rc = -1;
} else {
v4l2fe_ioctl = (v4l2fe_ioctl_func)dlsym(glib_handle, "v4l2fe_ioctl");
if (v4l2fe_ioctl == NULL) {
DEBUG_PRINT_ERROR("failed to get v4l2fe_ioctl handle");
video_fe_ioctl = (video_fe_ioctl_func)dlsym(glib_handle, "video_fe_ioctl");
if (video_fe_ioctl == NULL) {
DEBUG_PRINT_ERROR("failed to get video_fe_ioctl handle");
rc = -1;
} else {
v4l2fe_close = (v4l2fe_close_func)dlsym(glib_handle, "v4l2fe_close");
if (v4l2fe_close == 0) {
DEBUG_PRINT_ERROR("failed to get v4l2fe_close handle");
video_fe_close = (video_fe_close_func)dlsym(glib_handle, "video_fe_close");
if (video_fe_close == 0) {
DEBUG_PRINT_ERROR("failed to get video_fe_close handle");
rc = -1;
}//v4l2fe_close
} //v4l2fe_iocl
} //v4l2fe_open
}//video_fe_close
} //video_fe_iocl
} //video_fe_open
} //glib_handle
}//initialize

if (rc == 0)
g_hypv_init_count++;

pthread_mutex_unlock(&g_v4l2_handle_storage_lock);
pthread_mutex_unlock(&g_hvfe_handle_storage_lock);

return rc;
}

int hypv_open(const char *str, int flag, v4l2fe_callback_t* cb)
int hypv_open(const char *str, int flag, hvfe_callback_t* cb)
{
int rc = 0;

if (ghypv_which_build == HYPV_NOT_INITIAILIZED) {
DEBUG_PRINT_ERROR("hypervisor not initialized");
rc = -1;
} else if (ghypv_which_build == HYPV_HYPERVISOR_BUILD) {
V4L2FE_HANDLE v4l2_handle = v4l2fe_open(str, flag, cb);
DEBUG_PRINT_INFO("v4l2fe_open handle=%p", v4l2_handle);
if (v4l2_handle == NULL) {
DEBUG_PRINT_ERROR("v4l2fe_open failed");
HVFE_HANDLE hvfe_handle = video_fe_open(str, flag, cb);
DEBUG_PRINT_INFO("video_fe_open handle=%p", hvfe_handle);
if (hvfe_handle == NULL) {
DEBUG_PRINT_ERROR("video_fe_open failed");
rc = -1;
} else {
int fd = 0;

fd = add_to_v4l2_handle_storage(v4l2_handle);
fd = add_to_hvfe_handle_storage(hvfe_handle);
if (fd < 0) {
DEBUG_PRINT_ERROR("failed to store v4l2 handle");
v4l2fe_close(v4l2_handle);
DEBUG_PRINT_ERROR("failed to store hvfe handle");
video_fe_close(hvfe_handle);
rc = -1;
} else {
rc = (HYPV_HANDLE_SIGNATURE | fd);
Expand All @@ -188,11 +182,11 @@ int hypv_ioctl(int fd, int cmd, void *data)
rc = -1;
} else if (IS_HYPERVISOR_VIDEO(fd)) {
int fd_index = fd & HYPV_HANDLE_MASK;
if (fd_index >= MAX_V4L2_HANDLE_STORAGE) {
if (fd_index >= MAX_HVFE_HANDLE_STORAGE) {
DEBUG_PRINT_ERROR("invalid fd_index=%d", fd_index);
rc = -1;
}
rc = v4l2fe_ioctl(g_v4l2_handle_storage[fd_index], cmd, data);
rc = video_fe_ioctl(g_hvfe_handle_storage[fd_index], cmd, data);
DEBUG_PRINT_INFO("hyp ioctl: fd=%d, fd_index=%d, cmd=0x%x, data=0x%p, rc =%d",
fd, fd_index, cmd, data, rc);
} else {
Expand All @@ -211,19 +205,18 @@ int hypv_close(int fd)
DEBUG_PRINT_ERROR("hypervisor not initialized");
rc = -1;
} else if (IS_HYPERVISOR_VIDEO(fd)) {
int rc = 0;
int fd_index = fd & HYPV_HANDLE_MASK;

if ((fd_index >= MAX_V4L2_HANDLE_STORAGE) || (fd_index < 0)) {
if ((fd_index >= MAX_HVFE_HANDLE_STORAGE) || (fd_index < 0)) {
DEBUG_PRINT_ERROR("invalid fd=%d", fd_index);
rc = -1;
} else {
int handle_count = 0;
pthread_mutex_lock(&g_v4l2_handle_storage_lock);
rc = v4l2fe_close(g_v4l2_handle_storage[fd_index]);
g_v4l2_handle_storage[fd_index] = 0;
g_v4l2_handle_count--;
pthread_mutex_unlock(&g_v4l2_handle_storage_lock);
pthread_mutex_lock(&g_hvfe_handle_storage_lock);
rc = video_fe_close(g_hvfe_handle_storage[fd_index]);
g_hvfe_handle_storage[fd_index] = 0;
g_hvfe_handle_count--;
pthread_mutex_unlock(&g_hvfe_handle_storage_lock);
}
} else {
rc = close(fd);
Expand All @@ -242,9 +235,9 @@ int hypv_deinit()
} else {
int init_count = 0;

pthread_mutex_lock(&g_v4l2_handle_storage_lock);
pthread_mutex_lock(&g_hvfe_handle_storage_lock);
init_count = --g_hypv_init_count;
pthread_mutex_unlock(&g_v4l2_handle_storage_lock);
pthread_mutex_unlock(&g_hvfe_handle_storage_lock);
if (init_count == 0) {
if (glib_handle != NULL) {
dlclose(glib_handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------*/
#ifndef __HYPV_INTERCEPT_H
#define __HYPV_INTERCEPT_H
#ifndef __HYPV_INTERCEPT_H__
#define __HYPV_INTERCEPT_H__

typedef void* V4L2FE_HANDLE;
typedef int (*v4l2fe_callback_handler_t)(void *context, void *message);
typedef void* HVFE_HANDLE;
typedef int (*hvfe_callback_handler_t)(void *context, void *message);

struct v4l2fe_callback_t
struct hvfe_callback_t
{
v4l2fe_callback_handler_t handler;
hvfe_callback_handler_t handler;
void* context;
};

int hypv_init();
int hypv_open(const char *str, int flag, v4l2fe_callback_t* cb);
int hypv_open(const char *str, int flag, hvfe_callback_t* cb);
int hypv_ioctl(int fd, int cmd, void *data);
int hypv_close(int fd);
int hypv_deinit();

#endif
12 changes: 6 additions & 6 deletions mm-video-v4l2/vidc/vdec/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ libmm-vdec-inc += $(TARGET_OUT_HEADERS)/qcom/display
libmm-vdec-inc += $(TARGET_OUT_HEADERS)/adreno
libmm-vdec-inc += $(TOP)/frameworks/native/include/media/openmax
libmm-vdec-inc += $(TOP)/frameworks/native/include/media/hardware
libmm-vdec-inc += $(TOP)/hardware/qcom/media/libc2dcolorconvert
libmm-vdec-inc += $(TARGET_OUT_HEADERS)/mm-video/SwVdec
libmm-vdec-inc += $(TARGET_OUT_HEADERS)/mm-video/swvdec
libmm-vdec-inc += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
libmm-vdec-inc += $(TOP)/hardware/qcom/media/libc2dcolorconvert
libmm-vdec-inc += $(TOP)/hardware/qcom/media/hypv-intercept
libmm-vdec-inc += $(TARGET_OUT_HEADERS)/mm-video/SwVdec
libmm-vdec-inc += $(TARGET_OUT_HEADERS)/mm-video/swvdec
libmm-vdec-inc += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include

ifeq ($(PLATFORM_SDK_VERSION), 18) #JB_MR2
libmm-vdec-def += -DANDROID_JELLYBEAN_MR2=1
Expand Down Expand Up @@ -128,7 +129,7 @@ LOCAL_ADDITIONAL_DEPENDENCIES := $(libmm-vdec-add-dep)
LOCAL_PRELINK_MODULE := false
LOCAL_SHARED_LIBRARIES := liblog libcutils libdl

LOCAL_SHARED_LIBRARIES += libqdMetaData
LOCAL_SHARED_LIBRARIES += libqdMetaData libhypv_intercept

LOCAL_SRC_FILES := src/frameparser.cpp
LOCAL_SRC_FILES += src/h264_utils.cpp
Expand All @@ -137,7 +138,6 @@ LOCAL_SRC_FILES += src/mp4_utils.cpp
LOCAL_SRC_FILES += src/hevc_utils.cpp
LOCAL_STATIC_LIBRARIES := libOmxVidcCommon
LOCAL_SRC_FILES += src/omx_vdec_v4l2.cpp
LOCAL_SRC_FILES += ../common/src/hypv_intercept.cpp

include $(BUILD_SHARED_LIBRARY)

Expand Down
6 changes: 3 additions & 3 deletions mm-video-v4l2/vidc/vdec/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ AM_CPPFLAGS += -I$(top_srcdir)/mm-video-v4l2/vidc/vdec/inc/
AM_CPPFLAGS += -I$(top_srcdir)/libc2dcolorconvert/
AM_CPPFLAGS += -I$(top_srcdir)/mm-core/inc/
AM_CPPFLAGS += -I$(top_srcdir)/mm-core/src/common/
AM_CPPFLAGS += -I$(top_srcdir)/hyp-intercept/
AM_CPPFLAGS += -I$(top_srcdir)/hypv-intercept/

c_sources := src/frameparser.cpp
c_sources += src/h264_utils.cpp
Expand All @@ -81,5 +81,5 @@ libOmxVdec_la_SOURCES = $(c_sources)
libOmxVdec_la_CFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) -fPIC
libOmxVdec_la_CFLAGS += ../libc2d2colorconvert/libc2dcolorconvert.la
libOmxVdec_la_LDFLAGS = -llog -lutils -lbinder -lcutils -ldl -lqdMetaData -lglib-2.0 -shared -version-info 0
libOmxVdec_la_LDFLAGS += -L$(top_builddir)/hyp-intercept
libOmxVdec_la_LDFLAGS += -lhypintercept
libOmxVdec_la_LDFLAGS += -L$(top_builddir)/hypv-intercept
libOmxVdec_la_LDFLAGS += -lhypv_intercept
8 changes: 4 additions & 4 deletions mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2342,10 +2342,10 @@ OMX_ERRORTYPE omx_vdec::component_init(OMX_STRING role)
DEBUG_PRINT_ERROR("hypervisor init failed");
return OMX_ErrorInsufficientResources;
}
v4l2fe_callback_t v4l2cb;
v4l2cb.handler = async_message_process;
v4l2cb.context = (void *)this;
drv_ctx.video_driver_fd = hypv_open(device_name, O_RDWR, &v4l2cb);
hvfe_callback_t hvfe_cb;
hvfe_cb.handler = async_message_process;
hvfe_cb.context = (void *)this;
drv_ctx.video_driver_fd = hypv_open(device_name, O_RDWR, &hvfe_cb);
} else {
drv_ctx.video_driver_fd = open(device_name, O_RDWR);
}
Expand Down
Loading

0 comments on commit c280c12

Please sign in to comment.