| OLD | NEW |
| 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/buffer.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/timing.h" | 17 #include "webrtc/base/timing.h" |
| 18 #include "webrtc/media/base/codec.h" | 18 #include "webrtc/media/base/codec.h" |
| 19 #include "webrtc/media/base/mediaconstants.h" | 19 #include "webrtc/media/base/mediaconstants.h" |
| 20 #include "webrtc/media/base/rtputils.h" | 20 #include "webrtc/media/base/rtputils.h" |
| 21 #include "webrtc/media/base/streamparams.h" | 21 #include "webrtc/media/base/streamparams.h" |
| 22 | 22 |
| 23 namespace cricket { | 23 namespace cricket { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 << "' with ssrc=" << stream.first_ssrc(); | 198 << "' with ssrc=" << stream.first_ssrc(); |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool RtpDataMediaChannel::RemoveRecvStream(uint32_t ssrc) { | 202 bool RtpDataMediaChannel::RemoveRecvStream(uint32_t ssrc) { |
| 203 RemoveStreamBySsrc(&recv_streams_, ssrc); | 203 RemoveStreamBySsrc(&recv_streams_, ssrc); |
| 204 return true; | 204 return true; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void RtpDataMediaChannel::OnPacketReceived( | 207 void RtpDataMediaChannel::OnPacketReceived( |
| 208 rtc::Buffer* packet, const rtc::PacketTime& packet_time) { | 208 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { |
| 209 RtpHeader header; | 209 RtpHeader header; |
| 210 if (!GetRtpHeader(packet->data(), packet->size(), &header)) { | 210 if (!GetRtpHeader(packet->cdata(), packet->size(), &header)) { |
| 211 // Don't want to log for every corrupt packet. | 211 // Don't want to log for every corrupt packet. |
| 212 // LOG(LS_WARNING) << "Could not read rtp header from packet of length " | 212 // LOG(LS_WARNING) << "Could not read rtp header from packet of length " |
| 213 // << packet->length() << "."; | 213 // << packet->length() << "."; |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 | 216 |
| 217 size_t header_length; | 217 size_t header_length; |
| 218 if (!GetRtpHeaderLen(packet->data(), packet->size(), &header_length)) { | 218 if (!GetRtpHeaderLen(packet->cdata(), packet->size(), &header_length)) { |
| 219 // Don't want to log for every corrupt packet. | 219 // Don't want to log for every corrupt packet. |
| 220 // LOG(LS_WARNING) << "Could not read rtp header" | 220 // LOG(LS_WARNING) << "Could not read rtp header" |
| 221 // << length from packet of length " | 221 // << length from packet of length " |
| 222 // << packet->length() << "."; | 222 // << packet->length() << "."; |
| 223 return; | 223 return; |
| 224 } | 224 } |
| 225 const char* data = | 225 const char* data = |
| 226 packet->data<char>() + header_length + sizeof(kReservedSpace); | 226 packet->cdata<char>() + header_length + sizeof(kReservedSpace); |
| 227 size_t data_len = packet->size() - header_length - sizeof(kReservedSpace); | 227 size_t data_len = packet->size() - header_length - sizeof(kReservedSpace); |
| 228 | 228 |
| 229 if (!receiving_) { | 229 if (!receiving_) { |
| 230 LOG(LS_WARNING) << "Not receiving packet " | 230 LOG(LS_WARNING) << "Not receiving packet " |
| 231 << header.ssrc << ":" << header.seq_num | 231 << header.ssrc << ":" << header.seq_num |
| 232 << " before SetReceive(true) called."; | 232 << " before SetReceive(true) called."; |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 | 235 |
| 236 DataCodec codec; | 236 DataCodec codec; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 if (bps <= 0) { | 269 if (bps <= 0) { |
| 270 bps = kDataMaxBandwidth; | 270 bps = kDataMaxBandwidth; |
| 271 } | 271 } |
| 272 send_limiter_.reset(new rtc::RateLimiter(bps / 8, 1.0)); | 272 send_limiter_.reset(new rtc::RateLimiter(bps / 8, 1.0)); |
| 273 LOG(LS_INFO) << "RtpDataMediaChannel::SetSendBandwidth to " << bps << "bps."; | 273 LOG(LS_INFO) << "RtpDataMediaChannel::SetSendBandwidth to " << bps << "bps."; |
| 274 return true; | 274 return true; |
| 275 } | 275 } |
| 276 | 276 |
| 277 bool RtpDataMediaChannel::SendData( | 277 bool RtpDataMediaChannel::SendData( |
| 278 const SendDataParams& params, | 278 const SendDataParams& params, |
| 279 const rtc::Buffer& payload, | 279 const rtc::CopyOnWriteBuffer& payload, |
| 280 SendDataResult* result) { | 280 SendDataResult* result) { |
| 281 if (result) { | 281 if (result) { |
| 282 // If we return true, we'll set this to SDR_SUCCESS. | 282 // If we return true, we'll set this to SDR_SUCCESS. |
| 283 *result = SDR_ERROR; | 283 *result = SDR_ERROR; |
| 284 } | 284 } |
| 285 if (!sending_) { | 285 if (!sending_) { |
| 286 LOG(LS_WARNING) << "Not sending packet with ssrc=" << params.ssrc | 286 LOG(LS_WARNING) << "Not sending packet with ssrc=" << params.ssrc |
| 287 << " len=" << payload.size() << " before SetSend(true)."; | 287 << " len=" << payload.size() << " before SetSend(true)."; |
| 288 return false; | 288 return false; |
| 289 } | 289 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 << "/" << send_limiter_->max_per_period(); | 322 << "/" << send_limiter_->max_per_period(); |
| 323 return false; | 323 return false; |
| 324 } | 324 } |
| 325 | 325 |
| 326 RtpHeader header; | 326 RtpHeader header; |
| 327 header.payload_type = found_codec.id; | 327 header.payload_type = found_codec.id; |
| 328 header.ssrc = params.ssrc; | 328 header.ssrc = params.ssrc; |
| 329 rtp_clock_by_send_ssrc_[header.ssrc]->Tick( | 329 rtp_clock_by_send_ssrc_[header.ssrc]->Tick( |
| 330 now, &header.seq_num, &header.timestamp); | 330 now, &header.seq_num, &header.timestamp); |
| 331 | 331 |
| 332 rtc::Buffer packet(kMinRtpPacketLen, packet_len); | 332 rtc::CopyOnWriteBuffer packet(kMinRtpPacketLen, packet_len); |
| 333 if (!SetRtpHeader(packet.data(), packet.size(), header)) { | 333 if (!SetRtpHeader(packet.data(), packet.size(), header)) { |
| 334 return false; | 334 return false; |
| 335 } | 335 } |
| 336 packet.AppendData(kReservedSpace); | 336 packet.AppendData(kReservedSpace); |
| 337 packet.AppendData(payload); | 337 packet.AppendData(payload); |
| 338 | 338 |
| 339 LOG(LS_VERBOSE) << "Sent RTP data packet: " | 339 LOG(LS_VERBOSE) << "Sent RTP data packet: " |
| 340 << " stream=" << found_stream->id << " ssrc=" << header.ssrc | 340 << " stream=" << found_stream->id << " ssrc=" << header.ssrc |
| 341 << ", seqnum=" << header.seq_num | 341 << ", seqnum=" << header.seq_num |
| 342 << ", timestamp=" << header.timestamp | 342 << ", timestamp=" << header.timestamp |
| 343 << ", len=" << payload.size(); | 343 << ", len=" << payload.size(); |
| 344 | 344 |
| 345 MediaChannel::SendPacket(&packet, rtc::PacketOptions()); | 345 MediaChannel::SendPacket(&packet, rtc::PacketOptions()); |
| 346 send_limiter_->Use(packet_len, now); | 346 send_limiter_->Use(packet_len, now); |
| 347 if (result) { | 347 if (result) { |
| 348 *result = SDR_SUCCESS; | 348 *result = SDR_SUCCESS; |
| 349 } | 349 } |
| 350 return true; | 350 return true; |
| 351 } | 351 } |
| 352 | 352 |
| 353 } // namespace cricket | 353 } // namespace cricket |
| OLD | NEW |