mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 04:08:33 +00:00
Fix waveform array out of bounds.
This commit is contained in:
parent
26a9dd98c1
commit
91b142e0d9
@ -54,19 +54,19 @@ public final class AudioWaveForm {
|
|||||||
private static final Executor AUDIO_DECODER_EXECUTOR = new SerialExecutor(SignalExecutors.BOUNDED);
|
private static final Executor AUDIO_DECODER_EXECUTOR = new SerialExecutor(SignalExecutors.BOUNDED);
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
public void getWaveForm(@NonNull Consumer<AudioFileInfo> onSuccess, @NonNull Consumer<IOException> onFailure) {
|
public void getWaveForm(@NonNull Consumer<AudioFileInfo> onSuccess, @NonNull Runnable onFailure) {
|
||||||
Uri uri = slide.getUri();
|
Uri uri = slide.getUri();
|
||||||
Attachment attachment = slide.asAttachment();
|
Attachment attachment = slide.asAttachment();
|
||||||
|
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
Log.w(TAG, "No uri");
|
Log.w(TAG, "No uri");
|
||||||
Util.runOnMain(() -> onFailure.accept(null));
|
Util.runOnMain(onFailure);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(attachment instanceof DatabaseAttachment)) {
|
if (!(attachment instanceof DatabaseAttachment)) {
|
||||||
Log.i(TAG, "Not yet in database");
|
Log.i(TAG, "Not yet in database");
|
||||||
Util.runOnMain(() -> onFailure.accept(null));
|
Util.runOnMain(onFailure);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,9 +110,9 @@ public final class AudioWaveForm {
|
|||||||
|
|
||||||
WAVE_FORM_CACHE.put(cacheKey, fileInfo);
|
WAVE_FORM_CACHE.put(cacheKey, fileInfo);
|
||||||
Util.runOnMain(() -> onSuccess.accept(fileInfo));
|
Util.runOnMain(() -> onSuccess.accept(fileInfo));
|
||||||
} catch (IOException e) {
|
} catch (Throwable e) {
|
||||||
Log.w(TAG, "Failed to create audio wave form for " + cacheKey, e);
|
Log.w(TAG, "Failed to create audio wave form for " + cacheKey, e);
|
||||||
Util.runOnMain(() -> onFailure.accept(e));
|
Util.runOnMain(onFailure);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -126,9 +126,8 @@ public final class AudioWaveForm {
|
|||||||
@RequiresApi(api = 23)
|
@RequiresApi(api = 23)
|
||||||
private @NonNull AudioFileInfo generateWaveForm(@NonNull Uri uri) throws IOException {
|
private @NonNull AudioFileInfo generateWaveForm(@NonNull Uri uri) throws IOException {
|
||||||
try (MediaInput dataSource = DecryptableUriMediaInput.createForUri(context, uri)) {
|
try (MediaInput dataSource = DecryptableUriMediaInput.createForUri(context, uri)) {
|
||||||
long[] wave = new long[BAR_COUNT];
|
long[] wave = new long[BAR_COUNT];
|
||||||
int[] waveSamples = new int[BAR_COUNT];
|
int[] waveSamples = new int[BAR_COUNT];
|
||||||
int[] inputSamples = new int[BAR_COUNT * SAMPLES_PER_BAR];
|
|
||||||
|
|
||||||
MediaExtractor extractor = dataSource.createExtractor();
|
MediaExtractor extractor = dataSource.createExtractor();
|
||||||
|
|
||||||
@ -194,15 +193,12 @@ public final class AudioWaveForm {
|
|||||||
|
|
||||||
if (!sawInputEOS) {
|
if (!sawInputEOS) {
|
||||||
int barSampleIndex = (int) (SAMPLES_PER_BAR * (wave.length * extractor.getSampleTime()) / totalDurationUs);
|
int barSampleIndex = (int) (SAMPLES_PER_BAR * (wave.length * extractor.getSampleTime()) / totalDurationUs);
|
||||||
inputSamples[barSampleIndex]++;
|
|
||||||
sawInputEOS = !extractor.advance();
|
sawInputEOS = !extractor.advance();
|
||||||
if (inputSamples[barSampleIndex] > 0) {
|
int nextBarSampleIndex = (int) (SAMPLES_PER_BAR * (wave.length * extractor.getSampleTime()) / totalDurationUs);
|
||||||
int nextBarSampleIndex = (int) (SAMPLES_PER_BAR * (wave.length * extractor.getSampleTime()) / totalDurationUs);
|
while (!sawInputEOS && nextBarSampleIndex == barSampleIndex) {
|
||||||
while (!sawInputEOS && nextBarSampleIndex == barSampleIndex) {
|
sawInputEOS = !extractor.advance();
|
||||||
sawInputEOS = !extractor.advance();
|
if (!sawInputEOS) {
|
||||||
if (!sawInputEOS) {
|
nextBarSampleIndex = (int) (SAMPLES_PER_BAR * (wave.length * extractor.getSampleTime()) / totalDurationUs);
|
||||||
nextBarSampleIndex = (int) (SAMPLES_PER_BAR * (wave.length * extractor.getSampleTime()) / totalDurationUs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ public final class AudioView extends FrameLayout implements AudioSlidePlayer.Lis
|
|||||||
}
|
}
|
||||||
waveFormView.setWaveData(data.getWaveForm());
|
waveFormView.setWaveData(data.getWaveForm());
|
||||||
},
|
},
|
||||||
e -> waveFormView.setWaveMode(false));
|
() -> waveFormView.setWaveMode(false));
|
||||||
} else {
|
} else {
|
||||||
waveFormView.setWaveMode(false);
|
waveFormView.setWaveMode(false);
|
||||||
if (duration != null) {
|
if (duration != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user