使用C ++中的GStreamer 1.0从RTSP流中获取帧

时间:2018-10-01 10:51:38

标签: c++ qt gstreamer gstreamer-1.0

我正在尝试使用GStreamer 1.0和Qt库获取rtsp视频帧。我在从 appsink 获取帧时遇到问题,因为某种程度上我的回调函数不起作用。

FrameFlow::FrameFlow()
{
    pipeline_ = gst_parse_launch ("rtspsrc location=rtsp://admin:rce@192.168.88.240:554 ! decodebin ! appsink name=sink", nullptr);
    sink_ = gst_bin_get_by_name(GST_BIN(pipeline_), "sink");
    gst_app_sink_set_emit_signals(GST_APP_SINK(sink_), TRUE);
    g_signal_connect(sink_, "new-sample", G_CALLBACK(newSample(GST_APP_SINK(sink_), (gpointer) this)), (gpointer)this);

    gst_element_set_state(pipeline_, GST_STATE_PLAYING);
}

GstFlowReturn FrameFlow::newSample(GstAppSink *sink, gpointer gSelf)
{
    GstSample* sample = NULL;
    GstMapInfo bufferInfo;

    FrameFlow* self = static_cast<FrameFlow* >(gSelf);
    sample = gst_app_sink_pull_sample(GST_APP_SINK(sink_));
    if(sample != NULL)
    {
        buffer_ = gst_sample_get_buffer(sample);
        if(buffer_ != NULL)
        {
            gst_buffer_map(buffer_, &bufferInfo, GST_MAP_READ);
            self->mutex_.lock();
            self->image_ = QImage(bufferInfo.data, 320, 180, QImage::Format_RGB888);
            self->mutex_.unlock();
            gst_buffer_unmap(buffer_, &bufferInfo);
        }
        gst_sample_unref(sample);
    }
    return GST_FLOW_OK;
}

我正在尝试将newSample()函数注册为回调,但是当我调试该函数时,它甚至没有被调用,但是内存正在泄漏(我猜想它是有效的,因为当我评论gst_element_set_state(pipeline_, GST_STATE_PLAYING);时) ,它不再泄漏了。)

我在哪里做错了?

谢谢您的帮助!

0 个答案:

没有答案