GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info); GstH264NalUnitType nal_type = GST_H264_NAL_UNIT_TYPE (GST_BUFFER_DATA (buf)[0]);提示error: subscripted value is neither array nor pointer nor vector应该如何修改
时间: 2023-10-04 22:10:34 浏览: 156
这个错误通常是因为缺少包含相应头文件的声明。你需要包含 `gst/codecparsers/gsth264parser.h` 头文件来解决这个问题,该头文件定义了 `gst_h264_nal_unit_type_get_type()` 和 `GST_H264_NAL_UNIT_TYPE()` 宏,使你能够使用 `GST_H264_NAL_UNIT_TYPE()` 宏来获取 `GstH264NalUnitType` 类型的值。修改后的示例代码如下:
```c
#include <gst/gst.h>
#include <gst/codecparsers/gsth264parser.h>
static GstPadProbeReturn
sps_pps_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
GstH264NalUnitType nal_type = GST_H264_NAL_UNIT_TYPE (GST_BUFFER_DATA (buf)[0]);
if (nal_type == GST_H264_NAL_SPS) {
// This is an SPS unit
guint8 *sps = GST_BUFFER_DATA (buf);
guint sps_len = GST_BUFFER_SIZE (buf);
// Do something with the SPS data
} else if (nal_type == GST_H264_NAL_PPS) {
// This is a PPS unit
guint8 *pps = GST_BUFFER_DATA (buf);
guint pps_len = GST_BUFFER_SIZE (buf);
// Do something with the PPS data
}
return GST_PAD_PROBE_OK;
}
int main(int argc, char *argv[]) {
GstElement *pipeline, *source, *h264parse;
GstBus *bus;
GstMessage *msg;
/* Initialize GStreamer */
gst_init(&argc, &argv);
/* Create the elements */
source = gst_element_factory_make("filesrc", "source");
h264parse = gst_element_factory_make("h264parse", "h264parse");
/* Create the pipeline */
pipeline = gst_pipeline_new("test-pipeline");
/* Build the pipeline */
gst_bin_add_many(GST_BIN(pipeline), source, h264parse, NULL);
gst_element_link_many(source, h264parse, NULL);
/* Set the input file */
g_object_set(G_OBJECT(source), "location", "test.h264", NULL);
/* Register the SPS/PPS probe */
GstPad *h264parse_src_pad = gst_element_get_static_pad(h264parse, "src");
gst_pad_add_probe(h264parse_src_pad, GST_PAD_PROBE_TYPE_BUFFER, sps_pps_probe_cb, NULL, NULL);
/* Start playing */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
/* Wait until error or end of the stream */
bus = gst_element_get_bus(pipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
if (msg != NULL) {
gst_message_unref(msg);
}
/* Free resources */
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
return 0;
}
```
请确保你已经正确安装了 GStreamer 和相关的插件,以及包含了正确的头文件和库文件。
阅读全文