2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

505 lines
19 KiB

  1. // Generated by the announcer.rb DO NOT EDIT!!
  2. #import "SCManagedCapturerListenerAnnouncer.h"
  3. #include <mutex>
  4. using std::lock_guard;
  5. using std::mutex;
  6. #include <vector>
  7. using std::find;
  8. using std::make_shared;
  9. using std::shared_ptr;
  10. using std::vector;
  11. @implementation SCManagedCapturerListenerAnnouncer {
  12. mutex _mutex;
  13. shared_ptr<vector<__weak id<SCManagedCapturerListener>>> _listeners;
  14. }
  15. - (NSString *)description
  16. {
  17. auto listeners = atomic_load(&self->_listeners);
  18. NSMutableString *desc = [NSMutableString string];
  19. [desc appendFormat:@"<SCManagedCapturerListenerAnnouncer %p>: [", self];
  20. for (int i = 0; i < listeners->size(); ++i) {
  21. [desc appendFormat:@"%@", (*listeners)[i]];
  22. if (i != listeners->size() - 1) {
  23. [desc appendString:@", "];
  24. }
  25. }
  26. [desc appendString:@"]"];
  27. return desc;
  28. }
  29. - (BOOL)addListener:(id<SCManagedCapturerListener>)listener
  30. {
  31. lock_guard<mutex> lock(_mutex);
  32. auto listeners = make_shared<vector<__weak id<SCManagedCapturerListener>>>();
  33. if (_listeners != nil) {
  34. // The listener we want to add already exists
  35. if (find(_listeners->begin(), _listeners->end(), listener) != _listeners->end()) {
  36. return NO;
  37. }
  38. for (auto &one : *_listeners) {
  39. if (one != nil) {
  40. listeners->push_back(one);
  41. }
  42. }
  43. listeners->push_back(listener);
  44. atomic_store(&self->_listeners, listeners);
  45. } else {
  46. listeners->push_back(listener);
  47. atomic_store(&self->_listeners, listeners);
  48. }
  49. return YES;
  50. }
  51. - (void)removeListener:(id<SCManagedCapturerListener>)listener
  52. {
  53. lock_guard<mutex> lock(_mutex);
  54. if (_listeners == nil) {
  55. return;
  56. }
  57. // If the only item in the listener list is the one we want to remove, store it back to nil again
  58. if (_listeners->size() == 1 && (*_listeners)[0] == listener) {
  59. atomic_store(&self->_listeners, shared_ptr<vector<__weak id<SCManagedCapturerListener>>>());
  60. return;
  61. }
  62. auto listeners = make_shared<vector<__weak id<SCManagedCapturerListener>>>();
  63. for (auto &one : *_listeners) {
  64. if (one != nil && one != listener) {
  65. listeners->push_back(one);
  66. }
  67. }
  68. atomic_store(&self->_listeners, listeners);
  69. }
  70. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didStartRunning:(SCManagedCapturerState *)state
  71. {
  72. auto listeners = atomic_load(&self->_listeners);
  73. if (listeners) {
  74. for (id<SCManagedCapturerListener> listener : *listeners) {
  75. if ([listener respondsToSelector:@selector(managedCapturer:didStartRunning:)]) {
  76. [listener managedCapturer:managedCapturer didStartRunning:state];
  77. }
  78. }
  79. }
  80. }
  81. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didStopRunning:(SCManagedCapturerState *)state
  82. {
  83. auto listeners = atomic_load(&self->_listeners);
  84. if (listeners) {
  85. for (id<SCManagedCapturerListener> listener : *listeners) {
  86. if ([listener respondsToSelector:@selector(managedCapturer:didStopRunning:)]) {
  87. [listener managedCapturer:managedCapturer didStopRunning:state];
  88. }
  89. }
  90. }
  91. }
  92. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didResetFromRuntimeError:(SCManagedCapturerState *)state
  93. {
  94. auto listeners = atomic_load(&self->_listeners);
  95. if (listeners) {
  96. for (id<SCManagedCapturerListener> listener : *listeners) {
  97. if ([listener respondsToSelector:@selector(managedCapturer:didResetFromRuntimeError:)]) {
  98. [listener managedCapturer:managedCapturer didResetFromRuntimeError:state];
  99. }
  100. }
  101. }
  102. }
  103. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeState:(SCManagedCapturerState *)state
  104. {
  105. auto listeners = atomic_load(&self->_listeners);
  106. if (listeners) {
  107. for (id<SCManagedCapturerListener> listener : *listeners) {
  108. if ([listener respondsToSelector:@selector(managedCapturer:didChangeState:)]) {
  109. [listener managedCapturer:managedCapturer didChangeState:state];
  110. }
  111. }
  112. }
  113. }
  114. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeNightModeActive:(SCManagedCapturerState *)state
  115. {
  116. auto listeners = atomic_load(&self->_listeners);
  117. if (listeners) {
  118. for (id<SCManagedCapturerListener> listener : *listeners) {
  119. if ([listener respondsToSelector:@selector(managedCapturer:didChangeNightModeActive:)]) {
  120. [listener managedCapturer:managedCapturer didChangeNightModeActive:state];
  121. }
  122. }
  123. }
  124. }
  125. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangePortraitModeActive:(SCManagedCapturerState *)state
  126. {
  127. auto listeners = atomic_load(&self->_listeners);
  128. if (listeners) {
  129. for (id<SCManagedCapturerListener> listener : *listeners) {
  130. if ([listener respondsToSelector:@selector(managedCapturer:didChangePortraitModeActive:)]) {
  131. [listener managedCapturer:managedCapturer didChangePortraitModeActive:state];
  132. }
  133. }
  134. }
  135. }
  136. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeFlashActive:(SCManagedCapturerState *)state
  137. {
  138. auto listeners = atomic_load(&self->_listeners);
  139. if (listeners) {
  140. for (id<SCManagedCapturerListener> listener : *listeners) {
  141. if ([listener respondsToSelector:@selector(managedCapturer:didChangeFlashActive:)]) {
  142. [listener managedCapturer:managedCapturer didChangeFlashActive:state];
  143. }
  144. }
  145. }
  146. }
  147. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeLensesActive:(SCManagedCapturerState *)state
  148. {
  149. auto listeners = atomic_load(&self->_listeners);
  150. if (listeners) {
  151. for (id<SCManagedCapturerListener> listener : *listeners) {
  152. if ([listener respondsToSelector:@selector(managedCapturer:didChangeLensesActive:)]) {
  153. [listener managedCapturer:managedCapturer didChangeLensesActive:state];
  154. }
  155. }
  156. }
  157. }
  158. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeARSessionActive:(SCManagedCapturerState *)state
  159. {
  160. auto listeners = atomic_load(&self->_listeners);
  161. if (listeners) {
  162. for (id<SCManagedCapturerListener> listener : *listeners) {
  163. if ([listener respondsToSelector:@selector(managedCapturer:didChangeARSessionActive:)]) {
  164. [listener managedCapturer:managedCapturer didChangeARSessionActive:state];
  165. }
  166. }
  167. }
  168. }
  169. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  170. didChangeFlashSupportedAndTorchSupported:(SCManagedCapturerState *)state
  171. {
  172. auto listeners = atomic_load(&self->_listeners);
  173. if (listeners) {
  174. for (id<SCManagedCapturerListener> listener : *listeners) {
  175. if ([listener respondsToSelector:@selector(managedCapturer:didChangeFlashSupportedAndTorchSupported:)]) {
  176. [listener managedCapturer:managedCapturer didChangeFlashSupportedAndTorchSupported:state];
  177. }
  178. }
  179. }
  180. }
  181. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeZoomFactor:(SCManagedCapturerState *)state
  182. {
  183. auto listeners = atomic_load(&self->_listeners);
  184. if (listeners) {
  185. for (id<SCManagedCapturerListener> listener : *listeners) {
  186. if ([listener respondsToSelector:@selector(managedCapturer:didChangeZoomFactor:)]) {
  187. [listener managedCapturer:managedCapturer didChangeZoomFactor:state];
  188. }
  189. }
  190. }
  191. }
  192. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeLowLightCondition:(SCManagedCapturerState *)state
  193. {
  194. auto listeners = atomic_load(&self->_listeners);
  195. if (listeners) {
  196. for (id<SCManagedCapturerListener> listener : *listeners) {
  197. if ([listener respondsToSelector:@selector(managedCapturer:didChangeLowLightCondition:)]) {
  198. [listener managedCapturer:managedCapturer didChangeLowLightCondition:state];
  199. }
  200. }
  201. }
  202. }
  203. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeAdjustingExposure:(SCManagedCapturerState *)state
  204. {
  205. auto listeners = atomic_load(&self->_listeners);
  206. if (listeners) {
  207. for (id<SCManagedCapturerListener> listener : *listeners) {
  208. if ([listener respondsToSelector:@selector(managedCapturer:didChangeAdjustingExposure:)]) {
  209. [listener managedCapturer:managedCapturer didChangeAdjustingExposure:state];
  210. }
  211. }
  212. }
  213. }
  214. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeCaptureDevicePosition:(SCManagedCapturerState *)state
  215. {
  216. auto listeners = atomic_load(&self->_listeners);
  217. if (listeners) {
  218. for (id<SCManagedCapturerListener> listener : *listeners) {
  219. if ([listener respondsToSelector:@selector(managedCapturer:didChangeCaptureDevicePosition:)]) {
  220. [listener managedCapturer:managedCapturer didChangeCaptureDevicePosition:state];
  221. }
  222. }
  223. }
  224. }
  225. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  226. didChangeVideoPreviewLayer:(AVCaptureVideoPreviewLayer *)videoPreviewLayer
  227. {
  228. auto listeners = atomic_load(&self->_listeners);
  229. if (listeners) {
  230. for (id<SCManagedCapturerListener> listener : *listeners) {
  231. if ([listener respondsToSelector:@selector(managedCapturer:didChangeVideoPreviewLayer:)]) {
  232. [listener managedCapturer:managedCapturer didChangeVideoPreviewLayer:videoPreviewLayer];
  233. }
  234. }
  235. }
  236. }
  237. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeVideoPreviewGLView:(LSAGLView *)videoPreviewGLView
  238. {
  239. auto listeners = atomic_load(&self->_listeners);
  240. if (listeners) {
  241. for (id<SCManagedCapturerListener> listener : *listeners) {
  242. if ([listener respondsToSelector:@selector(managedCapturer:didChangeVideoPreviewGLView:)]) {
  243. [listener managedCapturer:managedCapturer didChangeVideoPreviewGLView:videoPreviewGLView];
  244. }
  245. }
  246. }
  247. }
  248. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  249. didBeginVideoRecording:(SCManagedCapturerState *)state
  250. session:(SCVideoCaptureSessionInfo)session
  251. {
  252. auto listeners = atomic_load(&self->_listeners);
  253. if (listeners) {
  254. for (id<SCManagedCapturerListener> listener : *listeners) {
  255. if ([listener respondsToSelector:@selector(managedCapturer:didBeginVideoRecording:session:)]) {
  256. [listener managedCapturer:managedCapturer didBeginVideoRecording:state session:session];
  257. }
  258. }
  259. }
  260. }
  261. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  262. didBeginAudioRecording:(SCManagedCapturerState *)state
  263. session:(SCVideoCaptureSessionInfo)session
  264. {
  265. auto listeners = atomic_load(&self->_listeners);
  266. if (listeners) {
  267. for (id<SCManagedCapturerListener> listener : *listeners) {
  268. if ([listener respondsToSelector:@selector(managedCapturer:didBeginAudioRecording:session:)]) {
  269. [listener managedCapturer:managedCapturer didBeginAudioRecording:state session:session];
  270. }
  271. }
  272. }
  273. }
  274. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  275. willFinishRecording:(SCManagedCapturerState *)state
  276. session:(SCVideoCaptureSessionInfo)session
  277. recordedVideoFuture:(SCFuture<id<SCManagedRecordedVideo>> *)recordedVideoFuture
  278. videoSize:(CGSize)videoSize
  279. placeholderImage:(UIImage *)placeholderImage
  280. {
  281. auto listeners = atomic_load(&self->_listeners);
  282. if (listeners) {
  283. for (id<SCManagedCapturerListener> listener : *listeners) {
  284. if ([listener respondsToSelector:@selector(managedCapturer:
  285. willFinishRecording:
  286. session:
  287. recordedVideoFuture:
  288. videoSize:
  289. placeholderImage:)]) {
  290. [listener managedCapturer:managedCapturer
  291. willFinishRecording:state
  292. session:session
  293. recordedVideoFuture:recordedVideoFuture
  294. videoSize:videoSize
  295. placeholderImage:placeholderImage];
  296. }
  297. }
  298. }
  299. }
  300. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  301. didFinishRecording:(SCManagedCapturerState *)state
  302. session:(SCVideoCaptureSessionInfo)session
  303. recordedVideo:(SCManagedRecordedVideo *)recordedVideo
  304. {
  305. auto listeners = atomic_load(&self->_listeners);
  306. if (listeners) {
  307. for (id<SCManagedCapturerListener> listener : *listeners) {
  308. if ([listener respondsToSelector:@selector(managedCapturer:didFinishRecording:session:recordedVideo:)]) {
  309. [listener managedCapturer:managedCapturer
  310. didFinishRecording:state
  311. session:session
  312. recordedVideo:recordedVideo];
  313. }
  314. }
  315. }
  316. }
  317. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  318. didFailRecording:(SCManagedCapturerState *)state
  319. session:(SCVideoCaptureSessionInfo)session
  320. error:(NSError *)error
  321. {
  322. auto listeners = atomic_load(&self->_listeners);
  323. if (listeners) {
  324. for (id<SCManagedCapturerListener> listener : *listeners) {
  325. if ([listener respondsToSelector:@selector(managedCapturer:didFailRecording:session:error:)]) {
  326. [listener managedCapturer:managedCapturer didFailRecording:state session:session error:error];
  327. }
  328. }
  329. }
  330. }
  331. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  332. didCancelRecording:(SCManagedCapturerState *)state
  333. session:(SCVideoCaptureSessionInfo)session
  334. {
  335. auto listeners = atomic_load(&self->_listeners);
  336. if (listeners) {
  337. for (id<SCManagedCapturerListener> listener : *listeners) {
  338. if ([listener respondsToSelector:@selector(managedCapturer:didCancelRecording:session:)]) {
  339. [listener managedCapturer:managedCapturer didCancelRecording:state session:session];
  340. }
  341. }
  342. }
  343. }
  344. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  345. didGetError:(NSError *)error
  346. forType:(SCManagedVideoCapturerInfoType)type
  347. session:(SCVideoCaptureSessionInfo)session
  348. {
  349. auto listeners = atomic_load(&self->_listeners);
  350. if (listeners) {
  351. for (id<SCManagedCapturerListener> listener : *listeners) {
  352. if ([listener respondsToSelector:@selector(managedCapturer:didGetError:forType:session:)]) {
  353. [listener managedCapturer:managedCapturer didGetError:error forType:type session:session];
  354. }
  355. }
  356. }
  357. }
  358. - (void)managedCapturerDidCallLenseResume:(id<SCCapturer>)managedCapturer session:(SCVideoCaptureSessionInfo)session
  359. {
  360. auto listeners = atomic_load(&self->_listeners);
  361. if (listeners) {
  362. for (id<SCManagedCapturerListener> listener : *listeners) {
  363. if ([listener respondsToSelector:@selector(managedCapturerDidCallLenseResume:session:)]) {
  364. [listener managedCapturerDidCallLenseResume:managedCapturer session:session];
  365. }
  366. }
  367. }
  368. }
  369. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  370. didAppendVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer
  371. sampleMetadata:(SCManagedCapturerSampleMetadata *)sampleMetadata
  372. {
  373. auto listeners = atomic_load(&self->_listeners);
  374. if (listeners) {
  375. for (id<SCManagedCapturerListener> listener : *listeners) {
  376. if ([listener respondsToSelector:@selector(managedCapturer:didAppendVideoSampleBuffer:sampleMetadata:)]) {
  377. [listener managedCapturer:managedCapturer
  378. didAppendVideoSampleBuffer:sampleBuffer
  379. sampleMetadata:sampleMetadata];
  380. }
  381. }
  382. }
  383. }
  384. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  385. willCapturePhoto:(SCManagedCapturerState *)state
  386. sampleMetadata:(SCManagedCapturerSampleMetadata *)sampleMetadata
  387. {
  388. auto listeners = atomic_load(&self->_listeners);
  389. if (listeners) {
  390. for (id<SCManagedCapturerListener> listener : *listeners) {
  391. if ([listener respondsToSelector:@selector(managedCapturer:willCapturePhoto:sampleMetadata:)]) {
  392. [listener managedCapturer:managedCapturer willCapturePhoto:state sampleMetadata:sampleMetadata];
  393. }
  394. }
  395. }
  396. }
  397. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didCapturePhoto:(SCManagedCapturerState *)state
  398. {
  399. auto listeners = atomic_load(&self->_listeners);
  400. if (listeners) {
  401. for (id<SCManagedCapturerListener> listener : *listeners) {
  402. if ([listener respondsToSelector:@selector(managedCapturer:didCapturePhoto:)]) {
  403. [listener managedCapturer:managedCapturer didCapturePhoto:state];
  404. }
  405. }
  406. }
  407. }
  408. - (BOOL)managedCapturer:(id<SCCapturer>)managedCapturer isUnderDeviceMotion:(SCManagedCapturerState *)state
  409. {
  410. auto listeners = atomic_load(&self->_listeners);
  411. if (listeners) {
  412. for (id<SCManagedCapturerListener> listener : *listeners) {
  413. if ([listener respondsToSelector:@selector(managedCapturer:didCapturePhoto:)]) {
  414. return [listener managedCapturer:managedCapturer isUnderDeviceMotion:state];
  415. }
  416. }
  417. }
  418. return NO;
  419. }
  420. - (BOOL)managedCapturer:(id<SCCapturer>)managedCapturer shouldProcessFileInput:(SCManagedCapturerState *)state
  421. {
  422. auto listeners = atomic_load(&self->_listeners);
  423. if (listeners) {
  424. for (id<SCManagedCapturerListener> listener : *listeners) {
  425. if ([listener respondsToSelector:@selector(managedCapturer:didCapturePhoto:)]) {
  426. return [listener managedCapturer:managedCapturer isUnderDeviceMotion:state];
  427. }
  428. }
  429. }
  430. return NO;
  431. }
  432. - (void)managedCapturer:(id<SCCapturer>)managedCapturer
  433. didDetectFaceBounds:(NSDictionary<NSNumber *, NSValue *> *)faceBoundsByFaceID
  434. {
  435. auto listeners = atomic_load(&self->_listeners);
  436. if (listeners) {
  437. for (id<SCManagedCapturerListener> listener : *listeners) {
  438. if ([listener respondsToSelector:@selector(managedCapturer:didDetectFaceBounds:)]) {
  439. [listener managedCapturer:managedCapturer didDetectFaceBounds:faceBoundsByFaceID];
  440. }
  441. }
  442. }
  443. }
  444. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeExposurePoint:(CGPoint)exposurePoint
  445. {
  446. auto listeners = atomic_load(&self->_listeners);
  447. if (listeners) {
  448. for (id<SCManagedCapturerListener> listener : *listeners) {
  449. if ([listener respondsToSelector:@selector(managedCapturer:didChangeExposurePoint:)]) {
  450. [listener managedCapturer:managedCapturer didChangeExposurePoint:exposurePoint];
  451. }
  452. }
  453. }
  454. }
  455. - (void)managedCapturer:(id<SCCapturer>)managedCapturer didChangeFocusPoint:(CGPoint)focusPoint
  456. {
  457. auto listeners = atomic_load(&self->_listeners);
  458. if (listeners) {
  459. for (id<SCManagedCapturerListener> listener : *listeners) {
  460. if ([listener respondsToSelector:@selector(managedCapturer:didChangeFocusPoint:)]) {
  461. [listener managedCapturer:managedCapturer didChangeFocusPoint:focusPoint];
  462. }
  463. }
  464. }
  465. }
  466. @end