当前位置: 首页 > news >正文

GStreamer学习5----probe数据探测

参考资料:

gstreamer中如何使用probe(探针)获取帧数据_gstreamer 视频编码时获取视频关键帧信息-CSDN博客

Gstreamer中可以使用AppSink作为一个分支来查看管线中的数据,还可以使用probe去处理。

在GStreamer中,probe是一种强大的机制,用于在管道(pipeline)的不同点上检查、修改或拦截数据流。当数据流经管道中的元素时,probe允许开发者在特定的pad(输入或输出端口)上设置监听器,从而可以捕获或处理正在通过的数据。

GStreamer提供了几种不同类型的probe:

  1. Buffer Probe (GST_PAD_PROBE_TYPE_BUFFER): 这是最常见的类型,它会在缓冲区(buffer)到达指定pad时被触发。缓冲区通常包含了一帧音频或视频数据。

  2. Event Probe (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAMGST_PAD_PROBE_TYPE_EVENT_UPSTREAM): 这种probe会在事件(event)通过pad时触发。事件可以是各种各样的信号,如标记(mark)、缓冲区开始(buffer start)或结束(buffer end)等。

  3. Block Probe (GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAMGST_PAD_PROBE_TYPE_BLOCK_UPSTREAM): 这种probe可以阻止数据流,直到回调函数返回一个非阻塞的状态。

  4. Latency Probe (GST_PAD_PROBE_TYPE_LATENCY): 这种probe用于测量数据从进入管道到离开管道所花费的时间。

  5. Buffer List Probe (GST_PAD_PROBE_TYPE_BUFFER_LIST): 类似于Buffer Probe,但可以处理多个连续的缓冲区。

为了在GStreamer中添加probe,你需要调用gst_pad_add_probe()函数,传入你想要监控的pad以及一个回调函数,当probe被触发时将执行此回调。回调函数的原型通常如下:

 

C

深色版本

1gboolean probe_callback (GstPad *pad,
2                         GstPadProbeInfo *info,
3                         gpointer user_data);

在回调函数中,你可以访问和操作GstPadProbeInfo结构,这包含了触发probe的数据(如缓冲区或事件)。你可以选择是否让数据继续通过管道,或者修改数据并让它通过,甚至完全阻止数据。

例如,一个简单的Buffer Probe回调函数可能如下所示:

 

C

深色版本

1static GstPadProbeReturn
2cb_have_data (GstPad *pad,
3              GstPadProbeInfo *info,
4              gpointer data)
5{
6  GstBuffer *buf;
7
8  /* Cast the info to a buffer probe info */
9  buf = GST_PAD_PROBE_INFO_BUFFER (info);
10
11  /* Do something with the buffer here... */
12
13  /* Let the buffer pass through */
14  return GST_PAD_PROBE_OK;
15}

通过使用probe,开发者可以在不打断数据流的情况下进行调试、性能分析或实时数据处理,这在开发复杂的流媒体应用程序时非常有用。

一个例子

添加probe

  //date probe
  GstPad* pad = gst_element_get_static_pad(videosink, "sink");
  gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER,
    (GstPadProbeCallback)cb_have_data, NULL, NULL);
  gst_object_unref(pad);

回调方法


static GstPadProbeReturn
cb_have_data(GstPad* pad,
  GstPadProbeInfo* info,
  gpointer user_data) {

  GstBuffer* buffer = NULL;
  GstMapInfo map_info;
  GstStructure* s;
  gint width, height;    //图片的尺寸

  GstCaps* sink_caps = gst_pad_get_current_caps(pad);
  s = gst_caps_get_structure(sink_caps, 0);

  gboolean res;
  res = gst_structure_get_int(s, "width", &width);        //获取图片的宽
  res |= gst_structure_get_int(s, "height", &height);    //获取图片的高
  if (!res) {
    g_print("gst_structure_get_int fail\n");

    return GST_PAD_PROBE_DROP;
  }
  g_print("width=%d, height=%d \n", width, height);
  return GST_PAD_PROBE_OK;
}
 

完整例子


static GstPadProbeReturn
cb_have_data(GstPad* pad,GstPadProbeInfo* info,gpointer user_data) {GstBuffer* buffer = NULL;GstMapInfo map_info;GstStructure* s;gint width, height;	//图片的尺寸GstCaps* sink_caps = gst_pad_get_current_caps(pad);s = gst_caps_get_structure(sink_caps, 0);gboolean res;res = gst_structure_get_int(s, "width", &width);		//获取图片的宽res |= gst_structure_get_int(s, "height", &height);	//获取图片的高if (!res) {g_print("gst_structure_get_int fail\n");return GST_PAD_PROBE_DROP;}g_print("width=%d, height=%d \n", width, height);return GST_PAD_PROBE_OK;
}

从打印结果中,可以看到,回调方法被调用了

http://www.lryc.cn/news/393940.html

相关文章:

  • Open3D 点云的圆柱形邻域搜索
  • python如何设计窗口
  • C语言获取当前时间
  • 【每日一练】python三目运算符的用法
  • CentOS 7.9 停止维护(2024-6-30)后可用在线yum源 —— 筑梦之路
  • Git 常用命令备忘
  • Ubuntu24.04安装Skynet环境
  • 【C++】cout.self()函数
  • VueQuill 富文本编辑器技术文档快速上手
  • 链式二叉树oj题
  • Curator 是一个开源工具为 Elasticsearch 集群设计,用于自动化索引的维护任务。
  • STM32-PWR和WDG看门狗
  • C++循环队列 经典示例
  • 【程序大侠传】大表分库分表切换数据库类型导致pagehelper生成sql语法报错
  • 7、Redis 队列与 Stream
  • FFT剖析
  • git clone报错RPC failed; curl 92 HTTP/2 stream 7 was not closed cleanly
  • Apispec,一个用于生成 OpenAPI(Swagger)规范的 Python 库
  • SpringBoot 自定义异常返回数据格式
  • 【xinference】(15):在compshare上,使用docker-compose运行xinference和chatgpt-web项目,配置成功!!!
  • 【Unity 3D角色移动】
  • 个人视角,社会影响力:自媒体的魅力所在
  • 算法训练营day70
  • EtherCAT转Profinet网关配置说明第二讲:上位机软件配置
  • 日志自动分析-Web---360星图GoaccessALBAnolog
  • 【面试八股文】java基础知识
  • ssrf结合redis未授权getshell
  • 魔法自如:精通 IPython %automagic 命令的切换艺术
  • 基于CentOS Stream 9平台搭建MinIO以及开机自启
  • shell-awk语法整理