[Release version 0.10.44] Set stride field for non-zero copy stream
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_gstcommon.c
index 8f0da1d..87b0682 100644 (file)
@@ -400,6 +400,9 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        char *err_name = NULL;
        const char *audiosrc_name = NULL;
        char *cat_name = NULL;
+       char *stream_type = NULL;
+       char stream_type_len = 0;
+       int stream_index = 0;
 
        GstCaps *caps = NULL;
        GstPad *pad = NULL;
@@ -424,14 +427,16 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        }
 
        err = mm_camcorder_get_attributes(handle, &err_name,
-                                         MMCAM_AUDIO_DEVICE, &a_dev,
-                                         MMCAM_AUDIO_ENCODER, &a_enc,
-                                         MMCAM_AUDIO_ENCODER_BITRATE, &val,
-                                         MMCAM_AUDIO_SAMPLERATE, &rate,
-                                         MMCAM_AUDIO_FORMAT, &format,
-                                         MMCAM_AUDIO_CHANNEL, &channel,
-                                         MMCAM_AUDIO_VOLUME, &volume,
-                                         NULL);
+               MMCAM_AUDIO_DEVICE, &a_dev,
+               MMCAM_AUDIO_ENCODER, &a_enc,
+               MMCAM_AUDIO_ENCODER_BITRATE, &val,
+               MMCAM_AUDIO_SAMPLERATE, &rate,
+               MMCAM_AUDIO_FORMAT, &format,
+               MMCAM_AUDIO_CHANNEL, &channel,
+               MMCAM_AUDIO_VOLUME, &volume,
+               MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
+               MMCAM_SOUND_STREAM_INDEX, &stream_index,
+               NULL);
        if (err != MM_ERROR_NONE) {
                _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
                SAFE_FREE(err_name);
@@ -475,6 +480,10 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
 
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
 
+       /* set sound stream info */
+       _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
+
+       /* set audiosrc properties in ini configuration */
        _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
 
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_FILT, "capsfilter", "audiosrc_capsfilter", element_list, err);
@@ -661,26 +670,31 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "max-bytes", 0); /* unlimited */
 
                /* set capsfilter */
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       _mmcam_dbg_log("get pad from videosrc_filter");
-                       pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
+               if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
+                       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+                               _mmcam_dbg_log("get pad from videosrc_filter");
+                               pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
+                       } else {
+                               _mmcam_dbg_log("get pad from videosrc_que");
+                               pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
+                       }
+                       if (!pad) {
+                               _mmcam_dbg_err("get videosrc_que src pad failed");
+                               err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
+                               goto pipeline_creation_error;
+                       }
+
+                       caps_from_pad = gst_pad_get_allowed_caps(pad);
+                       video_caps = gst_caps_copy(caps_from_pad);
+                       gst_caps_unref(caps_from_pad);
+                       caps_from_pad = NULL;
+                       gst_object_unref(pad);
+                       pad = NULL;
                } else {
-                       _mmcam_dbg_log("get pad from videosrc_que");
-                       pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
-               }
-               if (!pad) {
-                       _mmcam_dbg_err("get videosrc_que src pad failed");
-                       err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
-                       goto pipeline_creation_error;
+                       /* Image */
+                       MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
                }
 
-               caps_from_pad = gst_pad_get_allowed_caps(pad);
-               video_caps = gst_caps_copy(caps_from_pad);
-               gst_caps_unref(caps_from_pad);
-               caps_from_pad = NULL;
-               gst_object_unref(pad);
-               pad = NULL;
-
                if (video_caps) {
                        char *caps_str = NULL;
 
@@ -784,7 +798,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                }
 
                if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       gst_element_venc_name = strdup("capsfilter");
+                       gst_element_venc_name = "capsfilter";
                } else {
                        _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
                }
@@ -839,11 +853,6 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                if (use_venc_queue) {
                        _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC_QUE, "use-venc-queue", err);
                }
-
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       free(gst_element_venc_name);
-                       gst_element_venc_name = NULL;
-               }
        }
 
        if (sc->audio_disable == FALSE &&
@@ -1266,8 +1275,8 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        } else if (!strcmp(videosink_name, "waylandsink")) {
                MMCamWaylandInfo *wl_info = (MMCamWaylandInfo *)overlay;
                if (wl_info) {
-                       _mmcam_dbg_log("parent id : %d", wl_info->parent_id);
-                       gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)wl_info->parent_id);
+                       _mmcam_dbg_log("wayland global surface id : %d", wl_info->global_surface_id);
+                       gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), (guintptr)wl_info->global_surface_id);
                        gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
                                wl_info->window_x, wl_info->window_y, wl_info->window_width, wl_info->window_height);
                } else {
@@ -1585,6 +1594,10 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
                                        stream.data.yuv420sp.length_y = stream.width * stream.height;
                                        stream.data.yuv420sp.uv = stream.data.yuv420sp.y + stream.data.yuv420sp.length_y;
                                        stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1;
+                                       stream.stride[0] = stream.width;
+                                       stream.elevation[0] = stream.height;
+                                       stream.stride[1] = stream.width;
+                                       stream.elevation[1] = stream.height >> 1;
                                        /*
                                        _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:0x%x,size:%d [UV]p:0x%x,size:%d",
                                                       stream.format, stream.num_planes,
@@ -1600,6 +1613,12 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
                                        stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2;
                                        stream.data.yuv420p.v = stream.data.yuv420p.u + stream.data.yuv420p.length_u;
                                        stream.data.yuv420p.length_v = stream.data.yuv420p.length_u;
+                                       stream.stride[0] = stream.width;
+                                       stream.elevation[0] = stream.height;
+                                       stream.stride[1] = stream.width >> 1;
+                                       stream.elevation[1] = stream.height >> 1;
+                                       stream.stride[2] = stream.width >> 1;
+                                       stream.elevation[2] = stream.height >> 1;
                                        /*
                                        _mmcam_dbg_log("I420[num_planes:%d] [Y]p:0x%x,size:%d [U]p:0x%x,size:%d [V]p:0x%x,size:%d",
                                                        stream.num_planes,
@@ -1622,6 +1641,8 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
                                stream.data_type = MM_CAM_STREAM_DATA_YUV422;
                                stream.data.yuv422.yuv = mapinfo.data;
                                stream.data.yuv422.length_yuv = stream.length_total;
+                               stream.stride[0] = stream.width << 1;
+                               stream.elevation[0] = stream.height;
                        } else if (stream.format == MM_PIXEL_FORMAT_ENCODED_H264) {
                                        stream.data_type = MM_CAM_STREAM_DATA_ENCODED;
                                        stream.data.encoded.data = mapinfo.data;
@@ -1633,6 +1654,8 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
                                stream.data_type = MM_CAM_STREAM_DATA_YUV420;
                                stream.data.yuv420.yuv = mapinfo.data;
                                stream.data.yuv420.length_yuv = stream.length_total;
+                               stream.stride[0] = (stream.width * 3) >> 1;
+                               stream.elevation[0] = stream.height;
                        }
 
                        stream.num_planes = 1;
@@ -2551,3 +2574,35 @@ bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int inte
 
        return TRUE;
 }
+
+
+bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type, int stream_index)
+{
+       GstStructure *props = NULL;
+       char stream_props[64] = {'\0',};
+
+       if (element == NULL || stream_type == NULL || stream_index < 0) {
+               _mmcam_dbg_err("invalid argument %p %p %d", element, stream_type, stream_index);
+               return FALSE;
+       }
+
+       snprintf(stream_props, sizeof(stream_props) - 1,
+               "props,media.role=%s, media.parent_id=%d",
+               stream_type, stream_index);
+
+       _mmcam_dbg_log("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
+
+       props = gst_structure_from_string(stream_props, NULL);
+       if (!props) {
+               _mmcam_dbg_err("failed to create GstStructure");
+               return FALSE;
+       }
+
+       MMCAMCORDER_G_OBJECT_SET_POINTER(element, "stream-properties", props);
+
+       gst_structure_free(props);
+       props = NULL;
+
+       return TRUE;
+}
+