From 4e5a6721eb79f369923e9799dbef378fa1c7000d Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 2 Jul 2020 19:19:30 +0300 Subject: [PATCH] Video avatar fixes --- .../TGPhotoEditorTabController.h | 1 + .../LegacyComponents/Sources/PGPhotoEditor.m | 1 - .../Sources/TGPhotoAvatarCropView.m | 8 +++- .../Sources/TGPhotoAvatarPreviewController.m | 31 +++++++++----- .../Sources/TGPhotoEditorController.m | 40 ++++++++++++++----- .../Sources/TGPhotoEditorTabController.m | 5 +++ .../Sources/MediaTrackFrameBuffer.swift | 2 +- 7 files changed, 66 insertions(+), 22 deletions(-) diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h index d62573d6e4..7ee9d2b520 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h @@ -44,6 +44,7 @@ - (void)prepareTransitionOutSaving:(bool)saving; - (void)prepareForCustomTransitionOut; +- (void)finishCustomTransitionOut; - (void)animateTransitionIn; - (CGRect)_targetFrameForTransitionInFromFrame:(CGRect)fromFrame; diff --git a/submodules/LegacyComponents/Sources/PGPhotoEditor.m b/submodules/LegacyComponents/Sources/PGPhotoEditor.m index 52adf9807e..43b7bddd9e 100644 --- a/submodules/LegacyComponents/Sources/PGPhotoEditor.m +++ b/submodules/LegacyComponents/Sources/PGPhotoEditor.m @@ -484,7 +484,6 @@ [_finalFilter addTarget:self.previewOutput.imageView]; } } - if (_histogramGenerator != nil && !self.standalone) { [_finalFilter addTarget:_histogramGenerator]; diff --git a/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m b/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m index f4e8464753..7666ec7bb6 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m +++ b/submodules/LegacyComponents/Sources/TGPhotoAvatarCropView.m @@ -41,7 +41,7 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200; CGFloat _currentDiameter; - PGPhotoEditorView *_fullPreviewView; + __weak PGPhotoEditorView *_fullPreviewView; } @end @@ -84,7 +84,6 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200; _fullPreviewView.userInteractionEnabled = false; [_wrapperView addSubview:_fullPreviewView]; - _flashView = [[UIView alloc] init]; _flashView.alpha = 0.0; _flashView.backgroundColor = [UIColor whiteColor]; @@ -131,6 +130,11 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200; return self; } +- (void)dealloc +{ + _scrollView.delegate = nil; +} + - (void)handleTap:(UITapGestureRecognizer *)gestureRecognizer { if (self.tapped != nil) self.tapped(); diff --git a/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m b/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m index 6a8ef026f6..c83846c005 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m @@ -32,7 +32,7 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel UIView *_wrapperView; - TGPhotoAvatarCropView *_cropView; + __weak TGPhotoAvatarCropView *_cropView; UIView *_portraitToolsWrapperView; UIView *_landscapeToolsWrapperView; @@ -63,6 +63,10 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel return self; } +- (void)dealloc { + NSLog(@""); +} + - (void)loadView { [super loadView]; @@ -80,7 +84,7 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel if (strongSelf == nil) return; - self.controlVideoPlayback(false); + strongSelf.controlVideoPlayback(false); }; void(^interactionEnded)(void) = ^ { @@ -91,11 +95,12 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel if ([strongSelf shouldAutorotate]) [TGViewController attemptAutorotation]; - self.controlVideoPlayback(true); + strongSelf.controlVideoPlayback(true); }; PGPhotoEditor *photoEditor = self.photoEditor; - _cropView = [[TGPhotoAvatarCropView alloc] initWithOriginalSize:photoEditor.originalSize screenSize:[self referenceViewSize] fullPreviewView:_fullPreviewView]; + TGPhotoAvatarCropView *cropView = [[TGPhotoAvatarCropView alloc] initWithOriginalSize:photoEditor.originalSize screenSize:[self referenceViewSize] fullPreviewView:_fullPreviewView]; + _cropView = cropView; [_cropView setCropRect:photoEditor.cropRect]; [_cropView setCropOrientation:photoEditor.cropOrientation]; [_cropView setCropMirrored:photoEditor.cropMirrored]; @@ -132,7 +137,7 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel } _cropView.interactionBegan = interactionBegan; _cropView.interactionEnded = interactionEnded; - [_wrapperView addSubview:_cropView]; + [_wrapperView addSubview:cropView]; _portraitToolsWrapperView = [[UIView alloc] initWithFrame:CGRectZero]; [_wrapperView addSubview:_portraitToolsWrapperView]; @@ -371,6 +376,7 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel _cropView.transform = CGAffineTransformMakeScale(targetCropViewScale, targetCropViewScale); } completion:^(__unused BOOL finished) { + [_cropView removeFromSuperview]; _previewView.alpha = 1.0; if (self.finishedTransitionOut != nil) self.finishedTransitionOut(); @@ -378,8 +384,9 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel if (completion != nil) completion(); }]; - } else if (self.fromCamera) { - _previewView.alpha = 0.0f; + } else { + if (self.fromCamera) + _previewView.alpha = 0.0f; } switch (self.effectiveOrientation) @@ -426,6 +433,7 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel } completion:^(__unused BOOL finished) { if (!switching) { + [_cropView removeFromSuperview]; if (completion != nil) completion(); } @@ -533,12 +541,17 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel } completion:nil]; } +- (void)finishCustomTransitionOut +{ + [_cropView removeFromSuperview]; +} + - (CGRect)transitionOutReferenceFrame { if (_dismissingToCamera) { - return _fullPreviewView.frame; + return [_fullPreviewView.superview convertRect:_fullPreviewView.frame toView:self.view]; } else { - return _previewView.frame; + return [_wrapperView convertRect:_cropView.frame toView:self.view]; } } diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 4782b260ac..7320b06218 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -564,6 +564,9 @@ if (strongSelf->_ignoreDefaultPreviewViewTransitionIn) { + __strong TGPhotoEditorController *strongSelf = weakSelf; + if (strongSelf == nil) + return; TGDispatchOnMainThread(^ { if (strongSelf->_dismissed) @@ -578,6 +581,9 @@ { [photoEditor processAnimated:false completion:^ { + __strong TGPhotoEditorController *strongSelf = weakSelf; + if (strongSelf == nil) + return; TGDispatchOnMainThread(^ { if (strongSelf->_dismissed) @@ -1093,7 +1099,13 @@ rep = imageView; } [_currentTabController prepareForCustomTransitionOut]; - self.beginCustomTransitionOut([_currentTabController transitionOutReferenceFrame], rep, completion); + + TGPhotoEditorTabController *tabController = _currentTabController; + self.beginCustomTransitionOut([_currentTabController transitionOutReferenceFrame], rep, ^{ + [tabController finishCustomTransitionOut]; + if (completion) + completion(); + }); } else { @@ -1128,6 +1140,8 @@ { if (![currentController isDismissAllowed]) return; + + [self savePaintingData]; currentController.switchingToTab = tab; [currentController transitionOutSwitching:true completion:^ @@ -1643,6 +1657,7 @@ self.view.frame = targetFrame; } completion:^(__unused BOOL finished) { + [_currentTabController finishCustomTransitionOut]; if (self.navigationController != nil) { [self.navigationController popViewControllerAnimated:false]; } else { @@ -1653,6 +1668,7 @@ else { if (self.navigationController != nil) { + [_currentTabController finishCustomTransitionOut]; [self.navigationController popViewControllerAnimated:false]; } else { [self dismiss]; @@ -1767,6 +1783,18 @@ } } +- (void)savePaintingData { + if (![_currentTabController isKindOfClass:[TGPhotoPaintController class]]) + return; + + TGPhotoPaintController *paintController = (TGPhotoPaintController *)_currentTabController; + TGPaintingData *paintingData = [paintController paintingData]; + _photoEditor.paintingData = paintingData; + + if (paintingData != nil) + [TGPaintingData storePaintingData:paintingData inContext:self.editingContext forItem:_item forVideo:(_intent == TGPhotoEditorControllerVideoIntent)]; +} + - (void)applyEditor { if (![_currentTabController isDismissAllowed]) @@ -1775,8 +1803,6 @@ self.view.userInteractionEnabled = false; [_currentTabController prepareTransitionOutSaving:true]; - TGPaintingData *paintingData = _photoEditor.paintingData; - bool saving = true; NSTimeInterval videoStartValue = 0.0; NSTimeInterval trimStartValue = 0.0; @@ -1784,12 +1810,7 @@ if ([_currentTabController isKindOfClass:[TGPhotoPaintController class]]) { - TGPhotoPaintController *paintController = (TGPhotoPaintController *)_currentTabController; - paintingData = [paintController paintingData]; - _photoEditor.paintingData = paintingData; - - if (paintingData != nil) - [TGPaintingData storePaintingData:paintingData inContext:self.editingContext forItem:_item forVideo:(_intent == TGPhotoEditorControllerVideoIntent)]; + [self savePaintingData]; } else if ([_currentTabController isKindOfClass:[TGPhotoQualityController class]]) { @@ -1807,6 +1828,7 @@ [self stopVideoPlayback:true]; + TGPaintingData *paintingData = _photoEditor.paintingData; TGVideoEditAdjustments *adjustments = [_photoEditor exportAdjustmentsWithPaintingData:paintingData]; if ([self presentedForAvatarCreation] && _item.isVideo) { [[SQueue concurrentDefaultQueue] dispatch:^ diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m index fe77eecf29..1f5a122725 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m @@ -215,6 +215,11 @@ const CGFloat TGPhotoEditorToolbarSize = 49.0f; } +- (void)finishCustomTransitionOut +{ + +} + - (void)transitionOutSwitching:(bool)__unused switching completion:(void (^)(void))__unused completion { diff --git a/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift b/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift index 210fc7ab2a..598ae2be68 100644 --- a/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift +++ b/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift @@ -161,7 +161,7 @@ public final class MediaTrackFrameBuffer { if self.endOfStream, let decodedFrame = self.decoder.takeRemainingFrame() { return .frame(decodedFrame) } else { - if let bufferedUntilTime = bufferedUntilTime { + if let bufferedUntilTime = self.bufferedUntilTime { if CMTimeCompare(bufferedUntilTime, self.duration) >= 0 || self.endOfStream { return .finished }