inter_frame_delay.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_VIDEO_CODING_INTER_FRAME_DELAY_H_
  11. #define MODULES_VIDEO_CODING_INTER_FRAME_DELAY_H_
  12. #include <stdint.h>
  13. namespace webrtc {
  14. class VCMInterFrameDelay {
  15. public:
  16. explicit VCMInterFrameDelay(int64_t currentWallClock);
  17. // Resets the estimate. Zeros are given as parameters.
  18. void Reset(int64_t currentWallClock);
  19. // Calculates the delay of a frame with the given timestamp.
  20. // This method is called when the frame is complete.
  21. //
  22. // Input:
  23. // - timestamp : RTP timestamp of a received frame.
  24. // - *delay : Pointer to memory where the result should be
  25. // stored.
  26. // - currentWallClock : The current time in milliseconds.
  27. // Should be -1 for normal operation, only used
  28. // for testing.
  29. // Return value : true if OK, false when reordered timestamps.
  30. bool CalculateDelay(uint32_t timestamp,
  31. int64_t* delay,
  32. int64_t currentWallClock);
  33. private:
  34. // Controls if the RTP timestamp counter has had a wrap around between the
  35. // current and the previously received frame.
  36. //
  37. // Input:
  38. // - timestamp : RTP timestamp of the current frame.
  39. void CheckForWrapArounds(uint32_t timestamp);
  40. int64_t _zeroWallClock; // Local timestamp of the first video packet received
  41. int32_t _wrapArounds; // Number of wrapArounds detected
  42. // The previous timestamp passed to the delay estimate
  43. uint32_t _prevTimestamp;
  44. // The previous wall clock timestamp used by the delay estimate
  45. int64_t _prevWallClock;
  46. // Wrap-around compensated difference between incoming timestamps
  47. int64_t _dTS;
  48. };
  49. } // namespace webrtc
  50. #endif // MODULES_VIDEO_CODING_INTER_FRAME_DELAY_H_