webrtc_source_mediapacket: move _set_media_format() to webrtc_source_mediapacket.c 00/278800/3
authorhj kim <backto.kim@samsung.com>
Tue, 26 Jul 2022 07:35:19 +0000 (16:35 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 26 Jul 2022 08:33:49 +0000 (17:33 +0900)
Plus, remove some mediapacket internal APIs from webrtc_private.h and add static keyword.

[Version] 0.3.176
[Issue Type] Refactoring

Change-Id: I81f958dbc33a600075295ee558ce5a377a9d7045

include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_source.c
src/webrtc_source_mediapacket.c

index 95668b1fa1df991256255fd68f28cd1fb6aa111f..7e9886816c60116ab22b2d04b3a1c50cf9e7a7e2 100644 (file)
@@ -650,11 +650,9 @@ void _remove_rest_of_elements_for_filesrc_pipeline(webrtc_gst_slot_s *source, bo
 
 /* media packet source */
 int _build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source);
-int _complete_rest_of_mediapacketsrc(webrtc_gst_slot_s *source, GstPad **src_pad, GstElement *appsrc, GList *element_list);
-int _complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source);
 GstCaps *_make_mediapacketsrc_raw_caps_from_media_format(webrtc_gst_slot_s *source);
 int _push_media_packet(webrtc_s *webrtc, unsigned int source_id, media_packet_h packet);
-int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_type);
+int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format);
 
 /* screen source */
 int _get_screen_resolution(int *width, int *height);
@@ -695,7 +693,6 @@ int _unset_audio_loopback(webrtc_s *webrtc, unsigned int source_id);
 int _set_video_loopback(webrtc_s *webrtc, unsigned int source_id, unsigned int type, void *display, unsigned int *track_id);
 int _unset_video_loopback(webrtc_s *webrtc, unsigned int source_id);
 int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_stream_info_h stream_info);
-int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format);
 int _set_media_path(webrtc_s *webrtc, unsigned int source_id, const char *path);
 
 /* sink */
index 6bde943d87ac83bed00f169193285c664ec87ee1..03c95751f9b5d955ef5e9a5e14a1339d00b166a0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.175
+Version:    0.3.176
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 4451bac4b4f54ccb7fbcb747416840aba07229a3..b93798157ee595a8d063a84e8efbfaed8a21db1b 100644 (file)
@@ -1495,112 +1495,6 @@ int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_strea
        return _apply_stream_info(element, stream_type, stream_index, aec_ref_device_id);
 }
 
-static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gst_slot_s *source)
-{
-       int ret;
-       GstPad **src_pad;
-       GstElement *appsrc;
-       GList *element_list = NULL;
-       GstCaps *sink_caps;
-
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
-       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
-
-       src_pad = &source->av[GET_AV_IDX_BY_TYPE(source->media_types)].src_pad;
-       ret = _add_no_target_ghostpad_to_slot(source, true, src_pad);
-       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
-
-       appsrc = _find_element_in_bin(source->bin, "appsrc");
-       RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL");
-
-       source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types);
-
-       if ((ret = _create_rest_of_elements(webrtc, source, false, &element_list, (source->media_types == MEDIA_TYPE_AUDIO))) != WEBRTC_ERROR_NONE)
-               goto exit;
-
-       if (!(sink_caps = _make_mediapacketsrc_raw_caps_from_media_format(source))) {
-               ret = WEBRTC_ERROR_INVALID_OPERATION;
-               goto exit;
-       }
-       PRINT_CAPS(sink_caps, "appsrc");
-       g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL);
-       gst_caps_unref(sink_caps);
-
-       if ((ret = _complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE)
-               goto exit;
-
-       SAFE_G_LIST_FREE(element_list);
-
-       return WEBRTC_ERROR_NONE;
-
-exit:
-       SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref);
-       return ret;
-}
-
-int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format)
-{
-       int ret;
-       webrtc_gst_slot_s *source;
-       media_format_type_e format_type;
-       media_format_mimetype_e mime_type;
-
-       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
-       RET_VAL_IF(format == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "format 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");
-       RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid media source type(%d)", source->type);
-       RET_VAL_IF(source->media_format != NULL, WEBRTC_ERROR_INVALID_OPERATION, "format is already set to this media packet source");
-
-       RET_VAL_IF(media_format_get_type(format, &format_type) != MEDIA_FORMAT_ERROR_NONE, WEBRTC_ERROR_INVALID_OPERATION,
-               "failed to media_format_get_type()");
-
-       if (format_type == MEDIA_FORMAT_AUDIO) {
-               source->media_types = MEDIA_TYPE_AUDIO;
-               RET_VAL_IF(media_format_get_audio_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
-                       WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_audio_info()");
-
-       } else if (format_type == MEDIA_FORMAT_VIDEO) {
-               source->media_types = MEDIA_TYPE_VIDEO;
-               RET_VAL_IF(media_format_get_video_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
-                       WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_video_info()");
-
-       } else {
-               LOG_ERROR("invalid media format type[0x%x]", format_type);
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
-
-       RET_VAL_IF(!_is_supported_mime_type(mime_type), WEBRTC_ERROR_INVALID_PARAMETER, "mime_type[0x%x] is not supported", mime_type);
-
-       media_format_ref(format);
-       source->media_format = format;
-       if((ret = _set_mediapacketsrc_codec_info(webrtc, source, mime_type)) != WEBRTC_ERROR_NONE)
-               goto error;
-
-       if ((mime_type & MEDIA_FORMAT_RAW) &&
-               !(mime_type == MEDIA_FORMAT_PCMU || mime_type == MEDIA_FORMAT_PCMA)) /* FIXME: media_format.h defined PCMU/PCMA as a raw format, it's a bug. */
-               ret = __complete_mediapacketsrc_from_raw_format(webrtc, source);
-       else
-               ret = _complete_mediapacketsrc_from_encoded_format(webrtc, source);
-       if (ret != WEBRTC_ERROR_NONE) {
-               LOG_ERROR("failed to complete mediapacketsrc");
-               goto error;
-       }
-
-       ret = _link_source_with_webrtcbin(source, webrtc->gst.webrtcbin);
-       if (ret != WEBRTC_ERROR_NONE)
-               goto error;
-
-       LOG_INFO("webrtc[%p] source_id[%u] format[%p]", webrtc, source_id, format);
-
-       return WEBRTC_ERROR_NONE;
-
-error:
-       media_format_unref(format);
-       source->media_format = NULL;
-       return ret;
-}
-
 static gboolean __check_format_is_not_set_cb(gpointer key, gpointer value, gpointer user_data)
 {
        const webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value;
index e2da456738dd0a6687cd928a2111bc39c58381e3..e9e488a42bbe174f206cc08d0a03e4c9db0b4b00 100644 (file)
@@ -553,7 +553,7 @@ int _build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 }
 
-int _complete_rest_of_mediapacketsrc(webrtc_gst_slot_s *source, GstPad **src_pad, GstElement *appsrc, GList *element_list)
+static int __complete_rest_of_mediapacketsrc(webrtc_gst_slot_s *source, GstPad **src_pad, GstElement *appsrc, GList *element_list)
 {
        int ret;
        GstElement *capsfilter;
@@ -589,7 +589,7 @@ error:
 }
 
 //LCOV_EXCL_START
-int _complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source)
+static int __complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
        int ret;
        GstPad **src_pad;
@@ -620,7 +620,7 @@ int _complete_mediapacketsrc_from_encoded_format(webrtc_s *webrtc, webrtc_gst_sl
        g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL);
        gst_caps_unref(sink_caps);
 
-       if ((ret = _complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE)
+       if ((ret = __complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE)
                goto exit;
 
        SAFE_G_LIST_FREE(element_list);
@@ -633,7 +633,7 @@ exit:
 }
 //LCOV_EXCL_STOP
 
-int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_type)
+static int __set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source, media_format_mimetype_e mime_type)
 {
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
@@ -665,3 +665,109 @@ int _set_mediapacketsrc_codec_info(webrtc_s *webrtc, webrtc_gst_slot_s *source,
 
        return WEBRTC_ERROR_NONE;
 }
+
+static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gst_slot_s *source)
+{
+       int ret;
+       GstPad **src_pad;
+       GstElement *appsrc;
+       GList *element_list = NULL;
+       GstCaps *sink_caps;
+
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+       RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
+
+       src_pad = &source->av[GET_AV_IDX_BY_TYPE(source->media_types)].src_pad;
+       ret = _add_no_target_ghostpad_to_slot(source, true, src_pad);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
+
+       appsrc = _find_element_in_bin(source->bin, "appsrc");
+       RET_VAL_IF(appsrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "appsrc is NULL");
+
+       source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types);
+
+       if ((ret = _create_rest_of_elements(webrtc, source, false, &element_list, (source->media_types == MEDIA_TYPE_AUDIO))) != WEBRTC_ERROR_NONE)
+               goto exit;
+
+       if (!(sink_caps = _make_mediapacketsrc_raw_caps_from_media_format(source))) {
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit;
+       }
+       PRINT_CAPS(sink_caps, "appsrc");
+       g_object_set(G_OBJECT(appsrc), "caps", sink_caps, NULL);
+       gst_caps_unref(sink_caps);
+
+       if ((ret = __complete_rest_of_mediapacketsrc(source, src_pad, appsrc, element_list)) != WEBRTC_ERROR_NONE)
+               goto exit;
+
+       SAFE_G_LIST_FREE(element_list);
+
+       return WEBRTC_ERROR_NONE;
+
+exit:
+       SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref);
+       return ret;
+}
+
+int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format)
+{
+       int ret;
+       webrtc_gst_slot_s *source;
+       media_format_type_e format_type;
+       media_format_mimetype_e mime_type;
+
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(format == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "format 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");
+       RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid media source type(%d)", source->type);
+       RET_VAL_IF(source->media_format != NULL, WEBRTC_ERROR_INVALID_OPERATION, "format is already set to this media packet source");
+
+       RET_VAL_IF(media_format_get_type(format, &format_type) != MEDIA_FORMAT_ERROR_NONE, WEBRTC_ERROR_INVALID_OPERATION,
+               "failed to media_format_get_type()");
+
+       if (format_type == MEDIA_FORMAT_AUDIO) {
+               source->media_types = MEDIA_TYPE_AUDIO;
+               RET_VAL_IF(media_format_get_audio_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
+                       WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_audio_info()");
+
+       } else if (format_type == MEDIA_FORMAT_VIDEO) {
+               source->media_types = MEDIA_TYPE_VIDEO;
+               RET_VAL_IF(media_format_get_video_info(format, &mime_type, NULL, NULL, NULL, NULL) != MEDIA_FORMAT_ERROR_NONE,
+                       WEBRTC_ERROR_INVALID_OPERATION, "failed to media_format_get_video_info()");
+
+       } else {
+               LOG_ERROR("invalid media format type[0x%x]", format_type);
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
+
+       RET_VAL_IF(!_is_supported_mime_type(mime_type), WEBRTC_ERROR_INVALID_PARAMETER, "mime_type[0x%x] is not supported", mime_type);
+
+       media_format_ref(format);
+       source->media_format = format;
+       if((ret = __set_mediapacketsrc_codec_info(webrtc, source, mime_type)) != WEBRTC_ERROR_NONE)
+               goto error;
+
+       if ((mime_type & MEDIA_FORMAT_RAW) &&
+               !(mime_type == MEDIA_FORMAT_PCMU || mime_type == MEDIA_FORMAT_PCMA)) /* FIXME: media_format.h defined PCMU/PCMA as a raw format, it's a bug. */
+               ret = __complete_mediapacketsrc_from_raw_format(webrtc, source);
+       else
+               ret = __complete_mediapacketsrc_from_encoded_format(webrtc, source);
+       if (ret != WEBRTC_ERROR_NONE) {
+               LOG_ERROR("failed to complete mediapacketsrc");
+               goto error;
+       }
+
+       ret = _link_source_with_webrtcbin(source, webrtc->gst.webrtcbin);
+       if (ret != WEBRTC_ERROR_NONE)
+               goto error;
+
+       LOG_INFO("webrtc[%p] source_id[%u] format[%p]", webrtc, source_id, format);
+
+       return WEBRTC_ERROR_NONE;
+
+error:
+       media_format_unref(format);
+       source->media_format = NULL;
+       return ret;
+}