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

Side by Side Diff: media/cast/net/rtp/framer.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/net/rtp/framer.h" 5 #include "media/cast/net/rtp/framer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/cast/cast_defines.h" 8 #include "media/cast/cast_defines.h"
9 #include "media/cast/constants.h" 9 #include "media/cast/constants.h"
10 10
11 namespace media { 11 namespace media {
12 namespace cast { 12 namespace cast {
13 13
14 typedef FrameList::const_iterator ConstFrameIterator; 14 typedef FrameList::const_iterator ConstFrameIterator;
15 15
16 Framer::Framer(base::TickClock* clock, 16 Framer::Framer(base::TickClock* clock,
17 RtpPayloadFeedback* incoming_payload_feedback, 17 RtpPayloadFeedback* incoming_payload_feedback,
18 uint32 ssrc, 18 uint32_t ssrc,
19 bool decoder_faster_than_max_frame_rate, 19 bool decoder_faster_than_max_frame_rate,
20 int max_unacked_frames) 20 int max_unacked_frames)
21 : decoder_faster_than_max_frame_rate_(decoder_faster_than_max_frame_rate), 21 : decoder_faster_than_max_frame_rate_(decoder_faster_than_max_frame_rate),
22 cast_msg_builder_( 22 cast_msg_builder_(
23 new CastMessageBuilder(clock, 23 new CastMessageBuilder(clock,
24 incoming_payload_feedback, 24 incoming_payload_feedback,
25 this, 25 this,
26 ssrc, 26 ssrc,
27 decoder_faster_than_max_frame_rate, 27 decoder_faster_than_max_frame_rate,
28 max_unacked_frames)), 28 max_unacked_frames)),
29 waiting_for_key_(true), 29 waiting_for_key_(true),
30 last_released_frame_(kFirstFrameId - 1), 30 last_released_frame_(kFirstFrameId - 1),
31 newest_frame_id_(kFirstFrameId - 1) { 31 newest_frame_id_(kFirstFrameId - 1) {
32 DCHECK(incoming_payload_feedback) << "Invalid argument"; 32 DCHECK(incoming_payload_feedback) << "Invalid argument";
33 } 33 }
34 34
35 Framer::~Framer() {} 35 Framer::~Framer() {}
36 36
37 bool Framer::InsertPacket(const uint8* payload_data, 37 bool Framer::InsertPacket(const uint8_t* payload_data,
38 size_t payload_size, 38 size_t payload_size,
39 const RtpCastHeader& rtp_header, 39 const RtpCastHeader& rtp_header,
40 bool* duplicate) { 40 bool* duplicate) {
41 *duplicate = false; 41 *duplicate = false;
42 uint32 frame_id = rtp_header.frame_id; 42 uint32_t frame_id = rtp_header.frame_id;
43 43
44 if (rtp_header.is_key_frame && waiting_for_key_) { 44 if (rtp_header.is_key_frame && waiting_for_key_) {
45 last_released_frame_ = static_cast<uint32>(frame_id - 1); 45 last_released_frame_ = static_cast<uint32_t>(frame_id - 1);
46 waiting_for_key_ = false; 46 waiting_for_key_ = false;
47 } 47 }
48 48
49 VLOG(1) << "InsertPacket frame:" << frame_id 49 VLOG(1) << "InsertPacket frame:" << frame_id
50 << " packet:" << static_cast<int>(rtp_header.packet_id) 50 << " packet:" << static_cast<int>(rtp_header.packet_id)
51 << " max packet:" << static_cast<int>(rtp_header.max_packet_id); 51 << " max packet:" << static_cast<int>(rtp_header.max_packet_id);
52 52
53 if (IsOlderFrameId(frame_id, last_released_frame_) && !waiting_for_key_) { 53 if (IsOlderFrameId(frame_id, last_released_frame_) && !waiting_for_key_) {
54 // Packet is too old. 54 // Packet is too old.
55 return false; 55 return false;
(...skipping 25 matching lines...) Expand all
81 81
82 return it->second->Complete(); 82 return it->second->Complete();
83 } 83 }
84 84
85 // This does not release the frame. 85 // This does not release the frame.
86 bool Framer::GetEncodedFrame(EncodedFrame* frame, 86 bool Framer::GetEncodedFrame(EncodedFrame* frame,
87 bool* next_frame, 87 bool* next_frame,
88 bool* have_multiple_decodable_frames) { 88 bool* have_multiple_decodable_frames) {
89 *have_multiple_decodable_frames = HaveMultipleDecodableFrames(); 89 *have_multiple_decodable_frames = HaveMultipleDecodableFrames();
90 90
91 uint32 frame_id; 91 uint32_t frame_id;
92 // Find frame id. 92 // Find frame id.
93 if (NextContinuousFrame(&frame_id)) { 93 if (NextContinuousFrame(&frame_id)) {
94 // We have our next frame. 94 // We have our next frame.
95 *next_frame = true; 95 *next_frame = true;
96 } else { 96 } else {
97 // Check if we can skip frames when our decoder is too slow. 97 // Check if we can skip frames when our decoder is too slow.
98 if (!decoder_faster_than_max_frame_rate_) 98 if (!decoder_faster_than_max_frame_rate_)
99 return false; 99 return false;
100 100
101 if (!NextFrameAllowingSkippingFrames(&frame_id)) { 101 if (!NextFrameAllowingSkippingFrames(&frame_id)) {
102 return false; 102 return false;
103 } 103 }
104 *next_frame = false; 104 *next_frame = false;
105 } 105 }
106 106
107 ConstFrameIterator it = frames_.find(frame_id); 107 ConstFrameIterator it = frames_.find(frame_id);
108 DCHECK(it != frames_.end()); 108 DCHECK(it != frames_.end());
109 if (it == frames_.end()) 109 if (it == frames_.end())
110 return false; 110 return false;
111 111
112 return it->second->AssembleEncodedFrame(frame); 112 return it->second->AssembleEncodedFrame(frame);
113 } 113 }
114 114
115 void Framer::AckFrame(uint32 frame_id) { 115 void Framer::AckFrame(uint32_t frame_id) {
116 VLOG(2) << "ACK frame " << frame_id; 116 VLOG(2) << "ACK frame " << frame_id;
117 cast_msg_builder_->CompleteFrameReceived(frame_id); 117 cast_msg_builder_->CompleteFrameReceived(frame_id);
118 } 118 }
119 119
120 void Framer::Reset() { 120 void Framer::Reset() {
121 waiting_for_key_ = true; 121 waiting_for_key_ = true;
122 last_released_frame_ = kFirstFrameId - 1; 122 last_released_frame_ = kFirstFrameId - 1;
123 newest_frame_id_ = kFirstFrameId - 1; 123 newest_frame_id_ = kFirstFrameId - 1;
124 frames_.clear(); 124 frames_.clear();
125 cast_msg_builder_->Reset(); 125 cast_msg_builder_->Reset();
126 } 126 }
127 127
128 void Framer::ReleaseFrame(uint32 frame_id) { 128 void Framer::ReleaseFrame(uint32_t frame_id) {
129 RemoveOldFrames(frame_id); 129 RemoveOldFrames(frame_id);
130 frames_.erase(frame_id); 130 frames_.erase(frame_id);
131 131
132 // We have a frame - remove all frames with lower frame id. 132 // We have a frame - remove all frames with lower frame id.
133 bool skipped_old_frame = false; 133 bool skipped_old_frame = false;
134 FrameList::iterator it; 134 FrameList::iterator it;
135 for (it = frames_.begin(); it != frames_.end();) { 135 for (it = frames_.begin(); it != frames_.end();) {
136 if (IsOlderFrameId(it->first, frame_id)) { 136 if (IsOlderFrameId(it->first, frame_id)) {
137 frames_.erase(it++); 137 frames_.erase(it++);
138 skipped_old_frame = true; 138 skipped_old_frame = true;
139 } else { 139 } else {
140 ++it; 140 ++it;
141 } 141 }
142 } 142 }
143 if (skipped_old_frame) { 143 if (skipped_old_frame) {
144 cast_msg_builder_->UpdateCastMessage(); 144 cast_msg_builder_->UpdateCastMessage();
145 } 145 }
146 } 146 }
147 147
148 bool Framer::TimeToSendNextCastMessage(base::TimeTicks* time_to_send) { 148 bool Framer::TimeToSendNextCastMessage(base::TimeTicks* time_to_send) {
149 return cast_msg_builder_->TimeToSendNextCastMessage(time_to_send); 149 return cast_msg_builder_->TimeToSendNextCastMessage(time_to_send);
150 } 150 }
151 151
152 void Framer::SendCastMessage() { cast_msg_builder_->UpdateCastMessage(); } 152 void Framer::SendCastMessage() { cast_msg_builder_->UpdateCastMessage(); }
153 153
154 void Framer::RemoveOldFrames(uint32 frame_id) { 154 void Framer::RemoveOldFrames(uint32_t frame_id) {
155 FrameList::iterator it = frames_.begin(); 155 FrameList::iterator it = frames_.begin();
156 156
157 while (it != frames_.end()) { 157 while (it != frames_.end()) {
158 if (IsNewerFrameId(it->first, frame_id)) { 158 if (IsNewerFrameId(it->first, frame_id)) {
159 ++it; 159 ++it;
160 } else { 160 } else {
161 // Older or equal; erase. 161 // Older or equal; erase.
162 frames_.erase(it++); 162 frames_.erase(it++);
163 } 163 }
164 } 164 }
165 last_released_frame_ = frame_id; 165 last_released_frame_ = frame_id;
166 } 166 }
167 167
168 uint32 Framer::NewestFrameId() const { return newest_frame_id_; } 168 uint32_t Framer::NewestFrameId() const {
169 return newest_frame_id_;
170 }
169 171
170 bool Framer::NextContinuousFrame(uint32* frame_id) const { 172 bool Framer::NextContinuousFrame(uint32_t* frame_id) const {
171 FrameList::const_iterator it; 173 FrameList::const_iterator it;
172 174
173 for (it = frames_.begin(); it != frames_.end(); ++it) { 175 for (it = frames_.begin(); it != frames_.end(); ++it) {
174 if (it->second->Complete() && ContinuousFrame(it->second.get())) { 176 if (it->second->Complete() && ContinuousFrame(it->second.get())) {
175 *frame_id = it->first; 177 *frame_id = it->first;
176 return true; 178 return true;
177 } 179 }
178 } 180 }
179 return false; 181 return false;
180 } 182 }
181 183
182 bool Framer::HaveMultipleDecodableFrames() const { 184 bool Framer::HaveMultipleDecodableFrames() const {
183 // Find the oldest decodable frame. 185 // Find the oldest decodable frame.
184 FrameList::const_iterator it; 186 FrameList::const_iterator it;
185 bool found_one = false; 187 bool found_one = false;
186 for (it = frames_.begin(); it != frames_.end(); ++it) { 188 for (it = frames_.begin(); it != frames_.end(); ++it) {
187 if (it->second->Complete() && DecodableFrame(it->second.get())) { 189 if (it->second->Complete() && DecodableFrame(it->second.get())) {
188 if (found_one) { 190 if (found_one) {
189 return true; 191 return true;
190 } else { 192 } else {
191 found_one = true; 193 found_one = true;
192 } 194 }
193 } 195 }
194 } 196 }
195 return false; 197 return false;
196 } 198 }
197 199
198 uint32 Framer::LastContinuousFrame() const { 200 uint32_t Framer::LastContinuousFrame() const {
199 uint32 last_continuous_frame_id = last_released_frame_; 201 uint32_t last_continuous_frame_id = last_released_frame_;
200 uint32 next_expected_frame = last_released_frame_; 202 uint32_t next_expected_frame = last_released_frame_;
201 203
202 FrameList::const_iterator it; 204 FrameList::const_iterator it;
203 205
204 do { 206 do {
205 next_expected_frame++; 207 next_expected_frame++;
206 it = frames_.find(next_expected_frame); 208 it = frames_.find(next_expected_frame);
207 if (it == frames_.end()) 209 if (it == frames_.end())
208 break; 210 break;
209 if (!it->second->Complete()) 211 if (!it->second->Complete())
210 break; 212 break;
211 213
212 // We found the next continuous frame. 214 // We found the next continuous frame.
213 last_continuous_frame_id = it->first; 215 last_continuous_frame_id = it->first;
214 } while (next_expected_frame != newest_frame_id_); 216 } while (next_expected_frame != newest_frame_id_);
215 return last_continuous_frame_id; 217 return last_continuous_frame_id;
216 } 218 }
217 219
218 bool Framer::NextFrameAllowingSkippingFrames(uint32* frame_id) const { 220 bool Framer::NextFrameAllowingSkippingFrames(uint32_t* frame_id) const {
219 // Find the oldest decodable frame. 221 // Find the oldest decodable frame.
220 FrameList::const_iterator it_best_match = frames_.end(); 222 FrameList::const_iterator it_best_match = frames_.end();
221 FrameList::const_iterator it; 223 FrameList::const_iterator it;
222 for (it = frames_.begin(); it != frames_.end(); ++it) { 224 for (it = frames_.begin(); it != frames_.end(); ++it) {
223 if (it->second->Complete() && DecodableFrame(it->second.get())) { 225 if (it->second->Complete() && DecodableFrame(it->second.get())) {
224 if (it_best_match == frames_.end() || 226 if (it_best_match == frames_.end() ||
225 IsOlderFrameId(it->first, it_best_match->first)) { 227 IsOlderFrameId(it->first, it_best_match->first)) {
226 it_best_match = it; 228 it_best_match = it;
227 } 229 }
228 } 230 }
(...skipping 11 matching lines...) Expand all
240 int count = 0; 242 int count = 0;
241 FrameList::const_iterator it; 243 FrameList::const_iterator it;
242 for (it = frames_.begin(); it != frames_.end(); ++it) { 244 for (it = frames_.begin(); it != frames_.end(); ++it) {
243 if (it->second->Complete()) { 245 if (it->second->Complete()) {
244 ++count; 246 ++count;
245 } 247 }
246 } 248 }
247 return count; 249 return count;
248 } 250 }
249 251
250 bool Framer::FrameExists(uint32 frame_id) const { 252 bool Framer::FrameExists(uint32_t frame_id) const {
251 return frames_.end() != frames_.find(frame_id); 253 return frames_.end() != frames_.find(frame_id);
252 } 254 }
253 255
254 void Framer::GetMissingPackets(uint32 frame_id, 256 void Framer::GetMissingPackets(uint32_t frame_id,
255 bool last_frame, 257 bool last_frame,
256 PacketIdSet* missing_packets) const { 258 PacketIdSet* missing_packets) const {
257 FrameList::const_iterator it = frames_.find(frame_id); 259 FrameList::const_iterator it = frames_.find(frame_id);
258 if (it == frames_.end()) 260 if (it == frames_.end())
259 return; 261 return;
260 262
261 it->second->GetMissingPackets(last_frame, missing_packets); 263 it->second->GetMissingPackets(last_frame, missing_packets);
262 } 264 }
263 265
264 bool Framer::ContinuousFrame(FrameBuffer* frame) const { 266 bool Framer::ContinuousFrame(FrameBuffer* frame) const {
265 DCHECK(frame); 267 DCHECK(frame);
266 if (waiting_for_key_ && !frame->is_key_frame()) 268 if (waiting_for_key_ && !frame->is_key_frame())
267 return false; 269 return false;
268 return static_cast<uint32>(last_released_frame_ + 1) == frame->frame_id(); 270 return static_cast<uint32_t>(last_released_frame_ + 1) == frame->frame_id();
269 } 271 }
270 272
271 bool Framer::DecodableFrame(FrameBuffer* frame) const { 273 bool Framer::DecodableFrame(FrameBuffer* frame) const {
272 if (frame->is_key_frame()) 274 if (frame->is_key_frame())
273 return true; 275 return true;
274 if (waiting_for_key_ && !frame->is_key_frame()) 276 if (waiting_for_key_ && !frame->is_key_frame())
275 return false; 277 return false;
276 // Self-reference? 278 // Self-reference?
277 if (frame->last_referenced_frame_id() == frame->frame_id()) 279 if (frame->last_referenced_frame_id() == frame->frame_id())
278 return true; 280 return true;
279 281
280 // Current frame is not necessarily referencing the last frame. 282 // Current frame is not necessarily referencing the last frame.
281 // Do we have the reference frame? 283 // Do we have the reference frame?
282 if (IsOlderFrameId(frame->last_referenced_frame_id(), last_released_frame_)) { 284 if (IsOlderFrameId(frame->last_referenced_frame_id(), last_released_frame_)) {
283 return true; 285 return true;
284 } 286 }
285 return frame->last_referenced_frame_id() == last_released_frame_; 287 return frame->last_referenced_frame_id() == last_released_frame_;
286 } 288 }
287 289
288 290
289 } // namespace cast 291 } // namespace cast
290 } // namespace media 292 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698