OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <errno.h> | 11 #include <errno.h> |
12 #include <stdarg.h> | 12 #include <stdarg.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 |
| 15 #include <memory> |
14 #include <string> | 16 #include <string> |
15 #include <vector> | 17 #include <vector> |
16 | 18 |
17 #include "webrtc/base/bind.h" | 19 #include "webrtc/base/bind.h" |
18 #include "webrtc/base/buffer.h" | 20 #include "webrtc/base/buffer.h" |
19 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/base/gunit.h" | 22 #include "webrtc/base/gunit.h" |
21 #include "webrtc/base/helpers.h" | 23 #include "webrtc/base/helpers.h" |
22 #include "webrtc/base/messagehandler.h" | 24 #include "webrtc/base/messagehandler.h" |
23 #include "webrtc/base/messagequeue.h" | 25 #include "webrtc/base/messagequeue.h" |
24 #include "webrtc/base/scoped_ptr.h" | |
25 #include "webrtc/base/ssladapter.h" | 26 #include "webrtc/base/ssladapter.h" |
26 #include "webrtc/base/thread.h" | 27 #include "webrtc/base/thread.h" |
27 #include "webrtc/media/base/constants.h" | 28 #include "webrtc/media/base/constants.h" |
28 #include "webrtc/media/base/mediachannel.h" | 29 #include "webrtc/media/base/mediachannel.h" |
29 #include "webrtc/media/sctp/sctpdataengine.h" | 30 #include "webrtc/media/sctp/sctpdataengine.h" |
30 | 31 |
31 enum { | 32 enum { |
32 MSG_PACKET = 1, | 33 MSG_PACKET = 1, |
33 }; | 34 }; |
34 | 35 |
(...skipping 21 matching lines...) Expand all Loading... |
56 thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer)); | 57 thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer)); |
57 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message."; | 58 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message."; |
58 return true; | 59 return true; |
59 } | 60 } |
60 | 61 |
61 // Called when a raw packet has been recieved. This passes the data to the | 62 // Called when a raw packet has been recieved. This passes the data to the |
62 // code that will interpret the packet. e.g. to get the content payload from | 63 // code that will interpret the packet. e.g. to get the content payload from |
63 // an SCTP packet. | 64 // an SCTP packet. |
64 virtual void OnMessage(rtc::Message* msg) { | 65 virtual void OnMessage(rtc::Message* msg) { |
65 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::OnMessage"; | 66 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::OnMessage"; |
66 rtc::scoped_ptr<rtc::Buffer> buffer( | 67 std::unique_ptr<rtc::Buffer> buffer( |
67 static_cast<rtc::TypedMessageData<rtc::Buffer*>*>( | 68 static_cast<rtc::TypedMessageData<rtc::Buffer*>*>( |
68 msg->pdata)->data()); | 69 msg->pdata)->data()); |
69 if (dest_) { | 70 if (dest_) { |
70 dest_->OnPacketReceived(buffer.get(), rtc::PacketTime()); | 71 dest_->OnPacketReceived(buffer.get(), rtc::PacketTime()); |
71 } | 72 } |
72 delete msg->pdata; | 73 delete msg->pdata; |
73 } | 74 } |
74 | 75 |
75 // Unsupported functions required to exist by NetworkInterface. | 76 // Unsupported functions required to exist by NetworkInterface. |
76 // TODO(ldixon): Refactor parent NetworkInterface class so these are not | 77 // TODO(ldixon): Refactor parent NetworkInterface class so these are not |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 307 } |
307 | 308 |
308 cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); } | 309 cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); } |
309 cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); } | 310 cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); } |
310 SctpFakeDataReceiver* receiver1() { return recv1_.get(); } | 311 SctpFakeDataReceiver* receiver1() { return recv1_.get(); } |
311 SctpFakeDataReceiver* receiver2() { return recv2_.get(); } | 312 SctpFakeDataReceiver* receiver2() { return recv2_.get(); } |
312 | 313 |
313 int channel1_ready_to_send_count() { return chan1_ready_to_send_count_; } | 314 int channel1_ready_to_send_count() { return chan1_ready_to_send_count_; } |
314 int channel2_ready_to_send_count() { return chan2_ready_to_send_count_; } | 315 int channel2_ready_to_send_count() { return chan2_ready_to_send_count_; } |
315 private: | 316 private: |
316 rtc::scoped_ptr<cricket::SctpDataEngine> engine_; | 317 std::unique_ptr<cricket::SctpDataEngine> engine_; |
317 rtc::scoped_ptr<SctpFakeNetworkInterface> net1_; | 318 std::unique_ptr<SctpFakeNetworkInterface> net1_; |
318 rtc::scoped_ptr<SctpFakeNetworkInterface> net2_; | 319 std::unique_ptr<SctpFakeNetworkInterface> net2_; |
319 rtc::scoped_ptr<SctpFakeDataReceiver> recv1_; | 320 std::unique_ptr<SctpFakeDataReceiver> recv1_; |
320 rtc::scoped_ptr<SctpFakeDataReceiver> recv2_; | 321 std::unique_ptr<SctpFakeDataReceiver> recv2_; |
321 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan1_; | 322 std::unique_ptr<cricket::SctpDataMediaChannel> chan1_; |
322 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan2_; | 323 std::unique_ptr<cricket::SctpDataMediaChannel> chan2_; |
323 | 324 |
324 int chan1_ready_to_send_count_; | 325 int chan1_ready_to_send_count_; |
325 int chan2_ready_to_send_count_; | 326 int chan2_ready_to_send_count_; |
326 | 327 |
327 void OnChan1ReadyToSend(bool send) { | 328 void OnChan1ReadyToSend(bool send) { |
328 if (send) | 329 if (send) |
329 ++chan1_ready_to_send_count_; | 330 ++chan1_ready_to_send_count_; |
330 } | 331 } |
331 void OnChan2ReadyToSend(bool send) { | 332 void OnChan2ReadyToSend(bool send) { |
332 if (send) | 333 if (send) |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 // Channel 1 is gone now. | 518 // Channel 1 is gone now. |
518 | 519 |
519 // Create a new channel 1. | 520 // Create a new channel 1. |
520 AddStream(1); | 521 AddStream(1); |
521 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result)); | 522 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result)); |
522 EXPECT_EQ(cricket::SDR_SUCCESS, result); | 523 EXPECT_EQ(cricket::SDR_SUCCESS, result); |
523 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000); | 524 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000); |
524 channel1()->RemoveSendStream(1); | 525 channel1()->RemoveSendStream(1); |
525 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000); | 526 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000); |
526 } | 527 } |
OLD | NEW |