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