Only generate incremental mac for faststart videos.

This commit is contained in:
Nicholas
2023-11-28 09:36:32 -05:00
committed by Cody Henthorne
parent 1fd6aae3d9
commit 67ef831681
17 changed files with 96 additions and 49 deletions

View File

@@ -942,10 +942,16 @@ public class AttachmentTable extends DatabaseTable {
}
}
public void markAttachmentAsTransformed(@NonNull AttachmentId attachmentId) {
public void markAttachmentAsTransformed(@NonNull AttachmentId attachmentId, boolean withFaststart) {
getWritableDatabase().beginTransaction();
try {
updateAttachmentTransformProperties(attachmentId, getTransformProperties(attachmentId).withSkipTransform());
TransformProperties transformProperties = getTransformProperties(attachmentId).withSkipTransform();
if (withFaststart) {
transformProperties = transformProperties.withMp4Faststart();
}
updateAttachmentTransformProperties(attachmentId, transformProperties);
getWritableDatabase().setTransactionSuccessful();
} catch (Exception e) {
Log.w(TAG, "Could not mark attachment as transformed.", e);
@@ -1645,19 +1651,22 @@ public class AttachmentTable extends DatabaseTable {
@JsonProperty private final long videoTrimStartTimeUs;
@JsonProperty private final long videoTrimEndTimeUs;
@JsonProperty private final int sentMediaQuality;
@JsonProperty private final boolean mp4Faststart;
@JsonCreator
public TransformProperties(@JsonProperty("skipTransform") boolean skipTransform,
@JsonProperty("videoTrim") boolean videoTrim,
@JsonProperty("videoTrimStartTimeUs") long videoTrimStartTimeUs,
@JsonProperty("videoTrimEndTimeUs") long videoTrimEndTimeUs,
@JsonProperty("sentMediaQuality") int sentMediaQuality)
@JsonProperty("sentMediaQuality") int sentMediaQuality,
@JsonProperty("mp4Faststart") boolean mp4Faststart)
{
this.skipTransform = skipTransform;
this.videoTrim = videoTrim;
this.videoTrimStartTimeUs = videoTrimStartTimeUs;
this.videoTrimEndTimeUs = videoTrimEndTimeUs;
this.sentMediaQuality = sentMediaQuality;
this.mp4Faststart = mp4Faststart;
}
protected TransformProperties(Parcel in) {
@@ -1666,6 +1675,7 @@ public class AttachmentTable extends DatabaseTable {
videoTrimStartTimeUs = in.readLong();
videoTrimEndTimeUs = in.readLong();
sentMediaQuality = in.readInt();
mp4Faststart = in.readByte() != 0;
}
@Override
@@ -1675,6 +1685,7 @@ public class AttachmentTable extends DatabaseTable {
dest.writeLong(videoTrimStartTimeUs);
dest.writeLong(videoTrimEndTimeUs);
dest.writeInt(sentMediaQuality);
dest.writeByte((byte) (mp4Faststart ? 1 : 0));
}
@Override
@@ -1695,20 +1706,20 @@ public class AttachmentTable extends DatabaseTable {
};
public static @NonNull TransformProperties empty() {
return new TransformProperties(false, false, 0, 0, DEFAULT_MEDIA_QUALITY);
return new TransformProperties(false, false, 0, 0, DEFAULT_MEDIA_QUALITY, false);
}
public static @NonNull TransformProperties forSkipTransform() {
return new TransformProperties(true, false, 0, 0, DEFAULT_MEDIA_QUALITY);
return new TransformProperties(true, false, 0, 0, DEFAULT_MEDIA_QUALITY, false);
}
public static @NonNull TransformProperties forVideoTrim(long videoTrimStartTimeUs, long videoTrimEndTimeUs) {
return new TransformProperties(false, true, videoTrimStartTimeUs, videoTrimEndTimeUs, DEFAULT_MEDIA_QUALITY);
return new TransformProperties(false, true, videoTrimStartTimeUs, videoTrimEndTimeUs, DEFAULT_MEDIA_QUALITY, false);
}
public static @NonNull TransformProperties forSentMediaQuality(@NonNull Optional<TransformProperties> currentProperties, @NonNull SentMediaQuality sentMediaQuality) {
TransformProperties existing = currentProperties.orElse(empty());
return new TransformProperties(existing.skipTransform, existing.videoTrim, existing.videoTrimStartTimeUs, existing.videoTrimEndTimeUs, sentMediaQuality.getCode());
return new TransformProperties(existing.skipTransform, existing.videoTrim, existing.videoTrimStartTimeUs, existing.videoTrimEndTimeUs, sentMediaQuality.getCode(), existing.mp4Faststart);
}
public boolean shouldSkipTransform() {
@@ -1723,6 +1734,10 @@ public class AttachmentTable extends DatabaseTable {
return videoTrim;
}
public boolean isMp4Faststart() {
return mp4Faststart;
}
public long getVideoTrimStartTimeUs() {
return videoTrimStartTimeUs;
}
@@ -1736,9 +1751,12 @@ public class AttachmentTable extends DatabaseTable {
}
@NonNull TransformProperties withSkipTransform() {
return new TransformProperties(true, false, 0, 0, sentMediaQuality);
return new TransformProperties(true, false, 0, 0, sentMediaQuality, false);
}
@NonNull TransformProperties withMp4Faststart() {
return new TransformProperties(skipTransform, videoTrim, videoTrimStartTimeUs, videoTrimEndTimeUs, sentMediaQuality, true);
}
public @NonNull String serialize() {
return JsonUtil.toJson(this);
}

View File

@@ -174,10 +174,10 @@ public final class AttachmentCompressionJob extends BaseJob {
try (MediaStream converted = compressImage(context, attachment, constraints)) {
attachmentDatabase.updateAttachmentData(attachment, converted, false);
}
attachmentDatabase.markAttachmentAsTransformed(attachmentId);
attachmentDatabase.markAttachmentAsTransformed(attachmentId, false);
} else if (constraints.isSatisfied(context, attachment)) {
Log.i(TAG, "Not compressing.");
attachmentDatabase.markAttachmentAsTransformed(attachmentId);
attachmentDatabase.markAttachmentAsTransformed(attachmentId, false);
} else {
throw new UndeliverableMessageException("Size constraints could not be met!");
}
@@ -253,7 +253,7 @@ public final class AttachmentCompressionJob extends BaseJob {
}
}
attachmentDatabase.markAttachmentAsTransformed(attachment.getAttachmentId());
attachmentDatabase.markAttachmentAsTransformed(attachment.getAttachmentId(), false);
return Objects.requireNonNull(attachmentDatabase.getAttachment(attachment.getAttachmentId()));
} else {
@@ -276,7 +276,7 @@ public final class AttachmentCompressionJob extends BaseJob {
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true);
}
attachmentDatabase.markAttachmentAsTransformed(attachment.getAttachmentId());
attachmentDatabase.markAttachmentAsTransformed(attachment.getAttachmentId(), true);
return Objects.requireNonNull(attachmentDatabase.getAttachment(attachment.getAttachmentId()));
} else {

View File

@@ -177,6 +177,7 @@ class AttachmentUploadJob private constructor(
.withVoiceNote(attachment.isVoiceNote)
.withBorderless(attachment.isBorderless)
.withGif(attachment.isVideoGif)
.withFaststart(attachment.transformProperties.isMp4Faststart)
.withWidth(attachment.width)
.withHeight(attachment.height)
.withUploadTimestamp(System.currentTimeMillis())

View File

@@ -193,6 +193,7 @@ public final class LegacyAttachmentUploadJob extends BaseJob {
.withVoiceNote(attachment.isVoiceNote())
.withBorderless(attachment.isBorderless())
.withGif(attachment.isVideoGif())
.withFaststart(attachment.getTransformProperties().isMp4Faststart())
.withWidth(attachment.getWidth())
.withHeight(attachment.getHeight())
.withUploadTimestamp(System.currentTimeMillis())

View File

@@ -207,6 +207,7 @@ public abstract class PushSendJob extends SendJob {
.withVoiceNote(attachment.isVoiceNote())
.withBorderless(attachment.isBorderless())
.withGif(attachment.isVideoGif())
.withFaststart(attachment.getTransformProperties().isMp4Faststart())
.withWidth(attachment.getWidth())
.withHeight(attachment.getHeight())
.withCaption(attachment.getCaption())

View File

@@ -33,6 +33,6 @@ public final class VideoTrimTransform implements MediaTransform {
media.isVideoGif(),
media.getBucketId(),
media.getCaption(),
Optional.of(new AttachmentTable.TransformProperties(false, data.durationEdited, data.startTimeUs, data.endTimeUs, SentMediaQuality.STANDARD.getCode())));
Optional.of(new AttachmentTable.TransformProperties(false, data.durationEdited, data.startTimeUs, data.endTimeUs, SentMediaQuality.STANDARD.getCode(), false)));
}
}

View File

@@ -339,7 +339,7 @@ object Stories {
error("Illegal clip: $startTimeUs > $endTimeUs for clip $clipIndex")
}
AttachmentTable.TransformProperties(false, true, startTimeUs, endTimeUs, SentMediaQuality.STANDARD.code)
AttachmentTable.TransformProperties(false, true, startTimeUs, endTimeUs, SentMediaQuality.STANDARD.code, false)
}.map { transformMedia(media, it) }
}