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

Unified Diff: media/cast/net/cast_transport_defines.h

Issue 458313003: Smarter algorithm for extending 8-bit frame IDs to 32-bit frame IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/0LL/0/g Created 6 years, 4 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/net/cast_transport_defines.h
diff --git a/media/cast/net/cast_transport_defines.h b/media/cast/net/cast_transport_defines.h
index fe329a2f44019af5ecda7c05e2aeed675c367474..bbea1eb75e1dac2eff19b567d7d9cd8baa61278b 100644
--- a/media/cast/net/cast_transport_defines.h
+++ b/media/cast/net/cast_transport_defines.h
@@ -66,59 +66,26 @@ typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
class FrameIdWrapHelper {
public:
FrameIdWrapHelper()
- : first_(true), frame_id_wrap_count_(0), range_(kLowRange) {}
+ : largest_frame_id_seen_(kStartFrameId) {}
Alpha Left Google 2014/08/13 18:47:24 Please add another ctor for testing edge cases.
hubbe 2014/08/13 21:18:29 Added setter instead.
uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) {
- if (first_) {
- first_ = false;
- if (over_the_wire_frame_id == 0xff) {
- // Special case for startup.
- return kStartFrameId;
- }
+ int32 ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id;
+ if (ret - largest_frame_id_seen_ > 127) {
+ ret -= 0x100;
}
-
- uint32 wrap_count = frame_id_wrap_count_;
- switch (range_) {
- case kLowRange:
- if (over_the_wire_frame_id > kLowRangeThreshold &&
- over_the_wire_frame_id < kHighRangeThreshold) {
- range_ = kMiddleRange;
- }
- if (over_the_wire_frame_id >= kHighRangeThreshold) {
- // Wrap count was incremented in High->Low transition, but this frame
- // is 'old', actually from before the wrap count got incremented.
- --wrap_count;
- }
- break;
- case kMiddleRange:
- if (over_the_wire_frame_id >= kHighRangeThreshold) {
- range_ = kHighRange;
- }
- break;
- case kHighRange:
- if (over_the_wire_frame_id <= kLowRangeThreshold) {
- // Wrap-around detected.
- range_ = kLowRange;
- ++frame_id_wrap_count_;
- // Frame triggering wrap-around so wrap count should be incremented as
- // as well to match |frame_id_wrap_count_|.
- ++wrap_count;
- }
- break;
+ if (ret - largest_frame_id_seen_ < -128) {
miu 2014/08/13 18:38:57 s/if/else if/
Alpha Left Google 2014/08/13 18:47:24 I think so too.
+ ret += 0x100;
+ }
+ if (ret - largest_frame_id_seen_ > 0) {
miu 2014/08/13 18:38:57 I think this is wrong. Shouldn't it be: if (st
+ largest_frame_id_seen_ = ret;
}
- return (wrap_count << 8) + over_the_wire_frame_id;
+ return static_cast<uint32>(ret);
}
private:
- enum Range { kLowRange, kMiddleRange, kHighRange, };
-
- static const uint8 kLowRangeThreshold = 63;
- static const uint8 kHighRangeThreshold = 192;
static const uint32 kStartFrameId = UINT32_C(0xffffffff);
- bool first_;
- uint32 frame_id_wrap_count_;
- Range range_;
+ int32 largest_frame_id_seen_;
DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper);
};

Powered by Google App Engine
This is Rietveld 408576698