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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "talk/session/media/mediamonitor.h" | 45 #include "talk/session/media/mediamonitor.h" |
46 #include "talk/session/media/mediasession.h" | 46 #include "talk/session/media/mediasession.h" |
47 #include "talk/session/media/rtcpmuxfilter.h" | 47 #include "talk/session/media/rtcpmuxfilter.h" |
48 #include "talk/session/media/srtpfilter.h" | 48 #include "talk/session/media/srtpfilter.h" |
49 #include "webrtc/base/asyncudpsocket.h" | 49 #include "webrtc/base/asyncudpsocket.h" |
50 #include "webrtc/base/criticalsection.h" | 50 #include "webrtc/base/criticalsection.h" |
51 #include "webrtc/base/network.h" | 51 #include "webrtc/base/network.h" |
52 #include "webrtc/base/sigslot.h" | 52 #include "webrtc/base/sigslot.h" |
53 #include "webrtc/base/window.h" | 53 #include "webrtc/base/window.h" |
54 | 54 |
| 55 namespace webrtc { |
| 56 class MediaControllerInterface; |
| 57 } // namespace webrtc |
| 58 |
55 namespace cricket { | 59 namespace cricket { |
56 | 60 |
57 struct CryptoParams; | 61 struct CryptoParams; |
58 class MediaContentDescription; | 62 class MediaContentDescription; |
59 struct ViewRequest; | 63 struct ViewRequest; |
60 | 64 |
61 enum SinkType { | 65 enum SinkType { |
62 SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption. | 66 SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption. |
63 SINK_POST_CRYPTO // Sink packets after encryption or before decryption. | 67 SINK_POST_CRYPTO // Sink packets after encryption or before decryption. |
64 }; | 68 }; |
65 | 69 |
66 // BaseChannel contains logic common to voice and video, including | 70 // BaseChannel contains logic common to voice and video, including |
67 // enable, marshaling calls to a worker thread, and | 71 // enable, marshaling calls to a worker thread, and |
68 // connection and media monitors. | 72 // connection and media monitors. |
69 // | 73 // |
70 // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! | 74 // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! |
71 // This is required to avoid a data race between the destructor modifying the | 75 // This is required to avoid a data race between the destructor modifying the |
72 // vtable, and the media channel's thread using BaseChannel as the | 76 // vtable, and the media channel's thread using BaseChannel as the |
73 // NetworkInterface. | 77 // NetworkInterface. |
74 | 78 |
75 class BaseChannel | 79 class BaseChannel |
76 : public rtc::MessageHandler, public sigslot::has_slots<>, | 80 : public rtc::MessageHandler, public sigslot::has_slots<>, |
77 public MediaChannel::NetworkInterface, | 81 public MediaChannel::NetworkInterface, |
78 public ConnectionStatsGetter { | 82 public ConnectionStatsGetter { |
79 public: | 83 public: |
80 BaseChannel(rtc::Thread* thread, | 84 BaseChannel(rtc::Thread* thread, |
81 MediaChannel* channel, | 85 MediaChannel* channel, |
| 86 webrtc::MediaControllerInterface* media_controller, |
82 TransportController* transport_controller, | 87 TransportController* transport_controller, |
83 const std::string& content_name, | 88 const std::string& content_name, |
84 bool rtcp); | 89 bool rtcp); |
85 virtual ~BaseChannel(); | 90 virtual ~BaseChannel(); |
86 bool Init(); | 91 bool Init(); |
87 // Deinit may be called multiple times and is simply ignored if it's alreay | 92 // Deinit may be called multiple times and is simply ignored if it's alreay |
88 // done. | 93 // done. |
89 void Deinit(); | 94 void Deinit(); |
90 | 95 |
91 rtc::Thread* worker_thread() const { return worker_thread_; } | 96 rtc::Thread* worker_thread() const { return worker_thread_; } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 197 } |
193 bool rtcp_transport_enabled() const { return rtcp_transport_enabled_; } | 198 bool rtcp_transport_enabled() const { return rtcp_transport_enabled_; } |
194 | 199 |
195 void ConnectToTransportChannel(TransportChannel* tc); | 200 void ConnectToTransportChannel(TransportChannel* tc); |
196 void DisconnectFromTransportChannel(TransportChannel* tc); | 201 void DisconnectFromTransportChannel(TransportChannel* tc); |
197 | 202 |
198 void FlushRtcpMessages(); | 203 void FlushRtcpMessages(); |
199 | 204 |
200 // NetworkInterface implementation, called by MediaEngine | 205 // NetworkInterface implementation, called by MediaEngine |
201 virtual bool SendPacket(rtc::Buffer* packet, | 206 virtual bool SendPacket(rtc::Buffer* packet, |
202 rtc::DiffServCodePoint dscp); | 207 const rtc::PacketOptions& options); |
203 virtual bool SendRtcp(rtc::Buffer* packet, | 208 virtual bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options); |
204 rtc::DiffServCodePoint dscp); | |
205 | 209 |
206 // From TransportChannel | 210 // From TransportChannel |
207 void OnWritableState(TransportChannel* channel); | 211 void OnWritableState(TransportChannel* channel); |
208 virtual void OnChannelRead(TransportChannel* channel, | 212 virtual void OnChannelRead(TransportChannel* channel, |
209 const char* data, | 213 const char* data, |
210 size_t len, | 214 size_t len, |
211 const rtc::PacketTime& packet_time, | 215 const rtc::PacketTime& packet_time, |
212 int flags); | 216 int flags); |
213 void OnReadyToSend(TransportChannel* channel); | 217 void OnReadyToSend(TransportChannel* channel); |
214 | 218 |
215 bool PacketIsRtcp(const TransportChannel* channel, const char* data, | 219 bool PacketIsRtcp(const TransportChannel* channel, const char* data, |
216 size_t len); | 220 size_t len); |
217 bool SendPacket(bool rtcp, rtc::Buffer* packet, | 221 bool SendPacket(bool rtcp, |
218 rtc::DiffServCodePoint dscp); | 222 rtc::Buffer* packet, |
| 223 const rtc::PacketOptions& options); |
219 virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet); | 224 virtual bool WantsPacket(bool rtcp, rtc::Buffer* packet); |
220 void HandlePacket(bool rtcp, rtc::Buffer* packet, | 225 void HandlePacket(bool rtcp, rtc::Buffer* packet, |
221 const rtc::PacketTime& packet_time); | 226 const rtc::PacketTime& packet_time); |
222 | 227 |
223 void EnableMedia_w(); | 228 void EnableMedia_w(); |
224 void DisableMedia_w(); | 229 void DisableMedia_w(); |
225 void UpdateWritableState_w(); | 230 void UpdateWritableState_w(); |
226 void ChannelWritable_w(); | 231 void ChannelWritable_w(); |
227 void ChannelNotWritable_w(); | 232 void ChannelNotWritable_w(); |
228 bool AddRecvStream_w(const StreamParams& sp); | 233 bool AddRecvStream_w(const StreamParams& sp); |
(...skipping 25 matching lines...) Expand all Loading... |
254 ContentAction action, | 259 ContentAction action, |
255 std::string* error_desc) = 0; | 260 std::string* error_desc) = 0; |
256 bool SetRtpTransportParameters_w(const MediaContentDescription* content, | 261 bool SetRtpTransportParameters_w(const MediaContentDescription* content, |
257 ContentAction action, | 262 ContentAction action, |
258 ContentSource src, | 263 ContentSource src, |
259 std::string* error_desc); | 264 std::string* error_desc); |
260 | 265 |
261 // Helper method to get RTP Absoulute SendTime extension header id if | 266 // Helper method to get RTP Absoulute SendTime extension header id if |
262 // present in remote supported extensions list. | 267 // present in remote supported extensions list. |
263 void MaybeCacheRtpAbsSendTimeHeaderExtension( | 268 void MaybeCacheRtpAbsSendTimeHeaderExtension( |
264 const std::vector<RtpHeaderExtension>& extensions); | 269 const std::vector<RtpHeaderExtension>& extensions); |
265 | 270 |
266 bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, | 271 bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, |
267 bool* dtls, | 272 bool* dtls, |
268 std::string* error_desc); | 273 std::string* error_desc); |
269 bool SetSrtp_w(const std::vector<CryptoParams>& params, | 274 bool SetSrtp_w(const std::vector<CryptoParams>& params, |
270 ContentAction action, | 275 ContentAction action, |
271 ContentSource src, | 276 ContentSource src, |
272 std::string* error_desc); | 277 std::string* error_desc); |
273 void ActivateRtcpMux_w(); | 278 void ActivateRtcpMux_w(); |
274 bool SetRtcpMux_w(bool enable, | 279 bool SetRtcpMux_w(bool enable, |
(...skipping 14 matching lines...) Expand all Loading... |
289 // Helper function for invoking bool-returning methods on the worker thread. | 294 // Helper function for invoking bool-returning methods on the worker thread. |
290 template <class FunctorT> | 295 template <class FunctorT> |
291 bool InvokeOnWorker(const FunctorT& functor) { | 296 bool InvokeOnWorker(const FunctorT& functor) { |
292 return worker_thread_->Invoke<bool>(functor); | 297 return worker_thread_->Invoke<bool>(functor); |
293 } | 298 } |
294 | 299 |
295 private: | 300 private: |
296 rtc::Thread* worker_thread_; | 301 rtc::Thread* worker_thread_; |
297 TransportController* transport_controller_; | 302 TransportController* transport_controller_; |
298 MediaChannel* media_channel_; | 303 MediaChannel* media_channel_; |
| 304 webrtc::MediaControllerInterface* const media_controller_; |
299 std::vector<StreamParams> local_streams_; | 305 std::vector<StreamParams> local_streams_; |
300 std::vector<StreamParams> remote_streams_; | 306 std::vector<StreamParams> remote_streams_; |
301 | 307 |
302 const std::string content_name_; | 308 const std::string content_name_; |
303 std::string transport_name_; | 309 std::string transport_name_; |
304 bool rtcp_transport_enabled_; | 310 bool rtcp_transport_enabled_; |
305 TransportChannel* transport_channel_; | 311 TransportChannel* transport_channel_; |
306 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; | 312 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; |
307 TransportChannel* rtcp_transport_channel_; | 313 TransportChannel* rtcp_transport_channel_; |
308 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; | 314 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; |
(...skipping 14 matching lines...) Expand all Loading... |
323 int rtp_abs_sendtime_extn_id_; | 329 int rtp_abs_sendtime_extn_id_; |
324 }; | 330 }; |
325 | 331 |
326 // VoiceChannel is a specialization that adds support for early media, DTMF, | 332 // VoiceChannel is a specialization that adds support for early media, DTMF, |
327 // and input/output level monitoring. | 333 // and input/output level monitoring. |
328 class VoiceChannel : public BaseChannel { | 334 class VoiceChannel : public BaseChannel { |
329 public: | 335 public: |
330 VoiceChannel(rtc::Thread* thread, | 336 VoiceChannel(rtc::Thread* thread, |
331 MediaEngineInterface* media_engine, | 337 MediaEngineInterface* media_engine, |
332 VoiceMediaChannel* channel, | 338 VoiceMediaChannel* channel, |
| 339 webrtc::MediaControllerInterface* media_controller, |
333 TransportController* transport_controller, | 340 TransportController* transport_controller, |
334 const std::string& content_name, | 341 const std::string& content_name, |
335 bool rtcp); | 342 bool rtcp); |
336 ~VoiceChannel(); | 343 ~VoiceChannel(); |
337 bool Init(); | 344 bool Init(); |
338 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer); | 345 bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer); |
339 | 346 |
340 // Configure sending media on the stream with SSRC |ssrc| | 347 // Configure sending media on the stream with SSRC |ssrc| |
341 // If there is only one sending stream SSRC 0 can be used. | 348 // If there is only one sending stream SSRC 0 can be used. |
342 bool SetAudioSend(uint32 ssrc, | 349 bool SetAudioSend(uint32 ssrc, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // Last AudioRecvParameters sent down to the media_channel() via | 432 // Last AudioRecvParameters sent down to the media_channel() via |
426 // SetRecvParameters. | 433 // SetRecvParameters. |
427 AudioRecvParameters last_recv_params_; | 434 AudioRecvParameters last_recv_params_; |
428 }; | 435 }; |
429 | 436 |
430 // VideoChannel is a specialization for video. | 437 // VideoChannel is a specialization for video. |
431 class VideoChannel : public BaseChannel { | 438 class VideoChannel : public BaseChannel { |
432 public: | 439 public: |
433 VideoChannel(rtc::Thread* thread, | 440 VideoChannel(rtc::Thread* thread, |
434 VideoMediaChannel* channel, | 441 VideoMediaChannel* channel, |
| 442 webrtc::MediaControllerInterface* media_controller, |
435 TransportController* transport_controller, | 443 TransportController* transport_controller, |
436 const std::string& content_name, | 444 const std::string& content_name, |
437 bool rtcp); | 445 bool rtcp); |
438 ~VideoChannel(); | 446 ~VideoChannel(); |
439 bool Init(); | 447 bool Init(); |
440 | 448 |
441 // downcasts a MediaChannel | 449 // downcasts a MediaChannel |
442 virtual VideoMediaChannel* media_channel() const { | 450 virtual VideoMediaChannel* media_channel() const { |
443 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); | 451 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); |
444 } | 452 } |
(...skipping 19 matching lines...) Expand all Loading... |
464 SignalConnectionMonitor; | 472 SignalConnectionMonitor; |
465 | 473 |
466 void StartMediaMonitor(int cms); | 474 void StartMediaMonitor(int cms); |
467 void StopMediaMonitor(); | 475 void StopMediaMonitor(); |
468 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor; | 476 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor; |
469 sigslot::signal2<uint32, rtc::WindowEvent> SignalScreencastWindowEvent; | 477 sigslot::signal2<uint32, rtc::WindowEvent> SignalScreencastWindowEvent; |
470 | 478 |
471 bool SendIntraFrame(); | 479 bool SendIntraFrame(); |
472 bool RequestIntraFrame(); | 480 bool RequestIntraFrame(); |
473 | 481 |
474 // Configure sending media on the stream with SSRC |ssrc| | |
475 // If there is only one sending stream SSRC 0 can be used. | |
476 bool SetVideoSend(uint32 ssrc, bool enable, const VideoOptions* options); | 482 bool SetVideoSend(uint32 ssrc, bool enable, const VideoOptions* options); |
477 | 483 |
478 private: | 484 private: |
479 typedef std::map<uint32, VideoCapturer*> ScreencastMap; | 485 typedef std::map<uint32, VideoCapturer*> ScreencastMap; |
480 struct ScreencastDetailsData; | 486 struct ScreencastDetailsData; |
481 | 487 |
482 // overrides from BaseChannel | 488 // overrides from BaseChannel |
483 virtual void ChangeState(); | 489 virtual void ChangeState(); |
484 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); | 490 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); |
485 virtual bool SetLocalContent_w(const MediaContentDescription* content, | 491 virtual bool SetLocalContent_w(const MediaContentDescription* content, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // SetSendParameters. | 646 // SetSendParameters. |
641 DataSendParameters last_send_params_; | 647 DataSendParameters last_send_params_; |
642 // Last DataRecvParameters sent down to the media_channel() via | 648 // Last DataRecvParameters sent down to the media_channel() via |
643 // SetRecvParameters. | 649 // SetRecvParameters. |
644 DataRecvParameters last_recv_params_; | 650 DataRecvParameters last_recv_params_; |
645 }; | 651 }; |
646 | 652 |
647 } // namespace cricket | 653 } // namespace cricket |
648 | 654 |
649 #endif // TALK_SESSION_MEDIA_CHANNEL_H_ | 655 #endif // TALK_SESSION_MEDIA_CHANNEL_H_ |
OLD | NEW |