Class Segment
- All Implemented Interfaces:
Proxy
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 gst_segment_init(), which takes a GstFormat
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 gst_segment_do_seek() 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 GstSegment
to track the playback region,
update the segment fields with the information from the newsegment event.
The gst_segment_clip() 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, gst_segment_to_running_time() 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, gst_segment_to_stream_time() 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).
-
Constructor Summary
ConstructorDescriptionSegment()
Allocate a newGstSegment
structure and initialize it using gst_segment_init().Segment
(MemorySegment address) Create a Segment proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
clip
(Format format, long start, long stop, @Nullable Out<Long> clipStart, @Nullable Out<Long> clipStop) Clip the givenstart
andstop
values to the segment boundaries given in this Segment.copy()
Create a copy of given this Segment.void
Copy the contents of this Segment intodest
.boolean
doSeek
(double rate, Format format, Set<SeekFlags> flags, SeekType startType, long start, SeekType stopType, long stop, @Nullable Out<Boolean> update) Update the segment structure with the field values of a seek event (see gst_event_new_seek()).boolean
doSeek
(double rate, Format format, SeekFlags flags, SeekType startType, long start, SeekType stopType, long stop, @Nullable Out<Boolean> update) Update the segment structure with the field values of a seek event (see gst_event_new_seek()).void
free()
Free the allocated segment this Segment.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the Segment classvoid
The start/position fields are set to 0 and the stop/duration fields are set to -1 (unknown).boolean
Checks for two segments being equal.boolean
offsetRunningTime
(Format format, long offset) Adjust the values in this Segment so thatoffset
is applied to all future running-time calculations.long
positionFromRunningTime
(Format format, long runningTime) ConvertrunningTime
into a position in the segment so that gst_segment_to_running_time() with that position returnsrunningTime
.int
positionFromRunningTimeFull
(Format format, long runningTime, Out<Long> position) TranslaterunningTime
to the segment position using the currently configured segment.long
positionFromStreamTime
(Format format, long streamTime) ConvertstreamTime
into a position in the segment so that gst_segment_to_stream_time() with that position returnsstreamTime
.int
positionFromStreamTimeFull
(Format format, long streamTime, Out<Long> position) TranslatestreamTime
to the segment position using the currently configured segment.double
Read the value of the fieldapplied_rate
.long
readBase()
Read the value of the fieldbase
.long
Read the value of the fieldduration
.Read the value of the fieldflags
.Read the value of the fieldformat
.long
Read the value of the fieldoffset
.long
Read the value of the fieldposition
.double
readRate()
Read the value of the fieldrate
.long
Read the value of the fieldstart
.long
readStop()
Read the value of the fieldstop
.long
readTime()
Read the value of the fieldtime
.boolean
setRunningTime
(Format format, long runningTime) Adjust the start/stop and base values of this Segment such that the next valid buffer will be one withrunningTime
.long
toPosition
(Format format, long runningTime) Deprecated.Use gst_segment_position_from_running_time() instead.long
toRunningTime
(Format format, long position) Translateposition
to the total running time using the currently configured segment.int
toRunningTimeFull
(Format format, long position, @Nullable Out<Long> runningTime) Translateposition
to the total running time using the currently configured segment.long
toStreamTime
(Format format, long position) Translateposition
to stream time using the currently configured segment.int
toStreamTimeFull
(Format format, long position, Out<Long> streamTime) Translateposition
to the total stream time using the currently configured segment.void
writeAppliedRate
(double appliedRate) Write a value in the fieldapplied_rate
.void
writeBase
(long base) Write a value in the fieldbase
.void
writeDuration
(long duration) Write a value in the fieldduration
.void
writeFlags
(Set<SegmentFlags> flags) Write a value in the fieldflags
.void
writeFormat
(Format format) Write a value in the fieldformat
.void
writeOffset
(long offset) Write a value in the fieldoffset
.void
writePosition
(long position) Write a value in the fieldposition
.void
writeRate
(double rate) Write a value in the fieldrate
.void
writeStart
(long start) Write a value in the fieldstart
.void
writeStop
(long stop) Write a value in the fieldstop
.void
writeTime
(long time) Write a value in the fieldtime
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Segment
Create a Segment proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Segment
public Segment()Allocate a newGstSegment
structure and initialize it using gst_segment_init().Free-function: gst_segment_free
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readFlags
Read the value of the fieldflags
.- Returns:
- The value of the field
flags
-
writeFlags
Write a value in the fieldflags
.- Parameters:
flags
- The new value for the fieldflags
-
readRate
public double readRate()Read the value of the fieldrate
.- Returns:
- The value of the field
rate
-
writeRate
public void writeRate(double rate) Write a value in the fieldrate
.- Parameters:
rate
- The new value for the fieldrate
-
readAppliedRate
public double readAppliedRate()Read the value of the fieldapplied_rate
.- Returns:
- The value of the field
applied_rate
-
writeAppliedRate
public void writeAppliedRate(double appliedRate) Write a value in the fieldapplied_rate
.- Parameters:
appliedRate
- The new value for the fieldapplied_rate
-
readFormat
Read the value of the fieldformat
.- Returns:
- The value of the field
format
-
writeFormat
Write a value in the fieldformat
.- Parameters:
format
- The new value for the fieldformat
-
readBase
public long readBase()Read the value of the fieldbase
.- Returns:
- The value of the field
base
-
writeBase
public void writeBase(long base) Write a value in the fieldbase
.- Parameters:
base
- The new value for the fieldbase
-
readOffset
public long readOffset()Read the value of the fieldoffset
.- Returns:
- The value of the field
offset
-
writeOffset
public void writeOffset(long offset) Write a value in the fieldoffset
.- Parameters:
offset
- The new value for the fieldoffset
-
readStart
public long readStart()Read the value of the fieldstart
.- Returns:
- The value of the field
start
-
writeStart
public void writeStart(long start) Write a value in the fieldstart
.- Parameters:
start
- The new value for the fieldstart
-
readStop
public long readStop()Read the value of the fieldstop
.- Returns:
- The value of the field
stop
-
writeStop
public void writeStop(long stop) Write a value in the fieldstop
.- Parameters:
stop
- The new value for the fieldstop
-
readTime
public long readTime()Read the value of the fieldtime
.- Returns:
- The value of the field
time
-
writeTime
public void writeTime(long time) Write a value in the fieldtime
.- Parameters:
time
- The new value for the fieldtime
-
readPosition
public long readPosition()Read the value of the fieldposition
.- Returns:
- The value of the field
position
-
writePosition
public void writePosition(long position) Write a value in the fieldposition
.- Parameters:
position
- The new value for the fieldposition
-
readDuration
public long readDuration()Read the value of the fieldduration
.- Returns:
- The value of the field
duration
-
writeDuration
public void writeDuration(long duration) Write a value in the fieldduration
.- Parameters:
duration
- The new value for the fieldduration
-
clip
public boolean clip(Format format, long start, long stop, @Nullable @Nullable Out<Long> clipStart, @Nullable @Nullable Out<Long> clipStop) Clip the givenstart
andstop
values to the segment boundaries given in this Segment.start
andstop
are compared and clipped to this Segment start and stop values.If the function returns
false
,start
andstop
are known to fall outside of this Segment andclipStart
andclipStop
are not updated.When the function returns
true
,clipStart
andclipStop
will be updated. IfclipStart
orclipStop
are different fromstart
orstop
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.- Parameters:
format
- the format of the segment.start
- the start position in the segmentstop
- the stop position in the segmentclipStart
- the clipped start position in the segmentclipStop
- the clipped stop position in the segment- Returns:
true
if the givenstart
andstop
times fall partially or completely in this Segment,false
if the values are completely outside of the segment.
-
copy
Create a copy of given this Segment.Free-function: gst_segment_free
- Returns:
- a new
GstSegment
, free with gst_segment_free().
-
copyInto
Copy the contents of this Segment intodest
.- Parameters:
dest
- aGstSegment
-
doSeek
public boolean doSeek(double rate, Format format, Set<SeekFlags> flags, SeekType startType, long start, SeekType stopType, long stop, @Nullable @Nullable Out<Boolean> update) Update the segment structure with the field values of a seek event (see gst_event_new_seek()).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
andstartType
andstopType
.For positive
rate
, the new position in the segment is the new this Segment start field when it was updated with astartType
different fromGST_SEEK_TYPE_NONE
. If no update was performed on this Segment start position (GST_SEEK_TYPE_NONE
),start
is ignored and this Segment position is unmodified.For negative
rate
, the new position in the segment is the new this Segment stop field when it was updated with astopType
different fromGST_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 this Segment stop position (GST_SEEK_TYPE_NONE
),stop
is ignored and this 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 this Segment rate and applied_rate after calling this function.
update
will be set totrue
if a seek should be performed to the segment position field. This field can befalse
if, for example, only therate
has been changed but not the playback position.- Parameters:
rate
- the rate of the segment.format
- the format of the segment.flags
- the segment flags for the segmentstartType
- the seek methodstart
- the seek start valuestopType
- the seek methodstop
- the seek stop valueupdate
- boolean holding whether position was updated.- Returns:
true
if the seek could be performed.
-
doSeek
public boolean doSeek(double rate, Format format, SeekFlags flags, SeekType startType, long start, SeekType stopType, long stop, @Nullable @Nullable Out<Boolean> update) Update the segment structure with the field values of a seek event (see gst_event_new_seek()).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
andstartType
andstopType
.For positive
rate
, the new position in the segment is the new this Segment start field when it was updated with astartType
different fromGST_SEEK_TYPE_NONE
. If no update was performed on this Segment start position (GST_SEEK_TYPE_NONE
),start
is ignored and this Segment position is unmodified.For negative
rate
, the new position in the segment is the new this Segment stop field when it was updated with astopType
different fromGST_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 this Segment stop position (GST_SEEK_TYPE_NONE
),stop
is ignored and this 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 this Segment rate and applied_rate after calling this function.
update
will be set totrue
if a seek should be performed to the segment position field. This field can befalse
if, for example, only therate
has been changed but not the playback position.- Parameters:
rate
- the rate of the segment.format
- the format of the segment.flags
- the segment flags for the segmentstartType
- the seek methodstart
- the seek start valuestopType
- the seek methodstop
- the seek stop valueupdate
- boolean holding whether position was updated.- Returns:
true
if the seek could be performed.
-
free
public void free()Free the allocated segment this Segment. -
init
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 this Segment to its default values.
- Parameters:
format
- the format of the segment.
-
isEqual
Checks for two segments being equal. Equality here is defined as perfect equality, including floating point values.- Parameters:
s1
- aGstSegment
structure.- Returns:
true
if the segments are equal,false
otherwise.
-
offsetRunningTime
Adjust the values in this Segment so thatoffset
is applied to all future running-time calculations.- Parameters:
format
- the format of the segment.offset
- the offset to apply in the segment- Returns:
true
if the segment could be updated successfully. Iffalse
is returned,offset
is not in this Segment.
-
positionFromRunningTime
ConvertrunningTime
into a position in the segment so that gst_segment_to_running_time() with that position returnsrunningTime
.- Parameters:
format
- the format of the segment.runningTime
- the running_time in the segment- Returns:
- the position in the segment for
runningTime
. This function returns -1 whenrunningTime
is -1 or when it is not inside this Segment.
-
positionFromRunningTimeFull
TranslaterunningTime
to the segment position using the currently configured segment. Compared to gst_segment_position_from_running_time() 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 inposition
.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.- Parameters:
format
- the format of the segment.runningTime
- the running-timeposition
- the resulting position in the segment- Returns:
- a 1 or -1 on success, 0 on failure.
-
positionFromStreamTime
ConvertstreamTime
into a position in the segment so that gst_segment_to_stream_time() with that position returnsstreamTime
.- Parameters:
format
- the format of the segment.streamTime
- the stream_time in the segment- Returns:
- the position in the segment for
streamTime
. This function returns -1 whenstreamTime
is -1 or when it is not inside this Segment.
-
positionFromStreamTimeFull
TranslatestreamTime
to the segment position using the currently configured segment. Compared to gst_segment_position_from_stream_time() 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 inposition
.When this function returns -1, the returned
position
should be negated to get the real negative segment position.- Parameters:
format
- the format of the segment.streamTime
- the stream-timeposition
- the resulting position in the segment- Returns:
- a 1 or -1 on success, 0 on failure.
-
setRunningTime
Adjust the start/stop and base values of this Segment such that the next valid buffer will be one withrunningTime
.- Parameters:
format
- the format of the segment.runningTime
- the running_time in the segment- Returns:
true
if the segment could be updated successfully. Iffalse
is returned,runningTime
is -1 or not in this Segment.
-
toPosition
Deprecated.Use gst_segment_position_from_running_time() instead.ConvertrunningTime
into a position in the segment so that gst_segment_to_running_time() with that position returnsrunningTime
.- Parameters:
format
- the format of the segment.runningTime
- the running_time in the segment- Returns:
- the position in the segment for
runningTime
. This function returns -1 whenrunningTime
is -1 or when it is not inside this Segment.
-
toRunningTime
Translateposition
to the total running time using the currently configured segment. Position is a value between this 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 gst_segment_init() is called, this value will reset to 0.
This function returns -1 if the position is outside of this Segment start and stop.
- Parameters:
format
- the format of the segment.position
- the position in the segment- Returns:
- the position as the total running time or -1 when an invalid position was given.
-
toRunningTimeFull
public int toRunningTimeFull(Format format, long position, @Nullable @Nullable Out<Long> runningTime) Translateposition
to the total running time using the currently configured segment. Compared to gst_segment_to_running_time() 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 inrunningTime
.When this function returns -1, the returned
runningTime
should be negated to get the real negative running time.- Parameters:
format
- the format of the segment.position
- the position in the segmentrunningTime
- result running-time- Returns:
- a 1 or -1 on success, 0 on failure.
-
toStreamTime
Translateposition
to stream time using the currently configured segment. Theposition
value must be between this 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.- Parameters:
format
- the format of the segment.position
- the position in the segment- Returns:
- the position in stream_time or -1 when an invalid position was given.
-
toStreamTimeFull
Translateposition
to the total stream time using the currently configured segment. Compared to gst_segment_to_stream_time() 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 instreamTime
.When this function returns -1, the returned
streamTime
should be negated to get the real negative stream time.- Parameters:
format
- the format of the segment.position
- the position in the segmentstreamTime
- result stream-time- Returns:
- a 1 or -1 on success, 0 on failure.
-