OperationNodeVideoBase.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // OperationNodeVideoBase.m
  3. // LenzCameraNativeModuleForRN
  4. //
  5. // Created by 王昭威 on 2023/1/25.
  6. //
  7. #import "PCSBaseViewController.h"
  8. #import "OperationNodeVideoBase.h"
  9. #import "PCSRoundButton.h"
  10. #import "TimerLabel.h"
  11. #import "PCSModeList.h"
  12. #import "PanoramaGuideView.h"
  13. #import "SVProgressHUD.h"
  14. @interface OperationNodeVideoBase()
  15. @property (nonatomic) dispatch_source_t stitchTimer;
  16. @end
  17. @implementation OperationNodeVideoBase
  18. - (instancetype)initWithController:(PCSBaseViewController *)controller{
  19. self = [super init];
  20. if(self){
  21. _controller = controller;
  22. _isRecording = NO;
  23. }
  24. return self;
  25. }
  26. #pragma mark - strategy
  27. - (void)discardPhotoResultButtonTouchUpInside{
  28. [self cleanOnCompleted:^{
  29. [self.controller dismissViewControllerAnimated:YES completion:^{}];
  30. }];
  31. }
  32. - (BOOL)start{
  33. return YES;
  34. }
  35. - (void)stop{
  36. self.isRecording = NO;
  37. [self updateButtonStatusByCurrentRecordingState];
  38. }
  39. #pragma mark - button
  40. - (void)takePhotoButtonTouched{
  41. BOOL updatedRecording = !self.isRecording;
  42. self.controller.isVideoStitchStopedWhenRecording = NO;
  43. self.isRecording = updatedRecording && [self start];
  44. if(self.isRecording){
  45. if (self.controller.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  46. self.controller.panoramaGuideView.hidden = NO;
  47. }
  48. if ([self.controller.panoramOrientationGuideView.delegate respondsToSelector:@selector(panoramDirDidChange)]) {
  49. [self.controller.panoramOrientationGuideView.delegate panoramDirDidChange];
  50. }
  51. }
  52. self.controller.panGesture.enabled = !self.isRecording;
  53. self.controller.timerLabel.backgroundColor = !self.isRecording ? [UIColor clearColor] : [PCSThemeColorManager orange];
  54. [self updateTakePhotoButtonStatus];
  55. if(!self.isRecording){
  56. if (self.stitchResult != LenVideoStitchResultStitchFail && self.stitchResult != LenVideoStitchResultFail) {
  57. self.controller.isVideoStitchStopedWhenRecording = YES;
  58. } else {
  59. self.controller.isVideoStitchStopedWhenRecording = NO;
  60. }
  61. [self updateButtonStatusByCurrentRecordingState];
  62. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  63. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  64. [self stop];
  65. });
  66. } else {
  67. [self stop];
  68. }
  69. }
  70. else{
  71. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  72. [self.controller.timerLabel updateWith:0];
  73. self.controller.timerLabel.padding = UIEdgeInsetsMake(0, 2.5, 0, 2.5);
  74. self.stitchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
  75. uint64_t duration = (uint64_t)(1.0 * NSEC_PER_SEC);
  76. __block NSInteger count = 0;
  77. dispatch_source_set_timer(self.stitchTimer, DISPATCH_TIME_NOW, duration, 0 * NSEC_PER_SEC);
  78. dispatch_source_set_event_handler(self.stitchTimer, ^{
  79. dispatch_async(dispatch_get_main_queue(), ^{
  80. if (!self.isRecording) {
  81. dispatch_source_cancel(self.stitchTimer);
  82. self.controller.timerLabel.hidden = YES;
  83. self.controller.modeLabel.hidden = NO;
  84. return;
  85. }
  86. if (self.recTime == 0 || count <= self.recTime) {
  87. self.controller.timerLabel.backgroundColor = [PCSThemeColorManager orange];
  88. [self.controller.timerLabel updateWith:count];
  89. self.controller.timerLabel.hidden = NO;
  90. self.controller.modeLabel.hidden = YES;
  91. self.controller.flashButton.hidden = YES;
  92. self.controller.ai_fullView.hidden = YES;
  93. self.controller.panoramOrientationGuideView.hidden = YES;
  94. count++;
  95. } else {
  96. [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"超过最大拼接时长,拼接结束"];
  97. self.controller.timerLabel.backgroundColor = [UIColor clearColor];
  98. [self.controller.timerLabel updateWith:0];
  99. self.controller.timerLabel.hidden = YES;
  100. self.controller.modeLabel.hidden = NO;
  101. self.controller.flashButton.hidden = NO;
  102. self.controller.ai_fullView.hidden = NO;
  103. self.controller.panoramOrientationGuideView.hidden = NO;
  104. self.controller.isVideoStitchStopedWhenRecording = YES;
  105. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  106. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  107. dispatch_source_cancel(self.stitchTimer);
  108. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  109. [self stop];
  110. [self.controller stopVideoDataOutputing];
  111. });
  112. [SVProgressHUD dismissWithDelay:3 completion:^{
  113. }];
  114. }
  115. });
  116. });
  117. dispatch_resume(self.stitchTimer);
  118. }
  119. [self updateUI];
  120. }
  121. }
  122. - (void)updateUI{
  123. }
  124. #pragma mark - update UI
  125. - (void)updateButtonStatusByCurrentRecordingState{
  126. dispatch_async(dispatch_get_main_queue(), ^{
  127. self.controller.timerLabel.hidden = YES;
  128. self.controller.modeLabel.hidden = NO;
  129. });
  130. }
  131. #pragma mark - Accessor
  132. - (void)updateTakePhotoButtonStatus {
  133. dispatch_async(dispatch_get_main_queue(), ^{
  134. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  135. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  136. if (!self.isRecording) {
  137. [self.controller.timerLabel updateWith:0];
  138. self.controller.flashButton.hidden = NO;
  139. self.controller.discardPhotoButton.hidden = NO;
  140. self.controller.savePhotoButton.hidden = NO;
  141. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  142. self.controller.switchButton.hidden = YES;
  143. } else {
  144. self.controller.switchButton.hidden = NO;
  145. }
  146. self.controller.modeList.hidden = NO;
  147. self.controller.ablumImageView.hidden = NO;
  148. } else {
  149. self.controller.flashButton.hidden = YES;
  150. self.controller.discardPhotoButton.hidden = YES;
  151. self.controller.savePhotoButton.hidden = YES;
  152. self.controller.switchButton.hidden = YES;
  153. self.controller.backButton.hidden = YES;
  154. self.controller.modeList.hidden = YES;
  155. self.controller.ablumImageView.hidden = YES;
  156. self.controller.numberOfImagesLabel.hidden = YES;
  157. }
  158. });
  159. }
  160. @end