为什么此程序在地址上免费使用细分故障堆堆
程序试图创建多个Webrtcbin元素以从不同来源接收媒体 同一程序在Windows上正常运行,但在Mac中给出了细分故障。 在Mac上,如果For循环迭代多次迭代,那么我会得到细分错误
static void on_offer_created(GstPromise *promise, gpointer data)
{
GstWebRTCSessionDescription *offer = NULL;
const GstStructure *reply;
gchar *desc;
gchar *sdp_string;
gchar *json_string;
reply = gst_promise_get_reply(promise);
GstElement *webrtc;
webrtc = gst_bin_get_by_name(GST_BIN(gst_pipe), (gchar *)data);
g_assert_nonnull(webrtc);
gst_structure_get(reply, "offer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &offer, NULL);
gst_promise_unref(promise);
g_signal_emit_by_name(webrtc, "set-local-description", offer, NULL);
sdp_string = gst_sdp_message_as_text(offer->sdp);
g_print(" offer created:\n%s\n", sdp_string);
JsonObject *sdp_json = json_object_new();
json_object_set_string_member(sdp_json, "type", "offer");
json_object_set_string_member(sdp_json, "sdp", sdp_string);
json_object_set_string_member(sdp_json, "from", ourid);
json_object_set_string_member(sdp_json, "to", (gchar *)data);
json_string = get_string_from_json_object(sdp_json);
soup_websocket_connection_send_text(connection, json_string);
g_print("sending offer to %s",(gchar *)data);
gst_webrtc_session_description_free(offer);
}
static void
on_negotiation_needed(GstElement *webrtc, gpointer user_data)
{
GstPromise *promise;
g_print("negosiation needed");
promise = gst_promise_new_with_change_func(on_offer_created, (gchar *)user_data, NULL);
g_signal_emit_by_name(webrtc, "create-offer", NULL, promise);
}
for (int i = json_array_get_length(chain)-1; i >= 0; i--)
{
peerid = (gchar *)g_malloc0(sizeof(gchar*)*9);
webrtc =(GstElement*)g_malloc0(sizeof(GstElement*));
peerid=json_array_get_string_element(chain, i);
webrtc = gst_element_factory_make("webrtcbin", peerid);
g_assert(webrtc != NULL);
gst_bin_add_many(GST_BIN(gst_pipe), webrtc, NULL);
GstCaps *caps = gst_caps_from_string(TRANS_AUDIO_CAPS);
g_signal_emit_by_name(webrtc, "add-transceiver", GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_RECVONLY, caps, NULL);
g_signal_connect(webrtc, "pad-added", G_CALLBACK(on_incoming_stream), &peer_delay);
g_signal_connect(webrtc, "on-negotiation-needed", G_CALLBACK(on_negotiation_needed),g_strdup (peerid));
g_signal_connect(webrtc, "on-ice-candidate", G_CALLBACK(send_ice_candidate_message), g_strdup (peerid));
g_assert_true(gst_element_sync_state_with_parent(webrtc));
}
Program tries to create multiple webrtcbin elements to receive media from different sources
same program works fine on windows but in mac it gives segmentation fault.
on mac if the for loop iterates more than one time then I am getting segmentation fault
static void on_offer_created(GstPromise *promise, gpointer data)
{
GstWebRTCSessionDescription *offer = NULL;
const GstStructure *reply;
gchar *desc;
gchar *sdp_string;
gchar *json_string;
reply = gst_promise_get_reply(promise);
GstElement *webrtc;
webrtc = gst_bin_get_by_name(GST_BIN(gst_pipe), (gchar *)data);
g_assert_nonnull(webrtc);
gst_structure_get(reply, "offer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &offer, NULL);
gst_promise_unref(promise);
g_signal_emit_by_name(webrtc, "set-local-description", offer, NULL);
sdp_string = gst_sdp_message_as_text(offer->sdp);
g_print(" offer created:\n%s\n", sdp_string);
JsonObject *sdp_json = json_object_new();
json_object_set_string_member(sdp_json, "type", "offer");
json_object_set_string_member(sdp_json, "sdp", sdp_string);
json_object_set_string_member(sdp_json, "from", ourid);
json_object_set_string_member(sdp_json, "to", (gchar *)data);
json_string = get_string_from_json_object(sdp_json);
soup_websocket_connection_send_text(connection, json_string);
g_print("sending offer to %s",(gchar *)data);
gst_webrtc_session_description_free(offer);
}
static void
on_negotiation_needed(GstElement *webrtc, gpointer user_data)
{
GstPromise *promise;
g_print("negosiation needed");
promise = gst_promise_new_with_change_func(on_offer_created, (gchar *)user_data, NULL);
g_signal_emit_by_name(webrtc, "create-offer", NULL, promise);
}
for (int i = json_array_get_length(chain)-1; i >= 0; i--)
{
peerid = (gchar *)g_malloc0(sizeof(gchar*)*9);
webrtc =(GstElement*)g_malloc0(sizeof(GstElement*));
peerid=json_array_get_string_element(chain, i);
webrtc = gst_element_factory_make("webrtcbin", peerid);
g_assert(webrtc != NULL);
gst_bin_add_many(GST_BIN(gst_pipe), webrtc, NULL);
GstCaps *caps = gst_caps_from_string(TRANS_AUDIO_CAPS);
g_signal_emit_by_name(webrtc, "add-transceiver", GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_RECVONLY, caps, NULL);
g_signal_connect(webrtc, "pad-added", G_CALLBACK(on_incoming_stream), &peer_delay);
g_signal_connect(webrtc, "on-negotiation-needed", G_CALLBACK(on_negotiation_needed),g_strdup (peerid));
g_signal_connect(webrtc, "on-ice-candidate", G_CALLBACK(send_ice_candidate_message), g_strdup (peerid));
g_assert_true(gst_element_sync_state_with_parent(webrtc));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用libsoup进行插座连接。失败了,我更改了图书馆,现在正常工作
I was using libsoup for socket connection. It was failing I have changed the library and It works fine now