3 * Copyright 2004 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef TALK_SESSION_MEDIA_CHANNEL_H_
29 #define TALK_SESSION_MEDIA_CHANNEL_H_
34 #include "talk/media/base/mediachannel.h"
35 #include "talk/media/base/mediaengine.h"
36 #include "talk/media/base/streamparams.h"
37 #include "talk/media/base/videocapturer.h"
38 #include "webrtc/p2p/base/session.h"
39 #include "webrtc/p2p/client/socketmonitor.h"
40 #include "talk/session/media/audiomonitor.h"
41 #include "talk/session/media/bundlefilter.h"
42 #include "talk/session/media/mediamonitor.h"
43 #include "talk/session/media/mediasession.h"
44 #include "talk/session/media/rtcpmuxfilter.h"
45 #include "talk/session/media/srtpfilter.h"
46 #include "webrtc/base/asyncudpsocket.h"
47 #include "webrtc/base/criticalsection.h"
48 #include "webrtc/base/network.h"
49 #include "webrtc/base/sigslot.h"
50 #include "webrtc/base/window.h"
55 class MediaContentDescription;
56 struct TypingMonitorOptions;
61 SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption.
62 SINK_POST_CRYPTO // Sink packets after encryption or before decryption.
65 // BaseChannel contains logic common to voice and video, including
66 // enable/mute, marshaling calls to a worker thread, and
67 // connection and media monitors.
69 // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
70 // This is required to avoid a data race between the destructor modifying the
71 // vtable, and the media channel's thread using BaseChannel as the
75 : public rtc::MessageHandler, public sigslot::has_slots<>,
76 public MediaChannel::NetworkInterface {
78 BaseChannel(rtc::Thread* thread, MediaEngineInterface* media_engine,
79 MediaChannel* channel, BaseSession* session,
80 const std::string& content_name, bool rtcp);
81 virtual ~BaseChannel();
82 bool Init(TransportChannel* transport_channel,
83 TransportChannel* rtcp_transport_channel);
84 // Deinit may be called multiple times and is simply ignored if it's alreay
88 rtc::Thread* worker_thread() const { return worker_thread_; }
89 BaseSession* session() const { return session_; }
90 const std::string& content_name() { return content_name_; }
91 TransportChannel* transport_channel() const {
92 return transport_channel_;
94 TransportChannel* rtcp_transport_channel() const {
95 return rtcp_transport_channel_;
97 bool enabled() const { return enabled_; }
99 // This function returns true if we are using SRTP.
100 bool secure() const { return srtp_filter_.IsActive(); }
101 // The following function returns true if we are using
102 // DTLS-based keying. If you turned off SRTP later, however
103 // you could have secure() == false and dtls_secure() == true.
104 bool secure_dtls() const { return dtls_keyed_; }
105 // This function returns true if we require secure channel for call setup.
106 bool secure_required() const { return secure_required_; }
108 bool writable() const { return writable_; }
109 bool IsStreamMuted(uint32 ssrc);
112 bool SetLocalContent(const MediaContentDescription* content,
113 ContentAction action,
114 std::string* error_desc);
115 bool SetRemoteContent(const MediaContentDescription* content,
116 ContentAction action,
117 std::string* error_desc);
119 bool Enable(bool enable);
120 // Mute sending media on the stream with SSRC |ssrc|
121 // If there is only one sending stream SSRC 0 can be used.
122 bool MuteStream(uint32 ssrc, bool mute);
125 bool AddRecvStream(const StreamParams& sp);
126 bool RemoveRecvStream(uint32 ssrc);
127 bool AddSendStream(const StreamParams& sp);
128 bool RemoveSendStream(uint32 ssrc);
131 void StartConnectionMonitor(int cms);
132 void StopConnectionMonitor();
134 void set_srtp_signal_silent_time(uint32 silent_time) {
135 srtp_filter_.set_signal_silent_time(silent_time);
138 void set_content_name(const std::string& content_name) {
139 ASSERT(signaling_thread()->IsCurrent());
141 if (session_->state() != BaseSession::STATE_INIT) {
142 LOG(LS_ERROR) << "Content name for a channel can be changed only "
143 << "when BaseSession is in STATE_INIT state.";
146 content_name_ = content_name;
150 void RegisterSendSink(T* sink,
151 void (T::*OnPacket)(const void*, size_t, bool),
153 rtc::CritScope cs(&signal_send_packet_cs_);
154 if (SINK_POST_CRYPTO == type) {
155 SignalSendPacketPostCrypto.disconnect(sink);
156 SignalSendPacketPostCrypto.connect(sink, OnPacket);
158 SignalSendPacketPreCrypto.disconnect(sink);
159 SignalSendPacketPreCrypto.connect(sink, OnPacket);
163 void UnregisterSendSink(sigslot::has_slots<>* sink,
165 rtc::CritScope cs(&signal_send_packet_cs_);
166 if (SINK_POST_CRYPTO == type) {
167 SignalSendPacketPostCrypto.disconnect(sink);
169 SignalSendPacketPreCrypto.disconnect(sink);
173 bool HasSendSinks(SinkType type) {
174 rtc::CritScope cs(&signal_send_packet_cs_);
175 if (SINK_POST_CRYPTO == type) {
176 return !SignalSendPacketPostCrypto.is_empty();
178 return !SignalSendPacketPreCrypto.is_empty();
183 void RegisterRecvSink(T* sink,
184 void (T::*OnPacket)(const void*, size_t, bool),
186 rtc::CritScope cs(&signal_recv_packet_cs_);
187 if (SINK_POST_CRYPTO == type) {
188 SignalRecvPacketPostCrypto.disconnect(sink);
189 SignalRecvPacketPostCrypto.connect(sink, OnPacket);
191 SignalRecvPacketPreCrypto.disconnect(sink);
192 SignalRecvPacketPreCrypto.connect(sink, OnPacket);
196 void UnregisterRecvSink(sigslot::has_slots<>* sink,
198 rtc::CritScope cs(&signal_recv_packet_cs_);
199 if (SINK_POST_CRYPTO == type) {
200 SignalRecvPacketPostCrypto.disconnect(sink);
202 SignalRecvPacketPreCrypto.disconnect(sink);
206 bool HasRecvSinks(SinkType type) {
207 rtc::CritScope cs(&signal_recv_packet_cs_);
208 if (SINK_POST_CRYPTO == type) {
209 return !SignalRecvPacketPostCrypto.is_empty();
211 return !SignalRecvPacketPreCrypto.is_empty();
215 BundleFilter* bundle_filter() { return &bundle_filter_; }
217 const std::vector<StreamParams>& local_streams() const {
218 return local_streams_;
220 const std::vector<StreamParams>& remote_streams() const {
221 return remote_streams_;
224 // Used for latency measurements.
225 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
227 // Used to alert UI when the muted status changes, perhaps autonomously.
228 sigslot::repeater2<BaseChannel*, bool> SignalAutoMuted;
230 // Made public for easier testing.
231 void SetReadyToSend(TransportChannel* channel, bool ready);
234 MediaEngineInterface* media_engine() const { return media_engine_; }
235 virtual MediaChannel* media_channel() const { return media_channel_; }
236 void set_rtcp_transport_channel(TransportChannel* transport);
237 bool was_ever_writable() const { return was_ever_writable_; }
238 void set_local_content_direction(MediaContentDirection direction) {
239 local_content_direction_ = direction;
241 void set_remote_content_direction(MediaContentDirection direction) {
242 remote_content_direction_ = direction;
244 bool IsReadyToReceive() const;
245 bool IsReadyToSend() const;
246 rtc::Thread* signaling_thread() { return session_->signaling_thread(); }
247 SrtpFilter* srtp_filter() { return &srtp_filter_; }
248 bool rtcp() const { return rtcp_; }
250 void FlushRtcpMessages();
252 // NetworkInterface implementation, called by MediaEngine
253 virtual bool SendPacket(rtc::Buffer* packet,
254 rtc::DiffServCodePoint dscp);
255 virtual bool SendRtcp(rtc::Buffer* packet,
256 rtc::DiffServCodePoint dscp);
257 virtual int SetOption(SocketType type, rtc::Socket::Option o, int val);
259 // From TransportChannel
260 void OnWritableState(TransportChannel* channel);
261 virtual void OnChannelRead(TransportChannel* channel,
264 const rtc::PacketTime& packet_time,
266 void OnReadyToSend(TransportChannel* channel);
268 bool PacketIsRtcp(const TransportChannel* channel, const char* data,
270 bool SendPacket(bool rtcp, rtc::Buffer* packet,
271 rtc::DiffServCodePoint dscp);
272 virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet);
273 void HandlePacket(bool rtcp, rtc::Buffer* packet,
274 const rtc::PacketTime& packet_time);
276 // Apply the new local/remote session description.
277 void OnNewLocalDescription(BaseSession* session, ContentAction action);
278 void OnNewRemoteDescription(BaseSession* session, ContentAction action);
280 void EnableMedia_w();
281 void DisableMedia_w();
282 virtual bool MuteStream_w(uint32 ssrc, bool mute);
283 bool IsStreamMuted_w(uint32 ssrc);
284 void ChannelWritable_w();
285 void ChannelNotWritable_w();
286 bool AddRecvStream_w(const StreamParams& sp);
287 bool RemoveRecvStream_w(uint32 ssrc);
288 bool AddSendStream_w(const StreamParams& sp);
289 bool RemoveSendStream_w(uint32 ssrc);
290 virtual bool ShouldSetupDtlsSrtp() const;
291 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
292 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
293 bool SetupDtlsSrtp(bool rtcp_channel);
294 // Set the DTLS-SRTP cipher policy on this channel as appropriate.
295 bool SetDtlsSrtpCiphers(TransportChannel *tc, bool rtcp);
297 virtual void ChangeState() = 0;
299 // Gets the content info appropriate to the channel (audio or video).
300 virtual const ContentInfo* GetFirstContent(
301 const SessionDescription* sdesc) = 0;
302 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
303 ContentAction action,
304 std::string* error_desc);
305 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
306 ContentAction action,
307 std::string* error_desc);
308 bool SetBaseLocalContent_w(const MediaContentDescription* content,
309 ContentAction action,
310 std::string* error_desc);
311 virtual bool SetLocalContent_w(const MediaContentDescription* content,
312 ContentAction action,
313 std::string* error_desc) = 0;
314 bool SetBaseRemoteContent_w(const MediaContentDescription* content,
315 ContentAction action,
316 std::string* error_desc);
317 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
318 ContentAction action,
319 std::string* error_desc) = 0;
321 // Helper method to get RTP Absoulute SendTime extension header id if
322 // present in remote supported extensions list.
323 void MaybeCacheRtpAbsSendTimeHeaderExtension(
324 const std::vector<RtpHeaderExtension>& extensions);
326 bool SetRecvRtpHeaderExtensions_w(const MediaContentDescription* content,
327 MediaChannel* media_channel,
328 std::string* error_desc);
329 bool SetSendRtpHeaderExtensions_w(const MediaContentDescription* content,
330 MediaChannel* media_channel,
331 std::string* error_desc);
333 bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos,
335 std::string* error_desc);
336 bool SetSrtp_w(const std::vector<CryptoParams>& params,
337 ContentAction action,
339 std::string* error_desc);
340 bool SetRtcpMux_w(bool enable,
341 ContentAction action,
343 std::string* error_desc);
345 // From MessageHandler
346 virtual void OnMessage(rtc::Message* pmsg);
348 // Handled in derived classes
349 // Get the SRTP ciphers to use for RTP media
350 virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const = 0;
351 virtual void OnConnectionMonitorUpdate(SocketMonitor* monitor,
352 const std::vector<ConnectionInfo>& infos) = 0;
354 // Helper function for invoking bool-returning methods on the worker thread.
355 template <class FunctorT>
356 bool InvokeOnWorker(const FunctorT& functor) {
357 return worker_thread_->Invoke<bool>(functor);
361 sigslot::signal3<const void*, size_t, bool> SignalSendPacketPreCrypto;
362 sigslot::signal3<const void*, size_t, bool> SignalSendPacketPostCrypto;
363 sigslot::signal3<const void*, size_t, bool> SignalRecvPacketPreCrypto;
364 sigslot::signal3<const void*, size_t, bool> SignalRecvPacketPostCrypto;
365 rtc::CriticalSection signal_send_packet_cs_;
366 rtc::CriticalSection signal_recv_packet_cs_;
368 rtc::Thread* worker_thread_;
369 MediaEngineInterface* media_engine_;
370 BaseSession* session_;
371 MediaChannel* media_channel_;
372 std::vector<StreamParams> local_streams_;
373 std::vector<StreamParams> remote_streams_;
375 std::string content_name_;
377 TransportChannel* transport_channel_;
378 TransportChannel* rtcp_transport_channel_;
379 SrtpFilter srtp_filter_;
380 RtcpMuxFilter rtcp_mux_filter_;
381 BundleFilter bundle_filter_;
382 rtc::scoped_ptr<SocketMonitor> socket_monitor_;
385 bool rtp_ready_to_send_;
386 bool rtcp_ready_to_send_;
387 bool was_ever_writable_;
388 MediaContentDirection local_content_direction_;
389 MediaContentDirection remote_content_direction_;
390 std::set<uint32> muted_streams_;
391 bool has_received_packet_;
393 bool secure_required_;
394 int rtp_abs_sendtime_extn_id_;
397 // VoiceChannel is a specialization that adds support for early media, DTMF,
398 // and input/output level monitoring.
399 class VoiceChannel : public BaseChannel {
401 VoiceChannel(rtc::Thread* thread, MediaEngineInterface* media_engine,
402 VoiceMediaChannel* channel, BaseSession* session,
403 const std::string& content_name, bool rtcp);
406 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer);
407 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer);
409 // downcasts a MediaChannel
410 virtual VoiceMediaChannel* media_channel() const {
411 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
414 bool SetRingbackTone(const void* buf, int len);
415 void SetEarlyMedia(bool enable);
416 // This signal is emitted when we have gone a period of time without
417 // receiving early media. When received, a UI should start playing its
419 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
421 bool PlayRingbackTone(uint32 ssrc, bool play, bool loop);
422 // TODO(ronghuawu): Replace PressDTMF with InsertDtmf.
423 bool PressDTMF(int digit, bool playout);
424 // Returns if the telephone-event has been negotiated.
425 bool CanInsertDtmf();
426 // Send and/or play a DTMF |event| according to the |flags|.
427 // The DTMF out-of-band signal will be used on sending.
428 // The |ssrc| should be either 0 or a valid send stream ssrc.
429 // The valid value for the |event| are 0 which corresponding to DTMF
430 // event 0-9, *, #, A-D.
431 bool InsertDtmf(uint32 ssrc, int event_code, int duration, int flags);
432 bool SetOutputScaling(uint32 ssrc, double left, double right);
433 // Get statistics about the current media session.
434 bool GetStats(VoiceMediaInfo* stats);
436 // Monitoring functions
437 sigslot::signal2<VoiceChannel*, const std::vector<ConnectionInfo>&>
438 SignalConnectionMonitor;
440 void StartMediaMonitor(int cms);
441 void StopMediaMonitor();
442 sigslot::signal2<VoiceChannel*, const VoiceMediaInfo&> SignalMediaMonitor;
444 void StartAudioMonitor(int cms);
445 void StopAudioMonitor();
446 bool IsAudioMonitorRunning() const;
447 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
449 void StartTypingMonitor(const TypingMonitorOptions& settings);
450 void StopTypingMonitor();
451 bool IsTypingMonitorRunning() const;
453 // Overrides BaseChannel::MuteStream_w.
454 virtual bool MuteStream_w(uint32 ssrc, bool mute);
456 int GetInputLevel_w();
457 int GetOutputLevel_w();
458 void GetActiveStreams_w(AudioInfo::StreamList* actives);
460 // Signal errors from VoiceMediaChannel. Arguments are:
461 // ssrc(uint32), and error(VoiceMediaChannel::Error).
462 sigslot::signal3<VoiceChannel*, uint32, VoiceMediaChannel::Error>
465 // Configuration and setting.
466 bool SetChannelOptions(const AudioOptions& options);
469 // overrides from BaseChannel
470 virtual void OnChannelRead(TransportChannel* channel,
471 const char* data, size_t len,
472 const rtc::PacketTime& packet_time,
474 virtual void ChangeState();
475 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
476 virtual bool SetLocalContent_w(const MediaContentDescription* content,
477 ContentAction action,
478 std::string* error_desc);
479 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
480 ContentAction action,
481 std::string* error_desc);
482 bool SetRingbackTone_w(const void* buf, int len);
483 bool PlayRingbackTone_w(uint32 ssrc, bool play, bool loop);
484 void HandleEarlyMediaTimeout();
485 bool InsertDtmf_w(uint32 ssrc, int event, int duration, int flags);
486 bool SetOutputScaling_w(uint32 ssrc, double left, double right);
487 bool GetStats_w(VoiceMediaInfo* stats);
489 virtual void OnMessage(rtc::Message* pmsg);
490 virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const;
491 virtual void OnConnectionMonitorUpdate(
492 SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos);
493 virtual void OnMediaMonitorUpdate(
494 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info);
495 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
496 void OnVoiceChannelError(uint32 ssrc, VoiceMediaChannel::Error error);
497 void SendLastMediaError();
498 void OnSrtpError(uint32 ssrc, SrtpFilter::Mode mode, SrtpFilter::Error error);
500 static const int kEarlyMediaTimeout = 1000;
501 bool received_media_;
502 rtc::scoped_ptr<VoiceMediaMonitor> media_monitor_;
503 rtc::scoped_ptr<AudioMonitor> audio_monitor_;
504 rtc::scoped_ptr<TypingMonitor> typing_monitor_;
507 // VideoChannel is a specialization for video.
508 class VideoChannel : public BaseChannel {
510 VideoChannel(rtc::Thread* thread, MediaEngineInterface* media_engine,
511 VideoMediaChannel* channel, BaseSession* session,
512 const std::string& content_name, bool rtcp,
513 VoiceChannel* voice_channel);
517 bool SetRenderer(uint32 ssrc, VideoRenderer* renderer);
518 bool ApplyViewRequest(const ViewRequest& request);
520 // TODO(pthatcher): Refactor to use a "capture id" instead of an
521 // ssrc here as the "key".
522 // Passes ownership of the capturer to the channel.
523 bool AddScreencast(uint32 ssrc, VideoCapturer* capturer);
524 bool SetCapturer(uint32 ssrc, VideoCapturer* capturer);
525 bool RemoveScreencast(uint32 ssrc);
526 // True if we've added a screencast. Doesn't matter if the capturer
527 // has been started or not.
528 bool IsScreencasting();
529 int GetScreencastFps(uint32 ssrc);
530 int GetScreencastMaxPixels(uint32 ssrc);
531 // Get statistics about the current media session.
532 bool GetStats(const StatsOptions& options, VideoMediaInfo* stats);
534 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
535 SignalConnectionMonitor;
537 void StartMediaMonitor(int cms);
538 void StopMediaMonitor();
539 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
540 sigslot::signal2<uint32, rtc::WindowEvent> SignalScreencastWindowEvent;
542 bool SendIntraFrame();
543 bool RequestIntraFrame();
544 sigslot::signal3<VideoChannel*, uint32, VideoMediaChannel::Error>
547 // Configuration and setting.
548 bool SetChannelOptions(const VideoOptions& options);
551 // downcasts a MediaChannel
552 virtual VideoMediaChannel* media_channel() const {
553 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
557 typedef std::map<uint32, VideoCapturer*> ScreencastMap;
558 struct ScreencastDetailsData;
560 // overrides from BaseChannel
561 virtual void ChangeState();
562 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
563 virtual bool SetLocalContent_w(const MediaContentDescription* content,
564 ContentAction action,
565 std::string* error_desc);
566 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
567 ContentAction action,
568 std::string* error_desc);
569 bool ApplyViewRequest_w(const ViewRequest& request);
571 bool AddScreencast_w(uint32 ssrc, VideoCapturer* capturer);
572 bool RemoveScreencast_w(uint32 ssrc);
573 void OnScreencastWindowEvent_s(uint32 ssrc, rtc::WindowEvent we);
574 bool IsScreencasting_w() const;
575 void GetScreencastDetails_w(ScreencastDetailsData* d) const;
576 bool GetStats_w(VideoMediaInfo* stats);
578 virtual void OnMessage(rtc::Message* pmsg);
579 virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const;
580 virtual void OnConnectionMonitorUpdate(
581 SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos);
582 virtual void OnMediaMonitorUpdate(
583 VideoMediaChannel* media_channel, const VideoMediaInfo& info);
584 virtual void OnScreencastWindowEvent(uint32 ssrc,
585 rtc::WindowEvent event);
586 virtual void OnStateChange(VideoCapturer* capturer, CaptureState ev);
587 bool GetLocalSsrc(const VideoCapturer* capturer, uint32* ssrc);
589 void OnVideoChannelError(uint32 ssrc, VideoMediaChannel::Error error);
590 void OnSrtpError(uint32 ssrc, SrtpFilter::Mode mode, SrtpFilter::Error error);
592 VoiceChannel* voice_channel_;
593 VideoRenderer* renderer_;
594 ScreencastMap screencast_capturers_;
595 rtc::scoped_ptr<VideoMediaMonitor> media_monitor_;
597 rtc::WindowEvent previous_we_;
600 // DataChannel is a specialization for data.
601 class DataChannel : public BaseChannel {
603 DataChannel(rtc::Thread* thread,
604 DataMediaChannel* media_channel,
605 BaseSession* session,
606 const std::string& content_name,
611 virtual bool SendData(const SendDataParams& params,
612 const rtc::Buffer& payload,
613 SendDataResult* result);
615 void StartMediaMonitor(int cms);
616 void StopMediaMonitor();
618 // Should be called on the signaling thread only.
619 bool ready_to_send_data() const {
620 return ready_to_send_data_;
623 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
624 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
625 SignalConnectionMonitor;
626 sigslot::signal3<DataChannel*, uint32, DataMediaChannel::Error>
628 sigslot::signal3<DataChannel*,
629 const ReceiveDataParams&,
632 // Signal for notifying when the channel becomes ready to send data.
633 // That occurs when the channel is enabled, the transport is writable,
634 // both local and remote descriptions are set, and the channel is unblocked.
635 sigslot::signal1<bool> SignalReadyToSendData;
636 // Signal for notifying that the remote side has closed the DataChannel.
637 sigslot::signal1<uint32> SignalStreamClosedRemotely;
640 // downcasts a MediaChannel.
641 virtual DataMediaChannel* media_channel() const {
642 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
646 struct SendDataMessageData : public rtc::MessageData {
647 SendDataMessageData(const SendDataParams& params,
648 const rtc::Buffer* payload,
649 SendDataResult* result)
656 const SendDataParams& params;
657 const rtc::Buffer* payload;
658 SendDataResult* result;
662 struct DataReceivedMessageData : public rtc::MessageData {
663 // We copy the data because the data will become invalid after we
664 // handle DataMediaChannel::SignalDataReceived but before we fire
665 // SignalDataReceived.
666 DataReceivedMessageData(
667 const ReceiveDataParams& params, const char* data, size_t len)
671 const ReceiveDataParams params;
672 const rtc::Buffer payload;
675 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
677 // overrides from BaseChannel
678 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
679 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
680 // it's the same as what was set previously. Returns false if it's
681 // set to one type one type and changed to another type later.
682 bool SetDataChannelType(DataChannelType new_data_channel_type,
683 std::string* error_desc);
684 // Same as SetDataChannelType, but extracts the type from the
685 // DataContentDescription.
686 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
687 std::string* error_desc);
688 virtual bool SetLocalContent_w(const MediaContentDescription* content,
689 ContentAction action,
690 std::string* error_desc);
691 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
692 ContentAction action,
693 std::string* error_desc);
694 virtual void ChangeState();
695 virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet);
697 virtual void OnMessage(rtc::Message* pmsg);
698 virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const;
699 virtual void OnConnectionMonitorUpdate(
700 SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos);
701 virtual void OnMediaMonitorUpdate(
702 DataMediaChannel* media_channel, const DataMediaInfo& info);
703 virtual bool ShouldSetupDtlsSrtp() const;
705 const ReceiveDataParams& params, const char* data, size_t len);
706 void OnDataChannelError(uint32 ssrc, DataMediaChannel::Error error);
707 void OnDataChannelReadyToSend(bool writable);
708 void OnSrtpError(uint32 ssrc, SrtpFilter::Mode mode, SrtpFilter::Error error);
709 void OnStreamClosedRemotely(uint32 sid);
711 rtc::scoped_ptr<DataMediaMonitor> media_monitor_;
712 // TODO(pthatcher): Make a separate SctpDataChannel and
713 // RtpDataChannel instead of using this.
714 DataChannelType data_channel_type_;
715 bool ready_to_send_data_;
718 } // namespace cricket
720 #endif // TALK_SESSION_MEDIA_CHANNEL_H_