Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Switch motion photo and XMP usage to Rust APIs

Neeraj Gupta7eb28dcbbb95
diff --git a/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart b/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart
index 2116a5bdde..8df5aef99c 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart
@@ -3,10 +3,9 @@ import "dart:io";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
-// ignore: implementation_imports
-import "package:motion_photos/src/xmp_extractor.dart";
import "package:panorama/panorama.dart";
import "package:photos/generated/l10n.dart";
+import "package:photos/src/rust/api/motion_photo_api.dart";
class PanoramaViewerScreen extends StatefulWidget {
const PanoramaViewerScreen({
@@ -54,7 +53,7 @@ class _PanoramaViewerScreenState extends State<PanoramaViewerScreen> {
}
Future<void> init() async {
- final data = XMPExtractor().extract(widget.file.readAsBytesSync());
+ final data = await extractXmp(filePath: widget.file.path);
double? cWidth =
double.tryParse(data["GPano:CroppedAreaImageWidthPixels"] ?? "");
double? cHeight =
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
index 2e2a984b98..3a0f2d7601 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
@@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import "package:media_kit/media_kit.dart";
import "package:media_kit_video/media_kit_video.dart";
-import 'package:motion_photos/motion_photos.dart';
import "package:path_provider/path_provider.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/guest_view_event.dart";
@@ -14,6 +13,7 @@ import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/metadata/file_magic.dart";
import "package:photos/services/file_magic_service.dart";
+import "package:photos/src/rust/api/motion_photo_api.dart";
import 'package:photos/ui/notification/toast.dart';
import 'package:photos/ui/viewer/file/zoomable_image.dart';
import 'package:photos/utils/file_util.dart';
@@ -196,20 +196,23 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
return null;
});
if (imageFile != null) {
- final motionPhoto = MotionPhotos(imageFile.path);
- final index = await motionPhoto.getMotionVideoIndex();
+ final index = await getMotionVideoIndex(filePath: imageFile.path);
if (index != null) {
// Update the metadata if it is not updated
if (!_enteFile.isMotionPhoto && _enteFile.canEditMetaInfo) {
FileMagicService.instance.updatePublicMagicMetadata(
[_enteFile],
- {motionVideoIndexKey: index.start},
+ {motionVideoIndexKey: index.start.toInt()},
).ignore();
}
- return motionPhoto.getMotionVideoFile(
- await getTemporaryDirectory(),
+ final outputPath = await extractMotionVideoFile(
+ filePath: imageFile.path,
+ destinationDirectory: (await getTemporaryDirectory()).path,
index: index,
);
+ if (outputPath != null) {
+ return File(outputPath);
+ }
} else if (_enteFile.isMotionPhoto && _enteFile.canEditMetaInfo) {
_logger.info('Incorrectly tagged as MP, reset tag ${_enteFile.tag}');
FileMagicService.instance.updatePublicMagicMetadata(
diff --git a/mobile/apps/photos/lib/utils/exif_util.dart b/mobile/apps/photos/lib/utils/exif_util.dart
index c2d5fb3cb0..416a990a06 100644
--- a/mobile/apps/photos/lib/utils/exif_util.dart
+++ b/mobile/apps/photos/lib/utils/exif_util.dart
@@ -5,13 +5,12 @@ import "package:computer/computer.dart";
import 'package:exif_reader/exif_reader.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
-// ignore: implementation_imports
-import "package:motion_photos/src/xmp_extractor.dart";
import "package:photos/models/ffmpeg/ffprobe_props.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/location/location.dart";
import "package:photos/services/isolated_ffmpeg_service.dart";
import "package:photos/services/location_service.dart";
+import "package:photos/src/rust/api/motion_photo_api.dart";
import 'package:photos/utils/file_util.dart';
const kDateTimeOriginal = "EXIF DateTimeOriginal";
@@ -54,16 +53,7 @@ Future<Map<String, IfdTag>?> tryExifFromFile(File originFile) async {
}
Future<Map<String, dynamic>> getXmp(File file) async {
- return Computer.shared().compute(
- _getXMPComputer,
- param: {"file": file},
- taskName: "getXMPAsync",
- );
-}
-
-Map<String, dynamic> _getXMPComputer(Map<String, dynamic> args) {
- final File originalFile = args["file"] as File;
- return XMPExtractor().extract(originalFile.readAsBytesSync());
+ return extractXmp(filePath: file.path);
}
Future<FFProbeProps?> getVideoPropsAsync(File originalFile) async {
diff --git a/mobile/apps/photos/lib/utils/file_uploader_util.dart b/mobile/apps/photos/lib/utils/file_uploader_util.dart
index 643fe19611..7de82cfeb7 100644
--- a/mobile/apps/photos/lib/utils/file_uploader_util.dart
+++ b/mobile/apps/photos/lib/utils/file_uploader_util.dart
@@ -9,7 +9,6 @@ import "package:computer/computer.dart";
import 'package:ente_crypto/ente_crypto.dart';
import "package:exif_reader/exif_reader.dart";
import 'package:logging/logging.dart';
-import "package:motion_photos/motion_photos.dart";
import 'package:motionphoto/motionphoto.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
@@ -25,6 +24,7 @@ import 'package:photos/models/file/file_type.dart';
import "package:photos/models/location/location.dart";
import "package:photos/models/metadata/file_magic.dart";
import "package:photos/services/sync/local_sync_service.dart";
+import "package:photos/src/rust/api/motion_photo_api.dart";
import "package:photos/utils/exif_util.dart";
import 'package:photos/utils/file_util.dart';
import "package:uuid/uuid.dart";
@@ -199,11 +199,8 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
int? motionPhotoStartingIndex;
if (Platform.isAndroid && asset.type == AssetType.image) {
try {
- motionPhotoStartingIndex = await Computer.shared().compute(
- motionVideoIndex,
- param: {'path': sourceFile.path},
- taskName: 'motionPhotoIndex',
- );
+ motionPhotoStartingIndex =
+ await motionVideoIndex({'path': sourceFile.path});
} catch (e) {
_logger.severe('error while detecthing motion photo start index', e);
}
@@ -224,7 +221,8 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
Future<int?> motionVideoIndex(Map<String, dynamic> args) async {
final String path = args['path'];
- return (await MotionPhotos(path).getMotionVideoIndex())?.start;
+ final videoIndex = await getMotionVideoIndex(filePath: path);
+ return videoIndex?.start.toInt();
}
Future<void> _computeZip(Map<String, dynamic> args) async {
diff --git a/mobile/apps/photos/lib/utils/panorama_util.dart b/mobile/apps/photos/lib/utils/panorama_util.dart
index 3a583c2809..124a016e46 100644
--- a/mobile/apps/photos/lib/utils/panorama_util.dart
+++ b/mobile/apps/photos/lib/utils/panorama_util.dart
@@ -1,10 +1,9 @@
-// ignore: implementation_imports
-import "package:motion_photos/src/xmp_extractor.dart";
import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/metadata/file_magic.dart";
import "package:photos/services/file_magic_service.dart";
+import "package:photos/src/rust/api/motion_photo_api.dart";
import "package:photos/utils/exif_util.dart";
import "package:photos/utils/file_util.dart";
@@ -18,7 +17,7 @@ Future<bool> checkIfPanorama(EnteFile enteFile) async {
return false;
}
try {
- final result = XMPExtractor().extract(file.readAsBytesSync());
+ final result = await extractXmp(filePath: file.path);
if (checkPanoramaFromXMP(result)) {
return true;
}
diff --git a/mobile/apps/photos/pubspec.lock b/mobile/apps/photos/pubspec.lock
index 9342ff0462..01d2830fc3 100644
--- a/mobile/apps/photos/pubspec.lock
+++ b/mobile/apps/photos/pubspec.lock
@@ -1807,15 +1807,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
- motion_photos:
- dependency: "direct main"
- description:
- path: "."
- ref: HEAD
- resolved-ref: ddf5eba70103c2add7c20010430d9db654ddf95c
- url: "https://github.com/ente-io/motion_photo.git"
- source: git
- version: "1.0.0"
motion_sensors:
dependency: transitive
description:
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index 9ac0d775af..8a4eff146e 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -153,8 +153,6 @@ dependencies:
url: https://github.com/ente-io/mobile_ocr
ref: f5ff2124c8424196ea3dc5cf493d98107a5276d4
modal_bottom_sheet: ^3.0.0
- motion_photos:
- git: "https://github.com/ente-io/motion_photo.git"
motionphoto:
git: "https://github.com/ente-io/motionphoto.git"
move_to_background: # no updates in git, replace package