niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_INTER_FRAME_DELAY_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_INTER_FRAME_DELAY_H_ |
| 13 | |
pbos@webrtc.org | a440732 | 2013-07-16 12:32:05 +0000 | [diff] [blame] | 14 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc |
| 17 | { |
| 18 | |
| 19 | class VCMInterFrameDelay |
| 20 | { |
| 21 | public: |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 22 | VCMInterFrameDelay(int64_t currentWallClock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | // Resets the estimate. Zeros are given as parameters. |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 25 | void Reset(int64_t currentWallClock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | // Calculates the delay of a frame with the given timestamp. |
| 28 | // This method is called when the frame is complete. |
| 29 | // |
| 30 | // Input: |
| 31 | // - timestamp : RTP timestamp of a received frame |
| 32 | // - *delay : Pointer to memory where the result should be stored |
| 33 | // - currentWallClock : The current time in milliseconds. |
| 34 | // Should be -1 for normal operation, only used for testing. |
| 35 | // Return value : true if OK, false when reordered timestamps |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 36 | bool CalculateDelay(uint32_t timestamp, |
| 37 | int64_t *delay, |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 38 | int64_t currentWallClock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
| 40 | // Returns the current difference between incoming timestamps |
| 41 | // |
| 42 | // Return value : Wrap-around compensated difference between incoming |
| 43 | // timestamps. |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 44 | uint32_t CurrentTimeStampDiffMs() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | // Controls if the RTP timestamp counter has had a wrap around |
| 48 | // between the current and the previously received frame. |
| 49 | // |
| 50 | // Input: |
| 51 | // - timestmap : RTP timestamp of the current frame. |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 52 | void CheckForWrapArounds(uint32_t timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 54 | int64_t _zeroWallClock; // Local timestamp of the first video packet received |
| 55 | int32_t _wrapArounds; // Number of wrapArounds detected |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | // The previous timestamp passed to the delay estimate |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 57 | uint32_t _prevTimestamp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | // The previous wall clock timestamp used by the delay estimate |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 59 | int64_t _prevWallClock; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | // Wrap-around compensated difference between incoming timestamps |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 61 | int64_t _dTS; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 64 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
| 66 | #endif // WEBRTC_MODULES_VIDEO_CODING_INTER_FRAME_DELAY_H_ |