*/
#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>
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,
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,
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");
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");
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;
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);
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;
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;
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;
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;
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() */
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;
* limitations under the License.
*/
-#include <webrtc.h>
#include <webrtc_internal.h>
#include <media_format.h>
#include <media_packet_internal.h>
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)
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");
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;
}