2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-02-26 03:00:35 -08:00
|
|
|
#include <memory>
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2016-03-20 06:15:43 -07:00
|
|
|
#include "webrtc/base/copyonwritebuffer.h"
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/gunit.h"
|
|
|
|
|
#include "webrtc/base/helpers.h"
|
|
|
|
|
#include "webrtc/base/ssladapter.h"
|
|
|
|
|
#include "webrtc/base/timing.h"
|
Move talk/media to webrtc/media
I removed the 'libjingle' target in talk/libjingle.gyp and replaced
all users of it with base/base.gyp:rtc_base. It seems the jsoncpp
and expat dependencies were not used by it's previous references.
The files in talk/media/testdata were uploaded to Google Storage and
added .sha1 files in resources/media instead of simply moving them.
The previously disabled warnings that were inherited from
talk/build/common.gypi are now replaced by target-specific disabling
of only the failing warnings. Additional disabling was needed since the stricter
compilation warnings that applies to code in webrtc/.
License headers will be updated in a follow-up CL in order to not
break Git history.
Other modifications:
* Updated the header guards.
* Sorted the includes using chromium/src/tools/sort-headers.py
except for these files:
talk/app/webrtc/peerconnectionendtoend_unittest.cc
talk/app/webrtc/java/jni/androidmediadecoder_jni.cc
talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
webrtc/media/devices/win32devicemanager.cc.
* Unused GYP reference to libjingle_tests_additional_deps was removed.
* Removed duplicated GYP entries of
webrtc/base/testutils.cc
webrtc/base/testutils.h
The HAVE_WEBRTC_VIDEO and HAVE_WEBRTC_VOICE defines were used by only talk/media,
so they were moved to the media.gyp.
I also checked that none of
EXPAT_RELATIVE_PATH,
FEATURE_ENABLE_VOICEMAIL,
GTEST_RELATIVE_PATH,
JSONCPP_RELATIVE_PATH,
LOGGING=1,
SRTP_RELATIVE_PATH,
FEATURE_ENABLE_SSL,
FEATURE_ENABLE_VOICEMAIL,
FEATURE_ENABLE_PSTN,
HAVE_SCTP,
HAVE_SRTP,
are used by the talk/media code.
For Chromium, the following changes will need to be applied to the roll CL that updates the
DEPS for WebRTC and libjingle: https://codereview.chromium.org/1604303002/
BUG=webrtc:5420
NOPRESUBMIT=True
TBR=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/1587193006
Cr-Commit-Position: refs/heads/master@{#11495}
2016-02-04 23:52:28 -08:00
|
|
|
#include "webrtc/media/base/fakenetworkinterface.h"
|
2016-03-02 05:42:30 -08:00
|
|
|
#include "webrtc/media/base/mediaconstants.h"
|
Move talk/media to webrtc/media
I removed the 'libjingle' target in talk/libjingle.gyp and replaced
all users of it with base/base.gyp:rtc_base. It seems the jsoncpp
and expat dependencies were not used by it's previous references.
The files in talk/media/testdata were uploaded to Google Storage and
added .sha1 files in resources/media instead of simply moving them.
The previously disabled warnings that were inherited from
talk/build/common.gypi are now replaced by target-specific disabling
of only the failing warnings. Additional disabling was needed since the stricter
compilation warnings that applies to code in webrtc/.
License headers will be updated in a follow-up CL in order to not
break Git history.
Other modifications:
* Updated the header guards.
* Sorted the includes using chromium/src/tools/sort-headers.py
except for these files:
talk/app/webrtc/peerconnectionendtoend_unittest.cc
talk/app/webrtc/java/jni/androidmediadecoder_jni.cc
talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
webrtc/media/devices/win32devicemanager.cc.
* Unused GYP reference to libjingle_tests_additional_deps was removed.
* Removed duplicated GYP entries of
webrtc/base/testutils.cc
webrtc/base/testutils.h
The HAVE_WEBRTC_VIDEO and HAVE_WEBRTC_VOICE defines were used by only talk/media,
so they were moved to the media.gyp.
I also checked that none of
EXPAT_RELATIVE_PATH,
FEATURE_ENABLE_VOICEMAIL,
GTEST_RELATIVE_PATH,
JSONCPP_RELATIVE_PATH,
LOGGING=1,
SRTP_RELATIVE_PATH,
FEATURE_ENABLE_SSL,
FEATURE_ENABLE_VOICEMAIL,
FEATURE_ENABLE_PSTN,
HAVE_SCTP,
HAVE_SRTP,
are used by the talk/media code.
For Chromium, the following changes will need to be applied to the roll CL that updates the
DEPS for WebRTC and libjingle: https://codereview.chromium.org/1604303002/
BUG=webrtc:5420
NOPRESUBMIT=True
TBR=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/1587193006
Cr-Commit-Position: refs/heads/master@{#11495}
2016-02-04 23:52:28 -08:00
|
|
|
#include "webrtc/media/base/rtpdataengine.h"
|
|
|
|
|
#include "webrtc/media/base/rtputils.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
class FakeTiming : public rtc::Timing {
|
2013-07-10 00:45:36 +00:00
|
|
|
public:
|
|
|
|
|
FakeTiming() : now_(0.0) {}
|
|
|
|
|
|
|
|
|
|
virtual double TimerNow() {
|
|
|
|
|
return now_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_now(double now) {
|
|
|
|
|
now_ = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
double now_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FakeDataReceiver : public sigslot::has_slots<> {
|
|
|
|
|
public:
|
|
|
|
|
FakeDataReceiver() : has_received_data_(false) {}
|
|
|
|
|
|
|
|
|
|
void OnDataReceived(
|
|
|
|
|
const cricket::ReceiveDataParams& params,
|
|
|
|
|
const char* data, size_t len) {
|
|
|
|
|
has_received_data_ = true;
|
|
|
|
|
last_received_data_ = std::string(data, len);
|
|
|
|
|
last_received_data_len_ = len;
|
|
|
|
|
last_received_data_params_ = params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool has_received_data() const { return has_received_data_; }
|
|
|
|
|
std::string last_received_data() const { return last_received_data_; }
|
|
|
|
|
size_t last_received_data_len() const { return last_received_data_len_; }
|
|
|
|
|
cricket::ReceiveDataParams last_received_data_params() const {
|
|
|
|
|
return last_received_data_params_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool has_received_data_;
|
|
|
|
|
std::string last_received_data_;
|
|
|
|
|
size_t last_received_data_len_;
|
|
|
|
|
cricket::ReceiveDataParams last_received_data_params_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RtpDataMediaChannelTest : public testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
|
// Seed needed for each test to satisfy expectations.
|
|
|
|
|
iface_.reset(new cricket::FakeNetworkInterface());
|
|
|
|
|
timing_ = new FakeTiming();
|
|
|
|
|
dme_.reset(CreateEngine(timing_));
|
|
|
|
|
receiver_.reset(new FakeDataReceiver());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetNow(double now) {
|
|
|
|
|
timing_->set_now(now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cricket::RtpDataEngine* CreateEngine(FakeTiming* timing) {
|
|
|
|
|
cricket::RtpDataEngine* dme = new cricket::RtpDataEngine();
|
|
|
|
|
dme->SetTiming(timing);
|
|
|
|
|
return dme;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cricket::RtpDataMediaChannel* CreateChannel() {
|
|
|
|
|
return CreateChannel(dme_.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cricket::RtpDataMediaChannel* CreateChannel(cricket::RtpDataEngine* dme) {
|
|
|
|
|
cricket::RtpDataMediaChannel* channel =
|
|
|
|
|
static_cast<cricket::RtpDataMediaChannel*>(dme->CreateChannel(
|
|
|
|
|
cricket::DCT_RTP));
|
|
|
|
|
channel->SetInterface(iface_.get());
|
|
|
|
|
channel->SignalDataReceived.connect(
|
|
|
|
|
receiver_.get(), &FakeDataReceiver::OnDataReceived);
|
|
|
|
|
return channel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FakeDataReceiver* receiver() {
|
|
|
|
|
return receiver_.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HasReceivedData() {
|
|
|
|
|
return receiver_->has_received_data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetReceivedData() {
|
|
|
|
|
return receiver_->last_received_data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t GetReceivedDataLen() {
|
|
|
|
|
return receiver_->last_received_data_len();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cricket::ReceiveDataParams GetReceivedDataParams() {
|
|
|
|
|
return receiver_->last_received_data_params();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HasSentData(int count) {
|
|
|
|
|
return (iface_->NumRtpPackets() > count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetSentData(int index) {
|
|
|
|
|
// Assume RTP header of length 12
|
2016-03-20 06:15:43 -07:00
|
|
|
std::unique_ptr<const rtc::CopyOnWriteBuffer> packet(
|
2013-07-17 14:42:53 +00:00
|
|
|
iface_->GetRtpPacket(index));
|
2015-03-24 09:19:06 +00:00
|
|
|
if (packet->size() > 12) {
|
rtc::Buffer improvements
1. Constructors, SetData(), and AppendData() now accept uint8_t*,
int8_t*, and char*. Previously, they accepted void*, meaning that
any kind of pointer was accepted. I think requiring an explicit
cast in cases where the input array isn't already of a byte-sized
type is a better compromise between convenience and safety.
2. data() can now return a uint8_t* instead of a char*, which seems
more appropriate for a byte array, and is harder to mix up with
zero-terminated C strings. data<int8_t>() is also available so
that callers that want that type instead won't have to cast, as
is data<char>() (which remains the default until all existing
callers have been fixed).
3. Constructors, SetData(), and AppendData() now accept arrays
natively, not just decayed to pointers. The advantage of this is
that callers don't have to pass the size separately.
4. There are new constructors that allow setting size and capacity
without initializing the array. Previously, this had to be done
separately after construction.
5. Instead of TransferTo(), Buffer now supports swap(), and move
construction and assignment, and has a Pass() method that works
just like std::move(). (The Pass method is modeled after
scoped_ptr::Pass().)
R=jmarusic@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/42989004
Cr-Commit-Position: refs/heads/master@{#9033}
2015-04-20 14:03:07 +02:00
|
|
|
return std::string(packet->data<char>() + 12, packet->size() - 12);
|
2013-07-10 00:45:36 +00:00
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cricket::RtpHeader GetSentDataHeader(int index) {
|
2016-03-20 06:15:43 -07:00
|
|
|
std::unique_ptr<const rtc::CopyOnWriteBuffer> packet(
|
2013-07-17 14:42:53 +00:00
|
|
|
iface_->GetRtpPacket(index));
|
2013-07-10 00:45:36 +00:00
|
|
|
cricket::RtpHeader header;
|
2015-03-24 09:19:06 +00:00
|
|
|
GetRtpHeader(packet->data(), packet->size(), &header);
|
2013-07-10 00:45:36 +00:00
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataEngine> dme_;
|
2013-07-10 00:45:36 +00:00
|
|
|
// Timing passed into dme_. Owned by dme_;
|
|
|
|
|
FakeTiming* timing_;
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::FakeNetworkInterface> iface_;
|
|
|
|
|
std::unique_ptr<FakeDataReceiver> receiver_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) {
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
cricket::DataCodec known_codec;
|
|
|
|
|
known_codec.id = 103;
|
|
|
|
|
known_codec.name = "google-data";
|
|
|
|
|
cricket::DataCodec unknown_codec;
|
|
|
|
|
unknown_codec.id = 104;
|
|
|
|
|
unknown_codec.name = "unknown-data";
|
|
|
|
|
|
2015-09-17 16:42:56 +02:00
|
|
|
cricket::DataSendParameters send_parameters_known;
|
|
|
|
|
send_parameters_known.codecs.push_back(known_codec);
|
|
|
|
|
cricket::DataRecvParameters recv_parameters_known;
|
|
|
|
|
recv_parameters_known.codecs.push_back(known_codec);
|
|
|
|
|
|
|
|
|
|
cricket::DataSendParameters send_parameters_unknown;
|
|
|
|
|
send_parameters_unknown.codecs.push_back(unknown_codec);
|
|
|
|
|
cricket::DataRecvParameters recv_parameters_unknown;
|
|
|
|
|
recv_parameters_unknown.codecs.push_back(unknown_codec);
|
|
|
|
|
|
|
|
|
|
cricket::DataSendParameters send_parameters_mixed;
|
|
|
|
|
send_parameters_mixed.codecs.push_back(known_codec);
|
|
|
|
|
send_parameters_mixed.codecs.push_back(unknown_codec);
|
|
|
|
|
cricket::DataRecvParameters recv_parameters_mixed;
|
|
|
|
|
recv_parameters_mixed.codecs.push_back(known_codec);
|
|
|
|
|
recv_parameters_mixed.codecs.push_back(unknown_codec);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc->SetSendParameters(send_parameters_known));
|
|
|
|
|
EXPECT_FALSE(dmc->SetSendParameters(send_parameters_unknown));
|
|
|
|
|
EXPECT_TRUE(dmc->SetSendParameters(send_parameters_mixed));
|
|
|
|
|
EXPECT_TRUE(dmc->SetRecvParameters(recv_parameters_known));
|
|
|
|
|
EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_unknown));
|
|
|
|
|
EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_mixed));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, AddRemoveSendStream) {
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
cricket::StreamParams stream1;
|
|
|
|
|
stream1.add_ssrc(41);
|
|
|
|
|
EXPECT_TRUE(dmc->AddSendStream(stream1));
|
|
|
|
|
cricket::StreamParams stream2;
|
|
|
|
|
stream2.add_ssrc(42);
|
|
|
|
|
EXPECT_TRUE(dmc->AddSendStream(stream2));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc->RemoveSendStream(41));
|
|
|
|
|
EXPECT_TRUE(dmc->RemoveSendStream(42));
|
|
|
|
|
EXPECT_FALSE(dmc->RemoveSendStream(43));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, AddRemoveRecvStream) {
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
cricket::StreamParams stream1;
|
|
|
|
|
stream1.add_ssrc(41);
|
|
|
|
|
EXPECT_TRUE(dmc->AddRecvStream(stream1));
|
|
|
|
|
cricket::StreamParams stream2;
|
|
|
|
|
stream2.add_ssrc(42);
|
|
|
|
|
EXPECT_TRUE(dmc->AddRecvStream(stream2));
|
|
|
|
|
EXPECT_FALSE(dmc->AddRecvStream(stream2));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc->RemoveRecvStream(41));
|
|
|
|
|
EXPECT_TRUE(dmc->RemoveRecvStream(42));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, SendData) {
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
cricket::SendDataParams params;
|
|
|
|
|
params.ssrc = 42;
|
|
|
|
|
unsigned char data[] = "food";
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer payload(data, 4);
|
2013-07-10 00:45:36 +00:00
|
|
|
unsigned char padded_data[] = {
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
'f', 'o', 'o', 'd',
|
|
|
|
|
};
|
|
|
|
|
cricket::SendDataResult result;
|
|
|
|
|
|
|
|
|
|
// Not sending
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_EQ(cricket::SDR_ERROR, result);
|
|
|
|
|
EXPECT_FALSE(HasSentData(0));
|
|
|
|
|
ASSERT_TRUE(dmc->SetSend(true));
|
|
|
|
|
|
|
|
|
|
// Unknown stream name.
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_EQ(cricket::SDR_ERROR, result);
|
|
|
|
|
EXPECT_FALSE(HasSentData(0));
|
|
|
|
|
|
|
|
|
|
cricket::StreamParams stream;
|
|
|
|
|
stream.add_ssrc(42);
|
|
|
|
|
ASSERT_TRUE(dmc->AddSendStream(stream));
|
|
|
|
|
|
|
|
|
|
// Unknown codec;
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_EQ(cricket::SDR_ERROR, result);
|
|
|
|
|
EXPECT_FALSE(HasSentData(0));
|
|
|
|
|
|
|
|
|
|
cricket::DataCodec codec;
|
|
|
|
|
codec.id = 103;
|
|
|
|
|
codec.name = cricket::kGoogleRtpDataCodecName;
|
2015-09-17 16:42:56 +02:00
|
|
|
cricket::DataSendParameters parameters;
|
|
|
|
|
parameters.codecs.push_back(codec);
|
|
|
|
|
ASSERT_TRUE(dmc->SetSendParameters(parameters));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Length too large;
|
|
|
|
|
std::string x10000(10000, 'x');
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(
|
2016-03-20 06:15:43 -07:00
|
|
|
params, rtc::CopyOnWriteBuffer(x10000.data(), x10000.length()), &result));
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_EQ(cricket::SDR_ERROR, result);
|
|
|
|
|
EXPECT_FALSE(HasSentData(0));
|
|
|
|
|
|
|
|
|
|
// Finally works!
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_EQ(cricket::SDR_SUCCESS, result);
|
|
|
|
|
ASSERT_TRUE(HasSentData(0));
|
|
|
|
|
EXPECT_EQ(sizeof(padded_data), GetSentData(0).length());
|
|
|
|
|
EXPECT_EQ(0, memcmp(
|
|
|
|
|
padded_data, GetSentData(0).data(), sizeof(padded_data)));
|
|
|
|
|
cricket::RtpHeader header0 = GetSentDataHeader(0);
|
|
|
|
|
EXPECT_NE(0, header0.seq_num);
|
|
|
|
|
EXPECT_NE(0U, header0.timestamp);
|
|
|
|
|
EXPECT_EQ(header0.ssrc, 42U);
|
|
|
|
|
EXPECT_EQ(header0.payload_type, 103);
|
|
|
|
|
|
|
|
|
|
// Should bump timestamp by 180000 because the clock rate is 90khz.
|
|
|
|
|
SetNow(2);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
ASSERT_TRUE(HasSentData(1));
|
|
|
|
|
EXPECT_EQ(sizeof(padded_data), GetSentData(1).length());
|
|
|
|
|
EXPECT_EQ(0, memcmp(
|
|
|
|
|
padded_data, GetSentData(1).data(), sizeof(padded_data)));
|
|
|
|
|
cricket::RtpHeader header1 = GetSentDataHeader(1);
|
|
|
|
|
EXPECT_EQ(header1.ssrc, 42U);
|
|
|
|
|
EXPECT_EQ(header1.payload_type, 103);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
EXPECT_EQ(static_cast<uint16_t>(header0.seq_num + 1),
|
|
|
|
|
static_cast<uint16_t>(header1.seq_num));
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_EQ(header0.timestamp + 180000, header1.timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 18:59:08 +00:00
|
|
|
TEST_F(RtpDataMediaChannelTest, SendDataMultipleClocks) {
|
2013-07-10 00:45:36 +00:00
|
|
|
// Timings owned by RtpDataEngines.
|
|
|
|
|
FakeTiming* timing1 = new FakeTiming();
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataEngine> dme1(CreateEngine(timing1));
|
|
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc1(
|
2013-07-10 00:45:36 +00:00
|
|
|
CreateChannel(dme1.get()));
|
|
|
|
|
FakeTiming* timing2 = new FakeTiming();
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataEngine> dme2(CreateEngine(timing2));
|
|
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc2(
|
2013-07-10 00:45:36 +00:00
|
|
|
CreateChannel(dme2.get()));
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(dmc1->SetSend(true));
|
|
|
|
|
ASSERT_TRUE(dmc2->SetSend(true));
|
|
|
|
|
|
|
|
|
|
cricket::StreamParams stream1;
|
|
|
|
|
stream1.add_ssrc(41);
|
|
|
|
|
ASSERT_TRUE(dmc1->AddSendStream(stream1));
|
|
|
|
|
cricket::StreamParams stream2;
|
|
|
|
|
stream2.add_ssrc(42);
|
|
|
|
|
ASSERT_TRUE(dmc2->AddSendStream(stream2));
|
|
|
|
|
|
|
|
|
|
cricket::DataCodec codec;
|
|
|
|
|
codec.id = 103;
|
|
|
|
|
codec.name = cricket::kGoogleRtpDataCodecName;
|
2015-09-17 16:42:56 +02:00
|
|
|
cricket::DataSendParameters parameters;
|
|
|
|
|
parameters.codecs.push_back(codec);
|
|
|
|
|
ASSERT_TRUE(dmc1->SetSendParameters(parameters));
|
|
|
|
|
ASSERT_TRUE(dmc2->SetSendParameters(parameters));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
cricket::SendDataParams params1;
|
|
|
|
|
params1.ssrc = 41;
|
|
|
|
|
cricket::SendDataParams params2;
|
|
|
|
|
params2.ssrc = 42;
|
|
|
|
|
|
|
|
|
|
unsigned char data[] = "foo";
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer payload(data, 3);
|
2013-07-10 00:45:36 +00:00
|
|
|
cricket::SendDataResult result;
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc2->SendData(params2, payload, &result));
|
|
|
|
|
|
|
|
|
|
// Should bump timestamp by 90000 because the clock rate is 90khz.
|
|
|
|
|
timing1->set_now(1);
|
|
|
|
|
// Should bump timestamp by 180000 because the clock rate is 90khz.
|
|
|
|
|
timing2->set_now(2);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc2->SendData(params2, payload, &result));
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(HasSentData(3));
|
|
|
|
|
cricket::RtpHeader header1a = GetSentDataHeader(0);
|
|
|
|
|
cricket::RtpHeader header2a = GetSentDataHeader(1);
|
|
|
|
|
cricket::RtpHeader header1b = GetSentDataHeader(2);
|
|
|
|
|
cricket::RtpHeader header2b = GetSentDataHeader(3);
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
EXPECT_EQ(static_cast<uint16_t>(header1a.seq_num + 1),
|
|
|
|
|
static_cast<uint16_t>(header1b.seq_num));
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_EQ(header1a.timestamp + 90000, header1b.timestamp);
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
EXPECT_EQ(static_cast<uint16_t>(header2a.seq_num + 1),
|
|
|
|
|
static_cast<uint16_t>(header2b.seq_num));
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_EQ(header2a.timestamp + 180000, header2b.timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, SendDataRate) {
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(dmc->SetSend(true));
|
|
|
|
|
|
|
|
|
|
cricket::DataCodec codec;
|
|
|
|
|
codec.id = 103;
|
|
|
|
|
codec.name = cricket::kGoogleRtpDataCodecName;
|
2015-09-17 16:42:56 +02:00
|
|
|
cricket::DataSendParameters parameters;
|
|
|
|
|
parameters.codecs.push_back(codec);
|
|
|
|
|
ASSERT_TRUE(dmc->SetSendParameters(parameters));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
cricket::StreamParams stream;
|
|
|
|
|
stream.add_ssrc(42);
|
|
|
|
|
ASSERT_TRUE(dmc->AddSendStream(stream));
|
|
|
|
|
|
|
|
|
|
cricket::SendDataParams params;
|
|
|
|
|
params.ssrc = 42;
|
|
|
|
|
unsigned char data[] = "food";
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer payload(data, 4);
|
2013-07-10 00:45:36 +00:00
|
|
|
cricket::SendDataResult result;
|
|
|
|
|
|
|
|
|
|
// With rtp overhead of 32 bytes, each one of our packets is 36
|
|
|
|
|
// bytes, or 288 bits. So, a limit of 872bps will allow 3 packets,
|
|
|
|
|
// but not four.
|
2015-09-17 16:42:56 +02:00
|
|
|
parameters.max_bandwidth_bps = 872;
|
|
|
|
|
ASSERT_TRUE(dmc->SetSendParameters(parameters));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
|
|
|
|
|
SetNow(0.9);
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
|
|
|
|
|
SetNow(1.1);
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
SetNow(1.9);
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
|
|
|
|
|
SetNow(2.2);
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_TRUE(dmc->SendData(params, payload, &result));
|
|
|
|
|
EXPECT_FALSE(dmc->SendData(params, payload, &result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, ReceiveData) {
|
|
|
|
|
// PT= 103, SN=2, TS=3, SSRC = 4, data = "abcde"
|
|
|
|
|
unsigned char data[] = {
|
|
|
|
|
0x80, 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2A,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
'a', 'b', 'c', 'd', 'e'
|
|
|
|
|
};
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer packet(data, sizeof(data));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// SetReceived not called.
|
2014-07-29 17:36:52 +00:00
|
|
|
dmc->OnPacketReceived(&packet, rtc::PacketTime());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(HasReceivedData());
|
|
|
|
|
|
|
|
|
|
dmc->SetReceive(true);
|
|
|
|
|
|
|
|
|
|
// Unknown payload id
|
2014-07-29 17:36:52 +00:00
|
|
|
dmc->OnPacketReceived(&packet, rtc::PacketTime());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(HasReceivedData());
|
|
|
|
|
|
|
|
|
|
cricket::DataCodec codec;
|
|
|
|
|
codec.id = 103;
|
|
|
|
|
codec.name = cricket::kGoogleRtpDataCodecName;
|
2015-09-17 16:42:56 +02:00
|
|
|
cricket::DataRecvParameters parameters;
|
|
|
|
|
parameters.codecs.push_back(codec);
|
|
|
|
|
ASSERT_TRUE(dmc->SetRecvParameters(parameters));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Unknown stream
|
2014-07-29 17:36:52 +00:00
|
|
|
dmc->OnPacketReceived(&packet, rtc::PacketTime());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(HasReceivedData());
|
|
|
|
|
|
|
|
|
|
cricket::StreamParams stream;
|
|
|
|
|
stream.add_ssrc(42);
|
|
|
|
|
ASSERT_TRUE(dmc->AddRecvStream(stream));
|
|
|
|
|
|
|
|
|
|
// Finally works!
|
2014-07-29 17:36:52 +00:00
|
|
|
dmc->OnPacketReceived(&packet, rtc::PacketTime());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(HasReceivedData());
|
|
|
|
|
EXPECT_EQ("abcde", GetReceivedData());
|
|
|
|
|
EXPECT_EQ(5U, GetReceivedDataLen());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(RtpDataMediaChannelTest, InvalidRtpPackets) {
|
|
|
|
|
unsigned char data[] = {
|
|
|
|
|
0x80, 0x65, 0x00, 0x02
|
|
|
|
|
};
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer packet(data, sizeof(data));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Too short
|
2014-07-29 17:36:52 +00:00
|
|
|
dmc->OnPacketReceived(&packet, rtc::PacketTime());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(HasReceivedData());
|
|
|
|
|
}
|