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

Side by Side Diff: webrtc/media/base/rtpdataengine.cc

Issue 2541583003: RtpDataEngine, FindCodecByName: Don't reassign codecs (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/media/base/rtpdataengine.h" 11 #include "webrtc/media/base/rtpdataengine.h"
12 12
13 #include "webrtc/base/copyonwritebuffer.h" 13 #include "webrtc/base/copyonwritebuffer.h"
14 #include "webrtc/base/helpers.h" 14 #include "webrtc/base/helpers.h"
15 #include "webrtc/base/logging.h" 15 #include "webrtc/base/logging.h"
16 #include "webrtc/base/ratelimiter.h" 16 #include "webrtc/base/ratelimiter.h"
17 #include "webrtc/base/stringutils.h"
17 #include "webrtc/media/base/codec.h" 18 #include "webrtc/media/base/codec.h"
18 #include "webrtc/media/base/mediaconstants.h" 19 #include "webrtc/media/base/mediaconstants.h"
19 #include "webrtc/media/base/rtputils.h" 20 #include "webrtc/media/base/rtputils.h"
20 #include "webrtc/media/base/streamparams.h" 21 #include "webrtc/media/base/streamparams.h"
21 22
22 namespace cricket { 23 namespace cricket {
23 24
24 // We want to avoid IP fragmentation. 25 // We want to avoid IP fragmentation.
25 static const size_t kDataMaxRtpPacketLen = 1200U; 26 static const size_t kDataMaxRtpPacketLen = 1200U;
26 // We reserve space after the RTP header for future wiggle room. 27 // We reserve space after the RTP header for future wiggle room.
(...skipping 12 matching lines...) Expand all
39 } 40 }
40 41
41 DataMediaChannel* RtpDataEngine::CreateChannel( 42 DataMediaChannel* RtpDataEngine::CreateChannel(
42 DataChannelType data_channel_type) { 43 DataChannelType data_channel_type) {
43 if (data_channel_type != DCT_RTP) { 44 if (data_channel_type != DCT_RTP) {
44 return NULL; 45 return NULL;
45 } 46 }
46 return new RtpDataMediaChannel(); 47 return new RtpDataMediaChannel();
47 } 48 }
48 49
49 bool FindCodecByName(const std::vector<DataCodec>& codecs, 50 static const DataCodec* FindCodecByName(const std::vector<DataCodec>& codecs,
50 const std::string& name, DataCodec* codec_out) { 51 const std::string& name) {
51 std::vector<DataCodec>::const_iterator iter; 52 for (const DataCodec& codec : codecs) {
52 for (iter = codecs.begin(); iter != codecs.end(); ++iter) { 53 if (_stricmp(name.c_str(), codec.name.c_str()) == 0)
53 if (iter->name == name) { 54 return &codec;
54 *codec_out = *iter;
55 return true;
56 }
57 } 55 }
58 return false; 56 return nullptr;
59 } 57 }
60 58
61 RtpDataMediaChannel::RtpDataMediaChannel() { 59 RtpDataMediaChannel::RtpDataMediaChannel() {
62 Construct(); 60 Construct();
63 } 61 }
64 62
65 void RtpDataMediaChannel::Construct() { 63 void RtpDataMediaChannel::Construct() {
66 sending_ = false; 64 sending_ = false;
67 receiving_ = false; 65 receiving_ = false;
68 send_limiter_.reset(new rtc::RateLimiter(kDataMaxBandwidth / 8, 1.0)); 66 send_limiter_.reset(new rtc::RateLimiter(kDataMaxBandwidth / 8, 1.0));
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 283 }
286 284
287 const StreamParams* found_stream = 285 const StreamParams* found_stream =
288 GetStreamBySsrc(send_streams_, params.ssrc); 286 GetStreamBySsrc(send_streams_, params.ssrc);
289 if (!found_stream) { 287 if (!found_stream) {
290 LOG(LS_WARNING) << "Not sending data because ssrc is unknown: " 288 LOG(LS_WARNING) << "Not sending data because ssrc is unknown: "
291 << params.ssrc; 289 << params.ssrc;
292 return false; 290 return false;
293 } 291 }
294 292
295 DataCodec found_codec; 293 const DataCodec* found_codec =
296 if (!FindCodecByName(send_codecs_, kGoogleRtpDataCodecName, &found_codec)) { 294 FindCodecByName(send_codecs_, kGoogleRtpDataCodecName);
295 if (!found_codec) {
297 LOG(LS_WARNING) << "Not sending data because codec is unknown: " 296 LOG(LS_WARNING) << "Not sending data because codec is unknown: "
298 << kGoogleRtpDataCodecName; 297 << kGoogleRtpDataCodecName;
299 return false; 298 return false;
300 } 299 }
301 300
302 size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace) + 301 size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace) +
303 payload.size() + kMaxSrtpHmacOverhead); 302 payload.size() + kMaxSrtpHmacOverhead);
304 if (packet_len > kDataMaxRtpPacketLen) { 303 if (packet_len > kDataMaxRtpPacketLen) {
305 return false; 304 return false;
306 } 305 }
307 306
308 double now = 307 double now =
309 rtc::TimeMicros() / static_cast<double>(rtc::kNumMicrosecsPerSec); 308 rtc::TimeMicros() / static_cast<double>(rtc::kNumMicrosecsPerSec);
310 309
311 if (!send_limiter_->CanUse(packet_len, now)) { 310 if (!send_limiter_->CanUse(packet_len, now)) {
312 LOG(LS_VERBOSE) << "Dropped data packet of len=" << packet_len 311 LOG(LS_VERBOSE) << "Dropped data packet of len=" << packet_len
313 << "; already sent " << send_limiter_->used_in_period() 312 << "; already sent " << send_limiter_->used_in_period()
314 << "/" << send_limiter_->max_per_period(); 313 << "/" << send_limiter_->max_per_period();
315 return false; 314 return false;
316 } 315 }
317 316
318 RtpHeader header; 317 RtpHeader header;
319 header.payload_type = found_codec.id; 318 header.payload_type = found_codec->id;
320 header.ssrc = params.ssrc; 319 header.ssrc = params.ssrc;
321 rtp_clock_by_send_ssrc_[header.ssrc]->Tick( 320 rtp_clock_by_send_ssrc_[header.ssrc]->Tick(
322 now, &header.seq_num, &header.timestamp); 321 now, &header.seq_num, &header.timestamp);
323 322
324 rtc::CopyOnWriteBuffer packet(kMinRtpPacketLen, packet_len); 323 rtc::CopyOnWriteBuffer packet(kMinRtpPacketLen, packet_len);
325 if (!SetRtpHeader(packet.data(), packet.size(), header)) { 324 if (!SetRtpHeader(packet.data(), packet.size(), header)) {
326 return false; 325 return false;
327 } 326 }
328 packet.AppendData(kReservedSpace); 327 packet.AppendData(kReservedSpace);
329 packet.AppendData(payload); 328 packet.AppendData(payload);
330 329
331 LOG(LS_VERBOSE) << "Sent RTP data packet: " 330 LOG(LS_VERBOSE) << "Sent RTP data packet: "
332 << " stream=" << found_stream->id << " ssrc=" << header.ssrc 331 << " stream=" << found_stream->id << " ssrc=" << header.ssrc
333 << ", seqnum=" << header.seq_num 332 << ", seqnum=" << header.seq_num
334 << ", timestamp=" << header.timestamp 333 << ", timestamp=" << header.timestamp
335 << ", len=" << payload.size(); 334 << ", len=" << payload.size();
336 335
337 MediaChannel::SendPacket(&packet, rtc::PacketOptions()); 336 MediaChannel::SendPacket(&packet, rtc::PacketOptions());
338 send_limiter_->Use(packet_len, now); 337 send_limiter_->Use(packet_len, now);
339 if (result) { 338 if (result) {
340 *result = SDR_SUCCESS; 339 *result = SDR_SUCCESS;
341 } 340 }
342 return true; 341 return true;
343 } 342 }
344 343
345 } // namespace cricket 344 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698