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.

377 lines
15 KiB

  1. //
  2. // SCCameraTweaks.h
  3. // Snapchat
  4. //
  5. // Created by Liu Liu on 9/16/15.
  6. // Copyright © 2015 Snapchat, Inc. All rights reserved.
  7. //
  8. #import <SCBase/SCMacros.h>
  9. #import <SCCameraFoundation/SCManagedCaptureDevicePosition.h>
  10. #import <SCTweakAdditions/SCTweakDefines.h>
  11. #import <Tweaks/FBTweakInline.h>
  12. #import <CoreGraphics/CoreGraphics.h>
  13. #import <Foundation/Foundation.h>
  14. // Core Camera
  15. typedef NS_ENUM(NSUInteger, SCManagedCaptureDeviceZoomHandlerType) {
  16. SCManagedCaptureDeviceDefaultZoom,
  17. SCManagedCaptureDeviceSavitzkyGolayFilter,
  18. SCManagedCaptureDeviceLinearInterpolation,
  19. };
  20. typedef NS_ENUM(NSUInteger, SCCameraTweaksStrategyType) {
  21. SCCameraTweaksStrategyFollowABTest = 0,
  22. SCCameraTweaksStrategyOverrideToYes,
  23. SCCameraTweaksStrategyOverrideToNo
  24. };
  25. typedef NS_ENUM(NSUInteger, SCCameraHandsFreeModeType) {
  26. SCCameraHandsFreeModeTypeABTest = 0,
  27. SCCameraHandsFreeModeTypeDisabled,
  28. SCCameraHandsFreeModeTypeMainOnly,
  29. SCCameraHandsFreeModeTypeChatMoveCaptureButton,
  30. SCCameraHandsFreeModeTypeMainAndChat,
  31. SCCameraHandsFreeModeTypeLeftOfCapture,
  32. };
  33. /// Face detection and focus strategy in Tweak. There are less options in internal Tweaks than the A/B testing
  34. /// strategies.
  35. typedef NS_ENUM(NSUInteger, SCCameraFaceFocusModeStrategyType) {
  36. SCCameraFaceFocusModeStrategyTypeABTest = 0,
  37. SCCameraFaceFocusModeStrategyTypeDisabled, // Disabled for both cameras.
  38. SCCameraFaceFocusModeStrategyTypeOffByDefault, // Enabled for both cameras, but is off by default.
  39. SCCameraFaceFocusModeStrategyTypeOnByDefault, // Enabled for both cameras, but is off by default.
  40. };
  41. typedef NS_ENUM(NSUInteger, SCCameraFaceFocusDetectionMethodType) {
  42. SCCameraFaceFocusDetectionMethodTypeABTest = 0,
  43. SCCameraFaceFocusDetectionMethodTypeCIDetector, // Use SCCaptureCoreImageFaceDetector
  44. SCCameraFaceFocusDetectionMethodTypeAVMetadata, // Use SCCaptureMetadataOutputDetector
  45. };
  46. SC_EXTERN_C_BEGIN
  47. extern SCManagedCaptureDeviceZoomHandlerType SCCameraTweaksDeviceZoomHandlerStrategy(void);
  48. extern BOOL SCCameraTweaksBlackCameraRecoveryEnabled(void);
  49. extern BOOL SCCameraTweaksMicPermissionEnabled(void);
  50. extern BOOL SCCameraTweaksEnableCaptureKeepRecordedVideo(void);
  51. extern BOOL SCCameraTweaksEnableHandsFreeXToCancel(void);
  52. extern SCCameraHandsFreeModeType SCCameraTweaksHandsFreeMode(void);
  53. BOOL SCCameraTweaksEnableShortPreviewTransitionAnimationDuration(void);
  54. extern BOOL SCCameraTweaksEnablePreviewPresenterFastPreview(void);
  55. extern BOOL SCCameraTweaksEnableCaptureSharePerformer(void);
  56. extern BOOL SCCameraTweaksEnableFaceDetectionFocus(SCManagedCaptureDevicePosition captureDevicePosition);
  57. extern BOOL SCCameraTweaksTurnOnFaceDetectionFocusByDefault(SCManagedCaptureDevicePosition captureDevicePosition);
  58. extern SCCameraFaceFocusDetectionMethodType SCCameraFaceFocusDetectionMethod(void);
  59. extern CGFloat SCCameraFaceFocusMinFaceSize(void);
  60. extern BOOL SCCameraTweaksSessionLightWeightFixEnabled(void);
  61. SC_EXTERN_C_END
  62. static inline BOOL SCCameraTweaksEnableVideoStabilization(void)
  63. {
  64. return FBTweakValue(@"Camera", @"Core Camera", @"Enable video stabilization", NO);
  65. }
  66. static inline BOOL SCCameraTweaksEnableForceTouchToToggleCamera(void)
  67. {
  68. return FBTweakValue(@"Camera", @"Recording", @"Force Touch to Toggle", NO);
  69. }
  70. static inline BOOL SCCameraTweaksEnableStayOnCameraAfterPostingStory(void)
  71. {
  72. return FBTweakValue(@"Camera", @"Story", @"Stay on camera after posting", NO);
  73. }
  74. static inline BOOL SCCameraTweaksEnableKeepLastFrameOnCamera(void)
  75. {
  76. return FBTweakValue(@"Camera", @"Core Camera", @"Keep last frame on camera", YES);
  77. }
  78. static inline BOOL SCCameraTweaksSmoothAutoFocusWhileRecording(void)
  79. {
  80. return FBTweakValue(@"Camera", @"Core Camera", @"Smooth autofocus while recording", YES);
  81. }
  82. static inline NSInteger SCCameraExposureAdjustmentMode(void)
  83. {
  84. return [FBTweakValue(
  85. @"Camera", @"Core Camera", @"Adjust Exposure", (id) @0,
  86. (@{ @0 : @"NO",
  87. @1 : @"Dynamic enhancement",
  88. @2 : @"Night vision",
  89. @3 : @"Inverted night vision" })) integerValue];
  90. }
  91. static inline BOOL SCCameraTweaksRotateToggleCameraButton(void)
  92. {
  93. return SCTweakValueWithHalt(@"Camera", @"Core Camera", @"Rotate Toggle-Camera Button", NO);
  94. }
  95. static inline CGFloat SCCameraTweaksRotateToggleCameraButtonTime(void)
  96. {
  97. return FBTweakValue(@"Camera", @"Core Camera", @"Toggle-Camera Button Rotation Time", 0.3);
  98. }
  99. static inline BOOL SCCameraTweaksDefaultPortrait(void)
  100. {
  101. return FBTweakValue(@"Camera", @"Core Camera", @"Default to Portrait Orientation", YES);
  102. }
  103. // For test purpose
  104. static inline BOOL SCCameraTweaksTranscodingAlwaysFails(void)
  105. {
  106. return FBTweakValue(@"Camera", @"Core Camera", @"Transcoding always fails", NO);
  107. }
  108. // This tweak disables the video masking behavior of the snap overlays;
  109. // Intended to be used by curators who are on-site snapping special events.
  110. // Ping [email protected] for any questions/comments
  111. static inline BOOL SCCameraTweaksDisableOverlayVideoMask(void)
  112. {
  113. return FBTweakValue(@"Camera", @"Creative Tools", @"Disable Overlay Video Masking", NO);
  114. }
  115. static inline NSInteger SCCameraTweaksDelayTurnOnFilters(void)
  116. {
  117. return [FBTweakValue(@"Camera", @"Core Camera", @"Delay turn on filter", (id) @0,
  118. (@{ @0 : @"Respect A/B testing",
  119. @1 : @"Override to YES",
  120. @2 : @"Override to NO" })) integerValue];
  121. }
  122. static inline BOOL SCCameraTweaksEnableExposurePointObservation(void)
  123. {
  124. return FBTweakValue(@"Camera", @"Core Camera - Face Focus", @"Observe Exposure Point", NO);
  125. }
  126. static inline BOOL SCCameraTweaksEnableFocusPointObservation(void)
  127. {
  128. return FBTweakValue(@"Camera", @"Core Camera - Face Focus", @"Observe Focus Point", NO);
  129. }
  130. static inline CGFloat SCCameraTweaksSmoothZoomThresholdTime()
  131. {
  132. return FBTweakValue(@"Camera", @"Zoom Strategy - Linear Interpolation", @"Threshold time", 0.3);
  133. }
  134. static inline CGFloat SCCameraTweaksSmoothZoomThresholdFactor()
  135. {
  136. return FBTweakValue(@"Camera", @"Zoom Strategy - Linear Interpolation", @"Threshold factor diff", 0.25);
  137. }
  138. static inline CGFloat SCCameraTweaksSmoothZoomIntermediateFramesPerSecond()
  139. {
  140. return FBTweakValue(@"Camera", @"Zoom Strategy - Linear Interpolation", @"Intermediate fps", 60);
  141. }
  142. static inline CGFloat SCCameraTweaksSmoothZoomDelayTolerantTime()
  143. {
  144. return FBTweakValue(@"Camera", @"Zoom Strategy - Linear Interpolation", @"Delay tolerant time", 0.15);
  145. }
  146. static inline CGFloat SCCameraTweaksSmoothZoomMinStepLength()
  147. {
  148. return FBTweakValue(@"Camera", @"Zoom Strategy - Linear Interpolation", @"Min step length", 0.05);
  149. }
  150. static inline CGFloat SCCameraTweaksExposureDeadline()
  151. {
  152. return FBTweakValue(@"Camera", @"Adjust Exposure", @"Exposure Deadline", 0.2);
  153. }
  154. static inline BOOL SCCameraTweaksKillFrontCamera(void)
  155. {
  156. return SCTweakValueWithHalt(@"Camera", @"Debugging", @"Kill Front Camera", NO);
  157. }
  158. static inline BOOL SCCameraTweaksKillBackCamera(void)
  159. {
  160. return SCTweakValueWithHalt(@"Camera", @"Debugging", @"Kill Back Camera", NO);
  161. }
  162. #if TARGET_IPHONE_SIMULATOR
  163. static inline BOOL SCCameraTweaksUseRealMockImage(void)
  164. {
  165. return FBTweakValue(@"Camera", @"Debugging", @"Use real mock image on simulator", YES);
  166. }
  167. #endif
  168. static inline CGFloat SCCameraTweaksShortPreviewTransitionAnimationDuration()
  169. {
  170. return FBTweakValue(@"Camera", @"Preview Transition", @"Short Animation Duration", 0.35);
  171. }
  172. static inline SCCameraTweaksStrategyType SCCameraTweaksPreviewTransitionAnimationDurationStrategy()
  173. {
  174. NSNumber *strategy = SCTweakValueWithHalt(@"Camera", @"Preview Transition", @"Enable Short Animation Duration",
  175. (id) @(SCCameraTweaksStrategyFollowABTest), (@{
  176. @(SCCameraTweaksStrategyFollowABTest) : @"Respect A/B testing",
  177. @(SCCameraTweaksStrategyOverrideToYes) : @"Override to YES",
  178. @(SCCameraTweaksStrategyOverrideToNo) : @"Override to NO"
  179. }));
  180. return (SCCameraTweaksStrategyType)[strategy unsignedIntegerValue];
  181. }
  182. static inline CGFloat SCCameraTweaksEnablePortraitModeButton(void)
  183. {
  184. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Enable Button", NO);
  185. }
  186. static inline CGFloat SCCameraTweaksDepthBlurForegroundThreshold(void)
  187. {
  188. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Foreground Blur Threshold", 0.3);
  189. }
  190. static inline CGFloat SCCameraTweaksDepthBlurBackgroundThreshold(void)
  191. {
  192. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Background Blur Threshold", 0.1);
  193. }
  194. static inline CGFloat SCCameraTweaksBlurSigma(void)
  195. {
  196. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Blur Sigma", 4.0);
  197. }
  198. static inline BOOL SCCameraTweaksEnableFilterInputFocusRect(void)
  199. {
  200. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Filter Input Focus Rect", NO);
  201. }
  202. static inline BOOL SCCameraTweaksEnablePortraitModeTapToFocus(void)
  203. {
  204. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Tap to Focus", NO);
  205. }
  206. static inline BOOL SCCameraTweaksEnablePortraitModeAutofocus(void)
  207. {
  208. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Autofocus", NO);
  209. }
  210. static inline BOOL SCCameraTweaksDepthToGrayscaleOverride(void)
  211. {
  212. return FBTweakValue(@"Camera", @"Core Camera - Portrait Mode", @"Depth to Grayscale Override", NO);
  213. }
  214. static inline SCCameraTweaksStrategyType SCCameraTweaksEnableHandsFreeXToCancelStrategy(void)
  215. {
  216. NSNumber *strategy = SCTweakValueWithHalt(@"Camera", @"Hands-Free Recording", @"X to Cancel",
  217. (id) @(SCCameraTweaksStrategyFollowABTest), (@{
  218. @(SCCameraTweaksStrategyFollowABTest) : @"Respect A/B testing",
  219. @(SCCameraTweaksStrategyOverrideToYes) : @"Override to YES",
  220. @(SCCameraTweaksStrategyOverrideToNo) : @"Override to NO"
  221. }));
  222. return (SCCameraTweaksStrategyType)[strategy unsignedIntegerValue];
  223. }
  224. static inline SCCameraHandsFreeModeType SCCameraTweaksHandsFreeModeType()
  225. {
  226. NSNumber *strategy = SCTweakValueWithHalt(
  227. @"Camera", @"Hands-Free Recording", @"Enabled", (id) @(SCCameraHandsFreeModeTypeABTest), (@{
  228. @(SCCameraHandsFreeModeTypeABTest) : @"Respect A/B testing",
  229. @(SCCameraHandsFreeModeTypeDisabled) : @"Disable",
  230. @(SCCameraHandsFreeModeTypeMainOnly) : @"Main Camera only",
  231. @(SCCameraHandsFreeModeTypeChatMoveCaptureButton) : @"Main Camera + move Chat capture button",
  232. @(SCCameraHandsFreeModeTypeMainAndChat) : @"Main + Chat Cameras",
  233. @(SCCameraHandsFreeModeTypeLeftOfCapture) : @"Left of Main + Chat Cameras"
  234. }));
  235. return (SCCameraHandsFreeModeType)[strategy unsignedIntegerValue];
  236. }
  237. static inline SCCameraTweaksStrategyType SCCameraTweaksPreviewPresenterFastPreviewStrategy(void)
  238. {
  239. NSNumber *strategy = SCTweakValueWithHalt(@"Camera", @"Preview Presenter", @"Fast Preview",
  240. (id) @(SCCameraTweaksStrategyFollowABTest), (@{
  241. @(SCCameraTweaksStrategyFollowABTest) : @"Respect A/B testing",
  242. @(SCCameraTweaksStrategyOverrideToYes) : @"Override to YES",
  243. @(SCCameraTweaksStrategyOverrideToNo) : @"Override to NO"
  244. }));
  245. return (SCCameraTweaksStrategyType)[strategy unsignedIntegerValue];
  246. }
  247. static inline NSInteger SCCameraTweaksEnableCaptureKeepRecordedVideoStrategy(void)
  248. {
  249. NSNumber *strategy =
  250. SCTweakValueWithHalt(@"Camera", @"Core Camera - Capture Keep Recorded Video",
  251. @"Enable Capture Keep Recorded Video", (id) @(SCCameraTweaksStrategyFollowABTest), (@{
  252. @(SCCameraTweaksStrategyFollowABTest) : @"Respect A/B testing",
  253. @(SCCameraTweaksStrategyOverrideToYes) : @"Override to YES",
  254. @(SCCameraTweaksStrategyOverrideToNo) : @"Override to NO"
  255. }));
  256. return (SCCameraTweaksStrategyType)[strategy unsignedIntegerValue];
  257. }
  258. static inline NSInteger SCCameraTweaksEnableCaptureSharePerformerStrategy(void)
  259. {
  260. NSNumber *strategy =
  261. SCTweakValueWithHalt(@"Camera", @"Core Camera - Capture Share Performer", @"Enable Capture Share Performer",
  262. (id) @(SCCameraTweaksStrategyFollowABTest), (@{
  263. @(SCCameraTweaksStrategyFollowABTest) : @"Respect A/B testing",
  264. @(SCCameraTweaksStrategyOverrideToYes) : @"Override to YES",
  265. @(SCCameraTweaksStrategyOverrideToNo) : @"Override to NO"
  266. }));
  267. return (SCCameraTweaksStrategyType)[strategy unsignedIntegerValue];
  268. }
  269. static inline SCCameraFaceFocusModeStrategyType SCCameraTweaksFaceFocusStrategy()
  270. {
  271. NSNumber *strategy =
  272. SCTweakValueWithHalt(@"Camera", @"Core Camera - Face Focus", @"Enable Face Focus",
  273. (id) @(SCCameraFaceFocusModeStrategyTypeABTest), (@{
  274. @(SCCameraFaceFocusModeStrategyTypeABTest) : @"Respect A/B testing",
  275. @(SCCameraFaceFocusModeStrategyTypeDisabled) : @"Disabled",
  276. @(SCCameraFaceFocusModeStrategyTypeOffByDefault) : @"Enabled, off by default",
  277. @(SCCameraFaceFocusModeStrategyTypeOnByDefault) : @"Enabled, on by default",
  278. }));
  279. return (SCCameraFaceFocusModeStrategyType)[strategy unsignedIntegerValue];
  280. }
  281. static inline SCCameraFaceFocusDetectionMethodType SCCameraTweaksFaceFocusDetectionMethodType()
  282. {
  283. NSNumber *strategy =
  284. SCTweakValueWithHalt(@"Camera", @"Core Camera - Face Focus", @"Detection Method",
  285. (id) @(SCCameraFaceFocusDetectionMethodTypeABTest), (@{
  286. @(SCCameraFaceFocusDetectionMethodTypeABTest) : @"Respect A/B testing",
  287. @(SCCameraFaceFocusDetectionMethodTypeCIDetector) : @"CIDetector",
  288. @(SCCameraFaceFocusDetectionMethodTypeAVMetadata) : @"AVMetadata",
  289. }));
  290. return (SCCameraFaceFocusDetectionMethodType)[strategy unsignedIntegerValue];
  291. }
  292. static inline int SCCameraTweaksFaceFocusDetectionFrequency()
  293. {
  294. return FBTweakValue(@"Camera", @"Core Camera - Face Focus", @"Detection Frequency", 3, 1, 30);
  295. }
  296. static inline BOOL SCCameraTweaksFaceFocusMinFaceSizeRespectABTesting()
  297. {
  298. return SCTweakValueWithHalt(@"Camera", @"Core Camera - Face Focus", @"Min Face Size Respect AB", YES);
  299. }
  300. static inline CGFloat SCCameraTweaksFaceFocusMinFaceSizeValue()
  301. {
  302. return FBTweakValue(@"Camera", @"Core Camera - Face Focus", @"Min Face Size", 0.25, 0.01, 0.5);
  303. }
  304. static inline BOOL SCCameraTweaksEnableDualCamera(void)
  305. {
  306. return SCTweakValueWithHalt(@"Camera", @"Core Camera - Dual Camera", @"Enable Dual Camera", NO);
  307. }