C++ Kurento:无法接收来自GStreamer元素的回调;“切刀”;
我正在尝试在kurentoC++ Kurento:无法接收来自GStreamer元素的回调;“切刀”;,c++,gstreamer,kurento,C++,Gstreamer,Kurento,我正在尝试在kurentomediapipeline上应用一些GStreamer插件,这里我希望GStreamer代码在独立程序中运行良好,可以发送与cutter相关的回调消息 以下是我的代码: namespace kurento { namespace module { namespace vadcustomfilter { std::string Id = ""; void VADCustomF
mediapipeline
上应用一些GStreamer插件,这里我希望GStreamer代码在独立程序中运行良好,可以发送与cutter
相关的回调消息
以下是我的代码:
namespace kurento
{
namespace module
{
namespace vadcustomfilter
{
std::string Id = "";
void VADCustomFilterImpl::busMessage(GstMessage * message)
{
GST_ERROR("***In BusMessage***");
if (message->type == GST_MESSAGE_EOS)
{
g_object_set(G_OBJECT(valve), "drop", FALSE, NULL);
}
const GstStructure *s = gst_message_get_structure(message);
const gchar *name = gst_structure_get_name(s);
GST_INFO("Name: %s\n", name);
if (message->type == GST_MESSAGE_ELEMENT)
{
if (strcmp(name, "cutter") == 0)
{
GstClockTime time = 0;
GstClockTime prevsilencetime = 0;
if (!gst_structure_get_boolean(s, "above", &above))
{
GST_ERROR("could not parse above");
}
GST_INFO("above: %d", above);
if (above)
{
if (isSpeaking == 0)
{
revsilencetime = time;
g_object_set(G_OBJECT(valve), "drop", FALSE, NULL);
}
/*Send Voice Detected Event */
try
{
GST_ERROR("Sending Event: VoiceDetected");
VoiceDetected event(shared_from_this(), "voice-detected", Id.c_str());
signalVoiceDetected(event);
GST_ERROR("Sent Event: VoiceDetected");
}
catch (std::bad_weak_ptr & e)
{
GST_ERROR("EXCEPTION: Voice activity detected ");
}
isSpeaking = 1;
}
else
{
if (isSpeaking == 1)
{
g_object_set(G_OBJECT(valve), "drop", TRUE, NULL);
}
isSpeaking = 0;
}
}
}
}
VADCustomFilterImpl::VADCustomFilterImpl(const boost::property_tree::
ptree & config,
std::shared_ptr <
MediaPipeline > mediaPipeline,
const std::string &pipelineId) :FilterImpl
(config,
std::dynamic_pointer_cast <MediaObjectImpl> (mediaPipeline))
{
-->Edit Start
g_object_set (element, "filter-factory", "audioconvert", NULL);
g_object_get (G_OBJECT (element), "filter", &audioconvertfilter, NULL);
if (audioconvertfilter == NULL) {
throw KurentoException (MEDIA_OBJECT_NOT_FOUND, "MediaObject not found: audioconvertfilter");
}
g_object_set (element, "filter-factory", "cutter", NULL);
g_object_get (G_OBJECT (element), "filter", &cutterfilter, NULL);
if (cutterfilter == NULL) {
throw KurentoException (MEDIA_OBJECT_NOT_FOUND, "MediaObject not found: cutterfilter");
}
g_object_set (G_OBJECT (cutterfilter), "threshold-dB", -39.0, NULL);
g_object_set (G_OBJECT (cutterfilter), "run-length", 400000000, NULL);
g_object_set (element, "filter-factory", "vadcustomfilter", NULL);
g_object_get (G_OBJECT (element), "filter", &vadCustomFilter, NULL);
bus_handler_id = 0;
GST_ERROR("PipelineId: constructor %s",pipelineId.c_str());
Id = pipelineId;
-->Edit End
}
void VADCustomFilterImpl::postConstructor()
{
GstBus *bus;
std::shared_ptr < MediaPipelineImpl > pipe;
FilterImpl::postConstructor();
pipe =
std::dynamic_pointer_cast <MediaPipelineImpl>
(getMediaPipeline());
g_assert(pipe);
/* #1. Add cutter filter here */
create_gst_cutter_filter(pipe);
bus = gst_pipeline_get_bus(GST_PIPELINE(pipe->getPipeline()));
g_assert(bus);
bus_handler_id = register_signal_handler(G_OBJECT(bus),
"message",
std::function <
void(GstElement *,
GstMessage *) >
(std::bind
(&VADCustomFilterImpl::
busMessage, this,
std::placeholders::_2)),
std::dynamic_pointer_cast <
VADCustomFilterImpl>
(shared_from_this()));
GST_ERROR("busMessage added successfully.");
g_object_unref(bus);
}
VADCustomFilterImpl::~VADCustomFilterImpl()
{
std::shared_ptr < MediaPipelineImpl > pipe;
if (bus_handler_id > 0)
{
pipe =
std::dynamic_pointer_cast <MediaPipelineImpl>
(getMediaPipeline());
GstBus *bus =
gst_pipeline_get_bus(GST_PIPELINE(pipe->getPipeline()));
unregister_signal_handler(bus, bus_handler_id);
g_object_unref(bus);
}
}
MediaObjectImpl *VADCustomFilterImplFactory::createObject(const boost::
property_tree::
ptree &
config,
std::
shared_ptr <
MediaPipeline
>
mediaPipeline,
const std::string &pipelineId)
const
{
GST_ERROR("Pipeline Id createObject %s", pipelineId.c_str());
return new VADCustomFilterImpl(config, mediaPipeline, pipelineId.c_str());
}
VADCustomFilterImpl::StaticConstructor VADCustomFilterImpl::
staticConstructor;
VADCustomFilterImpl::StaticConstructor::StaticConstructor()
{
GST_DEBUG_CATEGORY_INIT(GST_CAT_DEFAULT, GST_DEFAULT_NAME, 0,
GST_DEFAULT_NAME);
}
}/* vadcustomfilter */
}/* module */
}/* kurento */
您创建gstreamer元素的方式似乎不是Kuranto所期望的方式。基本上,您是在函数
create\u gst\u cutter\u filter
中创建未正确链接的元素
如果您正在创建一个过滤器,那么所有gstreamer内容(创建元素并连接它们)都应该在您调用的gstreamer元素中完成vadcustomfilter
此元素只需要一个接收器和一个src垫
如果您想创建一种不同类型的元素,因为您正在添加MultifileSink,那么您需要从MediaElement进行扩展,并创建一个从KmsElement
扩展的gstreamer元素。您可以在中看到这方面的示例
编辑:
关于服务器返回的错误。这似乎与这里的问题无关,而是与依赖性问题有关。回过头来看看你是否有同样的问题@SagarPilkhwal是的,kms元素是一个巨大的项目,但它是我们唯一有非过滤器插件示例的地方。如果您按照此处关于gstreamer插件的说明进行操作,您将获得没有opencv的项目的基本代码。但我认为这是你已经做过的。你希望你的插件有什么目标?取决于它,你应该选择一条或另一条路径。看看zbar过滤器是如何完成的。也许你不需要
audioconvert
,agnosticbin在大多数情况下都可以为你做到。你是对的,kurento不允许在管道上进行搜索。你需要一种不同的技巧,创建自定义录音机或类似的东西,这不是一件容易的任务。另一个更简单的选择可能是录制一个文件,然后对其进行后期处理,用您已有的程序消除沉默。
Req-> {"id":13,"method":"invoke","params":{"object":"ff394885-ff7b-4cd2-ac83-190ab58056c3_kurento.MediaPipeline/4911aa60-27e4-461e-86c0-10532bc30d4f_kurento.WebRtcEndpoint","operation":"addIceCandidate","operationParams":{"candidate":{"sdpMid":"audio","__module__":"kurento","sdpMLineIndex":0,"__type__":"IceCandidate","candidate":"candidate:1226269011 1 udp 2122260223 172.24.9.207 62808 typ host generation 0 ufrag nSC45+9JNTCJm+yr"}},"sessionId":"15daae09-de86-4293-a3de-28f33f2d0b16"},"jsonrpc":"2.0"}
Res {"id":13,"error":{"code":40401,"message":"Error adding candidate","data":{"type":"ICE_ADD_CANDIDATE_ERROR"}},"jsonrpc":"2.0"}