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..ea5547d6a9f8c04ecec9c876bc038fbfbb5da9b4 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) {} |
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) { |
Alpha Left Google
2014/08/12 01:07:15
This code has some funny behavior for the followin
hubbe
2014/08/13 17:37:03
Fixed.
|
+ 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_ < -127) { |
+ ret += 0x100; |
+ } |
+ if (ret - largest_frame_id_seen_ > 0LL) { |
Alpha Left Google
2014/08/12 01:07:15
Why 0LL?
hubbe
2014/08/13 17:37:03
Leftover from when I was using int64s, removed.
|
+ 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); |
}; |