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