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
|
|
|
*/
|
|
|
|
|
|
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"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-03-20 06:15:43 -07:00
|
|
|
#include "webrtc/base/copyonwritebuffer.h"
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/helpers.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
|
#include "webrtc/base/ratelimiter.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/codec.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/rtputils.h"
|
|
|
|
|
#include "webrtc/media/base/streamparams.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
// We want to avoid IP fragmentation.
|
|
|
|
|
static const size_t kDataMaxRtpPacketLen = 1200U;
|
|
|
|
|
// We reserve space after the RTP header for future wiggle room.
|
|
|
|
|
static const unsigned char kReservedSpace[] = {
|
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Amount of overhead SRTP may take. We need to leave room in the
|
|
|
|
|
// buffer for it, otherwise SRTP will fail later. If SRTP ever uses
|
|
|
|
|
// more than this, we need to increase this number.
|
|
|
|
|
static const size_t kMaxSrtpHmacOverhead = 16;
|
|
|
|
|
|
|
|
|
|
RtpDataEngine::RtpDataEngine() {
|
|
|
|
|
data_codecs_.push_back(
|
2016-10-08 13:02:44 -07:00
|
|
|
DataCodec(kGoogleRtpDataCodecPlType, kGoogleRtpDataCodecName));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataMediaChannel* RtpDataEngine::CreateChannel(
|
|
|
|
|
DataChannelType data_channel_type) {
|
|
|
|
|
if (data_channel_type != DCT_RTP) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-09-13 23:41:47 -07:00
|
|
|
return new RtpDataMediaChannel();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FindCodecByName(const std::vector<DataCodec>& codecs,
|
|
|
|
|
const std::string& name, DataCodec* codec_out) {
|
|
|
|
|
std::vector<DataCodec>::const_iterator iter;
|
|
|
|
|
for (iter = codecs.begin(); iter != codecs.end(); ++iter) {
|
|
|
|
|
if (iter->name == name) {
|
|
|
|
|
*codec_out = *iter;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpDataMediaChannel::RtpDataMediaChannel() {
|
2016-09-13 23:41:47 -07:00
|
|
|
Construct();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-13 23:41:47 -07:00
|
|
|
void RtpDataMediaChannel::Construct() {
|
2013-07-10 00:45:36 +00:00
|
|
|
sending_ = false;
|
|
|
|
|
receiving_ = false;
|
2014-07-29 17:36:52 +00:00
|
|
|
send_limiter_.reset(new rtc::RateLimiter(kDataMaxBandwidth / 8, 1.0));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RtpDataMediaChannel::~RtpDataMediaChannel() {
|
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
|
|
|
std::map<uint32_t, RtpClock*>::const_iterator iter;
|
2013-07-10 00:45:36 +00:00
|
|
|
for (iter = rtp_clock_by_send_ssrc_.begin();
|
|
|
|
|
iter != rtp_clock_by_send_ssrc_.end();
|
|
|
|
|
++iter) {
|
|
|
|
|
delete iter->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
void RtpClock::Tick(double now, int* seq_num, uint32_t* timestamp) {
|
2013-07-10 00:45:36 +00:00
|
|
|
*seq_num = ++last_seq_num_;
|
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
|
|
|
*timestamp = timestamp_offset_ + static_cast<uint32_t>(now * clockrate_);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DataCodec* FindUnknownCodec(const std::vector<DataCodec>& codecs) {
|
2016-10-08 13:02:44 -07:00
|
|
|
DataCodec data_codec(kGoogleRtpDataCodecPlType, kGoogleRtpDataCodecName);
|
2013-07-10 00:45:36 +00:00
|
|
|
std::vector<DataCodec>::const_iterator iter;
|
|
|
|
|
for (iter = codecs.begin(); iter != codecs.end(); ++iter) {
|
|
|
|
|
if (!iter->Matches(data_codec)) {
|
|
|
|
|
return &(*iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DataCodec* FindKnownCodec(const std::vector<DataCodec>& codecs) {
|
2016-10-08 13:02:44 -07:00
|
|
|
DataCodec data_codec(kGoogleRtpDataCodecPlType, kGoogleRtpDataCodecName);
|
2013-07-10 00:45:36 +00:00
|
|
|
std::vector<DataCodec>::const_iterator iter;
|
|
|
|
|
for (iter = codecs.begin(); iter != codecs.end(); ++iter) {
|
|
|
|
|
if (iter->Matches(data_codec)) {
|
|
|
|
|
return &(*iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) {
|
|
|
|
|
const DataCodec* unknown_codec = FindUnknownCodec(codecs);
|
|
|
|
|
if (unknown_codec) {
|
|
|
|
|
LOG(LS_WARNING) << "Failed to SetRecvCodecs because of unknown codec: "
|
|
|
|
|
<< unknown_codec->ToString();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recv_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpDataMediaChannel::SetSendCodecs(const std::vector<DataCodec>& codecs) {
|
|
|
|
|
const DataCodec* known_codec = FindKnownCodec(codecs);
|
|
|
|
|
if (!known_codec) {
|
|
|
|
|
LOG(LS_WARNING) <<
|
|
|
|
|
"Failed to SetSendCodecs because there is no known codec.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-17 16:42:56 +02:00
|
|
|
bool RtpDataMediaChannel::SetSendParameters(const DataSendParameters& params) {
|
|
|
|
|
return (SetSendCodecs(params.codecs) &&
|
|
|
|
|
SetMaxSendBandwidth(params.max_bandwidth_bps));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpDataMediaChannel::SetRecvParameters(const DataRecvParameters& params) {
|
|
|
|
|
return SetRecvCodecs(params.codecs);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
bool RtpDataMediaChannel::AddSendStream(const StreamParams& stream) {
|
|
|
|
|
if (!stream.has_ssrcs()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 23:00:41 +00:00
|
|
|
if (GetStreamBySsrc(send_streams_, stream.first_ssrc())) {
|
2013-07-10 00:45:36 +00:00
|
|
|
LOG(LS_WARNING) << "Not adding data send stream '" << stream.id
|
|
|
|
|
<< "' with ssrc=" << stream.first_ssrc()
|
|
|
|
|
<< " because stream already exists.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send_streams_.push_back(stream);
|
|
|
|
|
// TODO(pthatcher): This should be per-stream, not per-ssrc.
|
|
|
|
|
// And we should probably allow more than one per stream.
|
|
|
|
|
rtp_clock_by_send_ssrc_[stream.first_ssrc()] = new RtpClock(
|
|
|
|
|
kDataCodecClockrate,
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::CreateRandomNonZeroId(), rtc::CreateRandomNonZeroId());
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
LOG(LS_INFO) << "Added data send stream '" << stream.id
|
|
|
|
|
<< "' with ssrc=" << stream.first_ssrc();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
bool RtpDataMediaChannel::RemoveSendStream(uint32_t ssrc) {
|
2015-01-22 23:00:41 +00:00
|
|
|
if (!GetStreamBySsrc(send_streams_, ssrc)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemoveStreamBySsrc(&send_streams_, ssrc);
|
|
|
|
|
delete rtp_clock_by_send_ssrc_[ssrc];
|
|
|
|
|
rtp_clock_by_send_ssrc_.erase(ssrc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpDataMediaChannel::AddRecvStream(const StreamParams& stream) {
|
|
|
|
|
if (!stream.has_ssrcs()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 23:00:41 +00:00
|
|
|
if (GetStreamBySsrc(recv_streams_, stream.first_ssrc())) {
|
2013-07-10 00:45:36 +00:00
|
|
|
LOG(LS_WARNING) << "Not adding data recv stream '" << stream.id
|
|
|
|
|
<< "' with ssrc=" << stream.first_ssrc()
|
|
|
|
|
<< " because stream already exists.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recv_streams_.push_back(stream);
|
|
|
|
|
LOG(LS_INFO) << "Added data recv stream '" << stream.id
|
|
|
|
|
<< "' with ssrc=" << stream.first_ssrc();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
bool RtpDataMediaChannel::RemoveRecvStream(uint32_t ssrc) {
|
2013-07-10 00:45:36 +00:00
|
|
|
RemoveStreamBySsrc(&recv_streams_, ssrc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 00:21:03 +00:00
|
|
|
void RtpDataMediaChannel::OnPacketReceived(
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) {
|
2013-07-10 00:45:36 +00:00
|
|
|
RtpHeader header;
|
2016-03-20 06:15:43 -07:00
|
|
|
if (!GetRtpHeader(packet->cdata(), packet->size(), &header)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
// Don't want to log for every corrupt packet.
|
|
|
|
|
// LOG(LS_WARNING) << "Could not read rtp header from packet of length "
|
|
|
|
|
// << packet->length() << ".";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t header_length;
|
2016-03-20 06:15:43 -07:00
|
|
|
if (!GetRtpHeaderLen(packet->cdata(), packet->size(), &header_length)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
// Don't want to log for every corrupt packet.
|
|
|
|
|
// LOG(LS_WARNING) << "Could not read rtp header"
|
|
|
|
|
// << length from packet of length "
|
|
|
|
|
// << packet->length() << ".";
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
|
|
const char* data =
|
2016-03-20 06:15:43 -07:00
|
|
|
packet->cdata<char>() + header_length + sizeof(kReservedSpace);
|
2015-03-24 09:19:06 +00:00
|
|
|
size_t data_len = packet->size() - header_length - sizeof(kReservedSpace);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
if (!receiving_) {
|
|
|
|
|
LOG(LS_WARNING) << "Not receiving packet "
|
|
|
|
|
<< header.ssrc << ":" << header.seq_num
|
|
|
|
|
<< " before SetReceive(true) called.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 04:00:16 -08:00
|
|
|
if (!FindCodecById(recv_codecs_, header.payload_type)) {
|
2013-12-05 00:24:06 +00:00
|
|
|
// For bundling, this will be logged for every message.
|
|
|
|
|
// So disable this logging.
|
|
|
|
|
// LOG(LS_WARNING) << "Not receiving packet "
|
|
|
|
|
// << header.ssrc << ":" << header.seq_num
|
|
|
|
|
// << " (" << data_len << ")"
|
|
|
|
|
// << " because unknown payload id: " << header.payload_type;
|
2013-07-10 00:45:36 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 23:00:41 +00:00
|
|
|
if (!GetStreamBySsrc(recv_streams_, header.ssrc)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
LOG(LS_WARNING) << "Received packet for unknown ssrc: " << header.ssrc;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Uncomment this for easy debugging.
|
2015-01-22 23:00:41 +00:00
|
|
|
// const auto* found_stream = GetStreamBySsrc(recv_streams_, header.ssrc);
|
2013-07-10 00:45:36 +00:00
|
|
|
// LOG(LS_INFO) << "Received packet"
|
|
|
|
|
// << " groupid=" << found_stream.groupid
|
|
|
|
|
// << ", ssrc=" << header.ssrc
|
|
|
|
|
// << ", seqnum=" << header.seq_num
|
|
|
|
|
// << ", timestamp=" << header.timestamp
|
|
|
|
|
// << ", len=" << data_len;
|
|
|
|
|
|
|
|
|
|
ReceiveDataParams params;
|
|
|
|
|
params.ssrc = header.ssrc;
|
|
|
|
|
params.seq_num = header.seq_num;
|
|
|
|
|
params.timestamp = header.timestamp;
|
|
|
|
|
SignalDataReceived(params, data, data_len);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-15 23:15:54 +00:00
|
|
|
bool RtpDataMediaChannel::SetMaxSendBandwidth(int bps) {
|
|
|
|
|
if (bps <= 0) {
|
2013-07-10 00:45:36 +00:00
|
|
|
bps = kDataMaxBandwidth;
|
|
|
|
|
}
|
2014-07-29 17:36:52 +00:00
|
|
|
send_limiter_.reset(new rtc::RateLimiter(bps / 8, 1.0));
|
2013-07-10 00:45:36 +00:00
|
|
|
LOG(LS_INFO) << "RtpDataMediaChannel::SetSendBandwidth to " << bps << "bps.";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpDataMediaChannel::SendData(
|
|
|
|
|
const SendDataParams& params,
|
2016-03-20 06:15:43 -07:00
|
|
|
const rtc::CopyOnWriteBuffer& payload,
|
2013-07-10 00:45:36 +00:00
|
|
|
SendDataResult* result) {
|
|
|
|
|
if (result) {
|
|
|
|
|
// If we return true, we'll set this to SDR_SUCCESS.
|
|
|
|
|
*result = SDR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (!sending_) {
|
|
|
|
|
LOG(LS_WARNING) << "Not sending packet with ssrc=" << params.ssrc
|
2015-03-24 09:19:06 +00:00
|
|
|
<< " len=" << payload.size() << " before SetSend(true).";
|
2013-07-10 00:45:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params.type != cricket::DMT_TEXT) {
|
|
|
|
|
LOG(LS_WARNING) << "Not sending data because binary type is unsupported.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 23:00:41 +00:00
|
|
|
const StreamParams* found_stream =
|
|
|
|
|
GetStreamBySsrc(send_streams_, params.ssrc);
|
|
|
|
|
if (!found_stream) {
|
2013-07-10 00:45:36 +00:00
|
|
|
LOG(LS_WARNING) << "Not sending data because ssrc is unknown: "
|
|
|
|
|
<< params.ssrc;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataCodec found_codec;
|
|
|
|
|
if (!FindCodecByName(send_codecs_, kGoogleRtpDataCodecName, &found_codec)) {
|
|
|
|
|
LOG(LS_WARNING) << "Not sending data because codec is unknown: "
|
|
|
|
|
<< kGoogleRtpDataCodecName;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-24 09:19:06 +00:00
|
|
|
size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace) +
|
|
|
|
|
payload.size() + kMaxSrtpHmacOverhead);
|
2013-07-10 00:45:36 +00:00
|
|
|
if (packet_len > kDataMaxRtpPacketLen) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-13 23:41:47 -07:00
|
|
|
double now =
|
|
|
|
|
rtc::TimeMicros() / static_cast<double>(rtc::kNumMicrosecsPerSec);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
if (!send_limiter_->CanUse(packet_len, now)) {
|
|
|
|
|
LOG(LS_VERBOSE) << "Dropped data packet of len=" << packet_len
|
|
|
|
|
<< "; already sent " << send_limiter_->used_in_period()
|
|
|
|
|
<< "/" << send_limiter_->max_per_period();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpHeader header;
|
|
|
|
|
header.payload_type = found_codec.id;
|
|
|
|
|
header.ssrc = params.ssrc;
|
|
|
|
|
rtp_clock_by_send_ssrc_[header.ssrc]->Tick(
|
|
|
|
|
now, &header.seq_num, &header.timestamp);
|
|
|
|
|
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer packet(kMinRtpPacketLen, packet_len);
|
2015-03-24 09:19:06 +00:00
|
|
|
if (!SetRtpHeader(packet.data(), packet.size(), header)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
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
|
|
|
packet.AppendData(kReservedSpace);
|
|
|
|
|
packet.AppendData(payload);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2013-09-27 23:04:10 +00:00
|
|
|
LOG(LS_VERBOSE) << "Sent RTP data packet: "
|
2015-03-24 09:19:06 +00:00
|
|
|
<< " stream=" << found_stream->id << " ssrc=" << header.ssrc
|
2013-09-27 23:04:10 +00:00
|
|
|
<< ", seqnum=" << header.seq_num
|
|
|
|
|
<< ", timestamp=" << header.timestamp
|
2015-03-24 09:19:06 +00:00
|
|
|
<< ", len=" << payload.size();
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-10-15 07:26:07 -07:00
|
|
|
MediaChannel::SendPacket(&packet, rtc::PacketOptions());
|
2013-07-10 00:45:36 +00:00
|
|
|
send_limiter_->Use(packet_len, now);
|
|
|
|
|
if (result) {
|
|
|
|
|
*result = SDR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|