【GStreamer源码分析】playbin播放test.wav加载插件过程分析

本文详细分析了GStreamer中playbin在播放test.wav时加载插件的过程,从gst_element_set_state如何触发playbin加载流程,到playbin创建uridecodebin、加载inputSelector及playsink中涉及的组件,如uridecodebin加载filesrc、decodebin、wavparse等,展示了playbin构建pipeline的机制。
摘要由CSDN通过智能技术生成

一、前言

希望通过这篇文章记录一下 playbin 加载 plugin 的机制,熟悉一些 playbin (或者是 GStreamer)的源码

二、playbin 播放 .wav 音频插件加载一览

在这里插入图片描述
从上图可以知道 playbin可分为两部分,中间用 input-selector 连接起来

uridecodebin -> input-selector -> playsink

当然,uridecodebin 和 playsink 中也包含很多组件,我们一点一点来分析。

三、测试代码

#include <gst/gst.h>
// In which states all these operations can be performed.

/* Structure to contain all our information, so we can pass it around */
typedef struct _CustomData {
   
  GstElement *playbin;  /* Our one and only element */
  gboolean playing;      /* Are we in the PLAYING state? */
  gboolean terminate;    /* Should we terminate execution? */
  gboolean seek_enabled; /* Is seeking enabled for this media? */
  gboolean seek_done;    /* Have we performed the seek already? */
  gint64 duration;       /* How long does this media last, in nanoseconds */
} CustomData;

/* Forward definition of the message processing function */
static void handle_message (CustomData *data, GstMessage *msg);

int main(int argc, char *argv[]) {
   
  CustomData data;
  GstBus *bus;
  GstMessage *msg;
  GstStateChangeReturn ret;

  data.playing = FALSE;
  data.terminate = FALSE;
  data.seek_enabled = FALSE;
  data.seek_done = FALSE;
  data.duration = GST_CLOCK_TIME_NONE;

  /* Initialize GStreamer */
  gst_init (&argc, &argv);
  // return 0;

  /* Create the elements */
  data.playbin = gst_element_factory_make ("playbin", "playbin");

  if (!data.playbin) {
   
    g_printerr ("Not all elements could be created.\n");
    return -1;
  }

  /* Set the URI to play */
  g_object_set (data.playbin, "uri", "file:///home/joshua/Project/gst_base_tutorial/media/test.wav", NULL);



    /* Start playing */
  ret = gst_element_set_state (data.playbin, GST_STATE_PLAYING);


  if (ret == GST_STATE_CHANGE_FAILURE) {
   
    g_printerr ("Unable to set the pipeline to the playing state.\n");
    gst_object_unref (data.playbin);
    return -1;
  }

  /* Listen to the bus */
  bus = gst_element_get_bus (data.playbin);
  do {
   
    msg = gst_bus_timed_pop_filtered (bus, 100 * GST_MSECOND,
        GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_DURATION);

    /* Parse message */
    if (msg != NULL) {
   
      handle_message (&data, msg);
    } else {
   
      /* We got no message, this means the timeout expired */
      if (data.playing) {
   
        gint64 current = -1;

        /* Query the current position of the stream */
        if (!gst_element_query_position (data.playbin, GST_FORMAT_TIME, &current)) {
   
          g_printerr ("Could not query current position.\n");
        }

        /* If we didn't know it yet, query the stream duration */
        if (!GST_CLOCK_TIME_IS_VALID (data.duration)) {
   
          if (!gst_element_query_duration (data.playbin, GST_FORMAT_TIME, &data.duration)) {
   
            g_printerr ("Could not query current duration.\n");
          }
        }

        /* Print current position and total duration */
        g_print ("Position %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\r",
            GST_TIME_ARGS (current), GST_TIME_ARGS (data.duration));

        /* If seeking is enabled, we have not done it yet, and the time is right, seek */
   
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值