Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: webrtc/modules/video_coding/sequence_number_util.h

Issue 1814753002: Moved sequence number specific operations from mod_ops.h (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comment fix. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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_SEQUENCE_NUMBER_UTIL_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_SEQUENCE_NUMBER_UTIL_H_
13
14 #include <limits>
15 #include <type_traits>
16
17 #include "webrtc/base/mod_ops.h"
18
19 namespace webrtc {
20
21 // Test if the sequence number a is ahead or at sequence number b.
torbjorng (webrtc) 2016/03/17 10:47:27 Nit: Please quite variable names, e.g. |a|.
philipel 2016/03/17 12:32:40 Done.
22 // If the two sequence numbers are at max distance from each other
23 // then the sequence number with highest value is considered to
24 // be ahead.
25 template <typename T, T M>
torbjorng (webrtc) 2016/03/17 10:47:27 I cannot work out the intended semantics of this f
philipel 2016/03/17 12:32:40 The reason for checking if the two numbers are at
26 inline bool AheadOrAt(T a, T b) {
27 static_assert(std::is_unsigned<T>::value,
28 "Type must be an unsigned integer.");
29 const T maxDist = M / 2;
30 if (MinDiff<T, M>(a, b) == maxDist)
torbjorng (webrtc) 2016/03/21 12:32:26 We agree that this ought to be triggered just for
philipel 2016/03/21 12:56:20 Done.
31 return b < a;
32 return ForwardDiff<T, M>(b, a) < maxDist;
33 }
34
35 template <typename T>
36 inline bool AheadOrAt(T a, T b) {
37 static_assert(std::is_unsigned<T>::value,
38 "Type must be an unsigned integer.");
39 const T maxDist = std::numeric_limits<T>::max() / 2 + T(1);
40 if (a - b == maxDist)
41 return b < a;
42 return ForwardDiff(b, a) < maxDist;
43 }
44
45 // Test if sequence number a is ahead of sequence number b.
46 template <typename T, T M>
47 inline bool AheadOf(T a, T b) {
48 static_assert(std::is_unsigned<T>::value,
49 "Type must be an unsigned integer.");
50 return a != b && AheadOrAt<T, M>(a, b);
51 }
52
53 template <typename T>
54 inline bool AheadOf(T a, T b) {
55 static_assert(std::is_unsigned<T>::value,
56 "Type must be an unsigned integer.");
57 return a != b && AheadOrAt(a, b);
58 }
59
60 template <typename T, typename M>
61 struct SeqNumComp_;
62
63 template <typename T, T M>
64 struct SeqNumComp_<T, std::integral_constant<T, M>> {
65 bool operator()(T a, T b) const {
66 return AheadOf<T, M>(a, b);
67 }
68 };
69
70 template <typename T>
71 struct SeqNumComp_<T, std::integral_constant<T, T(0)>> {
72 bool operator()(T a, T b) const {
73 return AheadOf<T>(a, b);
74 }
75 };
76
77 // Comparator used to compare sequence numbers in a continuous fashion.
78 //
79 // WARNING! If used to sort sequence numbers of length M then the interval
80 // covered by the sequence numbers may not be larger than floor(M/2).
81 template <typename T, T M = 0>
82 struct AscendingSeqNumComp :
83 private SeqNumComp_<T, std::integral_constant<T, M>> {
84 bool operator()(T a, T b) const {
85 return SeqNumComp_<T, std::integral_constant<T, M>>::operator()(a, b);
86 }
87 };
88
89 // Comparator used to compare sequence numbers in a continuous fashion.
90 //
91 // WARNING! If used to sort sequence numbers of length M then the interval
92 // covered by the sequence numbers may not be larger than floor(M/2).
93 template <typename T, T M = 0>
94 struct DescendingSeqNumComp :
95 private SeqNumComp_<T, std::integral_constant<T, M>> {
96 bool operator()(T a, T b) const {
97 return SeqNumComp_<T, std::integral_constant<T, M>>::operator()(b, a);
98 }
99 };
100
101 } // namespace webrtc
102
103 #endif // WEBRTC_MODULES_VIDEO_CODING_SEQUENCE_NUMBER_UTIL_H_
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/nack_module_unittest.cc ('k') | webrtc/modules/video_coding/sequence_number_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698