Stop and restart fix.

BUG=1398
TEST=Local stop and start test.

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3545 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2013-02-20 16:00:27 +00:00
parent eb7ebf20ed
commit 59b2d5fbce
3 changed files with 63 additions and 38 deletions

View File

@ -939,29 +939,30 @@ WebRtc_Word32 ModuleRtpRtcpImpl::SendOutgoingData(
std::list<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); std::list<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin();
if (it != child_modules_.end()) { if (it != child_modules_.end()) {
ret_val = (*it)->SendOutgoingData(frame_type, if ((*it)->SendingMedia()) {
payload_type, ret_val = (*it)->SendOutgoingData(frame_type,
time_stamp, payload_type,
capture_time_ms, time_stamp,
payload_data, capture_time_ms,
payload_size, payload_data,
fragmentation, payload_size,
rtp_video_hdr); fragmentation,
rtp_video_hdr);
}
it++; it++;
} }
// Send to all remaining "child" modules // Send to all remaining "child" modules
while (it != child_modules_.end()) { while (it != child_modules_.end()) {
ret_val = (*it)->SendOutgoingData(frame_type, if ((*it)->SendingMedia()) {
payload_type, ret_val = (*it)->SendOutgoingData(frame_type,
time_stamp, payload_type,
capture_time_ms, time_stamp,
payload_data, capture_time_ms,
payload_size, payload_data,
fragmentation, payload_size,
rtp_video_hdr); fragmentation,
rtp_video_hdr);
}
it++; it++;
} }
} }

View File

@ -225,6 +225,11 @@ ViEChannel::~ViEChannel() {
delete rtp_rtcp; delete rtp_rtcp;
simulcast_rtp_rtcp_.erase(it); simulcast_rtp_rtcp_.erase(it);
} }
while (removed_rtp_rtcp_.size() > 0) {
std::list<RtpRtcp*>::iterator it = removed_rtp_rtcp_.begin();
delete *it;
removed_rtp_rtcp_.erase(it);
}
if (decode_thread_) { if (decode_thread_) {
StopDecodeThread(); StopDecodeThread();
} }
@ -262,6 +267,11 @@ WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec,
if (rtp_rtcp_->Sending() && new_stream) { if (rtp_rtcp_->Sending() && new_stream) {
restart_rtp = true; restart_rtp = true;
rtp_rtcp_->SetSendingStatus(false); rtp_rtcp_->SetSendingStatus(false);
for (std::list<RtpRtcp*>::iterator it = simulcast_rtp_rtcp_.begin();
it != simulcast_rtp_rtcp_.end(); ++it) {
(*it)->SetSendingStatus(false);
(*it)->SetSendingMediaStatus(false);
}
} }
NACKMethod nack_method = rtp_rtcp_->NACK(); NACKMethod nack_method = rtp_rtcp_->NACK();
@ -275,10 +285,23 @@ WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec,
if (video_codec.numberOfSimulcastStreams > 0) { if (video_codec.numberOfSimulcastStreams > 0) {
// Set correct bitrate to base layer. // Set correct bitrate to base layer.
// Create our simulcast RTP modules. // Create our simulcast RTP modules.
int num_modules_to_add = video_codec.numberOfSimulcastStreams -
simulcast_rtp_rtcp_.size() - 1;
if (num_modules_to_add < 0) {
num_modules_to_add = 0;
}
for (int i = simulcast_rtp_rtcp_.size(); while (removed_rtp_rtcp_.size() > 0 && num_modules_to_add > 0) {
i < video_codec.numberOfSimulcastStreams - 1; RtpRtcp* rtp_rtcp = removed_rtp_rtcp_.front();
i++) { removed_rtp_rtcp_.pop_front();
simulcast_rtp_rtcp_.push_back(rtp_rtcp);
rtp_rtcp->SetSendingStatus(rtp_rtcp_->Sending());
rtp_rtcp->SetSendingMediaStatus(rtp_rtcp_->SendingMedia());
module_process_thread_.RegisterModule(rtp_rtcp);
--num_modules_to_add;
}
for (int i = 0; i < num_modules_to_add; ++i) {
RtpRtcp::Configuration configuration; RtpRtcp::Configuration configuration;
configuration.id = ViEModuleId(engine_id_, channel_id_); configuration.id = ViEModuleId(engine_id_, channel_id_);
configuration.audio = false; // Video. configuration.audio = false; // Video.
@ -311,15 +334,15 @@ WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec,
simulcast_rtp_rtcp_.push_back(rtp_rtcp); simulcast_rtp_rtcp_.push_back(rtp_rtcp);
} }
// Remove last in list if we have too many. // Remove last in list if we have too many.
std::list<RtpRtcp*> modules_to_delete;
for (int j = simulcast_rtp_rtcp_.size(); for (int j = simulcast_rtp_rtcp_.size();
j > (video_codec.numberOfSimulcastStreams - 1); j > (video_codec.numberOfSimulcastStreams - 1);
j--) { j--) {
RtpRtcp* rtp_rtcp = simulcast_rtp_rtcp_.back(); RtpRtcp* rtp_rtcp = simulcast_rtp_rtcp_.back();
module_process_thread_.DeRegisterModule(rtp_rtcp); module_process_thread_.DeRegisterModule(rtp_rtcp);
rtp_rtcp->SetSendingStatus(false);
rtp_rtcp->SetSendingMediaStatus(false);
simulcast_rtp_rtcp_.pop_back(); simulcast_rtp_rtcp_.pop_back();
// We need to deregister the module before deleting. removed_rtp_rtcp_.push_front(rtp_rtcp);
modules_to_delete.push_back(rtp_rtcp);
} }
WebRtc_UWord8 idx = 0; WebRtc_UWord8 idx = 0;
// Configure all simulcast modules. // Configure all simulcast modules.
@ -339,6 +362,7 @@ WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec,
} }
if (restart_rtp) { if (restart_rtp) {
rtp_rtcp->SetSendingStatus(true); rtp_rtcp->SetSendingStatus(true);
rtp_rtcp->SetSendingMediaStatus(true);
} }
if (send_timestamp_extension_id_ != kInvalidRtpExtensionId) { if (send_timestamp_extension_id_ != kInvalidRtpExtensionId) {
// Deregister in case the extension was previously enabled. // Deregister in case the extension was previously enabled.
@ -359,20 +383,14 @@ WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec,
// |RegisterSimulcastRtpRtcpModules| resets all old weak pointers and old // |RegisterSimulcastRtpRtcpModules| resets all old weak pointers and old
// modules can be deleted after this step. // modules can be deleted after this step.
vie_receiver_.RegisterSimulcastRtpRtcpModules(simulcast_rtp_rtcp_); vie_receiver_.RegisterSimulcastRtpRtcpModules(simulcast_rtp_rtcp_);
for (std::list<RtpRtcp*>::iterator it = modules_to_delete.begin();
it != modules_to_delete.end(); ++it) {
delete *it;
}
modules_to_delete.clear();
} else { } else {
if (!simulcast_rtp_rtcp_.empty()) { while (!simulcast_rtp_rtcp_.empty()) {
// Delete all simulcast rtp modules. RtpRtcp* rtp_rtcp = simulcast_rtp_rtcp_.back();
while (!simulcast_rtp_rtcp_.empty()) { module_process_thread_.DeRegisterModule(rtp_rtcp);
RtpRtcp* rtp_rtcp = simulcast_rtp_rtcp_.back(); rtp_rtcp->SetSendingStatus(false);
module_process_thread_.DeRegisterModule(rtp_rtcp); rtp_rtcp->SetSendingMediaStatus(false);
delete rtp_rtcp; simulcast_rtp_rtcp_.pop_back();
simulcast_rtp_rtcp_.pop_back(); removed_rtp_rtcp_.push_front(rtp_rtcp);
}
} }
// Clear any previous modules. // Clear any previous modules.
vie_receiver_.RegisterSimulcastRtpRtcpModules(simulcast_rtp_rtcp_); vie_receiver_.RegisterSimulcastRtpRtcpModules(simulcast_rtp_rtcp_);
@ -400,6 +418,11 @@ WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec,
} }
if (restart_rtp) { if (restart_rtp) {
rtp_rtcp_->SetSendingStatus(true); rtp_rtcp_->SetSendingStatus(true);
for (std::list<RtpRtcp*>::iterator it = simulcast_rtp_rtcp_.begin();
it != simulcast_rtp_rtcp_.end(); ++it) {
(*it)->SetSendingStatus(true);
(*it)->SetSendingMediaStatus(true);
}
} }
return 0; return 0;
} }

View File

@ -383,6 +383,7 @@ class ViEChannel
// Owned modules/classes. // Owned modules/classes.
scoped_ptr<RtpRtcp> rtp_rtcp_; scoped_ptr<RtpRtcp> rtp_rtcp_;
std::list<RtpRtcp*> simulcast_rtp_rtcp_; std::list<RtpRtcp*> simulcast_rtp_rtcp_;
std::list<RtpRtcp*> removed_rtp_rtcp_;
#ifndef WEBRTC_EXTERNAL_TRANSPORT #ifndef WEBRTC_EXTERNAL_TRANSPORT
UdpTransport& socket_transport_; UdpTransport& socket_transport_;
#endif #endif