| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "talk/media/base/constants.h" | 30 #include "talk/media/base/constants.h" |
| 31 #include "talk/media/base/rtputils.h" | 31 #include "talk/media/base/rtputils.h" |
| 32 #include "webrtc/p2p/base/transportchannel.h" | 32 #include "webrtc/p2p/base/transportchannel.h" |
| 33 #include "talk/session/media/channelmanager.h" | 33 #include "talk/session/media/channelmanager.h" |
| 34 #include "webrtc/base/bind.h" | 34 #include "webrtc/base/bind.h" |
| 35 #include "webrtc/base/buffer.h" | 35 #include "webrtc/base/buffer.h" |
| 36 #include "webrtc/base/byteorder.h" | 36 #include "webrtc/base/byteorder.h" |
| 37 #include "webrtc/base/common.h" | 37 #include "webrtc/base/common.h" |
| 38 #include "webrtc/base/dscp.h" | 38 #include "webrtc/base/dscp.h" |
| 39 #include "webrtc/base/logging.h" | 39 #include "webrtc/base/logging.h" |
| 40 #include "webrtc/call.h" |
| 41 #include "webrtc/common_types.h" |
| 40 | 42 |
| 41 namespace cricket { | 43 namespace cricket { |
| 42 | 44 |
| 43 using rtc::Bind; | 45 using rtc::Bind; |
| 44 | 46 |
| 45 enum { | 47 enum { |
| 46 MSG_EARLYMEDIATIMEOUT = 1, | 48 MSG_EARLYMEDIATIMEOUT = 1, |
| 47 MSG_SCREENCASTWINDOWEVENT, | 49 MSG_SCREENCASTWINDOWEVENT, |
| 48 MSG_RTPPACKET, | 50 MSG_RTPPACKET, |
| 49 MSG_RTCPPACKET, | 51 MSG_RTCPPACKET, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 60 static const int kAgcMinus10db = -10; | 62 static const int kAgcMinus10db = -10; |
| 61 | 63 |
| 62 static void SafeSetError(const std::string& message, std::string* error_desc) { | 64 static void SafeSetError(const std::string& message, std::string* error_desc) { |
| 63 if (error_desc) { | 65 if (error_desc) { |
| 64 *error_desc = message; | 66 *error_desc = message; |
| 65 } | 67 } |
| 66 } | 68 } |
| 67 | 69 |
| 68 struct PacketMessageData : public rtc::MessageData { | 70 struct PacketMessageData : public rtc::MessageData { |
| 69 rtc::Buffer packet; | 71 rtc::Buffer packet; |
| 70 rtc::DiffServCodePoint dscp; | 72 rtc::PacketOptions options; |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 struct ScreencastEventMessageData : public rtc::MessageData { | 75 struct ScreencastEventMessageData : public rtc::MessageData { |
| 74 ScreencastEventMessageData(uint32_t s, rtc::WindowEvent we) | 76 ScreencastEventMessageData(uint32_t s, rtc::WindowEvent we) |
| 75 : ssrc(s), event(we) {} | 77 : ssrc(s), event(we) {} |
| 76 uint32_t ssrc; | 78 uint32_t ssrc; |
| 77 rtc::WindowEvent event; | 79 rtc::WindowEvent event; |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 struct VoiceChannelErrorMessageData : public rtc::MessageData { | 82 struct VoiceChannelErrorMessageData : public rtc::MessageData { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 bool BaseChannel::IsReadyToSend() const { | 418 bool BaseChannel::IsReadyToSend() const { |
| 417 // Send outgoing data if we are enabled, have local and remote content, | 419 // Send outgoing data if we are enabled, have local and remote content, |
| 418 // and we have had some form of connectivity. | 420 // and we have had some form of connectivity. |
| 419 return enabled() && | 421 return enabled() && |
| 420 IsReceiveContentDirection(remote_content_direction_) && | 422 IsReceiveContentDirection(remote_content_direction_) && |
| 421 IsSendContentDirection(local_content_direction_) && | 423 IsSendContentDirection(local_content_direction_) && |
| 422 was_ever_writable(); | 424 was_ever_writable(); |
| 423 } | 425 } |
| 424 | 426 |
| 425 bool BaseChannel::SendPacket(rtc::Buffer* packet, | 427 bool BaseChannel::SendPacket(rtc::Buffer* packet, |
| 426 rtc::DiffServCodePoint dscp) { | 428 const rtc::PacketOptions& options) { |
| 427 return SendPacket(false, packet, dscp); | 429 return SendPacket(false, packet, options); |
| 428 } | 430 } |
| 429 | 431 |
| 430 bool BaseChannel::SendRtcp(rtc::Buffer* packet, | 432 bool BaseChannel::SendRtcp(rtc::Buffer* packet, |
| 431 rtc::DiffServCodePoint dscp) { | 433 const rtc::PacketOptions& options) { |
| 432 return SendPacket(true, packet, dscp); | 434 return SendPacket(true, packet, options); |
| 433 } | 435 } |
| 434 | 436 |
| 435 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, | 437 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
| 436 int value) { | 438 int value) { |
| 437 TransportChannel* channel = NULL; | 439 TransportChannel* channel = NULL; |
| 438 switch (type) { | 440 switch (type) { |
| 439 case ST_RTP: | 441 case ST_RTP: |
| 440 channel = transport_channel_; | 442 channel = transport_channel_; |
| 441 socket_options_.push_back( | 443 socket_options_.push_back( |
| 442 std::pair<rtc::Socket::Option, int>(opt, value)); | 444 std::pair<rtc::Socket::Option, int>(opt, value)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 media_channel_->OnReadyToSend(false); | 493 media_channel_->OnReadyToSend(false); |
| 492 } | 494 } |
| 493 } | 495 } |
| 494 | 496 |
| 495 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 497 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, |
| 496 const char* data, size_t len) { | 498 const char* data, size_t len) { |
| 497 return (channel == rtcp_transport_channel_ || | 499 return (channel == rtcp_transport_channel_ || |
| 498 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 500 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
| 499 } | 501 } |
| 500 | 502 |
| 501 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, | 503 bool BaseChannel::SendPacket(bool rtcp, |
| 502 rtc::DiffServCodePoint dscp) { | 504 rtc::Buffer* packet, |
| 505 const rtc::PacketOptions& options) { |
| 503 // SendPacket gets called from MediaEngine, typically on an encoder thread. | 506 // SendPacket gets called from MediaEngine, typically on an encoder thread. |
| 504 // If the thread is not our worker thread, we will post to our worker | 507 // If the thread is not our worker thread, we will post to our worker |
| 505 // so that the real work happens on our worker. This avoids us having to | 508 // so that the real work happens on our worker. This avoids us having to |
| 506 // synchronize access to all the pieces of the send path, including | 509 // synchronize access to all the pieces of the send path, including |
| 507 // SRTP and the inner workings of the transport channels. | 510 // SRTP and the inner workings of the transport channels. |
| 508 // The only downside is that we can't return a proper failure code if | 511 // The only downside is that we can't return a proper failure code if |
| 509 // needed. Since UDP is unreliable anyway, this should be a non-issue. | 512 // needed. Since UDP is unreliable anyway, this should be a non-issue. |
| 510 if (rtc::Thread::Current() != worker_thread_) { | 513 if (rtc::Thread::Current() != worker_thread_) { |
| 511 // Avoid a copy by transferring the ownership of the packet data. | 514 // Avoid a copy by transferring the ownership of the packet data. |
| 512 int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; | 515 int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; |
| 513 PacketMessageData* data = new PacketMessageData; | 516 PacketMessageData* data = new PacketMessageData; |
| 514 data->packet = packet->Pass(); | 517 data->packet = packet->Pass(); |
| 515 data->dscp = dscp; | 518 data->options = options; |
| 516 worker_thread_->Post(this, message_id, data); | 519 worker_thread_->Post(this, message_id, data); |
| 517 return true; | 520 return true; |
| 518 } | 521 } |
| 519 | 522 |
| 520 // Now that we are on the correct thread, ensure we have a place to send this | 523 // Now that we are on the correct thread, ensure we have a place to send this |
| 521 // packet before doing anything. (We might get RTCP packets that we don't | 524 // packet before doing anything. (We might get RTCP packets that we don't |
| 522 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 525 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
| 523 // transport. | 526 // transport. |
| 524 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? | 527 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? |
| 525 transport_channel_ : rtcp_transport_channel_; | 528 transport_channel_ : rtcp_transport_channel_; |
| 526 if (!channel || !channel->writable()) { | 529 if (!channel || !channel->writable()) { |
| 527 return false; | 530 return false; |
| 528 } | 531 } |
| 529 | 532 |
| 530 // Protect ourselves against crazy data. | 533 // Protect ourselves against crazy data. |
| 531 if (!ValidPacket(rtcp, packet)) { | 534 if (!ValidPacket(rtcp, packet)) { |
| 532 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 535 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
| 533 << PacketType(rtcp) | 536 << PacketType(rtcp) |
| 534 << " packet: wrong size=" << packet->size(); | 537 << " packet: wrong size=" << packet->size(); |
| 535 return false; | 538 return false; |
| 536 } | 539 } |
| 537 | 540 |
| 538 rtc::PacketOptions options(dscp); | 541 rtc::PacketOptions updated_options; |
| 542 updated_options = options; |
| 539 // Protect if needed. | 543 // Protect if needed. |
| 540 if (srtp_filter_.IsActive()) { | 544 if (srtp_filter_.IsActive()) { |
| 541 bool res; | 545 bool res; |
| 542 uint8_t* data = packet->data(); | 546 uint8_t* data = packet->data(); |
| 543 int len = static_cast<int>(packet->size()); | 547 int len = static_cast<int>(packet->size()); |
| 544 if (!rtcp) { | 548 if (!rtcp) { |
| 545 // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done | 549 // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done |
| 546 // inside libsrtp for a RTP packet. A external HMAC module will be writing | 550 // inside libsrtp for a RTP packet. A external HMAC module will be writing |
| 547 // a fake HMAC value. This is ONLY done for a RTP packet. | 551 // a fake HMAC value. This is ONLY done for a RTP packet. |
| 548 // Socket layer will update rtp sendtime extension header if present in | 552 // Socket layer will update rtp sendtime extension header if present in |
| 549 // packet with current time before updating the HMAC. | 553 // packet with current time before updating the HMAC. |
| 550 #if !defined(ENABLE_EXTERNAL_AUTH) | 554 #if !defined(ENABLE_EXTERNAL_AUTH) |
| 551 res = srtp_filter_.ProtectRtp( | 555 res = srtp_filter_.ProtectRtp( |
| 552 data, len, static_cast<int>(packet->capacity()), &len); | 556 data, len, static_cast<int>(packet->capacity()), &len); |
| 553 #else | 557 #else |
| 554 options.packet_time_params.rtp_sendtime_extension_id = | 558 updated_options.packet_time_params.rtp_sendtime_extension_id = |
| 555 rtp_abs_sendtime_extn_id_; | 559 rtp_abs_sendtime_extn_id_; |
| 556 res = srtp_filter_.ProtectRtp( | 560 res = srtp_filter_.ProtectRtp( |
| 557 data, len, static_cast<int>(packet->capacity()), &len, | 561 data, len, static_cast<int>(packet->capacity()), &len, |
| 558 &options.packet_time_params.srtp_packet_index); | 562 &updated_options.packet_time_params.srtp_packet_index); |
| 559 // If protection succeeds, let's get auth params from srtp. | 563 // If protection succeeds, let's get auth params from srtp. |
| 560 if (res) { | 564 if (res) { |
| 561 uint8_t* auth_key = NULL; | 565 uint8_t* auth_key = NULL; |
| 562 int key_len; | 566 int key_len; |
| 563 res = srtp_filter_.GetRtpAuthParams( | 567 res = srtp_filter_.GetRtpAuthParams( |
| 564 &auth_key, &key_len, &options.packet_time_params.srtp_auth_tag_len); | 568 &auth_key, &key_len, |
| 569 &updated_options.packet_time_params.srtp_auth_tag_len); |
| 565 if (res) { | 570 if (res) { |
| 566 options.packet_time_params.srtp_auth_key.resize(key_len); | 571 updated_options.packet_time_params.srtp_auth_key.resize(key_len); |
| 567 options.packet_time_params.srtp_auth_key.assign(auth_key, | 572 updated_options.packet_time_params.srtp_auth_key.assign( |
| 568 auth_key + key_len); | 573 auth_key, auth_key + key_len); |
| 569 } | 574 } |
| 570 } | 575 } |
| 571 #endif | 576 #endif |
| 572 if (!res) { | 577 if (!res) { |
| 573 int seq_num = -1; | 578 int seq_num = -1; |
| 574 uint32_t ssrc = 0; | 579 uint32_t ssrc = 0; |
| 575 GetRtpSeqNum(data, len, &seq_num); | 580 GetRtpSeqNum(data, len, &seq_num); |
| 576 GetRtpSsrc(data, len, &ssrc); | 581 GetRtpSsrc(data, len, &ssrc); |
| 577 LOG(LS_ERROR) << "Failed to protect " << content_name_ | 582 LOG(LS_ERROR) << "Failed to protect " << content_name_ |
| 578 << " RTP packet: size=" << len | 583 << " RTP packet: size=" << len |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 SafeSetError(desc.str(), error_desc); | 1141 SafeSetError(desc.str(), error_desc); |
| 1137 ret = false; | 1142 ret = false; |
| 1138 } | 1143 } |
| 1139 } | 1144 } |
| 1140 } | 1145 } |
| 1141 // Check for new streams. | 1146 // Check for new streams. |
| 1142 for (StreamParamsVec::const_iterator it = streams.begin(); | 1147 for (StreamParamsVec::const_iterator it = streams.begin(); |
| 1143 it != streams.end(); ++it) { | 1148 it != streams.end(); ++it) { |
| 1144 if (!GetStreamBySsrc(local_streams_, it->first_ssrc())) { | 1149 if (!GetStreamBySsrc(local_streams_, it->first_ssrc())) { |
| 1145 if (media_channel()->AddSendStream(*it)) { | 1150 if (media_channel()->AddSendStream(*it)) { |
| 1146 LOG(LS_INFO) << "Add send ssrc: " << it->ssrcs[0]; | 1151 LOG(LS_INFO) << "Add send stream ssrc: " << it->ssrcs[0]; |
| 1147 } else { | 1152 } else { |
| 1148 std::ostringstream desc; | 1153 std::ostringstream desc; |
| 1149 desc << "Failed to add send stream ssrc: " << it->first_ssrc(); | 1154 desc << "Failed to add send stream ssrc: " << it->first_ssrc(); |
| 1150 SafeSetError(desc.str(), error_desc); | 1155 SafeSetError(desc.str(), error_desc); |
| 1151 ret = false; | 1156 ret = false; |
| 1152 } | 1157 } |
| 1153 } | 1158 } |
| 1154 } | 1159 } |
| 1155 local_streams_ = streams; | 1160 local_streams_ = streams; |
| 1156 return ret; | 1161 return ret; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); | 1242 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); |
| 1238 rtp_abs_sendtime_extn_id_ = | 1243 rtp_abs_sendtime_extn_id_ = |
| 1239 send_time_extension ? send_time_extension->id : -1; | 1244 send_time_extension ? send_time_extension->id : -1; |
| 1240 } | 1245 } |
| 1241 | 1246 |
| 1242 void BaseChannel::OnMessage(rtc::Message *pmsg) { | 1247 void BaseChannel::OnMessage(rtc::Message *pmsg) { |
| 1243 switch (pmsg->message_id) { | 1248 switch (pmsg->message_id) { |
| 1244 case MSG_RTPPACKET: | 1249 case MSG_RTPPACKET: |
| 1245 case MSG_RTCPPACKET: { | 1250 case MSG_RTCPPACKET: { |
| 1246 PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); | 1251 PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); |
| 1247 SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, data->dscp); | 1252 SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, |
| 1253 data->options); |
| 1248 delete data; // because it is Posted | 1254 delete data; // because it is Posted |
| 1249 break; | 1255 break; |
| 1250 } | 1256 } |
| 1251 case MSG_FIRSTPACKETRECEIVED: { | 1257 case MSG_FIRSTPACKETRECEIVED: { |
| 1252 SignalFirstPacketReceived(this); | 1258 SignalFirstPacketReceived(this); |
| 1253 break; | 1259 break; |
| 1254 } | 1260 } |
| 1255 } | 1261 } |
| 1256 } | 1262 } |
| 1257 | 1263 |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2292 return (data_channel_type_ == DCT_RTP); | 2298 return (data_channel_type_ == DCT_RTP); |
| 2293 } | 2299 } |
| 2294 | 2300 |
| 2295 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2301 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2296 rtc::TypedMessageData<uint32_t>* message = | 2302 rtc::TypedMessageData<uint32_t>* message = |
| 2297 new rtc::TypedMessageData<uint32_t>(sid); | 2303 new rtc::TypedMessageData<uint32_t>(sid); |
| 2298 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2304 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2299 } | 2305 } |
| 2300 | 2306 |
| 2301 } // namespace cricket | 2307 } // namespace cricket |
| OLD | NEW |