有 GstPadProbeReturn 已被我的 main 调用的信息
Have the information that GstPadProbeReturn have been called by my main
当我的源正在抓取流时,回调函数被调用,我有 wxMessageBox("Got buffer"); 显示文本 Got Buffer。但是在这一点上,我不知道如何在我的主代码中获得信息,即我的流实际上正在抓取一些东西,所以我可以显示它(我想确保我的管道在请求显示之前正在抓取一些东西)。例如,更改我的工具栏图标,指示用户管道实际上正在抓取某些东西并且他可以显示它。你可以在下面找到我的代码:
#include "MainWindow.h"
wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_TOOL(10001, LoadVideo)
wxEND_EVENT_TABLE()
MainWindow::MainWindow(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxPoint(30, 30), wxSize(1224, 1024))
{
wxInitAllImageHandlers();
wxBitmap load(wxT("bitmap.png"), wxBITMAP_TYPE_PNG);
wxPanel* bg = new wxPanel(this, wxID_ANY);
bg->SetBackgroundColour(wxColor(230, 230, 230));
m_renderWindow = new wxWindow(bg, wxID_ANY);
m_renderWindow->SetBackgroundColour(*wxBLACK);
// Layout the UI.
wxBoxSizer* szr1 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* szr2 = new wxBoxSizer(wxHORIZONTAL);
szr1->Add(m_renderWindow, wxSizerFlags(1).Expand().Border(wxBOTTOM));
szr1->Add(szr2, wxSizerFlags(0));
bg->SetSizer(szr1);
toolbar->AddTool(10001, _T("ContinuousShot"), load);
toolbar->Realize();
Layout();
// Set up the event handlers.
#ifdef __WXGTK__
m_renderWindow->Bind(wxEVT_CREATE, &MainWindow::OnRendererWinCreated, this);
#endif
// Initialize GStreamer.
m_xid = 0;
m_pipeline = NULL;
gst_init(NULL, NULL);
}
GstPadProbeReturn buffer_out_cb(GstPad* pad, GstPadProbeInfo* info, gpointer user_data)
{
GstElement* pipe = (GstElement*)user_data;
//toolbar->SetToolNormalBitmap(10001, wxBitmap(wxT(icon-open-device.png), wxBITMAP_TYPE_PNG));
wxMessageBox("Got buffer");
gst_element_set_state(pipe, GST_STATE_PAUSED);
//remove the probe if you don't need it anymore, otherwise return GST_PAD_PROBE_OK
return GST_PAD_PROBE_REMOVE;
}
void MainWindow::LoadVideo(wxWindowCreateEvent&)
{
GstPad* pad;
GError* error = NULL;
//GstElement* pipeline;
GstElement* source;
GstCaps* caps = gst_caps_new_simple("application/x-rtp",
"media", G_TYPE_STRING, "video",
"payload", G_TYPE_INT, 96,
"encoding-name", G_TYPE_STRING, "H264",
NULL);
m_pipeline = gst_parse_launch("udpsrc name=source !rtpjitterbuffer !rtph264depay !h264parse !avdec_h264 !autovideoconvert !d3dvideosink name=mysink sync=false ", &error);
if (!m_pipeline) {
g_print("Parse error: %s\n", error->message);
exit(1);
}
source = gst_bin_get_by_name(GST_BIN(m_pipeline), "source");
g_object_set(G_OBJECT(source), "caps", caps, NULL);
g_object_set(G_OBJECT(source), "port", m_port, NULL);
pad = gst_element_get_static_pad(source, "src");
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, (GstPadProbeCallback)buffer_out_cb, m_pipeline, NULL);
gst_object_unref(pad);
#ifdef __WXGTK__
GstElement* sink = gst_bin_get_by_name((GstBin*)m_pipeline, "mysink");
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sink), m_xid);
#elif defined __WXMSW__
GstElement* sink = gst_bin_get_by_name((GstBin*)m_pipeline, "mysink");
WXWidget hwnd = m_renderWindow->GetHandle();
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sink),
reinterpret_cast<guintptr>(hwnd));
#endif
gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
}
解决方案:
在回调函数中传递一个指针 (gpointer user_data),例如一个 int,如果回调没有被调用则为 0,如果被调用则为 1
当我的源正在抓取流时,回调函数被调用,我有 wxMessageBox("Got buffer"); 显示文本 Got Buffer。但是在这一点上,我不知道如何在我的主代码中获得信息,即我的流实际上正在抓取一些东西,所以我可以显示它(我想确保我的管道在请求显示之前正在抓取一些东西)。例如,更改我的工具栏图标,指示用户管道实际上正在抓取某些东西并且他可以显示它。你可以在下面找到我的代码:
#include "MainWindow.h"
wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_TOOL(10001, LoadVideo)
wxEND_EVENT_TABLE()
MainWindow::MainWindow(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxPoint(30, 30), wxSize(1224, 1024))
{
wxInitAllImageHandlers();
wxBitmap load(wxT("bitmap.png"), wxBITMAP_TYPE_PNG);
wxPanel* bg = new wxPanel(this, wxID_ANY);
bg->SetBackgroundColour(wxColor(230, 230, 230));
m_renderWindow = new wxWindow(bg, wxID_ANY);
m_renderWindow->SetBackgroundColour(*wxBLACK);
// Layout the UI.
wxBoxSizer* szr1 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* szr2 = new wxBoxSizer(wxHORIZONTAL);
szr1->Add(m_renderWindow, wxSizerFlags(1).Expand().Border(wxBOTTOM));
szr1->Add(szr2, wxSizerFlags(0));
bg->SetSizer(szr1);
toolbar->AddTool(10001, _T("ContinuousShot"), load);
toolbar->Realize();
Layout();
// Set up the event handlers.
#ifdef __WXGTK__
m_renderWindow->Bind(wxEVT_CREATE, &MainWindow::OnRendererWinCreated, this);
#endif
// Initialize GStreamer.
m_xid = 0;
m_pipeline = NULL;
gst_init(NULL, NULL);
}
GstPadProbeReturn buffer_out_cb(GstPad* pad, GstPadProbeInfo* info, gpointer user_data)
{
GstElement* pipe = (GstElement*)user_data;
//toolbar->SetToolNormalBitmap(10001, wxBitmap(wxT(icon-open-device.png), wxBITMAP_TYPE_PNG));
wxMessageBox("Got buffer");
gst_element_set_state(pipe, GST_STATE_PAUSED);
//remove the probe if you don't need it anymore, otherwise return GST_PAD_PROBE_OK
return GST_PAD_PROBE_REMOVE;
}
void MainWindow::LoadVideo(wxWindowCreateEvent&)
{
GstPad* pad;
GError* error = NULL;
//GstElement* pipeline;
GstElement* source;
GstCaps* caps = gst_caps_new_simple("application/x-rtp",
"media", G_TYPE_STRING, "video",
"payload", G_TYPE_INT, 96,
"encoding-name", G_TYPE_STRING, "H264",
NULL);
m_pipeline = gst_parse_launch("udpsrc name=source !rtpjitterbuffer !rtph264depay !h264parse !avdec_h264 !autovideoconvert !d3dvideosink name=mysink sync=false ", &error);
if (!m_pipeline) {
g_print("Parse error: %s\n", error->message);
exit(1);
}
source = gst_bin_get_by_name(GST_BIN(m_pipeline), "source");
g_object_set(G_OBJECT(source), "caps", caps, NULL);
g_object_set(G_OBJECT(source), "port", m_port, NULL);
pad = gst_element_get_static_pad(source, "src");
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, (GstPadProbeCallback)buffer_out_cb, m_pipeline, NULL);
gst_object_unref(pad);
#ifdef __WXGTK__
GstElement* sink = gst_bin_get_by_name((GstBin*)m_pipeline, "mysink");
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sink), m_xid);
#elif defined __WXMSW__
GstElement* sink = gst_bin_get_by_name((GstBin*)m_pipeline, "mysink");
WXWidget hwnd = m_renderWindow->GetHandle();
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sink),
reinterpret_cast<guintptr>(hwnd));
#endif
gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
}
解决方案:
在回调函数中传递一个指针 (gpointer user_data),例如一个 int,如果回调没有被调用则为 0,如果被调用则为 1