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

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: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698