GstAppSrc简介

Description

  The appsrc element can be used by applications to insert data into a GStreamer pipeline. Unlike most GStreamer elements, appsrc provides external API functions.appsrc can be used by linking with the libgstapp library to access the methods directly or by using the appsrc action signals.

  应用程序可以通过appsrc元件向管道中插入数据。appsrc有别于其他GStreamer元件,它提供额外的API函数。通过链接libgstapp库来使用appsrc,直接调用其方法或者使用appsrc的响应信号。

  Before operating appsrc, the caps property must be set to fixed caps describing the format of the data that will be pushed with appsrc. An exception to this is when pushing buffers with unknown caps, in which case no caps should be set. This is typically true of file-like sources that push raw byte buffers. If you don't want to explicitly set the caps, you can use gst_app_src_push_sample. This method gets the caps associated with the sample and sets them on the appsrc replacing any previously set caps (if different from sample's caps).

  在操作appsrc前,caps属性必须被设定为一个固定的caps,以描述被推进appsrc数据的格式。当推送缓存搭到一个未知的caps即caps没有被设置,这时会发生一个异常。当使用类似文件一样的源时,推送其原始数据到appsrc将会典型地发生这种情况。如果你不想准确地设定caps,你可以使用gst_app_src_push_sample函数,该函数获取与采样数据关联的caps,且该caps取代appsrc上先前已设定的caps(如果你设定的caps不同于原来采样的caps)。

  The main way of handing data to the appsrc element is by calling the gst_app_src_push_buffer() method or by emitting the push-buffer action signal. This will put the buffer onto a queue from which appsrc will read from in its streaming thread. It is important to note that data transport will not happen from the thread that performed the push-buffer call.

  主要的操作数据到appsrc元件中的方式是调用gst_app_src_push_buffer方法,或者是发送push-buffer响应信号,该操作将缓存放进了一个队列,appsrc将在它的流线程中读取该队列中的数据。值得注意的是数据传输过程不是在执行push-buffer操作的线程。

  The "max-bytes" property controls how much data can be queued in appsrc before appsrc considers the queue full. A filled internal queue will always signal the "enough-data" signal, which signals the application that it should stop pushing data into appsrc. The "block" property will cause appsrc to block the push-buffer method until free data becomes available again.When the internal queue is running out of data, the "need-data" signal is emitted, which signals the application that it should start pushing more data into appsrc.

  max-bytes属性控制了在被appsrc认为队列满之前有多少数据可以被放进appsrc里的队列中。内部队列满时将发出“enough-data”信号,该信号通知应用程序应该停止向appsrc中推送数据了。block属性将是appsrc阻塞push-buffer方法直到可以推进去数据。当内部队列没有可用的数据,“need-data”信号将被发送,该信号将通知应用程序应该推送更多的数据到appsrc中。

  In addition to the "need-data" and "enough-data" signals, appsrc can emit the "seek-data" signal when the "stream-mode" property is set to "seekable" or "random-access". The signal argument will contain the new desired position in the stream expressed in the unit set with the "format" property. After receiving the seek-data signal, the application should push-buffers from the new position.These signals allow the application to operate the appsrc in two different ways:

  在“need-data”和“enough-data”之外,当stream-mode属性设置为seekable或者random-access时,appsrc能够发送“seek-data”信号。该信号的参数包含了新的希望在stream中设定的位置,且该参数以format属性为单位。在接收到seek-data信号后,应用程序应该从新的位置开始推送数据。这些信号(need-data,enought-data,和seek-data)允许应用程序以两种不同的方式操作appsrc。

  The push mode, in which the application repeatedly calls the push-buffer/push-sample method with a new buffer/sample. Optionally, the queue size in the appsrc can be controlled with the enough-data and need-data signals by respectively stopping/starting the push-buffer/push-sample calls. This is a typical mode of operation for the stream-type "stream" and "seekable". Use this mode when implementing various network protocols or hardware devices.

  推模式,应用程序重复的调用push-buffer/push-sample函数(来向appsrc中)推送一个新的buffer/sample。appsrc中队列里缓存的数量能够被控制,通过enough-data、need-data信号相应的停止或者开始调用push-buffer/push-sample。在stream-type属性为stream和seekable时,这是一种典型的模式。处理各种网络协议或者硬件设备(打交道)时使用这种模式。

  The pull mode, in which the need-data signal triggers the next push-buffer call. This mode is typically used in the "random-access" stream-type. Use this mode for file access or other randomly accessable sources. In this mode, a buffer of exactly the amount of bytes given by the need-data signal should be pushed into appsrc.

  拉模式,该模式下,need-data信号触发下一次push-buffer函数调用。该模式在random-access流类型下被典型使用。对于文件操作或者其他的可随机操作源使用这种模式,在这种模式下,由need-data信号确定字节数的缓存应该被推进appsrc中。

  In all modes, the size property on appsrc should contain the total stream size in bytes. Setting this property is mandatory in the random-access mode. For the stream and seekable modes, setting this property is optional but recommended.

  在所有模式下,appsrc的size属性都将以字节数表示包含的总的流数量。在random-access模式下务必要设置该属性,对于stream好seekable模式,该属性是可选但被推荐设置的。

  When the application has finished pushing data into appsrc, it should call gst_app_src_end_of_stream() or emit the end-of-stream action signal. After this call, no more buffers can be pushed into appsrc until a flushing seek occurs or the state of the appsrc has gone through READY.

  当应用程序完成推送数据到appsrc,其应该调用gst_app_src_end_of_stream函数,或者发送end-of-stream响应信号。在调用该函数后,不应该再由缓存被推送到appsrc,直到立即定位发生或者是appsrc切换到了REAY状态。

原文地址:https://www.cnblogs.com/kanite/p/10768811.html