Modern Apps git

← Modern-Apps.git

camera: add motion photo support for AVIF photos

Commit
0fba9e263b8506ee2de6009b7f409dd5906308f6
Author
Vayun Mathur <[email protected]>
When
2026-12-05 14:35 UTC (22 hours ago)
Parents
22c158b
AVIF selections previously precluded the Motion Photo diversion
because a Motion Photo was a JPEG with an MP4 trailer, so AVIF
shots silently lost their clip. AVIF is ISOBMFF, so the clip now
lives in-file instead: the Rust mux (generalised from the Exif
splicer in avif_mux.rs) inserts the same GCamera XMP packet the
JPEG layout uses as the file's XMP item (mime /
application/rdf+xml infe + iloc extent in a trailing mdat) and
appends the MP4 as a trailer with identical offset semantics
(clip length counted back from EOF). The still image item is
untouched, so plain AVIF decoders still render the photo.

Capture: MotionPhotoEligibility no longer takes a format input,
StillFormatRouting keeps an effective AVIF selection as AVIF for
motion (JPEG only when the native encoder is missing, as before
for plain still fallbacks), captureMotionPhoto names the file
.avif, and assembleAndSaveMotionPhoto encodes the AVIF still
(rotation baked, EXIF Exif item), muxes via the new
StitchNative.muxAvifMotionPhoto JNI, and saves image/avif. Any
mux/encode failure lands the plain AVIF still, the baked JPEG,
or the stamped JPEG motion photo - never a malformed file.
Ultra HDR sources still stay JPEG_R via the existing routes.
The settings dropdown is no longer blocked under AVIF.

Tests: Rust mux round-trip (XMP item via iinf/iloc, trailer
extraction, offset-mismatch/double-mux refusals), JNI round-trip,
format-routing and eligibility updates, capture-routing updates.
Verified: cargo test -p camera_stitch (145 passed), :camera:lint
:camera:lintVitalRelease :camera:testDevUnitTest green.

Diff

camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex 6632e860fd..c63fc1f2aa 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -79,7 +79,7 @@ for a direct open-on-phone broadcast. - com/vayunmathur/camera/domain/AnalysisRotation.kt — analysis-frame rotation (same formula as CaptureRotation) - com/vayunmathur/camera/domain/PanoXmp.kt - com/vayunmathur/camera/domain/SphereWaypoints.kt — FOV-derived photo-sphere waypoint layout + fused-orientation yaw/pitch math-- com/vayunmathur/camera/domain/MotionPhotoWriter.kt+- com/vayunmathur/camera/domain/MotionPhotoWriter.kt — GCamera XMP + assembly for both containers: JPEG (XMP injected, MP4 trailer) and AVIF (XMP item + MP4 trailer via the Rust mux) ### platform/ — capability queries - com/vayunmathur/camera/platform/CameraCapabilities.kt - com/vayunmathur/camera/platform/WearCameraSync.kt — phone conduit client node; mirrored state/thumbnail publish, op handling, preview streaming; wire protocol `com.vayunmathur.library.wearlink.camera.WearCameraProtocol` (WCF1 frames) in `:library:wearlink`; this module's `WearCameraProtocolTest` pins the golden JSON/frame bytes
camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoEligibility.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoEligibility.kt b/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoEligibility.ktindex 22e47cf0c0..da7ef32c87 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoEligibility.kt+++ b/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoEligibility.kt@@ -8,24 +8,24 @@ package com.vayunmathur.camera.domain  * @property plainPhoto a plain PHOTO capture (not another mode, and not  *   capturing for a caller).  * @property noBake no warmth/shadows bake is applied to the shot.- * @property avifPrecludes an effective AVIF selection, which precludes the- *   diversion because a Motion Photo is a JPEG with an MP4 trailer (see- *   [StillFormatRouting.avifPrecludesMotionPhoto]).  * @property nativeFourThree the capture is at the native 4:3 ratio: the  *   motion still is saved as raw JPEG bytes, which cannot carry a crop, so  *   other ratios take the single-shot path that saves a cropped JPEG.+ *+ * The still format is not an input: JPEG motion photos append the clip+ * to the JPEG, AVIF motion photos mux it into the AVIF (XMP item + MP4+ * trailer), and an AVIF selection with no native encoder falls back to+ * a JPEG motion photo — every format can carry the clip.  */ data class MotionPhotoInputs(     val enabled: Boolean,     val plainPhoto: Boolean,     val noBake: Boolean,-    val avifPrecludes: Boolean,     val nativeFourThree: Boolean, )  /** Pure eligibility for diverting a still to the Motion Photo path. */ object MotionPhotoEligibility {     fun isEligible(inputs: MotionPhotoInputs): Boolean =-        inputs.enabled && inputs.plainPhoto && inputs.noBake &&-            !inputs.avifPrecludes && inputs.nativeFourThree+        inputs.enabled && inputs.plainPhoto && inputs.noBake && inputs.nativeFourThree }
camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoWriter.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoWriter.kt b/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoWriter.ktindex ef21421262..960ffbe2e5 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoWriter.kt+++ b/camera/src/main/java/com/vayunmathur/camera/domain/MotionPhotoWriter.kt@@ -37,4 +37,14 @@ object MotionPhotoWriter {         val jpegWithXmp = PanoXmp.injectXmp(jpeg, buildMotionPhotoXmp(mp4.size))         return jpegWithXmp + mp4     }++    /**+     * The XMP packet for an AVIF Motion Photo: the same GCamera packet+     * the JPEG layout carries, muxed into the AVIF as its XMP item by+     * the Rust `muxAvifMotionPhoto` (the MP4 then trails the file, so+     * the offset semantics — clip length counted back from EOF — are+     * identical for both containers).+     */+    fun buildAvifMotionPhotoXmp(mp4Size: Int): ByteArray =+        buildMotionPhotoXmp(mp4Size).toByteArray(Charsets.UTF_8) }
camera/src/main/java/com/vayunmathur/camera/domain/StillFormatRouting.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/StillFormatRouting.kt b/camera/src/main/java/com/vayunmathur/camera/domain/StillFormatRouting.ktindex a3cc47bbcc..a22c11a614 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/StillFormatRouting.kt+++ b/camera/src/main/java/com/vayunmathur/camera/domain/StillFormatRouting.kt@@ -38,12 +38,14 @@ object StillFormatRouting {      /**      * The format a still is really saved as. AVIF is only honoured when-     * the native encoder is present; Motion Photos always stay JPEG-     * because the format is a JPEG with an appended MP4 trailer.+     * the native encoder is present; with no native encoder an AVIF+     * selection honestly falls back to JPEG (a JPEG Motion Photo when+     * [motionPhoto] is set). AVIF Motion Photos mux the clip in-file+     * (XMP item + MP4 trailer, see `MotionPhotoWriter`), so they keep+     * the AVIF container.      */     fun effectiveFormat(requested: StillFormat, nativeAvailable: Boolean, motionPhoto: Boolean): StillFormat =         when {-            motionPhoto -> StillFormat.JPEG             requested == StillFormat.AVIF && !nativeAvailable -> StillFormat.JPEG             else -> requested         }@@ -74,15 +76,6 @@ object StillFormatRouting {     fun plainSingleNeedsInMemory(requested: StillFormat, nativeAvailable: Boolean): Boolean =         effectiveFormat(requested, nativeAvailable, motionPhoto = false) == StillFormat.AVIF -    /**-     * True when an AVIF-bound plain still must not divert to Motion Photo:-     * a Motion Photo is a JPEG with an MP4 trailer, so honouring the AVIF-     * selection means taking the plain still (and its AVIF encode) instead.-     * JPEG-selected shots keep the Motion Photo diversion unchanged.-     */-    fun avifPrecludesMotionPhoto(requested: StillFormat, nativeAvailable: Boolean): Boolean =-        plainSingleNeedsInMemory(requested, nativeAvailable)-     /** How one pre-encoded still (HAL JPEG, ring encode, extension JPEG) must land. */     enum class StillSaveRoute {         /** Decode once and re-encode through the still encoder (AVIF when selected). */
camera/src/main/java/com/vayunmathur/camera/platform/CameraPhotoCapture.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/CameraPhotoCapture.kt b/camera/src/main/java/com/vayunmathur/camera/platform/CameraPhotoCapture.ktindex 8a7c990a7d..0ed2e10efa 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/CameraPhotoCapture.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/CameraPhotoCapture.kt@@ -175,23 +175,19 @@ internal fun CameraViewModel.stillCaptureIsZsl(): Boolean =  * Ultra HDR gain map + motion trailer), which can't carry CameraX's crop. For other ratios the  * single-shot path saves a cropped JPEG.  *- * The user's on/off setting gates first (off = plain stills always), and an- * effective AVIF selection precludes the diversion (a Motion Photo is a JPEG- * with an MP4 trailer): without that check a plain shot silently landed as- * .jpg whatever the format setting said. Both this router and the Camera2- * route in [tryCaptureCamera2Still] call this, so the decision is read once,+ * The user's on/off setting gates first (off = plain stills always).+ * Every still format can carry the clip (JPEG trailer, AVIF XMP item ++ * trailer, JPEG fallback when AVIF has no native encoder), so the format+ * never precludes the diversion. Both this router and the Camera2 route+ * in [tryCaptureCamera2Still] call this, so the decision is read once,  * at capture time, on every route.  */ internal fun CameraViewModel.motionPhotoEligible(): Boolean {-    val avifPrecludes = com.vayunmathur.camera.domain.StillFormatRouting.avifPrecludesMotionPhoto(-        requestedStillFormat(), StitchNative.isAvailable,-    )     return com.vayunmathur.camera.domain.MotionPhotoEligibility.isEligible(         com.vayunmathur.camera.domain.MotionPhotoInputs(             enabled = motionPhotoDurationMutable.value.isEnabled,             plainPhoto = cameraModeMutable.value == CameraMode.PHOTO && !captureForResult,             noBake = warmthMutable.value == 0f && shadowsMutable.value == 0f,-            avifPrecludes = avifPrecludes,             nativeFourThree = aspectRatioMutable.value == AspectRatioOption.RATIO_4_3,         )     )@@ -340,7 +336,13 @@ internal fun CameraViewModel.captureMotionPhoto() {     }     isCapturingMutable.value = true     // Name, mirroring and orientation are fixed at the shutter press, not when the save runs.-    val displayName = "IMG_${MediaStoreSaver.timestamp()}.jpg"+    // The extension follows the effective motion format (AVIF stays AVIF).+    val displayName = com.vayunmathur.camera.domain.StillFormatRouting.displayName(+        MediaStoreSaver.timestamp(),+        com.vayunmathur.camera.domain.StillFormatRouting.effectiveFormat(+            requestedStillFormat(), StitchNative.isAvailable, motionPhoto = true,+        ),+    )     val mirrored = mirrorCaptures     session.capture(         mirrored = mirrored,@@ -403,7 +405,7 @@ internal fun CameraViewModel.assembleAndSaveMotionPhoto(request: MotionSaveReque         list.filter { it.bitmap.width == w && it.bitmap.height == h }     }.orEmpty() -    val bytes = if (sized.size >= 2) {+    val mp4 = if (sized.size >= 2) {         val tmp = java.io.File(app.cacheDir, "motion_${System.currentTimeMillis()}.mp4")         val spanNs = (sized.last().timestampNanos - sized.first().timestampNanos).coerceAtLeast(1)         val fps = (sized.size * 1_000_000_000.0 / spanNs).roundToInt().coerceIn(5, 30)@@ -414,17 +416,76 @@ internal fun CameraViewModel.assembleAndSaveMotionPhoto(request: MotionSaveReque             sized.map { it.bitmap }, tmp, request.rotationDegrees, fps         )         if (ok && tmp.exists()) {-            val mp4 = tmp.readBytes()-            tmp.delete()-            MotionPhotoWriter.assemble(stillBytes, mp4)+            tmp.readBytes().also { tmp.delete() }         } else {             tmp.delete()-            stillBytes+            null         }     } else {-        stillBytes+        null     }-    return saveStillBytes(request.displayName, bytes)++    // AVIF motion: encode the still as AVIF (rotation baked, EXIF as its+    // Exif item), then mux the clip in as the XMP item + MP4 trailer.+    // Any failure lands the plain AVIF still (or the JPEG below), never+    // a malformed motion file. The name's stem is capture-time; the+    // extension follows the container actually written.+    val stem = request.displayName.substringBeforeLast('.')+    val effective = com.vayunmathur.camera.domain.StillFormatRouting.effectiveFormat(+        requestedStillFormat(), StitchNative.isAvailable, motionPhoto = true,+    )+    if (effective == com.vayunmathur.camera.domain.StillFormat.AVIF && StitchNative.isAvailable) {+        val bitmap = android.graphics.BitmapFactory.decodeByteArray(stillBytes, 0, stillBytes.size)+        if (bitmap != null) {+            try {+                val carrier = java.io.ByteArrayOutputStream().use { out ->+                    bitmap.compress(+                        android.graphics.Bitmap.CompressFormat.JPEG,+                        com.vayunmathur.camera.domain.StillFormatRouting.JPEG_QUALITY, out,+                    )+                    out.toByteArray()+                }+                val exifTiff = buildAvifExifTiff(stillBytes, carrier)+                if (exifTiff != null) {+                    val encoded = with(StillEncoder) {+                        encode(bitmap, request.rotationDegrees, exifTiff, request.mirrored)+                    }+                    if (encoded.format == com.vayunmathur.camera.domain.StillFormat.AVIF) {+                        val bytes = if (mp4 != null) {+                            try {+                                StitchNative.muxAvifMotionPhoto(+                                    encoded.bytes,+                                    MotionPhotoWriter.buildAvifMotionPhotoXmp(mp4.size),+                                    mp4,+                                )+                            } catch (e: UnsatisfiedLinkError) {+                                Log.status("CameraViewModel", "AVIF motion mux unavailable", e)+                                null+                            } ?: encoded.bytes+                        } else {+                            encoded.bytes+                        }+                        return saveStillBytes(+                            "$stem.avif", bytes,+                            com.vayunmathur.camera.domain.StillFormatRouting.mimeType(+                                com.vayunmathur.camera.domain.StillFormat.AVIF,+                            ),+                        )+                    }+                    // AVIF encode fell back to (baked) JPEG bytes: carry+                    // the clip as a JPEG motion photo instead.+                    val bytes = if (mp4 != null) MotionPhotoWriter.assemble(encoded.bytes, mp4)+                    else encoded.bytes+                    return saveStillBytes("$stem.jpg", bytes)+                }+            } finally {+                bitmap.recycle()+            }+        }+    }++    val bytes = if (mp4 != null) MotionPhotoWriter.assemble(stillBytes, mp4) else stillBytes+    return saveStillBytes("$stem.jpg", bytes) }  /**
camera/src/main/java/com/vayunmathur/camera/platform/StitchNative.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/StitchNative.kt b/camera/src/main/java/com/vayunmathur/camera/platform/StitchNative.ktindex 60767f901f..db6c1e1f6b 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/StitchNative.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/StitchNative.kt@@ -106,6 +106,15 @@ object StitchNative {      */     external fun muxAvifExif(avif: ByteArray, exif: ByteArray): ByteArray? +    /**+     * Muxes a Motion Photo into an AVIF still: [xmp] (the GCamera packet+     * from `MotionPhotoWriter.buildMotionPhotoXmp`, whose offset must+     * equal [mp4]'s length) becomes the file's XMP item and [mp4] is+     * appended as a trailer. Null on any failure — the caller then saves+     * the plain AVIF still rather than a malformed motion photo.+     */+    external fun muxAvifMotionPhoto(avif: ByteArray, xmp: ByteArray, mp4: ByteArray): ByteArray?+     // --- Zero-copy luma on-ramp (Camera2 migration Phase 3) ---      /**
camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.ktindex e364fd697a..462a11a5e7 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt@@ -30,19 +30,14 @@ import com.vayunmathur.library.ui.Text  * Post-processing settings rows owned by [SettingsPage]: the noise-reduction and  * edge-sharpening toggles (issue #662) plus the single Motion Photo dropdown  * (Off or a clip length, issue #712). Stateless: the caller passes values plus- * change callbacks.- *- * [motionPhotoBlockedByAvif] is an effective AVIF selection: a Motion Photo is- * a JPEG with an MP4 trailer, so the dropdown renders disabled showing the- * forced Off state with that reason (its stored value is kept) and captures- * stay plain stills.+ * change callbacks. The Motion Photo dropdown is available under every+ * still format: AVIF motion photos mux the clip into the AVIF file.  */ @Composable fun CameraPostProcessingSettings(     noiseReductionEnabled: Boolean,     edgeSharpeningEnabled: Boolean,     motionPhotoDuration: MotionPhotoDuration,-    motionPhotoBlockedByAvif: Boolean,     onNoiseReductionChange: (Boolean) -> Unit,     onEdgeSharpeningChange: (Boolean) -> Unit,     onMotionDurationChange: (MotionPhotoDuration) -> Unit,@@ -69,13 +64,7 @@ fun CameraPostProcessingSettings(             // Built from [OutlinedButton] + [DropdownMenu] like the codec/audio pickers             // in SettingsPage, rather than the library's `ExposedDropdownMenu` wrapper,             // which currently recurses into itself.-            // AVIF forces Off honestly: the button shows Off while blocked-            // (the stored choice is kept and returns when JPEG is selected).-            val displayed = if (motionPhotoBlockedByAvif) {-                MotionPhotoDuration.OFF-            } else {-                motionPhotoDuration-            }+            val displayed = motionPhotoDuration             var motionExpanded by remember { mutableStateOf(false) }             Box(                 modifier = Modifier@@ -84,7 +73,6 @@ fun CameraPostProcessingSettings(             ) {                 OutlinedButton(                     onClick = { motionExpanded = true },-                    enabled = !motionPhotoBlockedByAvif,                     modifier = Modifier.fillMaxWidth()                 ) {                     Text(@@ -115,12 +103,6 @@ fun CameraPostProcessingSettings(                     }                 }             }-            if (motionPhotoBlockedByAvif) {-                Text(-                    stringResource(R.string.settings_motion_photo_requires_jpeg),-                    modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),-                )-            }         }     } }
camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.ktindex 8da4906544..73f431e3b3 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt@@ -160,10 +160,6 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM                 noiseReductionEnabled = noiseReductionEnabled,                 edgeSharpeningEnabled = edgeSharpeningEnabled,                 motionPhotoDuration = motionPhotoDuration,-                // Effective AVIF only (native encoder present): a JPEG-fallback-                // AVIF selection leaves Motion Photo available, as at capture.-                motionPhotoBlockedByAvif = com.vayunmathur.camera.domain.StillFormatRouting-                    .avifPrecludesMotionPhoto(viewModel.requestedStillFormat(), com.vayunmathur.camera.platform.StitchNative.isAvailable),                 locationEnabled = locationEnabled,                 onChooseFolder = {                     val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {@@ -219,7 +215,6 @@ internal fun CameraSettingsContent(     noiseReductionEnabled: Boolean,     edgeSharpeningEnabled: Boolean,     motionPhotoDuration: MotionPhotoDuration,-    motionPhotoBlockedByAvif: Boolean,     locationEnabled: Boolean,     onChooseFolder: () -> Unit,     onResetSaveLocation: () -> Unit,@@ -268,7 +263,6 @@ internal fun CameraSettingsContent(             noiseReductionEnabled = noiseReductionEnabled,             edgeSharpeningEnabled = edgeSharpeningEnabled,             motionPhotoDuration = motionPhotoDuration,-            motionPhotoBlockedByAvif = motionPhotoBlockedByAvif,             onNoiseReductionChange = onNoiseReductionChange,             onEdgeSharpeningChange = onEdgeSharpeningChange,             onMotionDurationChange = onMotionDurationChange,
camera/src/main/rust/src/avif.rs
diff --git a/camera/src/main/rust/src/avif.rs b/camera/src/main/rust/src/avif.rsindex 5c47e01f28..4209009eb4 100644--- a/camera/src/main/rust/src/avif.rs+++ b/camera/src/main/rust/src/avif.rs@@ -236,6 +236,12 @@ pub fn avif_exif_item(bytes: &[u8]) -> Option<Vec<u8>> {     None } +/// The XMP item's raw packet, located via `iinf`/`iloc` like the Exif item.+#[cfg(test)]+pub fn avif_xmp_item(bytes: &[u8]) -> Option<Vec<u8>> {+    crate::avif_mux::avif_item_data(bytes, b"mime", Some("application/rdf+xml"))+}+ /// The TIFF payload inside the Exif item (skips the u32 TIFF offset). #[cfg(test)] pub fn avif_exif_tiff(bytes: &[u8]) -> Option<Vec<u8>> {
camera/src/main/rust/src/avif_mux.rs
diff --git a/camera/src/main/rust/src/avif_mux.rs b/camera/src/main/rust/src/avif_mux.rsindex 61651337d1..b6afa9bea1 100644--- a/camera/src/main/rust/src/avif_mux.rs+++ b/camera/src/main/rust/src/avif_mux.rs@@ -58,6 +58,21 @@ fn box_bytes(typ: &[u8; 4], payload: &[u8]) -> Option<Vec<u8>> {     Some(out) } +#[derive(Clone, Copy, PartialEq)]+enum ItemKind {+    Exif,+    Xmp,+}++impl ItemKind {+    fn item_type(self) -> &'static [u8; 4] {+        match self {+            ItemKind::Exif => b"Exif",+            ItemKind::Xmp => b"mime",+        }+    }+}+ /// Inserts [exif] (a TIFF payload) into an already-encoded AVIF file as /// its Exif item, returning the rewritten file. This is the post-mux a /// hardware `image/avif` MediaCodec encoder needs: such encoders emit a@@ -69,9 +84,109 @@ fn box_bytes(typ: &[u8; 4], payload: &[u8]) -> Option<Vec<u8>> { /// boxes — so the caller falls back to the software encoder rather than /// shipping a malformed or EXIF-less file. pub fn mux_avif_exif(avif: &[u8], exif: &[u8]) -> Option<Vec<u8>> {-    if avif.len() < 12 || &avif[4..8] != b"ftyp" || exif.is_empty() || !looks_like_exif(exif) {+    mux_avif_item(avif, exif, ItemKind::Exif)+}++/// The `MicroVideoOffset` value (clip length, bytes from EOF) in [xmp].+fn micro_video_offset(xmp: &[u8]) -> Option<u64> {+    let text = String::from_utf8_lossy(xmp);+    if !text.contains("MicroVideo") {         return None;     }+    let marker = "MicroVideoOffset";+    let idx = text.find(marker)?;+    let rest = &text[idx + marker.len()..];+    let start = rest.find(|c: char| c.is_ascii_digit())?;+    let digits: String = rest[start..].chars().take_while(|c| c.is_ascii_digit()).collect();+    digits.parse().ok()+}++/// Muxes a motion-photo clip into an AVIF still: [xmp] (a GCamera packet+/// whose `MicroVideoOffset` equals [mp4]'s length) becomes the file's XMP+/// item (`mime` / `application/rdf+xml`, per ISO/IEC 23008-12) and [mp4]+/// is appended as a trailer, mirroring the JPEG MicroVideo layout our+/// Photos app extracts (clip length counted back from EOF). The still+/// image item is untouched, so plain AVIF decoders still render it.+/// `None` on any mismatch so the caller saves a plain AVIF still.+pub fn mux_avif_motion_photo(avif: &[u8], xmp: &[u8], mp4: &[u8]) -> Option<Vec<u8>> {+    if mp4.is_empty() || micro_video_offset(xmp)? != mp4.len() as u64 {+        return None;+    }+    let mut out = mux_avif_item(avif, xmp, ItemKind::Xmp)?;+    out.extend_from_slice(mp4);+    Some(out)+}++/// The embedded motion clip of a file built by [mux_avif_motion_photo]:+/// the trailing bytes declared by the XMP item's `MicroVideoOffset`.+pub fn avif_motion_video(bytes: &[u8]) -> Option<&[u8]> {+    let xmp = avif_item_data(bytes, b"mime", Some("application/rdf+xml"))?;+    let len = usize::try_from(micro_video_offset(&xmp)?).ok()?;+    if len == 0 || len > bytes.len() {+        return None;+    }+    bytes.get(bytes.len() - len..)+}++/// Item data located via `iinf` (item of [item_type], for `mime` items+/// also matching the content-type prefix) plus `iloc` extents.+pub(crate) fn avif_item_data(+    bytes: &[u8],+    item_type: &[u8; 4],+    content_type_prefix: Option<&str>,+) -> Option<Vec<u8>> {+    let top = parse_boxes(bytes, 0..bytes.len());+    let meta = top.iter().find(|b| &b.typ == b"meta")?;+    let children = parse_boxes(bytes, (meta.payload.start + 4)..meta.payload.end);+    let iinf = children.iter().find(|b| &b.typ == b"iinf")?;+    let infes = parse_boxes(+        bytes,+        (iinf.payload.start + 4 + if *bytes.get(iinf.payload.start)? == 1 { 4 } else { 2 })+            ..iinf.payload.end,+    );+    let mut wanted: Option<u32> = None;+    for infe in &infes {+        let p = infe.payload.start + 4;+        if bytes.get(p + 4..p + 8)? != item_type {+            continue;+        }+        if let Some(prefix) = content_type_prefix {+            // mime infe: type, null-terminated name, null-terminated type.+            let mut pos = p + 8;+            while *bytes.get(pos)? != 0 {+                pos += 1;+            }+            pos += 1;+            let start = pos;+            while *bytes.get(pos)? != 0 {+                pos += 1;+            }+            if !String::from_utf8_lossy(&bytes[start..pos]).starts_with(prefix) {+                continue;+            }+        }+        wanted = Some(u16::from_be_bytes(bytes.get(p..p + 2)?.try_into().ok()?) as u32);+        break;+    }+    let iloc = children.iter().find(|b| &b.typ == b"iloc")?;+    let items = parse_iloc(bytes, iloc)?;+    let item = items.iter().find(|i| Some(i.item_id) == wanted)?;+    let mut out = Vec::new();+    for &(offset, length) in &item.extents {+        out.extend_from_slice(bytes.get(offset as usize..(offset + length) as usize)?);+    }+    Some(out)+}++fn mux_avif_item(avif: &[u8], payload: &[u8], kind: ItemKind) -> Option<Vec<u8>> {+    let valid = match kind {+        ItemKind::Exif => !payload.is_empty() && looks_like_exif(payload),+        ItemKind::Xmp => !payload.is_empty() && payload.windows(1).any(|w| w == b"<"),+    };+    if avif.len() < 12 || &avif[4..8] != b"ftyp" || !valid {+        return None;+    }+    let exif = payload;     let top = parse_boxes(avif, 0..avif.len());     let meta = top.iter().find(|b| &b.typ == b"meta")?;     let meta_children_span = (meta.payload.start + 4)..meta.payload.end;@@ -113,8 +228,8 @@ pub fn mux_avif_exif(avif: &[u8], exif: &[u8]) -> Option<Vec<u8>> {         let p = infe.payload.start + 4;         let id = u16::from_be_bytes(avif.get(p..p + 2)?.try_into().ok()?) as u32;         max_id = max_id.max(id);-        if avif.get(p + 4..p + 8)? == b"Exif" {-            return None; // already carries an Exif item+        if avif.get(p + 4..p + 8)? == kind.item_type() {+            return None; // already carries an item of this kind         }     }     let _ = entry_count;@@ -126,8 +241,13 @@ pub fn mux_avif_exif(avif: &[u8], exif: &[u8]) -> Option<Vec<u8>> {     infe_payload.extend_from_slice(&2u32.to_be_bytes()); // version 2, flags 0     infe_payload.extend_from_slice(&(new_id as u16).to_be_bytes());     infe_payload.extend_from_slice(&0u16.to_be_bytes()); // protection index-    infe_payload.extend_from_slice(b"Exif");+    infe_payload.extend_from_slice(kind.item_type());     infe_payload.push(0); // empty item name+    if kind == ItemKind::Xmp {+        infe_payload.extend_from_slice(b"application/rdf+xml");+        infe_payload.push(0); // content type terminator+        infe_payload.push(0); // empty content encoding+    }     let infe_box = box_bytes(b"infe", &infe_payload)?;     let mut iinf_payload = Vec::new();     iinf_payload.extend_from_slice(avif.get(iinf.payload.start..iinf.payload.start + 4)?);@@ -197,8 +317,9 @@ pub fn mux_avif_exif(avif: &[u8], exif: &[u8]) -> Option<Vec<u8>> {     let old_meta_total = meta.payload.end - meta.start;     let delta = new_meta_total as i64 - old_meta_total as i64; -    // Exif item data lives in a trailing mdat: [u32 offset = 0][TIFF].-    let framed_len = 4 + exif.len();+    // Item data lives in a trailing mdat: Exif is framed+    // [u32 offset = 0][TIFF]; an XMP item is the raw packet.+    let framed_len = if kind == ItemKind::Exif { 4 + exif.len() } else { exif.len() };     let mdat_start = (avif.len() as i64 + delta) as usize;     let exif_extent_offset = mdat_start + 8; @@ -258,7 +379,9 @@ pub fn mux_avif_exif(avif: &[u8], exif: &[u8]) -> Option<Vec<u8>> {     out.extend_from_slice(&avif[meta.payload.end..]);     debug_assert_eq!(out.len(), mdat_start);     let mut mdat_payload = Vec::with_capacity(framed_len);-    mdat_payload.extend_from_slice(&0u32.to_be_bytes());+    if kind == ItemKind::Exif {+        mdat_payload.extend_from_slice(&0u32.to_be_bytes());+    }     mdat_payload.extend_from_slice(exif);     out.extend_from_slice(&box_bytes(b"mdat", &mdat_payload)?);     Some(out)@@ -336,3 +459,25 @@ Java_com_vayunmathur_camera_platform_StitchNative_muxAvifExif -> jni::sys::jbyte             None => Ok(null),         }     } }++jni_fn! { /// JNI entry for `StitchNative.muxAvifMotionPhoto`: muxes a+/// GCamera XMP item plus MP4 trailer into an AVIF still. Null on failure.+Java_com_vayunmathur_camera_platform_StitchNative_muxAvifMotionPhoto -> jni::sys::jbyteArray; (_class: jni::objects::JClass<'l>, avif: jni::objects::JByteArray<'l>, xmp: jni::objects::JByteArray<'l>, mp4: jni::objects::JByteArray<'l>) |env| {+        let null = std::ptr::null_mut();+        let convert = |a: &jni::objects::JByteArray<'l>| env.convert_byte_array(a);+        let (bytes, xmp_bytes, mp4_bytes) = match (convert(&avif), convert(&xmp), convert(&mp4)) {+            (Ok(a), Ok(b), Ok(c)) => (a, b, c),+            _ => return Ok(null),+        };+        let muxed = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {+            mux_avif_motion_photo(&bytes, &xmp_bytes, &mp4_bytes)+        }))+        .unwrap_or(None);+        match muxed {+            Some(b) => match env.byte_array_from_slice(&b) {+                Ok(arr) => Ok(arr.into_raw()),+                Err(_) => Ok(null),+            },+            None => Ok(null),+        }+    } }
camera/src/main/rust/src/avif_tests.rs
diff --git a/camera/src/main/rust/src/avif_tests.rs b/camera/src/main/rust/src/avif_tests.rsindex c68a972162..2a8b265bb1 100644--- a/camera/src/main/rust/src/avif_tests.rs+++ b/camera/src/main/rust/src/avif_tests.rs@@ -1,8 +1,8 @@ use super::{-    avif_dimensions, avif_exif_item, avif_exif_tiff, encode_avif, encode_avif_with_exif,-    has_avif_magic,+    avif_dimensions, avif_exif_item, avif_exif_tiff, avif_xmp_item, encode_avif,+    encode_avif_with_exif, has_avif_magic, };-use crate::avif_mux::mux_avif_exif;+use crate::avif_mux::{avif_motion_video, mux_avif_exif, mux_avif_motion_photo};  /// Minimal little-endian TIFF: IFD0 with one Orientation(=1) entry, /// then a marker tail so content assertions can find the payload.@@ -76,6 +76,35 @@ fn mux_splices_exif_into_encoded_avif() {     assert!(mux_avif_exif(b"not an avif", &tiff).is_none()); } +fn motion_xmp(mp4_len: usize) -> Vec<u8> {+    format!(+        "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF><rdf:Description \+         GCamera:MotionPhoto=\"1\" GCamera:MicroVideo=\"1\" \+         GCamera:MicroVideoOffset=\"{mp4_len}\"/></rdf:RDF></x:xmpmeta>"+    )+    .into_bytes()+}++#[test]+fn motion_photo_mux_round_trips_xmp_and_video() {+    let rgba = gradient(64, 48);+    let mp4: Vec<u8> = b"\0\0\0\x18ftypmp42\0\0\0\0mp41mp42FAKE-CLIP-DATA".to_vec();+    let bare = encode_avif(&rgba, 64, 48, 80.0, 10).expect("encode must succeed");+    let muxed = mux_avif_motion_photo(&bare, &motion_xmp(mp4.len()), &mp4)+        .expect("motion mux must succeed");+    assert!(has_avif_magic(&muxed));+    assert_eq!(avif_dimensions(&muxed), Some((64, 48)));+    let xmp = avif_xmp_item(&muxed).expect("XMP item must be present via iinf/iloc");+    assert!(String::from_utf8_lossy(&xmp).contains("GCamera:MicroVideo=\"1\""));+    assert_eq!(avif_motion_video(&muxed), Some(mp4.as_slice()));+    // Refusals: offset/length mismatch, empty clip, non-AVIF, double mux.+    assert!(mux_avif_motion_photo(&bare, &motion_xmp(999), &mp4).is_none());+    assert!(mux_avif_motion_photo(&bare, &motion_xmp(0), &[]).is_none());+    assert!(mux_avif_motion_photo(b"not an avif", &motion_xmp(mp4.len()), &mp4).is_none());+    assert!(mux_avif_motion_photo(&muxed, &motion_xmp(mp4.len()), &mp4).is_none());+    assert_eq!(avif_motion_video(&bare), None);+}+ #[test] fn no_exif_item_when_no_payload_given() {     let rgba = gradient(32, 32);
camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt
diff --git a/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.ktindex abbf66be53..2d6f88ae0c 100644--- a/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt+++ b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt@@ -152,7 +152,6 @@ class MetadataPreviews {                         noiseReductionEnabled = true,                         edgeSharpeningEnabled = true,                         motionPhotoDuration = MotionPhotoDuration.THREE,-                        motionPhotoBlockedByAvif = false,                         locationEnabled = true,                         onChooseFolder = {},                         onResetSaveLocation = {},
camera/src/test/java/com/vayunmathur/camera/domain/MotionPhotoEligibilityTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/MotionPhotoEligibilityTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/MotionPhotoEligibilityTest.ktindex ef30050529..94d3f9ea78 100644--- a/camera/src/test/java/com/vayunmathur/camera/domain/MotionPhotoEligibilityTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/domain/MotionPhotoEligibilityTest.kt@@ -10,7 +10,6 @@ class MotionPhotoEligibilityTest {         enabled = true,         plainPhoto = true,         noBake = true,-        avifPrecludes = false,         nativeFourThree = true,     ) @@ -21,8 +20,6 @@ class MotionPhotoEligibilityTest {      @Test     fun offNeverEligibleEvenWhenEverythingElseAllows() {-        // 4:3 + JPEG (no AVIF preclusion) + no bake + plain photo, length-        // irrelevant here: off alone must veto.         assertFalse(MotionPhotoEligibility.isEligible(eligible.copy(enabled = false)))     } @@ -30,7 +27,6 @@ class MotionPhotoEligibilityTest {     fun onPreviousMatrixUnchanged() {         assertFalse(MotionPhotoEligibility.isEligible(eligible.copy(plainPhoto = false)))         assertFalse(MotionPhotoEligibility.isEligible(eligible.copy(noBake = false)))-        assertFalse(MotionPhotoEligibility.isEligible(eligible.copy(avifPrecludes = true)))         assertFalse(MotionPhotoEligibility.isEligible(eligible.copy(nativeFourThree = false)))     } @@ -38,18 +34,16 @@ class MotionPhotoEligibilityTest {     fun offVetoesEveryOtherCombination() {         for (plain in listOf(true, false)) {             for (bake in listOf(true, false)) {-                for (avif in listOf(true, false)) {-                    for (ratio in listOf(true, false)) {-                        assertFalse(-                            MotionPhotoEligibility.isEligible(-                                MotionPhotoInputs(-                                    enabled = false, plainPhoto = plain, noBake = bake,-                                    avifPrecludes = avif, nativeFourThree = ratio,-                                )-                            ),-                            "off must veto plain=$plain bake=$bake avif=$avif ratio=$ratio",-                        )-                    }+                for (ratio in listOf(true, false)) {+                    assertFalse(+                        MotionPhotoEligibility.isEligible(+                            MotionPhotoInputs(+                                enabled = false, plainPhoto = plain, noBake = bake,+                                nativeFourThree = ratio,+                            )+                        ),+                        "off must veto plain=$plain bake=$bake ratio=$ratio",+                    )                 }             }         }
camera/src/test/java/com/vayunmathur/camera/domain/StillFormatRoutingTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/StillFormatRoutingTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/StillFormatRoutingTest.ktindex e13d61965a..9d0c59b344 100644--- a/camera/src/test/java/com/vayunmathur/camera/domain/StillFormatRoutingTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/domain/StillFormatRoutingTest.kt@@ -24,11 +24,26 @@ class StillFormatRoutingTest {     }      @Test-    fun motionPhotosAlwaysStayJpeg() {+    fun motionPhotosKeepAvifWhenNativeAvailable() {+        // AVIF motion photos mux the clip into the AVIF (XMP item + MP4+        // trailer), so an effective AVIF selection stays AVIF.         assertEquals(-            StillFormat.JPEG,+            StillFormat.AVIF,             StillFormatRouting.effectiveFormat(StillFormat.AVIF, nativeAvailable = true, motionPhoto = true),         )+        assertEquals("IMG_20260101_120000_000.avif",+            StillFormatRouting.displayName("20260101_120000_000",+                StillFormatRouting.effectiveFormat(StillFormat.AVIF, nativeAvailable = true, motionPhoto = true)))+        assertEquals("image/avif", StillFormatRouting.mimeType(+            StillFormatRouting.effectiveFormat(StillFormat.AVIF, nativeAvailable = true, motionPhoto = true)))+    }++    @Test+    fun motionPhotosFallBackToJpegWhenNativeMissing() {+        assertEquals(+            StillFormat.JPEG,+            StillFormatRouting.effectiveFormat(StillFormat.AVIF, nativeAvailable = false, motionPhoto = true),+        )     }      @Test@@ -115,15 +130,6 @@ class StillFormatRoutingTest {         )     } -    @Test-    fun avifPrecludesMotionPhotoDiversionOnlyWhenEffective() {-        assertTrue(StillFormatRouting.avifPrecludesMotionPhoto(StillFormat.AVIF, nativeAvailable = true))-        // No native encoder: AVIF honestly falls back to JPEG, so the-        // Motion Photo diversion is unchanged.-        assertFalse(StillFormatRouting.avifPrecludesMotionPhoto(StillFormat.AVIF, nativeAvailable = false))-        assertFalse(StillFormatRouting.avifPrecludesMotionPhoto(StillFormat.JPEG, nativeAvailable = true))-    }-     @Test     fun avifSpeedAndQualityTargetsArePinned() {         // Quality target unchanged by the speed tuning; speed 10 is the
camera/src/test/java/com/vayunmathur/camera/platform/Camera2AvifRoutingTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/Camera2AvifRoutingTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/Camera2AvifRoutingTest.ktindex b8743a4840..7e84fecfce 100644--- a/camera/src/test/java/com/vayunmathur/camera/platform/Camera2AvifRoutingTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/platform/Camera2AvifRoutingTest.kt@@ -245,24 +245,25 @@ class Camera2AvifRoutingTest {         return session     } -    @Test fun avifPlainShotTakesCamera2InsteadOfMotionDiversion() {+    @Test fun avifPlainShotKeepsMotionDiversion() {         val executor = Camera2Executor("AvifRouting-direct")         try {             val handle = FakeHandle()             val session = streamingSession(executor, handle)             val viewModel = vm()             viewModel.registerCamera2Session(session)-            // Default plain shot (PHOTO, 4:3, no bake): Motion-eligible.-            // JPEG keeps the diversion; AVIF (set after bind) must not.+            // Default plain shot (PHOTO, 4:3, no bake): Motion-eligible+            // under both formats — AVIF muxes the clip in-file, so it+            // keeps the diversion exactly like JPEG.             viewModel.photoFormatMutable.value = PhotoFormat.JPEG             assertFalse(viewModel.tryCaptureCamera2Still())             executor.drain()             assertEquals(0, handle.stillRequests.size)              viewModel.photoFormatMutable.value = PhotoFormat.AVIF-            assertTrue(viewModel.tryCaptureCamera2Still())+            assertFalse(viewModel.tryCaptureCamera2Still())             executor.drain()-            assertEquals(1, handle.stillRequests.size)+            assertEquals(0, handle.stillRequests.size)             session.close()             executor.drain()         } finally {
camera/src/test/java/com/vayunmathur/camera/platform/CaptureRoutingExtraTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/CaptureRoutingExtraTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/CaptureRoutingExtraTest.ktindex 0ddc0d2791..3e2885bda3 100644--- a/camera/src/test/java/com/vayunmathur/camera/platform/CaptureRoutingExtraTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/platform/CaptureRoutingExtraTest.kt@@ -72,7 +72,7 @@ class CaptureRoutingExtraTest {         val v=vm(); v.lastAeState=CameraMetadata.CONTROL_AE_STATE_SEARCHING; assertFalse(v.isAeConvergedForCapture()); v.lastAeState=null; assertTrue(v.isAeConvergedForCapture())     }     @Test fun routeDefaultsToMotionPhotoWhenEligible() { assertEquals(StillRoute.MOTION_PHOTO, vm().routeStillCapture()) }-    @Test fun routeAvifSelectsSingle() { if(!StitchNative.isAvailable) return; val v=vm(); v.photoFormatMutable.value=PhotoFormat.AVIF; assertEquals(StillRoute.SINGLE,v.routeStillCapture()) }+    @Test fun routeAvifSelectsMotionPhoto() { if(!StitchNative.isAvailable) return; val v=vm(); v.photoFormatMutable.value=PhotoFormat.AVIF; assertEquals(StillRoute.MOTION_PHOTO,v.routeStillCapture()) }     @Test fun routeNightPreviewIsSingle() { val v=vm(); v.nightPreviewActiveMutable.value=true; assertEquals(StillRoute.SINGLE,v.routeStillCapture()) }     @Test fun routeNightWhenDark() {         val v=vm(); v.lowLightDetectedMutable.value=true; org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()
camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.ktindex b514438254..da596394e4 100644--- a/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/platform/StillEncoderNativeTest.kt@@ -69,6 +69,26 @@ class StillEncoderNativeTest {         assertEquals(null, StitchNative.muxAvifExif(muxed, tiff))     } +    @Test+    fun muxAvifMotionPhotoRoundTripsClip() {+        if (!StitchNative.isAvailable) return+        val width = 64+        val height = 48+        val rgba = ByteArray(width * height * 4) { 0x80.toByte() }+        val bare = StitchNative.encodeAvif(rgba, width, height, 80f, 10)+        assertNotNull(bare)+        val mp4 = byteArrayOf(0, 0, 0, 24) + "ftypmp42FAKECLIP".toByteArray(Charsets.US_ASCII)+        val xmp = com.vayunmathur.camera.domain.MotionPhotoWriter.buildAvifMotionPhotoXmp(mp4.size)+        val muxed = StitchNative.muxAvifMotionPhoto(bare, xmp, mp4)+        assertNotNull(muxed)+        assertEquals("ftypavif", String(muxed, 4, 8, Charsets.US_ASCII))+        assertTrue(muxed.takeLast(mp4.size).toByteArray().contentEquals(mp4))+        assertTrue("application/rdf+xml" in String(muxed, Charsets.ISO_8859_1))+        // Offset/length mismatch is refused.+        assertEquals(null, StitchNative.muxAvifMotionPhoto(bare,+            com.vayunmathur.camera.domain.MotionPhotoWriter.buildAvifMotionPhotoXmp(999), mp4))+    }+     @Test     fun encodeAvifRejectsMismatchedInput() {         if (!StitchNative.isAvailable) return
camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2SettingsTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2SettingsTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2SettingsTest.ktindex 2b4ab450c3..1e93aed943 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2SettingsTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2SettingsTest.kt@@ -113,7 +113,6 @@ class CameraCovC2SettingsTest {             CameraPostProcessingSettings(                 noiseReductionEnabled = noise, edgeSharpeningEnabled = edge,                 motionPhotoDuration = duration,-                motionPhotoBlockedByAvif = false,                 onNoiseReductionChange = { noise = it },                 onEdgeSharpeningChange = { edge = it },                 onMotionDurationChange = { duration = it },@@ -137,7 +136,6 @@ class CameraCovC2SettingsTest {             CameraPostProcessingSettings(                 noiseReductionEnabled = true, edgeSharpeningEnabled = true,                 motionPhotoDuration = duration,-                motionPhotoBlockedByAvif = false,                 onNoiseReductionChange = {}, onEdgeSharpeningChange = {},                 onMotionDurationChange = { duration = it },             )@@ -152,23 +150,19 @@ class CameraCovC2SettingsTest {         assertEquals(MotionPhotoDuration.OFF, duration)     } -    @Test fun motionPhotoDropdownDisabledShowingOffWhenAvifBlocks() {+    @Test fun motionPhotoDropdownStaysEnabledUnderAvif() {+        // AVIF motion photos mux the clip in-file, so the dropdown is+        // never blocked by the format: it shows the stored duration.         var duration = MotionPhotoDuration.THREE         rule.setContent {             CameraPostProcessingSettings(                 noiseReductionEnabled = true, edgeSharpeningEnabled = true,                 motionPhotoDuration = duration,-                motionPhotoBlockedByAvif = true,                 onNoiseReductionChange = {}, onEdgeSharpeningChange = {},                 onMotionDurationChange = { duration = it },             )         }-        rule.onNodeWithText(-            str(com.vayunmathur.camera.R.string.settings_motion_photo_requires_jpeg)-        ).assertIsDisplayed()-        // Honest forced Off: the disabled button shows Off, stored value kept.-        rule.onNodeWithText(str(com.vayunmathur.camera.R.string.settings_motion_photo_off))-            .assertIsNotEnabled()-        assertEquals(MotionPhotoDuration.THREE, duration, "AVIF block must not rewrite the stored setting")+        rule.onNodeWithText("3 seconds", substring = true).assertIsDisplayed()+        assertEquals(MotionPhotoDuration.THREE, duration)     } }
camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.ktindex d022ef01d9..f4a832ca15 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt@@ -180,7 +180,6 @@ class CameraPanesComposeTest {             CameraPostProcessingSettings(                 noiseReductionEnabled = true, edgeSharpeningEnabled = false,                 motionPhotoDuration = MotionPhotoDuration.THREE,-                motionPhotoBlockedByAvif = false,                 onNoiseReductionChange = { noise = it },                 onEdgeSharpeningChange = {},                 onMotionDurationChange = {},