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