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);,它不再泄漏了)。

我在哪里做错了?

谢谢您的帮助!

4

0 回答 0