mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Migrate to Util.durationUsToSampleCount in transformer audio.
PiperOrigin-RevId: 582700443
This commit is contained in:
parent
64d2210b79
commit
d5fbf0007b
6 changed files with 16 additions and 25 deletions
|
|
@ -280,8 +280,8 @@ sample:
|
||||||
presentationTimeUs = 998458
|
presentationTimeUs = 998458
|
||||||
sample:
|
sample:
|
||||||
trackType = audio
|
trackType = audio
|
||||||
dataHashCode = -873373951
|
dataHashCode = -1506281855
|
||||||
size = 4232
|
size = 4236
|
||||||
isKeyFrame = true
|
isKeyFrame = true
|
||||||
presentationTimeUs = 1000000
|
presentationTimeUs = 1000000
|
||||||
sample:
|
sample:
|
||||||
|
|
|
||||||
|
|
@ -280,8 +280,8 @@ sample:
|
||||||
presentationTimeUs = 998437
|
presentationTimeUs = 998437
|
||||||
sample:
|
sample:
|
||||||
trackType = audio
|
trackType = audio
|
||||||
dataHashCode = -1577850751
|
dataHashCode = 1020903425
|
||||||
size = 4604
|
size = 4608
|
||||||
isKeyFrame = true
|
isKeyFrame = true
|
||||||
presentationTimeUs = 1000000
|
presentationTimeUs = 1000000
|
||||||
sample:
|
sample:
|
||||||
|
|
@ -289,7 +289,7 @@ sample:
|
||||||
dataHashCode = 923521
|
dataHashCode = 923521
|
||||||
size = 4
|
size = 4
|
||||||
isKeyFrame = true
|
isKeyFrame = true
|
||||||
presentationTimeUs = 1023979
|
presentationTimeUs = 1024000
|
||||||
sample:
|
sample:
|
||||||
trackType = video
|
trackType = video
|
||||||
dataHashCode = -770308242
|
dataHashCode = -770308242
|
||||||
|
|
|
||||||
|
|
@ -283,8 +283,8 @@ sample:
|
||||||
presentationTimeUs = 998458
|
presentationTimeUs = 998458
|
||||||
sample:
|
sample:
|
||||||
trackType = audio
|
trackType = audio
|
||||||
dataHashCode = 799574529
|
dataHashCode = -1268670079
|
||||||
size = 176
|
size = 180
|
||||||
isKeyFrame = true
|
isKeyFrame = true
|
||||||
presentationTimeUs = 1000000
|
presentationTimeUs = 1000000
|
||||||
sample:
|
sample:
|
||||||
|
|
|
||||||
|
|
@ -292,8 +292,8 @@ sample:
|
||||||
presentationTimeUs = 1044897
|
presentationTimeUs = 1044897
|
||||||
sample:
|
sample:
|
||||||
trackType = audio
|
trackType = audio
|
||||||
dataHashCode = -2019986431
|
dataHashCode = 1976404865
|
||||||
size = 3680
|
size = 3684
|
||||||
isKeyFrame = true
|
isKeyFrame = true
|
||||||
presentationTimeUs = 1068117
|
presentationTimeUs = 1068117
|
||||||
sample:
|
sample:
|
||||||
|
|
|
||||||
|
|
@ -133,10 +133,7 @@ public final class DefaultAudioMixer implements AudioMixer {
|
||||||
endTimeUs >= mixerStartTimeUs, "End time must be at least the configured start time.");
|
endTimeUs >= mixerStartTimeUs, "End time must be at least the configured start time.");
|
||||||
|
|
||||||
endPosition =
|
endPosition =
|
||||||
Util.scaleLargeTimestamp(
|
Util.durationUsToSampleCount(endTimeUs - mixerStartTimeUs, outputAudioFormat.sampleRate);
|
||||||
endTimeUs - mixerStartTimeUs,
|
|
||||||
/* multiplier= */ outputAudioFormat.sampleRate,
|
|
||||||
/* divisor= */ C.MICROS_PER_SECOND);
|
|
||||||
updateInputFrameLimit();
|
updateInputFrameLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,10 +153,8 @@ public final class DefaultAudioMixer implements AudioMixer {
|
||||||
}
|
}
|
||||||
|
|
||||||
long startFrameOffset =
|
long startFrameOffset =
|
||||||
Util.scaleLargeTimestamp(
|
Util.durationUsToSampleCount(startTimeUs - mixerStartTimeUs, sourceFormat.sampleRate);
|
||||||
startTimeUs - mixerStartTimeUs,
|
|
||||||
/* multiplier= */ sourceFormat.sampleRate,
|
|
||||||
/* divisor= */ C.MICROS_PER_SECOND);
|
|
||||||
int sourceId = nextSourceId++;
|
int sourceId = nextSourceId++;
|
||||||
sources.append(
|
sources.append(
|
||||||
sourceId,
|
sourceId,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package androidx.media3.transformer;
|
package androidx.media3.transformer;
|
||||||
|
|
||||||
import androidx.media3.common.C;
|
|
||||||
import androidx.media3.common.audio.AudioProcessor.AudioFormat;
|
import androidx.media3.common.audio.AudioProcessor.AudioFormat;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
@ -49,14 +48,11 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
* @param durationUs The duration of the additional silence to generate, in microseconds.
|
* @param durationUs The duration of the additional silence to generate, in microseconds.
|
||||||
*/
|
*/
|
||||||
public void addSilence(long durationUs) {
|
public void addSilence(long durationUs) {
|
||||||
// The number of frames is not a timestamp, however this utility method provides
|
long outputFrameCount = Util.durationUsToSampleCount(durationUs, audioFormat.sampleRate);
|
||||||
// overflow-safe multiplication & division.
|
// If the durationUs maps to a non-integer number of samples, then an extra sample is output.
|
||||||
long outputFrameCount =
|
// In the worst case, this is one sample (~22us of audio) per media item.
|
||||||
Util.scaleLargeTimestamp(
|
|
||||||
/* timestamp= */ durationUs,
|
|
||||||
/* multiplier= */ audioFormat.sampleRate,
|
|
||||||
/* divisor= */ C.MICROS_PER_SECOND);
|
|
||||||
|
|
||||||
|
// TODO(b/260618558): Track leftover duration when generating in mixer.
|
||||||
remainingBytesToOutput.addAndGet(audioFormat.bytesPerFrame * outputFrameCount);
|
remainingBytesToOutput.addAndGet(audioFormat.bytesPerFrame * outputFrameCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue