Add API to set/get file source looping 59/264659/9
authorbackto.kim <backto.kim@samsung.com>
Tue, 28 Sep 2021 03:39:54 +0000 (12:39 +0900)
committerbackto.kim <backto.kim@samsung.com>
Fri, 1 Oct 2021 04:27:18 +0000 (13:27 +0900)
Functions are added as below.
- webrtc_file_source_set_looping()
- webrtc_file_source_get_looping()

[Version] 0.2.113
[Issue type] API

Change-Id: Ie088db29ac4aeaf19fe2d5f85138787c4da5c9f7

include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_source.c
test/webrtc_test.c

index c5a70a2b0737a1b2b90fc77376bd097bb7d0ee58..860988776a927c0e0ec1c918ec2b63eb33b72a25 100644 (file)
@@ -172,6 +172,40 @@ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_i
  */
 int webrtc_file_source_set_path(webrtc_h webrtc, unsigned int source_id, const char *path);
 
+/**
+ * @internal
+ * @brief Sets looping state to the file source.
+ * @details If the looping is @c true, the transfer starts again from the beginning of the file source.
+ *          If it is @c false, it won't. The default value is @c false.
+ * @since_tizen 6.5
+ * @param[in] webrtc       WebRTC handle
+ * @param[in] source_id    The file source id
+ * @param[in] looping      The new looping state: (@c true = looping, @c false = non-looping)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation
+ * @see webrtc_file_source_get_looping()
+ */
+int webrtc_file_source_set_looping(webrtc_h webrtc, unsigned int source_id, bool looping);
+
+/**
+ * @internal
+ * @brief Gets looping state to the file source.
+ * @since_tizen 6.5
+ * @param[in] webrtc       WebRTC handle
+ * @param[in] source_id    The file source id
+ * @param[out] looping     The looping state: (@c true = looping, @c false = non-looping)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation
+ * @see webrtc_file_source_set_looping()
+ */
+int webrtc_file_source_get_looping(webrtc_h webrtc, unsigned int source_id, bool *looping);
+
 /**
  * @internal
  * @brief Sets the crop coordinates of screen source.
index cfce82159b2a7d1b8affa609098a70d612502897..54a3f1acad4a570701d176378116087ad662c8cd 100644 (file)
@@ -475,6 +475,7 @@ typedef struct _webrtc_gst_slot_s {
        GstElement *filesrc_pipeline;
        GstBus *filesrc_bus;
        guint filesrc_bus_watcher;
+       bool filesrc_loop;
 
        webrtc_display_s *display;
 } webrtc_gst_slot_s;
@@ -655,6 +656,8 @@ int _check_privilege(const char *privilege);
 int _check_feature(const char *feature);
 
 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);
 
 #ifdef __cplusplus
 }
index 1e44ae412d638dc3d7d4bfb84331a974321f17fd..ae6fa979c50ca5a9eb9f119bb2c7c9521692f3c7 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.112
+Version:    0.2.113
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index a2c7200a8fb3dbd56458dfa77b51bb1fd7913670..3af38ad94f5eb7d43be18232ea69237b5ffa967c 100644 (file)
@@ -94,6 +94,33 @@ int webrtc_file_source_set_path(webrtc_h webrtc, unsigned int source_id, const c
        return _set_media_path(_webrtc, source_id, path);
 }
 
+int webrtc_file_source_set_looping(webrtc_h webrtc, unsigned int source_id, bool looping)
+{
+       g_autoptr(GMutexLocker) locker = NULL;
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       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");
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       return _set_filesrc_looping(_webrtc, source_id, looping);
+}
+
+int webrtc_file_source_get_looping(webrtc_h webrtc, unsigned int source_id, bool *looping)
+{
+       g_autoptr(GMutexLocker) locker = NULL;
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       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");
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       return _get_filesrc_looping(_webrtc, source_id, looping);
+}
+
 int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height)
 {
        int ret = WEBRTC_ERROR_NONE;
index d78ec380a2194db751ba9da40a24bd2ca8ee3a3e..aeb583d1f36322cfd3bea6f12f2e31ce649d69f6 100644 (file)
@@ -2048,14 +2048,14 @@ static gboolean __filesrc_pipeline_bus_watch_cb(GstBus *bus, GstMessage *message
        case GST_MESSAGE_EOS:
                LOG_INFO("GST_MESSAGE_EOS end-of-stream");
 
-#if 0  //ToDo
-               gst_element_seek(source->filesrc_pipeline,
-                       1.0,
-                       GST_FORMAT_TIME,
-                       GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
-                       GST_SEEK_TYPE_SET, 0,
-                       GST_SEEK_TYPE_NONE, 0);
-#endif
+               if (source->filesrc_loop) {
+                       gst_element_seek(source->filesrc_pipeline,
+                               1.0,
+                               GST_FORMAT_TIME,
+                               GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
+                               GST_SEEK_TYPE_SET, 0,
+                               GST_SEEK_TYPE_NONE, 0);
+               }
                break;
 
        default:
@@ -4173,3 +4173,38 @@ int _gst_filesrc_pipeline_set_state(webrtc_s *webrtc, GstState state)
 
        return WEBRTC_ERROR_NONE;
 }
+
+int _set_filesrc_looping(webrtc_s *webrtc, unsigned int source_id, bool looping)
+{
+       webrtc_gst_slot_s *source = 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, "could not find source");
+       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)
+{
+       webrtc_gst_slot_s *source = 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(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, "could not find source");
+       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;
+}
index df30be23b9370f65e4388121041ae17e0227e95a..fc245c794e13adab1cbbcd3e02104bbb95ff2d92 100644 (file)
@@ -98,6 +98,8 @@ enum {
        CURRENT_STATUS_START_PUSHING_PACKET_TO_MEDIA_PACKET_SOURCE,
        CURRENT_STATUS_STOP_PUSHING_PACKET_TO_MEDIA_PACKET_SOURCE,
        CURRENT_STATUS_SET_MEDIA_PATH_TO_MEDIA_FILE_SOURCE,
+       CURRENT_STATUS_MEDIA_SOURCE_SET_FILE_LOOPING,
+       CURRENT_STATUS_MEDIA_SOURCE_GET_FILE_LOOPING,
        CURRENT_STATUS_CREATE_PRIVATE_SIGNALING_SERVER,
        CURRENT_STATUS_CONNECT_TO_PRIVATE_SIGNALING_SERVER,
        CURRENT_STATUS_MUTE_MEDIA_SOURCE,
@@ -3188,6 +3190,27 @@ static void _set_media_path(int index, unsigned int source_id, const char *path)
                g_print("webrtc_file_source_set_path() success, source_id[%d]\n", source_id);
 }
 
+static void _webrtc_media_source_set_file_looping(int index, unsigned int source_id, bool looping)
+{
+       int ret = WEBRTC_ERROR_NONE;
+
+       ret = webrtc_file_source_set_looping(g_conns[index].webrtc, source_id, looping);
+       RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+
+       g_print("webrtc_file_source_set_looping() success, source_id[%u] looping_state[%u]\n", source_id, looping);
+}
+
+static void _webrtc_media_source_get_file_looping(int index, unsigned int source_id)
+{
+       int ret = WEBRTC_ERROR_NONE;
+       bool looping_state;
+
+       ret = webrtc_file_source_get_looping(g_conns[index].webrtc, source_id, &looping_state);
+       RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+
+       g_print("webrtc_file_source_get_looping() success, source_id[%u] looping_state[%u]\n", source_id, looping_state);
+}
+
 static void __close_websocket(connection_s *conn)
 {
        RET_IF(!conn, "conn is NULL");
@@ -3880,10 +3903,16 @@ void _interpret_main_menu(char *cmd)
                        _webrtc_signaling_disconnect(g_conn_index);
 
                } else if (strncmp(cmd, "scs", 3) == 0) {
-                               g_conns[g_conn_index].menu_state = CURRENT_STATUS_SET_CROP_SCREEN_SOURCE;
+                       g_conns[g_conn_index].menu_state = CURRENT_STATUS_SET_CROP_SCREEN_SOURCE;
 
                } else if (strncmp(cmd, "ucs", 3) == 0) {
-                               g_conns[g_conn_index].menu_state = CURRENT_STATUS_UNSET_CROP_SCREEN_SOURCE;
+                       g_conns[g_conn_index].menu_state = CURRENT_STATUS_UNSET_CROP_SCREEN_SOURCE;
+
+               } else if (strncmp(cmd, "sfl", 3) == 0) {
+                       g_conns[g_conn_index].menu_state = CURRENT_STATUS_MEDIA_SOURCE_SET_FILE_LOOPING;
+
+               } else if (strncmp(cmd, "gfl", 3) == 0) {
+                       g_conns[g_conn_index].menu_state = CURRENT_STATUS_MEDIA_SOURCE_GET_FILE_LOOPING;
 
                } else {
                        g_print("unknown menu \n");
@@ -3970,6 +3999,8 @@ void display_sub_basic()
        g_print("scs. *Set crop screen source\t");
        g_print("ucs. *Unset crop screen source\n");
        g_print("pa. *Set media path to file source\n");
+       g_print("sfl. Set file source looping\n");
+       g_print("gfl. Set file source looping\n");
        g_print("sf. Set media format to media packet source\n");
        g_print("dt. Set display type\t");
        g_print("dm. Set display mode\t");
@@ -4133,6 +4164,16 @@ static void displaymenu()
        } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_MEDIA_SOURCE_SET_VIDEO_LOOPBACK) {
                g_print("*** input source id.\n");
 
+       } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_MEDIA_SOURCE_SET_FILE_LOOPING) {
+               if (g_conns[g_conn_index].cnt == 0)
+                       g_print("*** input source id.\n");
+               else if (g_conns[g_conn_index].cnt == 1)
+                       g_print("*** input looping state.(1:true 0:false)\n");
+
+       } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_MEDIA_SOURCE_GET_FILE_LOOPING) {
+               if (g_conns[g_conn_index].cnt == 0)
+                       g_print("*** input source id.\n");
+
        } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_DATA_CHANNEL_SEND_STRING) {
                g_print("*** input string to send.\n");
 
@@ -4612,6 +4653,29 @@ static void interpret(char *cmd)
                }
                break;
        }
+       case CURRENT_STATUS_MEDIA_SOURCE_SET_FILE_LOOPING: {
+               static unsigned int id;
+               value = atoi(cmd);
+               switch (g_conns[g_conn_index].cnt) {
+               case 0:
+                       id = value;
+                       g_conns[g_conn_index].cnt++;
+                       break;
+               case 1:
+                       _webrtc_media_source_set_file_looping(g_conn_index, id, value);
+                       id = 0;
+                       g_conns[g_conn_index].cnt = 0;
+                       reset_menu_state();
+                       break;
+               }
+               break;
+       }
+       case CURRENT_STATUS_MEDIA_SOURCE_GET_FILE_LOOPING: {
+               value = atoi(cmd);
+               _webrtc_media_source_get_file_looping(g_conn_index, value);
+               reset_menu_state();
+               break;
+       }
        case CURRENT_STATUS_CREATE_PRIVATE_SIGNALING_SERVER: {
                value = atoi(cmd);
                _webrtc_signaling_server_create(value);