mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix access to stale ByteBuffer in FfmpegAudioDecoder
The native code can now reallocate the buffer if it needs to grow
its size, so we have to reacquire a reference in the Java code to
avoid accessing a stale instance.
This fixes a bug introduced by 8750ed8de6
.
PiperOrigin-RevId: 578799862
This commit is contained in:
parent
d4e5ab2c4d
commit
ae6f83d298
@ -15,11 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.decoder.ffmpeg;
|
package androidx.media3.decoder.ffmpeg;
|
||||||
|
|
||||||
|
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.Format;
|
import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.MimeTypes;
|
import androidx.media3.common.MimeTypes;
|
||||||
import androidx.media3.common.util.Assertions;
|
|
||||||
import androidx.media3.common.util.ParsableByteArray;
|
import androidx.media3.common.util.ParsableByteArray;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.decoder.DecoderInputBuffer;
|
import androidx.media3.decoder.DecoderInputBuffer;
|
||||||
@ -59,8 +60,8 @@ import java.util.List;
|
|||||||
if (!FfmpegLibrary.isAvailable()) {
|
if (!FfmpegLibrary.isAvailable()) {
|
||||||
throw new FfmpegDecoderException("Failed to load decoder native libraries.");
|
throw new FfmpegDecoderException("Failed to load decoder native libraries.");
|
||||||
}
|
}
|
||||||
Assertions.checkNotNull(format.sampleMimeType);
|
checkNotNull(format.sampleMimeType);
|
||||||
codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));
|
codecName = checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));
|
||||||
extraData = getExtraData(format.sampleMimeType, format.initializationData);
|
extraData = getExtraData(format.sampleMimeType, format.initializationData);
|
||||||
encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT;
|
encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT;
|
||||||
outputBufferSize =
|
outputBufferSize =
|
||||||
@ -128,7 +129,7 @@ import java.util.List;
|
|||||||
channelCount = ffmpegGetChannelCount(nativeContext);
|
channelCount = ffmpegGetChannelCount(nativeContext);
|
||||||
sampleRate = ffmpegGetSampleRate(nativeContext);
|
sampleRate = ffmpegGetSampleRate(nativeContext);
|
||||||
if (sampleRate == 0 && "alac".equals(codecName)) {
|
if (sampleRate == 0 && "alac".equals(codecName)) {
|
||||||
Assertions.checkNotNull(extraData);
|
checkNotNull(extraData);
|
||||||
// ALAC decoder did not set the sample rate in earlier versions of FFmpeg. See
|
// ALAC decoder did not set the sample rate in earlier versions of FFmpeg. See
|
||||||
// https://trac.ffmpeg.org/ticket/6096.
|
// https://trac.ffmpeg.org/ticket/6096.
|
||||||
ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
|
ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
|
||||||
@ -137,6 +138,9 @@ import java.util.List;
|
|||||||
}
|
}
|
||||||
hasOutputFormat = true;
|
hasOutputFormat = true;
|
||||||
}
|
}
|
||||||
|
// Get a new reference to the output ByteBuffer in case the native decode method reallocated the
|
||||||
|
// buffer to grow its size.
|
||||||
|
outputData = checkNotNull(outputBuffer.data);
|
||||||
outputData.position(0);
|
outputData.position(0);
|
||||||
outputData.limit(result);
|
outputData.limit(result);
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user