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狀態。