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

Unified Diff: media/cast/common/mod_util.h

Issue 556693002: Cast: Logging estimates clock difference based on packets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/common/mod_util.h
diff --git a/media/cast/common/mod_util.h b/media/cast/common/mod_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..30143fa20a50c8b74e0814299ccb2bb580f62c5a
--- /dev/null
+++ b/media/cast/common/mod_util.h
@@ -0,0 +1,54 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_CAST_MOD_UTIL_H_
imcheng 2014/09/09 01:04:23 MEDIA_CAST_COMMON_MOD_UTIL_H_
hubbe 2014/09/09 19:06:14 Done.
+#define MEDIA_CAST_MOD_UTIL_H_
+
+#include <map>
+#include "base/logging.h"
+
+namespace media {
+namespace cast {
+
+// MAP is a map<uint??, ...> where the unsigned integer is
+// assumed to wrap around, but only a small range is used at a time.
+// Return the oldest entry in the map.
+template<class MAP>
+typename MAP::iterator ModMapOldest(MAP* map) {
imcheng 2014/09/09 01:04:23 Can map be a const ref?
hubbe 2014/09/09 19:06:14 It can, but then I must return a MAP::const_iterat
+ typename MAP::iterator ret = map->begin();
+ if (ret != map->end()) {
+ typename MAP::key_type lower_quarter = 0;
+ lower_quarter--;
+ lower_quarter >>= 1;
+ if (ret->first < lower_quarter) {
+ typename MAP::iterator tmp = map->upper_bound(lower_quarter * 3);
+ if (tmp != map->end())
+ ret = tmp;
+ }
+ }
+ return ret;
+}
+
+// MAP is a map<uint??, ...> where the unsigned integer is
+// assumed to wrap around, but only a small range is used at a time.
+// Returns the previous entry in the map.
+template<class MAP>
+typename MAP::iterator ModMapPrevious(MAP* map, typename MAP::iterator i) {
imcheng 2014/09/09 01:04:23 Can map be a const ref?
hubbe 2014/09/09 19:06:15 Same argument as above.
+ DCHECK(!map->empty());
+ typename MAP::iterator ret = i;
+ if (i == map->begin()) {
+ ret = map->end();
+ }
+ ret--;
+ if (i == ret)
+ return map->end();
+ if ((i->first - ret->first) > ((typename MAP::key_type(0) - 1)) >> 1)
+ return map->end();
+ return ret;
+}
+
+} // namespace cast
+} // namespace media
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698