kopia lustrzana https://github.com/ryukoposting/Signal-Android
Reuse video preupload for unclipped media.
rodzic
7dfebdca32
commit
d17896ea09
|
@ -144,7 +144,7 @@ public class MediaUploadRepository {
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private void uploadMediaInternal(@NonNull Media media, @Nullable Recipient recipient) {
|
private void uploadMediaInternal(@NonNull Media media, @Nullable Recipient recipient) {
|
||||||
Attachment attachment = asAttachment(context, media);
|
Attachment attachment = asAttachment(context, media);
|
||||||
PreUploadResult result = MessageSender.preUploadPushAttachment(context, attachment, recipient, MediaUtil.isVideo(media.getMimeType()));
|
PreUploadResult result = MessageSender.preUploadPushAttachment(context, attachment, recipient, media);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
uploadResults.put(media, result);
|
uploadResults.put(media, result);
|
||||||
|
|
|
@ -41,7 +41,6 @@ import org.thoughtcrime.securesms.scribbles.ImageEditorFragment
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender
|
import org.thoughtcrime.securesms.sms.MessageSender
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult
|
import org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult
|
||||||
import org.thoughtcrime.securesms.stories.Stories
|
import org.thoughtcrime.securesms.stories.Stories
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil
|
|
||||||
import org.thoughtcrime.securesms.util.MessageUtil
|
import org.thoughtcrime.securesms.util.MessageUtil
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -129,12 +128,10 @@ class MediaSelectionRepository(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val clippedMediaForStories = if (singleContact?.isStory == true || contacts.any { it.isStory }) {
|
val clippedMediaForStories = if (singleContact?.isStory == true || contacts.any { it.isStory }) {
|
||||||
updatedMedia.filter { MediaUtil.isVideo(it.mimeType) }.map { media ->
|
updatedMedia.filter {
|
||||||
if (Stories.MediaTransform.getSendRequirements(media) == Stories.MediaTransform.SendRequirements.REQUIRES_CLIP) {
|
Stories.MediaTransform.getSendRequirements(it) == Stories.MediaTransform.SendRequirements.REQUIRES_CLIP
|
||||||
Stories.MediaTransform.clipMediaToStoryDuration(media)
|
}.map { media ->
|
||||||
} else {
|
Stories.MediaTransform.clipMediaToStoryDuration(media)
|
||||||
listOf(media)
|
|
||||||
}
|
|
||||||
}.flatten()
|
}.flatten()
|
||||||
} else emptyList()
|
} else emptyList()
|
||||||
|
|
||||||
|
@ -274,7 +271,7 @@ class MediaSelectionRepository(context: Context) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isStory) {
|
if (isStory) {
|
||||||
preUploadResults.filterNot { it.isVideo }.forEach {
|
preUploadResults.filterNot { result -> storyClips.any { it.uri == result.media.uri } }.forEach {
|
||||||
val list = storyPreUploadMessages[it] ?: mutableListOf()
|
val list = storyPreUploadMessages[it] ?: mutableListOf()
|
||||||
list.add(
|
list.add(
|
||||||
OutgoingSecureMediaMessage(message).withSentTimestamp(
|
OutgoingSecureMediaMessage(message).withSentTimestamp(
|
||||||
|
|
|
@ -67,6 +67,7 @@ import org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob;
|
||||||
import org.thoughtcrime.securesms.jobs.SmsSendJob;
|
import org.thoughtcrime.securesms.jobs.SmsSendJob;
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||||
|
import org.thoughtcrime.securesms.mediasend.Media;
|
||||||
import org.thoughtcrime.securesms.mms.MmsException;
|
import org.thoughtcrime.securesms.mms.MmsException;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage;
|
||||||
|
@ -215,7 +216,8 @@ public class MessageSender {
|
||||||
|
|
||||||
database.setTransactionSuccessful();
|
database.setTransactionSuccessful();
|
||||||
} catch (MmsException e) {
|
} catch (MmsException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, "Failed to send stories.", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
|
@ -443,7 +445,7 @@ public class MessageSender {
|
||||||
* @return A result if the attachment was enqueued, or null if it failed to enqueue or shouldn't
|
* @return A result if the attachment was enqueued, or null if it failed to enqueue or shouldn't
|
||||||
* be enqueued (like in the case of a local self-send).
|
* be enqueued (like in the case of a local self-send).
|
||||||
*/
|
*/
|
||||||
public static @Nullable PreUploadResult preUploadPushAttachment(@NonNull Context context, @NonNull Attachment attachment, @Nullable Recipient recipient, boolean isStoryClip) {
|
public static @Nullable PreUploadResult preUploadPushAttachment(@NonNull Context context, @NonNull Attachment attachment, @Nullable Recipient recipient, @NonNull Media media) {
|
||||||
if (isLocalSelfSend(context, recipient, false)) {
|
if (isLocalSelfSend(context, recipient, false)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -463,7 +465,7 @@ public class MessageSender {
|
||||||
.then(uploadJob)
|
.then(uploadJob)
|
||||||
.enqueue();
|
.enqueue();
|
||||||
|
|
||||||
return new PreUploadResult(isStoryClip, databaseAttachment.getAttachmentId(), Arrays.asList(compressionJob.getId(), resumableUploadSpecJob.getId(), uploadJob.getId()));
|
return new PreUploadResult(media, databaseAttachment.getAttachmentId(), Arrays.asList(compressionJob.getId(), resumableUploadSpecJob.getId(), uploadJob.getId()));
|
||||||
} catch (MmsException e) {
|
} catch (MmsException e) {
|
||||||
Log.w(TAG, "preUploadPushAttachment() - Failed to upload!", e);
|
Log.w(TAG, "preUploadPushAttachment() - Failed to upload!", e);
|
||||||
return null;
|
return null;
|
||||||
|
@ -751,24 +753,20 @@ public class MessageSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PreUploadResult implements Parcelable {
|
public static class PreUploadResult implements Parcelable {
|
||||||
private final boolean isVideo;
|
private final Media media;
|
||||||
private final AttachmentId attachmentId;
|
private final AttachmentId attachmentId;
|
||||||
private final Collection<String> jobIds;
|
private final Collection<String> jobIds;
|
||||||
|
|
||||||
PreUploadResult(boolean isVideo, @NonNull AttachmentId attachmentId, @NonNull Collection<String> jobIds) {
|
PreUploadResult(@NonNull Media media, @NonNull AttachmentId attachmentId, @NonNull Collection<String> jobIds) {
|
||||||
this.isVideo = isVideo;
|
this.media = media;
|
||||||
this.attachmentId = attachmentId;
|
this.attachmentId = attachmentId;
|
||||||
this.jobIds = jobIds;
|
this.jobIds = jobIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PreUploadResult(Parcel in) {
|
private PreUploadResult(Parcel in) {
|
||||||
this.attachmentId = in.readParcelable(AttachmentId.class.getClassLoader());
|
this.attachmentId = in.readParcelable(AttachmentId.class.getClassLoader());
|
||||||
this.jobIds = ParcelUtil.readStringCollection(in);
|
this.jobIds = ParcelUtil.readStringCollection(in);
|
||||||
this.isVideo = ParcelUtil.readBoolean(in);
|
this.media = in.readParcelable(Media.class.getClassLoader());
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isVideo() {
|
|
||||||
return isVideo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull AttachmentId getAttachmentId() {
|
public @NonNull AttachmentId getAttachmentId() {
|
||||||
|
@ -779,6 +777,10 @@ public class MessageSender {
|
||||||
return jobIds;
|
return jobIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull Media getMedia() {
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
|
||||||
public static final Creator<PreUploadResult> CREATOR = new Creator<PreUploadResult>() {
|
public static final Creator<PreUploadResult> CREATOR = new Creator<PreUploadResult>() {
|
||||||
@Override
|
@Override
|
||||||
public PreUploadResult createFromParcel(Parcel in) {
|
public PreUploadResult createFromParcel(Parcel in) {
|
||||||
|
@ -800,7 +802,7 @@ public class MessageSender {
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeParcelable(attachmentId, flags);
|
dest.writeParcelable(attachmentId, flags);
|
||||||
ParcelUtil.writeStringCollection(dest, jobIds);
|
ParcelUtil.writeStringCollection(dest, jobIds);
|
||||||
ParcelUtil.writeBoolean(dest, isVideo);
|
dest.writeParcelable(media, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,10 +300,11 @@ object Stories {
|
||||||
* Callers can utilize canClipMedia to determine if the given media can and should be clipped.
|
* Callers can utilize canClipMedia to determine if the given media can and should be clipped.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@WorkerThread
|
||||||
fun clipMediaToStoryDuration(media: Media): List<Media> {
|
fun clipMediaToStoryDuration(media: Media): List<Media> {
|
||||||
val storyDurationUs = TimeUnit.MILLISECONDS.toMicros(MAX_VIDEO_DURATION_MILLIS)
|
val storyDurationUs = TimeUnit.MILLISECONDS.toMicros(MAX_VIDEO_DURATION_MILLIS)
|
||||||
val startOffsetUs = media.transformProperties.map { it.videoTrimStartTimeUs }.orElse(0L)
|
val startOffsetUs = media.transformProperties.map { it.videoTrimStartTimeUs }.orElse(0L)
|
||||||
val endOffsetUs = media.transformProperties.map { it.videoTrimEndTimeUs }.orElse(TimeUnit.MILLISECONDS.toMicros(media.duration))
|
val endOffsetUs = media.transformProperties.map { it.videoTrimEndTimeUs }.orElse(TimeUnit.MILLISECONDS.toMicros(getVideoDuration(media.uri)))
|
||||||
val durationUs = endOffsetUs - startOffsetUs
|
val durationUs = endOffsetUs - startOffsetUs
|
||||||
|
|
||||||
if (durationUs <= 0L) {
|
if (durationUs <= 0L) {
|
||||||
|
|
Ładowanie…
Reference in New Issue