| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 BundleFilter* bundle_filter() { return &bundle_filter_; } | 143 BundleFilter* bundle_filter() { return &bundle_filter_; } |
| 144 | 144 |
| 145 const std::vector<StreamParams>& local_streams() const { | 145 const std::vector<StreamParams>& local_streams() const { |
| 146 return local_streams_; | 146 return local_streams_; |
| 147 } | 147 } |
| 148 const std::vector<StreamParams>& remote_streams() const { | 148 const std::vector<StreamParams>& remote_streams() const { |
| 149 return remote_streams_; | 149 return remote_streams_; |
| 150 } | 150 } |
| 151 | 151 |
| 152 sigslot::signal2<BaseChannel*, bool> SignalDtlsSrtpSetupFailure; | 152 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure; |
| 153 void SignalDtlsSrtpSetupFailure_n(bool rtcp); | 153 void SignalDtlsSetupFailure_n(bool rtcp); |
| 154 void SignalDtlsSrtpSetupFailure_s(bool rtcp); | 154 void SignalDtlsSetupFailure_s(bool rtcp); |
| 155 | 155 |
| 156 // Used for latency measurements. | 156 // Used for latency measurements. |
| 157 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; | 157 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; |
| 158 | 158 |
| 159 // Forward TransportChannel SignalSentPacket to worker thread. | 159 // Forward TransportChannel SignalSentPacket to worker thread. |
| 160 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket; | 160 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket; |
| 161 | 161 |
| 162 // Only public for unit tests. Otherwise, consider private. | 162 // Only public for unit tests. Otherwise, consider private. |
| 163 TransportChannel* transport_channel() const { return transport_channel_; } | 163 TransportChannel* transport_channel() const { return transport_channel_; } |
| 164 TransportChannel* rtcp_transport_channel() const { | 164 TransportChannel* rtcp_transport_channel() const { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 int last_sent_packet_id, | 254 int last_sent_packet_id, |
| 255 bool ready_to_send); | 255 bool ready_to_send); |
| 256 | 256 |
| 257 bool PacketIsRtcp(const rtc::PacketTransportInterface* transport, | 257 bool PacketIsRtcp(const rtc::PacketTransportInterface* transport, |
| 258 const char* data, | 258 const char* data, |
| 259 size_t len); | 259 size_t len); |
| 260 bool SendPacket(bool rtcp, | 260 bool SendPacket(bool rtcp, |
| 261 rtc::CopyOnWriteBuffer* packet, | 261 rtc::CopyOnWriteBuffer* packet, |
| 262 const rtc::PacketOptions& options); | 262 const rtc::PacketOptions& options); |
| 263 | 263 |
| 264 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); | 264 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); |
| 265 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, | 265 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, |
| 266 const rtc::PacketTime& packet_time); | 266 const rtc::PacketTime& packet_time); |
| 267 void OnPacketReceived(bool rtcp, | 267 void OnPacketReceived(bool rtcp, |
| 268 const rtc::CopyOnWriteBuffer& packet, | 268 const rtc::CopyOnWriteBuffer& packet, |
| 269 const rtc::PacketTime& packet_time); | 269 const rtc::PacketTime& packet_time); |
| 270 | 270 |
| 271 void EnableMedia_w(); | 271 void EnableMedia_w(); |
| 272 void DisableMedia_w(); | 272 void DisableMedia_w(); |
| 273 | 273 |
| 274 // Performs actions if the RTP/RTCP writable state changed. This should | 274 // Performs actions if the RTP/RTCP writable state changed. This should |
| 275 // be called whenever a channel's writable state changes or when RTCP muxing | 275 // be called whenever a channel's writable state changes or when RTCP muxing |
| 276 // becomes active/inactive. | 276 // becomes active/inactive. |
| 277 void UpdateWritableState_n(); | 277 void UpdateWritableState_n(); |
| 278 void ChannelWritable_n(); | 278 void ChannelWritable_n(); |
| 279 void ChannelNotWritable_n(); | 279 void ChannelNotWritable_n(); |
| 280 | 280 |
| 281 bool AddRecvStream_w(const StreamParams& sp); | 281 bool AddRecvStream_w(const StreamParams& sp); |
| 282 bool RemoveRecvStream_w(uint32_t ssrc); | 282 bool RemoveRecvStream_w(uint32_t ssrc); |
| 283 bool AddSendStream_w(const StreamParams& sp); | 283 bool AddSendStream_w(const StreamParams& sp); |
| 284 bool RemoveSendStream_w(uint32_t ssrc); | 284 bool RemoveSendStream_w(uint32_t ssrc); |
| 285 bool ShouldSetupDtlsSrtp_n() const; | 285 virtual bool ShouldSetupDtlsSrtp_n() const; |
| 286 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. | 286 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. |
| 287 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. | 287 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. |
| 288 bool SetupDtlsSrtp_n(bool rtcp_channel); | 288 bool SetupDtlsSrtp_n(bool rtcp_channel); |
| 289 void MaybeSetupDtlsSrtp_n(); | 289 void MaybeSetupDtlsSrtp_n(); |
| 290 // Set the DTLS-SRTP cipher policy on this channel as appropriate. | 290 // Set the DTLS-SRTP cipher policy on this channel as appropriate. |
| 291 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp); | 291 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp); |
| 292 | 292 |
| 293 // Should be called whenever the conditions for | 293 // Should be called whenever the conditions for |
| 294 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). | 294 // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 295 // Updates the send/recv state of the media channel. | 295 // Updates the send/recv state of the media channel. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 std::unique_ptr<VideoMediaMonitor> media_monitor_; | 608 std::unique_ptr<VideoMediaMonitor> media_monitor_; |
| 609 | 609 |
| 610 // Last VideoSendParameters sent down to the media_channel() via | 610 // Last VideoSendParameters sent down to the media_channel() via |
| 611 // SetSendParameters. | 611 // SetSendParameters. |
| 612 VideoSendParameters last_send_params_; | 612 VideoSendParameters last_send_params_; |
| 613 // Last VideoRecvParameters sent down to the media_channel() via | 613 // Last VideoRecvParameters sent down to the media_channel() via |
| 614 // SetRecvParameters. | 614 // SetRecvParameters. |
| 615 VideoRecvParameters last_recv_params_; | 615 VideoRecvParameters last_recv_params_; |
| 616 }; | 616 }; |
| 617 | 617 |
| 618 // RtpDataChannel is a specialization for data. | 618 // DataChannel is a specialization for data. |
| 619 class RtpDataChannel : public BaseChannel { | 619 class DataChannel : public BaseChannel { |
| 620 public: | 620 public: |
| 621 RtpDataChannel(rtc::Thread* worker_thread, | 621 DataChannel(rtc::Thread* worker_thread, |
| 622 rtc::Thread* network_thread, | 622 rtc::Thread* network_thread, |
| 623 DataMediaChannel* media_channel, | 623 DataMediaChannel* media_channel, |
| 624 TransportController* transport_controller, | 624 TransportController* transport_controller, |
| 625 const std::string& content_name, | 625 const std::string& content_name, |
| 626 bool rtcp, | 626 bool rtcp, |
| 627 bool srtp_required); | 627 bool srtp_required); |
| 628 ~RtpDataChannel(); | 628 ~DataChannel(); |
| 629 bool Init_w(const std::string* bundle_transport_name); | 629 bool Init_w(const std::string* bundle_transport_name); |
| 630 | 630 |
| 631 virtual bool SendData(const SendDataParams& params, | 631 virtual bool SendData(const SendDataParams& params, |
| 632 const rtc::CopyOnWriteBuffer& payload, | 632 const rtc::CopyOnWriteBuffer& payload, |
| 633 SendDataResult* result); | 633 SendDataResult* result); |
| 634 | 634 |
| 635 void StartMediaMonitor(int cms); | 635 void StartMediaMonitor(int cms); |
| 636 void StopMediaMonitor(); | 636 void StopMediaMonitor(); |
| 637 | 637 |
| 638 // Should be called on the signaling thread only. | 638 // Should be called on the signaling thread only. |
| 639 bool ready_to_send_data() const { | 639 bool ready_to_send_data() const { |
| 640 return ready_to_send_data_; | 640 return ready_to_send_data_; |
| 641 } | 641 } |
| 642 | 642 |
| 643 sigslot::signal2<RtpDataChannel*, const DataMediaInfo&> SignalMediaMonitor; | 643 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor; |
| 644 sigslot::signal2<RtpDataChannel*, const std::vector<ConnectionInfo>&> | 644 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&> |
| 645 SignalConnectionMonitor; | 645 SignalConnectionMonitor; |
| 646 | 646 sigslot::signal3<DataChannel*, const ReceiveDataParams&, |
| 647 sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&> | 647 const rtc::CopyOnWriteBuffer&> SignalDataReceived; |
| 648 SignalDataReceived; | |
| 649 // Signal for notifying when the channel becomes ready to send data. | 648 // Signal for notifying when the channel becomes ready to send data. |
| 650 // That occurs when the channel is enabled, the transport is writable, | 649 // That occurs when the channel is enabled, the transport is writable, |
| 651 // both local and remote descriptions are set, and the channel is unblocked. | 650 // both local and remote descriptions are set, and the channel is unblocked. |
| 652 sigslot::signal1<bool> SignalReadyToSendData; | 651 sigslot::signal1<bool> SignalReadyToSendData; |
| 652 // Signal for notifying that the remote side has closed the DataChannel. |
| 653 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; |
| 653 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; } | 654 cricket::MediaType media_type() override { return cricket::MEDIA_TYPE_DATA; } |
| 654 | 655 |
| 655 protected: | 656 protected: |
| 656 // downcasts a MediaChannel. | 657 // downcasts a MediaChannel. |
| 657 DataMediaChannel* media_channel() const override { | 658 DataMediaChannel* media_channel() const override { |
| 658 return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); | 659 return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); |
| 659 } | 660 } |
| 660 | 661 |
| 661 private: | 662 private: |
| 662 struct SendDataMessageData : public rtc::MessageData { | 663 struct SendDataMessageData : public rtc::MessageData { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 685 payload(data, len) { | 686 payload(data, len) { |
| 686 } | 687 } |
| 687 const ReceiveDataParams params; | 688 const ReceiveDataParams params; |
| 688 const rtc::CopyOnWriteBuffer payload; | 689 const rtc::CopyOnWriteBuffer payload; |
| 689 }; | 690 }; |
| 690 | 691 |
| 691 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; | 692 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; |
| 692 | 693 |
| 693 // overrides from BaseChannel | 694 // overrides from BaseChannel |
| 694 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override; | 695 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override; |
| 695 // Checks that data channel type is RTP. | 696 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that |
| 696 bool CheckDataChannelTypeFromContent(const DataContentDescription* content, | 697 // it's the same as what was set previously. Returns false if it's |
| 697 std::string* error_desc); | 698 // set to one type one type and changed to another type later. |
| 699 bool SetDataChannelType(DataChannelType new_data_channel_type, |
| 700 std::string* error_desc); |
| 701 // Same as SetDataChannelType, but extracts the type from the |
| 702 // DataContentDescription. |
| 703 bool SetDataChannelTypeFromContent(const DataContentDescription* content, |
| 704 std::string* error_desc); |
| 698 bool SetLocalContent_w(const MediaContentDescription* content, | 705 bool SetLocalContent_w(const MediaContentDescription* content, |
| 699 ContentAction action, | 706 ContentAction action, |
| 700 std::string* error_desc) override; | 707 std::string* error_desc) override; |
| 701 bool SetRemoteContent_w(const MediaContentDescription* content, | 708 bool SetRemoteContent_w(const MediaContentDescription* content, |
| 702 ContentAction action, | 709 ContentAction action, |
| 703 std::string* error_desc) override; | 710 std::string* error_desc) override; |
| 704 void UpdateMediaSendRecvState_w() override; | 711 void UpdateMediaSendRecvState_w() override; |
| 712 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override; |
| 705 | 713 |
| 706 void OnMessage(rtc::Message* pmsg) override; | 714 void OnMessage(rtc::Message* pmsg) override; |
| 707 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override; | 715 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override; |
| 708 void OnConnectionMonitorUpdate( | 716 void OnConnectionMonitorUpdate( |
| 709 ConnectionMonitor* monitor, | 717 ConnectionMonitor* monitor, |
| 710 const std::vector<ConnectionInfo>& infos) override; | 718 const std::vector<ConnectionInfo>& infos) override; |
| 711 void OnMediaMonitorUpdate(DataMediaChannel* media_channel, | 719 void OnMediaMonitorUpdate(DataMediaChannel* media_channel, |
| 712 const DataMediaInfo& info); | 720 const DataMediaInfo& info); |
| 721 bool ShouldSetupDtlsSrtp_n() const override; |
| 713 void OnDataReceived( | 722 void OnDataReceived( |
| 714 const ReceiveDataParams& params, const char* data, size_t len); | 723 const ReceiveDataParams& params, const char* data, size_t len); |
| 715 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error); | 724 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error); |
| 716 void OnDataChannelReadyToSend(bool writable); | 725 void OnDataChannelReadyToSend(bool writable); |
| 726 void OnStreamClosedRemotely(uint32_t sid); |
| 717 | 727 |
| 718 std::unique_ptr<DataMediaMonitor> media_monitor_; | 728 std::unique_ptr<DataMediaMonitor> media_monitor_; |
| 719 bool ready_to_send_data_ = false; | 729 // TODO(pthatcher): Make a separate SctpDataChannel and |
| 730 // RtpDataChannel instead of using this. |
| 731 DataChannelType data_channel_type_; |
| 732 bool ready_to_send_data_; |
| 720 | 733 |
| 721 // Last DataSendParameters sent down to the media_channel() via | 734 // Last DataSendParameters sent down to the media_channel() via |
| 722 // SetSendParameters. | 735 // SetSendParameters. |
| 723 DataSendParameters last_send_params_; | 736 DataSendParameters last_send_params_; |
| 724 // Last DataRecvParameters sent down to the media_channel() via | 737 // Last DataRecvParameters sent down to the media_channel() via |
| 725 // SetRecvParameters. | 738 // SetRecvParameters. |
| 726 DataRecvParameters last_recv_params_; | 739 DataRecvParameters last_recv_params_; |
| 727 }; | 740 }; |
| 728 | 741 |
| 729 } // namespace cricket | 742 } // namespace cricket |
| 730 | 743 |
| 731 #endif // WEBRTC_PC_CHANNEL_H_ | 744 #endif // WEBRTC_PC_CHANNEL_H_ |
| OLD | NEW |