Skip to content

Commit 09e0f82

Browse files
committed
enhancement #23: make mic a seperate pipeline since it is not sync with
AV
1 parent 818467b commit 09e0f82

File tree

7 files changed

+246
-175
lines changed

7 files changed

+246
-175
lines changed

Plugin/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ set(SOURCE_FILES
2222
src/GstBasePipeline.cpp
2323
src/GstAVPipeline.cpp
2424
src/GstAVPipeline.h
25+
src/GstMicPipeline.cpp
26+
src/GstMicPipeline.h
2527
src/GstDataPipeline.cpp
2628
src/GstDataPipeline.h
2729

Plugin/src/GstAVPipeline.cpp

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -354,157 +354,6 @@ GstElement* GstAVPipeline::add_webrtcsrc(GstElement* pipeline, const std::string
354354
return webrtcsrc;
355355
}
356356

357-
GstElement* GstAVPipeline::add_wasapi2src(GstElement* pipeline)
358-
{
359-
GstElement* wasapi2src = gst_element_factory_make("wasapi2src", nullptr);
360-
if (!wasapi2src)
361-
{
362-
Debug::Log("Failed to create wasapi2src", Level::Error);
363-
return nullptr;
364-
}
365-
g_object_set(wasapi2src, "low-latency", true, "provide-clock", false, nullptr);
366-
367-
gst_bin_add(GST_BIN(pipeline), wasapi2src);
368-
return wasapi2src;
369-
}
370-
371-
GstElement* GstAVPipeline::add_opusenc(GstElement* pipeline)
372-
{
373-
GstElement* opusenc = gst_element_factory_make("opusenc", nullptr);
374-
if (!opusenc)
375-
{
376-
Debug::Log("Failed to create opusenc", Level::Error);
377-
return nullptr;
378-
}
379-
380-
g_object_set(opusenc, "audio-type", "restricted-lowdelay", /* "frame-size", 10,*/ nullptr);
381-
382-
gst_bin_add(GST_BIN(pipeline), opusenc);
383-
return opusenc;
384-
}
385-
386-
GstElement* GstAVPipeline::add_audio_caps_capsfilter(GstElement* pipeline)
387-
{
388-
GstElement* audio_caps_capsfilter = gst_element_factory_make("capsfilter", nullptr);
389-
if (!audio_caps_capsfilter)
390-
{
391-
Debug::Log("Failed to create capsfilter", Level::Error);
392-
return nullptr;
393-
}
394-
395-
GstCaps* audio_caps = gst_caps_from_string("audio/x-opus");
396-
gst_caps_set_simple(audio_caps, "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 48000, nullptr);
397-
g_object_set(audio_caps_capsfilter, "caps", audio_caps, nullptr);
398-
399-
gst_bin_add(GST_BIN(pipeline), audio_caps_capsfilter);
400-
gst_caps_unref(audio_caps);
401-
return audio_caps_capsfilter;
402-
}
403-
404-
void GstAVPipeline::consumer_added_callback(GstElement* consumer_id, gchararray webrtcbin, GstElement* arg1, gpointer udata)
405-
{
406-
Debug::Log("Consumer added");
407-
GstIterator* sinks = gst_bin_iterate_sinks(GST_BIN(consumer_id));
408-
gboolean done = FALSE;
409-
while (!done)
410-
{
411-
GValue item = G_VALUE_INIT;
412-
switch (gst_iterator_next(sinks, &item))
413-
{
414-
case GST_ITERATOR_OK:
415-
{
416-
GstElement* sink = GST_ELEMENT(g_value_get_object(&item));
417-
418-
// Log a message indicating that the processing deadline is being set for the sink
419-
std::string name = GST_ELEMENT_NAME(sink);
420-
Debug::Log("Setting processing deadline for " + name);
421-
422-
// Set the processing deadline for the sink
423-
g_object_set(sink, "processing-deadline", 1000000, nullptr);
424-
425-
// Unref the sink to free its resources
426-
g_object_unref(sink);
427-
428-
// Free the item value
429-
g_value_unset(&item);
430-
431-
break;
432-
}
433-
case GST_ITERATOR_RESYNC:
434-
// Resync the iterator
435-
gst_iterator_resync(sinks);
436-
break;
437-
case GST_ITERATOR_ERROR:
438-
// Handle the error
439-
g_warning("Error iterating sinks");
440-
done = TRUE;
441-
break;
442-
case GST_ITERATOR_DONE:
443-
// We're done iterating
444-
done = TRUE;
445-
break;
446-
}
447-
}
448-
449-
// Free the iterator
450-
gst_iterator_free(sinks);
451-
}
452-
453-
GstElement* GstAVPipeline::add_webrtcsink(GstElement* pipeline, const std::string& uri)
454-
{
455-
GstElement* webrtcsink = gst_element_factory_make("webrtcsink", nullptr);
456-
if (!webrtcsink)
457-
{
458-
Debug::Log("Failed to create webrtcsink", Level::Error);
459-
return nullptr;
460-
}
461-
462-
GObject* signaller;
463-
g_object_get(webrtcsink, "signaller", &signaller, nullptr);
464-
if (signaller)
465-
{
466-
g_object_set(signaller, "uri", uri.c_str(), nullptr);
467-
g_object_unref(signaller); // Unref signaller when done
468-
}
469-
else
470-
{
471-
Debug::Log("Failed to get signaller property from webrtcsink.", Level::Error);
472-
}
473-
474-
GstStructure* meta_structure = gst_structure_new_empty("meta");
475-
gst_structure_set(meta_structure, "name", G_TYPE_STRING, "UnityClient", nullptr);
476-
GValue meta_value = G_VALUE_INIT;
477-
g_value_init(&meta_value, GST_TYPE_STRUCTURE);
478-
gst_value_set_structure(&meta_value, meta_structure);
479-
g_object_set_property(G_OBJECT(webrtcsink), "meta", &meta_value);
480-
gst_structure_free(meta_structure);
481-
g_value_unset(&meta_value);
482-
483-
g_object_set(webrtcsink, "stun-server", nullptr, "do-restransmission", false, nullptr);
484-
485-
//g_signal_connect(webrtcsink, "consumer-added", G_CALLBACK(consumer_added_callback), nullptr);
486-
487-
gst_bin_add(GST_BIN(pipeline), webrtcsink);
488-
return webrtcsink;
489-
}
490-
491-
492-
GstElement* GstAVPipeline::add_webrtcdsp(GstElement* pipeline)
493-
{
494-
GstElement* webrtcdsp = gst_element_factory_make("webrtcdsp", nullptr);
495-
if (!webrtcdsp)
496-
{
497-
Debug::Log("Failed to create webrtcdsp", Level::Error);
498-
return nullptr;
499-
}
500-
501-
// Echo cancel done on the robot side
502-
g_object_set(webrtcdsp, "echo-cancel", false, nullptr);
503-
504-
gst_bin_add(GST_BIN(pipeline), webrtcdsp);
505-
return webrtcdsp;
506-
}
507-
508357
void GstAVPipeline::on_pad_added(GstElement* src, GstPad* new_pad, gpointer data)
509358
{
510359
GstAVPipeline* avpipeline = static_cast<GstAVPipeline*>(data);
@@ -671,19 +520,6 @@ void GstAVPipeline::CreatePipeline(const char* uri, const char* remote_peer_id)
671520
GstBasePipeline::CreatePipeline();
672521

673522
GstElement* webrtcsrc = add_webrtcsrc(pipeline_, remote_peer_id, uri, this);
674-
GstElement* wasapi2src = add_wasapi2src(pipeline_);
675-
GstElement* webrtcdsp = add_webrtcdsp(pipeline_);
676-
GstElement* audioconvert = add_audioconvert(pipeline_);
677-
GstElement* queue = add_queue(pipeline_);
678-
GstElement* opusenc = add_opusenc(pipeline_);
679-
GstElement* audio_caps_capsfilter = add_audio_caps_capsfilter(pipeline_);
680-
GstElement* webrtcsink = add_webrtcsink(pipeline_, uri);
681-
682-
if (!gst_element_link_many(wasapi2src, audioconvert, webrtcdsp, queue, opusenc, audio_caps_capsfilter, webrtcsink,
683-
nullptr))
684-
{
685-
Debug::Log("Audio sending elements could not be linked.", Level::Error);
686-
}
687523

688524
CreateBusThread();
689525
}

Plugin/src/GstAVPipeline.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class GstAVPipeline : GstBasePipeline
5252
private:
5353
static void on_pad_added(GstElement* src, GstPad* new_pad, gpointer data);
5454
static void webrtcbin_ready(GstElement* self, gchararray peer_id, GstElement* webrtcbin, gpointer udata);
55-
static void consumer_added_callback(GstElement* consumer_id, gchararray webrtcbin, GstElement* arg1, gpointer udata);
5655

5756
static GstFlowReturn GstAVPipeline::on_new_sample(GstAppSink* appsink, gpointer user_data);
5857

@@ -71,9 +70,4 @@ class GstAVPipeline : GstBasePipeline
7170
static GstElement* add_wasapi2sink(GstElement* pipeline);
7271
static GstElement* add_webrtcsrc(GstElement* pipeline, const std::string& remote_peer_id, const std::string& uri,
7372
GstAVPipeline* self);
74-
static GstElement* add_wasapi2src(GstElement* pipeline);
75-
static GstElement* add_opusenc(GstElement* pipeline);
76-
static GstElement* add_audio_caps_capsfilter(GstElement* pipeline);
77-
static GstElement* add_webrtcsink(GstElement* pipeline, const std::string& uri);
78-
static GstElement* add_webrtcdsp(GstElement* pipeline);
7973
};

0 commit comments

Comments
 (0)