mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add some audio hooks.
This makes it easier to add an extension for adjusting audio playback rate.
This commit is contained in:
parent
b88012f51f
commit
c7635c9dbd
2 changed files with 21 additions and 3 deletions
|
|
@ -68,7 +68,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
|
||||||
private static final String RAW_DECODER_NAME = "OMX.google.raw.decoder";
|
private static final String RAW_DECODER_NAME = "OMX.google.raw.decoder";
|
||||||
|
|
||||||
private final EventListener eventListener;
|
private final EventListener eventListener;
|
||||||
private final AudioTrack audioTrack;
|
protected final AudioTrack audioTrack;
|
||||||
|
|
||||||
private int audioSessionId;
|
private int audioSessionId;
|
||||||
private long currentPositionUs;
|
private long currentPositionUs;
|
||||||
|
|
@ -294,6 +294,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
|
||||||
|
|
||||||
// If we are out of sync, allow currentPositionUs to jump backwards.
|
// If we are out of sync, allow currentPositionUs to jump backwards.
|
||||||
if ((handleBufferResult & AudioTrack.RESULT_POSITION_DISCONTINUITY) != 0) {
|
if ((handleBufferResult & AudioTrack.RESULT_POSITION_DISCONTINUITY) != 0) {
|
||||||
|
handleDiscontinuity();
|
||||||
allowPositionDiscontinuity = true;
|
allowPositionDiscontinuity = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -307,6 +308,10 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleDiscontinuity() {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
|
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
|
||||||
if (messageType == MSG_SET_VOLUME) {
|
if (messageType == MSG_SET_VOLUME) {
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,8 @@ public final class AudioTrack {
|
||||||
private static final int MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US = 30000;
|
private static final int MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US = 30000;
|
||||||
private static final int MIN_TIMESTAMP_SAMPLE_INTERVAL_US = 500000;
|
private static final int MIN_TIMESTAMP_SAMPLE_INTERVAL_US = 500000;
|
||||||
|
|
||||||
|
private static final int DEFAULT_TIMESCALE_PERCENT = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to enable a workaround for an issue where an audio effect does not keep its session
|
* Whether to enable a workaround for an issue where an audio effect does not keep its session
|
||||||
* active across releasing/initializing a new audio track, on platform API version < 21.
|
* active across releasing/initializing a new audio track, on platform API version < 21.
|
||||||
|
|
@ -191,6 +193,7 @@ public final class AudioTrack {
|
||||||
private long resumeSystemTimeUs;
|
private long resumeSystemTimeUs;
|
||||||
private long latencyUs;
|
private long latencyUs;
|
||||||
private float volume;
|
private float volume;
|
||||||
|
private int timeScalePercent;
|
||||||
|
|
||||||
private byte[] temporaryBuffer;
|
private byte[] temporaryBuffer;
|
||||||
private int temporaryBufferOffset;
|
private int temporaryBufferOffset;
|
||||||
|
|
@ -218,6 +221,7 @@ public final class AudioTrack {
|
||||||
}
|
}
|
||||||
playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
|
playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
|
||||||
volume = 1.0f;
|
volume = 1.0f;
|
||||||
|
timeScalePercent = DEFAULT_TIMESCALE_PERCENT;
|
||||||
startMediaTimeState = START_NOT_SET;
|
startMediaTimeState = START_NOT_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,7 +481,7 @@ public final class AudioTrack {
|
||||||
} else {
|
} else {
|
||||||
// Sanity check that bufferStartTime is consistent with the expected value.
|
// Sanity check that bufferStartTime is consistent with the expected value.
|
||||||
long expectedBufferStartTime = startMediaTimeUs
|
long expectedBufferStartTime = startMediaTimeUs
|
||||||
+ framesToDurationUs(bytesToFrames(submittedBytes));
|
+ (framesToDurationUs(bytesToFrames(submittedBytes)) * timeScalePercent) / 100;
|
||||||
if (startMediaTimeState == START_IN_SYNC
|
if (startMediaTimeState == START_IN_SYNC
|
||||||
&& Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) {
|
&& Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) {
|
||||||
Log.e(TAG, "Discontinuity detected [expected " + expectedBufferStartTime + ", got "
|
Log.e(TAG, "Discontinuity detected [expected " + expectedBufferStartTime + ", got "
|
||||||
|
|
@ -586,6 +590,15 @@ public final class AudioTrack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the timescale percent for reporting current time
|
||||||
|
*
|
||||||
|
* @param timeScalePercent The new percent multiplier
|
||||||
|
*/
|
||||||
|
public void setTimeScalePercent(int timeScalePercent) {
|
||||||
|
this.timeScalePercent = timeScalePercent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases the underlying audio track asynchronously. Calling {@link #initialize} will block
|
* Releases the underlying audio track asynchronously. Calling {@link #initialize} will block
|
||||||
* until the audio track has been released, so it is safe to initialize immediately after
|
* until the audio track has been released, so it is safe to initialize immediately after
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue