Chromium Code Reviews| 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); |
| }; |