Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (inaki@blueleaf.cc) |
Safe Haskell | None |
Language | Haskell2010 |
This helper structure holds the relevant values for tracking the region of interest in a media file, called a segment.
The structure can be used for two purposes:
- performing seeks (handling seek events)
- tracking playback regions (handling newsegment events)
The segment is usually configured by the application with a seek event which is propagated upstream and eventually handled by an element that performs the seek.
The configured segment is then propagated back downstream with a newsegment event. This information is then used to clip media to the segment boundaries.
A segment structure is initialized with segmentInit
, which takes a Format
that will be used as the format of the segment values. The segment will be configured
with a start value of 0 and a stop/duration of -1, which is undefined. The default
rate and applied_rate is 1.0.
The public duration field contains the duration of the segment. When using the segment for seeking, the start and time members should normally be left to their default 0 value. The stop position is left to -1 unless explicitly configured to a different value after a seek event.
The current position in the segment should be set by changing the position member in the structure.
For elements that perform seeks, the current segment should be updated with the
segmentDoSeek
and the values from the seek event. This method will update
all the segment fields. The position field will contain the new playback position.
If the start_type was different from GST_SEEK_TYPE_NONE, playback continues from
the position position, possibly with updated flags or rate.
For elements that want to use Segment
to track the playback region,
update the segment fields with the information from the newsegment event.
The segmentClip
method can be used to check and clip
the media data to the segment boundaries.
For elements that want to synchronize to the pipeline clock, segmentToRunningTime
can be used to convert a timestamp to a value that can be used to synchronize
to the clock. This function takes into account the base as well as
any rate or applied_rate conversions.
For elements that need to perform operations on media data in stream_time,
segmentToStreamTime
can be used to convert a timestamp and the segment
info to stream time (which is always between 0 and the duration of the stream).
Synopsis
- newtype Segment = Segment (ManagedPtr Segment)
- newZeroSegment :: MonadIO m => m Segment
- noSegment :: Maybe Segment
- segmentClip :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> Word64 -> m (Bool, Word64, Word64)
- segmentCopy :: (HasCallStack, MonadIO m) => Segment -> m Segment
- segmentCopyInto :: (HasCallStack, MonadIO m) => Segment -> Segment -> m ()
- segmentDoSeek :: (HasCallStack, MonadIO m) => Segment -> Double -> Format -> [SeekFlags] -> SeekType -> Word64 -> SeekType -> Word64 -> m (Bool, Bool)
- segmentFree :: (HasCallStack, MonadIO m) => Segment -> m ()
- segmentInit :: (HasCallStack, MonadIO m) => Segment -> Format -> m ()
- segmentIsEqual :: (HasCallStack, MonadIO m) => Segment -> Segment -> m Bool
- segmentNew :: (HasCallStack, MonadIO m) => m Segment
- segmentOffsetRunningTime :: (HasCallStack, MonadIO m) => Segment -> Format -> Int64 -> m Bool
- segmentPositionFromRunningTime :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m Word64
- segmentPositionFromRunningTimeFull :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m (Int32, Word64)
- segmentPositionFromStreamTime :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m Word64
- segmentPositionFromStreamTimeFull :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m (Int32, Word64)
- segmentSetRunningTime :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m Bool
- segmentToPosition :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m Word64
- segmentToRunningTime :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m Word64
- segmentToRunningTimeFull :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m (Int32, Word64)
- segmentToStreamTime :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m Word64
- segmentToStreamTimeFull :: (HasCallStack, MonadIO m) => Segment -> Format -> Word64 -> m (Int32, Word64)
- getSegmentAppliedRate :: MonadIO m => Segment -> m Double
- setSegmentAppliedRate :: MonadIO m => Segment -> Double -> m ()
- getSegmentBase :: MonadIO m => Segment -> m Word64
- setSegmentBase :: MonadIO m => Segment -> Word64 -> m ()
- getSegmentDuration :: MonadIO m => Segment -> m Word64
- setSegmentDuration :: MonadIO m => Segment -> Word64 -> m ()
- getSegmentFlags :: MonadIO m => Segment -> m [SegmentFlags]
- setSegmentFlags :: MonadIO m => Segment -> [SegmentFlags] -> m ()
- getSegmentFormat :: MonadIO m => Segment -> m Format
- setSegmentFormat :: MonadIO m => Segment -> Format -> m ()
- getSegmentOffset :: MonadIO m => Segment -> m Word64
- setSegmentOffset :: MonadIO m => Segment -> Word64 -> m ()
- getSegmentPosition :: MonadIO m => Segment -> m Word64
- setSegmentPosition :: MonadIO m => Segment -> Word64 -> m ()
- getSegmentRate :: MonadIO m => Segment -> m Double
- setSegmentRate :: MonadIO m => Segment -> Double -> m ()
- getSegmentStart :: MonadIO m => Segment -> m Word64
- setSegmentStart :: MonadIO m => Segment -> Word64 -> m ()
- getSegmentStop :: MonadIO m => Segment -> m Word64
- setSegmentStop :: MonadIO m => Segment -> Word64 -> m ()
- getSegmentTime :: MonadIO m => Segment -> m Word64
- setSegmentTime :: MonadIO m => Segment -> Word64 -> m ()
Exported types
Memory-managed wrapper type.
Instances
BoxedObject Segment Source # | |
tag ~ AttrSet => Constructible Segment tag Source # | |
Defined in GI.Gst.Structs.Segment |
Methods
clip
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> Word64 |
|
-> m (Bool, Word64, Word64) | Returns: |
Clip the given start
and stop
values to the segment boundaries given
in segment
. start
and stop
are compared and clipped to segment
start and stop values.
If the function returns False
, start
and stop
are known to fall
outside of segment
and clipStart
and clipStop
are not updated.
When the function returns True
, clipStart
and clipStop
will be
updated. If clipStart
or clipStop
are different from start
or stop
respectively, the region fell partially in the segment.
Note that when stop
is -1, clipStop
will be set to the end of the
segment. Depending on the use case, this may or may not be what you want.
copy
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> m Segment | Returns: a new |
Create a copy of given segment
.
Free-function: gst_segment_free
copyInto
Copy the contents of src
into dest
.
doSeek
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Double |
|
-> Format |
|
-> [SeekFlags] |
|
-> SeekType |
|
-> Word64 |
|
-> SeekType |
|
-> Word64 |
|
-> m (Bool, Bool) | Returns: |
Update the segment structure with the field values of a seek event (see
eventNewSeek
).
After calling this method, the segment field position and time will
contain the requested new position in the segment. The new requested
position in the segment depends on rate
and startType
and stopType
.
For positive rate
, the new position in the segment is the new segment
start field when it was updated with a startType
different from
GST_SEEK_TYPE_NONE
. If no update was performed on segment
start position
(GST_SEEK_TYPE_NONE
), start
is ignored and segment
position is
unmodified.
For negative rate
, the new position in the segment is the new segment
stop field when it was updated with a stopType
different from
GST_SEEK_TYPE_NONE
. If no stop was previously configured in the segment, the
duration of the segment will be used to update the stop position.
If no update was performed on segment
stop position (GST_SEEK_TYPE_NONE
),
stop
is ignored and segment
position is unmodified.
The applied rate of the segment will be set to 1.0 by default.
If the caller can apply a rate change, it should update segment
rate and applied_rate after calling this function.
update
will be set to True
if a seek should be performed to the segment
position field. This field can be False
if, for example, only the rate
has been changed but not the playback position.
free
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> m () |
Free the allocated segment segment
.
init
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> m () |
The start/position fields are set to 0 and the stop/duration fields are set to -1 (unknown). The default rate of 1.0 and no flags are set.
Initialize segment
to its default values.
isEqual
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Segment |
|
-> m Bool |
Checks for two segments being equal. Equality here is defined as perfect equality, including floating point values.
Since: 1.6
new
:: (HasCallStack, MonadIO m) | |
=> m Segment | Returns: a new |
Allocate a new Segment
structure and initialize it using
segmentInit
.
Free-function: gst_segment_free
offsetRunningTime
segmentOffsetRunningTime Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Int64 |
|
-> m Bool | Returns: |
Adjust the values in segment
so that offset
is applied to all
future running-time calculations.
Since: 1.2.3
positionFromRunningTime
segmentPositionFromRunningTime Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m Word64 | Returns: the position in the segment for |
Convert runningTime
into a position in the segment so that
segmentToRunningTime
with that position returns runningTime
.
Since: 1.8
positionFromRunningTimeFull
segmentPositionFromRunningTimeFull Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m (Int32, Word64) | Returns: a 1 or -1 on success, 0 on failure. |
Translate runningTime
to the segment position using the currently configured
segment. Compared to segmentPositionFromRunningTime
this function can
return negative segment position.
This function is typically used by elements that need to synchronize buffers against the clock or each other.
runningTime
can be any value and the result of this function for values
outside of the segment is extrapolated.
When 1 is returned, runningTime
resulted in a positive position returned
in position
.
When this function returns -1, the returned position
was < 0, and the value
in the position variable should be negated to get the real negative segment
position.
Since: 1.8
positionFromStreamTime
segmentPositionFromStreamTime Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m Word64 | Returns: the position in the segment for |
Convert streamTime
into a position in the segment so that
segmentToStreamTime
with that position returns streamTime
.
Since: 1.8
positionFromStreamTimeFull
segmentPositionFromStreamTimeFull Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m (Int32, Word64) | Returns: a 1 or -1 on success, 0 on failure. |
Translate streamTime
to the segment position using the currently configured
segment. Compared to segmentPositionFromStreamTime
this function can
return negative segment position.
This function is typically used by elements that need to synchronize buffers against the clock or each other.
streamTime
can be any value and the result of this function for values outside
of the segment is extrapolated.
When 1 is returned, streamTime
resulted in a positive position returned
in position
.
When this function returns -1, the returned position
should be negated
to get the real negative segment position.
Since: 1.8
setRunningTime
segmentSetRunningTime Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m Bool | Returns: |
Adjust the start/stop and base values of segment
such that the next valid
buffer will be one with runningTime
.
toPosition
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m Word64 | Returns: the position in the segment for |
Deprecated: Use segmentPositionFromRunningTime
instead.
Convert runningTime
into a position in the segment so that
segmentToRunningTime
with that position returns runningTime
.
toRunningTime
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m Word64 | Returns: the position as the total running time or -1 when an invalid position was given. |
Translate position
to the total running time using the currently configured
segment. Position is a value between segment
start and stop time.
This function is typically used by elements that need to synchronize to the
global clock in a pipeline. The running time is a constantly increasing value
starting from 0. When segmentInit
is called, this value will reset to
0.
This function returns -1 if the position is outside of segment
start and stop.
toRunningTimeFull
segmentToRunningTimeFull Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m (Int32, Word64) | Returns: a 1 or -1 on success, 0 on failure. |
Translate position
to the total running time using the currently configured
segment. Compared to segmentToRunningTime
this function can return
negative running-time.
This function is typically used by elements that need to synchronize buffers against the clock or each other.
position
can be any value and the result of this function for values outside
of the segment is extrapolated.
When 1 is returned, position
resulted in a positive running-time returned
in runningTime
.
When this function returns -1, the returned runningTime
should be negated
to get the real negative running time.
Since: 1.6
toStreamTime
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m Word64 | Returns: the position in stream_time or -1 when an invalid position was given. |
Translate position
to stream time using the currently configured
segment. The position
value must be between segment
start and
stop value.
This function is typically used by elements that need to operate on
the stream time of the buffers it receives, such as effect plugins.
In those use cases, position
is typically the buffer timestamp or
clock time that one wants to convert to the stream time.
The stream time is always between 0 and the total duration of the
media stream.
Since: 1.8
toStreamTimeFull
segmentToStreamTimeFull Source #
:: (HasCallStack, MonadIO m) | |
=> Segment |
|
-> Format |
|
-> Word64 |
|
-> m (Int32, Word64) | Returns: a 1 or -1 on success, 0 on failure. |
Translate position
to the total stream time using the currently configured
segment. Compared to segmentToStreamTime
this function can return
negative stream-time.
This function is typically used by elements that need to synchronize buffers against the clock or each other.
position
can be any value and the result of this function for values outside
of the segment is extrapolated.
When 1 is returned, position
resulted in a positive stream-time returned
in streamTime
.
When this function returns -1, the returned streamTime
should be negated
to get the real negative stream time.
Since: 1.8
Properties
appliedRate
the already applied rate to the segment
getSegmentAppliedRate :: MonadIO m => Segment -> m Double Source #
Get the value of the “applied_rate
” field.
When overloading is enabled, this is equivalent to
get
segment #appliedRate
setSegmentAppliedRate :: MonadIO m => Segment -> Double -> m () Source #
Set the value of the “applied_rate
” field.
When overloading is enabled, this is equivalent to
set
segment [ #appliedRate:=
value ]
base
the running time (plus elapsed time, see offset) of the segment start
getSegmentBase :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “base
” field.
When overloading is enabled, this is equivalent to
get
segment #base
setSegmentBase :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “base
” field.
When overloading is enabled, this is equivalent to
set
segment [ #base:=
value ]
duration
the duration of the stream
getSegmentDuration :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “duration
” field.
When overloading is enabled, this is equivalent to
get
segment #duration
setSegmentDuration :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “duration
” field.
When overloading is enabled, this is equivalent to
set
segment [ #duration:=
value ]
flags
flags for this segment
getSegmentFlags :: MonadIO m => Segment -> m [SegmentFlags] Source #
Get the value of the “flags
” field.
When overloading is enabled, this is equivalent to
get
segment #flags
setSegmentFlags :: MonadIO m => Segment -> [SegmentFlags] -> m () Source #
Set the value of the “flags
” field.
When overloading is enabled, this is equivalent to
set
segment [ #flags:=
value ]
format
the format of the segment values
getSegmentFormat :: MonadIO m => Segment -> m Format Source #
Get the value of the “format
” field.
When overloading is enabled, this is equivalent to
get
segment #format
setSegmentFormat :: MonadIO m => Segment -> Format -> m () Source #
Set the value of the “format
” field.
When overloading is enabled, this is equivalent to
set
segment [ #format:=
value ]
offset
the amount (in buffer timestamps) that has already been elapsed in the segment
getSegmentOffset :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “offset
” field.
When overloading is enabled, this is equivalent to
get
segment #offset
setSegmentOffset :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “offset
” field.
When overloading is enabled, this is equivalent to
set
segment [ #offset:=
value ]
position
the buffer timestamp position in the segment (used internally by elements such as sources, demuxers or parsers to track progress)
getSegmentPosition :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “position
” field.
When overloading is enabled, this is equivalent to
get
segment #position
setSegmentPosition :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “position
” field.
When overloading is enabled, this is equivalent to
set
segment [ #position:=
value ]
rate
the playback rate of the segment
getSegmentRate :: MonadIO m => Segment -> m Double Source #
Get the value of the “rate
” field.
When overloading is enabled, this is equivalent to
get
segment #rate
setSegmentRate :: MonadIO m => Segment -> Double -> m () Source #
Set the value of the “rate
” field.
When overloading is enabled, this is equivalent to
set
segment [ #rate:=
value ]
start
the start of the segment in buffer timestamp time (PTS)
getSegmentStart :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “start
” field.
When overloading is enabled, this is equivalent to
get
segment #start
setSegmentStart :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “start
” field.
When overloading is enabled, this is equivalent to
set
segment [ #start:=
value ]
stop
the stop of the segment in buffer timestamp time (PTS)
getSegmentStop :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “stop
” field.
When overloading is enabled, this is equivalent to
get
segment #stop
setSegmentStop :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “stop
” field.
When overloading is enabled, this is equivalent to
set
segment [ #stop:=
value ]
time
the stream time of the segment start
getSegmentTime :: MonadIO m => Segment -> m Word64 Source #
Get the value of the “time
” field.
When overloading is enabled, this is equivalent to
get
segment #time
setSegmentTime :: MonadIO m => Segment -> Word64 -> m () Source #
Set the value of the “time
” field.
When overloading is enabled, this is equivalent to
set
segment [ #time:=
value ]