OperationNodeVideoBase.m 7.2 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. self.controller.isVideoStitchStopedWhenRecording = YES;
  57. [self updateButtonStatusByCurrentRecordingState];
  58. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  59. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  60. [self stop];
  61. });
  62. } else {
  63. [self stop];
  64. }
  65. }
  66. else{
  67. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  68. [self.controller.timerLabel updateWith:0];
  69. self.controller.timerLabel.padding = UIEdgeInsetsMake(0, 2.5, 0, 2.5);
  70. self.stitchTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
  71. uint64_t duration = (uint64_t)(1.0 * NSEC_PER_SEC);
  72. __block NSInteger count = 0;
  73. dispatch_source_set_timer(self.stitchTimer, DISPATCH_TIME_NOW, duration, 0 * NSEC_PER_SEC);
  74. dispatch_source_set_event_handler(self.stitchTimer, ^{
  75. dispatch_async(dispatch_get_main_queue(), ^{
  76. if (!self.isRecording) {
  77. dispatch_source_cancel(self.stitchTimer);
  78. self.controller.timerLabel.hidden = YES;
  79. self.controller.modeLabel.hidden = NO;
  80. return;
  81. }
  82. if (self.recTime == 0 || count <= self.recTime) {
  83. self.controller.timerLabel.backgroundColor = [PCSThemeColorManager orange];
  84. [self.controller.timerLabel updateWith:count];
  85. self.controller.timerLabel.hidden = NO;
  86. self.controller.modeLabel.hidden = YES;
  87. self.controller.flashButton.hidden = YES;
  88. self.controller.ai_fullView.hidden = YES;
  89. self.controller.panoramOrientationGuideView.hidden = YES;
  90. count++;
  91. } else {
  92. [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"超过最大拼接时长,拼接结束"];
  93. self.controller.timerLabel.backgroundColor = [UIColor clearColor];
  94. [self.controller.timerLabel updateWith:0];
  95. self.controller.timerLabel.hidden = YES;
  96. self.controller.modeLabel.hidden = NO;
  97. self.controller.flashButton.hidden = NO;
  98. self.controller.ai_fullView.hidden = NO;
  99. self.controller.panoramOrientationGuideView.hidden = NO;
  100. self.controller.isVideoStitchStopedWhenRecording = YES;
  101. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  102. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  103. dispatch_source_cancel(self.stitchTimer);
  104. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  105. [self stop];
  106. [self.controller stopVideoDataOutputing];
  107. });
  108. [SVProgressHUD dismissWithDelay:3 completion:^{
  109. }];
  110. }
  111. });
  112. });
  113. dispatch_resume(self.stitchTimer);
  114. }
  115. [self updateUI];
  116. }
  117. }
  118. - (void)updateUI{
  119. }
  120. #pragma mark - update UI
  121. - (void)updateButtonStatusByCurrentRecordingState{
  122. dispatch_async(dispatch_get_main_queue(), ^{
  123. self.controller.timerLabel.hidden = YES;
  124. self.controller.modeLabel.hidden = NO;
  125. });
  126. }
  127. #pragma mark - Accessor
  128. - (void)updateTakePhotoButtonStatus {
  129. UIImage* img = self.isRecording ? [UIImage loadNamed:@"btn-stop-recording"] : [UIImage loadNamed:@"take-photo-btn"];
  130. if (!NSThread.isMainThread) {
  131. dispatch_async(dispatch_get_main_queue(), ^{
  132. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  133. });
  134. } else {
  135. [self.controller.takePhotoButton setImage:img forState:UIControlStateNormal];
  136. }
  137. if (!self.isRecording) {
  138. [self.controller.timerLabel updateWith:0];
  139. self.controller.flashButton.hidden = NO;
  140. self.controller.discardPhotoButton.hidden = NO;
  141. self.controller.savePhotoButton.hidden = NO;
  142. if (self.modeIndex == SDK_CAPTURE_MODE_PANORAMA || self.modeIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  143. self.controller.switchButton.hidden = YES;
  144. } else {
  145. self.controller.switchButton.hidden = NO;
  146. }
  147. self.controller.modeList.hidden = NO;
  148. self.controller.ablumImageView.hidden = NO;
  149. } else {
  150. self.controller.flashButton.hidden = YES;
  151. self.controller.discardPhotoButton.hidden = YES;
  152. self.controller.savePhotoButton.hidden = YES;
  153. self.controller.switchButton.hidden = YES;
  154. self.controller.backButton.hidden = YES;
  155. self.controller.modeList.hidden = YES;
  156. self.controller.ablumImageView.hidden = YES;
  157. self.controller.numberOfImagesLabel.hidden = YES;
  158. }
  159. }
  160. @end