Move those calls that may fail out of the ctor to Init function.

BUG=
TEST=

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2003 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
wu@webrtc.org 2012-04-10 16:54:05 +00:00
parent 91ed80e5c3
commit 5d8c102899
3 changed files with 65 additions and 23 deletions

View File

@ -92,7 +92,8 @@ int ViEChannelManager::CreateChannel(int& channel_id) {
ViEEncoder* vie_encoder = new ViEEncoder(engine_id_, new_channel_id, ViEEncoder* vie_encoder = new ViEEncoder(engine_id_, new_channel_id,
number_of_cores_, number_of_cores_,
*module_process_thread_); *module_process_thread_);
if (!CreateChannelObject(new_channel_id, vie_encoder)) { if (!(vie_encoder->Init() &&
CreateChannelObject(new_channel_id, vie_encoder))) {
delete vie_encoder; delete vie_encoder;
vie_encoder = NULL; vie_encoder = NULL;
ReturnChannelId(new_channel_id); ReturnChannelId(new_channel_id);
@ -126,7 +127,8 @@ int ViEChannelManager::CreateChannel(int& channel_id,
// We need to create a new ViEEncoder. // We need to create a new ViEEncoder.
vie_encoder = new ViEEncoder(engine_id_, new_channel_id, number_of_cores_, vie_encoder = new ViEEncoder(engine_id_, new_channel_id, number_of_cores_,
*module_process_thread_); *module_process_thread_);
if (!CreateChannelObject(new_channel_id, vie_encoder)) { if (!(vie_encoder->Init() &&
CreateChannelObject(new_channel_id, vie_encoder))) {
delete vie_encoder; delete vie_encoder;
vie_encoder = NULL; vie_encoder = NULL;
} }

View File

@ -87,44 +87,79 @@ ViEEncoder::ViEEncoder(WebRtc_Word32 engine_id, WebRtc_Word32 channel_id,
for (int i = 0; i < kMaxSimulcastStreams; i++) { for (int i = 0; i < kMaxSimulcastStreams; i++) {
time_last_intra_request_ms_[i] = 0; time_last_intra_request_ms_[i] = 0;
} }
// TODO(wu): Split out those may fail into an Init function. }
vcm_.InitializeSender();
bool ViEEncoder::Init() {
if (vcm_.InitializeSender() != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s InitializeSender failure", __FUNCTION__);
return false;
}
vpm_.EnableTemporalDecimation(true); vpm_.EnableTemporalDecimation(true);
// Enable/disable content analysis: off by default for now. // Enable/disable content analysis: off by default for now.
vpm_.EnableContentAnalysis(false); vpm_.EnableContentAnalysis(false);
module_process_thread_.RegisterModule(&vcm_); if (module_process_thread_.RegisterModule(&vcm_) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s RegisterModule failure", __FUNCTION__);
return false;
}
if (default_rtp_rtcp_.InitSender() != 0) { if (default_rtp_rtcp_.InitSender() != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), ViEId(engine_id_, channel_id_),
"ViEEncoder: RTP::InitSender failure"); "%s InitSender failure", __FUNCTION__);
assert(false); return false;
}
if (default_rtp_rtcp_.RegisterIncomingVideoCallback(this) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s RegisterIncomingVideoCallback failure", __FUNCTION__);
return false;
}
if (default_rtp_rtcp_.RegisterIncomingRTCPCallback(this) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s RegisterIncomingRTCPCallback failure", __FUNCTION__);
return false;
}
if (module_process_thread_.RegisterModule(&default_rtp_rtcp_) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s RegisterModule failure", __FUNCTION__);
return false;
} }
default_rtp_rtcp_.RegisterIncomingVideoCallback(this);
default_rtp_rtcp_.RegisterIncomingRTCPCallback(this);
module_process_thread_.RegisterModule(&default_rtp_rtcp_);
qm_callback_ = new QMVideoSettingsCallback( qm_callback_ = new QMVideoSettingsCallback(
engine_id_, engine_id_,
channel_id_, channel_id_,
&vpm_, &vpm_,
&vcm_, &vcm_,
number_of_cores, number_of_cores_,
default_rtp_rtcp_.MaxDataPayloadLength()); default_rtp_rtcp_.MaxDataPayloadLength());
#ifdef VIDEOCODEC_VP8 #ifdef VIDEOCODEC_VP8
VideoCodec video_codec; VideoCodec video_codec;
if (vcm_.Codec(webrtc::kVideoCodecVP8, &video_codec) == VCM_OK) { if (vcm_.Codec(webrtc::kVideoCodecVP8, &video_codec) != VCM_OK) {
if (vcm_.RegisterSendCodec(&video_codec, number_of_cores_, WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
default_rtp_rtcp_.MaxDataPayloadLength()) != 0) { ViEId(engine_id_, channel_id_),
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, "%s Codec failure", __FUNCTION__);
ViEId(engine_id_, channel_id_), return false;
"ViEEncoder: VCM::RegisterSendCodec failure"); }
} if (vcm_.RegisterSendCodec(&video_codec, number_of_cores_,
default_rtp_rtcp_.RegisterSendPayload(video_codec); default_rtp_rtcp_.MaxDataPayloadLength()) != 0) {
} else { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
assert(false); ViEId(engine_id_, channel_id_),
"%s RegisterSendCodec failure", __FUNCTION__);
return false;
}
if (default_rtp_rtcp_.RegisterSendPayload(video_codec) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_),
"%s RegisterSendPayload failure", __FUNCTION__);
return false;
} }
#else #else
VideoCodec video_codec; VideoCodec video_codec;
@ -133,7 +168,7 @@ ViEEncoder::ViEEncoder(WebRtc_Word32 engine_id, WebRtc_Word32 channel_id,
default_rtp_rtcp_.MaxDataPayloadLength()); default_rtp_rtcp_.MaxDataPayloadLength());
default_rtp_rtcp_.RegisterSendPayload(video_codec); default_rtp_rtcp_.RegisterSendPayload(video_codec);
} else { } else {
assert(false); return false;
} }
#endif #endif
@ -141,18 +176,21 @@ ViEEncoder::ViEEncoder(WebRtc_Word32 engine_id, WebRtc_Word32 channel_id,
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), ViEId(engine_id_, channel_id_),
"ViEEncoder: VCM::RegisterTransportCallback failure"); "ViEEncoder: VCM::RegisterTransportCallback failure");
return false;
} }
if (vcm_.RegisterSendStatisticsCallback(this) != 0) { if (vcm_.RegisterSendStatisticsCallback(this) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), ViEId(engine_id_, channel_id_),
"ViEEncoder: VCM::RegisterSendStatisticsCallback failure"); "ViEEncoder: VCM::RegisterSendStatisticsCallback failure");
return false;
} }
if (vcm_.RegisterVideoQMCallback(qm_callback_) != 0) { if (vcm_.RegisterVideoQMCallback(qm_callback_) != 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), ViEId(engine_id_, channel_id_),
"VCM::RegisterQMCallback failure"); "VCM::RegisterQMCallback failure");
return false;
} }
return true;
} }
ViEEncoder::~ViEEncoder() { ViEEncoder::~ViEEncoder() {

View File

@ -45,6 +45,8 @@ class ViEEncoder
ProcessThread& module_process_thread); ProcessThread& module_process_thread);
~ViEEncoder(); ~ViEEncoder();
bool Init();
// Returns the id of the owning channel. // Returns the id of the owning channel.
int Owner() const; int Owner() const;