Support user buffer fd 22/200222/4
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 20 Feb 2019 08:35:45 +0000 (17:35 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Fri, 22 Feb 2019 02:12:48 +0000 (11:12 +0900)
[Version] 0.10.180
[Profile] Common
[Issue Type] Update

Change-Id: I7e7902a05bdce954c4820a032e43c44aa254d1b8
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/libmm-camcorder.spec
src/include/mm_camcorder.h
src/include/mm_camcorder_attribute.h
src/include/mm_camcorder_internal.h
src/mm_camcorder_attribute.c
src/mm_camcorder_configure.c
src/mm_camcorder_gstcommon.c
src/mm_camcorder_internal.c

index ea3e369..e1bce11 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.179
+Version:    0.10.180
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 9ad8416..0eb6492 100644 (file)
@@ -1228,6 +1228,16 @@ extern "C" {
 #define MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB   "support-media-packet-preview-cb"
 
 /**
+* Support user buffer for zero copy
+*/
+#define MMCAM_SUPPORT_USER_BUFFER               "support-user-buffer"
+
+/**
+* Buffer fd from user
+*/
+#define MMCAM_USER_BUFFER_FD                    "user-buffer-fd"
+
+/**
  * Enable to write tags for recorded file
  */
 #define MMCAM_RECORDER_TAG_ENABLE               "recorder-tag-enable"
index e0ccc7c..2e8cbad 100644 (file)
@@ -188,6 +188,8 @@ typedef enum {
        MM_CAM_GDBUS_CONNECTION,                        /* 130 */
        MM_CAM_AUDIO_REPLAY_GAIN_ENABLE,
        MM_CAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL,
+       MM_CAM_SUPPORT_USER_BUFFER,
+       MM_CAM_USER_BUFFER_FD,
        MM_CAM_ATTRIBUTE_NUM
 } MMCamcorderAttrsID;
 
index f8f9ad9..144ae34 100644 (file)
@@ -770,6 +770,7 @@ typedef struct mmf_camcorder {
        int use_zero_copy_format;                               /**< Whether use zero copy format for camera input */
        int use_videoconvert;                                   /**< Whether use videoconvert element for display */
        int support_media_packet_preview_cb;                    /**< Whether support zero copy format for camera input */
+       int support_user_buffer;                                /**< Whether support user allocated buffer for zero copy */
        int shutter_sound_policy;                               /**< shutter sound policy */
        int brightness_default;                                 /**< default value of brightness */
        int brightness_step_denominator;                        /**< denominator of brightness bias step */
index 8f162b7..719c0fe 100644 (file)
@@ -1609,6 +1609,28 @@ _mmcamcorder_alloc_attribute(MMHandleType handle)
                        {.double_min = 0.0},
                        {.double_max = 150.0},
                        _mmcamcorder_commit_audio_replay_gain,
+               },
+               {
+                       MM_CAM_SUPPORT_USER_BUFFER,
+                       "support-user-buffer",
+                       MM_ATTRS_TYPE_INT,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)FALSE},
+                       MM_ATTRS_VALID_TYPE_INT_RANGE,
+                       {.int_min = FALSE},
+                       {.int_max = TRUE},
+                       NULL,
+               },
+               {
+                       MM_CAM_USER_BUFFER_FD,
+                       "user-buffer-fd",
+                       MM_ATTRS_TYPE_DATA,
+                       MM_ATTRS_FLAG_RW,
+                       {NULL},
+                       MM_ATTRS_VALID_TYPE_NONE,
+                       {0},
+                       {0},
+                       NULL,
                }
        };
 
index 575a073..a245b44 100644 (file)
@@ -635,6 +635,7 @@ int _mmcamcorder_conf_init(MMHandleType handle, int type, camera_conf *configure
                { "UseZeroCopyFormat",  CONFIGURE_VALUE_INT,            {.value_int = 0} },
                { "DeviceCount",        CONFIGURE_VALUE_INT,            {.value_int = MM_VIDEO_DEVICE_NUM} },
                { "SupportMediaPacketPreviewCb",  CONFIGURE_VALUE_INT,  {.value_int = 0} },
+               { "SupportUserBuffer",  CONFIGURE_VALUE_INT,            {.value_int = 0} },
        };
 
        /* [AudioInput] matching table */
index 3bc8440..ccff837 100644 (file)
@@ -188,7 +188,10 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
        char decoder_name[20] = {'\0',};
 #endif /* _MMCAMCORDER_RM_SUPPORT */
        GstElement *sink_element = NULL;
+       GstCameraControl *control = NULL;
        int sink_element_size = 0;
+       int *fds = NULL;
+       int fd_number = 0;
 
        GList *element_list = NULL;
 
@@ -248,6 +251,21 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
                return err;
        }
 
+       if (hcamcorder->support_user_buffer) {
+               err = mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_USER_BUFFER_FD, &fds, &fd_number,
+                       NULL);
+               if (err != MM_ERROR_NONE || fd_number < 1) {
+                       _mmcam_dbg_err("get user buffer fd failed 0x%x, number %d", err, fd_number);
+                       return err;
+               }
+
+               /*
+               for (i = 0 ; i < fd_number ; i++)
+                       _mmcam_dbg_log("fds[%d] %d", i, fds[i]);
+               */
+       }
+
        /* Get fourcc from picture format */
        sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
 
@@ -294,6 +312,15 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
        /* Set video device index */
        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
 
+       /* set user buffer fd to videosrc element */
+       if (hcamcorder->support_user_buffer) {
+               control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+               if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
+                       _mmcam_dbg_err("set user buffer fd failed");
+                       goto pipeline_creation_error;
+               }
+       }
+
        /* make demux and decoder for H264 stream from videosrc */
        if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
                int preview_bitrate = 0;
index eff03e1..a4ab29d 100644 (file)
@@ -403,13 +403,19 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
                "UseZeroCopyFormat",
-               &(hcamcorder->use_zero_copy_format));
+               &hcamcorder->use_zero_copy_format);
+
+       /* Get SupportUserBuffer value from INI */
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+               "SupportUserBuffer",
+               &hcamcorder->support_user_buffer);
 
        /* Get SupportMediaPacketPreviewCb value from INI */
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
                "SupportMediaPacketPreviewCb",
-               &(hcamcorder->support_media_packet_preview_cb));
+               &hcamcorder->support_media_packet_preview_cb);
 
        /* Get UseVideoconvert value from INI */
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
@@ -424,8 +430,10 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
 
        mm_camcorder_get_fps_list_by_resolution((MMHandleType)hcamcorder, resolution_width, resolution_height, &fps_info);
 
-       _mmcam_dbg_log("UseZeroCopyFormat %d, UseVideoconvert %d, SupportMediaPacketPreviewCb %d",
-               hcamcorder->use_zero_copy_format, hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb);
+       _mmcam_dbg_log("ZeroCopy %d, UserBuffer %d, Videoconvert %d, MPPreviewCb %d",
+               hcamcorder->use_zero_copy_format, hcamcorder->support_user_buffer,
+               hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb);
+
        _mmcam_dbg_log("res : %d X %d, Default FPS by resolution  : %d",
                resolution_width, resolution_height, fps_info.int_array.def);
 
@@ -447,6 +455,7 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
                MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
                MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
+               MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
                MMCAM_CAMERA_FPS, fps_info.int_array.def,
                MMCAM_DISPLAY_FLIP, camera_default_flip,
                MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,