From: Sangchul Lee Date: Wed, 8 Jun 2022 06:10:58 +0000 (+0900) Subject: webrtc_source: Save video framerate/width/height value if required element does not... X-Git-Tag: submit/tizen/20220613.225802~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f59128c1d93be75c0cad71533e87ffbb53a0485;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Save video framerate/width/height value if required element does not exist This is a preparation for setting option values regardless of elements creation or linking pads. [Version] 0.3.118 [Issue Type] Improvement Change-Id: I500ff6058f8bd4de4b7ebbea16b2cf82cfede4ef Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index f14be079..1f4ef8e3 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.3.117 +Version: 0.3.118 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index b96d38d6..307f008d 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -289,16 +289,18 @@ static GstCaps *__make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source, switch (source->type) { case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: - case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: + case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: { + int framerate = source->video_info.framerate > 0 ? source->video_info.framerate : ini_source->v_framerate; caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, "format", G_TYPE_STRING, ini_source->v_raw_format, - "framerate", GST_TYPE_FRACTION, source->video_info.framerate, 1, + "framerate", GST_TYPE_FRACTION, framerate, 1, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL); source->video_info.width = width; source->video_info.height = height; break; + } default: LOG_ERROR_IF_REACHED("type(%d)", source->type); break; @@ -322,15 +324,18 @@ static GstCaps *__make_video_raw_caps_with_framerate(webrtc_gst_slot_s *source, switch (source->type) { case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: - case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: + case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: { + int width = source->video_info.width > 0 ? source->video_info.width : ini_source->v_width; + int height = source->video_info.height > 0 ? source->video_info.height : ini_source->v_height; caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, "format", G_TYPE_STRING, ini_source->v_raw_format, "framerate", GST_TYPE_FRACTION, framerate, 1, - "width", G_TYPE_INT, source->video_info.width, - "height", G_TYPE_INT, source->video_info.height, + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, NULL); source->video_info.framerate = framerate; break; + } default: LOG_ERROR_IF_REACHED("type(%d)", source->type); break; @@ -405,18 +410,19 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST: case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA: case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: - case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO: + case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO: { + source->video_info.framerate = source->video_info.framerate > 0 ? source->video_info.framerate : ini_source->v_framerate; + source->video_info.width = source->video_info.width > 0 ? source->video_info.width : ini_source->v_width; + source->video_info.height = source->video_info.height > 0 ? source->video_info.height : ini_source->v_height; + caps = gst_caps_new_simple(MEDIA_TYPE_VIDEO_RAW, "format", G_TYPE_STRING, ini_source->v_raw_format, - "framerate", GST_TYPE_FRACTION, ini_source->v_framerate, 1, - "width", G_TYPE_INT, ini_source->v_width, - "height", G_TYPE_INT, ini_source->v_height, + "framerate", GST_TYPE_FRACTION, source->video_info.framerate, 1, + "width", G_TYPE_INT, source->video_info.width, + "height", G_TYPE_INT, source->video_info.height, NULL); - source->video_info.width = ini_source->v_width; - source->video_info.height = ini_source->v_height; - source->video_info.framerate = ini_source->v_framerate; break; - + } case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST: case WEBRTC_MEDIA_SOURCE_TYPE_MIC: case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO: @@ -511,11 +517,12 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO: _media_type = __get_video_media_type(ini_source->v_codec); RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL"); - caps = __get_caps_from_encoded_video_media_type(_media_type, ini_source->v_width, ini_source->v_height); - source->video_info.width = ini_source->v_width; - source->video_info.height = ini_source->v_height; - source->video_info.framerate = ini_source->v_framerate; + source->video_info.width = source->video_info.width > 0 ? source->video_info.width : ini_source->v_width; + source->video_info.height = source->video_info.height > 0 ? source->video_info.height : ini_source->v_height; + source->video_info.framerate = source->video_info.framerate > 0 ? source->video_info.framerate : ini_source->v_framerate; + + caps = __get_caps_from_encoded_video_media_type(_media_type, source->video_info.width, source->video_info.height); break; case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST: @@ -2903,17 +2910,21 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i RET_VAL_IF(!ini_source->v_drc_support, WEBRTC_ERROR_INVALID_OPERATION, "not supported dynamic resolution change"); } - capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER); - RET_VAL_IF(capsfilter == NULL, WEBRTC_ERROR_INVALID_OPERATION, "could not find the first capsfilter"); + if ((capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER))) { + /* FIXME: check if the [width x height] is supported or not */ + if (!(new_caps = __make_video_raw_caps_with_resolution(source, &webrtc->ini, width, height))) + return WEBRTC_ERROR_INVALID_OPERATION; + PRINT_CAPS(new_caps, "capsfilter"); - /* FIXME: check if the [width x height] is supported or not */ - if (!(new_caps = __make_video_raw_caps_with_resolution(source, &webrtc->ini, width, height))) - return WEBRTC_ERROR_INVALID_OPERATION; + g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL); + gst_caps_unref(new_caps); - PRINT_CAPS(new_caps, "capsfilter"); + } else { + source->video_info.width = width; + source->video_info.height = height; + } - g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL); - gst_caps_unref(new_caps); + LOG_INFO("webrtc[%p], source_id[%u], [%dx%d]", webrtc, source_id, width, height); return WEBRTC_ERROR_NONE; } @@ -2943,7 +2954,6 @@ int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate webrtc_gst_slot_s *source; GstElement *capsfilter; GstCaps *new_caps = NULL; - gchar *caps_str; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); @@ -2955,18 +2965,19 @@ int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate RET_VAL_IF(webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_OPERATION, "for now, it is only supported in IDLE state"); /* FIXME: check if the framerate is supported or not */ - capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER); - RET_VAL_IF(capsfilter == NULL, WEBRTC_ERROR_INVALID_OPERATION, "could not find the first capsfilter"); + if ((capsfilter = __find_element_in_bin(source->bin, ELEMENT_NAME_FIRST_CAPSFILTER))) { + if (!(new_caps = __make_video_raw_caps_with_framerate(source, &webrtc->ini, framerate))) + return WEBRTC_ERROR_INVALID_OPERATION; + PRINT_CAPS(new_caps, "capsfilter"); - if (!(new_caps = __make_video_raw_caps_with_framerate(source, &webrtc->ini, framerate))) - return WEBRTC_ERROR_INVALID_OPERATION; + g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL); + gst_caps_unref(new_caps); - caps_str = gst_caps_to_string(new_caps); - LOG_INFO("capsfilter caps[%s]", caps_str); - g_free(caps_str); + } else { + source->video_info.framerate = framerate; + } - g_object_set(G_OBJECT(capsfilter), "caps", new_caps, NULL); - gst_caps_unref(new_caps); + LOG_INFO("webrtc[%p], source_id[%u], framerate[%d]", webrtc, source_id, framerate); return WEBRTC_ERROR_NONE; }