OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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 |
11 #ifndef WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ |
12 #define WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ | 12 #define WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/basictypes.h" | 18 #include "webrtc/base/basictypes.h" |
19 #include "webrtc/base/buffer.h" | 19 #include "webrtc/base/copyonwritebuffer.h" |
20 #include "webrtc/base/dscp.h" | 20 #include "webrtc/base/dscp.h" |
21 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/optional.h" | 22 #include "webrtc/base/optional.h" |
23 #include "webrtc/base/sigslot.h" | 23 #include "webrtc/base/sigslot.h" |
24 #include "webrtc/base/socket.h" | 24 #include "webrtc/base/socket.h" |
25 #include "webrtc/base/window.h" | 25 #include "webrtc/base/window.h" |
26 #include "webrtc/media/base/codec.h" | 26 #include "webrtc/media/base/codec.h" |
27 #include "webrtc/media/base/mediaconstants.h" | 27 #include "webrtc/media/base/mediaconstants.h" |
28 #include "webrtc/media/base/streamparams.h" | 28 #include "webrtc/media/base/streamparams.h" |
29 #include "webrtc/media/base/videosinkinterface.h" | 29 #include "webrtc/media/base/videosinkinterface.h" |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 return &(*it); | 337 return &(*it); |
338 } | 338 } |
339 return NULL; | 339 return NULL; |
340 } | 340 } |
341 | 341 |
342 class MediaChannel : public sigslot::has_slots<> { | 342 class MediaChannel : public sigslot::has_slots<> { |
343 public: | 343 public: |
344 class NetworkInterface { | 344 class NetworkInterface { |
345 public: | 345 public: |
346 enum SocketType { ST_RTP, ST_RTCP }; | 346 enum SocketType { ST_RTP, ST_RTCP }; |
347 virtual bool SendPacket(rtc::Buffer* packet, | 347 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
348 const rtc::PacketOptions& options) = 0; | 348 const rtc::PacketOptions& options) = 0; |
349 virtual bool SendRtcp(rtc::Buffer* packet, | 349 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
350 const rtc::PacketOptions& options) = 0; | 350 const rtc::PacketOptions& options) = 0; |
351 virtual int SetOption(SocketType type, rtc::Socket::Option opt, | 351 virtual int SetOption(SocketType type, rtc::Socket::Option opt, |
352 int option) = 0; | 352 int option) = 0; |
353 virtual ~NetworkInterface() {} | 353 virtual ~NetworkInterface() {} |
354 }; | 354 }; |
355 | 355 |
356 MediaChannel(const MediaConfig& config) | 356 MediaChannel(const MediaConfig& config) |
357 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {} | 357 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {} |
358 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {} | 358 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {} |
359 virtual ~MediaChannel() {} | 359 virtual ~MediaChannel() {} |
360 | 360 |
361 // Sets the abstract interface class for sending RTP/RTCP data. | 361 // Sets the abstract interface class for sending RTP/RTCP data. |
362 virtual void SetInterface(NetworkInterface *iface) { | 362 virtual void SetInterface(NetworkInterface *iface) { |
363 rtc::CritScope cs(&network_interface_crit_); | 363 rtc::CritScope cs(&network_interface_crit_); |
364 network_interface_ = iface; | 364 network_interface_ = iface; |
365 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT); | 365 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT); |
366 } | 366 } |
367 virtual rtc::DiffServCodePoint PreferredDscp() const { | 367 virtual rtc::DiffServCodePoint PreferredDscp() const { |
368 return rtc::DSCP_DEFAULT; | 368 return rtc::DSCP_DEFAULT; |
369 } | 369 } |
370 // Called when a RTP packet is received. | 370 // Called when a RTP packet is received. |
371 virtual void OnPacketReceived(rtc::Buffer* packet, | 371 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
372 const rtc::PacketTime& packet_time) = 0; | 372 const rtc::PacketTime& packet_time) = 0; |
373 // Called when a RTCP packet is received. | 373 // Called when a RTCP packet is received. |
374 virtual void OnRtcpReceived(rtc::Buffer* packet, | 374 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
375 const rtc::PacketTime& packet_time) = 0; | 375 const rtc::PacketTime& packet_time) = 0; |
376 // Called when the socket's ability to send has changed. | 376 // Called when the socket's ability to send has changed. |
377 virtual void OnReadyToSend(bool ready) = 0; | 377 virtual void OnReadyToSend(bool ready) = 0; |
378 // Creates a new outgoing media stream with SSRCs and CNAME as described | 378 // Creates a new outgoing media stream with SSRCs and CNAME as described |
379 // by sp. | 379 // by sp. |
380 virtual bool AddSendStream(const StreamParams& sp) = 0; | 380 virtual bool AddSendStream(const StreamParams& sp) = 0; |
381 // Removes an outgoing media stream. | 381 // Removes an outgoing media stream. |
382 // ssrc must be the first SSRC of the media stream if the stream uses | 382 // ssrc must be the first SSRC of the media stream if the stream uses |
383 // multiple SSRCs. | 383 // multiple SSRCs. |
384 virtual bool RemoveSendStream(uint32_t ssrc) = 0; | 384 virtual bool RemoveSendStream(uint32_t ssrc) = 0; |
385 // Creates a new incoming media stream with SSRCs and CNAME as described | 385 // Creates a new incoming media stream with SSRCs and CNAME as described |
386 // by sp. | 386 // by sp. |
387 virtual bool AddRecvStream(const StreamParams& sp) = 0; | 387 virtual bool AddRecvStream(const StreamParams& sp) = 0; |
388 // Removes an incoming media stream. | 388 // Removes an incoming media stream. |
389 // ssrc must be the first SSRC of the media stream if the stream uses | 389 // ssrc must be the first SSRC of the media stream if the stream uses |
390 // multiple SSRCs. | 390 // multiple SSRCs. |
391 virtual bool RemoveRecvStream(uint32_t ssrc) = 0; | 391 virtual bool RemoveRecvStream(uint32_t ssrc) = 0; |
392 | 392 |
393 // Returns the absoulte sendtime extension id value from media channel. | 393 // Returns the absoulte sendtime extension id value from media channel. |
394 virtual int GetRtpSendTimeExtnId() const { | 394 virtual int GetRtpSendTimeExtnId() const { |
395 return -1; | 395 return -1; |
396 } | 396 } |
397 | 397 |
398 // Base method to send packet using NetworkInterface. | 398 // Base method to send packet using NetworkInterface. |
399 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) { | 399 bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 400 const rtc::PacketOptions& options) { |
400 return DoSendPacket(packet, false, options); | 401 return DoSendPacket(packet, false, options); |
401 } | 402 } |
402 | 403 |
403 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) { | 404 bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 405 const rtc::PacketOptions& options) { |
404 return DoSendPacket(packet, true, options); | 406 return DoSendPacket(packet, true, options); |
405 } | 407 } |
406 | 408 |
407 int SetOption(NetworkInterface::SocketType type, | 409 int SetOption(NetworkInterface::SocketType type, |
408 rtc::Socket::Option opt, | 410 rtc::Socket::Option opt, |
409 int option) { | 411 int option) { |
410 rtc::CritScope cs(&network_interface_crit_); | 412 rtc::CritScope cs(&network_interface_crit_); |
411 if (!network_interface_) | 413 if (!network_interface_) |
412 return -1; | 414 return -1; |
413 | 415 |
414 return network_interface_->SetOption(type, opt, option); | 416 return network_interface_->SetOption(type, opt, option); |
415 } | 417 } |
416 | 418 |
417 private: | 419 private: |
418 // This method sets DSCP |value| on both RTP and RTCP channels. | 420 // This method sets DSCP |value| on both RTP and RTCP channels. |
419 int SetDscp(rtc::DiffServCodePoint value) { | 421 int SetDscp(rtc::DiffServCodePoint value) { |
420 int ret; | 422 int ret; |
421 ret = SetOption(NetworkInterface::ST_RTP, | 423 ret = SetOption(NetworkInterface::ST_RTP, |
422 rtc::Socket::OPT_DSCP, | 424 rtc::Socket::OPT_DSCP, |
423 value); | 425 value); |
424 if (ret == 0) { | 426 if (ret == 0) { |
425 ret = SetOption(NetworkInterface::ST_RTCP, | 427 ret = SetOption(NetworkInterface::ST_RTCP, |
426 rtc::Socket::OPT_DSCP, | 428 rtc::Socket::OPT_DSCP, |
427 value); | 429 value); |
428 } | 430 } |
429 return ret; | 431 return ret; |
430 } | 432 } |
431 | 433 |
432 bool DoSendPacket(rtc::Buffer* packet, | 434 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet, |
433 bool rtcp, | 435 bool rtcp, |
434 const rtc::PacketOptions& options) { | 436 const rtc::PacketOptions& options) { |
435 rtc::CritScope cs(&network_interface_crit_); | 437 rtc::CritScope cs(&network_interface_crit_); |
436 if (!network_interface_) | 438 if (!network_interface_) |
437 return false; | 439 return false; |
438 | 440 |
439 return (!rtcp) ? network_interface_->SendPacket(packet, options) | 441 return (!rtcp) ? network_interface_->SendPacket(packet, options) |
440 : network_interface_->SendRtcp(packet, options); | 442 : network_interface_->SendRtcp(packet, options); |
441 } | 443 } |
442 | 444 |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0; | 1091 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0; |
1090 | 1092 |
1091 // TODO(pthatcher): Implement this. | 1093 // TODO(pthatcher): Implement this. |
1092 virtual bool GetStats(DataMediaInfo* info) { return true; } | 1094 virtual bool GetStats(DataMediaInfo* info) { return true; } |
1093 | 1095 |
1094 virtual bool SetSend(bool send) = 0; | 1096 virtual bool SetSend(bool send) = 0; |
1095 virtual bool SetReceive(bool receive) = 0; | 1097 virtual bool SetReceive(bool receive) = 0; |
1096 | 1098 |
1097 virtual bool SendData( | 1099 virtual bool SendData( |
1098 const SendDataParams& params, | 1100 const SendDataParams& params, |
1099 const rtc::Buffer& payload, | 1101 const rtc::CopyOnWriteBuffer& payload, |
1100 SendDataResult* result = NULL) = 0; | 1102 SendDataResult* result = NULL) = 0; |
1101 // Signals when data is received (params, data, len) | 1103 // Signals when data is received (params, data, len) |
1102 sigslot::signal3<const ReceiveDataParams&, | 1104 sigslot::signal3<const ReceiveDataParams&, |
1103 const char*, | 1105 const char*, |
1104 size_t> SignalDataReceived; | 1106 size_t> SignalDataReceived; |
1105 // Signal when the media channel is ready to send the stream. Arguments are: | 1107 // Signal when the media channel is ready to send the stream. Arguments are: |
1106 // writable(bool) | 1108 // writable(bool) |
1107 sigslot::signal1<bool> SignalReadyToSend; | 1109 sigslot::signal1<bool> SignalReadyToSend; |
1108 // Signal for notifying that the remote side has closed the DataChannel. | 1110 // Signal for notifying that the remote side has closed the DataChannel. |
1109 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; | 1111 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; |
1110 }; | 1112 }; |
1111 | 1113 |
1112 } // namespace cricket | 1114 } // namespace cricket |
1113 | 1115 |
1114 #endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ | 1116 #endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ |
OLD | NEW |