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.

58 lines
1.6 KiB

  1. //
  2. // SCManagedVideoStreamReporter.m
  3. // Snapchat
  4. //
  5. // Created by Liu Liu on 5/16/15.
  6. // Copyright (c) 2015 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCManagedVideoStreamReporter.h"
  9. #import <SCFoundation/SCLog.h>
  10. #import <SCLogger/SCLogger.h>
  11. static NSTimeInterval const SCManagedVideoStreamReporterInterval = 10;
  12. @implementation SCManagedVideoStreamReporter {
  13. NSUInteger _droppedSampleBuffers;
  14. NSUInteger _outputSampleBuffers;
  15. NSTimeInterval _lastReportTime;
  16. }
  17. - (instancetype)init
  18. {
  19. self = [super init];
  20. if (self) {
  21. _lastReportTime = CACurrentMediaTime();
  22. }
  23. return self;
  24. }
  25. - (void)_reportIfNeeded
  26. {
  27. NSTimeInterval currentTime = CACurrentMediaTime();
  28. if (currentTime - _lastReportTime > SCManagedVideoStreamReporterInterval) {
  29. SCLogGeneralInfo(@"Time: (%.3f - %.3f], Video Streamer Dropped %tu, Output %tu", _lastReportTime, currentTime,
  30. _droppedSampleBuffers, _outputSampleBuffers);
  31. _droppedSampleBuffers = _outputSampleBuffers = 0;
  32. _lastReportTime = currentTime;
  33. }
  34. }
  35. - (void)managedVideoDataSource:(id<SCManagedVideoDataSource>)managedVideoDataSource
  36. didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
  37. devicePosition:(SCManagedCaptureDevicePosition)devicePosition
  38. {
  39. ++_outputSampleBuffers;
  40. [self _reportIfNeeded];
  41. }
  42. - (void)managedVideoDataSource:(id<SCManagedVideoDataSource>)managedVideoDataSource
  43. didDropSampleBuffer:(CMSampleBufferRef)sampleBuffer
  44. devicePosition:(SCManagedCaptureDevicePosition)devicePosition
  45. {
  46. ++_droppedSampleBuffers;
  47. [self _reportIfNeeded];
  48. }
  49. @end