mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-26 14:27:34 +00:00
Prevent repeat attempts when waveforms cannot be generated.
This commit is contained in:
@@ -18,6 +18,7 @@ import com.google.protobuf.ByteString;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||||
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.model.databaseprotos.AudioWaveFormData;
|
import org.thoughtcrime.securesms.database.model.databaseprotos.AudioWaveFormData;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
@@ -89,7 +90,11 @@ public final class AudioWaveForm {
|
|||||||
AudioHash audioHash = attachment.getAudioHash();
|
AudioHash audioHash = attachment.getAudioHash();
|
||||||
if (audioHash != null) {
|
if (audioHash != null) {
|
||||||
AudioFileInfo audioFileInfo = AudioFileInfo.fromDatabaseProtobuf(audioHash.getAudioWaveForm());
|
AudioFileInfo audioFileInfo = AudioFileInfo.fromDatabaseProtobuf(audioHash.getAudioWaveForm());
|
||||||
if (audioFileInfo.waveForm.length != BAR_COUNT) {
|
if (audioFileInfo.waveForm.length == 0) {
|
||||||
|
Log.w(TAG, "Recovering from a wave form generation error " + cacheKey);
|
||||||
|
Util.runOnMain(onFailure);
|
||||||
|
return;
|
||||||
|
} else if (audioFileInfo.waveForm.length != BAR_COUNT) {
|
||||||
Log.w(TAG, "Wave form from database does not match bar count, regenerating " + cacheKey);
|
Log.w(TAG, "Wave form from database does not match bar count, regenerating " + cacheKey);
|
||||||
} else {
|
} else {
|
||||||
WAVE_FORM_CACHE.put(cacheKey, audioFileInfo);
|
WAVE_FORM_CACHE.put(cacheKey, audioFileInfo);
|
||||||
@@ -100,13 +105,19 @@ public final class AudioWaveForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
|
||||||
DatabaseAttachment dbAttachment = (DatabaseAttachment) attachment;
|
DatabaseAttachment dbAttachment = (DatabaseAttachment) attachment;
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
attachmentDatabase.writeAudioHash(dbAttachment.getAttachmentId(), AudioWaveFormData.getDefaultInstance());
|
||||||
|
|
||||||
|
Log.i(TAG, String.format("Starting wave form generation (%s)", cacheKey));
|
||||||
|
|
||||||
AudioFileInfo fileInfo = generateWaveForm(uri);
|
AudioFileInfo fileInfo = generateWaveForm(uri);
|
||||||
|
|
||||||
Log.i(TAG, String.format(Locale.US, "Audio wave form generation time %d ms (%s)", System.currentTimeMillis() - startTime, cacheKey));
|
Log.i(TAG, String.format(Locale.US, "Audio wave form generation time %d ms (%s)", System.currentTimeMillis() - startTime, cacheKey));
|
||||||
|
|
||||||
DatabaseFactory.getAttachmentDatabase(context).writeAudioHash(dbAttachment.getAttachmentId(), fileInfo.toDatabaseProtobuf());
|
attachmentDatabase.writeAudioHash(dbAttachment.getAttachmentId(), fileInfo.toDatabaseProtobuf());
|
||||||
|
|
||||||
WAVE_FORM_CACHE.put(cacheKey, fileInfo);
|
WAVE_FORM_CACHE.put(cacheKey, fileInfo);
|
||||||
Util.runOnMain(() -> onSuccess.accept(fileInfo));
|
Util.runOnMain(() -> onSuccess.accept(fileInfo));
|
||||||
|
Reference in New Issue
Block a user