FBScreenRecordingContainer.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. *
  3. * Copyright (c) 2015-present, Facebook, Inc.
  4. * All rights reserved.
  5. *
  6. * This source code is licensed under the BSD-style license found in the
  7. * LICENSE file in the root directory of this source tree. An additional grant
  8. * of patent rights can be found in the PATENTS file in the same directory.
  9. */
  10. #import "FBScreenRecordingContainer.h"
  11. #import "FBScreenRecordingPromise.h"
  12. @interface FBScreenRecordingContainer ()
  13. @property (readwrite) NSUInteger fps;
  14. @property (readwrite) long long codec;
  15. @property (readwrite) FBScreenRecordingPromise* screenRecordingPromise;
  16. @property (readwrite) NSNumber *startedAt;
  17. @end
  18. @implementation FBScreenRecordingContainer
  19. + (instancetype)sharedInstance
  20. {
  21. static FBScreenRecordingContainer *instance;
  22. static dispatch_once_t onceToken;
  23. dispatch_once(&onceToken, ^{
  24. instance = [[self alloc] init];
  25. });
  26. return instance;
  27. }
  28. - (void)storeScreenRecordingPromise:(FBScreenRecordingPromise *)screenRecordingPromise
  29. fps:(NSUInteger)fps
  30. codec:(long long)codec;
  31. {
  32. self.fps = fps;
  33. self.codec = codec;
  34. self.screenRecordingPromise = screenRecordingPromise;
  35. self.startedAt = @([NSDate.date timeIntervalSince1970]);
  36. }
  37. - (void)reset;
  38. {
  39. self.fps = 0;
  40. self.codec = 0;
  41. if (nil != self.screenRecordingPromise) {
  42. [XCTContext runActivityNamed:@"Video Cleanup" block:^(id<XCTActivity> activity){
  43. [activity addAttachment:(XCTAttachment *)self.screenRecordingPromise.nativePromise];
  44. }];
  45. self.screenRecordingPromise = nil;
  46. }
  47. self.startedAt = nil;
  48. }
  49. - (nullable NSDictionary *)toDictionary
  50. {
  51. if (nil == self.screenRecordingPromise) {
  52. return nil;
  53. }
  54. return @{
  55. @"fps": @(self.fps),
  56. @"codec": @(self.codec),
  57. @"uuid": [self.screenRecordingPromise identifier].UUIDString ?: [NSNull null],
  58. @"startedAt": self.startedAt ?: [NSNull null],
  59. };
  60. }
  61. @end