Gstreamer

本文深入介绍了GStreamer的基本概念和使用,包括如何初始化、构建管道、动态调整以及元素、bin、bus和pad的管理。详细阐述了GStreamer的状态转换、内存管理和时钟同步,并探讨了自定义插件的创建过程,从基础到高级,全面解析GStreamer的工作原理和应用实践。
摘要由CSDN通过智能技术生成

standard tutorial

  1. How to initialize GStreamer using gst_init().
  2. How to quickly build a pipeline from a textual description using gst_parse_launch().
  3. How to create an automatic playback pipeline using playbin.
  4. How to signal GStreamer to start playback using gst_element_set_state().
  5. How to sit back and relax, while GStreamer takes care of everything, using gst_element_get_bus() and gst_bus_timed_pop_filtered().
  • media from source to sink
  • playbin is a special element which acts as a source and as a sink, and is a whole pipeline
  • gst_bus_timed_pop_filtered() will block until you receive either an ERROR or an EOS (End-Of-Stream) through that bus.

customize elements

  1. How to create elements with gst_element_factory_make()
  2. How to create an empty pipeline with gst_pipeline_new()
  3. How to add elements to the pipeline with gst_bin_add_many()
  4. How to link the elements with each other with gst_element_link()
  • source = gst_element_factory_make (“videotestsrc”, “source”);
    param1: type
    param2: name(if null, GStreamer will provide a unique name for you)
  • pipeline is also another particular type of BIN
  • GStreamer elements are all a particular kind of GObject
  • Properties are read from with g_object_get() and written to with g_object_set().
  • First use GST_MESSAGE_TYPE() then check error via gst_message_parse_error().
  • Messages can be extracted from the bus synchronously with gst_bus_timed_pop_filtered() and its siblings, or asynchronously, using signals.

Dynamic pipelines

//piece of invoking.
g_signal_connect(data.source, "pad-added", G_CALLBACK(pad_added_handler), &data);

static void pad_added_handler(GstElement *src, GstPad *new_pad, CustomData *data) {
   
    //Caution: `sink` here refer to pad not element
    GstPad *sink_pad = gst_element_get_static_pad(data->convert, "sink");
    GstPadLinkReturn ret;
    GstCaps *new_pad_caps = NULL;
    GstStructure *new_pad_struct = NULL;
    const gchar *new_pad_type = NULL;

    g_print("Received new pad '%s' from '%s':\n", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src));

    /* If our converter is already linked, we have nothing to do here */
    if (gst_pad_is_linked(sink_pad)) {
   
        g_print("We are already linked. Ignoring.\n");
        goto exit;
    }

    /* Check the new pad's type */
    new_pad_caps = gst_pad_get_current_caps(new_pad); //retrive all caps  (the kind of data it currently outputs)
    new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
    new_pad_type = gst_structure_get_name(new_pad_struct); //get the name and check later
    if (!g_str_has_prefix(new_pad_type, "audio/x-raw")) {
   
        g_print("It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type);
        goto exit;
    }

    /* Attempt the link */
    ret = gst_pad_link(new_pad, sink_pad);
    if (GST_PAD_LINK_FAILED(ret)) {
   
        g_print("Type is '%s' but link failed.\n", new_pad_type);
    }
    else {
   
        g_print("Link succeeded (type '%s').\n", new_pad_type);
    }

exit:
    /* Unreference the new pad's caps, if we got them */
    if (new_pad_caps != NULL)
        gst_caps_unref(new_pad_caps);

    /* Unreference the sink pad */
    gst_object_unref(sink_pad);
}

GStreamer States

State Description
NULL the NULL state or initial state of an element.
READY the element is ready to go to PAUSED.
PAUSED the element is PAUSED, it is ready to accept and process data. Sink elements however only accept one buffer and then block.
PLAYING the element is PLAYING, the clock is running and the data is flowing.

You can only move between adjacent ones

element

gst_element_factory_make实际包含了两个功能:

  1. gst_element_factory_find () //查找工厂
  2. gst_element_factory_create () //使用改工厂创建对象

gst_object_unref 计数器-1

GstElement inherits GstObject

连接元素之前必须将他们放入一个bin中

you must add elements to a bin or pipeline before linking them, since adding an element to a bin will disconnect any already existing links. Also, you cannot directly link elements that are not in the same bin or pipeline;

gst_element_set_state (GST_STATE_PLAYING) //其内部会逐个设置 READY, PAUSED

状态会向前传播,一般只需要设置上层的状态

When you set a bin or pipeline to a certain target state, it will usually propagate the state

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值