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.

83 lines
2.9 KiB

  1. //
  2. // SCVideoCaptureSessionInfo.h
  3. // Snapchat
  4. //
  5. // Created by Michel Loenngren on 3/27/17.
  6. // Copyright © 2017 Snapchat, Inc. All rights reserved.
  7. //
  8. #import <SCFoundation/NSString+SCFormat.h>
  9. #import <CoreMedia/CoreMedia.h>
  10. #import <Foundation/Foundation.h>
  11. typedef NS_ENUM(NSInteger, SCManagedVideoCapturerInfoType) {
  12. SCManagedVideoCapturerInfoAudioQueueError,
  13. SCManagedVideoCapturerInfoAssetWriterError,
  14. SCManagedVideoCapturerInfoAudioSessionError,
  15. SCManagedVideoCapturerInfoAudioQueueRetrySuccess,
  16. SCManagedVideoCapturerInfoAudioQueueRetryDataSourceSuccess_audioQueue,
  17. SCManagedVideoCapturerInfoAudioQueueRetryDataSourceSuccess_hardware
  18. };
  19. typedef u_int32_t sc_managed_capturer_recording_session_t;
  20. /*
  21. Container object holding information about the
  22. current recording session.
  23. */
  24. typedef struct {
  25. CMTime startTime;
  26. CMTime endTime;
  27. CMTime duration;
  28. sc_managed_capturer_recording_session_t sessionId;
  29. } SCVideoCaptureSessionInfo;
  30. static inline SCVideoCaptureSessionInfo SCVideoCaptureSessionInfoMake(CMTime startTime, CMTime endTime,
  31. sc_managed_capturer_recording_session_t sessionId)
  32. {
  33. SCVideoCaptureSessionInfo session;
  34. session.startTime = startTime;
  35. session.endTime = endTime;
  36. if (CMTIME_IS_VALID(startTime) && CMTIME_IS_VALID(endTime)) {
  37. session.duration = CMTimeSubtract(endTime, startTime);
  38. } else {
  39. session.duration = kCMTimeInvalid;
  40. }
  41. session.sessionId = sessionId;
  42. return session;
  43. }
  44. static inline NSTimeInterval SCVideoCaptureSessionInfoGetCurrentDuration(SCVideoCaptureSessionInfo sessionInfo)
  45. {
  46. if (CMTIME_IS_VALID(sessionInfo.startTime)) {
  47. if (CMTIME_IS_VALID(sessionInfo.endTime)) {
  48. return CMTimeGetSeconds(sessionInfo.duration);
  49. }
  50. return CACurrentMediaTime() - CMTimeGetSeconds(sessionInfo.startTime);
  51. }
  52. return 0;
  53. }
  54. static inline NSString *SCVideoCaptureSessionInfoGetDebugString(CMTime time, NSString *label)
  55. {
  56. if (CMTIME_IS_VALID(time)) {
  57. return [NSString sc_stringWithFormat:@"%@: %f", label, CMTimeGetSeconds(time)];
  58. } else {
  59. return [NSString sc_stringWithFormat:@"%@: Invalid", label];
  60. }
  61. }
  62. static inline NSString *SCVideoCaptureSessionInfoGetDebugDescription(SCVideoCaptureSessionInfo sessionInfo)
  63. {
  64. NSMutableString *description = [NSMutableString new];
  65. [description appendString:SCVideoCaptureSessionInfoGetDebugString(sessionInfo.startTime, @"StartTime")];
  66. [description appendString:@", "];
  67. [description appendString:SCVideoCaptureSessionInfoGetDebugString(sessionInfo.endTime, @"EndTime")];
  68. [description appendString:@", "];
  69. [description appendString:SCVideoCaptureSessionInfoGetDebugString(sessionInfo.duration, @"Duration")];
  70. [description appendString:@", "];
  71. [description appendString:[NSString sc_stringWithFormat:@"Id: %u", sessionInfo.sessionId]];
  72. return [description copy];
  73. }