Fix failure for setting attribute on 64bit environment
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_gstcommon.c
index 914020e..317bb6b 100644 (file)
@@ -371,7 +371,7 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
 
                g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
        } else {
-               if (hcamcorder->use_videoconvert && !strcmp(videosink_name, "waylandsink")) {
+               if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "directvideosink"))) {
                        /* get video convert name */
                        _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
 
@@ -669,10 +669,55 @@ pipeline_creation_error:
 }
 
 
+void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, int bitrate, GstElement *element)
+{
+       int set_value = 0;
+
+       if (!element) {
+               _mmcam_dbg_warn("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
+               return;
+       }
+
+       if (bitrate <= 0) {
+               _mmcam_dbg_warn("[type %d, codec %d] too small bitrate[%d], use default",
+                       type, codec, bitrate);
+               return;
+       }
+
+       if (type == MM_CAMCORDER_ENCODER_TYPE_AUDIO) {
+               /* audio encoder bitrate setting */
+               switch (codec) {
+               case MM_AUDIO_CODEC_AMR:
+                       set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
+                       _mmcam_dbg_log("Set AMR encoder mode [%d]", set_value);
+                       MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
+                       break;
+               case MM_AUDIO_CODEC_MP3:
+                       set_value = bitrate / 1000;
+                       _mmcam_dbg_log("Set MP3 encoder bitrate [%d] kbps", set_value);
+                       MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
+                       break;
+               case MM_AUDIO_CODEC_AAC:
+                       _mmcam_dbg_log("Set AAC encoder bitrate [%d] bps", bitrate);
+                       MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
+                       break;
+               default:
+                       _mmcam_dbg_warn("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
+                       break;
+               }
+       } else {
+               /* video encoder bitrate setting */
+               _mmcam_dbg_log("Set video encoder bitrate %d", bitrate);
+               MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
+       }
+
+       return;
+}
+
+
 int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebinProfile profile)
 {
        int err = MM_ERROR_NONE;
-       int result = 0;
        int channel = 0;
        int audio_enc = 0;
        int v_bitrate = 0;
@@ -1021,39 +1066,22 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        }
 
        if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
-               /* video encoder attribute setting */
-               if (v_bitrate > 0) {
-                       MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, "bitrate", v_bitrate);
-               } else {
-                       _mmcam_dbg_warn("video bitrate is too small[%d], so skip setting. Use DEFAULT value.", v_bitrate);
-               }
-
+               /* property setting in ini */
                _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, VideoencElement);
+
+               /* bitrate setting */
+               _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_VIDEO, 0,
+                       v_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
        }
 
        if (sc->audio_disable == FALSE &&
            profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
-               /* audio encoder attribute setting */
-               if (a_bitrate > 0) {
-                       switch (audio_enc) {
-                       case MM_AUDIO_CODEC_AMR:
-                               result = __mmcamcorder_get_amrnb_bitrate_mode(a_bitrate);
-                               _mmcam_dbg_log("Set AMR encoder[%s] mode [%d]", gst_element_aenc_name, result);
-                               MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, "band-mode", result);
-                               break;
-                       case MM_AUDIO_CODEC_AAC:
-                               _mmcam_dbg_log("Set AAC encoder[%s] bitrate [%d]", gst_element_aenc_name, a_bitrate);
-                               MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, "bitrate", a_bitrate);
-                               break;
-                       default:
-                               _mmcam_dbg_log("Audio codec is not AMR or AAC... you need to implement setting function for audio encoder bit-rate");
-                               break;
-                       }
-               } else {
-                       _mmcam_dbg_warn("Setting bitrate is too small, so skip setting. Use DEFAULT value.");
-               }
-
+               /* property setting in ini */
                _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, AudioencElement);
+
+               /* bitrate setting */
+               _mmcamcorder_set_encoder_bitrate(MM_CAMCORDER_ENCODER_TYPE_AUDIO, audio_enc,
+                       a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
        }
 
        _mmcam_dbg_log("Element creation complete");
@@ -1257,10 +1285,10 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
 {
        int err = MM_ERROR_NONE;
        int size = 0;
-       int retx = 0;
-       int rety = 0;
-       int retwidth = 0;
-       int retheight = 0;
+       int rect_x = 0;
+       int rect_y = 0;
+       int rect_width = 0;
+       int rect_height = 0;
        int visible = 0;
        int rotation = MM_DISPLAY_ROTATION_NONE;
        int flip = MM_FLIP_NONE;
@@ -1296,10 +1324,10 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
 
        /* Get video display information */
        err = mm_camcorder_get_attributes(handle, &err_name,
-               MMCAM_DISPLAY_RECT_X, &retx,
-               MMCAM_DISPLAY_RECT_Y, &rety,
-               MMCAM_DISPLAY_RECT_WIDTH, &retwidth,
-               MMCAM_DISPLAY_RECT_HEIGHT, &retheight,
+               MMCAM_DISPLAY_RECT_X, &rect_x,
+               MMCAM_DISPLAY_RECT_Y, &rect_y,
+               MMCAM_DISPLAY_RECT_WIDTH, &rect_width,
+               MMCAM_DISPLAY_RECT_HEIGHT, &rect_height,
                MMCAM_DISPLAY_ROTATION, &rotation,
                MMCAM_DISPLAY_FLIP, &flip,
                MMCAM_DISPLAY_VISIBLE, &visible,
@@ -1351,7 +1379,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                        _mmcam_dbg_err("display handle(eavs object) is NULL");
                        return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
                }
-       } else if (!strcmp(videosink_name, "waylandsink")) {
+       } else if (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "directvideosink")) {
                MMCamWaylandInfo *wl_info = (MMCamWaylandInfo *)overlay;
 
                if (wl_info) {
@@ -1359,12 +1387,6 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                        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);
-#ifdef _MMCAMCORDER_RM_SUPPORT
-                       if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
-                               display_scaler = 1;
-
-                       MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", display_scaler);
-#endif /* _MMCAMCORDER_RM_SUPPORT */
                } else {
                        _mmcam_dbg_warn("Handle is NULL. skip setting.");
                }
@@ -1377,7 +1399,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
 
        /* Set attribute */
        if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "waylandsink") ||
-           !strcmp(videosink_name, "evaspixmapsink")) {
+           !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
                /* set rotation */
                MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
 
@@ -1406,12 +1428,17 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                MMCAMCORDER_G_OBJECT_SET(vsink, "zoom", zoom_level);
 
                if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) {
-                       g_object_set(vsink,
-                               "dst-roi-x", retx,
-                               "dst-roi-y", rety,
-                               "dst-roi-w", retwidth,
-                               "dst-roi-h", retheight,
-                               NULL);
+                       if (!strcmp(videosink_name, "waylandsink")) {
+                           gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
+                                       rect_x, rect_y, rect_width, rect_height);
+                       } else {
+                               g_object_set(vsink,
+                                       "dst-roi-x", rect_x,
+                                       "dst-roi-y", rect_y,
+                                       "dst-roi-w", rect_width,
+                                       "dst-roi-h", rect_height,
+                                       NULL);
+                       }
                }
        }
 
@@ -1805,7 +1832,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(Gst
        /* push buffer in appsrc to encode */
        if (!sc->info_video) {
                _mmcam_dbg_warn("sc->info_video is NULL!!");
-               return FALSE;
+               return GST_PAD_PROBE_DROP;
        }
 
        if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_RUN &&
@@ -1995,6 +2022,43 @@ void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int
 }
 
 
+int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, int codec, int file_format)
+{
+       mmf_return_val_if_fail(codec_type, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       /* Check compatibility between codec and file format */
+       if (!strcmp(codec_type, MMCAM_AUDIO_ENCODER)) {
+               if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
+                       file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
+                       if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
+                               _mmcam_dbg_err("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
+                               return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
+                       }
+
+                       _mmcam_dbg_log("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
+               } else {
+                       _mmcam_dbg_err("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
+                       return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
+               }
+       } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
+               if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
+                       file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
+                       if (videocodec_fileformat_compatibility_table[ codec][file_format] == 0) {
+                               _mmcam_dbg_err("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
+                               return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
+                       }
+
+                       _mmcam_dbg_log("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
+               } else {
+                       _mmcam_dbg_err("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
+                       return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
+               }
+       }
+
+       return MM_ERROR_NONE;
+}
+
+
 int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
 {
        int err = MM_ERROR_NONE;
@@ -2004,9 +2068,9 @@ int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
        char *err_name = NULL;
 
        err = mm_camcorder_get_attributes(handle, &err_name,
-                                                                         MMCAM_AUDIO_ENCODER, &audio_codec,
-                                                                         MMCAM_FILE_FORMAT, &file_format,
-                                                                         NULL);
+               MMCAM_AUDIO_ENCODER, &audio_codec,
+               MMCAM_FILE_FORMAT, &file_format,
+               NULL);
        if (err != MM_ERROR_NONE) {
                _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
                SAFE_FREE(err_name);
@@ -2014,23 +2078,9 @@ int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
        }
 
        /* Check compatibility between audio codec and file format */
-       if (audio_codec > MM_AUDIO_CODEC_INVALID && audio_codec < MM_AUDIO_CODEC_NUM &&
-           file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
-               if (audiocodec_fileformat_compatibility_table[audio_codec][file_format] == 0) {
-                       _mmcam_dbg_err("Audio codec[%d] and file format[%d] compatibility FAILED.",
-                               audio_codec, file_format);
-                       return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
-               }
+       err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_AUDIO_ENCODER, audio_codec, file_format);
 
-               _mmcam_dbg_log("Audio codec[%d] and file format[%d] compatibility SUCCESS.",
-                       audio_codec, file_format);
-       } else {
-               _mmcam_dbg_err("Audio codec[%d] or file format[%d] is INVALID.",
-                       audio_codec, file_format);
-               return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
-       }
-
-       return MM_ERROR_NONE;
+       return err;
 }
 
 
@@ -2052,24 +2102,10 @@ int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
                return err;
        }
 
-       /* Check compatibility between audio codec and file format */
-       if (video_codec > MM_VIDEO_CODEC_INVALID && video_codec < MM_VIDEO_CODEC_NUM &&
-           file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
-               if (videocodec_fileformat_compatibility_table[video_codec][file_format] == 0) {
-                       _mmcam_dbg_err("Video codec[%d] and file format[%d] compatibility FAILED.",
-                               video_codec, file_format);
-                       return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
-               }
+       /* Check compatibility between video codec and file format */
+       err = _mmcamcorder_check_codec_fileformat_compatibility(MMCAM_VIDEO_ENCODER, video_codec, file_format);
 
-               _mmcam_dbg_log("Video codec[%d] and file format[%d] compatibility SUCCESS.",
-                       video_codec, file_format);
-       } else {
-               _mmcam_dbg_err("Video codec[%d] or file format[%d] is INVALID.",
-                       video_codec, file_format);
-               return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
-       }
-
-       return MM_ERROR_NONE;
+       return err;
 }
 
 
@@ -2096,7 +2132,8 @@ bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate,
                }
 
                if (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "xvimagesink") ||
-                       !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
+                       !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
+                       !strcmp(videosink_name, "directvideosink")) {
                        MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
                        _mmcam_dbg_log("Set display-rotate [%d] done.", display_rotate);
                        return TRUE;
@@ -2134,7 +2171,8 @@ bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int vi
                }
 
                if (!strcmp(videosink_name, "waylandsink") || !strcmp(videosink_name, "xvimagesink") ||
-                       !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
+                       !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
+                       !strcmp(videosink_name, "directvideosink")) {
                        MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
                        _mmcam_dbg_log("Set display flip [%d] done.", display_flip);
                        return TRUE;