From: hj kim Date: Mon, 5 Sep 2022 03:53:29 +0000 (+0900) Subject: webrtc_source_file: move file source related code to webrtc_source_file.c X-Git-Tag: accepted/tizen/unified/20220908.124830^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c7ac66b07fc7f0013f8acb1c1a0c7306734d197d;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source_file: move file source related code to webrtc_source_file.c [Version] 0.3.235 [Issue Type] Refactoring Change-Id: I2df68784dcb962533faa95c3661a99f12aec9f0a --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 34205f54..86912306 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -716,15 +716,14 @@ int _get_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_medi int _foreach_supported_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_media_source_supported_transceiver_codec_cb callback, void *user_data); /* file source */ +int _set_media_path(webrtc_s *webrtc, unsigned int source_id, const char *path); int _gst_filesrc_pipeline_set_state(webrtc_s *webrtc, GstState state); int _set_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool looping); int _get_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool *looping); int _remove_all_filesrc_pad_block_probes(webrtc_s *webrtc); -void _set_filesrc_media_types(webrtc_gst_slot_s *source, const char *path); int _build_filesrc_pipeline(webrtc_s *webrtc, webrtc_gst_slot_s *source); void _destroy_filesrc_pipeline(webrtc_gst_slot_s *source); -void _remove_rest_of_elements_for_filesrc_pipeline(webrtc_gst_slot_s *source); -void _remove_filesrc_pad_block_probe(webrtc_gst_slot_s *source, unsigned int av_idx); +bool _check_if_path_is_set_to_file_sources(webrtc_s *webrtc); /* media packet source */ int _build_mediapacketsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source); @@ -767,7 +766,6 @@ int _add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id); int _add_media_source_internal(webrtc_s *webrtc, int type, unsigned int *source_id); int _remove_media_source(webrtc_s *webrtc, unsigned int source_id); bool _check_if_codec_is_set_to_null_sources(webrtc_s *webrtc); -bool _check_if_path_is_set_to_file_sources(webrtc_s *webrtc); bool _check_if_format_is_set_to_packet_sources(webrtc_s *webrtc); int _set_pause(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool pause); int _get_pause(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool *paused); @@ -784,7 +782,6 @@ int _get_video_framerate(webrtc_s *webrtc, unsigned int source_id, int *framerat int _set_camera_device_id(webrtc_s *webrtc, unsigned int source_id, unsigned int device_id); int _get_camera_device_id(webrtc_s *webrtc, unsigned int source_id, unsigned int *device_id); int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_stream_info_h stream_info); -int _set_media_path(webrtc_s *webrtc, unsigned int source_id, const char *path); /* sink */ bool _is_owner_of_track_build_context(webrtc_s *webrtc, unsigned int track_id); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index bbbb2c10..01ce9a7d 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.234 +Version: 0.3.235 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index c763e0a8..6d568ae5 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -1196,143 +1196,6 @@ bool _check_if_codec_is_set_to_null_sources(webrtc_s *webrtc) return true; } -//LCOV_EXCL_START -static void __release_filesrc_resources(webrtc_gst_slot_s *source) -{ - GstElement *appsrc = NULL; - GstElement *queue = NULL; - GstElement *capsfilter = NULL; - int av_idx = 0; - - RET_IF(source == NULL, "source is NULL"); - RET_IF(source->bin == NULL, "bin is NULL"); - RET_IF(source->filesrc_pipeline == NULL, "filesrc_pipeline is NULL"); - - _release_request_pad(source); - - for (av_idx = 0; av_idx < AV_IDX_MAX; av_idx++) { - GList *element_list = NULL; - - if (source->av[av_idx].src_pad_probe_id == 0) - continue; - - _remove_probe_from_pad_for_pause(source, av_idx); - _remove_probe_from_pad_for_render(source, av_idx); - _remove_filesrc_pad_block_probe(source, av_idx); - - if (source->av[av_idx].pt > 0) - _return_payload_type(source->webrtc, source->av[av_idx].pt); - - _destroy_looopback_render_pipeline(source, av_idx); - - if ((appsrc = gst_bin_get_by_name(source->bin, _get_element_name(av_idx, ELEMENT_APPSRC)))) - APPEND_ELEMENT(element_list, appsrc); - else - LOG_ERROR("appsrc is NULL"); - - if ((queue = gst_bin_get_by_name(source->bin, _get_element_name(av_idx, ELEMENT_QUEUE)))) - APPEND_ELEMENT(element_list, queue); - else - LOG_ERROR("queue is NULL"); - - if ((capsfilter = gst_bin_get_by_name(source->bin, _get_element_name(av_idx, ELEMENT_CAPSFILTER)))) - APPEND_ELEMENT(element_list, capsfilter); - else - LOG_ERROR("capsfilter is NULL"); - - _remove_elements_from_bin(source->bin, element_list); - - SAFE_G_LIST_FREE(element_list); - } - - _remove_rest_of_elements_for_filesrc_pipeline(source); - - if (source->display) - _release_display(source->display); - - if (source->sound_stream_info.type) { - free(source->sound_stream_info.type); - source->sound_stream_info.type = NULL; - } - - source->media_types = 0; -} - -int _set_media_path(webrtc_s *webrtc, unsigned int source_id, const char *path) -{ - webrtc_gst_slot_s *source = NULL; - GstElement *filesrc = NULL; - gchar *location = NULL; - - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); - RET_VAL_IF(path == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "path 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_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); - - if (access(path, R_OK) < 0) { - if (errno == EACCES || errno == EPERM) { - LOG_ERROR("Fail to open path: Permission Denied [%s]", path); - return WEBRTC_ERROR_PERMISSION_DENIED; - } else { - LOG_ERROR("Fail to open path: Invalid Path [%s] errno[%d]", path, errno); - return WEBRTC_ERROR_INVALID_PARAMETER; - } - } - - filesrc = gst_bin_get_by_name(GST_BIN(source->filesrc_pipeline), ELEMENT_NAME_FILE_SRC); - RET_VAL_IF(filesrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "filesrc is NULL"); - - g_object_get(G_OBJECT(filesrc), "location", &location, NULL); - if (location) { - __release_filesrc_resources(source); - g_free(location); - source->media_types = 0; - } - - g_object_set(G_OBJECT(filesrc), "location", path, NULL); - - _set_filesrc_media_types(source, path); - - LOG_DEBUG("source_id[%u] path[%s]", source_id, path); - - return WEBRTC_ERROR_NONE; -} -//LCOV_EXCL_STOP - -static gboolean __check_path_is_not_set_cb(gpointer key, gpointer value, gpointer user_data) -{ - const webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; - gchar *location = NULL; - - if (source->type == GPOINTER_TO_INT(user_data)) { - LOG_INFO("found file source[%p, id:%u]", source, source->id); - g_object_get(G_OBJECT(gst_bin_get_by_name(GST_BIN(source->filesrc_pipeline), ELEMENT_NAME_FILE_SRC)), "location", &location, NULL); - - if (!location) - return TRUE; - - g_free(location); - } - - return FALSE; -} - -bool _check_if_path_is_set_to_file_sources(webrtc_s *webrtc) -{ - const webrtc_gst_slot_s *source; - - RET_VAL_IF(webrtc == NULL, false, "webrtc is NULL"); - - source = g_hash_table_find(webrtc->gst.source_slots, __check_path_is_not_set_cb, GINT_TO_POINTER(WEBRTC_MEDIA_SOURCE_TYPE_FILE)); - if (source) { - LOG_ERROR("media path is not set to the file source[%u]", source->id); - return false; - } - - return true; -} - //LCOV_EXCL_START static GstPadProbeReturn __camerasrc_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { diff --git a/src/webrtc_source_file.c b/src/webrtc_source_file.c index ac94706f..50285e05 100644 --- a/src/webrtc_source_file.c +++ b/src/webrtc_source_file.c @@ -19,107 +19,149 @@ #include "webrtc_private.h" #include "webrtc_source_private.h" -static void __set_filesrc_pipline_state_foreach_cb(gpointer key, gpointer value, gpointer user_data) +static void __remove_filesrc_pad_block_probe(webrtc_gst_slot_s *source, unsigned int av_idx) { - webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; - GstStateChangeReturn ret; - GstState state = GPOINTER_TO_UINT(user_data); + RET_IF(source == NULL, "source is NULL"); + RET_IF(av_idx >= AV_IDX_MAX, "invalid idx(%u)", av_idx); - if (source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE) + if (source->filesrc_av[av_idx].sink_pad_probe_id == 0) return; - LOG_INFO("found file source[%p, id:%u]", source, source->id); + LOG_DEBUG("source[id:%u] for[%s] pad[%p] probe_id[%lu]", source->id, GET_MEDIA_TYPE_NAME(av_idx == AV_IDX_AUDIO), + source->filesrc_av[av_idx].sink_pad, source->filesrc_av[av_idx].sink_pad_probe_id); - ret = gst_element_set_state(source->filesrc_pipeline, state); - if (ret == GST_STATE_CHANGE_FAILURE) { - LOG_ERROR("failed to gst_element_set_state(), state[%s]", gst_element_state_get_name(state)); + gst_pad_remove_probe(source->filesrc_av[av_idx].sink_pad, source->filesrc_av[av_idx].sink_pad_probe_id); + + source->filesrc_av[av_idx].sink_pad = NULL; + source->filesrc_av[av_idx].sink_pad_probe_id = 0; +} + +static void __remove_filesrc_pad_block_foreach_cb(gpointer key, gpointer value, gpointer user_data) +{ + webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; + int av_idx; + + if (source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE) return; - } - LOG_INFO("change filesrc pipeline state to [%s]", gst_element_state_get_name(state)); + for (av_idx = 0; av_idx < AV_IDX_MAX; av_idx++) + __remove_filesrc_pad_block_probe(source, av_idx); } -int _gst_filesrc_pipeline_set_state(webrtc_s *webrtc, GstState state) +int _remove_all_filesrc_pad_block_probes(webrtc_s *webrtc) { RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - g_hash_table_foreach(webrtc->gst.source_slots, __set_filesrc_pipline_state_foreach_cb, GINT_TO_POINTER(state)); + g_hash_table_foreach(webrtc->gst.source_slots, __remove_filesrc_pad_block_foreach_cb, NULL); return WEBRTC_ERROR_NONE; } -int _set_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool looping) +static void __remove_rest_of_elements_for_filesrc_pipeline(webrtc_gst_slot_s *source) { - webrtc_gst_slot_s *source; + GstBin *bin = NULL; + GstIterator *iter = NULL; + GstIteratorResult result; + GValue value = { 0 }; + GstElement *elem = NULL; - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); - RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); + RET_IF(source == NULL, "pad is NULL"); + RET_IF(source->filesrc_pipeline == NULL, "filesrc_pipeline is NULL"); - source->filesrc_loop = looping; + bin = GST_BIN(source->filesrc_pipeline); - LOG_DEBUG("source_id[%u] looping[%d]", source_id, looping); + iter = gst_bin_iterate_elements(bin); - return WEBRTC_ERROR_NONE; -} + do { + switch ((result = gst_iterator_next (iter, &value))) { + case GST_ITERATOR_OK: + elem = (GstElement *) g_value_get_object(&value); + if (!g_strrstr(GST_ELEMENT_NAME(elem), ELEMENT_NAME_FILE_SRC) && !g_strrstr(GST_ELEMENT_NAME(elem), "decodebin")) + gst_bin_remove(bin, elem); + g_value_unset (&value); + break; -int _get_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool *looping) -{ - const webrtc_gst_slot_s *source; + case GST_ITERATOR_RESYNC: + gst_iterator_resync(iter); + break; - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); - RET_VAL_IF(looping == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "looping is NULL"); - RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); - RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); + case GST_ITERATOR_ERROR: + LOG_ERROR("error in iterating elements"); + break; - *looping = source->filesrc_loop; + case GST_ITERATOR_DONE: + break; - LOG_DEBUG("source_id[%u] looping[%d]", source_id, *looping); + default: + break; + } + } while (result == GST_ITERATOR_OK || result == GST_ITERATOR_RESYNC); - return WEBRTC_ERROR_NONE; + gst_iterator_free(iter); } -void _remove_filesrc_pad_block_probe(webrtc_gst_slot_s *source, unsigned int av_idx) +static void __release_filesrc_resources(webrtc_gst_slot_s *source) { + GstElement *appsrc = NULL; + GstElement *queue = NULL; + GstElement *capsfilter = NULL; + int av_idx = 0; + RET_IF(source == NULL, "source is NULL"); - RET_IF(av_idx >= AV_IDX_MAX, "invalid idx(%u)", av_idx); + RET_IF(source->bin == NULL, "bin is NULL"); + RET_IF(source->filesrc_pipeline == NULL, "filesrc_pipeline is NULL"); - if (source->filesrc_av[av_idx].sink_pad_probe_id == 0) - return; + _release_request_pad(source); - LOG_DEBUG("source[id:%u] for[%s] pad[%p] probe_id[%lu]", source->id, GET_MEDIA_TYPE_NAME(av_idx == AV_IDX_AUDIO), - source->filesrc_av[av_idx].sink_pad, source->filesrc_av[av_idx].sink_pad_probe_id); + for (av_idx = 0; av_idx < AV_IDX_MAX; av_idx++) { + GList *element_list = NULL; - gst_pad_remove_probe(source->filesrc_av[av_idx].sink_pad, source->filesrc_av[av_idx].sink_pad_probe_id); + if (source->av[av_idx].src_pad_probe_id == 0) + continue; - source->filesrc_av[av_idx].sink_pad = NULL; - source->filesrc_av[av_idx].sink_pad_probe_id = 0; -} + _remove_probe_from_pad_for_pause(source, av_idx); + _remove_probe_from_pad_for_render(source, av_idx); + __remove_filesrc_pad_block_probe(source, av_idx); -static void __remove_filesrc_pad_block_foreach_cb(gpointer key, gpointer value, gpointer user_data) -{ - webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; - int av_idx; + if (source->av[av_idx].pt > 0) + _return_payload_type(source->webrtc, source->av[av_idx].pt); - if (source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE) - return; + _destroy_looopback_render_pipeline(source, av_idx); - for (av_idx = 0; av_idx < AV_IDX_MAX; av_idx++) - _remove_filesrc_pad_block_probe(source, av_idx); -} + if ((appsrc = gst_bin_get_by_name(source->bin, _get_element_name(av_idx, ELEMENT_APPSRC)))) + APPEND_ELEMENT(element_list, appsrc); + else + LOG_ERROR("appsrc is NULL"); -int _remove_all_filesrc_pad_block_probes(webrtc_s *webrtc) -{ - RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + if ((queue = gst_bin_get_by_name(source->bin, _get_element_name(av_idx, ELEMENT_QUEUE)))) + APPEND_ELEMENT(element_list, queue); + else + LOG_ERROR("queue is NULL"); - g_hash_table_foreach(webrtc->gst.source_slots, __remove_filesrc_pad_block_foreach_cb, NULL); + if ((capsfilter = gst_bin_get_by_name(source->bin, _get_element_name(av_idx, ELEMENT_CAPSFILTER)))) + APPEND_ELEMENT(element_list, capsfilter); + else + LOG_ERROR("capsfilter is NULL"); - return WEBRTC_ERROR_NONE; + _remove_elements_from_bin(source->bin, element_list); + + SAFE_G_LIST_FREE(element_list); + } + + __remove_rest_of_elements_for_filesrc_pipeline(source); + + if (source->display) + _release_display(source->display); + + if (source->sound_stream_info.type) { + free(source->sound_stream_info.type); + source->sound_stream_info.type = NULL; + } + + source->media_types = 0; } -void _set_filesrc_media_types(webrtc_gst_slot_s *source, const char *path) +static void __set_filesrc_media_types(webrtc_gst_slot_s *source, const char *path) { int ret = FILEINFO_ERROR_NONE; int audio_tracks_num = 0; @@ -140,6 +182,109 @@ void _set_filesrc_media_types(webrtc_gst_slot_s *source, const char *path) source->media_types |= MEDIA_TYPE_VIDEO; } +int _set_media_path(webrtc_s *webrtc, unsigned int source_id, const char *path) +{ + webrtc_gst_slot_s *source = NULL; + GstElement *filesrc = NULL; + gchar *location = NULL; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF(path == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "path 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_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); + + if (access(path, R_OK) < 0) { + if (errno == EACCES || errno == EPERM) { + LOG_ERROR("Fail to open path: Permission Denied [%s]", path); + return WEBRTC_ERROR_PERMISSION_DENIED; + } else { + LOG_ERROR("Fail to open path: Invalid Path [%s] errno[%d]", path, errno); + return WEBRTC_ERROR_INVALID_PARAMETER; + } + } + + filesrc = gst_bin_get_by_name(GST_BIN(source->filesrc_pipeline), ELEMENT_NAME_FILE_SRC); + RET_VAL_IF(filesrc == NULL, WEBRTC_ERROR_INVALID_OPERATION, "filesrc is NULL"); + + g_object_get(G_OBJECT(filesrc), "location", &location, NULL); + if (location) { + __release_filesrc_resources(source); + g_free(location); + source->media_types = 0; + } + + g_object_set(G_OBJECT(filesrc), "location", path, NULL); + + __set_filesrc_media_types(source, path); + + LOG_DEBUG("source_id[%u] path[%s]", source_id, path); + + return WEBRTC_ERROR_NONE; +} + +static void __set_filesrc_pipline_state_foreach_cb(gpointer key, gpointer value, gpointer user_data) +{ + webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; + GstStateChangeReturn ret; + GstState state = GPOINTER_TO_UINT(user_data); + + if (source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE) + return; + + LOG_INFO("found file source[%p, id:%u]", source, source->id); + + ret = gst_element_set_state(source->filesrc_pipeline, state); + if (ret == GST_STATE_CHANGE_FAILURE) { + LOG_ERROR("failed to gst_element_set_state(), state[%s]", gst_element_state_get_name(state)); + return; + } + + LOG_INFO("change filesrc pipeline state to [%s]", gst_element_state_get_name(state)); +} + +int _gst_filesrc_pipeline_set_state(webrtc_s *webrtc, GstState state) +{ + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + + g_hash_table_foreach(webrtc->gst.source_slots, __set_filesrc_pipline_state_foreach_cb, GINT_TO_POINTER(state)); + + return WEBRTC_ERROR_NONE; +} + +int _set_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool looping) +{ + webrtc_gst_slot_s *source; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); + + source->filesrc_loop = looping; + + LOG_DEBUG("source_id[%u] looping[%d]", source_id, looping); + + return WEBRTC_ERROR_NONE; +} + +int _get_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool *looping) +{ + const webrtc_gst_slot_s *source; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF(looping == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "looping is NULL"); + RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_FILE, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type [%d]", source->type); + + *looping = source->filesrc_loop; + + LOG_DEBUG("source_id[%u] looping[%d]", source_id, *looping); + + return WEBRTC_ERROR_NONE; +} + static GstElement * __create_payloader_for_filesrc_pipeline(GstPad *pad, bool is_audio) { element_info_s elem_info; @@ -346,49 +491,6 @@ exit: return WEBRTC_ERROR_INVALID_OPERATION; } -void _remove_rest_of_elements_for_filesrc_pipeline(webrtc_gst_slot_s *source) -{ - GstBin *bin = NULL; - GstIterator *iter = NULL; - GstIteratorResult result; - GValue value = { 0 }; - GstElement *elem = NULL; - - RET_IF(source == NULL, "pad is NULL"); - RET_IF(source->filesrc_pipeline == NULL, "filesrc_pipeline is NULL"); - - bin = GST_BIN(source->filesrc_pipeline); - - iter = gst_bin_iterate_elements(bin); - - do { - switch ((result = gst_iterator_next (iter, &value))) { - case GST_ITERATOR_OK: - elem = (GstElement *) g_value_get_object(&value); - if (!g_strrstr(GST_ELEMENT_NAME(elem), ELEMENT_NAME_FILE_SRC) && !g_strrstr(GST_ELEMENT_NAME(elem), "decodebin")) - gst_bin_remove(bin, elem); - g_value_unset (&value); - break; - - case GST_ITERATOR_RESYNC: - gst_iterator_resync(iter); - break; - - case GST_ITERATOR_ERROR: - LOG_ERROR("error in iterating elements"); - break; - - case GST_ITERATOR_DONE: - break; - - default: - break; - } - } while (result == GST_ITERATOR_OK || result == GST_ITERATOR_RESYNC); - - gst_iterator_free(iter); -} - static gboolean __filesrc_pipeline_bus_watch_cb(GstBus *bus, GstMessage *message, gpointer user_data) { webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)user_data; @@ -826,3 +928,36 @@ void _destroy_filesrc_pipeline(webrtc_gst_slot_s *source) source->filesrc_pipeline = NULL; } } + +static gboolean __check_path_is_not_set_cb(gpointer key, gpointer value, gpointer user_data) +{ + const webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value; + gchar *location = NULL; + + if (source->type == GPOINTER_TO_INT(user_data)) { + LOG_INFO("found file source[%p, id:%u]", source, source->id); + g_object_get(G_OBJECT(gst_bin_get_by_name(GST_BIN(source->filesrc_pipeline), ELEMENT_NAME_FILE_SRC)), "location", &location, NULL); + + if (!location) + return TRUE; + + g_free(location); + } + + return FALSE; +} + +bool _check_if_path_is_set_to_file_sources(webrtc_s *webrtc) +{ + const webrtc_gst_slot_s *source; + + RET_VAL_IF(webrtc == NULL, false, "webrtc is NULL"); + + source = g_hash_table_find(webrtc->gst.source_slots, __check_path_is_not_set_cb, GINT_TO_POINTER(WEBRTC_MEDIA_SOURCE_TYPE_FILE)); + if (source) { + LOG_ERROR("media path is not set to the file source[%u]", source->id); + return false; + } + + return true; +}