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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 static const int kAgcMinus10db = -10; | 60 static const int kAgcMinus10db = -10; |
61 | 61 |
62 static void SafeSetError(const std::string& message, std::string* error_desc) { | 62 static void SafeSetError(const std::string& message, std::string* error_desc) { |
63 if (error_desc) { | 63 if (error_desc) { |
64 *error_desc = message; | 64 *error_desc = message; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 struct PacketMessageData : public rtc::MessageData { | 68 struct PacketMessageData : public rtc::MessageData { |
69 rtc::Buffer packet; | 69 rtc::Buffer packet; |
70 rtc::DiffServCodePoint dscp; | 70 rtc::PacketOptions options; |
71 }; | 71 }; |
72 | 72 |
73 struct ScreencastEventMessageData : public rtc::MessageData { | 73 struct ScreencastEventMessageData : public rtc::MessageData { |
74 ScreencastEventMessageData(uint32_t s, rtc::WindowEvent we) | 74 ScreencastEventMessageData(uint32_t s, rtc::WindowEvent we) |
75 : ssrc(s), event(we) {} | 75 : ssrc(s), event(we) {} |
76 uint32_t ssrc; | 76 uint32_t ssrc; |
77 rtc::WindowEvent event; | 77 rtc::WindowEvent event; |
78 }; | 78 }; |
79 | 79 |
80 struct VoiceChannelErrorMessageData : public rtc::MessageData { | 80 struct VoiceChannelErrorMessageData : public rtc::MessageData { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 bool BaseChannel::IsReadyToSend() const { | 416 bool BaseChannel::IsReadyToSend() const { |
417 // Send outgoing data if we are enabled, have local and remote content, | 417 // Send outgoing data if we are enabled, have local and remote content, |
418 // and we have had some form of connectivity. | 418 // and we have had some form of connectivity. |
419 return enabled() && | 419 return enabled() && |
420 IsReceiveContentDirection(remote_content_direction_) && | 420 IsReceiveContentDirection(remote_content_direction_) && |
421 IsSendContentDirection(local_content_direction_) && | 421 IsSendContentDirection(local_content_direction_) && |
422 was_ever_writable(); | 422 was_ever_writable(); |
423 } | 423 } |
424 | 424 |
425 bool BaseChannel::SendPacket(rtc::Buffer* packet, | 425 bool BaseChannel::SendPacket(rtc::Buffer* packet, |
426 rtc::DiffServCodePoint dscp) { | 426 const rtc::PacketOptions& options) { |
427 return SendPacket(false, packet, dscp); | 427 return SendPacket(false, packet, options); |
428 } | 428 } |
429 | 429 |
430 bool BaseChannel::SendRtcp(rtc::Buffer* packet, | 430 bool BaseChannel::SendRtcp(rtc::Buffer* packet, |
431 rtc::DiffServCodePoint dscp) { | 431 const rtc::PacketOptions& options) { |
432 return SendPacket(true, packet, dscp); | 432 return SendPacket(true, packet, options); |
433 } | 433 } |
434 | 434 |
435 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, | 435 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
436 int value) { | 436 int value) { |
437 TransportChannel* channel = NULL; | 437 TransportChannel* channel = NULL; |
438 switch (type) { | 438 switch (type) { |
439 case ST_RTP: | 439 case ST_RTP: |
440 channel = transport_channel_; | 440 channel = transport_channel_; |
441 socket_options_.push_back( | 441 socket_options_.push_back( |
442 std::pair<rtc::Socket::Option, int>(opt, value)); | 442 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); | 491 media_channel_->OnReadyToSend(false); |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 495 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, |
496 const char* data, size_t len) { | 496 const char* data, size_t len) { |
497 return (channel == rtcp_transport_channel_ || | 497 return (channel == rtcp_transport_channel_ || |
498 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 498 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
499 } | 499 } |
500 | 500 |
501 bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet, | 501 bool BaseChannel::SendPacket(bool rtcp, |
502 rtc::DiffServCodePoint dscp) { | 502 rtc::Buffer* packet, |
| 503 const rtc::PacketOptions& options) { |
503 // SendPacket gets called from MediaEngine, typically on an encoder thread. | 504 // 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 | 505 // 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 | 506 // 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 | 507 // synchronize access to all the pieces of the send path, including |
507 // SRTP and the inner workings of the transport channels. | 508 // SRTP and the inner workings of the transport channels. |
508 // The only downside is that we can't return a proper failure code if | 509 // 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. | 510 // needed. Since UDP is unreliable anyway, this should be a non-issue. |
510 if (rtc::Thread::Current() != worker_thread_) { | 511 if (rtc::Thread::Current() != worker_thread_) { |
511 // Avoid a copy by transferring the ownership of the packet data. | 512 // Avoid a copy by transferring the ownership of the packet data. |
512 int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; | 513 int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET; |
513 PacketMessageData* data = new PacketMessageData; | 514 PacketMessageData* data = new PacketMessageData; |
514 data->packet = packet->Pass(); | 515 data->packet = packet->Pass(); |
515 data->dscp = dscp; | 516 data->options = options; |
516 worker_thread_->Post(this, message_id, data); | 517 worker_thread_->Post(this, message_id, data); |
517 return true; | 518 return true; |
518 } | 519 } |
519 | 520 |
520 // Now that we are on the correct thread, ensure we have a place to send this | 521 // 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 | 522 // 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 | 523 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
523 // transport. | 524 // transport. |
524 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? | 525 TransportChannel* channel = (!rtcp || rtcp_mux_filter_.IsActive()) ? |
525 transport_channel_ : rtcp_transport_channel_; | 526 transport_channel_ : rtcp_transport_channel_; |
526 if (!channel || !channel->writable()) { | 527 if (!channel || !channel->writable()) { |
527 return false; | 528 return false; |
528 } | 529 } |
529 | 530 |
530 // Protect ourselves against crazy data. | 531 // Protect ourselves against crazy data. |
531 if (!ValidPacket(rtcp, packet)) { | 532 if (!ValidPacket(rtcp, packet)) { |
532 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 533 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
533 << PacketType(rtcp) | 534 << PacketType(rtcp) |
534 << " packet: wrong size=" << packet->size(); | 535 << " packet: wrong size=" << packet->size(); |
535 return false; | 536 return false; |
536 } | 537 } |
537 | 538 |
538 rtc::PacketOptions options(dscp); | 539 rtc::PacketOptions updated_options; |
| 540 updated_options = options; |
539 // Protect if needed. | 541 // Protect if needed. |
540 if (srtp_filter_.IsActive()) { | 542 if (srtp_filter_.IsActive()) { |
541 bool res; | 543 bool res; |
542 uint8_t* data = packet->data(); | 544 uint8_t* data = packet->data(); |
543 int len = static_cast<int>(packet->size()); | 545 int len = static_cast<int>(packet->size()); |
544 if (!rtcp) { | 546 if (!rtcp) { |
545 // If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done | 547 // 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 | 548 // 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. | 549 // a fake HMAC value. This is ONLY done for a RTP packet. |
548 // Socket layer will update rtp sendtime extension header if present in | 550 // Socket layer will update rtp sendtime extension header if present in |
549 // packet with current time before updating the HMAC. | 551 // packet with current time before updating the HMAC. |
550 #if !defined(ENABLE_EXTERNAL_AUTH) | 552 #if !defined(ENABLE_EXTERNAL_AUTH) |
551 res = srtp_filter_.ProtectRtp( | 553 res = srtp_filter_.ProtectRtp( |
552 data, len, static_cast<int>(packet->capacity()), &len); | 554 data, len, static_cast<int>(packet->capacity()), &len); |
553 #else | 555 #else |
554 options.packet_time_params.rtp_sendtime_extension_id = | 556 updated_options.packet_time_params.rtp_sendtime_extension_id = |
555 rtp_abs_sendtime_extn_id_; | 557 rtp_abs_sendtime_extn_id_; |
556 res = srtp_filter_.ProtectRtp( | 558 res = srtp_filter_.ProtectRtp( |
557 data, len, static_cast<int>(packet->capacity()), &len, | 559 data, len, static_cast<int>(packet->capacity()), &len, |
558 &options.packet_time_params.srtp_packet_index); | 560 &updated_options.packet_time_params.srtp_packet_index); |
559 // If protection succeeds, let's get auth params from srtp. | 561 // If protection succeeds, let's get auth params from srtp. |
560 if (res) { | 562 if (res) { |
561 uint8_t* auth_key = NULL; | 563 uint8_t* auth_key = NULL; |
562 int key_len; | 564 int key_len; |
563 res = srtp_filter_.GetRtpAuthParams( | 565 res = srtp_filter_.GetRtpAuthParams( |
564 &auth_key, &key_len, &options.packet_time_params.srtp_auth_tag_len); | 566 &auth_key, &key_len, |
| 567 &updated_options.packet_time_params.srtp_auth_tag_len); |
565 if (res) { | 568 if (res) { |
566 options.packet_time_params.srtp_auth_key.resize(key_len); | 569 updated_options.packet_time_params.srtp_auth_key.resize(key_len); |
567 options.packet_time_params.srtp_auth_key.assign(auth_key, | 570 updated_options.packet_time_params.srtp_auth_key.assign( |
568 auth_key + key_len); | 571 auth_key, auth_key + key_len); |
569 } | 572 } |
570 } | 573 } |
571 #endif | 574 #endif |
572 if (!res) { | 575 if (!res) { |
573 int seq_num = -1; | 576 int seq_num = -1; |
574 uint32_t ssrc = 0; | 577 uint32_t ssrc = 0; |
575 GetRtpSeqNum(data, len, &seq_num); | 578 GetRtpSeqNum(data, len, &seq_num); |
576 GetRtpSsrc(data, len, &ssrc); | 579 GetRtpSsrc(data, len, &ssrc); |
577 LOG(LS_ERROR) << "Failed to protect " << content_name_ | 580 LOG(LS_ERROR) << "Failed to protect " << content_name_ |
578 << " RTP packet: size=" << len | 581 << " RTP packet: size=" << len |
(...skipping 19 matching lines...) Expand all Loading... |
598 // This is a double check for something that supposedly can't happen. | 601 // This is a double check for something that supposedly can't happen. |
599 LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) | 602 LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp) |
600 << " packet when SRTP is inactive and crypto is required"; | 603 << " packet when SRTP is inactive and crypto is required"; |
601 | 604 |
602 ASSERT(false); | 605 ASSERT(false); |
603 return false; | 606 return false; |
604 } | 607 } |
605 | 608 |
606 // Bon voyage. | 609 // Bon voyage. |
607 int ret = | 610 int ret = |
608 channel->SendPacket(packet->data<char>(), packet->size(), options, | 611 channel->SendPacket(packet->data<char>(), packet->size(), updated_options, |
609 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); | 612 (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0); |
610 if (ret != static_cast<int>(packet->size())) { | 613 if (ret != static_cast<int>(packet->size())) { |
611 if (channel->GetError() == EWOULDBLOCK) { | 614 if (channel->GetError() == EWOULDBLOCK) { |
612 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; | 615 LOG(LS_WARNING) << "Got EWOULDBLOCK from socket."; |
613 SetReadyToSend(rtcp, false); | 616 SetReadyToSend(rtcp, false); |
614 } | 617 } |
615 return false; | 618 return false; |
616 } | 619 } |
617 return true; | 620 return true; |
618 } | 621 } |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 SafeSetError(desc.str(), error_desc); | 1139 SafeSetError(desc.str(), error_desc); |
1137 ret = false; | 1140 ret = false; |
1138 } | 1141 } |
1139 } | 1142 } |
1140 } | 1143 } |
1141 // Check for new streams. | 1144 // Check for new streams. |
1142 for (StreamParamsVec::const_iterator it = streams.begin(); | 1145 for (StreamParamsVec::const_iterator it = streams.begin(); |
1143 it != streams.end(); ++it) { | 1146 it != streams.end(); ++it) { |
1144 if (!GetStreamBySsrc(local_streams_, it->first_ssrc())) { | 1147 if (!GetStreamBySsrc(local_streams_, it->first_ssrc())) { |
1145 if (media_channel()->AddSendStream(*it)) { | 1148 if (media_channel()->AddSendStream(*it)) { |
1146 LOG(LS_INFO) << "Add send ssrc: " << it->ssrcs[0]; | 1149 LOG(LS_INFO) << "Add send stream ssrc: " << it->ssrcs[0]; |
1147 } else { | 1150 } else { |
1148 std::ostringstream desc; | 1151 std::ostringstream desc; |
1149 desc << "Failed to add send stream ssrc: " << it->first_ssrc(); | 1152 desc << "Failed to add send stream ssrc: " << it->first_ssrc(); |
1150 SafeSetError(desc.str(), error_desc); | 1153 SafeSetError(desc.str(), error_desc); |
1151 ret = false; | 1154 ret = false; |
1152 } | 1155 } |
1153 } | 1156 } |
1154 } | 1157 } |
1155 local_streams_ = streams; | 1158 local_streams_ = streams; |
1156 return ret; | 1159 return ret; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); | 1240 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); |
1238 rtp_abs_sendtime_extn_id_ = | 1241 rtp_abs_sendtime_extn_id_ = |
1239 send_time_extension ? send_time_extension->id : -1; | 1242 send_time_extension ? send_time_extension->id : -1; |
1240 } | 1243 } |
1241 | 1244 |
1242 void BaseChannel::OnMessage(rtc::Message *pmsg) { | 1245 void BaseChannel::OnMessage(rtc::Message *pmsg) { |
1243 switch (pmsg->message_id) { | 1246 switch (pmsg->message_id) { |
1244 case MSG_RTPPACKET: | 1247 case MSG_RTPPACKET: |
1245 case MSG_RTCPPACKET: { | 1248 case MSG_RTCPPACKET: { |
1246 PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); | 1249 PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata); |
1247 SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, data->dscp); | 1250 SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet, |
| 1251 data->options); |
1248 delete data; // because it is Posted | 1252 delete data; // because it is Posted |
1249 break; | 1253 break; |
1250 } | 1254 } |
1251 case MSG_FIRSTPACKETRECEIVED: { | 1255 case MSG_FIRSTPACKETRECEIVED: { |
1252 SignalFirstPacketReceived(this); | 1256 SignalFirstPacketReceived(this); |
1253 break; | 1257 break; |
1254 } | 1258 } |
1255 } | 1259 } |
1256 } | 1260 } |
1257 | 1261 |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 return (data_channel_type_ == DCT_RTP); | 2288 return (data_channel_type_ == DCT_RTP); |
2285 } | 2289 } |
2286 | 2290 |
2287 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2291 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2288 rtc::TypedMessageData<uint32_t>* message = | 2292 rtc::TypedMessageData<uint32_t>* message = |
2289 new rtc::TypedMessageData<uint32_t>(sid); | 2293 new rtc::TypedMessageData<uint32_t>(sid); |
2290 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2294 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2291 } | 2295 } |
2292 | 2296 |
2293 } // namespace cricket | 2297 } // namespace cricket |
OLD | NEW |