g_free(sink);
}
-int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
+static int __alloc_sink_slot(webrtc_s *webrtc, const gchar *pad_name, bool forward, webrtc_gst_slot_s **sink, gchar **name)
{
- int ret = WEBRTC_ERROR_NONE;
unsigned int id;
+
+ RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(pad_name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "pad_name is NULL");
+ RET_VAL_IF(sink == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+ RET_VAL_IF(name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "name is NULL");
+ RET_VAL_IF(webrtc->gst.sink_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "sink_slots is NULL");
+
+ /* name/sink will be freed by function which is set to g_hash_table_new_full() */
+ id = __get_id_from_name(pad_name);
+ *name = g_strdup_printf(forward ? "forwarding_%u" : "rendering_%u", ++id);
+
+ *sink = g_new0(webrtc_gst_slot_s, 1);
+ (*sink)->id = id;
+ (*sink)->bin = GST_BIN(gst_bin_new(*name));
+ (*sink)->webrtc = webrtc;
+
+ LOG_DEBUG("webrtc[%p] sink[%p, id:%u, name:%s]", webrtc, *sink, id, *name);
+
+ return WEBRTC_ERROR_NONE;
+}
+
+int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
+{
gchar *bin_name;
gchar *track_name;
webrtc_gst_slot_s *sink;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL");
- /* track_name/sink will be freed by function which is set to g_hash_table_new_full() */
- id = __get_id_from_name(GST_PAD_NAME(src_pad));
- bin_name = g_strdup_printf("rendering_%u", ++id);
- track_name = g_strdup_printf("track_%u", id);
+ if (__alloc_sink_slot(webrtc, GST_PAD_NAME(src_pad), false, &sink, &bin_name) != WEBRTC_ERROR_NONE)
+ return WEBRTC_ERROR_INVALID_OPERATION;
- MALLOC_AND_INIT_SLOT(sink, id, bin_name, webrtc);
+ track_name = g_strdup_printf("track_%u", sink->id);
g_free(bin_name);
g_signal_connect(decodebin, "autoplug-select", G_CALLBACK(_decodebin_autoplug_select_cb), webrtc);
g_signal_connect(decodebin, "element-added", G_CALLBACK(__decodebin_element_added_cb), sink);
- ret = _add_no_target_ghostpad_to_slot(sink, false, &sink_pad);
- if (ret != WEBRTC_ERROR_NONE)
+ if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE)
goto error_before_insert;
- ret = _set_ghost_pad_target(sink_pad, decodebin, false);
- if (ret != WEBRTC_ERROR_NONE)
+ if (_set_ghost_pad_target(sink_pad, decodebin, false) != WEBRTC_ERROR_NONE)
goto error_before_insert;
if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(sink->bin))) {
int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio)
{
- int ret = WEBRTC_ERROR_NONE;
- unsigned int id;
gchar *bin_name;
gchar *track_name;
element_info_s elem_info;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL");
- /* track_name/sink will be freed by function which is set to g_hash_table_new_full() */
- id = __get_id_from_name(GST_PAD_NAME(src_pad));
- bin_name = g_strdup_printf("forwarding_%u", ++id);
- track_name = g_strdup_printf("track_%u", id);
-
- MALLOC_AND_INIT_SLOT(sink, id, bin_name, webrtc);
+ if (__alloc_sink_slot(webrtc, GST_PAD_NAME(src_pad), true, &sink, &bin_name) != WEBRTC_ERROR_NONE)
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ track_name = g_strdup_printf("track_%u", sink->id);
g_free(bin_name);
CREATE_ELEMENT_FROM_REGISTRY(elem_info, GST_KLASS_NAME_DEPAYLOADER_RTP, gst_pad_get_current_caps(src_pad), NULL, NULL, depayloader);
gst_bin_add_many(sink->bin, depayloader, capsfilter, fakesink, NULL);
- ret = _add_no_target_ghostpad_to_slot(sink, false, &sink_pad);
- if (ret != WEBRTC_ERROR_NONE)
+ if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE)
goto error_before_insert;
- ret = _set_ghost_pad_target(sink_pad, depayloader, false);
- if (ret != WEBRTC_ERROR_NONE)
+ if (_set_ghost_pad_target(sink_pad, depayloader, false) != WEBRTC_ERROR_NONE)
goto error_before_insert;
if (!gst_element_link_many(depayloader, capsfilter, fakesink, NULL)) {
return ret;
}
-static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id)
+static int __alloc_source_slot(webrtc_s *webrtc, int type, webrtc_gst_slot_s **source, gchar **name)
{
- int ret = WEBRTC_ERROR_NONE;
unsigned int id;
- webrtc_gst_slot_s *source = NULL;
- gchar *bin_name = NULL;
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(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+ RET_VAL_IF(name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "name is NULL");
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() */
+ /* name/source will be freed by function which is set to g_hash_table_new_full() */
id = __get_unoccupied_id(webrtc->gst.source_slots);
RET_VAL_IF(id == 0, WEBRTC_ERROR_INVALID_OPERATION, "source_slots are full");
- bin_name = g_strdup_printf("media_source_%u", id);
+ *name = g_strdup_printf("media_source_%u", id);
- MALLOC_AND_INIT_SLOT(source, id, bin_name, webrtc);
- source->type = type;
+ *source = g_new0(webrtc_gst_slot_s, 1);
+ (*source)->id = id;
+ (*source)->bin = GST_BIN(gst_bin_new(*name));
+ (*source)->type = type;
+ (*source)->webrtc = webrtc;
- ret = __build_source_bin(webrtc, source);
- if (ret != WEBRTC_ERROR_NONE) {
- LOG_ERROR("failed to __build_source_bin()");
+ LOG_DEBUG("webrtc[%p] source[%p, id:%u, type:%d, name:%s]", webrtc, *source, id, type, *name);
+
+ return WEBRTC_ERROR_NONE;
+}
+
+static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id)
+{
+ webrtc_gst_slot_s *source = NULL;
+ gchar *bin_name = NULL;
+
+ 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");
+
+ if (__alloc_source_slot(webrtc, type, &source, &bin_name) != WEBRTC_ERROR_NONE)
+ goto error;
+
+ if (__build_source_bin(webrtc, source) != WEBRTC_ERROR_NONE)
goto error;
- }
if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(source->bin))) {
LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(source->bin), GST_ELEMENT_NAME(webrtc->gst.pipeline));
goto error_after_insert;
}
- *source_id = id;
+ *source_id = source->id;
LOG_INFO("added a source slot[%p, id:%u]", source, source->id);