OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INTER_ARRIVAL_H_ | 11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INTER_ARRIVAL_H_ |
12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INTER_ARRIVAL_H_ | 12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INTER_ARRIVAL_H_ |
13 | 13 |
14 #include <cstddef> | 14 #include <cstddef> |
15 | 15 |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 // Helper class to compute the inter-arrival time delta and the size delta | 21 // Helper class to compute the inter-arrival time delta and the size delta |
22 // between two timestamp groups. A timestamp is a 32 bit unsigned number with | 22 // between two timestamp groups. A timestamp is a 32 bit unsigned number with |
23 // a client defined rate. | 23 // a client defined rate. |
24 class InterArrival { | 24 class InterArrival { |
25 public: | 25 public: |
26 // A timestamp group is defined as all packets with a timestamp which are at | 26 // A timestamp group is defined as all packets with a timestamp which are at |
27 // most timestamp_group_length_ticks newer than the first timestamp in that | 27 // most timestamp_group_length_ticks older than the first timestamp in that |
28 // group. | 28 // group. |
29 InterArrival(uint32_t timestamp_group_length_ticks, | 29 InterArrival(uint32_t timestamp_group_length_ticks, |
30 double timestamp_to_ms_coeff, | 30 double timestamp_to_ms_coeff, |
31 bool enable_burst_grouping); | 31 bool enable_burst_grouping); |
32 | 32 |
33 // This function returns true if a delta was computed, or false if the current | 33 // This function returns true if a delta was computed, or false if the current |
34 // group is still incomplete or if only one group has been completed. | 34 // group is still incomplete or if only one group has been completed. |
35 // |timestamp| is the timestamp. | 35 // |timestamp| is the timestamp. |
36 // |arrival_time_ms| is the local time at which the packet arrived. | 36 // |arrival_time_ms| is the local time at which the packet arrived. |
| 37 // |packet_size| is the size of the packet. |
37 // |timestamp_delta| (output) is the computed timestamp delta. | 38 // |timestamp_delta| (output) is the computed timestamp delta. |
38 // |arrival_time_delta_ms| (output) is the computed arrival-time delta. | 39 // |arrival_time_delta_ms| (output) is the computed arrival-time delta. |
| 40 // |packet_size_delta| (output) is the computed size delta. |
39 bool ComputeDeltas(uint32_t timestamp, | 41 bool ComputeDeltas(uint32_t timestamp, |
40 int64_t arrival_time_ms, | 42 int64_t arrival_time_ms, |
| 43 size_t packet_size, |
41 uint32_t* timestamp_delta, | 44 uint32_t* timestamp_delta, |
42 int64_t* arrival_time_delta_ms); | 45 int64_t* arrival_time_delta_ms, |
| 46 int* packet_size_delta); |
43 | 47 |
44 private: | 48 private: |
45 struct TimestampGroup { | 49 struct TimestampGroup { |
46 TimestampGroup() : first_timestamp(0), timestamp(0), complete_time_ms(-1) {} | 50 TimestampGroup() |
| 51 : size(0), |
| 52 first_timestamp(0), |
| 53 timestamp(0), |
| 54 complete_time_ms(-1) {} |
47 | 55 |
48 bool IsFirstPacket() const { | 56 bool IsFirstPacket() const { |
49 return complete_time_ms == -1; | 57 return complete_time_ms == -1; |
50 } | 58 } |
51 | 59 |
| 60 size_t size; |
52 uint32_t first_timestamp; | 61 uint32_t first_timestamp; |
53 uint32_t timestamp; | 62 uint32_t timestamp; |
54 int64_t complete_time_ms; | 63 int64_t complete_time_ms; |
55 }; | 64 }; |
56 | 65 |
57 // Returns true if the packet with timestamp |timestamp| arrived in order. | 66 // Returns true if the packet with timestamp |timestamp| arrived in order. |
58 bool PacketInOrder(uint32_t timestamp); | 67 bool PacketInOrder(uint32_t timestamp); |
59 | 68 |
60 // Returns true if the last packet was the end of the current batch and the | 69 // Returns true if the last packet was the end of the current batch and the |
61 // packet with |timestamp| is the first of a new batch. | 70 // packet with |timestamp| is the first of a new batch. |
62 bool NewTimestampGroup(int64_t arrival_time_ms, uint32_t timestamp) const; | 71 bool NewTimestampGroup(int64_t arrival_time_ms, uint32_t timestamp) const; |
63 | 72 |
64 bool BelongsToBurst(int64_t arrival_time_ms, uint32_t timestamp) const; | 73 bool BelongsToBurst(int64_t arrival_time_ms, uint32_t timestamp) const; |
65 | 74 |
66 const uint32_t kTimestampGroupLengthTicks; | 75 const uint32_t kTimestampGroupLengthTicks; |
67 TimestampGroup current_timestamp_group_; | 76 TimestampGroup current_timestamp_group_; |
68 TimestampGroup prev_timestamp_group_; | 77 TimestampGroup prev_timestamp_group_; |
69 double timestamp_to_ms_coeff_; | 78 double timestamp_to_ms_coeff_; |
70 bool burst_grouping_; | 79 bool burst_grouping_; |
71 | 80 |
72 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(InterArrival); | 81 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(InterArrival); |
73 }; | 82 }; |
74 } // namespace webrtc | 83 } // namespace webrtc |
75 | 84 |
76 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INTER_ARRIVAL_H_ | 85 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INTER_ARRIVAL_H_ |
OLD | NEW |