Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: webrtc/media/sctp/sctpdataengine_unittest.cc

Issue 1817753003: Revert of Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/sctp/sctpdataengine.cc ('k') | webrtc/pc/channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14
15 #include <memory> 15 #include <memory>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/bind.h" 19 #include "webrtc/base/bind.h"
20 #include "webrtc/base/copyonwritebuffer.h" 20 #include "webrtc/base/buffer.h"
21 #include "webrtc/base/criticalsection.h" 21 #include "webrtc/base/criticalsection.h"
22 #include "webrtc/base/gunit.h" 22 #include "webrtc/base/gunit.h"
23 #include "webrtc/base/helpers.h" 23 #include "webrtc/base/helpers.h"
24 #include "webrtc/base/messagehandler.h" 24 #include "webrtc/base/messagehandler.h"
25 #include "webrtc/base/messagequeue.h" 25 #include "webrtc/base/messagequeue.h"
26 #include "webrtc/base/ssladapter.h" 26 #include "webrtc/base/ssladapter.h"
27 #include "webrtc/base/thread.h" 27 #include "webrtc/base/thread.h"
28 #include "webrtc/media/base/mediachannel.h" 28 #include "webrtc/media/base/mediachannel.h"
29 #include "webrtc/media/base/mediaconstants.h" 29 #include "webrtc/media/base/mediaconstants.h"
30 #include "webrtc/media/sctp/sctpdataengine.h" 30 #include "webrtc/media/sctp/sctpdataengine.h"
31 31
32 enum { 32 enum {
33 MSG_PACKET = 1, 33 MSG_PACKET = 1,
34 }; 34 };
35 35
36 // Fake NetworkInterface that sends/receives sctp packets. The one in 36 // Fake NetworkInterface that sends/receives sctp packets. The one in
37 // webrtc/media/base/fakenetworkinterface.h only works with rtp/rtcp. 37 // webrtc/media/base/fakenetworkinterface.h only works with rtp/rtcp.
38 class SctpFakeNetworkInterface : public cricket::MediaChannel::NetworkInterface, 38 class SctpFakeNetworkInterface : public cricket::MediaChannel::NetworkInterface,
39 public rtc::MessageHandler { 39 public rtc::MessageHandler {
40 public: 40 public:
41 explicit SctpFakeNetworkInterface(rtc::Thread* thread) 41 explicit SctpFakeNetworkInterface(rtc::Thread* thread)
42 : thread_(thread), 42 : thread_(thread),
43 dest_(NULL) { 43 dest_(NULL) {
44 } 44 }
45 45
46 void SetDestination(cricket::DataMediaChannel* dest) { dest_ = dest; } 46 void SetDestination(cricket::DataMediaChannel* dest) { dest_ = dest; }
47 47
48 protected: 48 protected:
49 // Called to send raw packet down the wire (e.g. SCTP an packet). 49 // Called to send raw packet down the wire (e.g. SCTP an packet).
50 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet, 50 virtual bool SendPacket(rtc::Buffer* packet,
51 const rtc::PacketOptions& options) { 51 const rtc::PacketOptions& options) {
52 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket"; 52 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket";
53 53
54 rtc::CopyOnWriteBuffer* buffer = new rtc::CopyOnWriteBuffer(*packet); 54 // TODO(ldixon): Can/should we use Buffer.TransferTo here?
55 // Note: this assignment does a deep copy of data from packet.
56 rtc::Buffer* buffer = new rtc::Buffer(packet->data(), packet->size());
55 thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer)); 57 thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer));
56 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message."; 58 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message.";
57 return true; 59 return true;
58 } 60 }
59 61
60 // 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
61 // 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
62 // an SCTP packet. 64 // an SCTP packet.
63 virtual void OnMessage(rtc::Message* msg) { 65 virtual void OnMessage(rtc::Message* msg) {
64 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::OnMessage"; 66 LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::OnMessage";
65 std::unique_ptr<rtc::CopyOnWriteBuffer> buffer( 67 std::unique_ptr<rtc::Buffer> buffer(
66 static_cast<rtc::TypedMessageData<rtc::CopyOnWriteBuffer*>*>( 68 static_cast<rtc::TypedMessageData<rtc::Buffer*>*>(
67 msg->pdata)->data()); 69 msg->pdata)->data());
68 if (dest_) { 70 if (dest_) {
69 dest_->OnPacketReceived(buffer.get(), rtc::PacketTime()); 71 dest_->OnPacketReceived(buffer.get(), rtc::PacketTime());
70 } 72 }
71 delete msg->pdata; 73 delete msg->pdata;
72 } 74 }
73 75
74 // Unsupported functions required to exist by NetworkInterface. 76 // Unsupported functions required to exist by NetworkInterface.
75 // TODO(ldixon): Refactor parent NetworkInterface class so these are not 77 // TODO(ldixon): Refactor parent NetworkInterface class so these are not
76 // required. They are RTC specific and should be in an appropriate subclass. 78 // required. They are RTC specific and should be in an appropriate subclass.
77 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet, 79 virtual bool SendRtcp(rtc::Buffer* packet,
78 const rtc::PacketOptions& options) { 80 const rtc::PacketOptions& options) {
79 LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SendRtcp."; 81 LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SendRtcp.";
80 return false; 82 return false;
81 } 83 }
82 virtual int SetOption(SocketType type, rtc::Socket::Option opt, 84 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
83 int option) { 85 int option) {
84 LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SetOption."; 86 LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SetOption.";
85 return 0; 87 return 0;
86 } 88 }
87 virtual void SetDefaultDSCPCode(rtc::DiffServCodePoint dscp) { 89 virtual void SetDefaultDSCPCode(rtc::DiffServCodePoint dscp) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return channel; 276 return channel;
275 } 277 }
276 278
277 bool SendData(cricket::SctpDataMediaChannel* chan, 279 bool SendData(cricket::SctpDataMediaChannel* chan,
278 uint32_t ssrc, 280 uint32_t ssrc,
279 const std::string& msg, 281 const std::string& msg,
280 cricket::SendDataResult* result) { 282 cricket::SendDataResult* result) {
281 cricket::SendDataParams params; 283 cricket::SendDataParams params;
282 params.ssrc = ssrc; 284 params.ssrc = ssrc;
283 285
284 return chan->SendData(params, rtc::CopyOnWriteBuffer( 286 return chan->SendData(params, rtc::Buffer(
285 &msg[0], msg.length()), result); 287 &msg[0], msg.length()), result);
286 } 288 }
287 289
288 bool ReceivedData(const SctpFakeDataReceiver* recv, 290 bool ReceivedData(const SctpFakeDataReceiver* recv,
289 uint32_t ssrc, 291 uint32_t ssrc,
290 const std::string& msg) { 292 const std::string& msg) {
291 return (recv->received() && 293 return (recv->received() &&
292 recv->last_params().ssrc == ssrc && 294 recv->last_params().ssrc == ssrc &&
293 recv->last_data() == msg); 295 recv->last_data() == msg);
294 } 296 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 SetupConnectedChannels(); 395 SetupConnectedChannels();
394 396
395 cricket::SendDataResult result; 397 cricket::SendDataResult result;
396 cricket::SendDataParams params; 398 cricket::SendDataParams params;
397 params.ssrc = 1; 399 params.ssrc = 1;
398 400
399 std::vector<char> buffer(1024 * 64, 0); 401 std::vector<char> buffer(1024 * 64, 0);
400 402
401 for (size_t i = 0; i < 100; ++i) { 403 for (size_t i = 0; i < 100; ++i) {
402 channel1()->SendData( 404 channel1()->SendData(
403 params, rtc::CopyOnWriteBuffer(&buffer[0], buffer.size()), &result); 405 params, rtc::Buffer(&buffer[0], buffer.size()), &result);
404 if (result == cricket::SDR_BLOCK) 406 if (result == cricket::SDR_BLOCK)
405 break; 407 break;
406 } 408 }
407 409
408 EXPECT_EQ(cricket::SDR_BLOCK, result); 410 EXPECT_EQ(cricket::SDR_BLOCK, result);
409 } 411 }
410 412
411 TEST_F(SctpDataMediaChannelTest, ClosesRemoteStream) { 413 TEST_F(SctpDataMediaChannelTest, ClosesRemoteStream) {
412 SetupConnectedChannels(); 414 SetupConnectedChannels();
413 SignalChannelClosedObserver chan_1_sig_receiver, chan_2_sig_receiver; 415 SignalChannelClosedObserver chan_1_sig_receiver, chan_2_sig_receiver;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Channel 1 is gone now. 518 // Channel 1 is gone now.
517 519
518 // Create a new channel 1. 520 // Create a new channel 1.
519 AddStream(1); 521 AddStream(1);
520 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result)); 522 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result));
521 EXPECT_EQ(cricket::SDR_SUCCESS, result); 523 EXPECT_EQ(cricket::SDR_SUCCESS, result);
522 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000); 524 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000);
523 channel1()->RemoveSendStream(1); 525 channel1()->RemoveSendStream(1);
524 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000); 526 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000);
525 } 527 }
OLDNEW
« no previous file with comments | « webrtc/media/sctp/sctpdataengine.cc ('k') | webrtc/pc/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698