最近学习GStreamer应用,其中一个需求是读取本地视频,并将视频数据发送到pipeline中。经过查询网上资料和动手调试,终于实现以上功能,现发布出来,供有需要的网友查看指导。
本机环境为Linux Ubuntu16.04 x86_64。
直接上代码:
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <stdio.h>
#include <string.h>
static FILE * appSrcFile = NULL;
static int read_counter = 0;
const int SIZE = 4096;
static char read_buffer[SIZE];
GMainLoop* loop;
static void cb_need_data (GstElement *source, guint unused_size, gpointer user_data)
{
GstBuffer *buffer;
GstFlowReturn ret;
GstMapInfo map;
g_print("%s\n", __func__);
if (appSrcFile == NULL) {
appSrcFile = fopen("test.h264", "r");
}
memset(read_buffer, 0, SIZE);
int size = fread(read_buffer, 1, SIZE, appSrcFile);
g_print("read_data() read_counter=%d, size=%d\n", read_counter++, size)