| 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/copyonwritebuffer.h" | 19 #include "webrtc/base/buffer.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::CopyOnWriteBuffer* packet, | 347 virtual bool SendPacket(rtc::Buffer* packet, |
| 348 const rtc::PacketOptions& options) = 0; | 348 const rtc::PacketOptions& options) = 0; |
| 349 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet, | 349 virtual bool SendRtcp(rtc::Buffer* 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::CopyOnWriteBuffer* packet, | 371 virtual void OnPacketReceived(rtc::Buffer* 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::CopyOnWriteBuffer* packet, | 374 virtual void OnRtcpReceived(rtc::Buffer* 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::CopyOnWriteBuffer* packet, | 399 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) { |
| 400 const rtc::PacketOptions& options) { | |
| 401 return DoSendPacket(packet, false, options); | 400 return DoSendPacket(packet, false, options); |
| 402 } | 401 } |
| 403 | 402 |
| 404 bool SendRtcp(rtc::CopyOnWriteBuffer* packet, | 403 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) { |
| 405 const rtc::PacketOptions& options) { | |
| 406 return DoSendPacket(packet, true, options); | 404 return DoSendPacket(packet, true, options); |
| 407 } | 405 } |
| 408 | 406 |
| 409 int SetOption(NetworkInterface::SocketType type, | 407 int SetOption(NetworkInterface::SocketType type, |
| 410 rtc::Socket::Option opt, | 408 rtc::Socket::Option opt, |
| 411 int option) { | 409 int option) { |
| 412 rtc::CritScope cs(&network_interface_crit_); | 410 rtc::CritScope cs(&network_interface_crit_); |
| 413 if (!network_interface_) | 411 if (!network_interface_) |
| 414 return -1; | 412 return -1; |
| 415 | 413 |
| 416 return network_interface_->SetOption(type, opt, option); | 414 return network_interface_->SetOption(type, opt, option); |
| 417 } | 415 } |
| 418 | 416 |
| 419 private: | 417 private: |
| 420 // This method sets DSCP |value| on both RTP and RTCP channels. | 418 // This method sets DSCP |value| on both RTP and RTCP channels. |
| 421 int SetDscp(rtc::DiffServCodePoint value) { | 419 int SetDscp(rtc::DiffServCodePoint value) { |
| 422 int ret; | 420 int ret; |
| 423 ret = SetOption(NetworkInterface::ST_RTP, | 421 ret = SetOption(NetworkInterface::ST_RTP, |
| 424 rtc::Socket::OPT_DSCP, | 422 rtc::Socket::OPT_DSCP, |
| 425 value); | 423 value); |
| 426 if (ret == 0) { | 424 if (ret == 0) { |
| 427 ret = SetOption(NetworkInterface::ST_RTCP, | 425 ret = SetOption(NetworkInterface::ST_RTCP, |
| 428 rtc::Socket::OPT_DSCP, | 426 rtc::Socket::OPT_DSCP, |
| 429 value); | 427 value); |
| 430 } | 428 } |
| 431 return ret; | 429 return ret; |
| 432 } | 430 } |
| 433 | 431 |
| 434 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet, | 432 bool DoSendPacket(rtc::Buffer* packet, |
| 435 bool rtcp, | 433 bool rtcp, |
| 436 const rtc::PacketOptions& options) { | 434 const rtc::PacketOptions& options) { |
| 437 rtc::CritScope cs(&network_interface_crit_); | 435 rtc::CritScope cs(&network_interface_crit_); |
| 438 if (!network_interface_) | 436 if (!network_interface_) |
| 439 return false; | 437 return false; |
| 440 | 438 |
| 441 return (!rtcp) ? network_interface_->SendPacket(packet, options) | 439 return (!rtcp) ? network_interface_->SendPacket(packet, options) |
| 442 : network_interface_->SendRtcp(packet, options); | 440 : network_interface_->SendRtcp(packet, options); |
| 443 } | 441 } |
| 444 | 442 |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0; | 1089 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0; |
| 1092 | 1090 |
| 1093 // TODO(pthatcher): Implement this. | 1091 // TODO(pthatcher): Implement this. |
| 1094 virtual bool GetStats(DataMediaInfo* info) { return true; } | 1092 virtual bool GetStats(DataMediaInfo* info) { return true; } |
| 1095 | 1093 |
| 1096 virtual bool SetSend(bool send) = 0; | 1094 virtual bool SetSend(bool send) = 0; |
| 1097 virtual bool SetReceive(bool receive) = 0; | 1095 virtual bool SetReceive(bool receive) = 0; |
| 1098 | 1096 |
| 1099 virtual bool SendData( | 1097 virtual bool SendData( |
| 1100 const SendDataParams& params, | 1098 const SendDataParams& params, |
| 1101 const rtc::CopyOnWriteBuffer& payload, | 1099 const rtc::Buffer& payload, |
| 1102 SendDataResult* result = NULL) = 0; | 1100 SendDataResult* result = NULL) = 0; |
| 1103 // Signals when data is received (params, data, len) | 1101 // Signals when data is received (params, data, len) |
| 1104 sigslot::signal3<const ReceiveDataParams&, | 1102 sigslot::signal3<const ReceiveDataParams&, |
| 1105 const char*, | 1103 const char*, |
| 1106 size_t> SignalDataReceived; | 1104 size_t> SignalDataReceived; |
| 1107 // Signal when the media channel is ready to send the stream. Arguments are: | 1105 // Signal when the media channel is ready to send the stream. Arguments are: |
| 1108 // writable(bool) | 1106 // writable(bool) |
| 1109 sigslot::signal1<bool> SignalReadyToSend; | 1107 sigslot::signal1<bool> SignalReadyToSend; |
| 1110 // Signal for notifying that the remote side has closed the DataChannel. | 1108 // Signal for notifying that the remote side has closed the DataChannel. |
| 1111 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; | 1109 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; |
| 1112 }; | 1110 }; |
| 1113 | 1111 |
| 1114 } // namespace cricket | 1112 } // namespace cricket |
| 1115 | 1113 |
| 1116 #endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ | 1114 #endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_ |
| OLD | NEW |