| 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_FAKENETWORKINTERFACE_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_FAKENETWORKINTERFACE_H_ |
| 12 #define WEBRTC_MEDIA_BASE_FAKENETWORKINTERFACE_H_ | 12 #define WEBRTC_MEDIA_BASE_FAKENETWORKINTERFACE_H_ |
| 13 | 13 |
| 14 #include <map> | 14 #include <map> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/buffer.h" | |
| 18 #include "webrtc/base/byteorder.h" | 17 #include "webrtc/base/byteorder.h" |
| 18 #include "webrtc/base/copyonwritebuffer.h" |
| 19 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
| 20 #include "webrtc/base/dscp.h" | 20 #include "webrtc/base/dscp.h" |
| 21 #include "webrtc/base/messagehandler.h" | 21 #include "webrtc/base/messagehandler.h" |
| 22 #include "webrtc/base/messagequeue.h" | 22 #include "webrtc/base/messagequeue.h" |
| 23 #include "webrtc/base/thread.h" | 23 #include "webrtc/base/thread.h" |
| 24 #include "webrtc/media/base/mediachannel.h" | 24 #include "webrtc/media/base/mediachannel.h" |
| 25 #include "webrtc/media/base/rtputils.h" | 25 #include "webrtc/media/base/rtputils.h" |
| 26 | 26 |
| 27 namespace cricket { | 27 namespace cricket { |
| 28 | 28 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 GetNumRtpBytesAndPackets(ssrc, NULL, &packets); | 77 GetNumRtpBytesAndPackets(ssrc, NULL, &packets); |
| 78 return packets; | 78 return packets; |
| 79 } | 79 } |
| 80 | 80 |
| 81 int NumSentSsrcs() { | 81 int NumSentSsrcs() { |
| 82 rtc::CritScope cs(&crit_); | 82 rtc::CritScope cs(&crit_); |
| 83 return static_cast<int>(sent_ssrcs_.size()); | 83 return static_cast<int>(sent_ssrcs_.size()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Note: callers are responsible for deleting the returned buffer. | 86 // Note: callers are responsible for deleting the returned buffer. |
| 87 const rtc::Buffer* GetRtpPacket(int index) { | 87 const rtc::CopyOnWriteBuffer* GetRtpPacket(int index) { |
| 88 rtc::CritScope cs(&crit_); | 88 rtc::CritScope cs(&crit_); |
| 89 if (index >= NumRtpPackets()) { | 89 if (index >= NumRtpPackets()) { |
| 90 return NULL; | 90 return NULL; |
| 91 } | 91 } |
| 92 return new rtc::Buffer(rtp_packets_[index]); | 92 return new rtc::CopyOnWriteBuffer(rtp_packets_[index]); |
| 93 } | 93 } |
| 94 | 94 |
| 95 int NumRtcpPackets() { | 95 int NumRtcpPackets() { |
| 96 rtc::CritScope cs(&crit_); | 96 rtc::CritScope cs(&crit_); |
| 97 return static_cast<int>(rtcp_packets_.size()); | 97 return static_cast<int>(rtcp_packets_.size()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Note: callers are responsible for deleting the returned buffer. | 100 // Note: callers are responsible for deleting the returned buffer. |
| 101 const rtc::Buffer* GetRtcpPacket(int index) { | 101 const rtc::CopyOnWriteBuffer* GetRtcpPacket(int index) { |
| 102 rtc::CritScope cs(&crit_); | 102 rtc::CritScope cs(&crit_); |
| 103 if (index >= NumRtcpPackets()) { | 103 if (index >= NumRtcpPackets()) { |
| 104 return NULL; | 104 return NULL; |
| 105 } | 105 } |
| 106 return new rtc::Buffer(rtcp_packets_[index]); | 106 return new rtc::CopyOnWriteBuffer(rtcp_packets_[index]); |
| 107 } | 107 } |
| 108 | 108 |
| 109 int sendbuf_size() const { return sendbuf_size_; } | 109 int sendbuf_size() const { return sendbuf_size_; } |
| 110 int recvbuf_size() const { return recvbuf_size_; } | 110 int recvbuf_size() const { return recvbuf_size_; } |
| 111 rtc::DiffServCodePoint dscp() const { return dscp_; } | 111 rtc::DiffServCodePoint dscp() const { return dscp_; } |
| 112 | 112 |
| 113 protected: | 113 protected: |
| 114 virtual bool SendPacket(rtc::Buffer* packet, | 114 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 115 const rtc::PacketOptions& options) { | 115 const rtc::PacketOptions& options) { |
| 116 rtc::CritScope cs(&crit_); | 116 rtc::CritScope cs(&crit_); |
| 117 | 117 |
| 118 uint32_t cur_ssrc = 0; | 118 uint32_t cur_ssrc = 0; |
| 119 if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) { | 119 if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) { |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 sent_ssrcs_[cur_ssrc]++; | 122 sent_ssrcs_[cur_ssrc]++; |
| 123 | 123 |
| 124 rtp_packets_.push_back(*packet); | 124 rtp_packets_.push_back(*packet); |
| 125 if (conf_) { | 125 if (conf_) { |
| 126 rtc::Buffer buffer_copy(*packet); | |
| 127 for (size_t i = 0; i < conf_sent_ssrcs_.size(); ++i) { | 126 for (size_t i = 0; i < conf_sent_ssrcs_.size(); ++i) { |
| 128 if (!SetRtpSsrc(buffer_copy.data(), buffer_copy.size(), | 127 if (!SetRtpSsrc(packet->data(), packet->size(), |
| 129 conf_sent_ssrcs_[i])) { | 128 conf_sent_ssrcs_[i])) { |
| 130 return false; | 129 return false; |
| 131 } | 130 } |
| 132 PostMessage(ST_RTP, buffer_copy); | 131 PostMessage(ST_RTP, *packet); |
| 133 } | 132 } |
| 134 } else { | 133 } else { |
| 135 PostMessage(ST_RTP, *packet); | 134 PostMessage(ST_RTP, *packet); |
| 136 } | 135 } |
| 137 return true; | 136 return true; |
| 138 } | 137 } |
| 139 | 138 |
| 140 virtual bool SendRtcp(rtc::Buffer* packet, | 139 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 141 const rtc::PacketOptions& options) { | 140 const rtc::PacketOptions& options) { |
| 142 rtc::CritScope cs(&crit_); | 141 rtc::CritScope cs(&crit_); |
| 143 rtcp_packets_.push_back(*packet); | 142 rtcp_packets_.push_back(*packet); |
| 144 if (!conf_) { | 143 if (!conf_) { |
| 145 // don't worry about RTCP in conf mode for now | 144 // don't worry about RTCP in conf mode for now |
| 146 PostMessage(ST_RTCP, *packet); | 145 PostMessage(ST_RTCP, *packet); |
| 147 } | 146 } |
| 148 return true; | 147 return true; |
| 149 } | 148 } |
| 150 | 149 |
| 151 virtual int SetOption(SocketType type, rtc::Socket::Option opt, | 150 virtual int SetOption(SocketType type, rtc::Socket::Option opt, |
| 152 int option) { | 151 int option) { |
| 153 if (opt == rtc::Socket::OPT_SNDBUF) { | 152 if (opt == rtc::Socket::OPT_SNDBUF) { |
| 154 sendbuf_size_ = option; | 153 sendbuf_size_ = option; |
| 155 } else if (opt == rtc::Socket::OPT_RCVBUF) { | 154 } else if (opt == rtc::Socket::OPT_RCVBUF) { |
| 156 recvbuf_size_ = option; | 155 recvbuf_size_ = option; |
| 157 } else if (opt == rtc::Socket::OPT_DSCP) { | 156 } else if (opt == rtc::Socket::OPT_DSCP) { |
| 158 dscp_ = static_cast<rtc::DiffServCodePoint>(option); | 157 dscp_ = static_cast<rtc::DiffServCodePoint>(option); |
| 159 } | 158 } |
| 160 return 0; | 159 return 0; |
| 161 } | 160 } |
| 162 | 161 |
| 163 void PostMessage(int id, const rtc::Buffer& packet) { | 162 void PostMessage(int id, const rtc::CopyOnWriteBuffer& packet) { |
| 164 thread_->Post(this, id, rtc::WrapMessageData(packet)); | 163 thread_->Post(this, id, rtc::WrapMessageData(packet)); |
| 165 } | 164 } |
| 166 | 165 |
| 167 virtual void OnMessage(rtc::Message* msg) { | 166 virtual void OnMessage(rtc::Message* msg) { |
| 168 rtc::TypedMessageData<rtc::Buffer>* msg_data = | 167 rtc::TypedMessageData<rtc::CopyOnWriteBuffer>* msg_data = |
| 169 static_cast<rtc::TypedMessageData<rtc::Buffer>*>( | 168 static_cast<rtc::TypedMessageData<rtc::CopyOnWriteBuffer>*>( |
| 170 msg->pdata); | 169 msg->pdata); |
| 171 if (dest_) { | 170 if (dest_) { |
| 172 if (msg->message_id == ST_RTP) { | 171 if (msg->message_id == ST_RTP) { |
| 173 dest_->OnPacketReceived(&msg_data->data(), | 172 dest_->OnPacketReceived(&msg_data->data(), |
| 174 rtc::CreatePacketTime(0)); | 173 rtc::CreatePacketTime(0)); |
| 175 } else { | 174 } else { |
| 176 dest_->OnRtcpReceived(&msg_data->data(), | 175 dest_->OnRtcpReceived(&msg_data->data(), |
| 177 rtc::CreatePacketTime(0)); | 176 rtc::CreatePacketTime(0)); |
| 178 } | 177 } |
| 179 } | 178 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 209 MediaChannel* dest_; | 208 MediaChannel* dest_; |
| 210 bool conf_; | 209 bool conf_; |
| 211 // The ssrcs used in sending out packets in conference mode. | 210 // The ssrcs used in sending out packets in conference mode. |
| 212 std::vector<uint32_t> conf_sent_ssrcs_; | 211 std::vector<uint32_t> conf_sent_ssrcs_; |
| 213 // Map to track counts of packets that have been sent per ssrc. | 212 // Map to track counts of packets that have been sent per ssrc. |
| 214 // This includes packets that are dropped. | 213 // This includes packets that are dropped. |
| 215 std::map<uint32_t, uint32_t> sent_ssrcs_; | 214 std::map<uint32_t, uint32_t> sent_ssrcs_; |
| 216 // Map to track packet-number that needs to be dropped per ssrc. | 215 // Map to track packet-number that needs to be dropped per ssrc. |
| 217 std::map<uint32_t, std::set<uint32_t> > drop_map_; | 216 std::map<uint32_t, std::set<uint32_t> > drop_map_; |
| 218 rtc::CriticalSection crit_; | 217 rtc::CriticalSection crit_; |
| 219 std::vector<rtc::Buffer> rtp_packets_; | 218 std::vector<rtc::CopyOnWriteBuffer> rtp_packets_; |
| 220 std::vector<rtc::Buffer> rtcp_packets_; | 219 std::vector<rtc::CopyOnWriteBuffer> rtcp_packets_; |
| 221 int sendbuf_size_; | 220 int sendbuf_size_; |
| 222 int recvbuf_size_; | 221 int recvbuf_size_; |
| 223 rtc::DiffServCodePoint dscp_; | 222 rtc::DiffServCodePoint dscp_; |
| 224 }; | 223 }; |
| 225 | 224 |
| 226 } // namespace cricket | 225 } // namespace cricket |
| 227 | 226 |
| 228 #endif // WEBRTC_MEDIA_BASE_FAKENETWORKINTERFACE_H_ | 227 #endif // WEBRTC_MEDIA_BASE_FAKENETWORKINTERFACE_H_ |
| OLD | NEW |