diff --git a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart index 81a0d91b4d..90ad9401ed 100644 --- a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart +++ b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart @@ -70,10 +70,14 @@ class ComputeController { _logger.info('init done '); } - bool requestCompute({bool ml = false, bool stream = false}) { - _logger.info("Requesting compute: ml: $ml, stream: $stream"); - if (!_isDeviceHealthy || !_canRunGivenUserInteraction()) { - _logger.info("Device not healthy or user interacting, denying request."); + bool requestCompute({bool ml = false, bool stream = false, bool bypassInteractionCheck = false}) { + _logger.info("Requesting compute: ml: $ml, stream: $stream, bypassInteraction: $bypassInteractionCheck"); + if (!_isDeviceHealthy) { + _logger.info("Device not healthy, denying request."); + return false; + } + if (!bypassInteractionCheck && !_canRunGivenUserInteraction()) { + _logger.info("User interacting, denying request."); return false; } bool result = false; diff --git a/mobile/apps/photos/lib/services/video_preview_service.dart b/mobile/apps/photos/lib/services/video_preview_service.dart index c7d3abd982..5b7113f3dd 100644 --- a/mobile/apps/photos/lib/services/video_preview_service.dart +++ b/mobile/apps/photos/lib/services/video_preview_service.dart @@ -131,7 +131,7 @@ class VideoPreviewService { // Start processing if not already processing if (uploadingFileId < 0) { - queueFiles(duration: Duration.zero); + queueFiles(duration: Duration.zero, isManual: true); } else { _items[file.uploadedFileID!] = PreviewItem( status: PreviewItemStatus.inQueue, @@ -252,13 +252,15 @@ class VideoPreviewService { BuildContext? ctx, EnteFile enteFile, [ bool forceUpload = false, + bool isManual = false, ]) async { - if (!_allowStream()) { + final canStream = isManual ? _allowManualStream() : _allowStream(); + if (!canStream) { _logger.info( - "Pause preview due to disabledSteaming($isVideoStreamingEnabled) or computeController permission)", + "Pause preview due to disabledSteaming($isVideoStreamingEnabled) or computeController permission) - isManual: $isManual", ); if (isVideoStreamingEnabled) _logger.info("No permission to run compute"); - clearQueue(); + if (!isManual) clearQueue(); // Only clear queue for automatic processing return; } @@ -1124,11 +1126,16 @@ class VideoPreviewService { computeController.requestCompute(stream: true); } - void queueFiles({Duration duration = const Duration(seconds: 5)}) { + bool _allowManualStream() { + return isVideoStreamingEnabled && + computeController.requestCompute(stream: true, bypassInteractionCheck: true); + } + + void queueFiles({Duration duration = const Duration(seconds: 5), bool isManual = false}) { Future.delayed(duration, () async { if (_hasQueuedFile) return; - final isStreamAllowed = _allowStream(); + final isStreamAllowed = isManual ? _allowManualStream() : _allowStream(); if (!isStreamAllowed) return; await _ensurePreviewIdsInitialized();