2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2004 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
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MEDIA_BASE_FAKEMEDIAENGINE_H_
|
|
|
|
|
#define MEDIA_BASE_FAKEMEDIAENGINE_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <map>
|
2016-02-26 03:00:35 -08:00
|
|
|
#include <memory>
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
2017-10-31 09:53:08 -07:00
|
|
|
#include <tuple>
|
|
|
|
|
#include <utility>
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/call/audio_sink.h"
|
|
|
|
|
#include "media/base/audiosource.h"
|
|
|
|
|
#include "media/base/mediaengine.h"
|
|
|
|
|
#include "media/base/rtputils.h"
|
|
|
|
|
#include "media/base/streamparams.h"
|
|
|
|
|
#include "media/engine/webrtcvideoengine.h"
|
|
|
|
|
#include "modules/audio_processing/include/audio_processing.h"
|
|
|
|
|
#include "p2p/base/sessiondescription.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/copyonwritebuffer.h"
|
|
|
|
|
#include "rtc_base/networkroute.h"
|
|
|
|
|
#include "rtc_base/ptr_util.h"
|
|
|
|
|
#include "rtc_base/stringutils.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-05-26 11:24:55 -07:00
|
|
|
using webrtc::RtpExtension;
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
class FakeMediaEngine;
|
|
|
|
|
class FakeVideoEngine;
|
|
|
|
|
class FakeVoiceEngine;
|
|
|
|
|
|
|
|
|
|
// A common helper class that handles sending and receiving RTP/RTCP packets.
|
|
|
|
|
template <class Base> class RtpHelper : public Base {
|
|
|
|
|
public:
|
|
|
|
|
RtpHelper()
|
|
|
|
|
: sending_(false),
|
|
|
|
|
playout_(false),
|
|
|
|
|
fail_set_send_codecs_(false),
|
|
|
|
|
fail_set_recv_codecs_(false),
|
|
|
|
|
send_ssrc_(0),
|
2017-08-09 06:42:32 -07:00
|
|
|
ready_to_send_(false),
|
|
|
|
|
transport_overhead_per_packet_(0),
|
|
|
|
|
num_network_route_changes_(0) {}
|
|
|
|
|
virtual ~RtpHelper() = default;
|
2016-05-26 11:24:55 -07:00
|
|
|
const std::vector<RtpExtension>& recv_extensions() {
|
2013-07-10 00:45:36 +00:00
|
|
|
return recv_extensions_;
|
|
|
|
|
}
|
2016-05-26 11:24:55 -07:00
|
|
|
const std::vector<RtpExtension>& send_extensions() {
|
2013-07-10 00:45:36 +00:00
|
|
|
return send_extensions_;
|
|
|
|
|
}
|
|
|
|
|
bool sending() const { return sending_; }
|
|
|
|
|
bool playout() const { return playout_; }
|
|
|
|
|
const std::list<std::string>& rtp_packets() const { return rtp_packets_; }
|
|
|
|
|
const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; }
|
|
|
|
|
|
2016-05-11 19:55:27 +02:00
|
|
|
bool SendRtp(const void* data,
|
|
|
|
|
size_t len,
|
|
|
|
|
const rtc::PacketOptions& options) {
|
2013-07-26 19:17:59 +00:00
|
|
|
if (!sending_) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len,
|
|
|
|
|
kMaxRtpPacketLen);
|
2015-10-15 07:26:07 -07:00
|
|
|
return Base::SendPacket(&packet, options);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-05-11 19:55:27 +02:00
|
|
|
bool SendRtcp(const void* data, size_t len) {
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len,
|
|
|
|
|
kMaxRtpPacketLen);
|
2015-10-15 07:26:07 -07:00
|
|
|
return Base::SendRtcp(&packet, rtc::PacketOptions());
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 19:55:27 +02:00
|
|
|
bool CheckRtp(const void* data, size_t len) {
|
2013-07-10 00:45:36 +00:00
|
|
|
bool success = !rtp_packets_.empty();
|
|
|
|
|
if (success) {
|
|
|
|
|
std::string packet = rtp_packets_.front();
|
|
|
|
|
rtp_packets_.pop_front();
|
|
|
|
|
success = (packet == std::string(static_cast<const char*>(data), len));
|
|
|
|
|
}
|
|
|
|
|
return success;
|
|
|
|
|
}
|
2016-05-11 19:55:27 +02:00
|
|
|
bool CheckRtcp(const void* data, size_t len) {
|
2013-07-10 00:45:36 +00:00
|
|
|
bool success = !rtcp_packets_.empty();
|
|
|
|
|
if (success) {
|
|
|
|
|
std::string packet = rtcp_packets_.front();
|
|
|
|
|
rtcp_packets_.pop_front();
|
|
|
|
|
success = (packet == std::string(static_cast<const char*>(data), len));
|
|
|
|
|
}
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
bool CheckNoRtp() { return rtp_packets_.empty(); }
|
|
|
|
|
bool CheckNoRtcp() { return rtcp_packets_.empty(); }
|
|
|
|
|
void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; }
|
|
|
|
|
void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; }
|
|
|
|
|
virtual bool AddSendStream(const StreamParams& sp) {
|
|
|
|
|
if (std::find(send_streams_.begin(), send_streams_.end(), sp) !=
|
|
|
|
|
send_streams_.end()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
send_streams_.push_back(sp);
|
2016-05-16 11:40:30 -07:00
|
|
|
rtp_send_parameters_[sp.first_ssrc()] =
|
|
|
|
|
CreateRtpParametersWithOneEncoding();
|
2013-07-10 00:45:36 +00:00
|
|
|
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
|
|
|
virtual bool RemoveSendStream(uint32_t ssrc) {
|
2016-05-16 11:40:30 -07:00
|
|
|
auto parameters_iterator = rtp_send_parameters_.find(ssrc);
|
|
|
|
|
if (parameters_iterator != rtp_send_parameters_.end()) {
|
|
|
|
|
rtp_send_parameters_.erase(parameters_iterator);
|
2016-03-16 19:07:43 -07:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
return RemoveStreamBySsrc(&send_streams_, ssrc);
|
|
|
|
|
}
|
|
|
|
|
virtual bool AddRecvStream(const StreamParams& sp) {
|
|
|
|
|
if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) !=
|
|
|
|
|
receive_streams_.end()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
receive_streams_.push_back(sp);
|
2016-05-16 11:40:30 -07:00
|
|
|
rtp_receive_parameters_[sp.first_ssrc()] =
|
|
|
|
|
CreateRtpParametersWithOneEncoding();
|
2013-07-10 00:45:36 +00:00
|
|
|
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
|
|
|
virtual bool RemoveRecvStream(uint32_t ssrc) {
|
2016-05-16 11:40:30 -07:00
|
|
|
auto parameters_iterator = rtp_receive_parameters_.find(ssrc);
|
|
|
|
|
if (parameters_iterator != rtp_receive_parameters_.end()) {
|
|
|
|
|
rtp_receive_parameters_.erase(parameters_iterator);
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
return RemoveStreamBySsrc(&receive_streams_, ssrc);
|
|
|
|
|
}
|
2016-03-16 19:07:43 -07:00
|
|
|
|
2016-05-16 11:40:30 -07:00
|
|
|
virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const {
|
|
|
|
|
auto parameters_iterator = rtp_send_parameters_.find(ssrc);
|
|
|
|
|
if (parameters_iterator != rtp_send_parameters_.end()) {
|
|
|
|
|
return parameters_iterator->second;
|
|
|
|
|
}
|
|
|
|
|
return webrtc::RtpParameters();
|
|
|
|
|
}
|
|
|
|
|
virtual bool SetRtpSendParameters(uint32_t ssrc,
|
|
|
|
|
const webrtc::RtpParameters& parameters) {
|
|
|
|
|
auto parameters_iterator = rtp_send_parameters_.find(ssrc);
|
|
|
|
|
if (parameters_iterator != rtp_send_parameters_.end()) {
|
|
|
|
|
parameters_iterator->second = parameters;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Replicate the behavior of the real media channel: return false
|
|
|
|
|
// when setting parameters for unknown SSRCs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const {
|
|
|
|
|
auto parameters_iterator = rtp_receive_parameters_.find(ssrc);
|
|
|
|
|
if (parameters_iterator != rtp_receive_parameters_.end()) {
|
2016-03-16 19:07:43 -07:00
|
|
|
return parameters_iterator->second;
|
|
|
|
|
}
|
|
|
|
|
return webrtc::RtpParameters();
|
|
|
|
|
}
|
2016-05-16 11:40:30 -07:00
|
|
|
virtual bool SetRtpReceiveParameters(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
const webrtc::RtpParameters& parameters) {
|
|
|
|
|
auto parameters_iterator = rtp_receive_parameters_.find(ssrc);
|
|
|
|
|
if (parameters_iterator != rtp_receive_parameters_.end()) {
|
2016-03-16 19:07:43 -07:00
|
|
|
parameters_iterator->second = parameters;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Replicate the behavior of the real media channel: return false
|
|
|
|
|
// when setting parameters for unknown SSRCs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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 IsStreamMuted(uint32_t ssrc) const {
|
2013-07-10 00:45:36 +00:00
|
|
|
bool ret = muted_streams_.find(ssrc) != muted_streams_.end();
|
|
|
|
|
// If |ssrc = 0| check if the first send stream is muted.
|
|
|
|
|
if (!ret && ssrc == 0 && !send_streams_.empty()) {
|
|
|
|
|
return muted_streams_.find(send_streams_[0].first_ssrc()) !=
|
|
|
|
|
muted_streams_.end();
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
const std::vector<StreamParams>& send_streams() const {
|
|
|
|
|
return send_streams_;
|
|
|
|
|
}
|
|
|
|
|
const std::vector<StreamParams>& recv_streams() const {
|
|
|
|
|
return receive_streams_;
|
|
|
|
|
}
|
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 HasRecvStream(uint32_t ssrc) const {
|
2015-01-22 23:00:41 +00:00
|
|
|
return GetStreamBySsrc(receive_streams_, ssrc) != nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
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 HasSendStream(uint32_t ssrc) const {
|
2015-01-22 23:00:41 +00:00
|
|
|
return GetStreamBySsrc(send_streams_, ssrc) != nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
// TODO(perkj): This is to support legacy unit test that only check one
|
|
|
|
|
// sending stream.
|
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
|
|
|
uint32_t send_ssrc() const {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (send_streams_.empty())
|
|
|
|
|
return 0;
|
|
|
|
|
return send_streams_[0].first_ssrc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(perkj): This is to support legacy unit test that only check one
|
|
|
|
|
// sending stream.
|
|
|
|
|
const std::string rtcp_cname() {
|
|
|
|
|
if (send_streams_.empty())
|
|
|
|
|
return "";
|
|
|
|
|
return send_streams_[0].cname;
|
|
|
|
|
}
|
2017-02-25 18:15:09 -08:00
|
|
|
const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; }
|
|
|
|
|
const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
bool ready_to_send() const {
|
|
|
|
|
return ready_to_send_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 02:50:09 -08:00
|
|
|
int transport_overhead_per_packet() const {
|
|
|
|
|
return transport_overhead_per_packet_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 15:41:36 -07:00
|
|
|
rtc::NetworkRoute last_network_route() const { return last_network_route_; }
|
2016-03-29 17:27:21 -07:00
|
|
|
int num_network_route_changes() const { return num_network_route_changes_; }
|
|
|
|
|
void set_num_network_route_changes(int changes) {
|
|
|
|
|
num_network_route_changes_ = changes;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
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 MuteStream(uint32_t ssrc, bool mute) {
|
2015-09-17 16:42:56 +02:00
|
|
|
if (!HasSendStream(ssrc) && ssrc != 0) {
|
2015-09-10 01:57:14 -07:00
|
|
|
return false;
|
2015-09-17 16:42:56 +02:00
|
|
|
}
|
|
|
|
|
if (mute) {
|
2015-09-10 01:57:14 -07:00
|
|
|
muted_streams_.insert(ssrc);
|
2015-09-17 16:42:56 +02:00
|
|
|
} else {
|
2015-09-10 01:57:14 -07:00
|
|
|
muted_streams_.erase(ssrc);
|
2015-09-17 16:42:56 +02:00
|
|
|
}
|
2015-09-10 01:57:14 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
bool set_sending(bool send) {
|
|
|
|
|
sending_ = send;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
void set_playout(bool playout) { playout_ = playout; }
|
2016-05-26 11:24:55 -07:00
|
|
|
bool SetRecvRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) {
|
2015-09-17 16:42:56 +02:00
|
|
|
recv_extensions_ = extensions;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-05-26 11:24:55 -07:00
|
|
|
bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) {
|
2015-09-17 16:42:56 +02:00
|
|
|
send_extensions_ = extensions;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-02-25 18:15:09 -08:00
|
|
|
void set_send_rtcp_parameters(const RtcpParameters& params) {
|
|
|
|
|
send_rtcp_parameters_ = params;
|
|
|
|
|
}
|
|
|
|
|
void set_recv_rtcp_parameters(const RtcpParameters& params) {
|
|
|
|
|
recv_rtcp_parameters_ = params;
|
|
|
|
|
}
|
2016-03-20 06:15:43 -07:00
|
|
|
virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
|
2014-07-29 17:36:52 +00:00
|
|
|
const rtc::PacketTime& packet_time) {
|
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
|
|
|
rtp_packets_.push_back(std::string(packet->data<char>(), packet->size()));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-03-20 06:15:43 -07:00
|
|
|
virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
|
2014-07-29 17:36:52 +00:00
|
|
|
const rtc::PacketTime& packet_time) {
|
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
|
|
|
rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size()));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
virtual void OnReadyToSend(bool ready) {
|
|
|
|
|
ready_to_send_ = ready;
|
|
|
|
|
}
|
2016-11-08 02:50:09 -08:00
|
|
|
|
2016-03-29 17:27:21 -07:00
|
|
|
virtual void OnNetworkRouteChanged(const std::string& transport_name,
|
2016-04-19 15:41:36 -07:00
|
|
|
const rtc::NetworkRoute& network_route) {
|
2016-03-29 17:27:21 -07:00
|
|
|
last_network_route_ = network_route;
|
|
|
|
|
++num_network_route_changes_;
|
2017-11-12 17:26:23 -08:00
|
|
|
transport_overhead_per_packet_ = network_route.packet_overhead;
|
2016-03-29 17:27:21 -07:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
bool fail_set_send_codecs() const { return fail_set_send_codecs_; }
|
|
|
|
|
bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool sending_;
|
|
|
|
|
bool playout_;
|
2016-05-26 11:24:55 -07:00
|
|
|
std::vector<RtpExtension> recv_extensions_;
|
|
|
|
|
std::vector<RtpExtension> send_extensions_;
|
2013-07-10 00:45:36 +00:00
|
|
|
std::list<std::string> rtp_packets_;
|
|
|
|
|
std::list<std::string> rtcp_packets_;
|
|
|
|
|
std::vector<StreamParams> send_streams_;
|
|
|
|
|
std::vector<StreamParams> receive_streams_;
|
2017-02-25 18:15:09 -08:00
|
|
|
RtcpParameters send_rtcp_parameters_;
|
|
|
|
|
RtcpParameters recv_rtcp_parameters_;
|
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::set<uint32_t> muted_streams_;
|
2016-05-16 11:40:30 -07:00
|
|
|
std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_;
|
|
|
|
|
std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_;
|
2013-07-10 00:45:36 +00:00
|
|
|
bool fail_set_send_codecs_;
|
|
|
|
|
bool fail_set_recv_codecs_;
|
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
|
|
|
uint32_t send_ssrc_;
|
2013-07-10 00:45:36 +00:00
|
|
|
std::string rtcp_cname_;
|
|
|
|
|
bool ready_to_send_;
|
2016-11-08 02:50:09 -08:00
|
|
|
int transport_overhead_per_packet_;
|
2016-04-19 15:41:36 -07:00
|
|
|
rtc::NetworkRoute last_network_route_;
|
2017-08-09 06:42:32 -07:00
|
|
|
int num_network_route_changes_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
|
|
|
|
|
public:
|
|
|
|
|
struct DtmfInfo {
|
2015-12-02 12:35:09 -08:00
|
|
|
DtmfInfo(uint32_t ssrc, int event_code, int duration)
|
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
|
|
|
: ssrc(ssrc),
|
|
|
|
|
event_code(event_code),
|
2015-12-02 12:35:09 -08:00
|
|
|
duration(duration) {}
|
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
|
|
|
uint32_t ssrc;
|
2013-07-10 00:45:36 +00:00
|
|
|
int event_code;
|
|
|
|
|
int duration;
|
|
|
|
|
};
|
2015-09-17 16:42:56 +02:00
|
|
|
explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine,
|
|
|
|
|
const AudioOptions& options)
|
2017-02-10 01:20:25 -08:00
|
|
|
: engine_(engine), max_bps_(-1) {
|
2015-10-09 02:32:53 -07:00
|
|
|
output_scalings_[0] = 1.0; // For default channel.
|
2015-09-17 16:42:56 +02:00
|
|
|
SetOptions(options);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
~FakeVoiceMediaChannel();
|
|
|
|
|
const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; }
|
|
|
|
|
const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; }
|
|
|
|
|
const std::vector<AudioCodec>& codecs() const { return send_codecs(); }
|
|
|
|
|
const std::vector<DtmfInfo>& dtmf_info_queue() const {
|
|
|
|
|
return dtmf_info_queue_;
|
|
|
|
|
}
|
|
|
|
|
const AudioOptions& options() const { return options_; }
|
2016-03-16 19:07:43 -07:00
|
|
|
int max_bps() const { return max_bps_; }
|
2015-09-17 16:42:56 +02:00
|
|
|
virtual bool SetSendParameters(const AudioSendParameters& params) {
|
2017-02-25 18:15:09 -08:00
|
|
|
set_send_rtcp_parameters(params.rtcp);
|
2015-09-17 16:42:56 +02:00
|
|
|
return (SetSendCodecs(params.codecs) &&
|
|
|
|
|
SetSendRtpHeaderExtensions(params.extensions) &&
|
|
|
|
|
SetMaxSendBandwidth(params.max_bandwidth_bps) &&
|
|
|
|
|
SetOptions(params.options));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2015-09-17 16:42:56 +02:00
|
|
|
|
|
|
|
|
virtual bool SetRecvParameters(const AudioRecvParameters& params) {
|
2017-02-25 18:15:09 -08:00
|
|
|
set_recv_rtcp_parameters(params.rtcp);
|
2015-09-17 16:42:56 +02:00
|
|
|
return (SetRecvCodecs(params.codecs) &&
|
|
|
|
|
SetRecvRtpHeaderExtensions(params.extensions));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-03-16 19:07:43 -07:00
|
|
|
|
2016-08-04 05:28:21 -07:00
|
|
|
virtual void SetPlayout(bool playout) { set_playout(playout); }
|
2016-03-08 12:37:39 -08:00
|
|
|
virtual void SetSend(bool send) { set_sending(send); }
|
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
|
|
|
virtual bool SetAudioSend(uint32_t ssrc,
|
|
|
|
|
bool enable,
|
2015-09-10 01:57:14 -07:00
|
|
|
const AudioOptions* options,
|
2016-03-08 12:37:39 -08:00
|
|
|
AudioSource* source) {
|
|
|
|
|
if (!SetLocalSource(ssrc, source)) {
|
2015-09-10 01:57:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-10-01 02:31:10 -07:00
|
|
|
if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) {
|
2015-09-10 01:57:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-10-01 02:31:10 -07:00
|
|
|
if (enable && options) {
|
2015-09-10 01:57:14 -07:00
|
|
|
return SetOptions(*options);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-06-27 16:30:35 -07:00
|
|
|
|
|
|
|
|
bool HasSource(uint32_t ssrc) const {
|
|
|
|
|
return local_sinks_.find(ssrc) != local_sinks_.end();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual bool AddRecvStream(const StreamParams& sp) {
|
|
|
|
|
if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp))
|
|
|
|
|
return false;
|
2015-10-09 02:32:53 -07:00
|
|
|
output_scalings_[sp.first_ssrc()] = 1.0;
|
2013-07-10 00:45:36 +00:00
|
|
|
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
|
|
|
virtual bool RemoveRecvStream(uint32_t ssrc) {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc))
|
|
|
|
|
return false;
|
|
|
|
|
output_scalings_.erase(ssrc);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; }
|
|
|
|
|
virtual int GetOutputLevel() { return 0; }
|
|
|
|
|
|
|
|
|
|
virtual bool CanInsertDtmf() {
|
|
|
|
|
for (std::vector<AudioCodec>::const_iterator it = send_codecs_.begin();
|
|
|
|
|
it != send_codecs_.end(); ++it) {
|
|
|
|
|
// Find the DTMF telephone event "codec".
|
|
|
|
|
if (_stricmp(it->name.c_str(), "telephone-event") == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
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
|
|
|
virtual bool InsertDtmf(uint32_t ssrc,
|
|
|
|
|
int event_code,
|
2015-12-02 12:35:09 -08:00
|
|
|
int duration) {
|
|
|
|
|
dtmf_info_queue_.push_back(DtmfInfo(ssrc, event_code, duration));
|
2013-07-10 00:45:36 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-09 02:32:53 -07:00
|
|
|
virtual bool SetOutputVolume(uint32_t ssrc, double volume) {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (0 == ssrc) {
|
2015-10-09 02:32:53 -07:00
|
|
|
std::map<uint32_t, double>::iterator it;
|
2013-07-10 00:45:36 +00:00
|
|
|
for (it = output_scalings_.begin(); it != output_scalings_.end(); ++it) {
|
2015-10-09 02:32:53 -07:00
|
|
|
it->second = volume;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else if (output_scalings_.find(ssrc) != output_scalings_.end()) {
|
2015-10-09 02:32:53 -07:00
|
|
|
output_scalings_[ssrc] = volume;
|
2013-07-10 00:45:36 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-10-09 02:32:53 -07:00
|
|
|
bool GetOutputVolume(uint32_t ssrc, double* volume) {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (output_scalings_.find(ssrc) == output_scalings_.end())
|
|
|
|
|
return false;
|
2015-10-09 02:32:53 -07:00
|
|
|
*volume = output_scalings_[ssrc];
|
2013-07-10 00:45:36 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool GetStats(VoiceMediaInfo* info) { return false; }
|
|
|
|
|
|
2015-12-12 01:37:01 +01:00
|
|
|
virtual void SetRawAudioSink(
|
|
|
|
|
uint32_t ssrc,
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<webrtc::AudioSinkInterface> sink) {
|
2016-01-13 12:00:26 -08:00
|
|
|
sink_ = std::move(sink);
|
2015-12-12 01:37:01 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-15 12:52:32 -07:00
|
|
|
virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const {
|
|
|
|
|
return std::vector<webrtc::RtpSource>();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
2016-03-08 12:37:39 -08:00
|
|
|
class VoiceChannelAudioSink : public AudioSource::Sink {
|
2014-02-21 15:51:43 +00:00
|
|
|
public:
|
2016-03-08 12:37:39 -08:00
|
|
|
explicit VoiceChannelAudioSink(AudioSource* source) : source_(source) {
|
|
|
|
|
source_->SetSink(this);
|
2014-02-21 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
virtual ~VoiceChannelAudioSink() {
|
2016-03-08 12:37:39 -08:00
|
|
|
if (source_) {
|
|
|
|
|
source_->SetSink(nullptr);
|
2014-02-21 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-04 12:58:35 +00:00
|
|
|
void OnData(const void* audio_data,
|
|
|
|
|
int bits_per_sample,
|
|
|
|
|
int sample_rate,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t number_of_channels,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t number_of_frames) override {}
|
2016-03-08 12:37:39 -08:00
|
|
|
void OnClose() override { source_ = nullptr; }
|
|
|
|
|
AudioSource* source() const { return source_; }
|
2014-02-21 15:51:43 +00:00
|
|
|
|
|
|
|
|
private:
|
2016-03-08 12:37:39 -08:00
|
|
|
AudioSource* source_;
|
2014-02-21 15:51:43 +00:00
|
|
|
};
|
|
|
|
|
|
2015-09-17 16:42:56 +02:00
|
|
|
bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
|
|
|
|
|
if (fail_set_recv_codecs()) {
|
|
|
|
|
// Fake the failure in SetRecvCodecs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
recv_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool SetSendCodecs(const std::vector<AudioCodec>& codecs) {
|
|
|
|
|
if (fail_set_send_codecs()) {
|
|
|
|
|
// Fake the failure in SetSendCodecs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
send_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-03-16 19:07:43 -07:00
|
|
|
bool SetMaxSendBandwidth(int bps) {
|
|
|
|
|
max_bps_ = bps;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-09-17 16:42:56 +02:00
|
|
|
bool SetOptions(const AudioOptions& options) {
|
|
|
|
|
// Does a "merge" of current options and set options.
|
|
|
|
|
options_.SetAll(options);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-03-08 12:37:39 -08:00
|
|
|
bool SetLocalSource(uint32_t ssrc, AudioSource* source) {
|
|
|
|
|
auto it = local_sinks_.find(ssrc);
|
|
|
|
|
if (source) {
|
|
|
|
|
if (it != local_sinks_.end()) {
|
2017-02-07 07:18:43 -08:00
|
|
|
RTC_CHECK(it->second->source() == source);
|
2015-09-10 01:57:14 -07:00
|
|
|
} else {
|
2017-10-20 15:30:51 -07:00
|
|
|
local_sinks_.insert(std::make_pair(
|
|
|
|
|
ssrc, rtc::MakeUnique<VoiceChannelAudioSink>(source)));
|
2015-09-10 01:57:14 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-08 12:37:39 -08:00
|
|
|
if (it != local_sinks_.end()) {
|
|
|
|
|
local_sinks_.erase(it);
|
2015-09-10 01:57:14 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-21 15:51:43 +00:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
FakeVoiceEngine* engine_;
|
|
|
|
|
std::vector<AudioCodec> recv_codecs_;
|
|
|
|
|
std::vector<AudioCodec> send_codecs_;
|
2015-10-09 02:32:53 -07:00
|
|
|
std::map<uint32_t, double> output_scalings_;
|
2013-07-10 00:45:36 +00:00
|
|
|
std::vector<DtmfInfo> dtmf_info_queue_;
|
|
|
|
|
AudioOptions options_;
|
2017-10-20 15:30:51 -07:00
|
|
|
std::map<uint32_t, std::unique_ptr<VoiceChannelAudioSink>> local_sinks_;
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<webrtc::AudioSinkInterface> sink_;
|
2016-03-16 19:07:43 -07:00
|
|
|
int max_bps_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A helper function to compare the FakeVoiceMediaChannel::DtmfInfo.
|
|
|
|
|
inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info,
|
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
|
|
|
uint32_t ssrc,
|
|
|
|
|
int event_code,
|
2015-12-02 12:35:09 -08:00
|
|
|
int duration) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return (info.duration == duration && info.event_code == event_code &&
|
2015-12-02 12:35:09 -08:00
|
|
|
info.ssrc == ssrc);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> {
|
|
|
|
|
public:
|
2017-08-09 06:42:32 -07:00
|
|
|
FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options)
|
2016-02-01 19:30:33 +01:00
|
|
|
: engine_(engine), max_bps_(-1) {
|
2015-09-17 16:42:56 +02:00
|
|
|
SetOptions(options);
|
|
|
|
|
}
|
2014-10-14 20:29:28 +00:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
~FakeVideoMediaChannel();
|
|
|
|
|
|
|
|
|
|
const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; }
|
|
|
|
|
const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; }
|
|
|
|
|
const std::vector<VideoCodec>& codecs() const { return send_codecs(); }
|
|
|
|
|
bool rendering() const { return playout(); }
|
|
|
|
|
const VideoOptions& options() const { return options_; }
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>&
|
|
|
|
|
sinks() const {
|
2016-02-04 01:24:52 -08:00
|
|
|
return sinks_;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2014-01-15 23:15:54 +00:00
|
|
|
int max_bps() const { return max_bps_; }
|
2016-04-29 06:09:15 -07:00
|
|
|
bool SetSendParameters(const VideoSendParameters& params) override {
|
2017-02-25 18:15:09 -08:00
|
|
|
set_send_rtcp_parameters(params.rtcp);
|
2015-09-17 16:42:56 +02:00
|
|
|
return (SetSendCodecs(params.codecs) &&
|
|
|
|
|
SetSendRtpHeaderExtensions(params.extensions) &&
|
2016-03-16 02:22:50 -07:00
|
|
|
SetMaxSendBandwidth(params.max_bandwidth_bps));
|
2015-09-17 16:42:56 +02:00
|
|
|
}
|
2016-04-29 06:09:15 -07:00
|
|
|
bool SetRecvParameters(const VideoRecvParameters& params) override {
|
2017-02-25 18:15:09 -08:00
|
|
|
set_recv_rtcp_parameters(params.rtcp);
|
2015-09-17 16:42:56 +02:00
|
|
|
return (SetRecvCodecs(params.codecs) &&
|
|
|
|
|
SetRecvRtpHeaderExtensions(params.extensions));
|
|
|
|
|
}
|
2016-04-29 06:09:15 -07:00
|
|
|
bool AddSendStream(const StreamParams& sp) override {
|
2016-02-02 14:14:30 +01:00
|
|
|
return RtpHelper<VideoMediaChannel>::AddSendStream(sp);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-04-29 06:09:15 -07:00
|
|
|
bool RemoveSendStream(uint32_t ssrc) override {
|
2013-07-10 00:45:36 +00:00
|
|
|
return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
bool GetSendCodec(VideoCodec* send_codec) override {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (send_codecs_.empty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
*send_codec = send_codecs_[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-02-04 01:24:52 -08:00
|
|
|
bool SetSink(uint32_t ssrc,
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
|
2016-02-04 01:24:52 -08:00
|
|
|
if (ssrc != 0 && sinks_.find(ssrc) == sinks_.end()) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (ssrc != 0) {
|
2016-02-04 01:24:52 -08:00
|
|
|
sinks_[ssrc] = sink;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-06-27 16:30:35 -07:00
|
|
|
bool HasSink(uint32_t ssrc) const {
|
|
|
|
|
return sinks_.find(ssrc) != sinks_.end() && sinks_.at(ssrc) != nullptr;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
bool SetSend(bool send) override { return set_sending(send); }
|
2016-06-02 16:23:38 -07:00
|
|
|
bool SetVideoSend(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
bool enable,
|
|
|
|
|
const VideoOptions* options,
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override {
|
2015-10-01 02:31:10 -07:00
|
|
|
if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, !enable)) {
|
2015-09-10 01:57:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-10-01 02:31:10 -07:00
|
|
|
if (enable && options) {
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!SetOptions(*options)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-09-10 01:57:14 -07:00
|
|
|
}
|
2016-04-08 02:23:55 -07:00
|
|
|
sources_[ssrc] = source;
|
2016-06-02 16:23:38 -07:00
|
|
|
return true;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-04-08 02:23:55 -07:00
|
|
|
|
|
|
|
|
bool HasSource(uint32_t ssrc) const {
|
2016-06-27 16:30:35 -07:00
|
|
|
return sources_.find(ssrc) != sources_.end() &&
|
|
|
|
|
sources_.at(ssrc) != nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2016-04-29 06:09:15 -07:00
|
|
|
bool AddRecvStream(const StreamParams& sp) override {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp))
|
|
|
|
|
return false;
|
2016-02-04 01:24:52 -08:00
|
|
|
sinks_[sp.first_ssrc()] = NULL;
|
2013-07-10 00:45:36 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2016-04-29 06:09:15 -07:00
|
|
|
bool RemoveRecvStream(uint32_t ssrc) override {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc))
|
|
|
|
|
return false;
|
2016-02-04 01:24:52 -08:00
|
|
|
sinks_.erase(ssrc);
|
2013-07-10 00:45:36 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 06:44:03 -07:00
|
|
|
void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override {}
|
2016-04-29 06:09:15 -07:00
|
|
|
bool GetStats(VideoMediaInfo* info) override { return false; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2015-09-17 16:42:56 +02:00
|
|
|
bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
|
|
|
|
|
if (fail_set_recv_codecs()) {
|
|
|
|
|
// Fake the failure in SetRecvCodecs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
recv_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool SetSendCodecs(const std::vector<VideoCodec>& codecs) {
|
|
|
|
|
if (fail_set_send_codecs()) {
|
|
|
|
|
// Fake the failure in SetSendCodecs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
send_codecs_ = codecs;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool SetOptions(const VideoOptions& options) {
|
|
|
|
|
options_ = options;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool SetMaxSendBandwidth(int bps) {
|
|
|
|
|
max_bps_ = bps;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
FakeVideoEngine* engine_;
|
|
|
|
|
std::vector<VideoCodec> recv_codecs_;
|
|
|
|
|
std::vector<VideoCodec> send_codecs_;
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_;
|
|
|
|
|
std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_;
|
2013-07-10 00:45:36 +00:00
|
|
|
VideoOptions options_;
|
2014-01-15 23:15:54 +00:00
|
|
|
int max_bps_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
2016-03-16 02:22:50 -07:00
|
|
|
// Dummy option class, needed for the DataTraits abstraction in
|
|
|
|
|
// channel_unittest.c.
|
|
|
|
|
class DataOptions {};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
|
|
|
|
|
public:
|
2015-09-17 16:42:56 +02:00
|
|
|
explicit FakeDataMediaChannel(void* unused, const DataOptions& options)
|
2014-01-15 23:15:54 +00:00
|
|
|
: send_blocked_(false), max_bps_(-1) {}
|
2013-07-10 00:45:36 +00:00
|
|
|
~FakeDataMediaChannel() {}
|
|
|
|
|
const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; }
|
|
|
|
|
const std::vector<DataCodec>& send_codecs() const { return send_codecs_; }
|
|
|
|
|
const std::vector<DataCodec>& codecs() const { return send_codecs(); }
|
|
|
|
|
int max_bps() const { return max_bps_; }
|
|
|
|
|
|
2015-09-17 16:42:56 +02:00
|
|
|
virtual bool SetSendParameters(const DataSendParameters& params) {
|
2017-02-25 18:15:09 -08:00
|
|
|
set_send_rtcp_parameters(params.rtcp);
|
2015-09-17 16:42:56 +02:00
|
|
|
return (SetSendCodecs(params.codecs) &&
|
|
|
|
|
SetMaxSendBandwidth(params.max_bandwidth_bps));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2015-09-17 16:42:56 +02:00
|
|
|
virtual bool SetRecvParameters(const DataRecvParameters& params) {
|
2017-02-25 18:15:09 -08:00
|
|
|
set_recv_rtcp_parameters(params.rtcp);
|
2015-09-17 16:42:56 +02:00
|
|
|
return SetRecvCodecs(params.codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
virtual bool SetSend(bool send) { return set_sending(send); }
|
|
|
|
|
virtual bool SetReceive(bool receive) {
|
|
|
|
|
set_playout(receive);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
virtual bool AddRecvStream(const StreamParams& sp) {
|
|
|
|
|
if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp))
|
|
|
|
|
return false;
|
|
|
|
|
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
|
|
|
virtual bool RemoveRecvStream(uint32_t ssrc) {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool 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) {
|
2013-08-01 00:00:07 +00:00
|
|
|
if (send_blocked_) {
|
|
|
|
|
*result = SDR_BLOCK;
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
last_sent_data_params_ = params;
|
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
|
|
|
last_sent_data_ = std::string(payload.data<char>(), payload.size());
|
2013-08-01 00:00:07 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendDataParams last_sent_data_params() { return last_sent_data_params_; }
|
|
|
|
|
std::string last_sent_data() { return last_sent_data_; }
|
2013-08-01 00:00:07 +00:00
|
|
|
bool is_send_blocked() { return send_blocked_; }
|
|
|
|
|
void set_send_blocked(bool blocked) { send_blocked_ = blocked; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2015-09-17 16:42:56 +02:00
|
|
|
bool SetRecvCodecs(const std::vector<DataCodec>& codecs) {
|
|
|
|
|
if (fail_set_recv_codecs()) {
|
|
|
|
|
// Fake the failure in SetRecvCodecs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
recv_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool SetSendCodecs(const std::vector<DataCodec>& codecs) {
|
|
|
|
|
if (fail_set_send_codecs()) {
|
|
|
|
|
// Fake the failure in SetSendCodecs.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
send_codecs_ = codecs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool SetMaxSendBandwidth(int bps) {
|
|
|
|
|
max_bps_ = bps;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
std::vector<DataCodec> recv_codecs_;
|
|
|
|
|
std::vector<DataCodec> send_codecs_;
|
|
|
|
|
SendDataParams last_sent_data_params_;
|
|
|
|
|
std::string last_sent_data_;
|
2013-08-01 00:00:07 +00:00
|
|
|
bool send_blocked_;
|
2013-07-10 00:45:36 +00:00
|
|
|
int max_bps_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A base class for all of the shared parts between FakeVoiceEngine
|
|
|
|
|
// and FakeVideoEngine.
|
|
|
|
|
class FakeBaseEngine {
|
|
|
|
|
public:
|
|
|
|
|
FakeBaseEngine()
|
2015-11-20 16:08:07 -08:00
|
|
|
: options_changed_(false),
|
2013-07-10 00:45:36 +00:00
|
|
|
fail_create_channel_(false) {}
|
|
|
|
|
void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; }
|
|
|
|
|
|
2015-12-07 10:45:43 +01:00
|
|
|
RtpCapabilities GetCapabilities() const { return capabilities_; }
|
2016-05-26 11:24:55 -07:00
|
|
|
void set_rtp_header_extensions(const std::vector<RtpExtension>& extensions) {
|
2015-12-07 10:45:43 +01:00
|
|
|
capabilities_.header_extensions = extensions;
|
2014-03-06 23:46:59 +00:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-05-31 16:12:24 -07:00
|
|
|
void set_rtp_header_extensions(
|
|
|
|
|
const std::vector<cricket::RtpHeaderExtension>& extensions) {
|
|
|
|
|
for (const cricket::RtpHeaderExtension& ext : extensions) {
|
|
|
|
|
RtpExtension webrtc_ext;
|
|
|
|
|
webrtc_ext.uri = ext.uri;
|
|
|
|
|
webrtc_ext.id = ext.id;
|
|
|
|
|
capabilities_.header_extensions.push_back(webrtc_ext);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
|
|
|
|
// Flag used by optionsmessagehandler_unittest for checking whether any
|
|
|
|
|
// relevant setting has been updated.
|
|
|
|
|
// TODO(thaloun): Replace with explicit checks of before & after values.
|
|
|
|
|
bool options_changed_;
|
|
|
|
|
bool fail_create_channel_;
|
2015-12-07 10:45:43 +01:00
|
|
|
RtpCapabilities capabilities_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FakeVoiceEngine : public FakeBaseEngine {
|
|
|
|
|
public:
|
2017-09-12 04:42:15 -07:00
|
|
|
FakeVoiceEngine() {
|
2013-07-10 00:45:36 +00:00
|
|
|
// Add a fake audio codec. Note that the name must not be "" as there are
|
|
|
|
|
// sanity checks against that.
|
2016-04-13 10:07:16 -07:00
|
|
|
codecs_.push_back(AudioCodec(101, "fake_audio_codec", 0, 0, 1));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2017-06-15 08:29:25 -07:00
|
|
|
void Init() {}
|
2015-11-06 15:34:49 -08:00
|
|
|
rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
|
|
|
|
|
return rtc::scoped_refptr<webrtc::AudioState>();
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-09-15 12:26:33 +02:00
|
|
|
VoiceMediaChannel* CreateChannel(webrtc::Call* call,
|
2016-02-12 02:27:06 -08:00
|
|
|
const MediaConfig& config,
|
2015-09-15 12:26:33 +02:00
|
|
|
const AudioOptions& options) {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (fail_create_channel_) {
|
2015-05-29 15:05:44 +02:00
|
|
|
return nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-17 16:42:56 +02:00
|
|
|
FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this, options);
|
2013-07-10 00:45:36 +00:00
|
|
|
channels_.push_back(ch);
|
|
|
|
|
return ch;
|
|
|
|
|
}
|
|
|
|
|
FakeVoiceMediaChannel* GetChannel(size_t index) {
|
|
|
|
|
return (channels_.size() > index) ? channels_[index] : NULL;
|
|
|
|
|
}
|
|
|
|
|
void UnregisterChannel(VoiceMediaChannel* channel) {
|
|
|
|
|
channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 07:12:39 -07:00
|
|
|
// TODO(ossu): For proper testing, These should either individually settable
|
|
|
|
|
// or the voice engine should reference mockable factories.
|
|
|
|
|
const std::vector<AudioCodec>& send_codecs() { return codecs_; }
|
|
|
|
|
const std::vector<AudioCodec>& recv_codecs() { return codecs_; }
|
|
|
|
|
void SetCodecs(const std::vector<AudioCodec>& codecs) { codecs_ = codecs; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
int GetInputLevel() { return 0; }
|
|
|
|
|
|
2016-01-15 03:06:36 -08:00
|
|
|
bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-12-13 00:21:03 +00:00
|
|
|
|
2015-10-22 03:25:41 -07:00
|
|
|
void StopAecDump() {}
|
|
|
|
|
|
2016-05-13 08:30:39 -07:00
|
|
|
bool StartRtcEventLog(rtc::PlatformFile file, int64_t max_size_bytes) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-10-16 02:22:18 -07:00
|
|
|
|
|
|
|
|
void StopRtcEventLog() {}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
|
|
|
|
std::vector<FakeVoiceMediaChannel*> channels_;
|
|
|
|
|
std::vector<AudioCodec> codecs_;
|
|
|
|
|
|
|
|
|
|
friend class FakeMediaEngine;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FakeVideoEngine : public FakeBaseEngine {
|
|
|
|
|
public:
|
2015-09-15 12:26:33 +02:00
|
|
|
FakeVideoEngine() : capture_(false) {
|
2013-07-10 00:45:36 +00:00
|
|
|
// Add a fake video codec. Note that the name must not be "" as there are
|
|
|
|
|
// sanity checks against that.
|
2016-10-24 01:21:16 -07:00
|
|
|
codecs_.push_back(VideoCodec(0, "fake_video_codec"));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2017-08-09 06:42:32 -07:00
|
|
|
|
2013-09-27 23:04:10 +00:00
|
|
|
bool SetOptions(const VideoOptions& options) {
|
|
|
|
|
options_ = options;
|
|
|
|
|
options_changed_ = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-09-15 12:26:33 +02:00
|
|
|
VideoMediaChannel* CreateChannel(webrtc::Call* call,
|
2016-02-12 02:27:06 -08:00
|
|
|
const MediaConfig& config,
|
2015-09-15 12:26:33 +02:00
|
|
|
const VideoOptions& options) {
|
2013-07-10 00:45:36 +00:00
|
|
|
if (fail_create_channel_) {
|
2017-08-09 06:42:32 -07:00
|
|
|
return nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-17 16:42:56 +02:00
|
|
|
FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options);
|
2017-08-09 06:42:32 -07:00
|
|
|
channels_.emplace_back(ch);
|
2013-07-10 00:45:36 +00:00
|
|
|
return ch;
|
|
|
|
|
}
|
2017-08-09 06:42:32 -07:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
FakeVideoMediaChannel* GetChannel(size_t index) {
|
2017-08-09 06:42:32 -07:00
|
|
|
return (channels_.size() > index) ? channels_[index] : nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2017-08-09 06:42:32 -07:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
void UnregisterChannel(VideoMediaChannel* channel) {
|
2017-08-09 06:42:32 -07:00
|
|
|
auto it = std::find(channels_.begin(), channels_.end(), channel);
|
|
|
|
|
RTC_DCHECK(it != channels_.end());
|
|
|
|
|
channels_.erase(it);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<VideoCodec>& codecs() const { return codecs_; }
|
2017-08-09 06:42:32 -07:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; }
|
|
|
|
|
|
|
|
|
|
bool SetCapture(bool capture) {
|
|
|
|
|
capture_ = capture;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::vector<FakeVideoMediaChannel*> channels_;
|
|
|
|
|
std::vector<VideoCodec> codecs_;
|
|
|
|
|
bool capture_;
|
2013-09-27 23:04:10 +00:00
|
|
|
VideoOptions options_;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
friend class FakeMediaEngine;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FakeMediaEngine :
|
|
|
|
|
public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> {
|
|
|
|
|
public:
|
2016-06-13 07:34:51 -07:00
|
|
|
FakeMediaEngine()
|
2017-09-12 04:42:15 -07:00
|
|
|
: CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(std::tuple<>(),
|
|
|
|
|
std::tuple<>()) {
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual ~FakeMediaEngine() {}
|
|
|
|
|
|
2014-03-06 23:46:59 +00:00
|
|
|
void SetAudioCodecs(const std::vector<AudioCodec>& codecs) {
|
2017-09-12 04:42:15 -07:00
|
|
|
voice().SetCodecs(codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2014-03-06 23:46:59 +00:00
|
|
|
void SetVideoCodecs(const std::vector<VideoCodec>& codecs) {
|
2017-09-12 04:42:15 -07:00
|
|
|
video().SetCodecs(codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-06 23:46:59 +00:00
|
|
|
void SetAudioRtpHeaderExtensions(
|
2016-05-26 11:24:55 -07:00
|
|
|
const std::vector<RtpExtension>& extensions) {
|
2017-09-12 04:42:15 -07:00
|
|
|
voice().set_rtp_header_extensions(extensions);
|
2014-03-06 23:46:59 +00:00
|
|
|
}
|
|
|
|
|
void SetVideoRtpHeaderExtensions(
|
2016-05-26 11:24:55 -07:00
|
|
|
const std::vector<RtpExtension>& extensions) {
|
2017-09-12 04:42:15 -07:00
|
|
|
video().set_rtp_header_extensions(extensions);
|
2014-03-06 23:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-31 16:12:24 -07:00
|
|
|
void SetAudioRtpHeaderExtensions(
|
|
|
|
|
const std::vector<cricket::RtpHeaderExtension>& extensions) {
|
2017-09-12 04:42:15 -07:00
|
|
|
voice().set_rtp_header_extensions(extensions);
|
2016-05-31 16:12:24 -07:00
|
|
|
}
|
|
|
|
|
void SetVideoRtpHeaderExtensions(
|
|
|
|
|
const std::vector<cricket::RtpHeaderExtension>& extensions) {
|
2017-09-12 04:42:15 -07:00
|
|
|
video().set_rtp_header_extensions(extensions);
|
2016-05-31 16:12:24 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
FakeVoiceMediaChannel* GetVoiceChannel(size_t index) {
|
2017-09-12 04:42:15 -07:00
|
|
|
return voice().GetChannel(index);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
FakeVideoMediaChannel* GetVideoChannel(size_t index) {
|
2017-09-12 04:42:15 -07:00
|
|
|
return video().GetChannel(index);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-12 04:42:15 -07:00
|
|
|
bool capture() const { return video().capture_; }
|
|
|
|
|
bool options_changed() const { return video().options_changed_; }
|
|
|
|
|
void clear_options_changed() { video().options_changed_ = false; }
|
2013-07-10 00:45:36 +00:00
|
|
|
void set_fail_create_channel(bool fail) {
|
2017-09-12 04:42:15 -07:00
|
|
|
voice().set_fail_create_channel(fail);
|
|
|
|
|
video().set_fail_create_channel(fail);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Have to come afterwards due to declaration order
|
|
|
|
|
inline FakeVoiceMediaChannel::~FakeVoiceMediaChannel() {
|
|
|
|
|
if (engine_) {
|
|
|
|
|
engine_->UnregisterChannel(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline FakeVideoMediaChannel::~FakeVideoMediaChannel() {
|
|
|
|
|
if (engine_) {
|
|
|
|
|
engine_->UnregisterChannel(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FakeDataEngine : public DataEngineInterface {
|
|
|
|
|
public:
|
2017-01-09 14:53:41 -08:00
|
|
|
virtual DataMediaChannel* CreateChannel(const MediaConfig& config) {
|
2015-09-17 16:42:56 +02:00
|
|
|
FakeDataMediaChannel* ch = new FakeDataMediaChannel(this, DataOptions());
|
2013-07-10 00:45:36 +00:00
|
|
|
channels_.push_back(ch);
|
|
|
|
|
return ch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FakeDataMediaChannel* GetChannel(size_t index) {
|
|
|
|
|
return (channels_.size() > index) ? channels_[index] : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnregisterChannel(DataMediaChannel* channel) {
|
|
|
|
|
channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) {
|
|
|
|
|
data_codecs_ = data_codecs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::vector<FakeDataMediaChannel*> channels_;
|
|
|
|
|
std::vector<DataCodec> data_codecs_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MEDIA_BASE_FAKEMEDIAENGINE_H_
|