public final class SyncParams extends Object
MediaSync
{link MediaSync#getSyncParams()} and
{link MediaSync#setSyncParams(SyncParams)}
to control A/V sync behavior.
audio adjust mode: select handling of audio track when changing playback speed due to sync.
AUDIO_ADJUST_MODE_DEFAULT
:
System will determine best handling. AUDIO_ADJUST_MODE_STRETCH
:
Change the speed of audio playback without altering its pitch.AUDIO_ADJUST_MODE_RESAMPLE
:
Change the speed of audio playback by resampling the audio.sync source: select clock source for sync.
SYNC_SOURCE_DEFAULT
:
System will determine best selection.SYNC_SOURCE_SYSTEM_CLOCK
:
Use system clock for sync source.SYNC_SOURCE_AUDIO
:
Use audio track for sync source.SYNC_SOURCE_VSYNC
:
Syncronize media to vsync.tolerance: specifies the amount of allowed playback rate change to keep media in sync with the sync source. The handling of this depends on the sync source, but must not be negative, and must be less than one.
frameRate: initial hint for video frame rate. Used when sync source is vsync. Negative values can be used to clear a previous hint.
Modifier and Type | Class and Description |
---|---|
static interface |
SyncParams.AudioAdjustMode |
static interface |
SyncParams.SyncSource |
Modifier and Type | Field and Description |
---|---|
static int |
AUDIO_ADJUST_MODE_DEFAULT
System will determine best handling of audio for playback rate
adjustments.
|
static int |
AUDIO_ADJUST_MODE_RESAMPLE
Resample audio when playback rate must be adjusted.
|
static int |
AUDIO_ADJUST_MODE_STRETCH
Time stretch audio when playback rate must be adjusted.
|
static int |
SYNC_SOURCE_AUDIO
Use audio track for sync source.
|
static int |
SYNC_SOURCE_DEFAULT
Use the default sync source (default).
|
static int |
SYNC_SOURCE_SYSTEM_CLOCK
Use system monotonic clock for sync source.
|
static int |
SYNC_SOURCE_VSYNC
Use vsync as the sync source.
|
Constructor and Description |
---|
SyncParams() |
Modifier and Type | Method and Description |
---|---|
SyncParams |
allowDefaults()
Allows defaults to be returned for properties not set.
|
int |
getAudioAdjustMode()
Retrieves the audio adjust mode.
|
float |
getFrameRate()
Retrieves the video frame rate hint.
|
int |
getSyncSource()
Retrieves the sync source.
|
float |
getTolerance()
Retrieves the tolerance factor.
|
SyncParams |
setAudioAdjustMode(int audioAdjustMode)
Sets the audio adjust mode.
|
SyncParams |
setFrameRate(float frameRate)
Sets the video frame rate hint to be used.
|
SyncParams |
setSyncSource(int syncSource)
Sets the sync source.
|
SyncParams |
setTolerance(float tolerance)
Sets the tolerance.
|
public static final int SYNC_SOURCE_DEFAULT
public static final int SYNC_SOURCE_SYSTEM_CLOCK
System.nanoTime()
,
Constant Field Valuespublic static final int SYNC_SOURCE_AUDIO
AudioTrack#getTimeStamp
,
Constant Field Valuespublic static final int SYNC_SOURCE_VSYNC
SurfaceView
This mode allows smoother playback experience by adjusting the playback speed to match the vsync rate, e.g. playing 30fps content on a 59.94Hz display. When using this mode, the tolerance should be set to greater than 0 (e.g. at least 1/1000), so that the playback speed can actually be adjusted.
This mode can also be used to play 25fps content on a 60Hz display using a 2:3 pulldown (basically playing the content at 24fps), which results on better playback experience on most devices. In this case the tolerance should be at least (1/24).
public static final int AUDIO_ADJUST_MODE_DEFAULT
Used by default. This will make audio play faster or slower as required by the sync source without changing its pitch; however, system may fall back to some other method (e.g. change the pitch, or mute the audio) if time stretching is no longer supported for the playback rate.
public static final int AUDIO_ADJUST_MODE_STRETCH
This will make audio play faster or slower as required by the sync source without changing its pitch, as long as it is supported for the playback rate.
MediaSync#PLAYBACK_RATE_AUDIO_MODE_STRETCH
,
MediaPlayer.PLAYBACK_RATE_AUDIO_MODE_STRETCH
,
Constant Field Valuespublic static final int AUDIO_ADJUST_MODE_RESAMPLE
This will make audio play faster or slower as required by the sync source by changing its pitch (making it lower to play slower, and higher to play faster.)
MediaSync#PLAYBACK_RATE_AUDIO_MODE_RESAMPLE
,
MediaPlayer.PLAYBACK_RATE_AUDIO_MODE_RESAMPLE
,
Constant Field Valuespublic SyncParams allowDefaults()
IllegalArgumentException
exception
is raised when getting those properties
which have defaults but have never been set.SyncParams
instance.public SyncParams setAudioAdjustMode(int audioAdjustMode)
audioAdjustMode
- SyncParams
instance.public int getAudioAdjustMode()
IllegalStateException
- if the audio adjust mode is not set.public SyncParams setSyncSource(int syncSource)
syncSource
- SyncParams
instance.public int getSyncSource()
IllegalStateException
- if the sync source is not set.public SyncParams setTolerance(float tolerance)
tolerance
- A non-negative number representing
the maximum deviation of the playback rate from the playback rate
set. (abs(actual_rate - set_rate) / set_rate
)SyncParams
instance.InvalidArgumentException
- if the tolerance is negative, or not less than onepublic float getTolerance()
abs(actual_rate - set_rate) / set_rate
)IllegalStateException
- if tolerance is not set.public SyncParams setFrameRate(float frameRate)
frameRate
- A non-negative number used as an initial hint on
the video frame rate to be used when using vsync as the sync source. A negative
number is used to clear a previous hint.SyncParams
instance.public float getFrameRate()
abs(actual_rate - set_rate) / set_rate
), or a negative
number representing the desire to clear a previous hint using these params.IllegalStateException
- if frame rate is not set.