Reverse Merged r2884 & r2888 from trunk.

Review URL: https://webrtc-codereview.appspot.com/929005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2988 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
vikasmarwaha@webrtc.org 2012-10-24 22:35:52 +00:00
parent 746721b12d
commit 8239ca5096
11 changed files with 34 additions and 171 deletions

View File

@ -64,16 +64,13 @@ bool EncoderStateFeedback::AddEncoder(uint32_t ssrc, ViEEncoder* encoder) {
return true;
}
void EncoderStateFeedback::RemoveEncoder(const ViEEncoder* encoder) {
void EncoderStateFeedback::RemoveEncoder(uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
SsrcEncoderMap::iterator it = encoders_.begin();
while (it != encoders_.end()) {
if (it->second == encoder) {
encoders_.erase(it++);
} else {
++it;
}
}
SsrcEncoderMap::iterator it = encoders_.find(ssrc);
if (it == encoders_.end())
return;
encoders_.erase(it);
}
RtcpIntraFrameObserver* EncoderStateFeedback::GetRtcpIntraFrameObserver() {
@ -115,10 +112,8 @@ void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc,
return;
}
ViEEncoder* encoder = it->second;
encoders_[new_ssrc] = it->second;
encoders_.erase(it);
encoders_[new_ssrc] = encoder;
encoder->OnLocalSsrcChanged(old_ssrc, new_ssrc);
}
} // namespace webrtc

View File

@ -38,7 +38,7 @@ class EncoderStateFeedback {
bool AddEncoder(uint32_t ssrc, ViEEncoder* encoder);
// Removes a registered ViEEncoder.
void RemoveEncoder(const ViEEncoder* encoder);
void RemoveEncoder(uint32_t ssrc);
// Returns an observer to register at the requesting class. The observer has
// the same lifetime as the EncoderStateFeedback instance.

View File

@ -81,7 +81,7 @@ TEST_F(VieKeyRequestTest, CreateAndTriggerRequests) {
encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedRPSI(
ssrc, rpsi_picture_id);
encoder_state_feedback_->RemoveEncoder(&encoder);
encoder_state_feedback_->RemoveEncoder(ssrc);
}
// Register multiple encoders and make sure the request is relayed to correct
@ -125,12 +125,12 @@ TEST_F(VieKeyRequestTest, MultipleEncoders) {
encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedRPSI(
ssrc_2, rpsi_pid_2);
encoder_state_feedback_->RemoveEncoder(&encoder_1);
encoder_state_feedback_->RemoveEncoder(ssrc_1);
EXPECT_CALL(encoder_2, OnReceivedIntraFrameRequest(ssrc_2))
.Times(1);
encoder_state_feedback_->GetRtcpIntraFrameObserver()->
OnReceivedIntraFrameRequest(ssrc_2);
encoder_state_feedback_->RemoveEncoder(&encoder_2);
encoder_state_feedback_->RemoveEncoder(ssrc_2);
}
TEST_F(VieKeyRequestTest, AddTwiceError) {
@ -138,7 +138,7 @@ TEST_F(VieKeyRequestTest, AddTwiceError) {
MockVieEncoder encoder(process_thread_.get());
EXPECT_TRUE(encoder_state_feedback_->AddEncoder(ssrc, &encoder));
EXPECT_FALSE(encoder_state_feedback_->AddEncoder(ssrc, &encoder));
encoder_state_feedback_->RemoveEncoder(&encoder);
encoder_state_feedback_->RemoveEncoder(ssrc);
}
} // namespace webrtc

View File

@ -805,26 +805,10 @@ WebRtc_Word32 ViEChannel::SetRemoteSSRCType(const StreamType usage,
return rtp_rtcp_->SetRTXReceiveStatus(true, SSRC);
}
// TODO(mflodman) Add kViEStreamTypeRtx.
WebRtc_Word32 ViEChannel::GetLocalSSRC(uint8_t idx, unsigned int* ssrc) {
WebRtc_Word32 ViEChannel::GetLocalSSRC(uint32_t* ssrc) {
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_),
"%s", __FUNCTION__);
if (idx == 0) {
*ssrc = rtp_rtcp_->SSRC();
return 0;
}
CriticalSectionScoped cs(rtp_rtcp_cs_.get());
if (idx > simulcast_rtp_rtcp_.size()) {
return -1;
}
std::list<RtpRtcp*>::const_iterator it = simulcast_rtp_rtcp_.begin();
for (int i = 1; i < idx; ++i, ++it) {
if (it == simulcast_rtp_rtcp_.end()) {
return -1;
}
}
*ssrc = (*it)->SSRC();
*ssrc = rtp_rtcp_->SSRC();
return 0;
}

View File

@ -118,8 +118,8 @@ class ViEChannel
const StreamType usage,
const unsigned char simulcast_idx);
// Gets SSRC for outgoing stream number |idx|.
WebRtc_Word32 GetLocalSSRC(uint8_t idx, unsigned int* ssrc);
// Gets SSRC for outgoing stream.
WebRtc_Word32 GetLocalSSRC(uint32_t* ssrc);
// Gets SSRC for the incoming stream.
WebRtc_Word32 GetRemoteSSRC(uint32_t* ssrc);

View File

@ -121,12 +121,8 @@ int ViEChannelManager::CreateChannel(int* channel_id) {
// Add ViEEncoder to EncoderFeedBackObserver.
unsigned int ssrc = 0;
int idx = 0;
channel_map_[new_channel_id]->GetLocalSSRC(idx, &ssrc);
channel_map_[new_channel_id]->GetLocalSSRC(&ssrc);
encoder_state_feedback->AddEncoder(ssrc, vie_encoder);
std::list<unsigned int> ssrcs;
ssrcs.push_back(ssrc);
vie_encoder->SetSsrcs(ssrcs);
*channel_id = new_channel_id;
group->AddChannel(*channel_id);
@ -174,8 +170,7 @@ int ViEChannelManager::CreateChannel(int* channel_id,
}
// Register the ViEEncoder to get key frame requests for this channel.
unsigned int ssrc = 0;
int stream_idx = 0;
channel_map_[new_channel_id]->GetLocalSSRC(stream_idx, &ssrc);
channel_map_[new_channel_id]->GetLocalSSRC(&ssrc);
encoder_state_feedback->AddEncoder(ssrc, vie_encoder);
} else {
vie_encoder = ViEEncoderPtr(original_channel);
@ -229,12 +224,14 @@ int ViEChannelManager::DeleteChannel(int channel_id) {
group = FindGroup(channel_id);
group->SetChannelRembStatus(channel_id, false, false, vie_channel,
vie_encoder);
group->GetEncoderStateFeedback()->RemoveEncoder(vie_encoder);
unsigned int remote_ssrc = 0;
vie_channel->GetRemoteSSRC(&remote_ssrc);
group->RemoveChannel(channel_id, remote_ssrc);
unsigned int local_ssrc = 0;
vie_channel->GetLocalSSRC(&local_ssrc);
group->GetEncoderStateFeedback()->RemoveEncoder(local_ssrc);
// Check if other channels are using the same encoder.
if (ChannelUsingViEEncoder(channel_id)) {
vie_encoder = NULL;
@ -373,24 +370,6 @@ bool ViEChannelManager::SetBandwidthEstimationMode(
return true;
}
void ViEChannelManager::UpdateSsrcs(int channel_id,
const std::list<unsigned int>& ssrcs) {
CriticalSectionScoped cs(channel_id_critsect_);
ChannelGroup* channel_group = FindGroup(channel_id);
if (channel_group == NULL) {
return;
}
ViEEncoder* encoder = ViEEncoderPtr(channel_id);
assert(encoder);
EncoderStateFeedback* encoder_state_feedback =
channel_group->GetEncoderStateFeedback();
for (std::list<unsigned int>::const_iterator it = ssrcs.begin();
it != ssrcs.end(); ++it) {
encoder_state_feedback->AddEncoder(*it, encoder);
}
}
bool ViEChannelManager::CreateChannelObject(
int channel_id,
ViEEncoder* vie_encoder,

View File

@ -79,10 +79,6 @@ class ViEChannelManager: private ViEManagerBase {
// adding a channel.
bool SetBandwidthEstimationMode(BandwidthEstimationMode mode);
// Updates the SSRCs for a channel. If one of the SSRCs already is registered,
// it will simply be ignored and no error is returned.
void UpdateSsrcs(int channel_id, const std::list<unsigned int>& ssrcs);
private:
// Creates a channel object connected to |vie_encoder|. Assumed to be called
// protected.

View File

@ -10,8 +10,6 @@
#include "video_engine/vie_codec_impl.h"
#include <list>
#include "engine_configurations.h" // NOLINT
#include "modules/video_coding/main/interface/video_coding.h"
#include "system_wrappers/interface/trace.h"
@ -240,32 +238,6 @@ int ViECodecImpl::SetSendCodec(const int video_channel,
}
}
// TODO(mflodman) Break out this part in GetLocalSsrcListi().
// Update all SSRCs to ViEEncoder.
std::list<unsigned int> ssrcs;
if (video_codec_internal.numberOfSimulcastStreams == 0) {
unsigned int ssrc = 0;
if (vie_channel->GetLocalSSRC(0, &ssrc) != 0) {
WEBRTC_TRACE(kTraceError, kTraceVideo,
ViEId(shared_data_->instance_id(), video_channel),
"%s: Could not get ssrc", __FUNCTION__);
}
ssrcs.push_back(ssrc);
} else {
for (int idx = 0; idx < video_codec_internal.numberOfSimulcastStreams;
++idx) {
unsigned int ssrc = 0;
if (vie_channel->GetLocalSSRC(idx, &ssrc) != 0) {
WEBRTC_TRACE(kTraceError, kTraceVideo,
ViEId(shared_data_->instance_id(), video_channel),
"%s: Could not get ssrc for idx %d", __FUNCTION__, idx);
}
ssrcs.push_back(ssrc);
}
}
vie_encoder->SetSsrcs(ssrcs);
shared_data_->channel_manager()->UpdateSsrcs(video_channel, ssrcs);
// Update the protection mode, we might be switching NACK/FEC.
vie_encoder->UpdateProtectionMethod();

View File

@ -73,6 +73,7 @@ ViEEncoder::ViEEncoder(WebRtc_Word32 engine_id,
data_cs_(CriticalSectionWrapper::CreateCriticalSection()),
bitrate_controller_(bitrate_controller),
paused_(false),
time_last_intra_request_ms_(0),
channels_dropping_delta_frames_(0),
drop_next_frame_(false),
fec_enabled_(false),
@ -811,79 +812,23 @@ void ViEEncoder::OnReceivedRPSI(uint32_t /*ssrc*/,
has_received_rpsi_ = true;
}
void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) {
void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t /*ssrc*/) {
// Key frame request from remote side, signal to VCM.
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), "%s", __FUNCTION__);
int idx = 0;
{
CriticalSectionScoped cs(data_cs_.get());
std::map<unsigned int, int>::iterator stream_it = ssrc_streams_.find(ssrc);
if (stream_it == ssrc_streams_.end()) {
assert(false);
return;
}
std::map<unsigned int, WebRtc_Word64>::iterator time_it =
time_last_intra_request_ms_.find(ssrc);
if (time_it == time_last_intra_request_ms_.end()) {
time_last_intra_request_ms_[ssrc] = 0;
}
WebRtc_Word64 now = TickTime::MillisecondTimestamp();
if (time_last_intra_request_ms_[ssrc] + kViEMinKeyRequestIntervalMs > now) {
WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s: Not encoding new intra due to timing", __FUNCTION__);
return;
}
time_last_intra_request_ms_[ssrc] = now;
idx = stream_it->second;
WebRtc_Word64 now = TickTime::MillisecondTimestamp();
if (time_last_intra_request_ms_ + kViEMinKeyRequestIntervalMs > now) {
WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s: Not not encoding new intra due to timing", __FUNCTION__);
return;
}
// Release the critsect before triggering key frame.
vcm_.IntraFrameRequest(idx);
vcm_.IntraFrameRequest(0);
time_last_intra_request_ms_ = now;
}
void ViEEncoder::OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) {
CriticalSectionScoped cs(data_cs_.get());
std::map<unsigned int, int>::iterator it = ssrc_streams_.find(old_ssrc);
if (it == ssrc_streams_.end()) {
return;
}
ssrc_streams_[new_ssrc] = it->second;
ssrc_streams_.erase(it);
std::map<unsigned int, int64_t>::iterator time_it =
time_last_intra_request_ms_.find(old_ssrc);
int64_t last_intra_request_ms = 0;
if (time_it != time_last_intra_request_ms_.end()) {
last_intra_request_ms = time_it->second;
time_last_intra_request_ms_.erase(time_it);
}
time_last_intra_request_ms_[new_ssrc] = last_intra_request_ms;
}
bool ViEEncoder::SetSsrcs(const std::list<unsigned int>& ssrcs) {
VideoCodec codec;
if (vcm_.SendCodec(&codec) != 0)
return false;
if (codec.numberOfSimulcastStreams > 0 &&
ssrcs.size() != codec.numberOfSimulcastStreams) {
return false;
}
CriticalSectionScoped cs(data_cs_.get());
ssrc_streams_.clear();
time_last_intra_request_ms_.clear();
int idx = 0;
for (std::list<unsigned int>::const_iterator it = ssrcs.begin();
it != ssrcs.end(); ++it, ++idx) {
unsigned int ssrc = *it;
ssrc_streams_[ssrc] = idx;
}
return true;
}
// Called from ViEBitrateObserver.

View File

@ -11,9 +11,6 @@
#ifndef WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_
#define WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_
#include <list>
#include <map>
#include "common_types.h" // NOLINT
#include "typedefs.h" //NOLINT
#include "modules/bitrate_controller/include/bitrate_controller.h"
@ -137,9 +134,6 @@ class ViEEncoder
virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id);
virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc);
// Sets SSRCs for all streams.
bool SetSsrcs(const std::list<unsigned int>& ssrcs);
// Effect filter.
WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter);
@ -173,7 +167,7 @@ class ViEEncoder
BitrateController* bitrate_controller_;
bool paused_;
std::map<unsigned int, int64_t> time_last_intra_request_ms_;
WebRtc_Word64 time_last_intra_request_ms_;
WebRtc_Word32 channels_dropping_delta_frames_;
bool drop_next_frame_;
@ -188,7 +182,6 @@ class ViEEncoder
WebRtc_UWord8 picture_id_sli_;
bool has_received_rpsi_;
WebRtc_UWord64 picture_id_rpsi_;
std::map<unsigned int, int> ssrc_streams_;
ViEFileRecorder file_recorder_;

View File

@ -183,8 +183,7 @@ int ViERTP_RTCPImpl::GetLocalSSRC(const int video_channel,
shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
return -1;
}
uint8_t idx = 0;
if (vie_channel->GetLocalSSRC(idx, &SSRC) != 0) {
if (vie_channel->GetLocalSSRC(&SSRC) != 0) {
shared_data_->SetLastError(kViERtpRtcpUnknownError);
return -1;
}