#include "mm_player_capture.h"
#include "mm_player_priv.h"
-#include <mm_util_image.h>
-#include <mm_util_imgp.h>
+#include <mm_util_type.h>
#include <gst/video/video-info.h>
//#define CAPTURE_OUTPUT_DUMP 1
-/*---------------------------------------------------------------------------
-| LOCAL VARIABLE DEFINITIONS for internal |
----------------------------------------------------------------------------*/
+#define MM_IMG_UITL_LIBRARY_PATH PATH_LIBDIR"/libmmutil_common.so"
+#define MM_IMGP_UITL_LIBRARY_PATH PATH_LIBDIR"/libmmutil_imgp.so"
+
+#define IMG_UTIL_INTERFACE(_player) (((mmplayer_t *)_player)->img_util)
/*---------------------------------------------------------------------------
| LOCAL FUNCTION PROTOTYPES: |
static gpointer __mmplayer_capture_thread(gpointer data);
static void __csc_tiled_to_linear_crop(unsigned char *yuv420_dest, unsigned char *nv12t_src, int yuv420_width, int yuv420_height, int left, int top, int right, int bottom);
static int __tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos);
-static int __mm_player_convert_colorspace(mmplayer_t *player, unsigned char *src_data, size_t src_size, mm_util_color_format_e src_fmt, unsigned int src_w, unsigned int src_h, mm_util_color_format_e dst_fmt);
static int __mm_player_convert_NV12_tiled(mmplayer_t *player);
static int __mm_player_convert_NV12(mmplayer_t *player);
static int __mm_player_convert_I420(mmplayer_t *player);
| FUNCTION DEFINITIONS |
| |
========================================================================================== */
+
+static int __mmplayer_init_img_util_interface(mmplayer_t *player)
+{
+ int ret = MM_ERROR_NONE;
+ gboolean sym_ret = FALSE;
+ GModule *img_module = NULL;
+ GModule *imgp_module = NULL;
+ mm_img_util_interface_t *img_util = NULL;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if ((access(MM_IMG_UITL_LIBRARY_PATH, F_OK) != 0) ||
+ (access(MM_IMGP_UITL_LIBRARY_PATH, F_OK) != 0)){
+ LOGE("there is no img util library");
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+
+ /* allocate new handle */
+ img_util = (mm_img_util_interface_t *)g_try_malloc0(sizeof(mm_img_util_interface_t));
+ if (!img_util) {
+ LOGE("failed to alloc memory for image util interface");
+ ret = MM_ERROR_OUT_OF_MEMORY;
+ goto _INIT_FAILED;
+ }
+
+ img_module = g_module_open(MM_IMG_UITL_LIBRARY_PATH, G_MODULE_BIND_LAZY);
+ if (!img_module) {
+ LOGE("failed to open img common module");
+ goto _INIT_FAILED;
+ }
+
+ imgp_module = g_module_open(MM_IMGP_UITL_LIBRARY_PATH, G_MODULE_BIND_LAZY);
+ if (!imgp_module) {
+ LOGE("failed to open imgp module");
+ goto _INIT_FAILED;
+ }
+
+ /* find symbols */
+ sym_ret = g_module_symbol(img_module, "mm_image_create_image", (gpointer *)&img_util->create);
+ sym_ret &= g_module_symbol(img_module, "mm_image_destroy_image", (gpointer *)&img_util->destroy);
+ sym_ret &= g_module_symbol(img_module, "mm_image_get_image", (gpointer *)&img_util->get);
+ sym_ret &= g_module_symbol(img_module, "mm_image_debug_image", (gpointer *)&img_util->debug);
+ sym_ret &= g_module_symbol(imgp_module, "mm_util_rotate_image", (gpointer *)&img_util->rotate);
+ sym_ret &= g_module_symbol(imgp_module, "mm_util_convert_colorspace", (gpointer *)&img_util->convert);
+
+ if (sym_ret == FALSE || !img_util->create || !img_util->rotate) {
+ LOGE("failed to find symbol %d %p %p", sym_ret, img_util->create, img_util->rotate);
+ ret = MM_ERROR_PLAYER_INTERNAL;
+ goto _INIT_FAILED;
+ }
+
+ img_util->img_module = img_module;
+ img_util->imgp_module = imgp_module;
+ player->img_util = img_util;
+
+ LOGD("image util interface handle %p", img_util);
+ return MM_ERROR_NONE;
+
+_INIT_FAILED:
+ /* release allocated resources */
+ if (img_module) {
+ g_module_close(img_module);
+ img_module = NULL;
+ }
+ if (imgp_module) {
+ g_module_close(imgp_module);
+ imgp_module = NULL;
+ }
+
+ MMPLAYER_FREEIF(img_util);
+ return ret;
+}
+
+static int __mmplayer_deinit_img_util_interface(mmplayer_t *player)
+{
+ int ret = MM_ERROR_NONE;
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (IMG_UTIL_INTERFACE(player)->img_module) {
+ LOGD("close img common module %p", IMG_UTIL_INTERFACE(player)->img_module);
+ if (!g_module_close(IMG_UTIL_INTERFACE(player)->img_module)) {
+ LOGE("failed to close module");
+ ret = MM_ERROR_PLAYER_INTERNAL;
+ }
+ }
+
+ if (IMG_UTIL_INTERFACE(player)->imgp_module) {
+ LOGD("close imgp module %p", IMG_UTIL_INTERFACE(player)->imgp_module);
+ if (!g_module_close(IMG_UTIL_INTERFACE(player)->imgp_module)) {
+ LOGE("failed to close module");
+ ret = MM_ERROR_PLAYER_INTERNAL;
+ }
+ }
+
+ MMPLAYER_FREEIF(IMG_UTIL_INTERFACE(player));
+ MMPLAYER_FLEAVE();
+ return ret;
+}
+
int
_mmplayer_initialize_video_capture(mmplayer_t *player)
{
int ret = MM_ERROR_NONE;
MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (__mmplayer_init_img_util_interface(player) != MM_ERROR_NONE) {
+ LOGE("failed to initialize img util interface");
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+
/* create capture mutex */
g_mutex_init(&player->capture_thread_mutex);
_mmplayer_release_video_capture(mmplayer_t *player)
{
MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ if (!IMG_UTIL_INTERFACE(player)) {
+ LOGW("there is no allocated resource");
+ return MM_ERROR_NONE;
+ }
+
+ __mmplayer_deinit_img_util_interface(player);
+
/* release capture thread */
MMPLAYER_CAPTURE_THREAD_LOCK(player);
player->capture_thread_exit = TRUE;
GstPad *pad = NULL;
MMPLAYER_FENTER();
-
MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ if (!IMG_UTIL_INTERFACE(player)) {
+ LOGW("video capture is not supported");
+ return MM_ERROR_NONE;
+ }
+
/* capturing or not */
if (player->video_capture_cb_probe_id || player->capture.data
|| player->captured.data[0] || player->captured.data[1]) {
LOGD("source buffer for rotation = %p and rotation = %d", src_buffer, rot_enum);
- ret = mm_image_create_image(player->captured.width[0], player->captured.height[0], format, src_buffer, (size_t)player->capture.size, &src_image);
+ ret = IMG_UTIL_INTERFACE(player)->create(player->captured.width[0], player->captured.height[0], format, src_buffer, (size_t)player->capture.size, &src_image);
if (ret != MM_ERROR_NONE) {
LOGE("failed to create image");
return ret;
}
- ret = mm_util_rotate_image(src_image, rot_enum, &dst_image);
- mm_image_destroy_image(src_image);
+ ret = IMG_UTIL_INTERFACE(player)->rotate(src_image, rot_enum, &dst_image);
+ IMG_UTIL_INTERFACE(player)->destroy(src_image);
if (ret != MM_ERROR_NONE) {
LOGE("failed to rotate image");
return ret;
}
- mm_image_debug_image(dst_image, NULL);
+ IMG_UTIL_INTERFACE(player)->debug(dst_image, NULL);
- ret = mm_image_get_image(dst_image, &player->capture.width, &player->capture.height, NULL, &player->capture.data, &dst_size);
- mm_image_destroy_image(dst_image);
+ ret = IMG_UTIL_INTERFACE(player)->get(dst_image, &player->capture.width, &player->capture.height, NULL, &player->capture.data, &dst_size);
+ IMG_UTIL_INTERFACE(player)->destroy(dst_image);
if (ret != MM_ERROR_NONE) {
LOGE("failed to get image");
return ret;
MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_INTERNAL);
SECURE_LOGD("src size info. width: %d, height: %d", src_w, src_h);
- ret = mm_image_create_image(src_w, src_h, src_fmt, src_data, src_size, &src_image);
+ ret = IMG_UTIL_INTERFACE(player)->create(src_w, src_h, src_fmt, src_data, src_size, &src_image);
if (ret != MM_ERROR_NONE) {
LOGE("failed to create image for capture, %d", ret);
return MM_ERROR_PLAYER_INTERNAL;
}
- ret = mm_util_convert_colorspace(src_image, dst_fmt, &dst_image);
- mm_image_destroy_image(src_image);
+ ret = IMG_UTIL_INTERFACE(player)->convert(src_image, dst_fmt, &dst_image);
+ IMG_UTIL_INTERFACE(player)->destroy(src_image);
if (ret != MM_ERROR_NONE) {
LOGE("failed to convert for capture, %d", ret);
return MM_ERROR_PLAYER_INTERNAL;
}
- mm_image_debug_image(dst_image, NULL);
+ IMG_UTIL_INTERFACE(player)->debug(dst_image, NULL);
- ret = mm_image_get_image(dst_image, NULL, NULL, NULL, &player->capture.data, &size);
- mm_image_destroy_image(dst_image);
+ ret = IMG_UTIL_INTERFACE(player)->get(dst_image, NULL, NULL, NULL, &player->capture.data, &size);
+ IMG_UTIL_INTERFACE(player)->destroy(dst_image);
if (ret != MM_ERROR_NONE) {
LOGE("failed to get image for capture, %d", ret);
return MM_ERROR_PLAYER_INTERNAL;
}
player->capture.size = (int)size;
-
return MM_ERROR_NONE;
}