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

Side by Side Diff: media/cast/framer/frame_id_map.cc

Issue 148663003: Cast: Refactor framer to Clang format (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/cast/framer/frame_id_map.h ('k') | media/cast/framer/framer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/framer/frame_id_map.h" 5 #include "media/cast/framer/frame_id_map.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/cast/rtp_receiver/rtp_receiver_defines.h" 8 #include "media/cast/rtp_receiver/rtp_receiver_defines.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 20 matching lines...) Expand all
31 return kDuplicatePacket; 31 return kDuplicatePacket;
32 } 32 }
33 // Update the last received packet id. 33 // Update the last received packet id.
34 if (IsNewerPacketId(packet_id, max_received_packet_id_)) { 34 if (IsNewerPacketId(packet_id, max_received_packet_id_)) {
35 max_received_packet_id_ = packet_id; 35 max_received_packet_id_ = packet_id;
36 } 36 }
37 missing_packets_.erase(packet_id); 37 missing_packets_.erase(packet_id);
38 return missing_packets_.empty() ? kNewPacketCompletingFrame : kNewPacket; 38 return missing_packets_.empty() ? kNewPacketCompletingFrame : kNewPacket;
39 } 39 }
40 40
41 bool FrameInfo::Complete() const { 41 bool FrameInfo::Complete() const { return missing_packets_.empty(); }
42 return missing_packets_.empty();
43 }
44 42
45 void FrameInfo::GetMissingPackets(bool newest_frame, 43 void FrameInfo::GetMissingPackets(bool newest_frame,
46 PacketIdSet* missing_packets) const { 44 PacketIdSet* missing_packets) const {
47 if (newest_frame) { 45 if (newest_frame) {
48 // Missing packets capped by max_received_packet_id_. 46 // Missing packets capped by max_received_packet_id_.
49 PacketIdSet::const_iterator it_after_last_received = 47 PacketIdSet::const_iterator it_after_last_received =
50 missing_packets_.lower_bound(max_received_packet_id_); 48 missing_packets_.lower_bound(max_received_packet_id_);
51 missing_packets->insert(missing_packets_.begin(), it_after_last_received); 49 missing_packets->insert(missing_packets_.begin(), it_after_last_received);
52 } else { 50 } else {
53 missing_packets->insert(missing_packets_.begin(), missing_packets_.end()); 51 missing_packets->insert(missing_packets_.begin(), missing_packets_.end());
54 } 52 }
55 } 53 }
56 54
57
58 FrameIdMap::FrameIdMap() 55 FrameIdMap::FrameIdMap()
59 : waiting_for_key_(true), 56 : waiting_for_key_(true),
60 last_released_frame_(kStartFrameId), 57 last_released_frame_(kStartFrameId),
61 newest_frame_id_(kStartFrameId) { 58 newest_frame_id_(kStartFrameId) {}
62 }
63 59
64 FrameIdMap::~FrameIdMap() {} 60 FrameIdMap::~FrameIdMap() {}
65 61
66 PacketType FrameIdMap::InsertPacket(const RtpCastHeader& rtp_header) { 62 PacketType FrameIdMap::InsertPacket(const RtpCastHeader& rtp_header) {
67 uint32 frame_id = rtp_header.frame_id; 63 uint32 frame_id = rtp_header.frame_id;
68 uint32 reference_frame_id; 64 uint32 reference_frame_id;
69 if (rtp_header.is_reference) { 65 if (rtp_header.is_reference) {
70 reference_frame_id = rtp_header.reference_frame_id; 66 reference_frame_id = rtp_header.reference_frame_id;
71 } else { 67 } else {
72 reference_frame_id = static_cast<uint32>(frame_id - 1); 68 reference_frame_id = static_cast<uint32>(frame_id - 1);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 last_released_frame_ = frame_id; 120 last_released_frame_ = frame_id;
125 } 121 }
126 122
127 void FrameIdMap::Clear() { 123 void FrameIdMap::Clear() {
128 frame_map_.clear(); 124 frame_map_.clear();
129 waiting_for_key_ = true; 125 waiting_for_key_ = true;
130 last_released_frame_ = kStartFrameId; 126 last_released_frame_ = kStartFrameId;
131 newest_frame_id_ = kStartFrameId; 127 newest_frame_id_ = kStartFrameId;
132 } 128 }
133 129
134 uint32 FrameIdMap::NewestFrameId() const { 130 uint32 FrameIdMap::NewestFrameId() const { return newest_frame_id_; }
135 return newest_frame_id_;
136 }
137 131
138 bool FrameIdMap::NextContinuousFrame(uint32* frame_id) const { 132 bool FrameIdMap::NextContinuousFrame(uint32* frame_id) const {
139 FrameMap::const_iterator it; 133 FrameMap::const_iterator it;
140 134
141 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) { 135 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
142 if (it->second->Complete() && ContinuousFrame(it->second.get())) { 136 if (it->second->Complete() && ContinuousFrame(it->second.get())) {
143 *frame_id = it->first; 137 *frame_id = it->first;
144 return true; 138 return true;
145 } 139 }
146 } 140 }
147 return false; 141 return false;
148 } 142 }
149 143
150 uint32 FrameIdMap::LastContinuousFrame() const { 144 uint32 FrameIdMap::LastContinuousFrame() const {
151 uint32 last_continuous_frame_id = last_released_frame_; 145 uint32 last_continuous_frame_id = last_released_frame_;
152 uint32 next_expected_frame = last_released_frame_; 146 uint32 next_expected_frame = last_released_frame_;
153 147
154 FrameMap::const_iterator it; 148 FrameMap::const_iterator it;
155 149
156 do { 150 do {
157 next_expected_frame++; 151 next_expected_frame++;
158 it = frame_map_.find(next_expected_frame); 152 it = frame_map_.find(next_expected_frame);
159 if (it == frame_map_.end()) break; 153 if (it == frame_map_.end())
160 if (!it->second->Complete()) break; 154 break;
155 if (!it->second->Complete())
156 break;
161 157
162 // We found the next continuous frame. 158 // We found the next continuous frame.
163 last_continuous_frame_id = it->first; 159 last_continuous_frame_id = it->first;
164 } while (next_expected_frame != newest_frame_id_); 160 } while (next_expected_frame != newest_frame_id_);
165 return last_continuous_frame_id; 161 return last_continuous_frame_id;
166 } 162 }
167 163
168 bool FrameIdMap::NextAudioFrameAllowingMissingFrames(uint32* frame_id) const { 164 bool FrameIdMap::NextAudioFrameAllowingMissingFrames(uint32* frame_id) const {
169 // First check if we have continuous frames. 165 // First check if we have continuous frames.
170 if (NextContinuousFrame(frame_id)) return true; 166 if (NextContinuousFrame(frame_id))
167 return true;
171 168
172 // Find the oldest frame. 169 // Find the oldest frame.
173 FrameMap::const_iterator it_best_match = frame_map_.end(); 170 FrameMap::const_iterator it_best_match = frame_map_.end();
174 FrameMap::const_iterator it; 171 FrameMap::const_iterator it;
175 172
176 // Find first complete frame. 173 // Find first complete frame.
177 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) { 174 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
178 if (it->second->Complete()) { 175 if (it->second->Complete()) {
179 it_best_match = it; 176 it_best_match = it;
180 break; 177 break;
181 } 178 }
182 } 179 }
183 if (it_best_match == frame_map_.end()) return false; // No complete frame. 180 if (it_best_match == frame_map_.end())
181 return false; // No complete frame.
184 182
185 ++it; 183 ++it;
186 for (; it != frame_map_.end(); ++it) { 184 for (; it != frame_map_.end(); ++it) {
187 if (it->second->Complete() && 185 if (it->second->Complete() &&
188 IsOlderFrameId(it->first, it_best_match->first)) { 186 IsOlderFrameId(it->first, it_best_match->first)) {
189 it_best_match = it; 187 it_best_match = it;
190 } 188 }
191 } 189 }
192 *frame_id = it_best_match->first; 190 *frame_id = it_best_match->first;
193 return true; 191 return true;
194 } 192 }
195 193
196 bool FrameIdMap::NextVideoFrameAllowingSkippingFrames(uint32* frame_id) const { 194 bool FrameIdMap::NextVideoFrameAllowingSkippingFrames(uint32* frame_id) const {
197 // Find the oldest decodable frame. 195 // Find the oldest decodable frame.
198 FrameMap::const_iterator it_best_match = frame_map_.end(); 196 FrameMap::const_iterator it_best_match = frame_map_.end();
199 FrameMap::const_iterator it; 197 FrameMap::const_iterator it;
200 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) { 198 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
201 if (it->second->Complete() && DecodableVideoFrame(it->second.get())) { 199 if (it->second->Complete() && DecodableVideoFrame(it->second.get())) {
202 it_best_match = it; 200 it_best_match = it;
203 } 201 }
204 } 202 }
205 if (it_best_match == frame_map_.end()) return false; 203 if (it_best_match == frame_map_.end())
204 return false;
206 205
207 *frame_id = it_best_match->first; 206 *frame_id = it_best_match->first;
208 return true; 207 return true;
209 } 208 }
210 209
211 bool FrameIdMap::Empty() const { 210 bool FrameIdMap::Empty() const { return frame_map_.empty(); }
212 return frame_map_.empty();
213 }
214 211
215 int FrameIdMap::NumberOfCompleteFrames() const { 212 int FrameIdMap::NumberOfCompleteFrames() const {
216 int count = 0; 213 int count = 0;
217 FrameMap::const_iterator it; 214 FrameMap::const_iterator it;
218 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) { 215 for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
219 if (it->second->Complete()) { 216 if (it->second->Complete()) {
220 ++count; 217 ++count;
221 } 218 }
222 } 219 }
223 return count; 220 return count;
224 } 221 }
225 222
226 bool FrameIdMap::FrameExists(uint32 frame_id) const { 223 bool FrameIdMap::FrameExists(uint32 frame_id) const {
227 return frame_map_.end() != frame_map_.find(frame_id); 224 return frame_map_.end() != frame_map_.find(frame_id);
228 } 225 }
229 226
230 void FrameIdMap::GetMissingPackets(uint32 frame_id, 227 void FrameIdMap::GetMissingPackets(uint32 frame_id,
231 bool last_frame, 228 bool last_frame,
232 PacketIdSet* missing_packets) const { 229 PacketIdSet* missing_packets) const {
233 FrameMap::const_iterator it = frame_map_.find(frame_id); 230 FrameMap::const_iterator it = frame_map_.find(frame_id);
234 if (it == frame_map_.end()) return; 231 if (it == frame_map_.end())
232 return;
235 233
236 it->second->GetMissingPackets(last_frame, missing_packets); 234 it->second->GetMissingPackets(last_frame, missing_packets);
237 } 235 }
238 236
239 bool FrameIdMap::ContinuousFrame(FrameInfo* frame) const { 237 bool FrameIdMap::ContinuousFrame(FrameInfo* frame) const {
240 DCHECK(frame); 238 DCHECK(frame);
241 if (waiting_for_key_ && !frame->is_key_frame()) return false; 239 if (waiting_for_key_ && !frame->is_key_frame())
240 return false;
242 return static_cast<uint32>(last_released_frame_ + 1) == frame->frame_id(); 241 return static_cast<uint32>(last_released_frame_ + 1) == frame->frame_id();
243 } 242 }
244 243
245 bool FrameIdMap::DecodableVideoFrame(FrameInfo* frame) const { 244 bool FrameIdMap::DecodableVideoFrame(FrameInfo* frame) const {
246 if (frame->is_key_frame()) return true; 245 if (frame->is_key_frame())
247 if (waiting_for_key_ && !frame->is_key_frame()) return false; 246 return true;
247 if (waiting_for_key_ && !frame->is_key_frame())
248 return false;
248 249
249 // Current frame is not necessarily referencing the last frame. 250 // Current frame is not necessarily referencing the last frame.
250 // Do we have the reference frame? 251 // Do we have the reference frame?
251 if (IsOlderFrameId(frame->referenced_frame_id(), last_released_frame_)) { 252 if (IsOlderFrameId(frame->referenced_frame_id(), last_released_frame_)) {
252 return true; 253 return true;
253 } 254 }
254 return frame->referenced_frame_id() == last_released_frame_; 255 return frame->referenced_frame_id() == last_released_frame_;
255 } 256 }
256 257
257 } // namespace cast 258 } // namespace cast
258 } // namespace media 259 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/framer/frame_id_map.h ('k') | media/cast/framer/framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698