π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: make continuation and releasing compute better
Prateek Sunal27d72eb821fa
diff --git a/mobile/apps/photos/lib/services/video_preview_service.dart b/mobile/apps/photos/lib/services/video_preview_service.dartindex a9d68664ae..652890a935 100644--- a/mobile/apps/photos/lib/services/video_preview_service.dart+++ b/mobile/apps/photos/lib/services/video_preview_service.dart@@ -274,9 +274,12 @@ class VideoPreviewService {Future<void> chunkAndUploadVideo(BuildContext? ctx,- EnteFile enteFile, [+ EnteFile enteFile, {+ /// Indicates this function is an continuation of a chunking thread+ bool continuation = false,+ // not used currentlybool forceUpload = false,- ]) async {+ }) async {final bool isManual =await uploadLocksDB.isInStreamQueue(enteFile.uploadedFileID!);final canStream = _isPermissionGranted();@@ -284,6 +287,7 @@ class VideoPreviewService {_logger.info("Pause preview due to disabledSteaming($isVideoStreamingEnabled) or computeController permission) - isManual: $isManual",);+ computeController.releaseCompute(stream: true);if (isVideoStreamingEnabled) _logger.info("No permission to run compute");clearQueue();return;@@ -330,7 +334,7 @@ class VideoPreviewService {}// check if there is already a preview in processing- if (uploadingFileId >= 0) {+ if (!continuation && uploadingFileId >= 0) {if (uploadingFileId == enteFile.uploadedFileID) return;_items[enteFile.uploadedFileID!] = PreviewItem(@@ -581,10 +585,6 @@ class VideoPreviewService {_removeFile(enteFile);_removeFromLocks(enteFile).ignore();}- // reset uploading status if this was getting processed- if (uploadingFileId == enteFile.uploadedFileID!) {- uploadingFileId = -1;- }if (fileQueue.isNotEmpty) {// process next file_logger.info(@@ -593,12 +593,18 @@ class VideoPreviewService {final entry = fileQueue.entries.first;final file = entry.value;fileQueue.remove(entry.key);- await chunkAndUploadVideo(ctx, file);+ await chunkAndUploadVideo(+ ctx,+ file,+ continuation: true,+ );} else {_logger.info("[chunk] Nothing to process releasing compute, $error",);computeController.releaseCompute(stream: true);++ uploadingFileId = -1;}}}@@ -1009,8 +1015,9 @@ class VideoPreviewService {}// generate stream for all files after cutoff date- Future<void> _putFilesForPreviewCreation() async {- if (!isVideoStreamingEnabled || !await canUseHighBandwidth()) return;+ // returns false if it fails to launch chuncking function+ Future<bool> _putFilesForPreviewCreation() async {+ if (!isVideoStreamingEnabled || !await canUseHighBandwidth()) return false;Map<int, String> failureFiles = {};Map<int, String> manualQueueFiles = {};@@ -1146,7 +1153,7 @@ class VideoPreviewService {final totalFiles = fileQueue.length;if (totalFiles == 0) {_logger.info("[init] No preview to cache");- return;+ return false;}_logger.info(@@ -1158,6 +1165,7 @@ class VideoPreviewService {final file = entry.value;fileQueue.remove(entry.key);chunkAndUploadVideo(null, file).ignore();+ return true;}bool _allowStream() {@@ -1174,9 +1182,11 @@ class VideoPreviewService {);}+ /// To check if it's enabled, device is healthy and running streamingbool _isPermissionGranted() {return isVideoStreamingEnabled &&- computeController.computeState == ComputeRunState.generatingStream;+ computeController.computeState == ComputeRunState.generatingStream &&+ computeController.isDeviceHealthy;}void queueFiles({@@ -1191,7 +1201,11 @@ class VideoPreviewService {if (!isStreamAllowed) return;await _ensurePreviewIdsInitialized();- await _putFilesForPreviewCreation();+ final result = await _putFilesForPreviewCreation();+ // Cannot proceed to stream generation, would have to release compute ASAP+ if (!result) {+ computeController.releaseCompute(stream: true);+ }});}}