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
ConstructorsConstructorDescriptionSegment()Allocate a newGstSegmentstructure and initialize it using gst_segment_init().Segment(MemorySegment address) Create a Segment proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanclip(Format format, long start, long stop, @Nullable Out<Long> clipStart, @Nullable Out<Long> clipStop) Clip the givenstartandstopvalues to the segment boundaries given insegment.startandstopare compared and clipped to this Segment start and stop values.copy()Create a copy of givensegment.voidCopy the contents of this Segment intodest.booleandoSeek(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()).booleandoSeek(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()).voidfree()Free the allocated segmentsegment.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the Segment classvoidThe start/position fields are set to 0 and the stop/duration fields are set to -1 (unknown).booleanChecks for two segments being equal.booleanoffsetRunningTime(Format format, long offset) Adjust the values in this Segment so thatoffsetis applied to all future running-time calculations.longpositionFromRunningTime(Format format, long runningTime) ConvertrunningTimeinto a position in the segment so that gst_segment_to_running_time() with that position returnsrunningTime.intpositionFromRunningTimeFull(Format format, long runningTime, Out<Long> position) TranslaterunningTimeto the segment position using the currently configured segment.longpositionFromStreamTime(Format format, long streamTime) ConvertstreamTimeinto a position in the segment so that gst_segment_to_stream_time() with that position returnsstreamTime.intpositionFromStreamTimeFull(Format format, long streamTime, Out<Long> position) TranslatestreamTimeto the segment position using the currently configured segment.doubleRead the value of the fieldapplied_rate.longreadBase()Read the value of the fieldbase.longRead the value of the fieldduration.Read the value of the fieldflags.Read the value of the fieldformat.longRead the value of the fieldoffset.longRead the value of the fieldposition.doublereadRate()Read the value of the fieldrate.longRead the value of the fieldstart.longreadStop()Read the value of the fieldstop.longreadTime()Read the value of the fieldtime.booleansetRunningTime(Format format, long runningTime) Adjust the start/stop and base values of this Segment such that the next valid buffer will be one withrunningTime.longtoPosition(Format format, long runningTime) Deprecated.Use gst_segment_position_from_running_time() instead.longtoRunningTime(Format format, long position) Translatepositionto the total running time using the currently configured segment.inttoRunningTimeFull(Format format, long position, @Nullable Out<Long> runningTime) Translatepositionto the total running time using the currently configured segment.longtoStreamTime(Format format, long position) Translatepositionto stream time using the currently configured segment.inttoStreamTimeFull(Format format, long position, Out<Long> streamTime) Translatepositionto the total stream time using the currently configured segment.voidwriteAppliedRate(double appliedRate) Write a value in the fieldapplied_rate.voidwriteBase(long base) Write a value in the fieldbase.voidwriteDuration(long duration) Write a value in the fieldduration.voidwriteFlags(Set<SegmentFlags> flags) Write a value in the fieldflags.voidwriteFormat(Format format) Write a value in the fieldformat.voidwriteOffset(long offset) Write a value in the fieldoffset.voidwritePosition(long position) Write a value in the fieldposition.voidwriteRate(double rate) Write a value in the fieldrate.voidwriteStart(long start) Write a value in the fieldstart.voidwriteStop(long stop) Write a value in the fieldstop.voidwriteTime(long time) Write a value in the fieldtime.Methods inherited from class org.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 newGstSegmentstructure 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 Out<Long> clipStart, @Nullable Out<Long> clipStop) Clip the givenstartandstopvalues to the segment boundaries given insegment.startandstopare compared and clipped to this Segment start and stop values.If the function returns
false,startandstopare known to fall outside of this Segment andclipStartandclipStopare not updated.When the function returns
true,clipStartandclipStopwill be updated. IfclipStartorclipStopare different fromstartorstoprespectively, the region fell partially in the segment.Note that when
stopis -1,clipStopwill 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:
trueif the givenstartandstoptimes fall partially or completely insegment,falseif the values are completely outside of the segment.
-
copy
Create a copy of givensegment.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 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
rateandstartTypeandstopType.For positive
rate,the new position in the segment is the new this Segment start field when it was updated with astartTypedifferent fromGST_SEEK_TYPE_NONE. If no update was performed on this Segment start position (GST_SEEK_TYPE_NONE),startis 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 astopTypedifferent 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),stopis 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.
updatewill be set totrueif a seek should be performed to the segment position field. This field can befalseif, for example, only theratehas 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:
trueif the seek could be performed.
-
doSeek
public 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()).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
rateandstartTypeandstopType.For positive
rate,the new position in the segment is the new this Segment start field when it was updated with astartTypedifferent fromGST_SEEK_TYPE_NONE. If no update was performed on this Segment start position (GST_SEEK_TYPE_NONE),startis 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 astopTypedifferent 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),stopis 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.
updatewill be set totrueif a seek should be performed to the segment position field. This field can befalseif, for example, only theratehas 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:
trueif the seek could be performed.
-
free
public void free()Free the allocated segmentsegment. -
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- aGstSegmentstructure.- Returns:
trueif the segments are equal,falseotherwise.- Since:
- 1.6
-
offsetRunningTime
Adjust the values in this Segment so thatoffsetis applied to all future running-time calculations.- Parameters:
format- the format of the segment.offset- the offset to apply in the segment- Returns:
trueif the segment could be updated successfully. Iffalseis returned,offsetis not insegment.- Since:
- 1.2.3
-
positionFromRunningTime
ConvertrunningTimeinto 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 whenrunningTimeis -1 or when it is not insidesegment. - Since:
- 1.8
-
positionFromRunningTimeFull
TranslaterunningTimeto 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.
runningTimecan be any value and the result of this function for values outside of the segment is extrapolated.When 1 is returned,
runningTimeresulted in a positive position returned inposition.When this function returns -1, the returned
positionwas < 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.
- Since:
- 1.8
-
positionFromStreamTime
ConvertstreamTimeinto 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 whenstreamTimeis -1 or when it is not insidesegment. - Since:
- 1.8
-
positionFromStreamTimeFull
TranslatestreamTimeto 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.
streamTimecan be any value and the result of this function for values outside of the segment is extrapolated.When 1 is returned,
streamTimeresulted in a positive position returned inposition.When this function returns -1, the returned
positionshould 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.
- Since:
- 1.8
-
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:
trueif the segment could be updated successfully. Iffalseis returned,runningTimeis -1 or not insegment.
-
toPosition
Deprecated.Use gst_segment_position_from_running_time() instead.ConvertrunningTimeinto 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 whenrunningTimeis -1 or when it is not insidesegment.
-
toRunningTime
Translatepositionto 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
Translatepositionto 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.
positioncan be any value and the result of this function for values outside of the segment is extrapolated.When 1 is returned,
positionresulted in a positive running-time returned inrunningTime.When this function returns -1, the returned
runningTimeshould 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.
- Since:
- 1.6
-
toStreamTime
Translatepositionto stream time using the currently configured segment. Thepositionvalue 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,
positionis 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.
- Since:
- 1.8
-
toStreamTimeFull
Translatepositionto 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.
positioncan be any value and the result of this function for values outside of the segment is extrapolated.When 1 is returned,
positionresulted in a positive stream-time returned instreamTime.When this function returns -1, the returned
streamTimeshould 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.
- Since:
- 1.8
-