diff --git a/webrtc/modules/video_coding/frame_buffer2.cc b/webrtc/modules/video_coding/frame_buffer2.cc index f314ccb5f6..5b81c5f997 100644 --- a/webrtc/modules/video_coding/frame_buffer2.cc +++ b/webrtc/modules/video_coding/frame_buffer2.cc @@ -248,9 +248,13 @@ void FrameBuffer::Stop() { } bool FrameBuffer::ValidReferences(const FrameObject& frame) const { + if (frame.picture_id < 0) + return false; + for (size_t i = 0; i < frame.num_references; ++i) { - if (AheadOrAt(frame.references[i], frame.picture_id)) + if (frame.references[i] < 0 || frame.references[i] >= frame.picture_id) return false; + for (size_t j = i + 1; j < frame.num_references; ++j) { if (frame.references[i] == frame.references[j]) return false; diff --git a/webrtc/modules/video_coding/frame_buffer2.h b/webrtc/modules/video_coding/frame_buffer2.h index 5f5173e4dd..77fe485627 100644 --- a/webrtc/modules/video_coding/frame_buffer2.h +++ b/webrtc/modules/video_coding/frame_buffer2.h @@ -76,19 +76,19 @@ class FrameBuffer { private: struct FrameKey { - FrameKey() : picture_id(0), spatial_layer(0) {} - FrameKey(uint16_t picture_id, uint8_t spatial_layer) + FrameKey() : picture_id(-1), spatial_layer(0) {} + FrameKey(int64_t picture_id, uint8_t spatial_layer) : picture_id(picture_id), spatial_layer(spatial_layer) {} bool operator<(const FrameKey& rhs) const { if (picture_id == rhs.picture_id) return spatial_layer < rhs.spatial_layer; - return AheadOf(rhs.picture_id, picture_id); + return picture_id < rhs.picture_id; } bool operator<=(const FrameKey& rhs) const { return !(rhs < *this); } - uint16_t picture_id; + int64_t picture_id; uint8_t spatial_layer; }; diff --git a/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc b/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc index 5500430391..a40a727647 100644 --- a/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc +++ b/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc @@ -54,7 +54,7 @@ class FakePacketBuffer : public PacketBuffer { class TestRtpFrameReferenceFinder : public ::testing::Test, public OnCompleteFrameCallback { protected: - static constexpr uint64_t kUnwrappedSequenceStart = 10000000000000000000UL; + static constexpr uint64_t kUnwrappedSequenceStart = 1000000000000000000UL; TestRtpFrameReferenceFinder() : rand_(0x8739211), diff --git a/webrtc/modules/video_coding/sequence_number_util.h b/webrtc/modules/video_coding/sequence_number_util.h index 3e7d64a2f5..053f9d0e49 100644 --- a/webrtc/modules/video_coding/sequence_number_util.h +++ b/webrtc/modules/video_coding/sequence_number_util.h @@ -91,11 +91,11 @@ class SeqNumUnwrapper { "Type unwrapped must be an unsigned integer smaller than uint64_t."); public: - // We want a value that is close to 2^63 for two reasons. Firstly, we - // can unwrap wrapping numbers in either direction, and secondly, we avoid - // causing a crash on bad input. We also want the default value to be somewhat - // human readable, a power of 10 for example. - static constexpr uint64_t kDefaultStartValue = 10000000000000000000UL; + // We want a default value that is close to 2^62 for a two reasons. Firstly, + // we can unwrap wrapping numbers in either direction, and secondly, the + // unwrapped numbers can be stored in either int64_t or uint64_t. We also want + // the default value to be human readable, which makes a power of 10 suitable. + static constexpr uint64_t kDefaultStartValue = 1000000000000000000UL; SeqNumUnwrapper() : last_unwrapped_(kDefaultStartValue) {} explicit SeqNumUnwrapper(uint64_t start_at) : last_unwrapped_(start_at) {}