gi-gstbase-1.0.13: GStreamerBase bindings

CopyrightWill Thompson, Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.GstBase.Objects.BaseSink

Contents

Description

BaseSink is the base class for sink elements in GStreamer, such as xvimagesink or filesink. It is a layer on top of Element that provides a simplified interface to plugin writers. BaseSink handles many details for you, for example: preroll, clock synchronization, state changes, activation in push or pull mode, and queries.

In most cases, when writing sink elements, there is no need to implement class methods from Element or to set functions on pads, because the BaseSink infrastructure should be sufficient.

BaseSink provides support for exactly one sink pad, which should be named "sink". A sink implementation (subclass of BaseSink) should install a pad template in its class_init function, like so:

C code

static void
my_element_class_init (GstMyElementClass *klass)
{
  GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);

  // sinktemplate should be a #GstStaticPadTemplate with direction
  // %GST_PAD_SINK and name "sink"
  gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);

  gst_element_class_set_static_metadata (gstelement_class,
      "Sink name",
      "Sink",
      "My Sink element",
      "The author <my.sink@my.email>");
}

BaseSink will handle the prerolling correctly. This means that it will return StateChangeReturnAsync from a state change to PAUSED until the first buffer arrives in this element. The base class will call the BaseSinkClass.preroll() vmethod with this preroll buffer and will then commit the state change to the next asynchronously pending state.

When the element is set to PLAYING, BaseSink will synchronise on the clock using the times returned from BaseSinkClass.get_times(). If this function returns CLOCK_TIME_NONE for the start time, no synchronisation will be done. Synchronisation can be disabled entirely by setting the object BaseSink:sync property to False.

After synchronisation the virtual method BaseSinkClass.render() will be called. Subclasses should minimally implement this method.

Subclasses that synchronise on the clock in the BaseSinkClass.render() method are supported as well. These classes typically receive a buffer in the render method and can then potentially block on the clock while rendering. A typical example is an audiosink. These subclasses can use baseSinkWaitPreroll to perform the blocking wait.

Upon receiving the EOS event in the PLAYING state, BaseSink will wait for the clock to reach the time indicated by the stop time of the last BaseSinkClass.get_times() call before posting an EOS message. When the element receives EOS in PAUSED, preroll completes, the event is queued and an EOS message is posted when going to PLAYING.

BaseSink will internally use the EventTypeSegment events to schedule synchronisation and clipping of buffers. Buffers that fall completely outside of the current segment are dropped. Buffers that fall partially in the segment are rendered (and prerolled). Subclasses should do any subbuffer clipping themselves when needed.

BaseSink will by default report the current playback position in FormatTime based on the current clock time and segment information. If no clock has been set on the element, the query will be forwarded upstream.

The BaseSinkClass.set_caps() function will be called when the subclass should configure itself to process a specific media type.

The BaseSinkClass.start() and BaseSinkClass.stop() virtual methods will be called when resources should be allocated. Any BaseSinkClass.preroll(), BaseSinkClass.render() and BaseSinkClass.set_caps() function will be called between the BaseSinkClass.start() and BaseSinkClass.stop() calls.

The BaseSinkClass.event() virtual method will be called when an event is received by BaseSink. Normally this method should only be overridden by very specific elements (such as file sinks) which need to handle the newsegment event specially.

The BaseSinkClass.unlock() method is called when the elements should unblock any blocking operations they perform in the BaseSinkClass.render() method. This is mostly useful when the BaseSinkClass.render() method performs a blocking write on a file descriptor, for example.

The BaseSink:max-lateness property affects how the sink deals with buffers that arrive too late in the sink. A buffer arrives too late in the sink when the presentation time (as a combination of the last segment, buffer timestamp and element base_time) plus the duration is before the current time of the clock. If the frame is later than max-lateness, the sink will drop the buffer without calling the render method. This feature is disabled if sync is disabled, the BaseSinkClass.get_times() method does not return a valid start time or max-lateness is set to -1 (the default). Subclasses can use baseSinkSetMaxLateness to configure the max-lateness value.

The BaseSink:qos property will enable the quality-of-service features of the basesink which gather statistics about the real-time performance of the clock synchronisation. For each buffer received in the sink, statistics are gathered and a QOS event is sent upstream with these numbers. This information can then be used by upstream elements to reduce their processing rate, for example.

The BaseSink:async property can be used to instruct the sink to never perform an ASYNC state change. This feature is mostly usable when dealing with non-synchronized streams or sparse streams.

Synopsis

Exported types

Methods

doPreroll

baseSinkDoPreroll Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> MiniObject

obj: the mini object that caused the preroll

-> m FlowReturn

Returns: FlowReturnOk if the preroll completed and processing can continue. Any other return value should be returned from the render vmethod.

If the sink spawns its own thread for pulling buffers from upstream it should call this method after it has pulled a buffer. If the element needed to preroll, this function will perform the preroll and will then block until the element state is changed.

This function should be called with the PREROLL_LOCK held.

getBlocksize

baseSinkGetBlocksize Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> m Word32

Returns: the number of bytes sink will pull in pull mode.

Get the number of bytes that the sink will pull when it is operating in pull mode.

getLastSample

baseSinkGetLastSample Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m (Maybe Sample)

Returns: a Sample. gst_sample_unref() after usage. This function returns Nothing when no buffer has arrived in the sink yet or when the sink is not in PAUSED or PLAYING.

Get the last sample that arrived in the sink and was used for preroll or for rendering. This property can be used to generate thumbnails.

The Caps on the sample can be used to determine the type of the buffer.

Free-function: gst_sample_unref

getLatency

baseSinkGetLatency Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Word64

Returns: The configured latency.

Get the currently configured latency.

getMaxBitrate

baseSinkGetMaxBitrate Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> m Word64

Returns: the maximum number of bits per second sink will render.

Get the maximum amount of bits per second that the sink will render.

Since: 1.2

getMaxLateness

baseSinkGetMaxLateness Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Int64

Returns: The maximum time in nanoseconds that a buffer can be late before it is dropped and not rendered. A value of -1 means an unlimited time.

Gets the max lateness value. See gst_base_sink_set_max_lateness for more details.

getRenderDelay

baseSinkGetRenderDelay Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> m Word64

Returns: the render delay of sink.

Get the render delay of sink. see baseSinkSetRenderDelay for more information about the render delay.

getSync

data BaseSinkGetSyncMethodInfo Source #

Instances

((~) * signature (m Bool), MonadIO m, IsBaseSink a) => MethodInfo * BaseSinkGetSyncMethodInfo a signature Source # 

baseSinkGetSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Bool

Returns: True if the sink is configured to synchronize against the clock.

Checks if sink is currently configured to synchronize against the clock.

getThrottleTime

baseSinkGetThrottleTime Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> m Word64

Returns: the number of nanoseconds sink will put between frames.

Get the time that will be inserted between frames to control the maximum buffers per second.

getTsOffset

baseSinkGetTsOffset Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Int64

Returns: The synchronisation offset.

Get the synchronisation offset of sink.

isAsyncEnabled

baseSinkIsAsyncEnabled Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Bool

Returns: True if the sink is configured to perform asynchronous state changes.

Checks if sink is currently configured to perform asynchronous state changes to PAUSED.

isLastSampleEnabled

baseSinkIsLastSampleEnabled Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Bool

Returns: True if the sink is configured to store the last received sample.

Checks if sink is currently configured to store the last received sample in the last-sample property.

isQosEnabled

baseSinkIsQosEnabled Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m Bool

Returns: True if the sink is configured to perform Quality-of-Service.

Checks if sink is currently configured to send Quality-of-Service events upstream.

queryLatency

baseSinkQueryLatency Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m (Bool, Bool, Bool, Word64, Word64)

Returns: True if the query succeeded.

Query the sink for the latency parameters. The latency will be queried from the upstream elements. live will be True if sink is configured to synchronize against the clock. upstreamLive will be True if an upstream element is live.

If both live and upstreamLive are True, the sink will want to compensate for the latency introduced by the upstream elements by setting the minLatency to a strictly positive value.

This function is mostly used by subclasses.

setAsyncEnabled

baseSinkSetAsyncEnabled Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Bool

enabled: the new async value.

-> m () 

Configures sink to perform all state changes asynchronously. When async is disabled, the sink will immediately go to PAUSED instead of waiting for a preroll buffer. This feature is useful if the sink does not synchronize against the clock or when it is dealing with sparse streams.

setBlocksize

baseSinkSetBlocksize Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> Word32

blocksize: the blocksize in bytes

-> m () 

Set the number of bytes that the sink will pull when it is operating in pull mode.

setLastSampleEnabled

baseSinkSetLastSampleEnabled Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Bool

enabled: the new enable-last-sample value.

-> m () 

Configures sink to store the last received sample in the last-sample property.

setMaxBitrate

baseSinkSetMaxBitrate Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> Word64

maxBitrate: the max_bitrate in bits per second

-> m () 

Set the maximum amount of bits per second that the sink will render.

Since: 1.2

setMaxLateness

baseSinkSetMaxLateness Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Int64

maxLateness: the new max lateness value.

-> m () 

Sets the new max lateness value to maxLateness. This value is used to decide if a buffer should be dropped or not based on the buffer timestamp and the current clock time. A value of -1 means an unlimited time.

setQosEnabled

baseSinkSetQosEnabled Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Bool

enabled: the new qos value.

-> m () 

Configures sink to send Quality-of-Service events upstream.

setRenderDelay

baseSinkSetRenderDelay Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> Word64

delay: the new delay

-> m () 

Set the render delay in sink to delay. The render delay is the time between actual rendering of a buffer and its synchronisation time. Some devices might delay media rendering which can be compensated for with this function.

After calling this function, this sink will report additional latency and other sinks will adjust their latency to delay the rendering of their media.

This function is usually called by subclasses.

setSync

data BaseSinkSetSyncMethodInfo Source #

Instances

((~) * signature (Bool -> m ()), MonadIO m, IsBaseSink a) => MethodInfo * BaseSinkSetSyncMethodInfo a signature Source # 

baseSinkSetSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Bool

sync: the new sync value.

-> m () 

Configures sink to synchronize on the clock or not. When sync is False, incoming samples will be played as fast as possible. If sync is True, the timestamps of the incoming buffers will be used to schedule the exact render time of its contents.

setThrottleTime

baseSinkSetThrottleTime Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: a BaseSink

-> Word64

throttle: the throttle time in nanoseconds

-> m () 

Set the time that will be inserted between rendered buffers. This can be used to control the maximum buffers per second that the sink will render.

setTsOffset

baseSinkSetTsOffset Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Int64

offset: the new offset

-> m () 

Adjust the synchronisation of sink with offset. A negative value will render buffers earlier than their timestamp. A positive value will delay rendering. This function can be used to fix playback of badly timestamped buffers.

wait

data BaseSinkWaitMethodInfo Source #

Instances

((~) * signature (Word64 -> m (FlowReturn, Int64)), MonadIO m, IsBaseSink a) => MethodInfo * BaseSinkWaitMethodInfo a signature Source # 

baseSinkWait Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Word64

time: the running_time to be reached

-> m (FlowReturn, Int64)

Returns: FlowReturn

This function will wait for preroll to complete and will then block until time is reached. It is usually called by subclasses that use their own internal synchronisation but want to let some synchronization (like EOS) be handled by the base class.

This function should only be called with the PREROLL_LOCK held (like when receiving an EOS event in the ::event vmethod or when handling buffers in ::render).

The time argument should be the running_time of when the timeout should happen and will be adjusted with any latency and offset configured in the sink.

waitClock

baseSinkWaitClock Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> Word64

time: the running_time to be reached

-> m (ClockReturn, Int64)

Returns: ClockReturn

This function will block until time is reached. It is usually called by subclasses that use their own internal synchronisation.

If time is not valid, no synchronisation is done and ClockReturnBadtime is returned. Likewise, if synchronisation is disabled in the element or there is no clock, no synchronisation is done and ClockReturnBadtime is returned.

This function should only be called with the PREROLL_LOCK held, like when receiving an EOS event in the BaseSinkClass.event() vmethod or when receiving a buffer in the BaseSinkClass.render() vmethod.

The time argument should be the running_time of when this method should return and is not adjusted with any latency or offset configured in the sink.

waitPreroll

baseSinkWaitPreroll Source #

Arguments

:: (HasCallStack, MonadIO m, IsBaseSink a) 
=> a

sink: the sink

-> m FlowReturn

Returns: FlowReturnOk if the preroll completed and processing can continue. Any other return value should be returned from the render vmethod.

If the BaseSinkClass.render() method performs its own synchronisation against the clock it must unblock when going from PLAYING to the PAUSED state and call this method before continuing to render the remaining data.

This function will block until a state change to PLAYING happens (in which case this function returns FlowReturnOk) or the processing must be stopped due to a state change to READY or a FLUSH event (in which case this function returns FlowReturnFlushing).

This function should only be called with the PREROLL_LOCK held, like in the render function.

Properties

async

data BaseSinkAsyncPropertyInfo Source #

Instances

AttrInfo BaseSinkAsyncPropertyInfo Source # 
type AttrOrigin BaseSinkAsyncPropertyInfo Source # 
type AttrLabel BaseSinkAsyncPropertyInfo Source # 
type AttrGetType BaseSinkAsyncPropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkAsyncPropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkAsyncPropertyInfo Source # 
type AttrAllowedOps BaseSinkAsyncPropertyInfo Source # 

setBaseSinkAsync :: (MonadIO m, IsBaseSink o) => o -> Bool -> m () Source #

blocksize

data BaseSinkBlocksizePropertyInfo Source #

Instances

AttrInfo BaseSinkBlocksizePropertyInfo Source # 
type AttrOrigin BaseSinkBlocksizePropertyInfo Source # 
type AttrLabel BaseSinkBlocksizePropertyInfo Source # 
type AttrGetType BaseSinkBlocksizePropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkBlocksizePropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkBlocksizePropertyInfo Source # 
type AttrAllowedOps BaseSinkBlocksizePropertyInfo Source # 

enableLastSample

data BaseSinkEnableLastSamplePropertyInfo Source #

Instances

AttrInfo BaseSinkEnableLastSamplePropertyInfo Source # 
type AttrOrigin BaseSinkEnableLastSamplePropertyInfo Source # 
type AttrLabel BaseSinkEnableLastSamplePropertyInfo Source # 
type AttrGetType BaseSinkEnableLastSamplePropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkEnableLastSamplePropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkEnableLastSamplePropertyInfo Source # 
type AttrAllowedOps BaseSinkEnableLastSamplePropertyInfo Source # 

lastSample

data BaseSinkLastSamplePropertyInfo Source #

Instances

AttrInfo BaseSinkLastSamplePropertyInfo Source # 
type AttrOrigin BaseSinkLastSamplePropertyInfo Source # 
type AttrLabel BaseSinkLastSamplePropertyInfo Source # 
type AttrGetType BaseSinkLastSamplePropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkLastSamplePropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkLastSamplePropertyInfo Source # 
type AttrAllowedOps BaseSinkLastSamplePropertyInfo Source # 

maxBitrate

data BaseSinkMaxBitratePropertyInfo Source #

Instances

AttrInfo BaseSinkMaxBitratePropertyInfo Source # 
type AttrOrigin BaseSinkMaxBitratePropertyInfo Source # 
type AttrLabel BaseSinkMaxBitratePropertyInfo Source # 
type AttrGetType BaseSinkMaxBitratePropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkMaxBitratePropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkMaxBitratePropertyInfo Source # 
type AttrAllowedOps BaseSinkMaxBitratePropertyInfo Source # 

maxLateness

data BaseSinkMaxLatenessPropertyInfo Source #

Instances

AttrInfo BaseSinkMaxLatenessPropertyInfo Source # 
type AttrOrigin BaseSinkMaxLatenessPropertyInfo Source # 
type AttrLabel BaseSinkMaxLatenessPropertyInfo Source # 
type AttrGetType BaseSinkMaxLatenessPropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkMaxLatenessPropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkMaxLatenessPropertyInfo Source # 
type AttrAllowedOps BaseSinkMaxLatenessPropertyInfo Source # 

qos

data BaseSinkQosPropertyInfo Source #

Instances

AttrInfo BaseSinkQosPropertyInfo Source # 
type AttrOrigin BaseSinkQosPropertyInfo Source # 
type AttrLabel BaseSinkQosPropertyInfo Source # 
type AttrGetType BaseSinkQosPropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkQosPropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkQosPropertyInfo Source # 
type AttrAllowedOps BaseSinkQosPropertyInfo Source # 

setBaseSinkQos :: (MonadIO m, IsBaseSink o) => o -> Bool -> m () Source #

renderDelay

data BaseSinkRenderDelayPropertyInfo Source #

Instances

AttrInfo BaseSinkRenderDelayPropertyInfo Source # 
type AttrOrigin BaseSinkRenderDelayPropertyInfo Source # 
type AttrLabel BaseSinkRenderDelayPropertyInfo Source # 
type AttrGetType BaseSinkRenderDelayPropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkRenderDelayPropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkRenderDelayPropertyInfo Source # 
type AttrAllowedOps BaseSinkRenderDelayPropertyInfo Source # 

sync

data BaseSinkSyncPropertyInfo Source #

Instances

AttrInfo BaseSinkSyncPropertyInfo Source # 
type AttrOrigin BaseSinkSyncPropertyInfo Source # 
type AttrLabel BaseSinkSyncPropertyInfo Source # 
type AttrGetType BaseSinkSyncPropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkSyncPropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkSyncPropertyInfo Source # 
type AttrAllowedOps BaseSinkSyncPropertyInfo Source # 

setBaseSinkSync :: (MonadIO m, IsBaseSink o) => o -> Bool -> m () Source #

throttleTime

data BaseSinkThrottleTimePropertyInfo Source #

Instances

AttrInfo BaseSinkThrottleTimePropertyInfo Source # 
type AttrOrigin BaseSinkThrottleTimePropertyInfo Source # 
type AttrLabel BaseSinkThrottleTimePropertyInfo Source # 
type AttrGetType BaseSinkThrottleTimePropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkThrottleTimePropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkThrottleTimePropertyInfo Source # 
type AttrAllowedOps BaseSinkThrottleTimePropertyInfo Source # 

tsOffset

data BaseSinkTsOffsetPropertyInfo Source #

Instances

AttrInfo BaseSinkTsOffsetPropertyInfo Source # 
type AttrOrigin BaseSinkTsOffsetPropertyInfo Source # 
type AttrLabel BaseSinkTsOffsetPropertyInfo Source # 
type AttrGetType BaseSinkTsOffsetPropertyInfo Source # 
type AttrBaseTypeConstraint BaseSinkTsOffsetPropertyInfo Source # 
type AttrSetTypeConstraint BaseSinkTsOffsetPropertyInfo Source # 
type AttrAllowedOps BaseSinkTsOffsetPropertyInfo Source #