Chromium Code Reviews| Index: webrtc/modules/video_coding/main/source/timestamp_map.cc |
| diff --git a/webrtc/modules/video_coding/main/source/timestamp_map.cc b/webrtc/modules/video_coding/main/source/timestamp_map.cc |
| index f3806bb87fea5091b2c1cbf6564ae68678c3b3ac..2f8e2cb8b4b87d6f2e0e63a117dfc13bb182668a 100644 |
| --- a/webrtc/modules/video_coding/main/source/timestamp_map.cc |
| +++ b/webrtc/modules/video_coding/main/source/timestamp_map.cc |
| @@ -10,90 +10,56 @@ |
| #include <assert.h> |
| #include <stdlib.h> |
| + |
| +#include "webrtc/modules/interface/module_common_types.h" |
| #include "webrtc/modules/video_coding/main/source/timestamp_map.h" |
| namespace webrtc { |
| -// Constructor. Optional parameter specifies maximum number of |
| -// coexisting timers. |
| -VCMTimestampMap::VCMTimestampMap(int32_t length): |
| - _nextAddIx(0), |
| - _nextPopIx(0) |
| -{ |
| - if (length <= 0) |
| - { |
| - // default |
| - length = 10; |
| - } |
| - |
| - _map = new VCMTimestampDataTuple[length]; |
| - _length = length; |
| -} |
| - |
| -// Destructor. |
| -VCMTimestampMap::~VCMTimestampMap() |
| -{ |
| - delete [] _map; |
| +VCMTimestampMap::VCMTimestampMap(size_t length) |
|
stefan-webrtc
2015/09/21 15:15:46
Named length here, size in the .h file.
pbos-webrtc
2015/09/23 13:51:55
Done.
|
| + : ring_buffer_(new TimestampDataTuple[length]), |
| + length_(length), |
| + next_add_idx_(0), |
| + next_pop_idx_(0) { |
| } |
| -// Empty the list of timers. |
| -void |
| -VCMTimestampMap::Reset() |
| -{ |
| - _nextAddIx = 0; |
| - _nextPopIx = 0; |
| +VCMTimestampMap::~VCMTimestampMap() { |
| } |
| -int32_t |
| -VCMTimestampMap::Add(uint32_t timestamp, void* data) |
| -{ |
| - _map[_nextAddIx].timestamp = timestamp; |
| - _map[_nextAddIx].data = data; |
| - _nextAddIx = (_nextAddIx + 1) % _length; |
| +void VCMTimestampMap::Add(uint32_t timestamp, void* data) { |
| + ring_buffer_[next_add_idx_].timestamp = timestamp; |
| + ring_buffer_[next_add_idx_].data = data; |
| + next_add_idx_ = (next_add_idx_ + 1) % length_; |
| - if (_nextAddIx == _nextPopIx) |
| - { |
| - // Circular list full; forget oldest entry |
| - _nextPopIx = (_nextPopIx + 1) % _length; |
| - return -1; |
| - } |
| - return 0; |
| + if (next_add_idx_ == next_pop_idx_) { |
| + // Circular list full; forget oldest entry |
|
stefan-webrtc
2015/09/21 15:15:46
Feel free to properly format the comments in this
pbos-webrtc
2015/09/23 13:51:55
Done.
|
| + next_pop_idx_ = (next_pop_idx_ + 1) % length_; |
| + } |
| } |
| -void* |
| -VCMTimestampMap::Pop(uint32_t timestamp) |
| -{ |
| - while (!IsEmpty()) |
| - { |
| - if (_map[_nextPopIx].timestamp == timestamp) |
| - { |
| - // found start time for this timestamp |
| - void* data = _map[_nextPopIx].data; |
| - _map[_nextPopIx].data = NULL; |
| - _nextPopIx = (_nextPopIx + 1) % _length; |
| - return data; |
| - } |
| - else if (_map[_nextPopIx].timestamp > timestamp) |
| - { |
| - // the timestamp we are looking for is not in the list |
| - assert(_nextPopIx < _length && _nextPopIx >= 0); |
| - return NULL; |
| - } |
| - |
| - // not in this position, check next (and forget this position) |
| - _nextPopIx = (_nextPopIx + 1) % _length; |
| +void* VCMTimestampMap::Pop(uint32_t timestamp) { |
| + while (!IsEmpty()) { |
| + if (ring_buffer_[next_pop_idx_].timestamp == timestamp) { |
| + // found start time for this timestamp |
| + void* data = ring_buffer_[next_pop_idx_].data; |
| + ring_buffer_[next_pop_idx_].data = NULL; |
| + next_pop_idx_ = (next_pop_idx_ + 1) % length_; |
| + return data; |
| + } else if (IsNewerTimestamp(ring_buffer_[next_pop_idx_].timestamp, |
| + timestamp)) { |
| + // the timestamp we are looking for is not in the list |
| + return NULL; |
| } |
| - // could not find matching timestamp in list |
| - assert(_nextPopIx < _length && _nextPopIx >= 0); |
| - return NULL; |
| -} |
| + // not in this position, check next (and forget this position) |
| + next_pop_idx_ = (next_pop_idx_ + 1) % length_; |
| + } |
| -// Check if no timers are currently running |
| -bool |
| -VCMTimestampMap::IsEmpty() const |
| -{ |
| - return (_nextAddIx == _nextPopIx); |
| + // could not find matching timestamp in list |
| + return NULL; |
| } |
| +bool VCMTimestampMap::IsEmpty() const { |
| + return (next_add_idx_ == next_pop_idx_); |
| +} |
| } |