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

Side by Side Diff: webrtc/modules/video_coding/main/source/timestamp_map.cc

Issue 1417283007: modules/video_coding refactorings (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix the other copy of the mock include header Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <assert.h>
12 #include <stdlib.h>
13
14 #include "webrtc/modules/include/module_common_types.h"
15 #include "webrtc/modules/video_coding/main/source/timestamp_map.h"
16
17 namespace webrtc {
18
19 VCMTimestampMap::VCMTimestampMap(size_t capacity)
20 : ring_buffer_(new TimestampDataTuple[capacity]),
21 capacity_(capacity),
22 next_add_idx_(0),
23 next_pop_idx_(0) {
24 }
25
26 VCMTimestampMap::~VCMTimestampMap() {
27 }
28
29 void VCMTimestampMap::Add(uint32_t timestamp, VCMFrameInformation* data) {
30 ring_buffer_[next_add_idx_].timestamp = timestamp;
31 ring_buffer_[next_add_idx_].data = data;
32 next_add_idx_ = (next_add_idx_ + 1) % capacity_;
33
34 if (next_add_idx_ == next_pop_idx_) {
35 // Circular list full; forget oldest entry.
36 next_pop_idx_ = (next_pop_idx_ + 1) % capacity_;
37 }
38 }
39
40 VCMFrameInformation* VCMTimestampMap::Pop(uint32_t timestamp) {
41 while (!IsEmpty()) {
42 if (ring_buffer_[next_pop_idx_].timestamp == timestamp) {
43 // Found start time for this timestamp.
44 VCMFrameInformation* data = ring_buffer_[next_pop_idx_].data;
45 ring_buffer_[next_pop_idx_].data = nullptr;
46 next_pop_idx_ = (next_pop_idx_ + 1) % capacity_;
47 return data;
48 } else if (IsNewerTimestamp(ring_buffer_[next_pop_idx_].timestamp,
49 timestamp)) {
50 // The timestamp we are looking for is not in the list.
51 return nullptr;
52 }
53
54 // Not in this position, check next (and forget this position).
55 next_pop_idx_ = (next_pop_idx_ + 1) % capacity_;
56 }
57
58 // Could not find matching timestamp in list.
59 return nullptr;
60 }
61
62 bool VCMTimestampMap::IsEmpty() const {
63 return (next_add_idx_ == next_pop_idx_);
64 }
65 }
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/main/source/timestamp_map.h ('k') | webrtc/modules/video_coding/main/source/timing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698