webrtc_internal: Add support for internal source types 43/260443/5
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 25 Jun 2021 03:38:12 +0000 (12:38 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 28 Jun 2021 07:21:53 +0000 (16:21 +0900)
WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO and WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO
are added for internal use.

[Version] 0.2.26
[Issue Type] Internal API

Change-Id: I71257ba153aaf16f83a77e65214953803c1ba017
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_ini.c
src/webrtc_internal.c
src/webrtc_source.c
test/webrtc_test.c

index 26cf05ac8cce158dc0bf73517cc3d7fb0ffb8171..906b78f2303976d92ade96be16e45546f3d69b47 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __TIZEN_MEDIA_WEBRTC_INTERNAL_H__
 #define __TIZEN_MEDIA_WEBRTC_INTERNAL_H__
 
+#include "webrtc.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -45,6 +47,16 @@ typedef void *webrtc_signaling_server_h;
  */
 typedef void *webrtc_signaling_client_h;
 
+/**
+ * @internal
+ * @brief Enumeration for WebRTC media source type for internal use.
+ * @since_tizen 6.5
+ */
+typedef enum {
+       WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO = 7,  /**<  Custom audio */
+       WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO,      /**<  Custom video */
+} webrtc_media_source_type_internal_e;
+
 /**
  * @internal
  * @brief Enumeration for WebRTC signaling message type.
@@ -90,6 +102,34 @@ typedef void (*webrtc_signaling_message_cb)(webrtc_signaling_message_type_e type
  */
 int webrtc_set_ecore_wl_display(webrtc_h webrtc, unsigned int track_id, void *ecore_wl_window);
 
+/**
+ * @internal
+ * @brief Adds an internal media source.
+ * @since_tizen 6.5
+ * @param[in] webrtc      WebRTC handle
+ * @param[in] type        The media source type to be added
+ * @param[out] source_id  The media source id
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WEBRTC_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #WEBRTC_ERROR_INVALID_STATE Invalid state
+ * @pre @a webrtc state must be set to #WEBRTC_STATE_IDLE.
+ * @see webrtc_remove_media_source()
+ * @see webrtc_media_source_set_transceiver_direction()
+ * @see webrtc_media_source_get_transceiver_direction()
+ * @see webrtc_media_source_set_pause()
+ * @see webrtc_media_source_get_pause()
+ * @see webrtc_media_source_set_mute()
+ * @see webrtc_media_source_get_mute()
+ * @see webrtc_media_source_set_video_resolution()
+ * @see webrtc_media_source_get_video_resolution()
+ */
+int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_internal_e type, unsigned int *source_id);
+
 /**
  * @internal
  * @brief Create a signaling server for private network.
index f2d407e0917ce4f6209c45d959401318568bf0a2..ad8a0bedb51ed0c201a7d5bdfe363eb215d7608d 100644 (file)
@@ -421,7 +421,7 @@ typedef struct _webrtc_gst_slot_s {
        webrtc_s *webrtc;
        GList *signals;
 
-       webrtc_media_source_type_e type;
+       int type;
        int media_types;    /* values of media_type_e combined with bitwise 'or' */
        struct {
                int mline;
@@ -505,14 +505,15 @@ typedef struct webrtc_signaling_client_s {
 
 int _load_ini(webrtc_s *webrtc);
 void _unload_ini(webrtc_s *webrtc);
-ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, webrtc_media_source_type_e type);
+ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, int type);
 
 int _webrtc_stop(webrtc_s *webrtc);
 int _gst_init(webrtc_s *webrtc);
 int _gst_build_pipeline(webrtc_s *webrtc);
 void _gst_destroy_pipeline(webrtc_s *webrtc);
 int _gst_pipeline_set_state(webrtc_s *webrtc, GstState state);
-int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigned int *source_id);
+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);
 int _set_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_direction_e direction);
 int _get_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_direction_e *direction);
index 960125a4b5e90abc201a6a750f1e8a5e060329a9..55d82ca3387d0c8617328f79d34d18f1a51f32be 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.25
+Version:    0.2.26
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 89cbcb94375b575580e334883213b7374f823dc1..b02b0802cb767b774e0c723505cb3431ca89bbc6 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "webrtc.h"
+#include "webrtc_internal.h"
 #include "webrtc_private.h"
 
 #define WEBRTC_INI_PATH                   SYSCONFDIR"/multimedia/mmfw_webrtc.ini"
@@ -34,6 +34,8 @@
 #define INI_CATEGORY_SOURCE_MEDIA_PACKET  "source media packet"
 #define INI_CATEGORY_SOURCE_SCREEN        "source screen"
 #define INI_CATEGORY_SOURCE_FILE          "source file"
+#define INI_CATEGORY_SOURCE_CUSTOM_AUDIO  "source custom audio"
+#define INI_CATEGORY_SOURCE_CUSTOM_VIDEO  "source custom video"
 #define INI_CATEGORY_RENDERING_SINK       "rendering sink"
 #define INI_CATEGORY_RESOURCE_ACQUISITION "resource acquisition"
 #define INI_CATEGORY_VPXENC_PARAMS        "vpxenc params"
@@ -133,7 +135,9 @@ static const char* category_source_names[] = {
        [WEBRTC_MEDIA_SOURCE_TYPE_SCREEN] = INI_CATEGORY_SOURCE_SCREEN,
        [WEBRTC_MEDIA_SOURCE_TYPE_FILE] = INI_CATEGORY_SOURCE_FILE,
        [WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET] = INI_CATEGORY_SOURCE_MEDIA_PACKET,
-       [WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET + 1] = NULL,
+       [WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO] = INI_CATEGORY_SOURCE_CUSTOM_AUDIO,
+       [WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO] = INI_CATEGORY_SOURCE_CUSTOM_VIDEO,
+       [WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO + 1] = NULL,
 };
 
 static void __dump_item(const char *prefix_str, ini_item_type_e type, void *item)
@@ -472,7 +476,7 @@ int _load_ini(webrtc_s *webrtc)
        return WEBRTC_ERROR_NONE;
 }
 
-ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, webrtc_media_source_type_e type)
+ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, int type)
 {
        RET_VAL_IF(ini == NULL, NULL, "ini is NULL");
 
index 603f8956bc2c7831a560bd3631120436dbbac890..6996789a2699e123131763f050c82817e56985f0 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "webrtc.h"
+#include "webrtc_internal.h"
 #include "webrtc_private.h"
 
 int webrtc_set_ecore_wl_display(webrtc_h webrtc, unsigned int track_id, void *ecore_wl_window)
@@ -40,3 +40,24 @@ int webrtc_set_ecore_wl_display(webrtc_h webrtc, unsigned int track_id, void *ec
 
        return ret;
 }
+
+int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_internal_e type, unsigned int *source_id)
+{
+       int ret = WEBRTC_ERROR_NONE;
+       webrtc_s *_webrtc = (webrtc_s*)webrtc;
+
+       RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL");
+
+       g_mutex_lock(&_webrtc->mutex);
+
+       RET_VAL_WITH_UNLOCK_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, &_webrtc->mutex, "the state should be IDLE");
+
+       ret = _add_media_source_internal(webrtc, type, source_id);
+       if (ret == WEBRTC_ERROR_NONE)
+               LOG_INFO("source_id[%u]", *source_id);
+
+       g_mutex_unlock(&_webrtc->mutex);
+
+       return ret;
+}
\ No newline at end of file
index 041787c7794413c911d2cbae2144e371295dca13..025ecbe39c50b755c884a1ad9bbc35b7e72a8e39 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include <gst/audio/audio.h>
-#include "webrtc.h"
+#include "webrtc_internal.h"
 #include "webrtc_private.h"
 #include <tbm_surface_internal.h>
 #include <media_packet_internal.h>
@@ -250,6 +250,7 @@ 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:
                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,
@@ -262,6 +263,7 @@ static GstCaps *__make_default_raw_caps(webrtc_gst_slot_s *source, webrtc_ini_s
 
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO:
                caps = gst_caps_new_simple(MEDIA_TYPE_AUDIO_RAW,
                                                "format", G_TYPE_STRING, ini_source->a_raw_format,
                                                "channels", G_TYPE_INT, ini_source->a_channels,
@@ -381,6 +383,7 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in
        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:
                _media_type = __get_video_media_type(ini_source->v_codec);
                RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
 
@@ -395,6 +398,7 @@ static GstCaps *__make_default_encoded_caps(webrtc_gst_slot_s *source, webrtc_in
 
        case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
        case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO:
                _media_type = __get_audio_media_type(ini_source->a_codec);
                RET_VAL_IF(_media_type == NULL, NULL, "_media_type is NULL");
 
@@ -795,7 +799,7 @@ static int __create_rest_of_elements_for_encoded_format(webrtc_s *webrtc, webrtc
        return WEBRTC_ERROR_NONE;
 }
 
-static const char *__get_default_element(webrtc_media_source_type_e type)
+static const char *__get_default_element(int type)
 {
        const char *element = NULL;
 
@@ -811,6 +815,10 @@ static const char *__get_default_element(webrtc_media_source_type_e type)
                element = DEFAULT_ELEMENT_SCREENSRC;
        else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET)
                element = DEFAULT_ELEMENT_APPSRC;
+       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO)
+               element = DEFAULT_ELEMENT_AUDIOTESTSRC;
+       else if (type == WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO)
+               element = DEFAULT_ELEMENT_VIDEOTESTSRC;
        else
                LOG_ERROR_IF_REACHED("type(%d)", type);
 
@@ -819,7 +827,7 @@ static const char *__get_default_element(webrtc_media_source_type_e type)
        return element;
 }
 
-static const char *__get_source_element(webrtc_s *webrtc, webrtc_media_source_type_e type)
+static const char *__get_source_element(webrtc_s *webrtc, int type)
 {
        ini_item_media_source_s *source;
 
@@ -1285,6 +1293,127 @@ exit:
        return ret;
 }
 
+static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
+{
+       int ret = WEBRTC_ERROR_NONE;
+       GstElement *custom_videosrc;
+       GstElement *capsfilter;
+       GList *element_list = NULL;
+
+       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");
+
+       ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
+
+       source->media_types = MEDIA_TYPE_VIDEO;
+       source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
+
+       if (!(custom_videosrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO), ELEMENT_NAME_VIDEO_SRC)))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       APPEND_ELEMENT(element_list, custom_videosrc);
+
+       if ((ret = __create_rest_of_elements(webrtc, source, true, &element_list)) != WEBRTC_ERROR_NONE)
+               goto exit;
+
+       if (!__add_elements_to_bin(source->bin, element_list))
+               goto exit;
+
+       if (!__link_elements(element_list)) {
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit_with_remove_from_bin;
+       }
+
+       if (!(capsfilter = gst_bin_get_by_name(source->bin, ELEMENT_NAME_RTP_CAPSFILTER))) {
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit_with_remove_from_bin;
+       }
+       ret = _set_ghost_pad_target(source->av[AV_IDX_VIDEO].src_pad, capsfilter, true);
+       if (ret != WEBRTC_ERROR_NONE)
+               goto exit_with_remove_from_bin;
+
+       __add_probe_to_pad(source->av[AV_IDX_VIDEO].src_pad, MEDIA_TYPE_VIDEO, source);
+
+       SAFE_G_LIST_FREE(element_list);
+
+       return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+       /* elements will be dereferenced */
+       __remove_elements_from_bin(source->bin, element_list);
+       SAFE_G_LIST_FREE(element_list);
+       return ret;
+exit:
+       __unref_elements(element_list);
+       SAFE_G_LIST_FREE(element_list);
+       return ret;
+}
+
+static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
+{
+       int ret = WEBRTC_ERROR_NONE;
+       const char *source_factory_name;
+       GstElement *custom_audiosrc;
+       GstElement *volume;
+       GstElement *capsfilter;
+       GList *element_list = NULL;
+
+       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");
+
+       ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_AUDIO].src_pad);
+       RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
+
+       source->media_types = MEDIA_TYPE_AUDIO;
+       source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
+
+       source_factory_name = __get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO);
+       if (!(custom_audiosrc = _create_element(source_factory_name, NULL)))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       APPEND_ELEMENT(element_list, custom_audiosrc);
+
+       if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
+               goto exit;
+       APPEND_ELEMENT(element_list, volume);
+
+       if ((ret = __create_rest_of_elements(webrtc, source, true, &element_list)) != WEBRTC_ERROR_NONE)
+               goto exit;
+
+       if (!__add_elements_to_bin(source->bin, element_list))
+               goto exit;
+
+       if (!__link_elements(element_list)) {
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit_with_remove_from_bin;
+       }
+
+       if (!(capsfilter = gst_bin_get_by_name(source->bin, ELEMENT_NAME_RTP_CAPSFILTER))) {
+               ret = WEBRTC_ERROR_INVALID_OPERATION;
+               goto exit_with_remove_from_bin;
+       }
+       ret = _set_ghost_pad_target(source->av[AV_IDX_AUDIO].src_pad, capsfilter, true);
+       if (ret != WEBRTC_ERROR_NONE)
+               goto exit_with_remove_from_bin;
+
+       __add_probe_to_pad(source->av[AV_IDX_AUDIO].src_pad, MEDIA_TYPE_AUDIO, source);
+
+       SAFE_G_LIST_FREE(element_list);
+
+       return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+       /* elements will be dereferenced */
+       __remove_elements_from_bin(source->bin, element_list);
+       SAFE_G_LIST_FREE(element_list);
+       return ret;
+exit:
+       __unref_elements(element_list);
+       SAFE_G_LIST_FREE(element_list);
+       return ret;
+}
+
 static void _appsrc_need_data_cb(GstElement *appsrc, guint size, gpointer data)
 {
        webrtc_gst_slot_s *source = (webrtc_gst_slot_s*)data;
@@ -1501,6 +1630,13 @@ static int __build_source_bin(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
                return __build_mediapacketsrc(webrtc, source);
 
+       /* for internal use */
+       case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO:
+               return __build_custom_audiosrc(webrtc, source);
+
+       case WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO:
+               return __build_custom_videosrc(webrtc, source);
+
        default:
                LOG_ERROR_IF_REACHED("type(%d)", source->type);
                return WEBRTC_ERROR_INVALID_PARAMETER;
@@ -1624,7 +1760,7 @@ exit:
        return ret;
 }
 
-int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigned int *source_id)
+static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id)
 {
        int ret = WEBRTC_ERROR_NONE;
        unsigned int id;
@@ -1633,7 +1769,6 @@ int _add_media_source(webrtc_s *webrtc, webrtc_media_source_type_e type, unsigne
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL");
-       RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type(%d)", type);
        RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
 
        /* bin_name/source will be freed by function which is set to g_hash_table_new_full() */
@@ -1688,6 +1823,27 @@ error:
        return WEBRTC_ERROR_INVALID_OPERATION;
 }
 
+int _add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id)
+{
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL");
+       RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid source type(%d)", type);
+       RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
+
+       return __add_media_source(webrtc, type, source_id);
+}
+
+int _add_media_source_internal(webrtc_s *webrtc, int type, unsigned int *source_id)
+{
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+       RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL");
+       RET_VAL_IF(type <= WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET, WEBRTC_ERROR_INVALID_PARAMETER, "invalid internal source type(%d)", type);
+       RET_VAL_IF(type > WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO, WEBRTC_ERROR_INVALID_PARAMETER, "invalid internal source type(%d)", type);
+       RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
+
+       return __add_media_source(webrtc, type, source_id);
+}
+
 int _remove_media_source(webrtc_s *webrtc, unsigned int source_id)
 {
        int ret = WEBRTC_ERROR_NONE;
index eb37630a8f95e6bd0fca6614d759540277ff18c6..1b0eeef1d460b576e38c8861dc56c24a9d76df90 100644 (file)
@@ -14,7 +14,6 @@
 * limitations under the License.
 */
 
-#include <webrtc.h>
 #include <webrtc_internal.h>
 #include <media_format.h>
 #include <media_packet_internal.h>
@@ -496,26 +495,43 @@ static int _find_packet_sources_index(int index, unsigned int source_id)
        return -1;
 }
 
-static void _webrtc_add_media_source(int index, int type)
+static void _webrtc_add_media_source(int index, int value)
 {
        int ret = WEBRTC_ERROR_NONE;
        unsigned int source_id = 0;
        int i;
 
-       if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
-               i = _get_empty_packet_sources_index(index);
-               RET_IF(i == -1, "media packet source can be added up to %d", MAX_MEDIA_PACKET_SOURCE_LEN);
+       switch (value) {
+       case 1: /* WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST */
+       case 2: /* WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST */
+       case 3: /* WEBRTC_MEDIA_SOURCE_TYPE_MIC */
+       case 4: /* WEBRTC_MEDIA_SOURCE_TYPE_CAMERA */
+       case 5: /* WEBRTC_MEDIA_SOURCE_TYPE_SCREEN */
+       case 6: /* WEBRTC_MEDIA_SOURCE_TYPE_FILE */
+       case 7: /* WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET */
+               if ((value - 1) == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
+                       i = _get_empty_packet_sources_index(index);
+                       RET_IF(i == -1, "media packet source can be added up to %d", MAX_MEDIA_PACKET_SOURCE_LEN);
+               }
+               ret = webrtc_add_media_source(g_conns[index].webrtc, (webrtc_media_source_type_e)(value - 1), &source_id);
+               RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+               break;
+       case 8: /* WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO */
+       case 9: /* WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO */
+               ret = webrtc_add_media_source_internal(g_conns[index].webrtc, (webrtc_media_source_type_internal_e)(value - 1), &source_id);
+               RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+               break;
+       default:
+               break;
        }
 
-       ret = webrtc_add_media_source(g_conns[index].webrtc, (webrtc_media_source_type_e)type, &source_id);
-       RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
-
-       g_print("webrtc_add_media_source() success, source_id[%u]\n", source_id);
-       if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
+       if ((value - 1) == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
                g_conns[index].packet_sources[i].source_id = source_id;
                g_mutex_init(&g_conns[index].packet_sources[i].mutex);
                g_cond_init(&g_conns[index].packet_sources[i].cond);
        }
+
+       g_print("webrtc_add_media_source() success, source_id[%u]\n", source_id);
 }
 
 static void _webrtc_remove_media_source(int index, unsigned int source_id)
@@ -3174,7 +3190,7 @@ static void displaymenu()
                display_sub_basic();
 
        } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_ADD_MEDIA_SOURCE) {
-               g_print("*** input media source type.(1:audiotest, 2:videotest, 3:mic, 4:camera, 5:screen, 6:file, 7:media packet)\n");
+               g_print("*** input media source type.(1:audiotest, 2:videotest, 3:mic, 4:camera, 5:screen, 6:file, 7:media packet, 8:custom audio, 9:custom video)\n");
 
        } else if (g_conns[g_conn_index].menu_state == CURRENT_STATUS_REMOVE_MEDIA_SOURCE) {
                g_print("*** input media source id to remove.\n");
@@ -3324,7 +3340,7 @@ static void interpret(char *cmd)
                break;
        case CURRENT_STATUS_ADD_MEDIA_SOURCE: {
                value = atoi(cmd);
-               _webrtc_add_media_source(g_conn_index, value - 1);
+               _webrtc_add_media_source(g_conn_index, value);
                reset_menu_state();
                break;
        }