(Auto)update libjingle 73072800 -> 73215194

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6887 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org 2014-08-13 14:57:30 +00:00
parent 23a4d8522e
commit 4eeeefebb2
4 changed files with 277 additions and 226 deletions

View File

@ -1720,7 +1720,6 @@ class VideoMediaChannelTest : public testing::Test,
EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1])); EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1]));
} }
// Two streams one channel tests. // Two streams one channel tests.
// Tests that we can send and receive frames. // Tests that we can send and receive frames.
@ -1742,18 +1741,18 @@ class VideoMediaChannelTest : public testing::Test,
void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) { void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) {
SetUpSecondStream(); SetUpSecondStream();
// Default channel used by the first stream. // Default channel used by the first stream.
EXPECT_EQ(kSsrc, channel_->GetDefaultChannelSsrc()); EXPECT_EQ(kSsrc, channel_->GetDefaultSendChannelSsrc());
EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc)); EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc));
EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc)); EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc));
EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
EXPECT_FALSE(channel_->RemoveSendStream(kSsrc)); EXPECT_FALSE(channel_->RemoveSendStream(kSsrc));
// Default channel is no longer used by a stream. // Default channel is no longer used by a stream.
EXPECT_EQ(0u, channel_->GetDefaultChannelSsrc()); EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc());
uint32 new_ssrc = kSsrc + 100; uint32 new_ssrc = kSsrc + 100;
EXPECT_TRUE(channel_->AddSendStream( EXPECT_TRUE(channel_->AddSendStream(
cricket::StreamParams::CreateLegacy(new_ssrc))); cricket::StreamParams::CreateLegacy(new_ssrc)));
// Re-use default channel. // Re-use default channel.
EXPECT_EQ(new_ssrc, channel_->GetDefaultChannelSsrc()); EXPECT_EQ(new_ssrc, channel_->GetDefaultSendChannelSsrc());
EXPECT_FALSE(channel_->AddSendStream( EXPECT_FALSE(channel_->AddSendStream(
cricket::StreamParams::CreateLegacy(new_ssrc))); cricket::StreamParams::CreateLegacy(new_ssrc)));
EXPECT_TRUE(channel_->AddRecvStream( EXPECT_TRUE(channel_->AddRecvStream(
@ -1766,7 +1765,7 @@ class VideoMediaChannelTest : public testing::Test,
SendAndReceive(codec); SendAndReceive(codec);
EXPECT_TRUE(channel_->RemoveSendStream(new_ssrc)); EXPECT_TRUE(channel_->RemoveSendStream(new_ssrc));
EXPECT_EQ(0u, channel_->GetDefaultChannelSsrc()); EXPECT_EQ(0u, channel_->GetDefaultSendChannelSsrc());
} }
// Tests that we can send and receive frames with early receive. // Tests that we can send and receive frames with early receive.

View File

@ -548,13 +548,21 @@ class FakeWebRtcVideoEngine
WEBRTC_ASSERT_CHANNEL(channel); WEBRTC_ASSERT_CHANNEL(channel);
return channels_.find(channel)->second->overuse_options_; return channels_.find(channel)->second->overuse_options_;
} }
int GetRtxSsrc(int channel, int simulcast_idx) const { int GetSsrc(int channel, int idx) const {
WEBRTC_ASSERT_CHANNEL(channel); WEBRTC_ASSERT_CHANNEL(channel);
if (channels_.find(channel)->second->rtx_ssrcs_.find(simulcast_idx) == if (channels_.find(channel)->second->ssrcs_.find(idx) ==
channels_.find(channel)->second->ssrcs_.end()) {
return -1;
}
return channels_.find(channel)->second->ssrcs_[idx];
}
int GetRtxSsrc(int channel, int idx) const {
WEBRTC_ASSERT_CHANNEL(channel);
if (channels_.find(channel)->second->rtx_ssrcs_.find(idx) ==
channels_.find(channel)->second->rtx_ssrcs_.end()) { channels_.find(channel)->second->rtx_ssrcs_.end()) {
return -1; return -1;
} }
return channels_.find(channel)->second->rtx_ssrcs_[simulcast_idx]; return channels_.find(channel)->second->rtx_ssrcs_[idx];
} }
bool ReceiveCodecRegistered(int channel, bool ReceiveCodecRegistered(int channel,
const webrtc::VideoCodec& codec) const { const webrtc::VideoCodec& codec) const {

View File

@ -88,6 +88,10 @@ static const int kDefaultNumberOfTemporalLayers = 1; // 1:1
static const int kExternalVideoPayloadTypeBase = 120; static const int kExternalVideoPayloadTypeBase = 120;
static const int kChannelIdUnset = -1;
static const uint32 kDefaultChannelSsrcKey = 0;
static const uint32 kSsrcUnset = 0;
static bool BitrateIsSet(int value) { static bool BitrateIsSet(int value) {
return value > kAutoBandwidth; return value > kAutoBandwidth;
} }
@ -177,7 +181,7 @@ class WebRtcRenderAdapter : public webrtc::ExternalRenderer {
// TODO(ronghuawu): Add unit test for this case. Didn't do it now // TODO(ronghuawu): Add unit test for this case. Didn't do it now
// because the WebRtcRenderAdapter is currently hiding in cc file. No // because the WebRtcRenderAdapter is currently hiding in cc file. No
// good way to get access to it from the unit test. // good way to get access to it from the unit test.
if (width_ > 0 && height_ > 0 && renderer_ != NULL) { if (width_ > 0 && height_ > 0 && renderer_) {
if (!renderer_->SetSize(width_, height_, 0)) { if (!renderer_->SetSize(width_, height_, 0)) {
LOG(LS_ERROR) LOG(LS_ERROR)
<< "WebRtcRenderAdapter (channel " << channel_id_ << "WebRtcRenderAdapter (channel " << channel_id_
@ -196,7 +200,7 @@ class WebRtcRenderAdapter : public webrtc::ExternalRenderer {
LOG(LS_INFO) << "WebRtcRenderAdapter (channel " << channel_id_ LOG(LS_INFO) << "WebRtcRenderAdapter (channel " << channel_id_
<< ") frame size changed to: " << ") frame size changed to: "
<< width << "x" << height; << width << "x" << height;
if (renderer_ == NULL) { if (!renderer_) {
LOG(LS_VERBOSE) << "WebRtcRenderAdapter (channel " << channel_id_ LOG(LS_VERBOSE) << "WebRtcRenderAdapter (channel " << channel_id_
<< ") the renderer has not been set. " << ") the renderer has not been set. "
<< "SetSize will be called later in SetRenderer."; << "SetSize will be called later in SetRenderer.";
@ -225,7 +229,7 @@ class WebRtcRenderAdapter : public webrtc::ExternalRenderer {
capture_start_ntp_time_ms_ = ntp_time_ms - elapsed_time_ms; capture_start_ntp_time_ms_ = ntp_time_ms - elapsed_time_ms;
} }
frame_rate_tracker_.Update(1); frame_rate_tracker_.Update(1);
if (renderer_ == NULL) { if (!renderer_) {
return 0; return 0;
} }
// Convert elapsed_time_ms to ns timestamp. // Convert elapsed_time_ms to ns timestamp.
@ -237,7 +241,7 @@ class WebRtcRenderAdapter : public webrtc::ExternalRenderer {
// Note that here we send the |elapsed_time_ns| to renderer as the // Note that here we send the |elapsed_time_ns| to renderer as the
// cricket::VideoFrame's elapsed_time_ and the |render_time_ns| as the // cricket::VideoFrame's elapsed_time_ and the |render_time_ns| as the
// cricket::VideoFrame's time_stamp_. // cricket::VideoFrame's time_stamp_.
if (handle == NULL) { if (!handle) {
return DeliverBufferFrame(buffer, buffer_size, render_time_ns, return DeliverBufferFrame(buffer, buffer_size, render_time_ns,
elapsed_time_ns); elapsed_time_ns);
} else { } else {
@ -311,8 +315,8 @@ class WebRtcRenderAdapter : public webrtc::ExternalRenderer {
class WebRtcDecoderObserver : public webrtc::ViEDecoderObserver { class WebRtcDecoderObserver : public webrtc::ViEDecoderObserver {
public: public:
explicit WebRtcDecoderObserver(int video_channel) explicit WebRtcDecoderObserver(int video_channel_id)
: video_channel_(video_channel), : video_channel_id_(video_channel_id),
framerate_(0), framerate_(0),
bitrate_(0), bitrate_(0),
decode_ms_(0), decode_ms_(0),
@ -325,13 +329,13 @@ class WebRtcDecoderObserver : public webrtc::ViEDecoderObserver {
} }
// virtual functions from VieDecoderObserver. // virtual functions from VieDecoderObserver.
virtual void IncomingCodecChanged(const int videoChannel, virtual void IncomingCodecChanged(const int video_channel_id,
const webrtc::VideoCodec& videoCodec) {} const webrtc::VideoCodec& videoCodec) {}
virtual void IncomingRate(const int videoChannel, virtual void IncomingRate(const int video_channel_id,
const unsigned int framerate, const unsigned int framerate,
const unsigned int bitrate) { const unsigned int bitrate) {
rtc::CritScope cs(&crit_); rtc::CritScope cs(&crit_);
ASSERT(video_channel_ == videoChannel); ASSERT(video_channel_id_ == video_channel_id);
framerate_ = framerate; framerate_ = framerate;
bitrate_ = bitrate; bitrate_ = bitrate;
} }
@ -353,7 +357,7 @@ class WebRtcDecoderObserver : public webrtc::ViEDecoderObserver {
render_delay_ms_ = render_delay_ms; render_delay_ms_ = render_delay_ms;
} }
virtual void RequestNewKeyFrame(const int videoChannel) {} virtual void RequestNewKeyFrame(const int video_channel_id) {}
// Populate |rinfo| based on previously-set data in |*this|. // Populate |rinfo| based on previously-set data in |*this|.
void ExportTo(VideoReceiverInfo* rinfo) { void ExportTo(VideoReceiverInfo* rinfo) {
@ -370,7 +374,7 @@ class WebRtcDecoderObserver : public webrtc::ViEDecoderObserver {
private: private:
mutable rtc::CriticalSection crit_; mutable rtc::CriticalSection crit_;
int video_channel_; int video_channel_id_;
int framerate_; int framerate_;
int bitrate_; int bitrate_;
int decode_ms_; int decode_ms_;
@ -384,26 +388,26 @@ class WebRtcDecoderObserver : public webrtc::ViEDecoderObserver {
class WebRtcEncoderObserver : public webrtc::ViEEncoderObserver { class WebRtcEncoderObserver : public webrtc::ViEEncoderObserver {
public: public:
explicit WebRtcEncoderObserver(int video_channel) explicit WebRtcEncoderObserver(int video_channel_id)
: video_channel_(video_channel), : video_channel_id_(video_channel_id),
framerate_(0), framerate_(0),
bitrate_(0), bitrate_(0),
suspended_(false) { suspended_(false) {
} }
// virtual functions from VieEncoderObserver. // virtual functions from VieEncoderObserver.
virtual void OutgoingRate(const int videoChannel, virtual void OutgoingRate(const int video_channel_id,
const unsigned int framerate, const unsigned int framerate,
const unsigned int bitrate) { const unsigned int bitrate) {
rtc::CritScope cs(&crit_); rtc::CritScope cs(&crit_);
ASSERT(video_channel_ == videoChannel); ASSERT(video_channel_id_ == video_channel_id);
framerate_ = framerate; framerate_ = framerate;
bitrate_ = bitrate; bitrate_ = bitrate;
} }
virtual void SuspendChange(int video_channel, bool is_suspended) { virtual void SuspendChange(int video_channel_id, bool is_suspended) {
rtc::CritScope cs(&crit_); rtc::CritScope cs(&crit_);
ASSERT(video_channel_ == video_channel); ASSERT(video_channel_id_ == video_channel_id);
suspended_ = is_suspended; suspended_ = is_suspended;
} }
@ -422,7 +426,7 @@ class WebRtcEncoderObserver : public webrtc::ViEEncoderObserver {
private: private:
mutable rtc::CriticalSection crit_; mutable rtc::CriticalSection crit_;
int video_channel_; int video_channel_id_;
int framerate_; int framerate_;
int bitrate_; int bitrate_;
bool suspended_; bool suspended_;
@ -840,7 +844,7 @@ const VideoFormatPod WebRtcVideoEngine::kDefaultMaxVideoFormat =
static void UpdateVideoCodec(const cricket::VideoFormat& video_format, static void UpdateVideoCodec(const cricket::VideoFormat& video_format,
webrtc::VideoCodec* target_codec) { webrtc::VideoCodec* target_codec) {
if ((target_codec == NULL) || (video_format == cricket::VideoFormat())) { if ((!target_codec) || (video_format == cricket::VideoFormat())) {
return; return;
} }
target_codec->width = video_format.width; target_codec->width = video_format.width;
@ -1473,7 +1477,7 @@ void WebRtcVideoEngine::Print(webrtc::TraceLevel level, const char* trace,
webrtc::VideoDecoder* WebRtcVideoEngine::CreateExternalDecoder( webrtc::VideoDecoder* WebRtcVideoEngine::CreateExternalDecoder(
webrtc::VideoCodecType type) { webrtc::VideoCodecType type) {
if (decoder_factory_ == NULL) { if (!decoder_factory_) {
return NULL; return NULL;
} }
return decoder_factory_->CreateVideoDecoder(type); return decoder_factory_->CreateVideoDecoder(type);
@ -1481,14 +1485,14 @@ webrtc::VideoDecoder* WebRtcVideoEngine::CreateExternalDecoder(
void WebRtcVideoEngine::DestroyExternalDecoder(webrtc::VideoDecoder* decoder) { void WebRtcVideoEngine::DestroyExternalDecoder(webrtc::VideoDecoder* decoder) {
ASSERT(decoder_factory_ != NULL); ASSERT(decoder_factory_ != NULL);
if (decoder_factory_ == NULL) if (!decoder_factory_)
return; return;
decoder_factory_->DestroyVideoDecoder(decoder); decoder_factory_->DestroyVideoDecoder(decoder);
} }
webrtc::VideoEncoder* WebRtcVideoEngine::CreateExternalEncoder( webrtc::VideoEncoder* WebRtcVideoEngine::CreateExternalEncoder(
webrtc::VideoCodecType type) { webrtc::VideoCodecType type) {
if (encoder_factory_ == NULL) { if (!encoder_factory_) {
return NULL; return NULL;
} }
return encoder_factory_->CreateVideoEncoder(type); return encoder_factory_->CreateVideoEncoder(type);
@ -1496,7 +1500,7 @@ webrtc::VideoEncoder* WebRtcVideoEngine::CreateExternalEncoder(
void WebRtcVideoEngine::DestroyExternalEncoder(webrtc::VideoEncoder* encoder) { void WebRtcVideoEngine::DestroyExternalEncoder(webrtc::VideoEncoder* encoder) {
ASSERT(encoder_factory_ != NULL); ASSERT(encoder_factory_ != NULL);
if (encoder_factory_ == NULL) if (!encoder_factory_)
return; return;
encoder_factory_->DestroyVideoEncoder(encoder); encoder_factory_->DestroyVideoEncoder(encoder);
} }
@ -1559,11 +1563,11 @@ WebRtcVideoMediaChannel::WebRtcVideoMediaChannel(
VoiceMediaChannel* channel) VoiceMediaChannel* channel)
: engine_(engine), : engine_(engine),
voice_channel_(channel), voice_channel_(channel),
vie_channel_(-1), default_channel_id_(kChannelIdUnset),
nack_enabled_(true), nack_enabled_(true),
remb_enabled_(false), remb_enabled_(false),
render_started_(false), render_started_(false),
first_receive_ssrc_(0), first_receive_ssrc_(kSsrcUnset),
num_unsignalled_recv_channels_(0), num_unsignalled_recv_channels_(0),
send_rtx_type_(-1), send_rtx_type_(-1),
send_red_type_(-1), send_red_type_(-1),
@ -1576,7 +1580,7 @@ WebRtcVideoMediaChannel::WebRtcVideoMediaChannel(
bool WebRtcVideoMediaChannel::Init() { bool WebRtcVideoMediaChannel::Init() {
const uint32 ssrc_key = 0; const uint32 ssrc_key = 0;
return CreateChannel(ssrc_key, MD_SENDRECV, &vie_channel_); return CreateChannel(ssrc_key, MD_SENDRECV, &default_channel_id_);
} }
WebRtcVideoMediaChannel::~WebRtcVideoMediaChannel() { WebRtcVideoMediaChannel::~WebRtcVideoMediaChannel() {
@ -1758,7 +1762,7 @@ bool WebRtcVideoMediaChannel::GetSendCodec(VideoCodec* send_codec) {
bool WebRtcVideoMediaChannel::SetSendStreamFormat(uint32 ssrc, bool WebRtcVideoMediaChannel::SetSendStreamFormat(uint32 ssrc,
const VideoFormat& format) { const VideoFormat& format) {
WebRtcVideoChannelSendInfo* send_channel = GetSendChannel(ssrc); WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrc(ssrc);
if (!send_channel) { if (!send_channel) {
LOG(LS_ERROR) << "The specified ssrc " << ssrc << " is not in use."; LOG(LS_ERROR) << "The specified ssrc " << ssrc << " is not in use.";
return false; return false;
@ -1840,22 +1844,23 @@ bool WebRtcVideoMediaChannel::AddSendStream(const StreamParams& sp) {
} }
uint32 ssrc_key; uint32 ssrc_key;
if (!CreateSendChannelKey(sp.first_ssrc(), &ssrc_key)) { if (!CreateSendChannelSsrcKey(sp.first_ssrc(), &ssrc_key)) {
LOG(LS_ERROR) << "Trying to register duplicate ssrc: " << sp.first_ssrc(); LOG(LS_ERROR) << "Trying to register duplicate ssrc: " << sp.first_ssrc();
return false; return false;
} }
// If the default channel is already used for sending create a new channel // If the default channel is already used for sending create a new channel
// otherwise use the default channel for sending. // otherwise use the default channel for sending.
int channel_id = -1; int channel_id = kChannelIdUnset;
if (send_channels_[0]->stream_params() == NULL) { if (!DefaultSendChannelInUse()) {
channel_id = vie_channel_; channel_id = default_channel_id_;
} else { } else {
if (!CreateChannel(ssrc_key, MD_SEND, &channel_id)) { if (!CreateChannel(ssrc_key, MD_SEND, &channel_id)) {
LOG(LS_ERROR) << "AddSendStream: unable to create channel"; LOG(LS_ERROR) << "AddSendStream: unable to create channel";
return false; return false;
} }
} }
WebRtcVideoChannelSendInfo* send_channel = send_channels_[ssrc_key];
WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrcKey(ssrc_key);
// Set the send (local) SSRC. // Set the send (local) SSRC.
// If there are multiple send SSRCs, we can only set the first one here, and // If there are multiple send SSRCs, we can only set the first one here, and
// the rest of the SSRC(s) need to be set after SetSendCodec has been called // the rest of the SSRC(s) need to be set after SetSendCodec has been called
@ -1882,7 +1887,7 @@ bool WebRtcVideoMediaChannel::AddSendStream(const StreamParams& sp) {
// the default channel make sure that all the receive channels are updated as // the default channel make sure that all the receive channels are updated as
// well. Receive channels have to have the same SSRC as the default channel in // well. Receive channels have to have the same SSRC as the default channel in
// order to send receiver reports with this SSRC. // order to send receiver reports with this SSRC.
if (IsDefaultChannel(channel_id)) { if (IsDefaultChannelId(channel_id)) {
for (RecvChannelMap::const_iterator it = recv_channels_.begin(); for (RecvChannelMap::const_iterator it = recv_channels_.begin();
it != recv_channels_.end(); ++it) { it != recv_channels_.end(); ++it) {
WebRtcVideoChannelRecvInfo* info = it->second; WebRtcVideoChannelRecvInfo* info = it->second;
@ -1918,14 +1923,14 @@ bool WebRtcVideoMediaChannel::RemoveSendStream(uint32 ssrc) {
} }
uint32 ssrc_key; uint32 ssrc_key;
if (!GetSendChannelKey(ssrc, &ssrc_key)) { if (!GetSendChannelSsrcKey(ssrc, &ssrc_key)) {
LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc
<< " which doesn't exist."; << " which doesn't exist.";
return false; return false;
} }
WebRtcVideoChannelSendInfo* send_channel = send_channels_[ssrc_key]; WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrcKey(ssrc_key);
int channel_id = send_channel->channel_id(); int channel_id = send_channel->channel_id();
if (IsDefaultChannel(channel_id) && (send_channel->stream_params() == NULL)) { if (IsDefaultChannelId(channel_id) && !send_channel->stream_params()) {
// Default channel will still exist. However, if stream_params() is NULL // Default channel will still exist. However, if stream_params() is NULL
// there is no stream to remove. // there is no stream to remove.
return false; return false;
@ -1947,8 +1952,8 @@ bool WebRtcVideoMediaChannel::RemoveSendStream(uint32 ssrc) {
send_channel->ClearRegisteredEncoders(); send_channel->ClearRegisteredEncoders();
// The receive channels depend on the default channel, recycle it instead. // The receive channels depend on the default channel, recycle it instead.
if (IsDefaultChannel(channel_id)) { if (IsDefaultChannelId(channel_id)) {
SetCapturer(GetDefaultChannelSsrc(), NULL); SetCapturer(GetDefaultSendChannelSsrc(), NULL);
send_channel->ClearStreamParams(); send_channel->ClearStreamParams();
} else { } else {
return DeleteSendChannel(ssrc_key); return DeleteSendChannel(ssrc_key);
@ -1965,27 +1970,26 @@ bool WebRtcVideoMediaChannel::AddRecvStream(const StreamParams& sp) {
// TODO(zhurunz) Remove this once BWE works properly across different send // TODO(zhurunz) Remove this once BWE works properly across different send
// and receive channels. // and receive channels.
// Reuse default channel for recv stream in 1:1 call. // Reuse default channel for recv stream in 1:1 call.
if (!InConferenceMode() && first_receive_ssrc_ == 0) { if (!InConferenceMode() && first_receive_ssrc_ == kSsrcUnset) {
LOG(LS_INFO) << "Recv stream " << sp.first_ssrc() LOG(LS_INFO) << "Recv stream " << sp.first_ssrc()
<< " reuse default channel #" << " reuse default channel #"
<< vie_channel_; << default_channel_id_;
first_receive_ssrc_ = sp.first_ssrc(); first_receive_ssrc_ = sp.first_ssrc();
if (!MaybeSetRtxSsrc(sp, vie_channel_)) { if (!MaybeSetRtxSsrc(sp, default_channel_id_)) {
return false; return false;
} }
if (render_started_) { if (render_started_) {
if (engine()->vie()->render()->StartRender(vie_channel_) !=0) { if (engine()->vie()->render()->StartRender(default_channel_id_) !=0) {
LOG_RTCERR1(StartRender, vie_channel_); LOG_RTCERR1(StartRender, default_channel_id_);
} }
} }
return true; return true;
} }
int channel_id = -1; int channel_id = kChannelIdUnset;
RecvChannelMap::iterator channel_iterator = uint32 ssrc = sp.first_ssrc();
recv_channels_.find(sp.first_ssrc()); WebRtcVideoChannelRecvInfo* recv_channel = GetRecvChannelBySsrc(ssrc);
if (channel_iterator == recv_channels_.end() && if (!recv_channel && first_receive_ssrc_ != ssrc) {
first_receive_ssrc_ != sp.first_ssrc()) {
// TODO(perkj): Implement recv media from multiple media SSRCs per stream. // TODO(perkj): Implement recv media from multiple media SSRCs per stream.
// NOTE: We have two SSRCs per stream when RTX is enabled. // NOTE: We have two SSRCs per stream when RTX is enabled.
if (!IsOneSsrcStream(sp)) { if (!IsOneSsrcStream(sp)) {
@ -2003,13 +2007,12 @@ bool WebRtcVideoMediaChannel::AddRecvStream(const StreamParams& sp) {
} }
} else { } else {
// Already exists. // Already exists.
if (first_receive_ssrc_ == sp.first_ssrc()) { if (first_receive_ssrc_ == ssrc) {
return false; return false;
} }
// Early receive added channel. // Early receive added channel.
channel_id = (*channel_iterator).second->channel_id(); channel_id = recv_channel->channel_id();
} }
channel_iterator = recv_channels_.find(sp.first_ssrc());
if (!MaybeSetRtxSsrc(sp, channel_id)) { if (!MaybeSetRtxSsrc(sp, channel_id)) {
return false; return false;
@ -2018,13 +2021,13 @@ bool WebRtcVideoMediaChannel::AddRecvStream(const StreamParams& sp) {
// Get the default renderer. // Get the default renderer.
VideoRenderer* default_renderer = NULL; VideoRenderer* default_renderer = NULL;
if (InConferenceMode()) { if (InConferenceMode()) {
// The recv_channels_ size start out being 1, so if it is two here this // The recv_channels_ size start out being 1, so if it is two here
// is the first receive channel created (vie_channel_ is not used for // this is the first receive channel created (default_channel_id_
// receiving in a conference call). This means that the renderer stored // is not used for receiving in a conference call). This means
// inside vie_channel_ should be used for the just created channel. // that the renderer stored inside default_channel_id_ should be
if (recv_channels_.size() == 2 && // used for the just created channel.
recv_channels_.find(0) != recv_channels_.end()) { if (recv_channels_.size() == 2 && GetDefaultRecvChannel()) {
GetRenderer(0, &default_renderer); GetDefaultRenderer(&default_renderer);
} }
} }
@ -2036,8 +2039,8 @@ bool WebRtcVideoMediaChannel::AddRecvStream(const StreamParams& sp) {
LOG(LS_INFO) << "New video stream " << sp.first_ssrc() LOG(LS_INFO) << "New video stream " << sp.first_ssrc()
<< " registered to VideoEngine channel #" << " registered to VideoEngine channel #"
<< channel_id << " and connected to channel #" << vie_channel_; << channel_id << " and connected to channel #"
<< default_channel_id_;
return true; return true;
} }
@ -2068,26 +2071,25 @@ bool WebRtcVideoMediaChannel::RemoveRecvStream(uint32 ssrc) {
} }
bool WebRtcVideoMediaChannel::RemoveRecvStreamInternal(uint32 ssrc) { bool WebRtcVideoMediaChannel::RemoveRecvStreamInternal(uint32 ssrc) {
RecvChannelMap::iterator it = recv_channels_.find(ssrc); WebRtcVideoChannelRecvInfo* recv_channel = GetRecvChannelBySsrc(ssrc);
if (it == recv_channels_.end()) { if (!recv_channel) {
// TODO(perkj): Remove this once BWE works properly across different send // TODO(perkj): Remove this once BWE works properly across different send
// and receive channels. // and receive channels.
// The default channel is reused for recv stream in 1:1 call. // The default channel is reused for recv stream in 1:1 call.
if (first_receive_ssrc_ == ssrc) { if (first_receive_ssrc_ == ssrc) {
first_receive_ssrc_ = 0; first_receive_ssrc_ = kSsrcUnset;
// Need to stop the renderer and remove it since the render window can be // Need to stop the renderer and remove it since the render window can be
// deleted after this. // deleted after this.
if (render_started_) { if (render_started_) {
if (engine()->vie()->render()->StopRender(vie_channel_) !=0) { if (engine()->vie()->render()->StopRender(default_channel_id_) !=0) {
LOG_RTCERR1(StopRender, it->second->channel_id()); LOG_RTCERR1(StopRender, recv_channel->channel_id());
} }
} }
recv_channels_[0]->SetRenderer(NULL); GetDefaultRecvChannel()->SetRenderer(NULL);
return true; return true;
} }
return false; return false;
} }
WebRtcVideoChannelRecvInfo* info = it->second;
// Remove any RTX SSRC mappings to this stream. // Remove any RTX SSRC mappings to this stream.
SsrcMap::iterator rtx_it = rtx_to_primary_ssrc_.begin(); SsrcMap::iterator rtx_it = rtx_to_primary_ssrc_.begin();
@ -2099,7 +2101,7 @@ bool WebRtcVideoMediaChannel::RemoveRecvStreamInternal(uint32 ssrc) {
} }
} }
int channel_id = info->channel_id(); int channel_id = recv_channel->channel_id();
if (engine()->vie()->render()->RemoveRenderer(channel_id) != 0) { if (engine()->vie()->render()->RemoveRenderer(channel_id) != 0) {
LOG_RTCERR1(RemoveRenderer, channel_id); LOG_RTCERR1(RemoveRenderer, channel_id);
} }
@ -2114,7 +2116,7 @@ bool WebRtcVideoMediaChannel::RemoveRecvStreamInternal(uint32 ssrc) {
} }
const WebRtcVideoChannelRecvInfo::DecoderMap& decoder_map = const WebRtcVideoChannelRecvInfo::DecoderMap& decoder_map =
info->registered_decoders(); recv_channel->registered_decoders();
for (WebRtcVideoChannelRecvInfo::DecoderMap::const_iterator it = for (WebRtcVideoChannelRecvInfo::DecoderMap::const_iterator it =
decoder_map.begin(); it != decoder_map.end(); ++it) { decoder_map.begin(); it != decoder_map.end(); ++it) {
if (engine()->vie()->ext_codec()->DeRegisterExternalReceiveCodec( if (engine()->vie()->ext_codec()->DeRegisterExternalReceiveCodec(
@ -2123,7 +2125,7 @@ bool WebRtcVideoMediaChannel::RemoveRecvStreamInternal(uint32 ssrc) {
} }
engine()->DestroyExternalDecoder(it->second); engine()->DestroyExternalDecoder(it->second);
} }
info->ClearRegisteredDecoders(); recv_channel->ClearRegisteredDecoders();
LOG(LS_INFO) << "Removing video stream " << ssrc LOG(LS_INFO) << "Removing video stream " << ssrc
<< " with VideoEngine channel #" << " with VideoEngine channel #"
@ -2134,8 +2136,8 @@ bool WebRtcVideoMediaChannel::RemoveRecvStreamInternal(uint32 ssrc) {
ret = false; ret = false;
} }
// Delete the WebRtcVideoChannelRecvInfo pointed to by it->second. // Delete the WebRtcVideoChannelRecvInfo pointed to by it->second.
delete info; delete recv_channel;
recv_channels_.erase(it); recv_channels_.erase(ssrc);
return ret; return ret;
} }
@ -2203,67 +2205,86 @@ bool WebRtcVideoMediaChannel::SendIntraFrame() {
bool WebRtcVideoMediaChannel::HasReadySendChannels() { bool WebRtcVideoMediaChannel::HasReadySendChannels() {
return !send_channels_.empty() && return !send_channels_.empty() &&
((send_channels_.size() > 1) || ((send_channels_.size() > 1) || DefaultSendChannelInUse());
(send_channels_[0]->stream_params() != NULL));
} }
bool WebRtcVideoMediaChannel::GetSendChannelKey(uint32 local_ssrc, bool WebRtcVideoMediaChannel::DefaultSendChannelInUse() {
uint32* key) { return GetDefaultSendChannel() && GetDefaultSendChannel()->stream_params();
*key = 0; }
bool WebRtcVideoMediaChannel::GetSendChannelSsrcKey(uint32 local_ssrc,
uint32* ssrc_key) {
*ssrc_key = kDefaultChannelSsrcKey;
// If a send channel is not ready to send it will not have local_ssrc // If a send channel is not ready to send it will not have local_ssrc
// registered to it. // registered to it.
if (!HasReadySendChannels()) { if (!HasReadySendChannels()) {
return false; return false;
} }
// The default channel is stored with key 0. The key therefore does not match // The default channel is stored with ssrc key
// the SSRC associated with the default channel. Check if the SSRC provided // kDefaultChannelSsrcKey. The ssrc key therefore does not match the
// corresponds to the default channel's SSRC. // SSRC associated with the default channel. Check if the SSRC
if (local_ssrc == GetDefaultChannelSsrc()) { // provided corresponds to the default channel's SSRC.
if (local_ssrc == GetDefaultSendChannelSsrc()) {
return true; return true;
} }
if (send_channels_.find(local_ssrc) == send_channels_.end()) { if (!GetSendChannelBySsrcKey(local_ssrc)) {
for (SendChannelMap::iterator iter = send_channels_.begin(); for (SendChannelMap::iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) { iter != send_channels_.end(); ++iter) {
WebRtcVideoChannelSendInfo* send_channel = iter->second; WebRtcVideoChannelSendInfo* send_channel = iter->second;
if (send_channel->has_ssrc(local_ssrc)) { if (send_channel->has_ssrc(local_ssrc)) {
*key = iter->first; *ssrc_key = iter->first;
return true; return true;
} }
} }
return false; return false;
} }
// The key was found in the above std::map::find call. This means that the // The ssrc key was found in the above std::map::find call. This
// ssrc is the key. // means that the ssrc is the ssrc key.
*key = local_ssrc; *ssrc_key = local_ssrc;
return true; return true;
} }
WebRtcVideoChannelSendInfo* WebRtcVideoMediaChannel::GetSendChannel( WebRtcVideoChannelSendInfo* WebRtcVideoMediaChannel::GetDefaultSendChannel() {
uint32 local_ssrc) { return GetSendChannelBySsrcKey(kDefaultChannelSsrcKey);
uint32 key;
if (!GetSendChannelKey(local_ssrc, &key)) {
return NULL;
}
return send_channels_[key];
} }
bool WebRtcVideoMediaChannel::CreateSendChannelKey(uint32 local_ssrc, WebRtcVideoChannelSendInfo* WebRtcVideoMediaChannel::GetSendChannelBySsrcKey(
uint32* key) { uint32 ssrc_key) {
if (GetSendChannelKey(local_ssrc, key)) { std::map<uint32, WebRtcVideoChannelSendInfo *>::iterator iter =
// If there is a key corresponding to |local_ssrc|, the SSRC is already in send_channels_.find(ssrc_key);
// use. SSRCs need to be unique in a session and at this point a duplicate if (iter == send_channels_.end()) {
// SSRC has been detected. return NULL;
}
return iter->second;
}
WebRtcVideoChannelSendInfo* WebRtcVideoMediaChannel::GetSendChannelBySsrc(
uint32 local_ssrc) {
uint32 ssrc_key;
if (!GetSendChannelSsrcKey(local_ssrc, &ssrc_key)) {
return NULL;
}
return send_channels_[ssrc_key];
}
bool WebRtcVideoMediaChannel::CreateSendChannelSsrcKey(uint32 local_ssrc,
uint32* ssrc_key) {
if (GetSendChannelSsrcKey(local_ssrc, ssrc_key)) {
// If there is an ssrc key corresponding to |local_ssrc|, the SSRC
// is already in use. SSRCs need to be unique in a session and at
// this point a duplicate SSRC has been detected.
return false; return false;
} }
if (send_channels_[0]->stream_params() == NULL) { if (!DefaultSendChannelInUse()) {
// key should be 0 here as the default channel should be re-used whenever it // |ssrc_key| should be kDefaultChannelSsrcKey here as the default
// is not used. // channel should be re-used whenever it is not used.
*key = 0; *ssrc_key = kDefaultChannelSsrcKey;
return true; return true;
} }
// SSRC is currently not in use and the default channel is already in use. Use // SSRC is currently not in use and the default channel is already
// the SSRC as key since it is supposed to be unique in a session. // in use. Use the SSRC as ssrc_key since it is supposed to be
*key = local_ssrc; // unique in a session.
*ssrc_key = local_ssrc;
return true; return true;
} }
@ -2279,21 +2300,18 @@ int WebRtcVideoMediaChannel::GetSendChannelNum(VideoCapturer* capturer) {
return num; return num;
} }
uint32 WebRtcVideoMediaChannel::GetDefaultChannelSsrc() { uint32 WebRtcVideoMediaChannel::GetDefaultSendChannelSsrc() {
WebRtcVideoChannelSendInfo* send_channel = send_channels_[0]; if (!DefaultSendChannelInUse()) {
const StreamParams* sp = send_channel->stream_params();
if (sp == NULL) {
// This happens if no send stream is currently registered.
return 0; return 0;
} }
return sp->first_ssrc(); return GetDefaultSendChannel()->stream_params()->first_ssrc();
} }
bool WebRtcVideoMediaChannel::DeleteSendChannel(uint32 ssrc_key) { bool WebRtcVideoMediaChannel::DeleteSendChannel(uint32 ssrc_key) {
if (send_channels_.find(ssrc_key) == send_channels_.end()) { WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrcKey(ssrc_key);
if (!send_channel) {
return false; return false;
} }
WebRtcVideoChannelSendInfo* send_channel = send_channels_[ssrc_key];
MaybeDisconnectCapturer(send_channel->video_capturer()); MaybeDisconnectCapturer(send_channel->video_capturer());
send_channel->set_video_capturer(NULL, engine()->vie()); send_channel->set_video_capturer(NULL, engine()->vie());
@ -2317,7 +2335,7 @@ bool WebRtcVideoMediaChannel::DeleteSendChannel(uint32 ssrc_key) {
// The default channel is stored in both |send_channels_| and // The default channel is stored in both |send_channels_| and
// |recv_channels_|. To make sure it is only deleted once from vie let the // |recv_channels_|. To make sure it is only deleted once from vie let the
// delete call happen when tearing down |recv_channels_| and not here. // delete call happen when tearing down |recv_channels_| and not here.
if (!IsDefaultChannel(channel_id)) { if (!IsDefaultChannelId(channel_id)) {
engine_->vie()->base()->DeleteChannel(channel_id); engine_->vie()->base()->DeleteChannel(channel_id);
} }
delete send_channel; delete send_channel;
@ -2325,13 +2343,25 @@ bool WebRtcVideoMediaChannel::DeleteSendChannel(uint32 ssrc_key) {
return true; return true;
} }
WebRtcVideoChannelRecvInfo* WebRtcVideoMediaChannel::GetDefaultRecvChannel() {
return GetRecvChannelBySsrc(kDefaultChannelSsrcKey);
}
WebRtcVideoChannelRecvInfo* WebRtcVideoMediaChannel::GetRecvChannelBySsrc(
uint32 ssrc) {
if (recv_channels_.find(ssrc) == recv_channels_.end()) {
return NULL;
}
return recv_channels_[ssrc];
}
bool WebRtcVideoMediaChannel::RemoveCapturer(uint32 ssrc) { bool WebRtcVideoMediaChannel::RemoveCapturer(uint32 ssrc) {
WebRtcVideoChannelSendInfo* send_channel = GetSendChannel(ssrc); WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrc(ssrc);
if (!send_channel) { if (!send_channel) {
return false; return false;
} }
VideoCapturer* capturer = send_channel->video_capturer(); VideoCapturer* capturer = send_channel->video_capturer();
if (capturer == NULL) { if (!capturer) {
return false; return false;
} }
MaybeDisconnectCapturer(capturer); MaybeDisconnectCapturer(capturer);
@ -2345,22 +2375,22 @@ bool WebRtcVideoMediaChannel::RemoveCapturer(uint32 ssrc) {
bool WebRtcVideoMediaChannel::SetRenderer(uint32 ssrc, bool WebRtcVideoMediaChannel::SetRenderer(uint32 ssrc,
VideoRenderer* renderer) { VideoRenderer* renderer) {
if (recv_channels_.find(ssrc) == recv_channels_.end()) { WebRtcVideoChannelRecvInfo* recv_channel = GetRecvChannelBySsrc(ssrc);
if (!recv_channel) {
// TODO(perkj): Remove this once BWE works properly across different send // TODO(perkj): Remove this once BWE works properly across different send
// and receive channels. // and receive channels.
// The default channel is reused for recv stream in 1:1 call. // The default channel is reused for recv stream in 1:1 call.
if (first_receive_ssrc_ == ssrc && if (first_receive_ssrc_ == ssrc && GetDefaultRecvChannel()) {
recv_channels_.find(0) != recv_channels_.end()) {
LOG(LS_INFO) << "SetRenderer " << ssrc LOG(LS_INFO) << "SetRenderer " << ssrc
<< " reuse default channel #" << " reuse default channel #"
<< vie_channel_; << default_channel_id_;
recv_channels_[0]->SetRenderer(renderer); GetDefaultRecvChannel()->SetRenderer(renderer);
return true; return true;
} }
return false; return false;
} }
recv_channels_[ssrc]->SetRenderer(renderer); recv_channel->SetRenderer(renderer);
return true; return true;
} }
@ -2380,21 +2410,21 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options,
const int channel_id = send_channel->channel_id(); const int channel_id = send_channel->channel_id();
VideoSenderInfo sinfo; VideoSenderInfo sinfo;
const StreamParams* send_params = send_channel->stream_params(); const StreamParams* send_params = send_channel->stream_params();
if (send_params == NULL) { if (!send_params) {
// This should only happen if the default vie channel is not in use. // This should only happen if the default vie channel is not in use.
// This can happen if no streams have ever been added or the stream // This can happen if no streams have ever been added or the stream
// corresponding to the default channel has been removed. Note that // corresponding to the default channel has been removed. Note that
// there may be non-default vie channels in use when this happen so // there may be non-default vie channels in use when this happen so
// asserting send_channels_.size() == 1 is not correct and neither is // asserting send_channels_.size() == 1 is not correct and neither is
// breaking out of the loop. // breaking out of the loop.
ASSERT(channel_id == vie_channel_); ASSERT(channel_id == default_channel_id_);
continue; continue;
} }
unsigned int bytes_sent, packets_sent, bytes_recv, packets_recv; unsigned int bytes_sent, packets_sent, bytes_recv, packets_recv;
if (engine_->vie()->rtp()->GetRTPStatistics(channel_id, bytes_sent, if (engine_->vie()->rtp()->GetRTPStatistics(channel_id, bytes_sent,
packets_sent, bytes_recv, packets_sent, bytes_recv,
packets_recv) != 0) { packets_recv) != 0) {
LOG_RTCERR1(GetRTPStatistics, vie_channel_); LOG_RTCERR1(GetRTPStatistics, default_channel_id_);
continue; continue;
} }
WebRtcLocalStreamInfo* channel_stream_info = WebRtcLocalStreamInfo* channel_stream_info =
@ -2638,7 +2668,7 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options,
// Only call for the default channel because the returned stats are // Only call for the default channel because the returned stats are
// collected for all the channels using the same estimator. // collected for all the channels using the same estimator.
if (engine_->vie()->rtp()->GetReceiveBandwidthEstimatorStats( if (engine_->vie()->rtp()->GetReceiveBandwidthEstimatorStats(
recv_channels_[0]->channel_id(), &additional_stats) == 0) { GetDefaultRecvChannel()->channel_id(), &additional_stats) == 0) {
bwe.total_received_propagation_delta_ms = bwe.total_received_propagation_delta_ms =
additional_stats.total_propagation_time_delta_ms; additional_stats.total_propagation_time_delta_ms;
bwe.recent_received_propagation_delta_ms.swap( bwe.recent_received_propagation_delta_ms.swap(
@ -2649,7 +2679,7 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options,
} }
engine_->vie()->rtp()->GetPacerQueuingDelayMs( engine_->vie()->rtp()->GetPacerQueuingDelayMs(
recv_channels_[0]->channel_id(), &bwe.bucket_delay); GetDefaultRecvChannel()->channel_id(), &bwe.bucket_delay);
// Calculations done above per send/receive stream. // Calculations done above per send/receive stream.
bwe.actual_enc_bitrate = video_bitrate_sent; bwe.actual_enc_bitrate = video_bitrate_sent;
@ -2670,7 +2700,7 @@ bool WebRtcVideoMediaChannel::SetCapturer(uint32 ssrc,
if (!capturer) { if (!capturer) {
return RemoveCapturer(ssrc); return RemoveCapturer(ssrc);
} }
WebRtcVideoChannelSendInfo* send_channel = GetSendChannel(ssrc); WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrc(ssrc);
if (!send_channel) { if (!send_channel) {
return false; return false;
} }
@ -2703,13 +2733,13 @@ void WebRtcVideoMediaChannel::OnPacketReceived(
uint32 ssrc = 0; uint32 ssrc = 0;
if (!GetRtpSsrc(packet->data(), packet->length(), &ssrc)) if (!GetRtpSsrc(packet->data(), packet->length(), &ssrc))
return; return;
int processing_channel = GetRecvChannelNum(ssrc); int processing_channel_id = GetRecvChannelId(ssrc);
if (processing_channel == -1) { if (processing_channel_id == kChannelIdUnset) {
// Allocate an unsignalled recv channel for processing in conference mode. // Allocate an unsignalled recv channel for processing in conference mode.
if (!InConferenceMode()) { if (!InConferenceMode()) {
// If we can't find or allocate one, use the default. // If we can't find or allocate one, use the default.
processing_channel = video_channel(); processing_channel_id = default_channel_id_;
} else if (!CreateUnsignalledRecvChannel(ssrc, &processing_channel)) { } else if (!CreateUnsignalledRecvChannel(ssrc, &processing_channel_id)) {
// If we can't create an unsignalled recv channel, drop the packet in // If we can't create an unsignalled recv channel, drop the packet in
// conference mode. // conference mode.
return; return;
@ -2717,7 +2747,7 @@ void WebRtcVideoMediaChannel::OnPacketReceived(
} }
engine()->vie()->network()->ReceivedRTPPacket( engine()->vie()->network()->ReceivedRTPPacket(
processing_channel, processing_channel_id,
packet->data(), packet->data(),
static_cast<int>(packet->length()), static_cast<int>(packet->length()),
webrtc::PacketTime(packet_time.timestamp, packet_time.not_before)); webrtc::PacketTime(packet_time.timestamp, packet_time.not_before));
@ -2743,10 +2773,10 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
// If it is a sender report, find the channel that is listening. // If it is a sender report, find the channel that is listening.
if (type == kRtcpTypeSR) { if (type == kRtcpTypeSR) {
int which_channel = GetRecvChannelNum(ssrc); int recv_channel_id = GetRecvChannelId(ssrc);
if (which_channel != -1 && !IsDefaultChannel(which_channel)) { if (recv_channel_id != kChannelIdUnset && !IsDefaultChannelId(recv_channel_id)) {
engine_->vie()->network()->ReceivedRTCPPacket( engine_->vie()->network()->ReceivedRTCPPacket(
which_channel, recv_channel_id,
packet->data(), packet->data(),
static_cast<int>(packet->length())); static_cast<int>(packet->length()));
} }
@ -2770,7 +2800,7 @@ void WebRtcVideoMediaChannel::OnReadyToSend(bool ready) {
} }
bool WebRtcVideoMediaChannel::MuteStream(uint32 ssrc, bool muted) { bool WebRtcVideoMediaChannel::MuteStream(uint32 ssrc, bool muted) {
WebRtcVideoChannelSendInfo* send_channel = GetSendChannel(ssrc); WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrc(ssrc);
if (!send_channel) { if (!send_channel) {
LOG(LS_ERROR) << "The specified ssrc " << ssrc << " is not in use."; LOG(LS_ERROR) << "The specified ssrc " << ssrc << " is not in use.";
return false; return false;
@ -3110,30 +3140,33 @@ void WebRtcVideoMediaChannel::UpdateAspectRatio(int ratio_w, int ratio_h) {
bool WebRtcVideoMediaChannel::GetRenderer(uint32 ssrc, bool WebRtcVideoMediaChannel::GetRenderer(uint32 ssrc,
VideoRenderer** renderer) { VideoRenderer** renderer) {
RecvChannelMap::const_iterator it = recv_channels_.find(ssrc); WebRtcVideoChannelRecvInfo* recv_channel = GetRecvChannelBySsrc(ssrc);
if (it == recv_channels_.end()) { if (!recv_channel) {
if (first_receive_ssrc_ == ssrc && if (first_receive_ssrc_ == ssrc && GetDefaultRecvChannel()) {
recv_channels_.find(0) != recv_channels_.end()) {
LOG(LS_INFO) << " GetRenderer " << ssrc LOG(LS_INFO) << " GetRenderer " << ssrc
<< " reuse default renderer #" << " reuse default renderer #"
<< vie_channel_; << default_channel_id_;
*renderer = recv_channels_[0]->render_adapter()->renderer(); *renderer = GetDefaultRecvChannel()->render_adapter()->renderer();
return true; return true;
} }
return false; return false;
} }
*renderer = it->second->render_adapter()->renderer(); *renderer = recv_channel->render_adapter()->renderer();
return true; return true;
} }
bool WebRtcVideoMediaChannel::GetDefaultRenderer(VideoRenderer** renderer) {
return GetRenderer(kDefaultChannelSsrcKey, renderer);
}
bool WebRtcVideoMediaChannel::GetVideoAdapter( bool WebRtcVideoMediaChannel::GetVideoAdapter(
uint32 ssrc, CoordinatedVideoAdapter** video_adapter) { uint32 ssrc, CoordinatedVideoAdapter** video_adapter) {
SendChannelMap::iterator it = send_channels_.find(ssrc); WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrc(ssrc);
if (it == send_channels_.end()) { if (!send_channel) {
return false; return false;
} }
*video_adapter = it->second->video_adapter(); *video_adapter = send_channel->video_adapter();
return true; return true;
} }
@ -3159,7 +3192,7 @@ void WebRtcVideoMediaChannel::SendFrame(VideoCapturer* capturer,
for (SendChannelMap::iterator iter = send_channels_.begin(); for (SendChannelMap::iterator iter = send_channels_.begin();
iter != send_channels_.end(); ++iter) { iter != send_channels_.end(); ++iter) {
WebRtcVideoChannelSendInfo* send_channel = iter->second; WebRtcVideoChannelSendInfo* send_channel = iter->second;
if (send_channel->video_capturer() == NULL) { if (!send_channel->video_capturer()) {
SendFrame(send_channel, frame, capturer->IsScreencast()); SendFrame(send_channel, frame, capturer->IsScreencast());
} }
} }
@ -3244,32 +3277,33 @@ bool WebRtcVideoMediaChannel::CreateChannel(uint32 ssrc_key,
int* channel_id) { int* channel_id) {
// There are 3 types of channels. Sending only, receiving only and // There are 3 types of channels. Sending only, receiving only and
// sending and receiving. The sending and receiving channel is the // sending and receiving. The sending and receiving channel is the
// default channel and there is only one. All other channels that are created // default channel and there is only one. All other channels that
// are associated with the default channel which must exist. The default // are created are associated with the default channel which must
// channel id is stored in |vie_channel_|. All channels need to know about // exist. The default channel id is stored in
// the default channel to properly handle remb which is why there are // |default_channel_id_|. All channels need to know about the
// different ViE create channel calls. // default channel to properly handle remb which is why there are
// For this channel the local and remote ssrc key is 0. However, it may // different ViE create channel calls. For this channel the local
// have a non-zero local and/or remote ssrc depending on if it is currently // and remote ssrc_key is kDefaultChannelSsrcKey. However, it may
// sending and/or receiving. // have a non-zero local and/or remote ssrc depending on if it is
if ((vie_channel_ == -1 || direction == MD_SENDRECV) && // currently sending and/or receiving.
if ((default_channel_id_ == kChannelIdUnset || direction == MD_SENDRECV) &&
(!send_channels_.empty() || !recv_channels_.empty())) { (!send_channels_.empty() || !recv_channels_.empty())) {
ASSERT(false); ASSERT(false);
return false; return false;
} }
*channel_id = -1; *channel_id = kChannelIdUnset;
if (direction == MD_RECV) { if (direction == MD_RECV) {
// All rec channels are associated with the default channel |vie_channel_| // All rec channels are associated with default_channel_id_.
if (engine_->vie()->base()->CreateReceiveChannel(*channel_id, if (engine_->vie()->base()->CreateReceiveChannel(*channel_id,
vie_channel_) != 0) { default_channel_id_) != 0) {
LOG_RTCERR2(CreateReceiveChannel, *channel_id, vie_channel_); LOG_RTCERR2(CreateReceiveChannel, *channel_id, default_channel_id_);
return false; return false;
} }
} else if (direction == MD_SEND) { } else if (direction == MD_SEND) {
if (engine_->vie()->base()->CreateChannel(*channel_id, if (engine_->vie()->base()->CreateChannel(*channel_id,
vie_channel_) != 0) { default_channel_id_) != 0) {
LOG_RTCERR2(CreateChannel, *channel_id, vie_channel_); LOG_RTCERR2(CreateChannel, *channel_id, default_channel_id_);
return false; return false;
} }
} else { } else {
@ -3281,7 +3315,7 @@ bool WebRtcVideoMediaChannel::CreateChannel(uint32 ssrc_key,
} }
if (!ConfigureChannel(*channel_id, direction, ssrc_key)) { if (!ConfigureChannel(*channel_id, direction, ssrc_key)) {
engine_->vie()->base()->DeleteChannel(*channel_id); engine_->vie()->base()->DeleteChannel(*channel_id);
*channel_id = -1; *channel_id = kChannelIdUnset;
return false; return false;
} }
@ -3363,9 +3397,9 @@ bool WebRtcVideoMediaChannel::ConfigureChannel(int channel_id,
} }
bool WebRtcVideoMediaChannel::ConfigureReceiving(int channel_id, bool WebRtcVideoMediaChannel::ConfigureReceiving(int channel_id,
uint32 remote_ssrc_key) { uint32 remote_ssrc) {
// Make sure that an SSRC/key isn't registered more than once. // Make sure that an SSRC isn't registered more than once.
if (recv_channels_.find(remote_ssrc_key) != recv_channels_.end()) { if (GetRecvChannelBySsrc(remote_ssrc)) {
return false; return false;
} }
// Connect the voice channel, if there is one. // Connect the voice channel, if there is one.
@ -3373,11 +3407,11 @@ bool WebRtcVideoMediaChannel::ConfigureReceiving(int channel_id,
// know the SSRC of the remote audio channel in order to fetch the correct // know the SSRC of the remote audio channel in order to fetch the correct
// webrtc VoiceEngine channel. For now- only sync the default channel used // webrtc VoiceEngine channel. For now- only sync the default channel used
// in 1-1 calls. // in 1-1 calls.
if (remote_ssrc_key == 0 && voice_channel_) { if (remote_ssrc == kDefaultChannelSsrcKey && voice_channel_) {
WebRtcVoiceMediaChannel* voice_channel = WebRtcVoiceMediaChannel* voice_channel =
static_cast<WebRtcVoiceMediaChannel*>(voice_channel_); static_cast<WebRtcVoiceMediaChannel*>(voice_channel_);
if (engine_->vie()->base()->ConnectAudioChannel( if (engine_->vie()->base()->ConnectAudioChannel(
vie_channel_, voice_channel->voe_channel()) != 0) { default_channel_id_, voice_channel->voe_channel()) != 0) {
LOG_RTCERR2(ConnectAudioChannel, channel_id, LOG_RTCERR2(ConnectAudioChannel, channel_id,
voice_channel->voe_channel()); voice_channel->voe_channel());
LOG(LS_WARNING) << "A/V not synchronized"; LOG(LS_WARNING) << "A/V not synchronized";
@ -3414,13 +3448,13 @@ bool WebRtcVideoMediaChannel::ConfigureReceiving(int channel_id,
return false; return false;
} }
if (remote_ssrc_key != 0) { if (remote_ssrc != kDefaultChannelSsrcKey) {
// Use the same SSRC as our default channel // Use the same SSRC as our default channel
// (so the RTCP reports are correct). // (so the RTCP reports are correct).
unsigned int send_ssrc = 0; unsigned int send_ssrc = 0;
webrtc::ViERTP_RTCP* rtp = engine()->vie()->rtp(); webrtc::ViERTP_RTCP* rtp = engine()->vie()->rtp();
if (rtp->GetLocalSSRC(vie_channel_, send_ssrc) == -1) { if (rtp->GetLocalSSRC(default_channel_id_, send_ssrc) == -1) {
LOG_RTCERR2(GetLocalSSRC, vie_channel_, send_ssrc); LOG_RTCERR2(GetLocalSSRC, default_channel_id_, send_ssrc);
return false; return false;
} }
if (rtp->SetLocalSSRC(channel_id, send_ssrc) == -1) { if (rtp->SetLocalSSRC(channel_id, send_ssrc) == -1) {
@ -3464,7 +3498,7 @@ bool WebRtcVideoMediaChannel::ConfigureReceiving(int channel_id,
return false; return false;
} }
recv_channels_[remote_ssrc_key] = channel_info.release(); recv_channels_[remote_ssrc] = channel_info.release();
return true; return true;
} }
@ -3472,12 +3506,12 @@ bool WebRtcVideoMediaChannel::ConfigureSending(int channel_id,
uint32 local_ssrc_key) { uint32 local_ssrc_key) {
// The ssrc key can be zero or correspond to an SSRC. // The ssrc key can be zero or correspond to an SSRC.
// Make sure the default channel isn't configured more than once. // Make sure the default channel isn't configured more than once.
if (local_ssrc_key == 0 && send_channels_.find(0) != send_channels_.end()) { if (local_ssrc_key == kDefaultChannelSsrcKey && GetDefaultSendChannel()) {
return false; return false;
} }
// Make sure that the SSRC is not already in use. // Make sure that the SSRC is not already in use.
uint32 dummy_key; uint32 dummy_key;
if (GetSendChannelKey(local_ssrc_key, &dummy_key)) { if (GetSendChannelSsrcKey(local_ssrc_key, &dummy_key)) {
return false; return false;
} }
int vie_capture = 0; int vie_capture = 0;
@ -3731,8 +3765,8 @@ static std::string ToString(webrtc::VP8ResilienceMode resilience) {
void WebRtcVideoMediaChannel::LogSendCodecChange(const std::string& reason) { void WebRtcVideoMediaChannel::LogSendCodecChange(const std::string& reason) {
webrtc::VideoCodec vie_codec; webrtc::VideoCodec vie_codec;
if (engine()->vie()->codec()->GetSendCodec(vie_channel_, vie_codec) != 0) { if (engine()->vie()->codec()->GetSendCodec(default_channel_id_, vie_codec) != 0) {
LOG_RTCERR1(GetSendCodec, vie_channel_); LOG_RTCERR1(GetSendCodec, default_channel_id_);
return; return;
} }
@ -3846,28 +3880,28 @@ bool WebRtcVideoMediaChannel::SetReceiveCodecs(
return true; return true;
} }
int WebRtcVideoMediaChannel::GetRecvChannelNum(uint32 ssrc) { int WebRtcVideoMediaChannel::GetRecvChannelId(uint32 ssrc) {
if (ssrc == first_receive_ssrc_) { if (ssrc == first_receive_ssrc_) {
return vie_channel_; return default_channel_id_;
} }
int recv_channel = -1; int recv_channel_id = kChannelIdUnset;
RecvChannelMap::iterator it = recv_channels_.find(ssrc); WebRtcVideoChannelRecvInfo* recv_channel = GetRecvChannelBySsrc(ssrc);
if (it == recv_channels_.end()) { if (!recv_channel) {
// Check if we have an RTX stream registered on this SSRC. // Check if we have an RTX stream registered on this SSRC.
SsrcMap::iterator rtx_it = rtx_to_primary_ssrc_.find(ssrc); SsrcMap::iterator rtx_it = rtx_to_primary_ssrc_.find(ssrc);
if (rtx_it != rtx_to_primary_ssrc_.end()) { if (rtx_it != rtx_to_primary_ssrc_.end()) {
if (rtx_it->second == first_receive_ssrc_) { if (rtx_it->second == first_receive_ssrc_) {
recv_channel = vie_channel_; recv_channel_id = default_channel_id_;
} else { } else {
it = recv_channels_.find(rtx_it->second); recv_channel = GetRecvChannelBySsrc(rtx_it->second);
assert(it != recv_channels_.end()); ASSERT(recv_channel != NULL);
recv_channel = it->second->channel_id(); recv_channel_id = recv_channel->channel_id();
} }
} }
} else { } else {
recv_channel = it->second->channel_id(); recv_channel_id = recv_channel->channel_id();
} }
return recv_channel; return recv_channel_id;
} }
// If the new frame size is different from the send codec size we set on vie, // If the new frame size is different from the send codec size we set on vie,
@ -4057,7 +4091,7 @@ void WebRtcVideoMediaChannel::QueueBlackFrame(uint32 ssrc, int64 timestamp,
} }
void WebRtcVideoMediaChannel::FlushBlackFrame(uint32 ssrc, int64 timestamp) { void WebRtcVideoMediaChannel::FlushBlackFrame(uint32 ssrc, int64 timestamp) {
WebRtcVideoChannelSendInfo* send_channel = GetSendChannel(ssrc); WebRtcVideoChannelSendInfo* send_channel = GetSendChannelBySsrc(ssrc);
if (!send_channel) { if (!send_channel) {
return; return;
} }
@ -4145,14 +4179,14 @@ bool WebRtcVideoMediaChannel::SetLocalRtxSsrc(int channel_id,
} }
void WebRtcVideoMediaChannel::MaybeConnectCapturer(VideoCapturer* capturer) { void WebRtcVideoMediaChannel::MaybeConnectCapturer(VideoCapturer* capturer) {
if (capturer != NULL && GetSendChannelNum(capturer) == 1) { if (capturer && GetSendChannelNum(capturer) == 1) {
capturer->SignalVideoFrame.connect(this, capturer->SignalVideoFrame.connect(this,
&WebRtcVideoMediaChannel::SendFrame); &WebRtcVideoMediaChannel::SendFrame);
} }
} }
void WebRtcVideoMediaChannel::MaybeDisconnectCapturer(VideoCapturer* capturer) { void WebRtcVideoMediaChannel::MaybeDisconnectCapturer(VideoCapturer* capturer) {
if (capturer != NULL && GetSendChannelNum(capturer) == 1) { if (capturer && GetSendChannelNum(capturer) == 1) {
capturer->SignalVideoFrame.disconnect(this); capturer->SignalVideoFrame.disconnect(this);
} }
} }

View File

@ -243,11 +243,11 @@ class WebRtcVideoMediaChannel : public rtc::MessageHandler,
WebRtcVideoEngine* engine() { return engine_; } WebRtcVideoEngine* engine() { return engine_; }
VoiceMediaChannel* voice_channel() { return voice_channel_; } VoiceMediaChannel* voice_channel() { return voice_channel_; }
int video_channel() const { return vie_channel_; }
bool sending() const { return sending_; } bool sending() const { return sending_; }
// Public for testing purpose. // Public for testing purpose.
uint32 GetDefaultChannelSsrc(); uint32 GetDefaultSendChannelSsrc();
int GetDefaultChannelId() const { return default_channel_id_; }
// VideoMediaChannel implementation // VideoMediaChannel implementation
virtual bool SetRecvCodecs(const std::vector<VideoCodec> &codecs); virtual bool SetRecvCodecs(const std::vector<VideoCodec> &codecs);
@ -318,14 +318,15 @@ class WebRtcVideoMediaChannel : public rtc::MessageHandler,
enum MediaDirection { MD_RECV, MD_SEND, MD_SENDRECV }; enum MediaDirection { MD_RECV, MD_SEND, MD_SENDRECV };
// Creates and initializes a ViE channel. When successful |channel_id| will // Creates and initializes a ViE channel. When successful
// contain the new channel's ID. If |receiving| is true |ssrc| is the // |channel_id| will contain the new channel's ID. If |receiving| is
// remote ssrc. If |sending| is true the ssrc is local ssrc. If both // true |ssrc| is the remote ssrc. If |sending| is true the ssrc is
// |receiving| and |sending| is true the ssrc must be 0 and the channel will // local ssrc. If both |receiving| and |sending| is true the ssrc
// be created as a default channel. The ssrc must be different for receive // must be kDefaultChannelSsrcKey and the channel will be created as
// channels and it must be different for send channels. If the same SSRC is // a default channel. The ssrc must be different for receive
// being used for creating channel more than once, this function will fail // channels and it must be different for send channels. If the same
// returning false. // SSRC is being used for creating channel more than once, this
// function will fail returning false.
bool CreateChannel(uint32 ssrc_key, MediaDirection direction, bool CreateChannel(uint32 ssrc_key, MediaDirection direction,
int* channel_id); int* channel_id);
bool CreateUnsignalledRecvChannel(uint32 ssrc_key, int* channel_id); bool CreateUnsignalledRecvChannel(uint32 ssrc_key, int* channel_id);
@ -342,8 +343,8 @@ class WebRtcVideoMediaChannel : public rtc::MessageHandler,
// Prepares the channel with channel id |info->channel_id()| to receive all // Prepares the channel with channel id |info->channel_id()| to receive all
// codecs in |receive_codecs_| and start receive packets. // codecs in |receive_codecs_| and start receive packets.
bool SetReceiveCodecs(WebRtcVideoChannelRecvInfo* info); bool SetReceiveCodecs(WebRtcVideoChannelRecvInfo* info);
// Returns the channel number that receives the stream with SSRC |ssrc|. // Returns the channel ID that receives the stream with SSRC |ssrc|.
int GetRecvChannelNum(uint32 ssrc); int GetRecvChannelId(uint32 ssrc);
bool MaybeSetRtxSsrc(const StreamParams& sp, int channel_id); bool MaybeSetRtxSsrc(const StreamParams& sp, int channel_id);
// Given captured video frame size, checks if we need to reset vie send codec. // Given captured video frame size, checks if we need to reset vie send codec.
// |reset| is set to whether resetting has happened on vie or not. // |reset| is set to whether resetting has happened on vie or not.
@ -365,25 +366,34 @@ class WebRtcVideoMediaChannel : public rtc::MessageHandler,
bool SendIntraFrame(int channel_id); bool SendIntraFrame(int channel_id);
bool HasReadySendChannels(); bool HasReadySendChannels();
bool DefaultSendChannelInUse();
// Send channel key returns the key corresponding to the provided local SSRC // Returns the ssrc key corresponding to the provided local SSRC in
// in |key|. The return value is true upon success. // |ssrc_key|. The return value is true upon success. If the local
// If the local ssrc correspond to that of the default channel the key is 0. // ssrc correspond to that of the default channel the key is
// For all other channels the returned key will be the same as the local ssrc. // kDefaultChannelSsrcKey.
bool GetSendChannelKey(uint32 local_ssrc, uint32* key); // For all other channels the returned ssrc key will be the same as
WebRtcVideoChannelSendInfo* GetSendChannel(uint32 local_ssrc); // the local ssrc.
// Creates a new unique key that can be used for inserting a new send channel bool GetSendChannelSsrcKey(uint32 local_ssrc, uint32* ssrc_key);
// into |send_channels_| WebRtcVideoChannelSendInfo* GetDefaultSendChannel();
bool CreateSendChannelKey(uint32 local_ssrc, uint32* key); WebRtcVideoChannelSendInfo* GetSendChannelBySsrcKey(uint32 ssrc_key);
WebRtcVideoChannelSendInfo* GetSendChannelBySsrc(uint32 local_ssrc);
// Creates a new unique ssrc key that can be used for inserting a
// new send channel into |send_channels_|
bool CreateSendChannelSsrcKey(uint32 local_ssrc, uint32* ssrc_key);
// Get the number of the send channels |capturer| registered with. // Get the number of the send channels |capturer| registered with.
int GetSendChannelNum(VideoCapturer* capturer); int GetSendChannelNum(VideoCapturer* capturer);
bool IsDefaultChannel(int channel_id) const { bool IsDefaultChannelId(int channel_id) const {
return channel_id == vie_channel_; return channel_id == default_channel_id_;
} }
bool GetDefaultRenderer(VideoRenderer** renderer);
bool DeleteSendChannel(uint32 ssrc_key); bool DeleteSendChannel(uint32 ssrc_key);
WebRtcVideoChannelRecvInfo* GetDefaultRecvChannel();
WebRtcVideoChannelRecvInfo* GetRecvChannelBySsrc(uint32 ssrc);
bool InConferenceMode() const { bool InConferenceMode() const {
return options_.conference_mode.GetWithDefaultIfUnset(false); return options_.conference_mode.GetWithDefaultIfUnset(false);
} }
@ -420,17 +430,17 @@ class WebRtcVideoMediaChannel : public rtc::MessageHandler,
// Global state. // Global state.
WebRtcVideoEngine* engine_; WebRtcVideoEngine* engine_;
VoiceMediaChannel* voice_channel_; VoiceMediaChannel* voice_channel_;
int vie_channel_; int default_channel_id_;
bool nack_enabled_; bool nack_enabled_;
// Receiver Estimated Max Bitrate // Receiver Estimated Max Bitrate
bool remb_enabled_; bool remb_enabled_;
VideoOptions options_; VideoOptions options_;
// Global recv side state. // Global recv side state.
// Note the default channel (vie_channel_), i.e. the send channel // Note the default channel (default_channel_id_), i.e. the send channel
// corresponding to all the receive channels (this must be done for REMB to // corresponding to all the receive channels (this must be done for REMB to
// work properly), resides in both recv_channels_ and send_channels_ with the // work properly), resides in both recv_channels_ and send_channels_ with the
// ssrc key 0. // ssrc key kDefaultChannelSsrcKey.
RecvChannelMap recv_channels_; // Contains all receive channels. RecvChannelMap recv_channels_; // Contains all receive channels.
// A map from the SSRCs on which RTX packets are received to the media SSRCs // A map from the SSRCs on which RTX packets are received to the media SSRCs
// the RTX packets are associated with. RTX packets will be delivered to the // the RTX packets are associated with. RTX packets will be delivered to the