From 03c06505fb7f928501a787580a4a7416d7af31ee Mon Sep 17 00:00:00 2001 From: "mflodman@webrtc.org" Date: Thu, 15 Dec 2011 15:23:08 +0000 Subject: [PATCH] Refactored ViEChannel. Pointers/references and types will be in a future CL. Review URL: http://webrtc-codereview.appspot.com/322016 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1205 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/video_engine/vie_channel.cc | 5268 ++++++++++++------------------- src/video_engine/vie_channel.h | 801 +++-- 2 files changed, 2419 insertions(+), 3650 deletions(-) diff --git a/src/video_engine/vie_channel.cc b/src/video_engine/vie_channel.cc index b7208df15..6668c2b8f 100644 --- a/src/video_engine/vie_channel.cc +++ b/src/video_engine/vie_channel.cc @@ -8,3618 +8,2482 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * ViEChannel.cpp - */ +#include "video_engine/vie_channel.h" -#include "vie_channel.h" -#include "vie_defines.h" -#include "critical_section_wrapper.h" -#include "rtp_rtcp.h" -#include "udp_transport.h" -#include "video_coding.h" -#include "video_processing.h" -#include "video_render_defines.h" -#ifdef WEBRTC_SRTP -#include "SrtpModule.h" -#endif -#include "process_thread.h" -#include "trace.h" -#include "thread_wrapper.h" -#include "vie_codec.h" -#include "vie_errors.h" -#include "vie_image_process.h" -#include "vie_rtp_rtcp.h" -#include "vie_receiver.h" -#include "vie_sender.h" -#include "vie_sync_module.h" +#include -namespace webrtc -{ -// ---------------------------------------------------------------------------- -// Constructor -// ---------------------------------------------------------------------------- +#include "modules/rtp_rtcp/interface/rtp_rtcp.h" +#include "modules/udp_transport/interface/udp_transport.h" +#include "modules/utility/interface/process_thread.h" +#include "modules/video_coding/main/interface/video_coding.h" +#include "modules/video_processing/main/interface/video_processing.h" +#include "modules/video_render/main/interface/video_render_defines.h" +#include "system_wrappers/interface/critical_section_wrapper.h" +#include "system_wrappers/interface/thread_wrapper.h" +#include "system_wrappers/interface/trace.h" +#include "video_engine/main/interface/vie_codec.h" +#include "video_engine/main/interface/vie_errors.h" +#include "video_engine/main/interface/vie_image_process.h" +#include "video_engine/main/interface/vie_rtp_rtcp.h" +#include "video_engine/vie_defines.h" +#include "video_engine/vie_receiver.h" +#include "video_engine/vie_sender.h" +#include "video_engine/vie_sync_module.h" -ViEChannel::ViEChannel(WebRtc_Word32 channelId, WebRtc_Word32 engineId, - WebRtc_UWord32 numberOfCores, - ProcessThread& moduleProcessThread) : - ViEFrameProviderBase(channelId, engineId), - _channelId(channelId), - _engineId(engineId), - _numberOfCores(numberOfCores), - _numSocketThreads(kViESocketThreads), - _callbackCritsect(*CriticalSectionWrapper::CreateCriticalSection()), - _rtpRtcp(*RtpRtcp::CreateRtpRtcp( - ViEModuleId(engineId, channelId), false)), +namespace webrtc { + +const int kMaxDecodeWaitTimeMs = 50; + +ViEChannel::ViEChannel(WebRtc_Word32 channel_id, + WebRtc_Word32 engine_id, + WebRtc_UWord32 number_of_cores, + ProcessThread& module_process_thread) + : ViEFrameProviderBase(channel_id, engine_id), + channel_id_(channel_id), + engine_id_(engine_id), + number_of_cores_(number_of_cores), + num_socket_threads_(kViESocketThreads), + callbackCritsect_(*CriticalSectionWrapper::CreateCriticalSection()), + rtp_rtcp_(*RtpRtcp::CreateRtpRtcp(ViEModuleId(engine_id, channel_id), + false)), #ifndef WEBRTC_EXTERNAL_TRANSPORT - _socketTransport( - *UdpTransport::Create( - ViEModuleId(engineId, channelId), _numSocketThreads)), + socket_transport_(*UdpTransport::Create( + ViEModuleId(engine_id, channel_id), num_socket_threads_)), #endif - _vcm(*VideoCodingModule::Create( - ViEModuleId(engineId, channelId))), - - _vieReceiver(*(new ViEReceiver(engineId, channelId, _rtpRtcp, _vcm))), - _vieSender(*(new ViESender(engineId, channelId))), - _vieSync(*(new ViESyncModule(ViEId(engineId, channelId), _vcm, - _rtpRtcp))), - _moduleProcessThread(moduleProcessThread), - _codecObserver(NULL), - _doKeyFrameCallbackRequest(false), - _rtpObserver(NULL), - _rtcpObserver(NULL), - _networkObserver(NULL), - _rtpPacketTimeout(false), - _usingPacketSpread(false), - _ptrExternalTransport(NULL), - _decoderReset(true), - _waitForKeyFrame(false), - _ptrDecodeThread(NULL), - _ptrSrtpModuleEncryption(NULL), - _ptrSrtpModuleDecryption(NULL), - _ptrExternalEncryption(NULL), - _effectFilter(NULL), - _colorEnhancement(true), - _vcmRTTReported(TickTime::Now()), - _fileRecorder(channelId) -{ - WEBRTC_TRACE( - webrtc::kTraceMemory, webrtc::kTraceVideo, ViEId(engineId, channelId), - "ViEChannel::ViEChannel(channelId: %d, engineId: %d) - Constructor", - channelId, engineId); + vcm_(*VideoCodingModule::Create(ViEModuleId(engine_id, channel_id))), + vie_receiver_(*(new ViEReceiver(engine_id, channel_id, rtp_rtcp_, vcm_))), + vie_sender_(*(new ViESender(engine_id, channel_id))), + vie_sync_(*(new ViESyncModule(ViEId(engine_id, channel_id), vcm_, + rtp_rtcp_))), + module_process_thread_(module_process_thread), + codec_observer_(NULL), + do_key_frame_callbackRequest_(false), + rtp_observer_(NULL), + rtcp_observer_(NULL), + networkObserver_(NULL), + rtp_packet_timeout_(false), + using_packet_spread_(false), + external_transport_(NULL), + decoder_reset_(true), + wait_for_key_frame_(false), + decode_thread_(NULL), + external_encryption_(NULL), + effect_filter_(NULL), + color_enhancement_(true), + vcm_rttreported_(TickTime::Now()), + file_recorder_(channel_id) { + WEBRTC_TRACE(kTraceMemory, kTraceVideo, ViEId(engine_id, channel_id), + "ViEChannel::ViEChannel(channel_id: %d, engine_id: %d)", + channel_id, engine_id); } -WebRtc_Word32 ViEChannel::Init() -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: channelId: %d, engineId: %d)", __FUNCTION__, _channelId, - _engineId); - // RTP/RTCP initialization - if (_rtpRtcp.InitSender() != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: RTP::InitSender failure", - __FUNCTION__); - return -1; - } - if (_rtpRtcp.SetSendingMediaStatus(false) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::SetSendingMediaStatus failure", __FUNCTION__); - return -1; - } - if (_rtpRtcp.InitReceiver() != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::InitReceiver failure", __FUNCTION__); - return -1; - } - if (_rtpRtcp.RegisterIncomingDataCallback((RtpData*) &_vieReceiver) - != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterIncomingDataCallback failure", - __FUNCTION__); - return -1; - } - if (_rtpRtcp.RegisterSendTransport((Transport*) &_vieSender) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterSendTransport failure", __FUNCTION__); - return -1; - } - if (_moduleProcessThread.RegisterModule(&_rtpRtcp) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterModule failure", __FUNCTION__); - return -1; - } - if (_rtpRtcp.SetKeyFrameRequestMethod(kKeyFrameReqFirRtp) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId,_channelId), - "%s: RTP::SetKeyFrameRequestMethod failure", __FUNCTION__); - } - if (_rtpRtcp.SetRTCPStatus(kRtcpCompound) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::SetRTCPStatus failure", __FUNCTION__); - } - if (_rtpRtcp.RegisterIncomingRTPCallback(this) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterIncomingRTPCallback failure", - __FUNCTION__); - return -1; - } - if (_rtpRtcp.RegisterIncomingRTCPCallback(this) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterIncomingRTCPCallback failure", - __FUNCTION__); - return -1; - } +WebRtc_Word32 ViEChannel::Init() { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: channel_id: %d, engine_id: %d)", __FUNCTION__, channel_id_, + engine_id_); + // RTP/RTCP initialization. + if (rtp_rtcp_.InitSender() != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::InitSender failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.SetSendingMediaStatus(false) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::SetSendingMediaStatus failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.InitReceiver() != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::InitReceiver failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.RegisterIncomingDataCallback( + static_cast(&vie_receiver_)) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterIncomingDataCallback failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.RegisterSendTransport( + static_cast(&vie_sender_)) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterSendTransport failure", __FUNCTION__); + return -1; + } + if (module_process_thread_.RegisterModule(&rtp_rtcp_) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterModule failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.SetKeyFrameRequestMethod(kKeyFrameReqFirRtp) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::SetKeyFrameRequestMethod failure", __FUNCTION__); + } + if (rtp_rtcp_.SetRTCPStatus(kRtcpCompound) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::SetRTCPStatus failure", __FUNCTION__); + } + if (rtp_rtcp_.RegisterIncomingRTPCallback(this) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterIncomingRTPCallback failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.RegisterIncomingRTCPCallback(this) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterIncomingRTCPCallback failure", __FUNCTION__); + return -1; + } - // VCM initialization - if (_vcm.InitializeReceiver() != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM::InitializeReceiver failure", __FUNCTION__); - return -1; - } - if (_vcm.RegisterReceiveCallback(this) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM::RegisterReceiveCallback failure", __FUNCTION__); - return -1; - } - if (_vcm.RegisterFrameTypeCallback(this) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM::RegisterFrameTypeCallback failure", __FUNCTION__); - } - if (_vcm.RegisterReceiveStatisticsCallback(this) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM::RegisterReceiveStatisticsCallback failure", - __FUNCTION__); - } - if (_vcm.SetRenderDelay(kViEDefaultRenderDelayMs) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM::SetRenderDelay failure", __FUNCTION__); - } - if (_moduleProcessThread.RegisterModule(&_vcm) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM::RegisterModule(vcm) failure", __FUNCTION__); - return -1; - } + // VCM initialization + if (vcm_.InitializeReceiver() != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, + ViEId(engine_id_, channel_id_), + "%s: VCM::InitializeReceiver failure", __FUNCTION__); + return -1; + } + if (vcm_.RegisterReceiveCallback(this) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: VCM::RegisterReceiveCallback failure", __FUNCTION__); + return -1; + } + if (vcm_.RegisterFrameTypeCallback(this) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: VCM::RegisterFrameTypeCallback failure", __FUNCTION__); + } + if (vcm_.RegisterReceiveStatisticsCallback(this) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: VCM::RegisterReceiveStatisticsCallback failure", + __FUNCTION__); + } + if (vcm_.SetRenderDelay(kViEDefaultRenderDelayMs) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: VCM::SetRenderDelay failure", __FUNCTION__); + } + if (module_process_thread_.RegisterModule(&vcm_) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: VCM::RegisterModule(vcm) failure", __FUNCTION__); + return -1; + } #ifdef VIDEOCODEC_VP8 - VideoCodec videoCodec; - if (_vcm.Codec(kVideoCodecVP8, &videoCodec) == VCM_OK) - { - _rtpRtcp.RegisterSendPayload(videoCodec); - _rtpRtcp.RegisterReceivePayload(videoCodec); - _vcm.RegisterReceiveCodec(&videoCodec, _numberOfCores); - _vcm.RegisterSendCodec(&videoCodec, _numberOfCores, - _rtpRtcp.MaxDataPayloadLength()); - } - else - { - assert(false); - } + VideoCodec video_codec; + if (vcm_.Codec(kVideoCodecVP8, &video_codec) == VCM_OK) { + rtp_rtcp_.RegisterSendPayload(video_codec); + rtp_rtcp_.RegisterReceivePayload(video_codec); + vcm_.RegisterReceiveCodec(&video_codec, number_of_cores_); + vcm_.RegisterSendCodec(&video_codec, number_of_cores_, + rtp_rtcp_.MaxDataPayloadLength()); + } else { + assert(false); + } #endif - return 0; + return 0; } -// ---------------------------------------------------------------------------- -// Destructor -// ---------------------------------------------------------------------------- +ViEChannel::~ViEChannel() { + WEBRTC_TRACE(kTraceMemory, kTraceVideo, ViEId(engine_id_, channel_id_), + "ViEChannel Destructor, channel_id: %d, engine_id: %d", + channel_id_, engine_id_); -ViEChannel::~ViEChannel() -{ - WEBRTC_TRACE(webrtc::kTraceMemory, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "ViEChannel Destructor, channelId: %d, engineId: %d", - _channelId, _engineId); - - // Make sure we don't get more callbacks from the RTP module. - _rtpRtcp.RegisterIncomingRTPCallback(NULL); - _rtpRtcp.RegisterSendTransport(NULL); + // Make sure we don't get more callbacks from the RTP module. + rtp_rtcp_.RegisterIncomingRTPCallback(NULL); + rtp_rtcp_.RegisterSendTransport(NULL); #ifndef WEBRTC_EXTERNAL_TRANSPORT - _socketTransport.StopReceiving(); + socket_transport_.StopReceiving(); #endif - _moduleProcessThread.DeRegisterModule(&_rtpRtcp); - _moduleProcessThread.DeRegisterModule(&_vcm); - _moduleProcessThread.DeRegisterModule(&_vieSync); - while (_simulcastRtpRtcp.size() > 0) - { - std::list::iterator it = _simulcastRtpRtcp.begin(); - RtpRtcp* rtpRtcp = *it; - rtpRtcp->RegisterIncomingRTCPCallback(NULL); - rtpRtcp->RegisterSendTransport(NULL); - _moduleProcessThread.DeRegisterModule(rtpRtcp); - RtpRtcp::DestroyRtpRtcp(rtpRtcp); - _simulcastRtpRtcp.erase(it); - } - if (_ptrDecodeThread) - { - StopDecodeThread(); - } + module_process_thread_.DeRegisterModule(&rtp_rtcp_); + module_process_thread_.DeRegisterModule(&vcm_); + module_process_thread_.DeRegisterModule(&vie_sync_); + while (simulcast_rtp_rtcp_.size() > 0) { + std::list::iterator it = simulcast_rtp_rtcp_.begin(); + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->RegisterIncomingRTCPCallback(NULL); + rtp_rtcp->RegisterSendTransport(NULL); + module_process_thread_.DeRegisterModule(rtp_rtcp); + RtpRtcp::DestroyRtpRtcp(rtp_rtcp); + simulcast_rtp_rtcp_.erase(it); + } + if (decode_thread_) { + StopDecodeThread(); + } - delete &_vieReceiver; - delete &_vieSender; - delete &_vieSync; + delete &vie_receiver_; + delete &vie_sender_; + delete &vie_sync_; - delete &_callbackCritsect; + delete &callbackCritsect_; - // Release modules - RtpRtcp::DestroyRtpRtcp(&_rtpRtcp); + // Release modules. + RtpRtcp::DestroyRtpRtcp(&rtp_rtcp_); #ifndef WEBRTC_EXTERNAL_TRANSPORT - UdpTransport::Destroy(&_socketTransport); + UdpTransport::Destroy(&socket_transport_); #endif - VideoCodingModule::Destroy(&_vcm); + VideoCodingModule::Destroy(&vcm_); } -// ============================================================================ -// Codec -// ============================================================================ +WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& video_codec, + bool new_stream) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: codec_type: %d", __FUNCTION__, video_codec.codecType); -// ---------------------------------------------------------------------------- -// SetSendCodec -// -// videoCodec: encoder settings -// newStream: the encoder type has changed and we should start a new RTP stream -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetSendCodec(const VideoCodec& videoCodec, - bool newStream) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: codecType: %d", - __FUNCTION__, - videoCodec.codecType); - - if (videoCodec.codecType == kVideoCodecRED || - videoCodec.codecType == kVideoCodecULPFEC) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: codecType: %d is not a valid send codec.", - __FUNCTION__, videoCodec.codecType); + if (video_codec.codecType == kVideoCodecRED || + video_codec.codecType == kVideoCodecULPFEC) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: codec_type: %d is not a valid send codec.", __FUNCTION__, + video_codec.codecType); + return -1; + } + if (kMaxSimulcastStreams < video_codec.numberOfSimulcastStreams) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Too many simulcast streams", __FUNCTION__); + return -1; + } + // Update the RTP module with the settings. + // Stop and Start the RTP module -> trigger new SSRC, if an SSRC hasn't been + // set explicitly. + bool restart_rtp = false; + if (rtp_rtcp_.Sending() && new_stream) { + restart_rtp = true; + rtp_rtcp_.SetSendingStatus(false); + } + if (video_codec.numberOfSimulcastStreams > 0) { + WebRtc_UWord32 start_bitrate = video_codec.startBitrate * 1000; + WebRtc_UWord32 stream_bitrate = + std::min(start_bitrate, video_codec.simulcastStream[0].maxBitrate); + start_bitrate -= stream_bitrate; + // Set correct bitrate to base layer. + if (rtp_rtcp_.SetSendBitrate( + stream_bitrate, video_codec.minBitrate, + video_codec.simulcastStream[0].maxBitrate) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not set send bitrates", __FUNCTION__); + return -1; + } + // Create our simulcast RTP modules. + for (int i = simulcast_rtp_rtcp_.size(); + i < video_codec.numberOfSimulcastStreams - 1; + i++) { + RtpRtcp* rtp_rtcp = RtpRtcp::CreateRtpRtcp( + ViEModuleId(engine_id_, channel_id_), false); + if (rtp_rtcp->RegisterDefaultModule(default_rtp_rtcp_)) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not register default module", __FUNCTION__); return -1; + } + simulcast_rtp_rtcp_.push_back(rtp_rtcp); } - if (kMaxSimulcastStreams < videoCodec.numberOfSimulcastStreams) - { - WEBRTC_TRACE(webrtc::kTraceError, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Too many simulcast streams", - __FUNCTION__); + // Remove last in list if we have too many. + for (int j = simulcast_rtp_rtcp_.size(); + j > (video_codec.numberOfSimulcastStreams - 1); + j--) { + RtpRtcp* rtp_rtcp = simulcast_rtp_rtcp_.back(); + rtp_rtcp->RegisterIncomingRTCPCallback(NULL); + rtp_rtcp->RegisterSendTransport(NULL); + module_process_thread_.DeRegisterModule(rtp_rtcp); + RtpRtcp::DestroyRtpRtcp(rtp_rtcp); + simulcast_rtp_rtcp_.pop_back(); + } + VideoCodec video_codec; + if (vcm_.Codec(kVideoCodecVP8, &video_codec) != VCM_OK) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: VCM: failure geting default VP8 pl_type", __FUNCTION__); + return -1; + } + WebRtc_UWord8 idx = 0; + // Configure all simulcast modules. + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + idx++; + RtpRtcp* rtp_rtcp = *it; + if (rtp_rtcp->InitSender() != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::InitSender failure", __FUNCTION__); return -1; - } - // Update the RTP module with the settigns - // Stop and Start the RTP module -> trigger new SSRC - bool restartRtp = false; - if (_rtpRtcp.Sending() && newStream) - { - restartRtp = true; - _rtpRtcp.SetSendingStatus(false); - } - if (videoCodec.numberOfSimulcastStreams > 0) - { - WebRtc_UWord32 startBitrate = videoCodec.startBitrate * 1000; - WebRtc_UWord32 streamBitrate = std::min(startBitrate, - videoCodec.simulcastStream[0].maxBitrate); - startBitrate -= streamBitrate; - // set correct bitrate to base layer - if (_rtpRtcp.SetSendBitrate( - streamBitrate, - videoCodec.minBitrate, - videoCodec.simulcastStream[0].maxBitrate) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not set send bitrates", - __FUNCTION__); - return -1; - } - // Create our simulcast RTP modules - for (int i = _simulcastRtpRtcp.size(); - i < videoCodec.numberOfSimulcastStreams - 1; - i++) - { - RtpRtcp* rtpRtcp = RtpRtcp::CreateRtpRtcp( - ViEModuleId(_engineId, _channelId), - false); - if (rtpRtcp->RegisterDefaultModule(_defaultRtpRtcp)) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not register default module", - __FUNCTION__); - return -1; - } - _simulcastRtpRtcp.push_back(rtpRtcp); - } - // Remove last in list if we have too many - for (int j = _simulcastRtpRtcp.size(); - j > (videoCodec.numberOfSimulcastStreams - 1); - j--) - { - RtpRtcp* rtpRtcp = _simulcastRtpRtcp.back(); - rtpRtcp->RegisterIncomingRTCPCallback(NULL); - rtpRtcp->RegisterSendTransport(NULL); - _moduleProcessThread.DeRegisterModule(rtpRtcp); - RtpRtcp::DestroyRtpRtcp(rtpRtcp); - _simulcastRtpRtcp.pop_back(); - } - VideoCodec videoCodec; - if (_vcm.Codec(kVideoCodecVP8, &videoCodec) != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceWarning, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: VCM: failure geting default VP8 plType", - __FUNCTION__); - return -1; - } - WebRtc_UWord8 idx = 0; - // Configure all simulcast modules - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - idx++; - RtpRtcp* rtpRtcp = *it; - if (rtpRtcp->InitSender() != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::InitSender failure", - __FUNCTION__); - return -1; - } - if (rtpRtcp->InitReceiver() != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::InitReceiver failure", - __FUNCTION__); - return -1; - } - if (rtpRtcp->RegisterSendTransport((Transport*) &_vieSender) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterSendTransport failure", - __FUNCTION__); - return -1; - } - if (_moduleProcessThread.RegisterModule(rtpRtcp) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::RegisterModule failure", __FUNCTION__); - return -1; - } - if (rtpRtcp->SetRTCPStatus(_rtpRtcp.RTCP()) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP::SetRTCPStatus failure", __FUNCTION__); - } - rtpRtcp->DeRegisterSendPayload(videoCodec.plType); - if (rtpRtcp->RegisterSendPayload(videoCodec) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not register payload type", - __FUNCTION__); - return -1; - } - if (restartRtp) - { - rtpRtcp->SetSendingStatus(true); - } - // Configure all simulcast streams min and max bitrates - const WebRtc_UWord32 streamBitrate = std::min(startBitrate, - videoCodec.simulcastStream[idx].maxBitrate); - startBitrate -= streamBitrate; - if (rtpRtcp->SetSendBitrate( - streamBitrate, - videoCodec.minBitrate, - videoCodec.simulcastStream[idx].maxBitrate) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not set send bitrates", - __FUNCTION__); - return -1; - } - } - _vieReceiver.RegisterSimulcastRtpRtcpModules(_simulcastRtpRtcp); - } else - { - if (!_simulcastRtpRtcp.empty()) - { - // delete all simulcast rtp modules - while (!_simulcastRtpRtcp.empty()) - { - RtpRtcp* rtpRtcp = _simulcastRtpRtcp.back(); - rtpRtcp->RegisterIncomingRTCPCallback(NULL); - rtpRtcp->RegisterSendTransport(NULL); - _moduleProcessThread.DeRegisterModule(rtpRtcp); - RtpRtcp::DestroyRtpRtcp(rtpRtcp); - _simulcastRtpRtcp.pop_back(); - } - } - // Clear any previus modules - _vieReceiver.RegisterSimulcastRtpRtcpModules(_simulcastRtpRtcp); - - if (_rtpRtcp.SetSendBitrate(videoCodec.startBitrate * 1000, - videoCodec.minBitrate, - videoCodec.maxBitrate) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not set send bitrates", __FUNCTION__); - return -1; - } - } - /* TODO Enable this if H264 is available. - * This sets the wanted packetization mode. - if(videoCodec.plType==kVideoCodecH264) - { - if (videoCodec.codecSpecific.H264.packetization == kH264SingleMode) - { - _rtpRtcp.SetH264PacketizationMode (H264_SINGLE_NAL_MODE); - } - else - { - _rtpRtcp.SetH264PacketizationMode(H264_NON_INTERLEAVED_MODE); - } - if (videoCodec.codecSpecific.H264.configParametersSize > 0) - { - _rtpRtcp.SetH264SendModeNALU_PPS_SPS(true); - } - }*/ - - // Don't log this error, no way to check in advance if this plType is - // registered or not... - _rtpRtcp.DeRegisterSendPayload(videoCodec.plType); - if (_rtpRtcp.RegisterSendPayload(videoCodec) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not register payload type", __FUNCTION__); + } + if (rtp_rtcp->InitReceiver() != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::InitReceiver failure", __FUNCTION__); return -1; + } + if (rtp_rtcp->RegisterSendTransport( + static_cast(&vie_sender_)) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterSendTransport failure", __FUNCTION__); + return -1; + } + if (module_process_thread_.RegisterModule(rtp_rtcp) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::RegisterModule failure", __FUNCTION__); + return -1; + } + if (rtp_rtcp->SetRTCPStatus(rtp_rtcp_.RTCP()) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP::SetRTCPStatus failure", __FUNCTION__); + } + rtp_rtcp->DeRegisterSendPayload(video_codec.plType); + if (rtp_rtcp->RegisterSendPayload(video_codec) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not register payload type", __FUNCTION__); + return -1; + } + if (restart_rtp) { + rtp_rtcp->SetSendingStatus(true); + } + // Configure all simulcast streams min and max bitrates + const WebRtc_UWord32 stream_bitrate = + std::min(start_bitrate, video_codec.simulcastStream[idx].maxBitrate); + start_bitrate -= stream_bitrate; + if (rtp_rtcp->SetSendBitrate( + stream_bitrate, video_codec.minBitrate, + video_codec.simulcastStream[idx].maxBitrate) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not set send bitrates", __FUNCTION__); + return -1; + } } - if (restartRtp) - { - _rtpRtcp.SetSendingStatus(true); + vie_receiver_.RegisterSimulcastRtpRtcpModules(simulcast_rtp_rtcp_); + } else { + if (!simulcast_rtp_rtcp_.empty()) { + // Delete all simulcast rtp modules. + while (!simulcast_rtp_rtcp_.empty()) { + RtpRtcp* rtp_rtcp = simulcast_rtp_rtcp_.back(); + rtp_rtcp->RegisterIncomingRTCPCallback(NULL); + rtp_rtcp->RegisterSendTransport(NULL); + module_process_thread_.DeRegisterModule(rtp_rtcp); + RtpRtcp::DestroyRtpRtcp(rtp_rtcp); + simulcast_rtp_rtcp_.pop_back(); + } } - return 0; + // Clear any previous modules. + vie_receiver_.RegisterSimulcastRtpRtcpModules(simulcast_rtp_rtcp_); + + if (rtp_rtcp_.SetSendBitrate(video_codec.startBitrate * 1000, + video_codec.minBitrate, + video_codec.maxBitrate) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not set send bitrates", __FUNCTION__); + return -1; + } + } + // Enable this if H264 is available. + // This sets the wanted packetization mode. + // if (video_codec.plType == kVideoCodecH264) { + // if (video_codec.codecSpecific.H264.packetization == kH264SingleMode) { + // rtp_rtcp_.SetH264PacketizationMode(H264_SINGLE_NAL_MODE); + // } else { + // rtp_rtcp_.SetH264PacketizationMode(H264_NON_INTERLEAVED_MODE); + // } + // if (video_codec.codecSpecific.H264.configParametersSize > 0) { + // rtp_rtcp_.SetH264SendModeNALU_PPS_SPS(true); + // } + // } + + // Don't log this error, no way to check in advance if this pl_type is + // registered or not... + rtp_rtcp_.DeRegisterSendPayload(video_codec.plType); + if (rtp_rtcp_.RegisterSendPayload(video_codec) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not register payload type", __FUNCTION__); + return -1; + } + if (restart_rtp) { + rtp_rtcp_.SetSendingStatus(true); + } + return 0; } -// ---------------------------------------------------------------------------- -// SetReceiveCodec -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetReceiveCodec(const VideoCodec& videoCodec) -{ - // We will not receive simulcast streams so no need to hadle that usecase - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::SetReceiveCodec(const VideoCodec& video_codec) { + // We will not receive simulcast streams, so no need to handle that use case. + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - WebRtc_Word8 old_pltype = -1; - if (_rtpRtcp.ReceivePayloadType(videoCodec, &old_pltype) != -1) - { - _rtpRtcp.DeRegisterReceivePayload(old_pltype); - } + WebRtc_Word8 old_pltype = -1; + if (rtp_rtcp_.ReceivePayloadType(video_codec, &old_pltype) != -1) { + rtp_rtcp_.DeRegisterReceivePayload(old_pltype); + } - if (_rtpRtcp.RegisterReceivePayload(videoCodec) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not register receive payload type", __FUNCTION__); - return -1; - } + if (rtp_rtcp_.RegisterReceivePayload(video_codec) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not register receive payload type", __FUNCTION__); + return -1; + } - if (videoCodec.codecType != kVideoCodecRED && - videoCodec.codecType != kVideoCodecULPFEC) - { //Register codec type with VCM. But do not register RED or ULPFEC - if (_vcm.RegisterReceiveCodec(&videoCodec, _numberOfCores, - _waitForKeyFrame) != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not register decoder", __FUNCTION__); - return -1; - } + if (video_codec.codecType != kVideoCodecRED && + video_codec.codecType != kVideoCodecULPFEC) { + // Register codec type with VCM, but do not register RED or ULPFEC. + if (vcm_.RegisterReceiveCodec(&video_codec, number_of_cores_, + wait_for_key_frame_) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not register decoder", __FUNCTION__); + return -1; } - return 0; + } + return 0; } -// ---------------------------------------------------------------------------- -// GetReceiveCodec -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetReceiveCodec(VideoCodec& videoCodec) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::GetReceiveCodec(VideoCodec& video_codec) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - if (_vcm.ReceiveCodec(&videoCodec) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get receive codec", __FUNCTION__); - return -1; - } - return 0; + if (vcm_.ReceiveCodec(&video_codec) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get receive codec", __FUNCTION__); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// RegisterCodecObserver -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::RegisterCodecObserver(ViEDecoderObserver* observer) -{ - CriticalSectionScoped cs(_callbackCritsect); - if (observer) - { - if (_codecObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: already added", - __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer added", __FUNCTION__); - _codecObserver = observer; +WebRtc_Word32 ViEChannel::RegisterCodecObserver(ViEDecoderObserver* observer) { + CriticalSectionScoped cs(callbackCritsect_); + if (observer) { + if (codec_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: already added", __FUNCTION__); + return -1; } - else - { - if (!_codecObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: no observer added", - __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer removed", __FUNCTION__); - _codecObserver = NULL; + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer added", __FUNCTION__); + codec_observer_ = observer; + } else { + if (!codec_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no observer added", __FUNCTION__); + return -1; } - return 0; + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer removed", __FUNCTION__); + codec_observer_ = NULL; + } + return 0; } -// ---------------------------------------------------------------------------- -// RegisterExternalDecoder -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::RegisterExternalDecoder( - const WebRtc_UWord8 plType, VideoDecoder* decoder, - bool decoderRender, //Decoder also render - WebRtc_Word32 renderDelay) // Decode and render delay -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::RegisterExternalDecoder(const WebRtc_UWord8 pl_type, + VideoDecoder* decoder, + bool decoder_render, + WebRtc_Word32 render_delay) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - WebRtc_Word32 result = 0; - result = _vcm.RegisterExternalDecoder(decoder, plType, decoderRender); - if (decoderRender && result == 0) - { - // Let VCM know how long before the actual render time the decoder needs - // to get a frame for decoding. - result = _vcm.SetRenderDelay(renderDelay); - } - return result; + WebRtc_Word32 result = 0; + result = vcm_.RegisterExternalDecoder(decoder, pl_type, decoder_render); + if (decoder_render && result == 0) { + // Let VCM know how long before the actual render time the decoder needs + // to get a frame for decoding. + result = vcm_.SetRenderDelay(render_delay); + } + return result; } -// ---------------------------------------------------------------------------- -// DeRegisterExternalDecoder -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::DeRegisterExternalDecoder( + const WebRtc_UWord8 pl_type) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s pl_type", __FUNCTION__, pl_type); -WebRtc_Word32 ViEChannel::DeRegisterExternalDecoder(const WebRtc_UWord8 plType) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s plType", __FUNCTION__, plType); + VideoCodec current_receive_codec; + WebRtc_Word32 result = 0; + result = vcm_.ReceiveCodec(¤t_receive_codec); + if (vcm_.RegisterExternalDecoder(NULL, pl_type, false) != VCM_OK) { + return -1; + } - VideoCodec currentReceiveCodec; - WebRtc_Word32 result = 0; - result = _vcm.ReceiveCodec(¤tReceiveCodec); - if (_vcm.RegisterExternalDecoder(NULL, plType, false) != VCM_OK) - { - return -1; - } - - if (result == 0 && currentReceiveCodec.plType == plType) - { - result = _vcm.RegisterReceiveCodec(¤tReceiveCodec, - _numberOfCores, _waitForKeyFrame); - } - - return result; + if (result == 0 && current_receive_codec.plType == pl_type) { + result = vcm_.RegisterReceiveCodec(¤t_receive_codec, number_of_cores_, + wait_for_key_frame_); + } + return result; } -// ---------------------------------------------------------------------------- -// ReceiveCodecStatistics -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::ReceiveCodecStatistics(WebRtc_UWord32& numKeyFrames, - WebRtc_UWord32& numDeltaFrames) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::ReceiveCodecStatistics( + WebRtc_UWord32& num_key_frames, WebRtc_UWord32& num_delta_frames) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - VCMFrameCount receivedFrames; - if (_vcm.ReceivedFrameCount(receivedFrames) != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get received frame information", __FUNCTION__); - return -1; - } - numKeyFrames = receivedFrames.numKeyFrames; - numDeltaFrames = receivedFrames.numDeltaFrames; - return 0; + VCMFrameCount received_frames; + if (vcm_.ReceivedFrameCount(received_frames) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get received frame information", __FUNCTION__); + return -1; + } + num_key_frames = received_frames.numKeyFrames; + num_delta_frames = received_frames.numDeltaFrames; + return 0; } WebRtc_UWord32 ViEChannel::DiscardedPackets() const { - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - return _vcm.DiscardedPackets(); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + return vcm_.DiscardedPackets(); } -// ---------------------------------------------------------------------------- -// WaitForKeyFrame -// -// Only affects calls to SetReceiveCodec done after this call. -// Default = false -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::WaitForKeyFrame(bool wait) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::WaitForKeyFrame(bool wait) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s(wait: %d)", __FUNCTION__, wait); - - _waitForKeyFrame = wait; - return 0; + wait_for_key_frame_ = wait; + return 0; } -// ---------------------------------------------------------------------------- -// SetSignalPacketLossStatus -// -// If enabled, a key frame request will be sent as soon as there are lost -// packets. If onlyKeyFrames are set, requests are only sent for loss in key -// frames. -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetSignalPacketLossStatus(bool enable, - bool onlyKeyFrames) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + bool only_key_frames) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s(enable: %d)", __FUNCTION__, enable); + if (enable) { + if (only_key_frames) { + vcm_.SetVideoProtection(kProtectionKeyOnLoss, false); + if (vcm_.SetVideoProtection(kProtectionKeyOnKeyLoss, true) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s failed %d", __FUNCTION__, enable); + return -1; + } + } else { + vcm_.SetVideoProtection(kProtectionKeyOnKeyLoss, false); + if (vcm_.SetVideoProtection(kProtectionKeyOnLoss, true) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s failed %d", __FUNCTION__, enable); + return -1; + } + } + } else { + vcm_.SetVideoProtection(kProtectionKeyOnLoss, false); + vcm_.SetVideoProtection(kProtectionKeyOnKeyLoss, false); + } + return 0; +} + +WebRtc_Word32 ViEChannel::SetRTCPMode(const RTCPMethod rtcp_mode) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: %d", __FUNCTION__, rtcp_mode); + + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetRTCPStatus(rtcp_mode); + } + return rtp_rtcp_.SetRTCPStatus(rtcp_mode); +} + +WebRtc_Word32 ViEChannel::GetRTCPMode(RTCPMethod& rtcp_mode) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s", __FUNCTION__); + rtcp_mode = rtp_rtcp_.RTCP(); + return 0; +} + +WebRtc_Word32 ViEChannel::SetNACKStatus(const bool enable) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s(enable: %d)", __FUNCTION__, enable); - if (enable) - { - if (onlyKeyFrames) - { - _vcm.SetVideoProtection(kProtectionKeyOnLoss, false); - if (_vcm.SetVideoProtection(kProtectionKeyOnKeyLoss, true) - != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, - _channelId), - "%s failed %d", __FUNCTION__, enable); - return -1; - } - } - else - { - _vcm.SetVideoProtection(kProtectionKeyOnKeyLoss, false); - if (_vcm.SetVideoProtection(kProtectionKeyOnLoss, true) - != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, - _channelId), - "%s failed %d", __FUNCTION__, enable); - return -1; - } - } - } - else - { - _vcm.SetVideoProtection(kProtectionKeyOnLoss, false); - _vcm.SetVideoProtection(kProtectionKeyOnKeyLoss, false); - } - return 0; + // Update the decoding VCM. + if (vcm_.SetVideoProtection(kProtectionNack, enable) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not set VCM NACK protection: %d", __FUNCTION__, + enable); + return -1; + } + if (enable) { + // Disable possible FEC. + SetFECStatus(false, 0, 0); + } + // Update the decoding VCM. + if (vcm_.SetVideoProtection(kProtectionNack, enable) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not set VCM NACK protection: %d", __FUNCTION__, + enable); + return -1; + } + return ProcessNACKRequest(enable); } -// ============================================================================ -// RTP/RTCP -// ============================================================================ +WebRtc_Word32 ViEChannel::ProcessNACKRequest(const bool enable) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s(enable: %d)", __FUNCTION__, enable); -// ---------------------------------------------------------------------------- -// SetRTCPMode -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetRTCPMode(const RTCPMethod rtcpMode) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: %d", __FUNCTION__, rtcpMode); - - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetRTCPStatus(rtcpMode); + if (enable) { + // Turn on NACK. + NACKMethod nackMethod = kNackRtcp; + if (rtp_rtcp_.RTCP() == kRtcpOff) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not enable NACK, RTPC not on ", __FUNCTION__); + return -1; } - return _rtpRtcp.SetRTCPStatus(rtcpMode); + if (rtp_rtcp_.SetNACKStatus(nackMethod) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not set NACK method %d", __FUNCTION__, + nackMethod); + return -1; + } + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Using NACK method %d", __FUNCTION__, nackMethod); + rtp_rtcp_.SetStorePacketsStatus(true, kNackHistorySize); + + vcm_.RegisterPacketRequestCallback(this); + + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetStorePacketsStatus(true, kNackHistorySize); + } + } else { + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetStorePacketsStatus(false); + } + rtp_rtcp_.SetStorePacketsStatus(false); + vcm_.RegisterPacketRequestCallback(NULL); + if (rtp_rtcp_.SetNACKStatus(kNackOff) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not turn off NACK", __FUNCTION__); + return -1; + } + } + return 0; } -// ---------------------------------------------------------------------------- -// GetRTCPMode -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetRTCPMode(RTCPMethod& rtcpMode) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - rtcpMode = _rtpRtcp.RTCP(); - return 0; -} - -// ---------------------------------------------------------------------------- -// EnableNACKStatus -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetNACKStatus(const bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s(enable: %d)", __FUNCTION__, enable); - - // Update the decoding VCM - if (_vcm.SetVideoProtection(kProtectionNack, enable) != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not set VCM NACK protection: %d", __FUNCTION__, - enable); - return -1; - } - if (enable) - { - // Disable possible FEC - SetFECStatus(false, 0, 0); - } - // Update the decoding VCM - if (_vcm.SetVideoProtection(kProtectionNack, enable) != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not set VCM NACK protection: %d", __FUNCTION__, - enable); - return -1; - } - return ProcessNACKRequest(enable); -} - -WebRtc_Word32 ViEChannel::ProcessNACKRequest(const bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s(enable: %d)", __FUNCTION__, enable); - - if (enable) - { - // Turn on NACK, - NACKMethod nackMethod = kNackRtcp; - if (_rtpRtcp.RTCP() == kRtcpOff) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not enable NACK, RTPC not on ", __FUNCTION__); - return -1; - } - if (_rtpRtcp.SetNACKStatus(nackMethod) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not set NACK method %d", __FUNCTION__, - nackMethod); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Using NACK method %d", __FUNCTION__, nackMethod); - _rtpRtcp.SetStorePacketsStatus(true, kNackHistorySize); - - _vcm.RegisterPacketRequestCallback(this); - - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetStorePacketsStatus(true, kNackHistorySize); - } - } - else - { - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetStorePacketsStatus(false); - } - _rtpRtcp.SetStorePacketsStatus(false); - _vcm.RegisterPacketRequestCallback(NULL); - if (_rtpRtcp.SetNACKStatus(kNackOff) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not turn off NACK", __FUNCTION__); - return -1; - } - } - return 0; -} - -// ---------------------------------------------------------------------------- -// SetFECStatus -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetFECStatus(const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC) -{ - // Disable possible NACK - if (enable) - { - SetNACKStatus(false); - } + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC) { + // Disable possible NACK. + if (enable) { + SetNACKStatus(false); + } - return ProcessFECRequest(enable, payloadTypeRED, payloadTypeFEC); - -} -WebRtc_Word32 -ViEChannel::ProcessFECRequest(const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s(enable: %d, payloadTypeRED: %u, payloadTypeFEC: %u)", - __FUNCTION__, enable, payloadTypeRED, payloadTypeFEC); - - if (_rtpRtcp.SetGenericFECStatus(enable, payloadTypeRED, payloadTypeFEC) - != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not change FEC status to %d", __FUNCTION__, - enable); - return -1; - } - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetGenericFECStatus(enable, payloadTypeRED, payloadTypeFEC); - } - return 0; + return ProcessFECRequest(enable, payload_typeRED, payload_typeFEC); } -// ---------------------------------------------------------------------------- -// EnableNACKFECStatus -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::ProcessFECRequest( + const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s(enable: %d, payload_typeRED: %u, payload_typeFEC: %u)", + __FUNCTION__, enable, payload_typeRED, payload_typeFEC); -WebRtc_Word32 -ViEChannel::SetHybridNACKFECStatus(const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC) -{ - // Update the decoding VCM with hybrid mode - if (_vcm.SetVideoProtection(kProtectionNackFEC, enable) != VCM_OK) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not set VCM NACK protection: %d", __FUNCTION__, - enable); - return -1; - } - - WebRtc_Word32 retVal = 0; - retVal = ProcessNACKRequest(enable); - if (retVal < 0) - { - return retVal; - } - return ProcessFECRequest(enable, payloadTypeRED, payloadTypeFEC); + if (rtp_rtcp_.SetGenericFECStatus(enable, payload_typeRED, + payload_typeFEC) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not change FEC status to %d", __FUNCTION__, + enable); + return -1; + } + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetGenericFECStatus(enable, payload_typeRED, payload_typeFEC); + } + return 0; } -// ---------------------------------------------------------------------------- -// KeyFrameRequestMethod -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::SetHybridNACKFECStatus( + const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC) { + // Update the decoding VCM with hybrid mode. + if (vcm_.SetVideoProtection(kProtectionNackFEC, enable) != VCM_OK) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not set VCM NACK protection: %d", __FUNCTION__, + enable); + return -1; + } + + WebRtc_Word32 ret_val = 0; + ret_val = ProcessNACKRequest(enable); + if (ret_val < 0) { + return ret_val; + } + return ProcessFECRequest(enable, payload_typeRED, payload_typeFEC); +} WebRtc_Word32 ViEChannel::SetKeyFrameRequestMethod( - const KeyFrameRequestMethod method) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + const KeyFrameRequestMethod method) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: %d", __FUNCTION__, method); - - return _rtpRtcp.SetKeyFrameRequestMethod(method); + return rtp_rtcp_.SetKeyFrameRequestMethod(method); } -// ---------------------------------------------------------------------------- -// EnableTMMBR -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::EnableTMMBR(const bool enable) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: %d", __FUNCTION__, enable); + return rtp_rtcp_.SetTMMBRStatus(enable); +} -WebRtc_Word32 ViEChannel::EnableTMMBR(const bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::EnableKeyFrameRequestCallback(const bool enable) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: %d", __FUNCTION__, enable); - return _rtpRtcp.SetTMMBRStatus(enable); + CriticalSectionScoped cs(callbackCritsect_); + if (enable && !codec_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: No ViECodecObserver set", __FUNCTION__, enable); + return -1; + } + do_key_frame_callbackRequest_ = enable; + return 0; } -// ---------------------------------------------------------------------------- -// EnableKeyFrameRequestCallback -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::EnableKeyFrameRequestCallback(const bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: %d", __FUNCTION__, enable); - - CriticalSectionScoped cs(_callbackCritsect); - if (enable && _codecObserver == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: No ViECodecObserver set", __FUNCTION__, enable); - return -1; - } - _doKeyFrameCallbackRequest = enable; - return 0; - -} - -// ---------------------------------------------------------------------------- -// SetSSRC -// -// Sets SSRC for outgoing stream -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetSSRC(const WebRtc_UWord32 SSRC, const StreamType /*usage*/, - const unsigned char simulcastIdx) -{ - // TODO(pwestin) add support for streamType when we add RTX - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s(SSRC: %u, idx:%u)", - __FUNCTION__, SSRC, simulcastIdx); + const unsigned char simulcast_idx) { + // TODO(pwestin) add support for stream_type when we add RTX. + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s(SSRC: %u, idx:%u)", __FUNCTION__, SSRC, simulcast_idx); - if (simulcastIdx == 0) - { - return _rtpRtcp.SetSSRC(SSRC); + if (simulcast_idx == 0) { + return rtp_rtcp_.SetSSRC(SSRC); + } + std::list::const_iterator it = simulcast_rtp_rtcp_.begin(); + for (int i = 1; i < simulcast_idx; i++) { + it++; + if (it == simulcast_rtp_rtcp_.end()) { + return -1; } - std::list::const_iterator it = _simulcastRtpRtcp.begin(); - for (int i = 1; i < simulcastIdx; i++) - { - it++; - if (it == _simulcastRtpRtcp.end()) - { - return -1; - } - } - RtpRtcp* rtpRtcp = *it; - return rtpRtcp->SetSSRC(SSRC); + } + RtpRtcp* rtp_rtcp = *it; + return rtp_rtcp->SetSSRC(SSRC); } -// ---------------------------------------------------------------------------- -// SetSSRC -// -// Gets SSRC for outgoing stream -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetLocalSSRC(WebRtc_UWord32& SSRC) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::GetLocalSSRC(WebRtc_UWord32& SSRC) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - - SSRC = _rtpRtcp.SSRC(); - return 0; + SSRC = rtp_rtcp_.SSRC(); + return 0; } -// ---------------------------------------------------------------------------- -// GetRemoteSSRC -// -// Gets SSRC for the incoming stream -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::GetRemoteSSRC(WebRtc_UWord32& SSRC) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::GetRemoteSSRC(WebRtc_UWord32& SSRC) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + SSRC = rtp_rtcp_.RemoteSSRC(); + return 0; +} + +WebRtc_Word32 ViEChannel::GetRemoteCSRC(unsigned int CSRCs[kRtpCsrcSize]) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + + WebRtc_UWord32 arrayCSRC[kRtpCsrcSize]; + memset(arrayCSRC, 0, sizeof(arrayCSRC)); + + WebRtc_Word32 num_csrcs = rtp_rtcp_.RemoteCSRCs(arrayCSRC); + if (num_csrcs > 0) { + memcpy(CSRCs, arrayCSRC, num_csrcs * sizeof(WebRtc_UWord32)); + for (int idx = 0; idx < num_csrcs; idx++) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "\tCSRC[%d] = %lu", idx, CSRCs[idx]); + } + } else { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: CSRC list is empty", __FUNCTION__); + } + return 0; +} + +WebRtc_Word32 ViEChannel::SetStartSequenceNumber( + WebRtc_UWord16 sequence_number) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + + if (rtp_rtcp_.Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: already sending", __FUNCTION__); + return -1; + } + return rtp_rtcp_.SetSequenceNumber(sequence_number); +} + +WebRtc_Word32 ViEChannel::SetRTCPCName(const WebRtc_Word8 rtcp_cname[]) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - - SSRC = _rtpRtcp.RemoteSSRC(); - return 0; + if (rtp_rtcp_.Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: already sending", __FUNCTION__); + return -1; + } + return rtp_rtcp_.SetCNAME(rtcp_cname); } -// ---------------------------------------------------------------------------- -// GetRemoteCSRC -// -// Gets the CSRC for the incoming stream -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetRemoteCSRC(unsigned int CSRCs[kRtpCsrcSize]) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::GetRTCPCName(WebRtc_Word8 rtcp_cname[]) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - - WebRtc_UWord32 arrayCSRC[kRtpCsrcSize]; - memset(arrayCSRC, 0, sizeof(arrayCSRC)); - - WebRtc_Word32 numCSRCs = _rtpRtcp.RemoteCSRCs(arrayCSRC); - if (numCSRCs > 0) - { - memcpy(CSRCs, arrayCSRC, numCSRCs * sizeof(WebRtc_UWord32)); - for (int idx = 0; idx < numCSRCs; idx++) - { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "\tCSRC[%d] = %lu", idx, - CSRCs[idx]); - } - } - else - { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: CSRC list is empty", __FUNCTION__); - } - return 0; + return rtp_rtcp_.CNAME(rtcp_cname); } -// ---------------------------------------------------------------------------- -// SetStartSequenceNumber -// -// Sets the starting sequence number, must be called before StartSend. -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::GetRemoteRTCPCName(WebRtc_Word8 rtcp_cname[]) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::SetStartSequenceNumber(WebRtc_UWord16 sequenceNumber) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_rtpRtcp.Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: already sending", - __FUNCTION__); - return -1; - } - return _rtpRtcp.SetSequenceNumber(sequenceNumber); + WebRtc_UWord32 remoteSSRC = rtp_rtcp_.RemoteSSRC(); + return rtp_rtcp_.RemoteCNAME(remoteSSRC, rtcp_cname); } -// ---------------------------------------------------------------------------- -// SetRTCPCName -// -// Sets the CName for the outgoing stream on the channel -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetRTCPCName(const WebRtc_Word8 rtcpCName[]) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_rtpRtcp.Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: already sending", - __FUNCTION__); - return -1; +WebRtc_Word32 ViEChannel::RegisterRtpObserver(ViERTPObserver* observer) { + CriticalSectionScoped cs(callbackCritsect_); + if (observer) { + if (rtp_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer alread added", __FUNCTION__); + return -1; } - return _rtpRtcp.SetCNAME(rtcpCName); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer added", __FUNCTION__); + rtp_observer_ = observer; + } else { + if (!rtp_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no observer added", __FUNCTION__); + return -1; + } + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer removed", __FUNCTION__); + rtp_observer_ = NULL; + } + return 0; } -// ---------------------------------------------------------------------------- -// GetRTCPCName -// -// Gets the CName for the outgoing stream on the channel -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetRTCPCName(WebRtc_Word8 rtcpCName[]) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - return _rtpRtcp.CNAME(rtcpCName); -} - -// ---------------------------------------------------------------------------- -// GetRemoteRTCPCName -// -// Gets the CName of the incoming stream -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetRemoteRTCPCName(WebRtc_Word8 rtcpCName[]) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - WebRtc_UWord32 remoteSSRC = _rtpRtcp.RemoteSSRC(); - return _rtpRtcp.RemoteCNAME(remoteSSRC, rtcpCName); -} - -// ---------------------------------------------------------------------------- -// RegisterRtpObserver -// -// Registers an RTP observer -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::RegisterRtpObserver(ViERTPObserver* observer) -{ - CriticalSectionScoped cs(_callbackCritsect); - if (observer) - { - if (_rtpObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: observer alread added", __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer added", __FUNCTION__); - _rtpObserver = observer; +WebRtc_Word32 ViEChannel::RegisterRtcpObserver(ViERTCPObserver* observer) { + CriticalSectionScoped cs(callbackCritsect_); + if (observer) { + if (rtcp_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer alread added", __FUNCTION__); + return -1; } - else - { - if (!_rtpObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: no observer added", - __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer removed", __FUNCTION__); - _rtpObserver = NULL; + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer added", __FUNCTION__); + rtcp_observer_ = observer; + } else { + if (!rtcp_observer_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no observer added", __FUNCTION__); + return -1; } - return 0; + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer removed", __FUNCTION__); + rtcp_observer_ = NULL; + } + return 0; } -// ---------------------------------------------------------------------------- -// RegisterRtcpObserver -// -// Registers an RTPC observer -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::RegisterRtcpObserver(ViERTCPObserver* observer) -{ - CriticalSectionScoped cs(_callbackCritsect); - if (observer) - { - if (_rtcpObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: observer alread added", __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer added", __FUNCTION__); - _rtcpObserver = observer; - } - else - { - if (!_rtcpObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: no observer added", - __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer removed", __FUNCTION__); - _rtcpObserver = NULL; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// SendApplicationDefinedRTCPPacket -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SendApplicationDefinedRTCPPacket( - const WebRtc_UWord8 subType, WebRtc_UWord32 name, const WebRtc_UWord8* data, - WebRtc_UWord16 dataLengthInBytes) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - // Sanity checks - if (!_rtpRtcp.Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: not sending", - __FUNCTION__); - return -1; - } - if (data == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: no input argument", - __FUNCTION__); - return -1; - } - if (dataLengthInBytes % 4 != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: input length error", - __FUNCTION__); - return -1; - } - RTCPMethod rtcpMethod = _rtpRtcp.RTCP(); - if (rtcpMethod == kRtcpOff) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: RTCP not enabled", - __FUNCTION__); - return -1; - } - // Create and send packet - if (_rtpRtcp.SetRTCPApplicationSpecificData(subType, name, data, - dataLengthInBytes) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not send RTCP application data", __FUNCTION__); - return -1; - } - return 0; + const WebRtc_UWord8 sub_type, + WebRtc_UWord32 name, + const WebRtc_UWord8* data, + WebRtc_UWord16 data_length_in_bytes) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + if (!rtp_rtcp_.Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not sending", __FUNCTION__); + return -1; + } + if (!data) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no input argument", __FUNCTION__); + return -1; + } + if (data_length_in_bytes % 4 != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: input length error", __FUNCTION__); + return -1; + } + RTCPMethod rtcp_method = rtp_rtcp_.RTCP(); + if (rtcp_method == kRtcpOff) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTCP not enabled", __FUNCTION__); + return -1; + } + // Create and send packet. + if (rtp_rtcp_.SetRTCPApplicationSpecificData(sub_type, name, data, + data_length_in_bytes) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not send RTCP application data", __FUNCTION__); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// GetSendRtcpStatistics -// -// Gets statistics sent in RTCP packets to remote side -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::GetSendRtcpStatistics(WebRtc_UWord16& fraction_lost, + WebRtc_UWord32& cumulative_lost, + WebRtc_UWord32& extended_max, + WebRtc_UWord32& jitter_samples, + WebRtc_Word32& rtt_ms) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::GetSendRtcpStatistics(WebRtc_UWord16& fractionLost, - WebRtc_UWord32& cumulativeLost, - WebRtc_UWord32& extendedMax, - WebRtc_UWord32& jitterSamples, - WebRtc_Word32& rttMs) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); + // TODO(pwestin) how do we do this for simulcast ? average for all + // except cumulative_lost that is the sum ? + // for (std::list::const_iterator it = simulcast_rtp_rtcp_.begin(); + // it != simulcast_rtp_rtcp_.end(); + // it++) { + // RtpRtcp* rtp_rtcp = *it; + // } + WebRtc_UWord32 remoteSSRC = rtp_rtcp_.RemoteSSRC(); + RTCPReportBlock remote_stat; + if (rtp_rtcp_.RemoteRTCPStat(remoteSSRC, &remote_stat) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get remote stats", __FUNCTION__); + return -1; + } + fraction_lost = remote_stat.fractionLost; + cumulative_lost = remote_stat.cumulativeLost; + extended_max = remote_stat.extendedHighSeqNum; + jitter_samples = remote_stat.jitter; - /* - TODO(pwestin) how do we do this for simulcast? average for all - except cumulativeLost that is the sum? - for (std::list::const_iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - } - */ - WebRtc_UWord32 remoteSSRC = _rtpRtcp.RemoteSSRC(); - - RTCPReportBlock remoteStat; - if (_rtpRtcp.RemoteRTCPStat(remoteSSRC, &remoteStat) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get remote stats", __FUNCTION__); - return -1; - } - fractionLost = remoteStat.fractionLost; - cumulativeLost = remoteStat.cumulativeLost; - extendedMax = remoteStat.extendedHighSeqNum; - jitterSamples = remoteStat.jitter; - - WebRtc_UWord16 dummy; - WebRtc_UWord16 rtt = 0; - if (_rtpRtcp.RTT(remoteSSRC, &rtt, &dummy, &dummy, &dummy) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Could not get RTT", - __FUNCTION__); - return -1; - } - rttMs = rtt; - return 0; + WebRtc_UWord16 dummy; + WebRtc_UWord16 rtt = 0; + if (rtp_rtcp_.RTT(remoteSSRC, &rtt, &dummy, &dummy, &dummy) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get RTT", __FUNCTION__); + return -1; + } + rtt_ms = rtt; + return 0; } -// ---------------------------------------------------------------------------- -// GetSendRtcpStatistics -// -// Gets statistics received in RTCP packets from remote side -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::GetReceivedRtcpStatistics( - WebRtc_UWord16& fractionLost, WebRtc_UWord32& cumulativeLost, - WebRtc_UWord32& extendedMax, WebRtc_UWord32& jitterSamples, - WebRtc_Word32& rttMs) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + WebRtc_UWord16& fraction_lost, + WebRtc_UWord32& cumulative_lost, + WebRtc_UWord32& extended_max, + WebRtc_UWord32& jitter_samples, + WebRtc_Word32& rtt_ms) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - WebRtc_UWord8 fracLost = 0; - if (_rtpRtcp.StatisticsRTP(&fracLost, &cumulativeLost, &extendedMax, - &jitterSamples) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get received RTP statistics", __FUNCTION__); - return -1; - } - fractionLost = fracLost; + WebRtc_UWord8 frac_lost = 0; + if (rtp_rtcp_.StatisticsRTP(&frac_lost, &cumulative_lost, &extended_max, + &jitter_samples) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get received RTP statistics", __FUNCTION__); + return -1; + } + fraction_lost = frac_lost; - WebRtc_UWord32 remoteSSRC = _rtpRtcp.RemoteSSRC(); - WebRtc_UWord16 dummy = 0; - WebRtc_UWord16 rtt = 0; - if (_rtpRtcp.RTT(remoteSSRC, &rtt, &dummy, &dummy, &dummy) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Could not get RTT", - __FUNCTION__); - return -1; - } - rttMs = rtt; - return 0; + WebRtc_UWord32 remoteSSRC = rtp_rtcp_.RemoteSSRC(); + WebRtc_UWord16 dummy = 0; + WebRtc_UWord16 rtt = 0; + if (rtp_rtcp_.RTT(remoteSSRC, &rtt, &dummy, &dummy, &dummy) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get RTT", __FUNCTION__); + return -1; + } + rtt_ms = rtt; + return 0; } -// ---------------------------------------------------------------------------- -// GetRtpStatistics -// -// Gets sent/received packets statistics -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::GetRtpStatistics( - WebRtc_UWord32& bytesSent, - WebRtc_UWord32& packetsSent, - WebRtc_UWord32& bytesReceived, - WebRtc_UWord32& packetsReceived) const -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); + WebRtc_UWord32& bytes_sent, + WebRtc_UWord32& packets_sent, + WebRtc_UWord32& bytes_received, + WebRtc_UWord32& packets_received) const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); - if (_rtpRtcp.DataCountersRTP(&bytesSent, - &packetsSent, - &bytesReceived, - &packetsReceived) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get counters", __FUNCTION__); - return -1; - } - for (std::list::const_iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - WebRtc_UWord32 bytesSentTemp = 0; - WebRtc_UWord32 packetsSentTemp = 0; - RtpRtcp* rtpRtcp = *it; - rtpRtcp->DataCountersRTP(&bytesSentTemp, &packetsSentTemp, NULL, NULL); - bytesSent += bytesSentTemp; - packetsSent += packetsSentTemp; - } - return 0; + if (rtp_rtcp_.DataCountersRTP(&bytes_sent, + &packets_sent, + &bytes_received, + &packets_received) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get counters", __FUNCTION__); + return -1; + } + for (std::list::const_iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + WebRtc_UWord32 bytes_sent_temp = 0; + WebRtc_UWord32 packets_sent_temp = 0; + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->DataCountersRTP(&bytes_sent_temp, &packets_sent_temp, NULL, NULL); + bytes_sent += bytes_sent_temp; + packets_sent += packets_sent_temp; + } + return 0; } -void ViEChannel::GetBandwidthUsage(WebRtc_UWord32& totalBitrateSent, - WebRtc_UWord32& videoBitrateSent, - WebRtc_UWord32& fecBitrateSent, +void ViEChannel::GetBandwidthUsage(WebRtc_UWord32& total_bitrate_sent, + WebRtc_UWord32& video_bitrate_sent, + WebRtc_UWord32& fec_bitrate_sent, WebRtc_UWord32& nackBitrateSent) const { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); - _rtpRtcp.BitrateSent(&totalBitrateSent, - &videoBitrateSent, - &fecBitrateSent, - &nackBitrateSent); - for (std::list::const_iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); it++) { - WebRtc_UWord32 streamRate = 0; - WebRtc_UWord32 videoRate = 0; - WebRtc_UWord32 fecRate = 0; + rtp_rtcp_.BitrateSent(&total_bitrate_sent, + &video_bitrate_sent, + &fec_bitrate_sent, + &nackBitrateSent); + for (std::list::const_iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); it++) { + WebRtc_UWord32 stream_rate = 0; + WebRtc_UWord32 video_rate = 0; + WebRtc_UWord32 fec_rate = 0; WebRtc_UWord32 nackRate = 0; - RtpRtcp* rtpRtcp = *it; - rtpRtcp->BitrateSent(&streamRate, &videoRate, &fecRate, &nackRate); - totalBitrateSent += streamRate; - fecBitrateSent += fecRate; + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->BitrateSent(&stream_rate, &video_rate, &fec_rate, &nackRate); + total_bitrate_sent += stream_rate; + fec_bitrate_sent += fec_rate; nackBitrateSent += nackRate; } } -// ---------------------------------------------------------------------------- -// SetKeepAliveStatus -// -// Enables/disbles RTP keeoalive -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetKeepAliveStatus( - const bool enable, const WebRtc_Word8 unknownPayloadType, - const WebRtc_UWord16 deltaTransmitTimeMS) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + const bool enable, + const WebRtc_Word8 unknown_payload_type, + const WebRtc_UWord16 delta_transmit_timeMS) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - if (enable && _rtpRtcp.RTPKeepalive()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP keepalive already enabled", __FUNCTION__); - return -1; - } - else if (!enable && !_rtpRtcp.RTPKeepalive()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: RTP keepalive already disabled", __FUNCTION__); - return -1; - } + if (enable && rtp_rtcp_.RTPKeepalive()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP keepalive already enabled", __FUNCTION__); + return -1; + } else if (!enable && !rtp_rtcp_.RTPKeepalive()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: RTP keepalive already disabled", __FUNCTION__); + return -1; + } - if (_rtpRtcp.SetRTPKeepaliveStatus(enable, unknownPayloadType, - deltaTransmitTimeMS) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not set RTP keepalive status %d", __FUNCTION__, - enable); - if (enable == false && !_rtpRtcp.DefaultModuleRegistered()) - { - // Not sending media and we try to disable keep alive - _rtpRtcp.ResetSendDataCountersRTP(); - _rtpRtcp.SetSendingStatus(false); - } - return -1; + if (rtp_rtcp_.SetRTPKeepaliveStatus(enable, unknown_payload_type, + delta_transmit_timeMS) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not set RTP keepalive status %d", __FUNCTION__, + enable); + if (enable == false && !rtp_rtcp_.DefaultModuleRegistered()) { + // Not sending media and we try to disable keep alive + rtp_rtcp_.ResetSendDataCountersRTP(); + rtp_rtcp_.SetSendingStatus(false); } + return -1; + } - if (enable && !_rtpRtcp.Sending()) - { - // Enable sending to start sending Sender reports instead of receive - // reports - if (_rtpRtcp.SetSendingStatus(true) != 0) - { - _rtpRtcp.SetRTPKeepaliveStatus(false, 0, 0); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not start sending", __FUNCTION__); - return -1; - } + if (enable && !rtp_rtcp_.Sending()) { + // Enable sending to start sending Sender reports instead of receive + // reports. + if (rtp_rtcp_.SetSendingStatus(true) != 0) { + rtp_rtcp_.SetRTPKeepaliveStatus(false, 0, 0); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not start sending", __FUNCTION__); + return -1; } - else if (!enable && !_rtpRtcp.SendingMedia()) - { - // Not sending media and we're disabling keep alive - _rtpRtcp.ResetSendDataCountersRTP(); - if (_rtpRtcp.SetSendingStatus(false) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not stop sending", __FUNCTION__); - return -1; - } + } else if (!enable && !rtp_rtcp_.SendingMedia()) { + // Not sending media and we're disabling keep alive. + rtp_rtcp_.ResetSendDataCountersRTP(); + if (rtp_rtcp_.SetSendingStatus(false) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not stop sending", __FUNCTION__); + return -1; } - return 0; + } + return 0; } -// ---------------------------------------------------------------------------- -// GetKeepAliveStatus -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::GetKeepAliveStatus( - bool& enabled, WebRtc_Word8& unknownPayloadType, - WebRtc_UWord16& deltaTransmitTimeMs) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - if (_rtpRtcp.RTPKeepaliveStatus(&enabled, &unknownPayloadType, - &deltaTransmitTimeMs) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get RTP keepalive status", __FUNCTION__); - return -1; - } - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: enabled = %d, unknownPayloadType = %d, deltaTransmitTimeMs = %ul", - __FUNCTION__, enabled, (WebRtc_Word32) unknownPayloadType, - deltaTransmitTimeMs); + bool& enabled, + WebRtc_Word8& unknown_payload_type, + WebRtc_UWord16& delta_transmit_time_ms) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + if (rtp_rtcp_.RTPKeepaliveStatus(&enabled, &unknown_payload_type, + &delta_transmit_time_ms) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get RTP keepalive status", __FUNCTION__); + return -1; + } + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: enabled = %d, unknown_payload_type = %d, " + "delta_transmit_time_ms = %ul", + __FUNCTION__, enabled, (WebRtc_Word32) unknown_payload_type, + delta_transmit_time_ms); - return 0; + return 0; } -// ---------------------------------------------------------------------------- -// StartRTPDump -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::StartRTPDump(const char file_nameUTF8[1024], + RTPDirections direction) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::StartRTPDump(const char fileNameUTF8[1024], - RTPDirections direction) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); + if (direction != kRtpIncoming && direction != kRtpOutgoing) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: invalid input", __FUNCTION__); + return -1; + } - if (direction != kRtpIncoming && direction != kRtpOutgoing) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: invalid input", - __FUNCTION__); - return -1; - } - - if (direction == kRtpIncoming) - { - return _vieReceiver.StartRTPDump(fileNameUTF8); - } - else - { - return _vieSender.StartRTPDump(fileNameUTF8); - } + if (direction == kRtpIncoming) { + return vie_receiver_.StartRTPDump(file_nameUTF8); + } else { + return vie_sender_.StartRTPDump(file_nameUTF8); + } } -// ---------------------------------------------------------------------------- -// StopRTPDump -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::StopRTPDump(RTPDirections direction) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::StopRTPDump(RTPDirections direction) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - if (direction != kRtpIncoming && direction != kRtpOutgoing) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: invalid input", - __FUNCTION__); - return -1; - } + if (direction != kRtpIncoming && direction != kRtpOutgoing) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: invalid input", __FUNCTION__); + return -1; + } - if (direction == kRtpIncoming) - { - return _vieReceiver.StopRTPDump(); - } - else - { - return _vieSender.StopRTPDump(); - } + if (direction == kRtpIncoming) { + return vie_receiver_.StopRTPDump(); + } else { + return vie_sender_.StopRTPDump(); + } } -// ============================================================================ -// Network -// ============================================================================ +WebRtc_Word32 ViEChannel::SetLocalReceiver(const WebRtc_UWord16 rtp_port, + const WebRtc_UWord16 rtcp_port, + const WebRtc_Word8* ip_address) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -// ---------------------------------------------------------------------------- -// SetLocalReceiver -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetLocalReceiver(const WebRtc_UWord16 rtpPort, - const WebRtc_UWord16 rtcpPort, - const WebRtc_Word8* ipAddress) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - _callbackCritsect.Enter(); - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: external transport registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); + callbackCritsect_.Enter(); + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external transport registered", __FUNCTION__); + return -1; + } + callbackCritsect_.Leave(); #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.Receiving()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: already receiving", - __FUNCTION__); - return -1; - } - - const WebRtc_Word8* multicastIpAddress = NULL; - if (_socketTransport.InitializeReceiveSockets(&_vieReceiver, rtpPort, - ipAddress, - multicastIpAddress, rtcpPort) - != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: could not initialize receive sockets. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.Receiving()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: already receiving", __FUNCTION__); return -1; + } + + const WebRtc_Word8* multicast_ip_address = NULL; + if (socket_transport_.InitializeReceiveSockets(&vie_receiver_, rtp_port, + ip_address, + multicast_ip_address, + rtcp_port) != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not initialize receive sockets. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// GetLocalReceiver -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::GetLocalReceiver(WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_Word8* ip_address) const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::GetLocalReceiver(WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_Word8* ipAddress) const -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - _callbackCritsect.Enter(); - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: external transport registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); + callbackCritsect_.Enter(); + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external transport registered", __FUNCTION__); + return -1; + } + callbackCritsect_.Leave(); #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.ReceiveSocketsInitialized() == false) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: receive sockets not initialized", __FUNCTION__); - return -1; - } - - WebRtc_Word8 multicastIpAddress[UdpTransport:: - kIpAddressVersion6Length]; - if (_socketTransport.ReceiveSocketInformation(ipAddress, rtpPort, rtcpPort, - multicastIpAddress) != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: could not get receive socket information. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.ReceiveSocketsInitialized() == false) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: receive sockets not initialized", __FUNCTION__); return -1; + } + + WebRtc_Word8 multicast_ip_address[UdpTransport::kIpAddressVersion6Length]; + if (socket_transport_.ReceiveSocketInformation(ip_address, rtp_port, + rtcp_port, + multicast_ip_address) != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not get receive socket information. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// SetSendDestination -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetSendDestination( - const WebRtc_Word8* ipAddress, const WebRtc_UWord16 rtpPort, - const WebRtc_UWord16 rtcpPort, const WebRtc_UWord16 sourceRtpPort, - const WebRtc_UWord16 sourceRtcpPort) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); + const WebRtc_Word8* ip_address, + const WebRtc_UWord16 rtp_port, + const WebRtc_UWord16 rtcp_port, + const WebRtc_UWord16 source_rtp_port, + const WebRtc_UWord16 source_rtcp_port) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); - _callbackCritsect.Enter(); - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: external transport registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); + callbackCritsect_.Enter(); + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external transport registered", __FUNCTION__); + return -1; + } + callbackCritsect_.Leave(); #ifndef WEBRTC_EXTERNAL_TRANSPORT - const bool isIPv6 = _socketTransport.IpV6Enabled(); - if (UdpTransport::IsIpAddressValid(ipAddress, isIPv6) == false) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Not a valid IP address: %s", __FUNCTION__, ipAddress); - return -1; - } - if (_socketTransport.InitializeSendSockets(ipAddress, rtpPort, rtcpPort) - != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not initialize send socket. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - - if (sourceRtpPort != 0) - { - WebRtc_UWord16 receiveRtpPort = 0; - WebRtc_UWord16 receiveRtcpPort = 0; - if (_socketTransport.ReceiveSocketInformation(NULL, receiveRtpPort, - receiveRtcpPort, NULL) - != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: could not get receive port information. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - // Initialize an extra socket only if send port differs from receive - // port - if (sourceRtpPort != receiveRtpPort) - { - if (_socketTransport.InitializeSourcePorts(sourceRtpPort, - sourceRtcpPort) != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not set source ports. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - } - } - _vieSender.RegisterSendTransport(&_socketTransport); - - // Workaround to avoid SSRC colision detection in loppback tests - if (!isIPv6) - { - WebRtc_UWord32 localHostAddress = 0; - const WebRtc_UWord32 currentIpAddress = - UdpTransport::InetAddrIPV4(ipAddress); - - if ((UdpTransport::LocalHostAddress(localHostAddress) == 0 - && localHostAddress == currentIpAddress) || - strncmp("127.0.0.1", ipAddress, 9) == 0) - { - _rtpRtcp.SetSSRC(0xFFFFFFFF); - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "Running in loopback. Forcing fixed SSRC"); - } - } - else - { - WebRtc_UWord8 localHostAddress[16]; - WebRtc_UWord8 currentIpAddress[16]; - - WebRtc_Word32 convResult = - UdpTransport::LocalHostAddressIPV6(localHostAddress); - convResult - += _socketTransport.InetPresentationToNumeric(23, ipAddress, - currentIpAddress); - if (convResult == 0) - { - bool localHost = true; - for (WebRtc_Word32 i = 0; i < 16; i++) - { - if (localHostAddress[i] != currentIpAddress[i]) - { - localHost = false; - break; - } - } - if (!localHost) - { - localHost = true; - for (WebRtc_Word32 i = 0; i < 15; i++) - { - if (currentIpAddress[i] != 0) - { - localHost = false; - break; - } - } - if (localHost == true && currentIpAddress[15] != 1) - { - localHost = false; - } - } - if (localHost) - { - _rtpRtcp.SetSSRC(0xFFFFFFFF); - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "Running in loopback. Forcing fixed SSRC"); - } - } - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + const bool is_ipv6 = socket_transport_.IpV6Enabled(); + if (UdpTransport::IsIpAddressValid(ip_address, is_ipv6) == false) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Not a valid IP address: %s", __FUNCTION__, ip_address); return -1; + } + if (socket_transport_.InitializeSendSockets(ip_address, rtp_port, + rtcp_port)!= 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not initialize send socket. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + + if (source_rtp_port != 0) { + WebRtc_UWord16 receive_rtp_port = 0; + WebRtc_UWord16 receive_rtcp_port = 0; + if (socket_transport_.ReceiveSocketInformation(NULL, receive_rtp_port, + receive_rtcp_port, + NULL) != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not get receive port information. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + // Initialize an extra socket only if send port differs from receive + // port. + if (source_rtp_port != receive_rtp_port) { + if (socket_transport_.InitializeSourcePorts(source_rtp_port, + source_rtcp_port) != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not set source ports. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + } + } + vie_sender_.RegisterSendTransport(&socket_transport_); + + // Workaround to avoid SSRC colision detection in loppback tests. + if (!is_ipv6) { + WebRtc_UWord32 local_host_address = 0; + const WebRtc_UWord32 current_ip_address = + UdpTransport::InetAddrIPV4(ip_address); + + if ((UdpTransport::LocalHostAddress(local_host_address) == 0 && + local_host_address == current_ip_address) || + strncmp("127.0.0.1", ip_address, 9) == 0) { + rtp_rtcp_.SetSSRC(0xFFFFFFFF); + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "Running in loopback. Forcing fixed SSRC"); + } + } else { + WebRtc_UWord8 local_host_address[16]; + WebRtc_UWord8 current_ip_address[16]; + + WebRtc_Word32 conv_result = + UdpTransport::LocalHostAddressIPV6(local_host_address); + conv_result += socket_transport_.InetPresentationToNumeric( + 23, ip_address, current_ip_address); + if (conv_result == 0) { + bool local_host = true; + for (WebRtc_Word32 i = 0; i < 16; i++) { + if (local_host_address[i] != current_ip_address[i]) { + local_host = false; + break; + } + } + if (!local_host) { + local_host = true; + for (WebRtc_Word32 i = 0; i < 15; i++) { + if (current_ip_address[i] != 0) { + local_host = false; + break; + } + } + if (local_host == true && current_ip_address[15] != 1) { + local_host = false; + } + } + if (local_host) { + rtp_rtcp_.SetSSRC(0xFFFFFFFF); + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, + ViEId(engine_id_, channel_id_), + "Running in loopback. Forcing fixed SSRC"); + } + } + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, + ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// GetSendDestination -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::GetSendDestination( - WebRtc_Word8* ipAddress, WebRtc_UWord16& rtpPort, WebRtc_UWord16& rtcpPort, - WebRtc_UWord16& sourceRtpPort, WebRtc_UWord16& sourceRtcpPort) const -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - _callbackCritsect.Enter(); - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: external transport registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); - -#ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.SendSocketsInitialized() == false) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: send sockets not initialized", __FUNCTION__); - return -1; - } - if (_socketTransport.SendSocketInformation(ipAddress, rtpPort, rtcpPort) - != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: could not get send socket information. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - sourceRtpPort = 0; - sourceRtcpPort = 0; - if (_socketTransport.SourcePortsInitialized()) - { - _socketTransport.SourcePorts(sourceRtpPort, sourceRtcpPort); - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); - return -1; -#endif -} - -// ---------------------------------------------------------------------------- -// StartSend -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::StartSend() -{ - CriticalSectionScoped cs(_callbackCritsect); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - -#ifndef WEBRTC_EXTERNAL_TRANSPORT - if (!_ptrExternalTransport) - { - if (_socketTransport.SendSocketsInitialized() == false) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId,_channelId), - "%s: send sockets not initialized", __FUNCTION__); - return -1; - } - } -#endif - _rtpRtcp.SetSendingMediaStatus(true); - - if (_rtpRtcp.Sending() && !_rtpRtcp.RTPKeepalive()) - { - if (_rtpRtcp.RTPKeepalive()) - { - // Sending Keep alive, don't trigger an error - return 0; - } - // Already sending - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Already sending", - __FUNCTION__); - return kViEBaseAlreadySending; - } - if (_rtpRtcp.SetSendingStatus(true) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not start sending RTP", __FUNCTION__); - return -1; - } - for (std::list::const_iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetSendingMediaStatus(true); - rtpRtcp->SetSendingStatus(true); - } - return 0; -} - -// ---------------------------------------------------------------------------- -// StopSend -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::StopSend() -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - _rtpRtcp.SetSendingMediaStatus(false); - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetSendingMediaStatus(false); - } - if (_rtpRtcp.RTPKeepalive()) - { - // Don't turn off sending since we'll send keep alive packets - return 0; - } - if (!_rtpRtcp.Sending()) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Not sending", - __FUNCTION__); - return kViEBaseNotSending; - } - // Reset - _rtpRtcp.ResetSendDataCountersRTP(); - if (_rtpRtcp.SetSendingStatus(false) != 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not stop RTP sending", __FUNCTION__); - return -1; - } - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->ResetSendDataCountersRTP(); - rtpRtcp->SetSendingStatus(false); - } - return 0; -} - -// ---------------------------------------------------------------------------- -// Sending -// ---------------------------------------------------------------------------- - -bool ViEChannel::Sending() -{ - return _rtpRtcp.Sending(); -} - -// ---------------------------------------------------------------------------- -// StartReceive -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::StartReceive() -{ - CriticalSectionScoped cs(_callbackCritsect); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - -#ifndef WEBRTC_EXTERNAL_TRANSPORT - if (!_ptrExternalTransport) - { - if (_socketTransport.Receiving()) - { - // Warning, don't return error - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: already receiving", - __FUNCTION__); - return 0; - } - if (_socketTransport.ReceiveSocketsInitialized() == false) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: receive sockets not initialized", __FUNCTION__); - return -1; - } - if (_socketTransport.StartReceiving(kViENumReceiveSocketBuffers) - != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE( - webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: could not get receive socket information. Socket error:%d", - __FUNCTION__, socketError); - return -1; - } - } -#endif - if (StartDecodeThread() != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: could not start decoder thread", __FUNCTION__); - -#ifndef WEBRTC_EXTERNAL_TRANSPORT - _socketTransport.StopReceiving(); -#endif - _vieReceiver.StopReceive(); - return -1; - } - _vieReceiver.StartReceive(); - - return 0; -} - -// ---------------------------------------------------------------------------- -// StopReceive -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::StopReceive() -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - _vieReceiver.StopReceive(); - StopDecodeThread(); - _vcm.ResetDecoder(); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - return 0; - } - } - -#ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.Receiving() == false) - { - // Warning, don't return error - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: not receiving", - __FUNCTION__); - return 0; - } - if (_socketTransport.StopReceiving() != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: Socket error: %d", __FUNCTION__, socketError); - return -1; - } -#endif - - return 0; -} - -bool ViEChannel::Receiving() -{ -#ifndef WEBRTC_EXTERNAL_TRANSPORT - return _socketTransport.Receiving(); -#else - return false; -#endif -} - -// ---------------------------------------------------------------------------- -// GetSourceInfo -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetSourceInfo(WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_Word8* ipAddress, - WebRtc_UWord32 ipAddressLength) -{ - { - CriticalSectionScoped cs(_callbackCritsect); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: external transport registered", __FUNCTION__); - return -1; - } - } -#ifndef WEBRTC_EXTERNAL_TRANSPORT - - if (_socketTransport.IpV6Enabled() && ipAddressLength - < UdpTransport::kIpAddressVersion6Length) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: IP address length is too small for IPv6", __FUNCTION__); - return -1; - } - else if (ipAddressLength < - UdpTransport::kIpAddressVersion4Length) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: IP address length is too small for IPv4", __FUNCTION__); - return -1; - } - - if (_socketTransport.RemoteSocketInformation(ipAddress, rtpPort, rtcpPort) - != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Error getting source ports. Socket error: %d", - __FUNCTION__, socketError); - return -1; - } - - return 0; -#else - - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", + WebRtc_Word8* ip_address, + WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_UWord16& source_rtp_port, + WebRtc_UWord16& source_rtcp_port) const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); + + callbackCritsect_.Enter(); + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external transport registered", __FUNCTION__); return -1; + } + callbackCritsect_.Leave(); + +#ifndef WEBRTC_EXTERNAL_TRANSPORT + if (socket_transport_.SendSocketsInitialized() == false) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: send sockets not initialized", __FUNCTION__); + return -1; + } + if (socket_transport_.SendSocketInformation(ip_address, rtp_port, rtcp_port) + != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not get send socket information. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + source_rtp_port = 0; + source_rtcp_port = 0; + if (socket_transport_.SourcePortsInitialized()) { + socket_transport_.SourcePorts(source_rtp_port, source_rtcp_port); + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// RegisterSendTransport -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::RegisterSendTransport(Transport& transport) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::StartSend() { + CriticalSectionScoped cs(callbackCritsect_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.SendSocketsInitialized() - || _socketTransport.ReceiveSocketsInitialized()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: socket transport already initialized", - __FUNCTION__); - return -1; + if (!external_transport_) { + if (socket_transport_.SendSocketsInitialized() == false) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: send sockets not initialized", __FUNCTION__); + return -1; } + } +#endif + rtp_rtcp_.SetSendingMediaStatus(true); + + if (rtp_rtcp_.Sending() && !rtp_rtcp_.RTPKeepalive()) { + if (rtp_rtcp_.RTPKeepalive()) { + // Sending Keep alive, don't trigger an error. + return 0; + } + // Already sending. + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Already sending", __FUNCTION__); + return kViEBaseAlreadySending; + } + if (rtp_rtcp_.SetSendingStatus(true) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not start sending RTP", __FUNCTION__); + return -1; + } + for (std::list::const_iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetSendingMediaStatus(true); + rtp_rtcp->SetSendingStatus(true); + } + return 0; +} + +WebRtc_Word32 ViEChannel::StopSend() { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + + rtp_rtcp_.SetSendingMediaStatus(false); + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetSendingMediaStatus(false); + } + if (rtp_rtcp_.RTPKeepalive()) { + // Don't turn off sending since we'll send keep alive packets. + return 0; + } + if (!rtp_rtcp_.Sending()) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Not sending", __FUNCTION__); + return kViEBaseNotSending; + } + + // Reset. + rtp_rtcp_.ResetSendDataCountersRTP(); + if (rtp_rtcp_.SetSendingStatus(false) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not stop RTP sending", __FUNCTION__); + return -1; + } + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->ResetSendDataCountersRTP(); + rtp_rtcp->SetSendingStatus(false); + } + return 0; +} + +bool ViEChannel::Sending() { + return rtp_rtcp_.Sending(); +} + +WebRtc_Word32 ViEChannel::StartReceive() { + CriticalSectionScoped cs(callbackCritsect_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + +#ifndef WEBRTC_EXTERNAL_TRANSPORT + if (!external_transport_) { + if (socket_transport_.Receiving()) { + // Warning, don't return error. + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: already receiving", __FUNCTION__); + return 0; + } + if (socket_transport_.ReceiveSocketsInitialized() == false) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: receive sockets not initialized", __FUNCTION__); + return -1; + } + if (socket_transport_.StartReceiving(kViENumReceiveSocketBuffers) != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not get receive socket information. Socket error:%d", + __FUNCTION__, socket_error); + return -1; + } + } +#endif + if (StartDecodeThread() != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not start decoder thread", __FUNCTION__); + +#ifndef WEBRTC_EXTERNAL_TRANSPORT + socket_transport_.StopReceiving(); +#endif + vie_receiver_.StopReceive(); + return -1; + } + vie_receiver_.StartReceive(); + + return 0; +} + +WebRtc_Word32 ViEChannel::StopReceive() { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + + vie_receiver_.StopReceive(); + StopDecodeThread(); + vcm_.ResetDecoder(); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + return 0; + } + } + +#ifndef WEBRTC_EXTERNAL_TRANSPORT + if (socket_transport_.Receiving() == false) { + // Warning, don't return error + WEBRTC_TRACE(kTraceWarning, kTraceVideo, + ViEId(engine_id_, channel_id_), "%s: not receiving", + __FUNCTION__); + return 0; + } + if (socket_transport_.StopReceiving() != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Socket error: %d", __FUNCTION__, socket_error); + return -1; + } #endif - if (_rtpRtcp.Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Sending", __FUNCTION__); - return -1; - } + return 0; +} - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: transport already registered", __FUNCTION__); - return -1; +bool ViEChannel::Receiving() { +#ifndef WEBRTC_EXTERNAL_TRANSPORT + return socket_transport_.Receiving(); +#else + return false; +#endif +} + +WebRtc_Word32 ViEChannel::GetSourceInfo(WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_Word8* ip_address, + WebRtc_UWord32 ip_address_length) { + { + CriticalSectionScoped cs(callbackCritsect_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external transport registered", __FUNCTION__); + return -1; } - _ptrExternalTransport = &transport; - _vieSender.RegisterSendTransport(&transport); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + } +#ifndef WEBRTC_EXTERNAL_TRANSPORT + if (socket_transport_.IpV6Enabled() && + ip_address_length < UdpTransport::kIpAddressVersion6Length) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: IP address length is too small for IPv6", __FUNCTION__); + return -1; + } else if (ip_address_length < UdpTransport::kIpAddressVersion4Length) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: IP address length is too small for IPv4", __FUNCTION__); + return -1; + } + + if (socket_transport_.RemoteSocketInformation(ip_address, rtp_port, rtcp_port) + != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Error getting source ports. Socket error: %d", + __FUNCTION__, socket_error); + return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; +#endif +} +WebRtc_Word32 ViEChannel::RegisterSendTransport(Transport& transport) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + +#ifndef WEBRTC_EXTERNAL_TRANSPORT + if (socket_transport_.SendSocketsInitialized() || + socket_transport_.ReceiveSocketsInitialized()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: socket transport already initialized", __FUNCTION__); + return -1; + } +#endif + if (rtp_rtcp_.Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Sending", __FUNCTION__); + return -1; + } + + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: transport already registered", __FUNCTION__); + return -1; + } + external_transport_ = &transport; + vie_sender_.RegisterSendTransport(&transport); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: Transport registered: 0x%p", __FUNCTION__, - &_ptrExternalTransport); + &external_transport_); - return 0; + return 0; } -// ---------------------------------------------------------------------------- -// DeregisterSendTransport -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::DeregisterSendTransport() { + CriticalSectionScoped cs(callbackCritsect_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::DeregisterSendTransport() -{ - CriticalSectionScoped cs(_callbackCritsect); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_ptrExternalTransport == NULL) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: no transport registered", __FUNCTION__); - return -1; - } - if (_rtpRtcp.Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Sending", __FUNCTION__); - return -1; - } - _ptrExternalTransport = NULL; - _vieSender.DeregisterSendTransport(); - return 0; + if (!external_transport_) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no transport registered", __FUNCTION__); + return -1; + } + if (rtp_rtcp_.Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Sending", __FUNCTION__); + return -1; + } + external_transport_ = NULL; + vie_sender_.DeregisterSendTransport(); + return 0; } -// ---------------------------------------------------------------------------- -// ReceivedRTPPacket -// -// Incoming packet from external transport -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::ReceivedRTPPacket(const void* rtpPacket, - const WebRtc_Word32 rtpPacketLength) -{ - { - CriticalSectionScoped cs(_callbackCritsect); - if (!_ptrExternalTransport) - { - return -1; - } +WebRtc_Word32 ViEChannel::ReceivedRTPPacket( + const void* rtp_packet, const WebRtc_Word32 rtp_packet_length) { + { + CriticalSectionScoped cs(callbackCritsect_); + if (!external_transport_) { + return -1; } - return _vieReceiver.ReceivedRTPPacket(rtpPacket, rtpPacketLength); + } + return vie_receiver_.ReceivedRTPPacket(rtp_packet, rtp_packet_length); } -// ---------------------------------------------------------------------------- -// ReceivedRTPPacket -// -// Incoming packet from external transport -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::ReceivedRTCPPacket( - const void* rtcpPacket, const WebRtc_Word32 rtcpPacketLength) -{ - { - CriticalSectionScoped cs(_callbackCritsect); - if (!_ptrExternalTransport) - { - return -1; - } + const void* rtcp_packet, const WebRtc_Word32 rtcp_packet_length) { + { + CriticalSectionScoped cs(callbackCritsect_); + if (!external_transport_) { + return -1; } - return _vieReceiver.ReceivedRTCPPacket(rtcpPacket, rtcpPacketLength); + } + return vie_receiver_.ReceivedRTCPPacket(rtcp_packet, rtcp_packet_length); } -// ---------------------------------------------------------------------------- -// EnableIPv6 -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::EnableIPv6() -{ - _callbackCritsect.Enter(); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::EnableIPv6() { + callbackCritsect_.Enter(); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, + ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; + } + callbackCritsect_.Leave(); #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.IpV6Enabled()) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, ViEId(_engineId, - _channelId), - "%s: IPv6 already enabled", __FUNCTION__); - return -1; - } + if (socket_transport_.IpV6Enabled()) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: IPv6 already enabled", __FUNCTION__); + return -1; + } - if (_socketTransport.EnableIpV6() != 0) - { - WebRtc_Word32 socketError = _socketTransport.LastError(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not enable IPv6. Socket error: %d", __FUNCTION__, - socketError); - return -1; - } - return 0; + if (socket_transport_.EnableIpV6() != 0) { + WebRtc_Word32 socket_error = socket_transport_.LastError(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not enable IPv6. Socket error: %d", __FUNCTION__, + socket_error); + return -1; + } + return 0; #else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: not available for external transport", __FUNCTION__); - return -1; -#endif - -} - -// ---------------------------------------------------------------------------- -// IsIPv6Enabled -// ---------------------------------------------------------------------------- - -bool ViEChannel::IsIPv6Enabled() -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return false; - } - } -#ifndef WEBRTC_EXTERNAL_TRANSPORT - return _socketTransport.IpV6Enabled(); -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); - return false; + return -1; #endif } -// ---------------------------------------------------------------------------- -// SetSourceFilter -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetSourceFilter(const WebRtc_UWord16 rtpPort, - const WebRtc_UWord16 rtcpPort, - const WebRtc_Word8* ipAddress) -{ - _callbackCritsect.Enter(); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +bool ViEChannel::IsIPv6Enabled() { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: External transport registered", __FUNCTION__); - return -1; + return false; } - _callbackCritsect.Leave(); - + } #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.SetFilterIP(ipAddress) != 0) - { - // Logging done in module - return -1; - } - if (_socketTransport.SetFilterPorts(rtpPort, rtcpPort) != 0) - { - // Logging done - return -1; - } - return 0; + return socket_transport_.IpV6Enabled(); #else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: not available for external transport", __FUNCTION__); - return -1; + return false; #endif } -// ---------------------------------------------------------------------------- -// GetSourceFilter -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::SetSourceFilter(const WebRtc_UWord16 rtp_port, + const WebRtc_UWord16 rtcp_port, + const WebRtc_Word8* ip_address) { + callbackCritsect_.Enter(); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::GetSourceFilter(WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_Word8* ipAddress) const -{ - _callbackCritsect.Enter(); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_ptrExternalTransport) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; + } + callbackCritsect_.Leave(); #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.FilterIP(ipAddress) != 0) - { - // Logging done in module - return -1; - } - if (_socketTransport.FilterPorts(rtpPort, rtcpPort) != 0) - { - // Logging done in module - return -1; - } - - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.SetFilterIP(ip_address) != 0) { + // Logging done in module. return -1; + } + if (socket_transport_.SetFilterPorts(rtp_port, rtcp_port) != 0) { + // Logging done. + return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// SetToS -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::GetSourceFilter(WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_Word8* ip_address) const { + callbackCritsect_.Enter(); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + + if (external_transport_) { + callbackCritsect_.Leave(); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; + } + callbackCritsect_.Leave(); + +#ifndef WEBRTC_EXTERNAL_TRANSPORT + if (socket_transport_.FilterIP(ip_address) != 0) { + // Logging done in module. + return -1; + } + if (socket_transport_.FilterPorts(rtp_port, rtcp_port) != 0) { + // Logging done in module. + return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; +#endif +} -// ToS WebRtc_Word32 ViEChannel::SetToS(const WebRtc_Word32 DSCP, - const bool useSetSockOpt) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } + const bool use_set_sockOpt) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; } + } #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.SetToS(DSCP, useSetSockOpt) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Socket error: %d", - __FUNCTION__, _socketTransport.LastError()); - return -1; - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.SetToS(DSCP, use_set_sockOpt) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Socket error: %d", __FUNCTION__, + socket_transport_.LastError()); return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// GetToS -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::GetToS(WebRtc_Word32& DSCP, bool& useSetSockOpt) const -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } +WebRtc_Word32 ViEChannel::GetToS(WebRtc_Word32& DSCP, + bool& use_set_sockOpt) const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; } + } #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.ToS(DSCP, useSetSockOpt) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Socket error: %d", - __FUNCTION__, _socketTransport.LastError()); - return -1; - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.ToS(DSCP, use_set_sockOpt) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Socket error: %d", __FUNCTION__, + socket_transport_.LastError()); return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// SetSendGQoS -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetSendGQoS(const bool enable, - const WebRtc_Word32 serviceType, - const WebRtc_UWord32 maxBitrate, - const WebRtc_Word32 overrideDSCP) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } + const WebRtc_Word32 service_type, + const WebRtc_UWord32 max_bitrate, + const WebRtc_Word32 overrideDSCP) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; } + } #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.SetQoS(enable, serviceType, maxBitrate, overrideDSCP, - false) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Socket error: %d", - __FUNCTION__, _socketTransport.LastError()); - return -1; - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.SetQoS(enable, service_type, max_bitrate, overrideDSCP, + false) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Socket error: %d", __FUNCTION__, + socket_transport_.LastError()); return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// GetSendGQoS -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::GetSendGQoS(bool& enabled, - WebRtc_Word32& serviceType, - WebRtc_Word32& overrideDSCP) const -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } + WebRtc_Word32& service_type, + WebRtc_Word32& overrideDSCP) const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; } + } #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.QoS(enabled, serviceType, overrideDSCP) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Socket error: %d", - __FUNCTION__, _socketTransport.LastError()); - return -1; - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + if (socket_transport_.QoS(enabled, service_type, overrideDSCP) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Socket error: %d", __FUNCTION__, + socket_transport_.LastError()); return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ---------------------------------------------------------------------------- -// SetMTU -// -// Sets the maximum transfer unit size for the network link, i.e. including -// IP, UDP[/TCP] and RTP headers, -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::SetMTU(WebRtc_UWord16 mtu) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_rtpRtcp.SetMaxTransferUnit(mtu) != 0) - { - // Logging done - return -1; - } - for (std::list::iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->SetMaxTransferUnit(mtu); - } - return 0; +WebRtc_Word32 ViEChannel::SetMTU(WebRtc_UWord16 mtu) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + if (rtp_rtcp_.SetMaxTransferUnit(mtu) != 0) { + // Logging done. + return -1; + } + for (std::list::iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->SetMaxTransferUnit(mtu); + } + return 0; } -// ---------------------------------------------------------------------------- -// GetMaxDataPayloadLength -// -// maxDataPayloadLength: maximum allowed payload size, i.e. the maximum -// allowed size of encoded data in each packet. -// ---------------------------------------------------------------------------- - -WebRtc_UWord16 ViEChannel::MaxDataPayloadLength() const -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_UWord16 ViEChannel::MaxDataPayloadLength() const { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); - - return _rtpRtcp.MaxDataPayloadLength(); + return rtp_rtcp_.MaxDataPayloadLength(); } -// ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// SetPacketTimeoutNotification -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::SetPacketTimeoutNotification( - bool enable, - WebRtc_UWord32 timeoutSeconds) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (enable) - { - WebRtc_UWord32 timeoutMs = 1000 * timeoutSeconds; - if (_rtpRtcp.SetPacketTimeout(timeoutMs, 0) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s", - __FUNCTION__); - return -1; - } + bool enable, WebRtc_UWord32 timeout_seconds) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + if (enable) { + WebRtc_UWord32 timeout_ms = 1000 * timeout_seconds; + if (rtp_rtcp_.SetPacketTimeout(timeout_ms, 0) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s", __FUNCTION__); + return -1; } - else - { - if (_rtpRtcp.SetPacketTimeout(0, 0) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId,_channelId), "%s", - __FUNCTION__); - return -1; - } + } else { + if (rtp_rtcp_.SetPacketTimeout(0, 0) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s", __FUNCTION__); + return -1; } - return 0; + } + return 0; } -// ---------------------------------------------------------------------------- -// RegisterObserver -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::RegisterNetworkObserver( - ViENetworkObserver* observer) -{ - CriticalSectionScoped cs(_callbackCritsect); - if (observer) - { - if (_networkObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: observer alread added", __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer added", __FUNCTION__); - _networkObserver = observer; + ViENetworkObserver* observer) { + CriticalSectionScoped cs(callbackCritsect_); + if (observer) { + if (networkObserver_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer alread added", __FUNCTION__); + return -1; } - else - { - if (!_networkObserver) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: no observer added", - __FUNCTION__); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: observer removed", __FUNCTION__); - _networkObserver = NULL; - } - return 0; -} -bool ViEChannel::NetworkObserverRegistered() -{ - CriticalSectionScoped cs(_callbackCritsect); - return _networkObserver != NULL; -} - -// ---------------------------------------------------------------------------- -// SetPeriodicDeadOrAliveStatus -// ---------------------------------------------------------------------------- -WebRtc_Word32 ViEChannel::SetPeriodicDeadOrAliveStatus( - const bool enable, const WebRtc_UWord32 sampleTimeSeconds) -{ - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - CriticalSectionScoped cs(_callbackCritsect); - if (_networkObserver == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer added", __FUNCTION__); + networkObserver_ = observer; + } else { + if (!networkObserver_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: no observer added", __FUNCTION__); - return -1; + return -1; } - - bool enabled = false; - WebRtc_UWord8 currentSampletimeSeconds = 0; - - // Get old settings - _rtpRtcp.PeriodicDeadOrAliveStatus(enabled, currentSampletimeSeconds); - // Set new settings - if (_rtpRtcp.SetPeriodicDeadOrAliveStatus( - enable, (WebRtc_UWord8) sampleTimeSeconds) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not set periodic dead-or-alive status", - __FUNCTION__); - return -1; - } - if (!enable) - { - // Restore last utilized sample time. - // Without this trick, the sample time would always be reset to default - // (2 sec), each time dead-or-alive was disabled without sample-time - // parameter. - _rtpRtcp.SetPeriodicDeadOrAliveStatus(enable, currentSampletimeSeconds); - } - - return 0; + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: observer removed", __FUNCTION__); + networkObserver_ = NULL; + } + return 0; +} + +bool ViEChannel::NetworkObserverRegistered() { + CriticalSectionScoped cs(callbackCritsect_); + return networkObserver_ != NULL; +} + +WebRtc_Word32 ViEChannel::SetPeriodicDeadOrAliveStatus( + const bool enable, const WebRtc_UWord32 sample_time_seconds) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + + CriticalSectionScoped cs(callbackCritsect_); + if (!networkObserver_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no observer added", __FUNCTION__); + return -1; + } + + bool enabled = false; + WebRtc_UWord8 current_sampletime_seconds = 0; + + // Get old settings. + rtp_rtcp_.PeriodicDeadOrAliveStatus(enabled, current_sampletime_seconds); + // Set new settings. + if (rtp_rtcp_.SetPeriodicDeadOrAliveStatus( + enable, static_cast(sample_time_seconds)) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not set periodic dead-or-alive status", + __FUNCTION__); + return -1; + } + if (!enable) { + // Restore last utilized sample time. + // Without this trick, the sample time would always be reset to default + // (2 sec), each time dead-or-alive was disabled without sample-time + // parameter. + rtp_rtcp_.SetPeriodicDeadOrAliveStatus(enable, current_sampletime_seconds); + } + return 0; } -// ---------------------------------------------------------------------------- -// SendUDPPacket -// ---------------------------------------------------------------------------- WebRtc_Word32 ViEChannel::SendUDPPacket(const WebRtc_Word8* data, const WebRtc_UWord32 length, - WebRtc_Word32& transmittedBytes, - bool useRtcpSocket) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - { - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalTransport) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: External transport registered", __FUNCTION__); - return -1; - } + WebRtc_Word32& transmitted_bytes, + bool use_rtcp_socket) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + { + CriticalSectionScoped cs(callbackCritsect_); + if (external_transport_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: External transport registered", __FUNCTION__); + return -1; } + } #ifndef WEBRTC_EXTERNAL_TRANSPORT - transmittedBytes = _socketTransport.SendRaw(data, length, useRtcpSocket); - if (transmittedBytes == -1) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s", __FUNCTION__); - return -1; - } - return 0; -#else - WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: not available for external transport", __FUNCTION__); + transmitted_bytes = socket_transport_.SendRaw(data, length, use_rtcp_socket); + if (transmitted_bytes == -1) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); return -1; + } + return 0; +#else + WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not available for external transport", __FUNCTION__); + return -1; #endif } -// ============================================================================ -// Color enahncement -// ============================================================================ - -// ---------------------------------------------------------------------------- -// EnableColorEnhancement -// -// Enables/disables color enhancement for all decoded frames -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::EnableColorEnhancement(bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::EnableColorEnhancement(bool enable) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s(enable: %d)", __FUNCTION__, enable); - CriticalSectionScoped cs(_callbackCritsect); - if (enable && _colorEnhancement) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: Already enabled", - __FUNCTION__); - return -1; - } - else if (enable == false && _colorEnhancement == false) - - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s: not enabled", - __FUNCTION__); - return -1; - } - _colorEnhancement = enable; - return 0; + CriticalSectionScoped cs(callbackCritsect_); + if (enable && color_enhancement_) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Already enabled", __FUNCTION__); + return -1; + } else if (!enable && !color_enhancement_) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: not enabled", __FUNCTION__); + return -1; + } + color_enhancement_ = enable; + return 0; } -// ============================================================================ -// Register sender -// ============================================================================ - -// ---------------------------------------------------------------------------- -// RegisterSendRtpRtcpModule -// -// Register send RTP RTCP module, which will deliver the frames to send -// ---------------------------------------------------------------------------- - WebRtc_Word32 ViEChannel::RegisterSendRtpRtcpModule( - RtpRtcp& sendRtpRtcpModule) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); + RtpRtcp& send_rtp_rtcp_module) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); - WebRtc_Word32 retVal = _rtpRtcp.RegisterDefaultModule(&sendRtpRtcpModule); - if (retVal == 0) - { - // we need to store this for the SetSendCodec call - _defaultRtpRtcp = &sendRtpRtcpModule; - } - return retVal; + WebRtc_Word32 ret_val = rtp_rtcp_.RegisterDefaultModule( + &send_rtp_rtcp_module); + if (ret_val == 0) { + // We need to store this for the SetSendCodec call. + default_rtp_rtcp_ = &send_rtp_rtcp_module; + } + return ret_val; } -// ---------------------------------------------------------------------------- -// RegisterSendDeregisterSendRtpRtcpModuleRtpRtcpModule -// -// Deregisters the send RTP RTCP module, which will stop the encoder input to -// the channel -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::DeregisterSendRtpRtcpModule() { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + default_rtp_rtcp_ = NULL; -WebRtc_Word32 ViEChannel::DeregisterSendRtpRtcpModule() -{ - WEBRTC_TRACE(webrtc::kTraceInfo, - webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - _defaultRtpRtcp = NULL; - - for (std::list::const_iterator it = _simulcastRtpRtcp.begin(); - it != _simulcastRtpRtcp.end(); - it++) - { - RtpRtcp* rtpRtcp = *it; - rtpRtcp->DeRegisterDefaultModule(); - } - return _rtpRtcp.DeRegisterDefaultModule(); + for (std::list::const_iterator it = simulcast_rtp_rtcp_.begin(); + it != simulcast_rtp_rtcp_.end(); + it++) { + RtpRtcp* rtp_rtcp = *it; + rtp_rtcp->DeRegisterDefaultModule(); + } + return rtp_rtcp_.DeRegisterDefaultModule(); } -// ============================================================================ -// FrameToRender -// Called by VCM when a frame have been decoded. -// ============================================================================ +WebRtc_Word32 ViEChannel::FrameToRender(VideoFrame& video_frame) { + CriticalSectionScoped cs(callbackCritsect_); -WebRtc_Word32 ViEChannel::FrameToRender(VideoFrame& videoFrame) -{ - CriticalSectionScoped cs(_callbackCritsect); - - if (_decoderReset) - { - // Trigger a callback to the user if the incoming codec has changed. - if (_codecObserver) - { - VideoCodec decoder; - memset(&decoder, 0, sizeof(decoder)); - if (_vcm.ReceiveCodec(&decoder) == VCM_OK) - { - // VCM::ReceiveCodec returns the codec set by - // RegisterReceiveCodec, which might not be the size we're - // actually decoding - decoder.width = (unsigned short) videoFrame.Width(); - decoder.height = (unsigned short) videoFrame.Height(); - _codecObserver->IncomingCodecChanged(_channelId, decoder); - } - else - { - assert(false); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: Could not get receive codec", __FUNCTION__); - } - } - _decoderReset = false; - } - if (_effectFilter) - { - _effectFilter->Transform(videoFrame.Length(), videoFrame.Buffer(), - videoFrame.TimeStamp(), videoFrame.Width(), - videoFrame.Height()); - } - if (_colorEnhancement) - { - VideoProcessingModule::ColorEnhancement(videoFrame); + if (decoder_reset_) { + // Trigger a callback to the user if the incoming codec has changed. + if (codec_observer_) { + VideoCodec decoder; + memset(&decoder, 0, sizeof(decoder)); + if (vcm_.ReceiveCodec(&decoder) == VCM_OK) { + // VCM::ReceiveCodec returns the codec set by + // RegisterReceiveCodec, which might not be the size we're + // actually decoding. + decoder.width = static_cast(video_frame.Width()); + decoder.height = static_cast(video_frame.Height()); + codec_observer_->IncomingCodecChanged(channel_id_, decoder); + } else { + assert(false); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: Could not get receive codec", __FUNCTION__); + } } + decoder_reset_ = false; + } + if (effect_filter_) { + effect_filter_->Transform(video_frame.Length(), video_frame.Buffer(), + video_frame.TimeStamp(), video_frame.Width(), + video_frame.Height()); + } + if (color_enhancement_) { + VideoProcessingModule::ColorEnhancement(video_frame); + } - // Record videoframe - _fileRecorder.RecordVideoFrame(videoFrame); + // Record videoframe. + file_recorder_.RecordVideoFrame(video_frame); - WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize]; - WebRtc_Word32 noOfCSRCs = _rtpRtcp.RemoteCSRCs(arrOfCSRC); - if (noOfCSRCs <= 0) - { - arrOfCSRC[0] = _rtpRtcp.RemoteSSRC(); - noOfCSRCs = 1; - } - - DeliverFrame(videoFrame, noOfCSRCs, arrOfCSRC); - - return 0; + WebRtc_UWord32 arr_ofCSRC[kRtpCsrcSize]; + WebRtc_Word32 no_of_csrcs = rtp_rtcp_.RemoteCSRCs(arr_ofCSRC); + if (no_of_csrcs <= 0) { + arr_ofCSRC[0] = rtp_rtcp_.RemoteSSRC(); + no_of_csrcs = 1; + } + DeliverFrame(video_frame, no_of_csrcs, arr_ofCSRC); + return 0; } WebRtc_Word32 ViEChannel::ReceivedDecodedReferenceFrame( - const WebRtc_UWord64 pictureId) -{ - return _rtpRtcp.SendRTCPReferencePictureSelection(pictureId); + const WebRtc_UWord64 picture_id) { + return rtp_rtcp_.SendRTCPReferencePictureSelection(picture_id); } -// ============================================================================ -// StoreReceivedFrame -// Called by VCM before a frame have been decoded. could be used for recording -// incoming video. -// ============================================================================ - WebRtc_Word32 ViEChannel::StoreReceivedFrame( - const EncodedVideoData& frameToStore) -{ - return 0; + const EncodedVideoData& frame_to_store) { + return 0; } -// ---------------------------------------------------------------------------- -// ReceiveStatistics -// -// Called by VCM with information about received video stream -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::ReceiveStatistics(const WebRtc_UWord32 bitRate, - const WebRtc_UWord32 frameRate) -{ - CriticalSectionScoped cs(_callbackCritsect); - if (_codecObserver) - { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: bitrate %u, framerate %u", __FUNCTION__, bitRate, - frameRate); - _codecObserver->IncomingRate(_channelId, frameRate, bitRate); - } - return 0; +WebRtc_Word32 ViEChannel::ReceiveStatistics(const WebRtc_UWord32 bit_rate, + const WebRtc_UWord32 frame_rate) { + CriticalSectionScoped cs(callbackCritsect_); + if (codec_observer_) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: bitrate %u, framerate %u", __FUNCTION__, bit_rate, + frame_rate); + codec_observer_->IncomingRate(channel_id_, frame_rate, bit_rate); + } + return 0; } -// ---------------------------------------------------------------------------- -// FrameTypeRequest -// -// Called by VCM when a certain frame type is needed to continue decoding -// ---------------------------------------------------------------------------- - -WebRtc_Word32 ViEChannel::FrameTypeRequest(const FrameType frameType) -{ - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s(frameType: %d)", __FUNCTION__, frameType); - - { - CriticalSectionScoped cs(_callbackCritsect); - if (_codecObserver && _doKeyFrameCallbackRequest) - { - _codecObserver->RequestNewKeyFrame(_channelId); - } +WebRtc_Word32 ViEChannel::FrameTypeRequest(const FrameType frame_type) { + WEBRTC_TRACE(kTraceStream, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s(frame_type: %d)", __FUNCTION__, frame_type); + { + CriticalSectionScoped cs(callbackCritsect_); + if (codec_observer_ && do_key_frame_callbackRequest_) { + codec_observer_->RequestNewKeyFrame(channel_id_); } - return _rtpRtcp.RequestKeyFrame(frameType); + } + return rtp_rtcp_.RequestKeyFrame(frame_type); } WebRtc_Word32 ViEChannel::SliceLossIndicationRequest( - const WebRtc_UWord64 pictureId) -{ - return _rtpRtcp.SendRTCPSliceLossIndication((WebRtc_UWord8) pictureId); + const WebRtc_UWord64 picture_id) { + return rtp_rtcp_.SendRTCPSliceLossIndication((WebRtc_UWord8) picture_id); } -// ---------------------------------------------------------------------------- -// ResendPackets -// -// Called by VCM when VCM wants to request resend of packets (NACK) -// ---------------------------------------------------------------------------- -WebRtc_Word32 ViEChannel::ResendPackets(const WebRtc_UWord16* sequenceNumbers, - WebRtc_UWord16 length) -{ - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::ResendPackets(const WebRtc_UWord16* sequence_numbers, + WebRtc_UWord16 length) { + WEBRTC_TRACE(kTraceStream, kTraceVideo, ViEId(engine_id_, channel_id_), "%s(length: %d)", __FUNCTION__, length); - - return _rtpRtcp.SendNACK(sequenceNumbers, length); + return rtp_rtcp_.SendNACK(sequence_numbers, length); } -// ============================================================================ -// Protected methods -// ============================================================================ - -// ---------------------------------------------------------------------------- -// ChannelDecodeThreadFunction -// ---------------------------------------------------------------------------- - -bool ViEChannel::ChannelDecodeThreadFunction(void* obj) -{ - return static_cast (obj)->ChannelDecodeProcess(); +bool ViEChannel::ChannelDecodeThreadFunction(void* obj) { + return static_cast(obj)->ChannelDecodeProcess(); } -// ---------------------------------------------------------------------------- -// ChannelDecodeThreadFunction -// ---------------------------------------------------------------------------- +bool ViEChannel::ChannelDecodeProcess() { + // Decode is blocking, but sleep some time anyway to not get a spin. + vcm_.Decode(kMaxDecodeWaitTimeMs); -bool ViEChannel::ChannelDecodeProcess() -{ - // Decode is blocking, but sleep some time anyway to not get a spin - _vcm.Decode(50); + if ((TickTime::Now() - vcm_rttreported_).Milliseconds() > 1000) { + WebRtc_UWord16 RTT; + WebRtc_UWord16 avgRTT; + WebRtc_UWord16 minRTT; + WebRtc_UWord16 maxRTT; - if ((TickTime::Now() - _vcmRTTReported).Milliseconds() > 1000) - { - WebRtc_UWord16 RTT; - WebRtc_UWord16 avgRTT; - WebRtc_UWord16 minRTT; - WebRtc_UWord16 maxRTT; - - if (_rtpRtcp.RTT(_rtpRtcp.RemoteSSRC(), &RTT, &avgRTT, &minRTT, &maxRTT) - == 0) - { - _vcm.SetReceiveChannelParameters(RTT); - } - _vcmRTTReported = TickTime::Now(); + if (rtp_rtcp_.RTT(rtp_rtcp_.RemoteSSRC(), &RTT, &avgRTT, &minRTT, &maxRTT) + == 0) { + vcm_.SetReceiveChannelParameters(RTT); } - return true; + vcm_rttreported_ = TickTime::Now(); + } + return true; } -// ============================================================================ -// Private methods -// ============================================================================ +WebRtc_Word32 ViEChannel::StartDecodeThread() { + // Start the decode thread + if (decode_thread_) { + // Already started. + return 0; + } + decode_thread_ = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction, + this, kHighestPriority, + "DecodingThread"); + if (!decode_thread_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not create decode thread", __FUNCTION__); + return -1; + } -// ---------------------------------------------------------------------------- -// StartDecodeThread -// -// Assumed to be critsect protected if needed -// ---------------------------------------------------------------------------- + unsigned int thread_id; + if (decode_thread_->Start(thread_id) == false) { + delete decode_thread_; + decode_thread_ = NULL; + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not start decode thread", __FUNCTION__); + return -1; + } -WebRtc_Word32 ViEChannel::StartDecodeThread() -{ - // Start the decode thread - if (_ptrDecodeThread) - { - // Already started - return 0; - } - _ptrDecodeThread = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction, - this, kHighestPriority, - "DecodingThread"); - if (_ptrDecodeThread == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not create decode thread", __FUNCTION__); - return -1; - } - - unsigned int threadId; - if (_ptrDecodeThread->Start(threadId) == false) - { - delete _ptrDecodeThread; - _ptrDecodeThread = NULL; - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not start decode thread", __FUNCTION__); - return -1; - } - - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: decode thread with id %u started", __FUNCTION__); + return 0; +} + +WebRtc_Word32 ViEChannel::StopDecodeThread() { + if (!decode_thread_) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: decode thread not running", __FUNCTION__); return 0; + } + + decode_thread_->SetNotAlive(); + if (decode_thread_->Stop()) { + delete decode_thread_; + } else { + // Couldn't stop the thread, leak instead of crash. + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: could not stop decode thread", __FUNCTION__); + assert(!"could not stop decode thread"); + } + decode_thread_ = NULL; + return 0; } -// ---------------------------------------------------------------------------- -// StopDecodeThread -// -// Assumed to be critsect protected if needed -// ---------------------------------------------------------------------------- +WebRtc_Word32 ViEChannel::RegisterExternalEncryption(Encryption* encryption) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); -WebRtc_Word32 ViEChannel::StopDecodeThread() -{ - if (_ptrDecodeThread == NULL) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: decode thread not running", __FUNCTION__); - return 0; - } + CriticalSectionScoped cs(callbackCritsect_); + if (external_encryption_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external encryption already registered", __FUNCTION__); + return -1; + } - _ptrDecodeThread->SetNotAlive(); - if (_ptrDecodeThread->Stop()) - { - delete _ptrDecodeThread; - } - else - { - // Couldn't stop the thread, leak instead of crash... - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: could not stop decode thread", __FUNCTION__); - assert(!"could not stop decode thread"); - } - _ptrDecodeThread = NULL; - return 0; -} + external_encryption_ = encryption; -#ifdef WEBRTC_SRTP + vie_receiver_.RegisterExternalDecryption(encryption); + vie_sender_.RegisterExternalEncryption(encryption); -WebRtc_Word32 -ViEChannel::EnableSRTPSend(const SrtpModule::CipherTypes cipherType, - const unsigned int cipherKeyLength, - const SrtpModule::AuthenticationTypes authType, - const unsigned int authKeyLength, const unsigned int authTagLength, - const SrtpModule::SecurityLevels level, const WebRtc_UWord8* key, - const bool useForRTCP) -{ - - _callbackCritsect.Enter(); - if (_ptrExternalEncryption) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: external encryption already registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); - - if (!_ptrSrtpModuleEncryption) - { - _ptrSrtpModuleEncryption = - SrtpModule::CreateSrtpModule( - ViEModuleId(_engineId, _channelId)); - if(!_ptrSrtpModuleEncryption) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "Failed to create SRTP module"); - return -1; - } - } - - const WebRtc_Word32 result = - _ptrSrtpModuleEncryption->EnableSRTPEncrypt( - !useForRTCP, cipherType, cipherKeyLength, authType, authKeyLength, - authTagLength,level,key); - if (0 != result) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "EnableSRTPEncrypt result %d, Apply To RTCP %d", result, - useForRTCP); - } - else - { - _vieSender.RegisterSRTPModule(_ptrSrtpModuleEncryption); - if (useForRTCP) - { - _vieSender.RegisterSRTCPModule(_ptrSrtpModuleEncryption); - } - } - return result; -} - -WebRtc_Word32 ViEChannel::DisableSRTPSend() -{ - WebRtc_Word32 result = -1; - if (_ptrSrtpModuleEncryption) - { - result = _ptrSrtpModuleEncryption->DisableSRTPEncrypt(); - _vieSender.DeregisterSRTPModule(); - _vieSender.DeregisterSRTCPModule(); - } - -} - -WebRtc_Word32 -ViEChannel::EnableSRTPReceive(const SrtpModule::CipherTypes cipherType, - const unsigned int cipherKeyLength, - const SrtpModule::AuthenticationTypes authType, - const unsigned int authKeyLength, const unsigned int authTagLength, - const SrtpModule::SecurityLevels level, const WebRtc_UWord8* key, - const bool useForRTCP) -{ - _callbackCritsect.Enter(); - if (_ptrExternalEncryption) - { - _callbackCritsect.Leave(); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: external encryption already registered", __FUNCTION__); - return -1; - } - _callbackCritsect.Leave(); - - if (!_ptrSrtpModuleDecryption) - { - _ptrSrtpModuleDecryption = - SrtpModule::CreateSrtpModule( - ViEModuleId(_engineId, _channelId)); - if(!_ptrSrtpModuleDecryption) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "Failed to create SRTP module"); - return -1; - } - } - - const WebRtc_Word32 result = - _ptrSrtpModuleDecryption->EnableSRTPDecrypt( - !useForRTCP, cipherType, cipherKeyLength, authType, authKeyLength, - authTagLength,level,key); - if (0 != result) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "EnableSRTPEncrypt result %d, Apply To RTCP %d", result, - useForRTCP); - } - else - { - _vieReceiver.RegisterSRTPModule(_ptrSrtpModuleDecryption); - if (useForRTCP) - { - _vieReceiver.RegisterSRTCPModule(_ptrSrtpModuleDecryption); - } - } - return result; -} - -WebRtc_Word32 ViEChannel::DisableSRTPReceive() -{ - WebRtc_Word32 result = -1; - if (_ptrSrtpModuleDecryption) - { - result = _ptrSrtpModuleDecryption->DisableSRTPDecrypt(); - _vieReceiver.DeregisterSRTPModule(); - _vieReceiver.DeregisterSRTPModule(); - } - return result; -} -#endif - -WebRtc_Word32 ViEChannel::RegisterExternalEncryption( - Encryption* encryption) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - CriticalSectionScoped cs(_callbackCritsect); - if (_ptrExternalEncryption) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: external encryption already registered", __FUNCTION__); - return -1; - } - - _ptrExternalEncryption = encryption; - - _vieReceiver.RegisterExternalDecryption(encryption); - _vieSender.RegisterExternalEncryption(encryption); - - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", "external encryption object registerd with channel=%d", - _channelId); - return 0; + channel_id_); + return 0; } -WebRtc_Word32 ViEChannel::DeRegisterExternalEncryption() -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); +WebRtc_Word32 ViEChannel::DeRegisterExternalEncryption() { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); - CriticalSectionScoped cs(_callbackCritsect); - if (!_ptrExternalEncryption) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: external encryption is not registered", __FUNCTION__); - return -1; - } + CriticalSectionScoped cs(callbackCritsect_); + if (!external_encryption_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: external encryption is not registered", __FUNCTION__); + return -1; + } - _ptrExternalTransport = NULL; - _vieReceiver.DeregisterExternalDecryption(); - _vieSender.DeregisterExternalEncryption(); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + external_transport_ = NULL; + vie_receiver_.DeregisterExternalDecryption(); + vie_sender_.DeregisterExternalEncryption(); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s external encryption object de-registerd with channel=%d", - __FUNCTION__, _channelId); - return 0; + __FUNCTION__, channel_id_); + return 0; } -WebRtc_Word32 ViEChannel::SetVoiceChannel(WebRtc_Word32 veChannelId, - VoEVideoSync* veSyncInterface) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), +WebRtc_Word32 ViEChannel::SetVoiceChannel(WebRtc_Word32 ve_channel_id, + VoEVideoSync* ve_sync_interface) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s, audio channel %d, video channel %d", __FUNCTION__, - veChannelId, _channelId); + ve_channel_id, channel_id_); - if (veSyncInterface) - { - // Register lip sync - _moduleProcessThread.RegisterModule(&_vieSync); - } - else - { - _moduleProcessThread.DeRegisterModule(&_vieSync); - } - return _vieSync.SetVoiceChannel(veChannelId, veSyncInterface); + if (ve_sync_interface) { + // Register lip sync + module_process_thread_.RegisterModule(&vie_sync_); + } else { + module_process_thread_.DeRegisterModule(&vie_sync_); + } + return vie_sync_.SetVoiceChannel(ve_channel_id, ve_sync_interface); } -WebRtc_Word32 ViEChannel::VoiceChannel() -{ - return _vieSync.VoiceChannel(); +WebRtc_Word32 ViEChannel::VoiceChannel() { + return vie_sync_.VoiceChannel(); } -WebRtc_Word32 ViEChannel::RegisterEffectFilter(ViEEffectFilter* effectFilter) -{ - CriticalSectionScoped cs(_callbackCritsect); - if (effectFilter == NULL) - { - if (_effectFilter == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: no effect filter added for channel %d", - __FUNCTION__, _channelId); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: deregister effect filter for device %d", __FUNCTION__, - _channelId); +WebRtc_Word32 ViEChannel::RegisterEffectFilter(ViEEffectFilter* effect_filter) { + CriticalSectionScoped cs(callbackCritsect_); + if (!effect_filter) { + if (!effect_filter_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: no effect filter added for channel %d", + __FUNCTION__, channel_id_); + return -1; } - else - { - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: register effect filter for device %d", __FUNCTION__, - _channelId); - if (_effectFilter) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), - "%s: effect filter already added for channel %d", - __FUNCTION__, _channelId); - return -1; - } + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: deregister effect filter for device %d", __FUNCTION__, + channel_id_); + } else { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: register effect filter for device %d", __FUNCTION__, + channel_id_); + if (effect_filter_) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: effect filter already added for channel %d", + __FUNCTION__, channel_id_); + return -1; } - _effectFilter = effectFilter; - return 0; + } + effect_filter_ = effect_filter; + return 0; } -ViEFileRecorder& ViEChannel::GetIncomingFileRecorder() -{ - // Start getting callback of all frames before they are decoded - _vcm.RegisterFrameStorageCallback(this); - return _fileRecorder; +ViEFileRecorder& ViEChannel::GetIncomingFileRecorder() { + // Start getting callback of all frames before they are decoded. + vcm_.RegisterFrameStorageCallback(this); + return file_recorder_; } -void ViEChannel::ReleaseIncomingFileRecorder() -{ - // Stop getting callback of all frames before they are decoded - _vcm.RegisterFrameStorageCallback(NULL); +void ViEChannel::ReleaseIncomingFileRecorder() { + // Stop getting callback of all frames before they are decoded. + vcm_.RegisterFrameStorageCallback(NULL); } void ViEChannel::OnLipSyncUpdate(const WebRtc_Word32 id, - const WebRtc_Word32 audioVideoOffset) -{ - if (_channelId != ChannelId(id)) - { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s, incorrect id", - __FUNCTION__, id); - return; - } - _vieSync.SetNetworkDelay(audioVideoOffset); + const WebRtc_Word32 audio_video_offset) { + if (channel_id_ != ChannelId(id)) { + WEBRTC_TRACE(kTraceStream, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s, incorrect id", __FUNCTION__, id); + return; + } + vie_sync_.SetNetworkDelay(audio_video_offset); } void ViEChannel::OnApplicationDataReceived(const WebRtc_Word32 id, - const WebRtc_UWord8 subType, + const WebRtc_UWord8 sub_type, const WebRtc_UWord32 name, const WebRtc_UWord16 length, - const WebRtc_UWord8* data) -{ - if (_channelId != ChannelId(id)) - { - WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo, - ViEId(_engineId, _channelId), "%s, incorrect id", - __FUNCTION__, id); - return; - } - CriticalSectionScoped cs(_callbackCritsect); - { - if (_rtcpObserver) - { - _rtcpObserver->OnApplicationDataReceived(_channelId, subType, name, - (const char*) data, length); - } + const WebRtc_UWord8* data) { + if (channel_id_ != ChannelId(id)) { + WEBRTC_TRACE(kTraceStream, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s, incorrect id", __FUNCTION__, id); + return; + } + CriticalSectionScoped cs(callbackCritsect_); + { + if (rtcp_observer_) { + rtcp_observer_->OnApplicationDataReceived( + channel_id_, sub_type, name, reinterpret_cast(data), + length); } + } } WebRtc_Word32 ViEChannel::OnInitializeDecoder( - const WebRtc_Word32 id, const WebRtc_Word8 payloadType, - const WebRtc_Word8 payloadName[RTP_PAYLOAD_NAME_SIZE], - const int frequency, const WebRtc_UWord8 channels, - const WebRtc_UWord32 rate) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s: payloadType %d, payloadName %s", __FUNCTION__, payloadType, - payloadName); + const WebRtc_Word32 id, + const WebRtc_Word8 payload_type, + const WebRtc_Word8 payload_name[RTP_PAYLOAD_NAME_SIZE], + const int frequency, + const WebRtc_UWord8 channels, + const WebRtc_UWord32 rate) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s: payload_type %d, payload_name %s", __FUNCTION__, + payload_type, payload_name); + vcm_.ResetDecoder(); - _vcm.ResetDecoder(); - - _callbackCritsect.Enter(); - _decoderReset = true; - _callbackCritsect.Leave(); - - return 0; + callbackCritsect_.Enter(); + decoder_reset_ = true; + callbackCritsect_.Leave(); + return 0; } -void ViEChannel::OnPacketTimeout(const WebRtc_Word32 id) -{ - assert(ChannelId(id) == _channelId); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); +void ViEChannel::OnPacketTimeout(const WebRtc_Word32 id) { + assert(ChannelId(id) == channel_id_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); - CriticalSectionScoped cs(_callbackCritsect); - if (_networkObserver) - { + CriticalSectionScoped cs(callbackCritsect_); + if (networkObserver_) { #ifndef WEBRTC_EXTERNAL_TRANSPORT - if (_socketTransport.Receiving() || _ptrExternalTransport) + if (socket_transport_.Receiving() || external_transport_) { #else - if (_ptrExternalTransport) + if (external_transport_) { #endif - { - _networkObserver->PacketTimeout(_channelId, NoPacket); - _rtpPacketTimeout = true; - } + networkObserver_->PacketTimeout(channel_id_, NoPacket); + rtp_packet_timeout_ = true; } + } } -// -// Called by the rtp module when the first packet is received and -// when first packet after a timeout is received. -// void ViEChannel::OnReceivedPacket(const WebRtc_Word32 id, - const RtpRtcpPacketType packetType) -{ - assert(ChannelId(id) == _channelId); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s", __FUNCTION__); - - if (_rtpPacketTimeout && packetType == kPacketRtp) - { - CriticalSectionScoped cs(_callbackCritsect); - if (_networkObserver) - { - _networkObserver->PacketTimeout(_channelId, PacketReceived); - } - // Reset even if no observer set, might have been removed during timeout - _rtpPacketTimeout = false; + const RtpRtcpPacketType packet_type) { + assert(ChannelId(id) == channel_id_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s", + __FUNCTION__); + if (rtp_packet_timeout_ && packet_type == kPacketRtp) { + CriticalSectionScoped cs(callbackCritsect_); + if (networkObserver_) { + networkObserver_->PacketTimeout(channel_id_, PacketReceived); } + + // Reset even if no observer set, might have been removed during timeout. + rtp_packet_timeout_ = false; + } } void ViEChannel::OnPeriodicDeadOrAlive(const WebRtc_Word32 id, - const RTPAliveType alive) -{ - assert(ChannelId(id) == _channelId); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + const RTPAliveType alive) { + assert(ChannelId(id) == channel_id_); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s(id=%d, alive=%d)", __FUNCTION__, id, alive); - CriticalSectionScoped cs(_callbackCritsect); - if (!_networkObserver) - { - return; - } - bool isAlive = true; - if (alive == kRtpDead) - { - isAlive = false; - } - _networkObserver->OnPeriodicDeadOrAlive(_channelId, isAlive); + CriticalSectionScoped cs(callbackCritsect_); + if (!networkObserver_) { return; + } + bool is_alive = true; + if (alive == kRtpDead) { + is_alive = false; + } + networkObserver_->OnPeriodicDeadOrAlive(channel_id_, is_alive); + return; } void ViEChannel::OnIncomingSSRCChanged(const WebRtc_Word32 id, - const WebRtc_UWord32 SSRC) -{ - if (_channelId != ChannelId(id)) - { - assert(false); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s, incorrect id", __FUNCTION__, id); - return; - } + const WebRtc_UWord32 SSRC) { + if (channel_id_ != ChannelId(id)) { + assert(false); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s, incorrect id", __FUNCTION__, id); + return; + } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: %u", __FUNCTION__, SSRC); - CriticalSectionScoped cs(_callbackCritsect); - { - if (_rtpObserver) - { - _rtpObserver->IncomingSSRCChanged(_channelId, SSRC); - } + CriticalSectionScoped cs(callbackCritsect_); + { + if (rtp_observer_) { + rtp_observer_->IncomingSSRCChanged(channel_id_, SSRC); } + } } void ViEChannel::OnIncomingCSRCChanged(const WebRtc_Word32 id, const WebRtc_UWord32 CSRC, - const bool added) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + const bool added) { + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: %u added: %d", __FUNCTION__, CSRC, added); - if (_channelId != ChannelId(id)) - { - assert(false); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), - "%s, incorrect id", __FUNCTION__, id); - return; - } + if (channel_id_ != ChannelId(id)) { + assert(false); + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), + "%s, incorrect id", __FUNCTION__, id); + return; + } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId, _channelId), + WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, channel_id_), "%s: %u", __FUNCTION__, CSRC); - CriticalSectionScoped cs(_callbackCritsect); - { - if (_rtpObserver) - { - _rtpObserver->IncomingCSRCChanged(_channelId, CSRC, added); - } + CriticalSectionScoped cs(callbackCritsect_); + { + if (rtp_observer_) { + rtp_observer_->IncomingCSRCChanged(channel_id_, CSRC, added); } + } } -WebRtc_Word32 ViEChannel::SetInverseH263Logic(const bool enable) -{ - return _rtpRtcp.SetH263InverseLogic(enable); +WebRtc_Word32 ViEChannel::SetInverseH263Logic(const bool enable) { + return rtp_rtcp_.SetH263InverseLogic(enable); } -} // namespace webrtc +} // namespace webrtc diff --git a/src/video_engine/vie_channel.h b/src/video_engine/vie_channel.h index ead3f19f9..a29ccd6bc 100644 --- a/src/video_engine/vie_channel.h +++ b/src/video_engine/vie_channel.h @@ -8,38 +8,26 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * vie_channel.h - */ +// vie_channel.h -#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CHANNEL_H_ -#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CHANNEL_H_ +#ifndef WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_H_ +#define WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_H_ #include -// Defines -#include "vie_defines.h" - +#include "modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "modules/udp_transport/interface/udp_transport.h" +#include "modules/video_coding/main/interface/video_coding_defines.h" +#include "system_wrappers/interface/tick_util.h" #include "typedefs.h" -#include "vie_network.h" -#include "vie_rtp_rtcp.h" -#include "rtp_rtcp_defines.h" -#include "udp_transport.h" -#include "video_coding_defines.h" -#ifdef WEBRTC_SRTP -#include "SrtpModule.h" -#endif -#include "tick_util.h" -#include "vie_frame_provider_base.h" -#include "vie_file_recorder.h" +#include "video_engine/main/interface/vie_network.h" +#include "video_engine/main/interface/vie_rtp_rtcp.h" +#include "video_engine/vie_defines.h" +#include "video_engine/vie_file_recorder.h" +#include "video_engine/vie_frame_provider_base.h" -// Forward declarations +namespace webrtc { -class SrtpModule; -class VideoRenderCallback; - -namespace webrtc -{ class CriticalSectionWrapper; class Encryption; class ProcessThread; @@ -47,6 +35,7 @@ class RtpRtcp; class ThreadWrapper; class VideoCodingModule; class VideoDecoder; +class VideoRenderCallback; class ViEDecoderObserver; class ViEEffectFilter; class ViENetworkObserver; @@ -57,437 +46,353 @@ class ViESender; class ViESyncModule; class VoEVideoSync; -class ViEChannel: - public VCMFrameTypeCallback, // VCM Module - public VCMReceiveCallback, // VCM Module - public VCMReceiveStatisticsCallback, // VCM Module - public VCMPacketRequestCallback, // VCM Module - public VCMFrameStorageCallback, // VCM Module - public RtcpFeedback, // RTP/RTCP Module - public RtpFeedback, // RTP/RTCP Module - public ViEFrameProviderBase -{ -public: - ViEChannel(WebRtc_Word32 channelId, WebRtc_Word32 engineId, - WebRtc_UWord32 numberOfCores, - ProcessThread& moduleProcessThread); - ~ViEChannel(); +class ViEChannel + : public VCMFrameTypeCallback, + public VCMReceiveCallback, + public VCMReceiveStatisticsCallback, + public VCMPacketRequestCallback, + public VCMFrameStorageCallback, + public RtcpFeedback, + public RtpFeedback, + public ViEFrameProviderBase { + public: + ViEChannel(WebRtc_Word32 channel_id, + WebRtc_Word32 engine_id, + WebRtc_UWord32 number_of_cores, + ProcessThread& module_process_thread); + ~ViEChannel(); + + WebRtc_Word32 Init(); + + // Sets the encoder to use for the channel. |new_stream| indicates the encoder + // type has changed and we should start a new RTP stream. + WebRtc_Word32 SetSendCodec(const VideoCodec& video_codec, + bool new_stream = true); + WebRtc_Word32 SetReceiveCodec(const VideoCodec& video_codec); + WebRtc_Word32 GetReceiveCodec(VideoCodec& video_codec); + WebRtc_Word32 RegisterCodecObserver(ViEDecoderObserver* observer); + // Registers an external decoder. |decoder_render| is set to true if the + // decoder will do the rendering. If |decoder_render| is set,|render_delay| + // indicates the time needed to decode and render a frame. + WebRtc_Word32 RegisterExternalDecoder(const WebRtc_UWord8 pl_type, + VideoDecoder* decoder, + bool decoder_render, + WebRtc_Word32 render_delay); + WebRtc_Word32 DeRegisterExternalDecoder(const WebRtc_UWord8 pl_type); + WebRtc_Word32 ReceiveCodecStatistics(WebRtc_UWord32& num_key_frames, + WebRtc_UWord32& num_delta_frames); + WebRtc_UWord32 DiscardedPackets() const; + + // Only affects calls to SetReceiveCodec done after this call. + WebRtc_Word32 WaitForKeyFrame(bool wait); + + // If enabled, a key frame request will be sent as soon as there are lost + // packets. If |only_key_frames| are set, requests are only sent for loss in + // key frames. + WebRtc_Word32 SetSignalPacketLossStatus(bool enable, bool only_key_frames); + + WebRtc_Word32 SetRTCPMode(const RTCPMethod rtcp_mode); + WebRtc_Word32 GetRTCPMode(RTCPMethod& rtcp_mode); + WebRtc_Word32 SetNACKStatus(const bool enable); + WebRtc_Word32 SetFECStatus(const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC); + WebRtc_Word32 SetHybridNACKFECStatus(const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC); + WebRtc_Word32 SetKeyFrameRequestMethod(const KeyFrameRequestMethod method); + WebRtc_Word32 EnableTMMBR(const bool enable); + WebRtc_Word32 EnableKeyFrameRequestCallback(const bool enable); + + // Sets SSRC for outgoing stream. + WebRtc_Word32 SetSSRC(const WebRtc_UWord32 SSRC, + const StreamType usage, + const unsigned char simulcast_idx); + + // Gets SSRC for outgoing stream. + WebRtc_Word32 GetLocalSSRC(WebRtc_UWord32& SSRC); + + // Gets SSRC for the incoming stream. + WebRtc_Word32 GetRemoteSSRC(WebRtc_UWord32& SSRC); + + // Gets the CSRC for the incoming stream. + WebRtc_Word32 GetRemoteCSRC(unsigned int CSRCs[kRtpCsrcSize]); + + // Sets the starting sequence number, must be called before StartSend. + WebRtc_Word32 SetStartSequenceNumber(WebRtc_UWord16 sequence_number); + + // Sets the CName for the outgoing stream on the channel. + WebRtc_Word32 SetRTCPCName(const WebRtc_Word8 rtcp_cname[]); + + // Gets the CName for the outgoing stream on the channel. + WebRtc_Word32 GetRTCPCName(WebRtc_Word8 rtcp_cname[]); + + // Gets the CName of the incoming stream. + WebRtc_Word32 GetRemoteRTCPCName(WebRtc_Word8 rtcp_cname[]); + WebRtc_Word32 RegisterRtpObserver(ViERTPObserver* observer); + WebRtc_Word32 RegisterRtcpObserver(ViERTCPObserver* observer); + WebRtc_Word32 SendApplicationDefinedRTCPPacket( + const WebRtc_UWord8 sub_type, + WebRtc_UWord32 name, + const WebRtc_UWord8* data, + WebRtc_UWord16 data_length_in_bytes); + + // Gets statistics sent in RTCP packets to remote side. + WebRtc_Word32 GetSendRtcpStatistics(WebRtc_UWord16& fraction_lost, + WebRtc_UWord32& cumulative_lost, + WebRtc_UWord32& extended_max, + WebRtc_UWord32& jitter_samples, + WebRtc_Word32& rtt_ms); + + // Gets statistics received in RTCP packets from remote side. + WebRtc_Word32 GetReceivedRtcpStatistics(WebRtc_UWord16& fraction_lost, + WebRtc_UWord32& cumulative_lost, + WebRtc_UWord32& extended_max, + WebRtc_UWord32& jitter_samples, + WebRtc_Word32& rtt_ms); + + // Gets sent/received packets statistics. + WebRtc_Word32 GetRtpStatistics(WebRtc_UWord32& bytes_sent, + WebRtc_UWord32& packets_sent, + WebRtc_UWord32& bytes_received, + WebRtc_UWord32& packets_received) const; + void GetBandwidthUsage(WebRtc_UWord32& total_bitrate_sent, + WebRtc_UWord32& video_bitrate_sent, + WebRtc_UWord32& fec_bitrate_sent, + WebRtc_UWord32& nackBitrateSent) const; + WebRtc_Word32 SetKeepAliveStatus(const bool enable, + const WebRtc_Word8 unknown_payload_type, + const WebRtc_UWord16 delta_transmit_timeMS); + WebRtc_Word32 GetKeepAliveStatus(bool& enable, + WebRtc_Word8& unknown_payload_type, + WebRtc_UWord16& delta_transmit_timeMS); + WebRtc_Word32 StartRTPDump(const char file_nameUTF8[1024], + RTPDirections direction); + WebRtc_Word32 StopRTPDump(RTPDirections direction); + + // Implements RtcpFeedback. + virtual void OnLipSyncUpdate(const WebRtc_Word32 id, + const WebRtc_Word32 audio_video_offset); + virtual void OnApplicationDataReceived(const WebRtc_Word32 id, + const WebRtc_UWord8 sub_type, + const WebRtc_UWord32 name, + const WebRtc_UWord16 length, + const WebRtc_UWord8* data); + + // Implements RtpFeedback. + virtual WebRtc_Word32 OnInitializeDecoder( + const WebRtc_Word32 id, + const WebRtc_Word8 payload_type, + const WebRtc_Word8 payload_name[RTP_PAYLOAD_NAME_SIZE], + const int frequency, + const WebRtc_UWord8 channels, + const WebRtc_UWord32 rate); + virtual void OnPacketTimeout(const WebRtc_Word32 id); + virtual void OnReceivedPacket(const WebRtc_Word32 id, + const RtpRtcpPacketType packet_type); + virtual void OnPeriodicDeadOrAlive(const WebRtc_Word32 id, + const RTPAliveType alive); + virtual void OnIncomingSSRCChanged(const WebRtc_Word32 id, + const WebRtc_UWord32 SSRC); + virtual void OnIncomingCSRCChanged(const WebRtc_Word32 id, + const WebRtc_UWord32 CSRC, + const bool added); + + WebRtc_Word32 SetLocalReceiver(const WebRtc_UWord16 rtp_port, + const WebRtc_UWord16 rtcp_port, + const WebRtc_Word8* ip_address); + WebRtc_Word32 GetLocalReceiver(WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_Word8* ip_address) const; + WebRtc_Word32 SetSendDestination(const WebRtc_Word8* ip_address, + const WebRtc_UWord16 rtp_port, + const WebRtc_UWord16 rtcp_port, + const WebRtc_UWord16 source_rtp_port, + const WebRtc_UWord16 source_rtcp_port); + WebRtc_Word32 GetSendDestination(WebRtc_Word8* ip_address, + WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_UWord16& source_rtp_port, + WebRtc_UWord16& source_rtcp_port) const; + WebRtc_Word32 GetSourceInfo(WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_Word8* ip_address, + WebRtc_UWord32 ip_address_length); + + + WebRtc_Word32 StartSend(); + WebRtc_Word32 StopSend(); + bool Sending(); + WebRtc_Word32 StartReceive(); + WebRtc_Word32 StopReceive(); + bool Receiving(); + + WebRtc_Word32 RegisterSendTransport(Transport& transport); + WebRtc_Word32 DeregisterSendTransport(); + + // Incoming packet from external transport. + WebRtc_Word32 ReceivedRTPPacket(const void* rtp_packet, + const WebRtc_Word32 rtp_packet_length); + + // Incoming packet from external transport. + WebRtc_Word32 ReceivedRTCPPacket(const void* rtcp_packet, + const WebRtc_Word32 rtcp_packet_length); + + WebRtc_Word32 EnableIPv6(); + bool IsIPv6Enabled(); + WebRtc_Word32 SetSourceFilter(const WebRtc_UWord16 rtp_port, + const WebRtc_UWord16 rtcp_port, + const WebRtc_Word8* ip_address); + WebRtc_Word32 GetSourceFilter(WebRtc_UWord16& rtp_port, + WebRtc_UWord16& rtcp_port, + WebRtc_Word8* ip_address) const; + + WebRtc_Word32 SetToS(const WebRtc_Word32 DSCP, const bool use_set_sockOpt); + WebRtc_Word32 GetToS(WebRtc_Word32& DSCP, bool& use_set_sockOpt) const; + WebRtc_Word32 SetSendGQoS(const bool enable, + const WebRtc_Word32 service_type, + const WebRtc_UWord32 max_bitrate, + const WebRtc_Word32 overrideDSCP); + WebRtc_Word32 GetSendGQoS(bool& enabled, WebRtc_Word32& service_type, + WebRtc_Word32& overrideDSCP) const; + + // Sets the maximum transfer unit size for the network link, i.e. including + // IP, UDP and RTP headers. + WebRtc_Word32 SetMTU(WebRtc_UWord16 mtu); + + // Returns maximum allowed payload size, i.e. the maximum allowed size of + // encoded data in each packet. + WebRtc_UWord16 MaxDataPayloadLength() const; + WebRtc_Word32 SetMaxPacketBurstSize(WebRtc_UWord16 max_number_of_packets); + WebRtc_Word32 SetPacketBurstSpreadState(bool enable, + const WebRtc_UWord16 frame_periodMS); + + WebRtc_Word32 SetPacketTimeoutNotification(bool enable, + WebRtc_UWord32 timeout_seconds); + WebRtc_Word32 RegisterNetworkObserver(ViENetworkObserver* observer); + bool NetworkObserverRegistered(); + WebRtc_Word32 SetPeriodicDeadOrAliveStatus( + const bool enable, const WebRtc_UWord32 sample_time_seconds); + + WebRtc_Word32 SendUDPPacket(const WebRtc_Word8* data, + const WebRtc_UWord32 length, + WebRtc_Word32& transmitted_bytes, + bool use_rtcp_socket); + + WebRtc_Word32 EnableColorEnhancement(bool enable); + + // Register send RTP RTCP module, which will deliver encoded frames to the + // to the channel RTP module. + WebRtc_Word32 RegisterSendRtpRtcpModule(RtpRtcp& send_rtp_rtcp_module); + + // Deregisters the send RTP RTCP module, which will stop the encoder input to + // the channel. + WebRtc_Word32 DeregisterSendRtpRtcpModule(); + + // Implements VCMReceiveCallback. + virtual WebRtc_Word32 FrameToRender(VideoFrame& video_frame); + + // Implements VCMReceiveCallback. + virtual WebRtc_Word32 ReceivedDecodedReferenceFrame( + const WebRtc_UWord64 picture_id); + + // Implements VCM. + virtual WebRtc_Word32 StoreReceivedFrame( + const EncodedVideoData& frame_to_store); + + // Implements VideoReceiveStatisticsCallback. + virtual WebRtc_Word32 ReceiveStatistics(const WebRtc_UWord32 bit_rate, + const WebRtc_UWord32 frame_rate); + + // Implements VideoFrameTypeCallback. + virtual WebRtc_Word32 FrameTypeRequest(const FrameType frame_type); + + // Implements VideoFrameTypeCallback. + virtual WebRtc_Word32 SliceLossIndicationRequest( + const WebRtc_UWord64 picture_id); + + // Implements VideoPacketRequestCallback. + virtual WebRtc_Word32 ResendPackets(const WebRtc_UWord16* sequence_numbers, + WebRtc_UWord16 length); + + WebRtc_Word32 RegisterExternalEncryption(Encryption* encryption); + WebRtc_Word32 DeRegisterExternalEncryption(); + + WebRtc_Word32 SetVoiceChannel(WebRtc_Word32 ve_channel_id, + VoEVideoSync* ve_sync_interface); + WebRtc_Word32 VoiceChannel(); + + // Implements ViEFrameProviderBase. + virtual int FrameCallbackChanged() {return -1;} + + WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter); + + WebRtc_Word32 SetInverseH263Logic(const bool enable); + + ViEFileRecorder& GetIncomingFileRecorder(); + void ReleaseIncomingFileRecorder(); + + protected: + static bool ChannelDecodeThreadFunction(void* obj); + bool ChannelDecodeProcess(); + + private: + // Assumed to be protected. + WebRtc_Word32 StartDecodeThread(); + WebRtc_Word32 StopDecodeThread(); + + WebRtc_Word32 ProcessNACKRequest(const bool enable); + WebRtc_Word32 ProcessFECRequest(const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC); + + WebRtc_Word32 channel_id_; + WebRtc_Word32 engine_id_; + WebRtc_UWord32 number_of_cores_; + WebRtc_UWord8 num_socket_threads_; + + // Used for all registered callbacks except rendering. + CriticalSectionWrapper& callbackCritsect_; - WebRtc_Word32 Init(); - - //----------------------------------------------------------------- - // Codecs - //----------------------------------------------------------------- - - WebRtc_Word32 SetSendCodec(const VideoCodec& videoCodec, - bool newStream = true); - - WebRtc_Word32 SetReceiveCodec(const VideoCodec& videoCodec); - - WebRtc_Word32 GetReceiveCodec(VideoCodec& videoCodec); - - WebRtc_Word32 RegisterCodecObserver(ViEDecoderObserver* observer); - - WebRtc_Word32 RegisterExternalDecoder(const WebRtc_UWord8 plType, - VideoDecoder* decoder, - bool decoderRender, - WebRtc_Word32 renderDelay); - - WebRtc_Word32 DeRegisterExternalDecoder(const WebRtc_UWord8 plType); - - WebRtc_Word32 ReceiveCodecStatistics(WebRtc_UWord32& numKeyFrames, - WebRtc_UWord32& numDeltaFrames); - - WebRtc_UWord32 DiscardedPackets() const; - - WebRtc_Word32 WaitForKeyFrame(bool wait); - - WebRtc_Word32 SetSignalPacketLossStatus(bool enable, bool onlyKeyFrames); - - //----------------------------------------------------------------- - // RTP/RTCP - //----------------------------------------------------------------- - WebRtc_Word32 SetRTCPMode(const RTCPMethod rtcpMode); - - WebRtc_Word32 GetRTCPMode(RTCPMethod& rtcpMode); - - WebRtc_Word32 SetNACKStatus(const bool enable); - - WebRtc_Word32 SetFECStatus(const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC); - WebRtc_Word32 SetHybridNACKFECStatus(const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC); - - WebRtc_Word32 SetKeyFrameRequestMethod(const KeyFrameRequestMethod method); - - WebRtc_Word32 EnableTMMBR(const bool enable); - - WebRtc_Word32 EnableKeyFrameRequestCallback(const bool enable); - - WebRtc_Word32 SetSSRC(const WebRtc_UWord32 SSRC, - const StreamType usage, - const unsigned char simulcastIdx); - - WebRtc_Word32 GetLocalSSRC(WebRtc_UWord32& SSRC); - - WebRtc_Word32 GetRemoteSSRC(WebRtc_UWord32& SSRC); - - WebRtc_Word32 GetRemoteCSRC(unsigned int CSRCs[kRtpCsrcSize]); - - WebRtc_Word32 SetStartSequenceNumber(WebRtc_UWord16 sequenceNumber); - - WebRtc_Word32 SetRTCPCName(const WebRtc_Word8 rtcpCName[]); - - WebRtc_Word32 GetRTCPCName(WebRtc_Word8 rtcpCName[]); - - WebRtc_Word32 GetRemoteRTCPCName(WebRtc_Word8 rtcpCName[]); - - WebRtc_Word32 RegisterRtpObserver(ViERTPObserver* observer); - - WebRtc_Word32 RegisterRtcpObserver(ViERTCPObserver* observer); - - WebRtc_Word32 SendApplicationDefinedRTCPPacket( - const WebRtc_UWord8 subType, - WebRtc_UWord32 name, - const WebRtc_UWord8* data, - WebRtc_UWord16 dataLengthInBytes); - - WebRtc_Word32 GetSendRtcpStatistics(WebRtc_UWord16& fractionLost, - WebRtc_UWord32& cumulativeLost, - WebRtc_UWord32& extendedMax, - WebRtc_UWord32& jitterSamples, - WebRtc_Word32& rttMs); - - WebRtc_Word32 GetReceivedRtcpStatistics(WebRtc_UWord16& fractionLost, - WebRtc_UWord32& cumulativeLost, - WebRtc_UWord32& extendedMax, - WebRtc_UWord32& jitterSamples, - WebRtc_Word32& rttMs); - - WebRtc_Word32 GetRtpStatistics(WebRtc_UWord32& bytesSent, - WebRtc_UWord32& packetsSent, - WebRtc_UWord32& bytesReceived, - WebRtc_UWord32& packetsReceived) const; - - void GetBandwidthUsage(WebRtc_UWord32& totalBitrateSent, - WebRtc_UWord32& videoBitrateSent, - WebRtc_UWord32& fecBitrateSent, - WebRtc_UWord32& nackBitrateSent) const; - - WebRtc_Word32 SetKeepAliveStatus(const bool enable, - const WebRtc_Word8 unknownPayloadType, - const WebRtc_UWord16 deltaTransmitTimeMS); - - WebRtc_Word32 GetKeepAliveStatus(bool& enable, - WebRtc_Word8& unknownPayloadType, - WebRtc_UWord16& deltaTransmitTimeMS); - - WebRtc_Word32 StartRTPDump(const char fileNameUTF8[1024], - RTPDirections direction); - - WebRtc_Word32 StopRTPDump(RTPDirections direction); - - // Implements RtcpFeedback - virtual void OnLipSyncUpdate(const WebRtc_Word32 id, - const WebRtc_Word32 audioVideoOffset); - - virtual void OnApplicationDataReceived(const WebRtc_Word32 id, - const WebRtc_UWord8 subType, - const WebRtc_UWord32 name, - const WebRtc_UWord16 length, - const WebRtc_UWord8* data); - - // Implements RtpFeedback - virtual WebRtc_Word32 OnInitializeDecoder( - const WebRtc_Word32 id, - const WebRtc_Word8 payloadType, - const WebRtc_Word8 payloadName[RTP_PAYLOAD_NAME_SIZE], - const int frequency, - const WebRtc_UWord8 channels, - const WebRtc_UWord32 rate); - - virtual void OnPacketTimeout(const WebRtc_Word32 id); - - virtual void OnReceivedPacket(const WebRtc_Word32 id, - const RtpRtcpPacketType packetType); - - virtual void OnPeriodicDeadOrAlive(const WebRtc_Word32 id, - const RTPAliveType alive); - - virtual void OnIncomingSSRCChanged(const WebRtc_Word32 id, - const WebRtc_UWord32 SSRC); - - virtual void OnIncomingCSRCChanged(const WebRtc_Word32 id, - const WebRtc_UWord32 CSRC, - const bool added); - - //----------------------------------------------------------------- - // Network - //----------------------------------------------------------------- - - // Soure and destination - WebRtc_Word32 SetLocalReceiver(const WebRtc_UWord16 rtpPort, - const WebRtc_UWord16 rtcpPort, - const WebRtc_Word8* ipAddress); - - WebRtc_Word32 GetLocalReceiver(WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_Word8* ipAddress) const; - - WebRtc_Word32 SetSendDestination(const WebRtc_Word8* ipAddress, - const WebRtc_UWord16 rtpPort, - const WebRtc_UWord16 rtcpPort, - const WebRtc_UWord16 sourceRtpPort, - const WebRtc_UWord16 sourceRtcpPort); - - WebRtc_Word32 GetSendDestination(WebRtc_Word8* ipAddress, - WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_UWord16& sourceRtpPort, - WebRtc_UWord16& sourceRtcpPort) const; - - WebRtc_Word32 GetSourceInfo(WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_Word8* ipAddress, - WebRtc_UWord32 ipAddressLength); - - // Start/Stop Send/Receive - WebRtc_Word32 StartSend(); - WebRtc_Word32 StopSend(); - bool Sending(); - WebRtc_Word32 StartReceive(); - WebRtc_Word32 StopReceive(); - bool Receiving(); - - // External transport - WebRtc_Word32 RegisterSendTransport(Transport& transport); - - WebRtc_Word32 DeregisterSendTransport(); - - WebRtc_Word32 ReceivedRTPPacket(const void* rtpPacket, - const WebRtc_Word32 rtpPacketLength); - - WebRtc_Word32 ReceivedRTCPPacket(const void* rtcpPacket, - const WebRtc_Word32 rtcpPacketLength); - - // IPv6 - WebRtc_Word32 EnableIPv6(); - - bool IsIPv6Enabled(); - - // Source IP address and port filter - WebRtc_Word32 SetSourceFilter(const WebRtc_UWord16 rtpPort, - const WebRtc_UWord16 rtcpPort, - const WebRtc_Word8* ipAddress); - - WebRtc_Word32 GetSourceFilter(WebRtc_UWord16& rtpPort, - WebRtc_UWord16& rtcpPort, - WebRtc_Word8* ipAddress) const; - - // ToS - WebRtc_Word32 SetToS(const WebRtc_Word32 DSCP, const bool useSetSockOpt); - - WebRtc_Word32 GetToS(WebRtc_Word32& DSCP, bool& useSetSockOpt) const; - - // GQoS - WebRtc_Word32 SetSendGQoS(const bool enable, - const WebRtc_Word32 serviceType, - const WebRtc_UWord32 maxBitrate, - const WebRtc_Word32 overrideDSCP); - - WebRtc_Word32 GetSendGQoS(bool& enabled, WebRtc_Word32& serviceType, - WebRtc_Word32& overrideDSCP) const; - - // Network settings - WebRtc_Word32 SetMTU(WebRtc_UWord16 mtu); - - WebRtc_UWord16 MaxDataPayloadLength() const; - - WebRtc_Word32 SetMaxPacketBurstSize(WebRtc_UWord16 maxNumberOfPackets); - - WebRtc_Word32 SetPacketBurstSpreadState(bool enable, - const WebRtc_UWord16 framePeriodMS); - - // Packet timout notification - WebRtc_Word32 SetPacketTimeoutNotification(bool enable, - WebRtc_UWord32 timeoutSeconds); - - // Periodic dead-or-alive reports - WebRtc_Word32 RegisterNetworkObserver(ViENetworkObserver* observer); - bool NetworkObserverRegistered(); - - WebRtc_Word32 - SetPeriodicDeadOrAliveStatus(const bool enable, - const WebRtc_UWord32 sampleTimeSeconds); - - WebRtc_Word32 SendUDPPacket(const WebRtc_Word8* data, - const WebRtc_UWord32 length, - WebRtc_Word32& transmittedBytes, - bool useRtcpSocket); - - //----------------------------------------------------------------- - // Image processing - //----------------------------------------------------------------- - WebRtc_Word32 EnableColorEnhancement(bool enable); - - //----------------------------------------------------------------- - // Register sender - //----------------------------------------------------------------- - WebRtc_Word32 - RegisterSendRtpRtcpModule(RtpRtcp& sendRtpRtcpModule); - - WebRtc_Word32 DeregisterSendRtpRtcpModule(); - - // Implements VCM::VCMReceiveCallback, getting decoded frames from - // VCM. - virtual WebRtc_Word32 FrameToRender(VideoFrame& videoFrame); - - // Implements VCM::VCMReceiveCallback, getting info about decoded - // frames from VCM. - virtual WebRtc_Word32 ReceivedDecodedReferenceFrame( - const WebRtc_UWord64 pictureId); - - //Implements VCM::VideoFrameStorageCallback - virtual WebRtc_Word32 StoreReceivedFrame( - const EncodedVideoData& frameToStore); - - // Implements VCM::VideoReceiveStatisticsCallback - virtual WebRtc_Word32 ReceiveStatistics(const WebRtc_UWord32 bitRate, - const WebRtc_UWord32 frameRate); - - // Implements VCM::VideoFrameTypeCallback - virtual WebRtc_Word32 FrameTypeRequest(const FrameType frameType); - - // Implements VCM::VideoFrameTypeCallback - virtual WebRtc_Word32 SliceLossIndicationRequest( - const WebRtc_UWord64 pictureId); - - // Implements VCM::VideoPacketRequestCallback - virtual WebRtc_Word32 ResendPackets(const WebRtc_UWord16* sequenceNumbers, - WebRtc_UWord16 length); - -#ifdef WEBRTC_SRTP - //SRTP - WebRtc_Word32 EnableSRTPSend( - const SrtpModule::CipherTypes cipherType, - const unsigned int cipherKeyLength, - const SrtpModule::AuthenticationTypes authType, - const unsigned int authKeyLength, - const unsigned int authTagLength, - const SrtpModule::SecurityLevels level, - const WebRtc_UWord8* key, - const bool useForRTCP); - - WebRtc_Word32 DisableSRTPSend(); - - WebRtc_Word32 EnableSRTPReceive( - const SrtpModule::CipherTypes cipherType, - const unsigned int cipherKeyLength, - const SrtpModule::AuthenticationTypes authType, - const unsigned int authKeyLength, - const unsigned int authTagLength, - const SrtpModule::SecurityLevels level, - const WebRtc_UWord8* key, - const bool useForRTCP); - WebRtc_Word32 DisableSRTPReceive(); -#endif - - WebRtc_Word32 RegisterExternalEncryption(Encryption* encryption); - WebRtc_Word32 DeRegisterExternalEncryption(); - - //Voice Engine - WebRtc_Word32 SetVoiceChannel(WebRtc_Word32 veChannelId, - VoEVideoSync* veSyncInterface); - WebRtc_Word32 VoiceChannel(); - - //ViEFrameProviderBase - virtual int FrameCallbackChanged(){return -1;} - - // Effect filter - WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effectFilter); - - WebRtc_Word32 SetInverseH263Logic(const bool enable); - - // File recording - ViEFileRecorder& GetIncomingFileRecorder(); - void ReleaseIncomingFileRecorder(); - -protected: - // Thread function according to ThreadWrapper - static bool ChannelDecodeThreadFunction(void* obj); - bool ChannelDecodeProcess(); - -private: - - WebRtc_Word32 StartDecodeThread(); - WebRtc_Word32 StopDecodeThread(); - - // Protection - WebRtc_Word32 ProcessNACKRequest(const bool enable); - - WebRtc_Word32 ProcessFECRequest(const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC); - - // General members - WebRtc_Word32 _channelId; - WebRtc_Word32 _engineId; - WebRtc_UWord32 _numberOfCores; - WebRtc_UWord8 _numSocketThreads; - - // Critical sections - // Used for all registered callbacks except rendering. - CriticalSectionWrapper& _callbackCritsect; - - // Owned modules/classes - RtpRtcp& _rtpRtcp; - RtpRtcp* _defaultRtpRtcp; - std::list _simulcastRtpRtcp; + // Owned modules/classes. + RtpRtcp& rtp_rtcp_; + RtpRtcp* default_rtp_rtcp_; + std::list simulcast_rtp_rtcp_; #ifndef WEBRTC_EXTERNAL_TRANSPORT - UdpTransport& _socketTransport; + UdpTransport& socket_transport_; #endif - VideoCodingModule& _vcm; - ViEReceiver& _vieReceiver; - ViESender& _vieSender; - ViESyncModule& _vieSync;//Lip syncronization + VideoCodingModule& vcm_; + ViEReceiver& vie_receiver_; + ViESender& vie_sender_; + ViESyncModule& vie_sync_; - //Uses - ProcessThread& _moduleProcessThread; - ViEDecoderObserver* _codecObserver; - bool _doKeyFrameCallbackRequest; - ViERTPObserver* _rtpObserver; - ViERTCPObserver* _rtcpObserver; - ViENetworkObserver* _networkObserver; - bool _rtpPacketTimeout; - bool _usingPacketSpread; + // Not owned. + ProcessThread& module_process_thread_; + ViEDecoderObserver* codec_observer_; + bool do_key_frame_callbackRequest_; + ViERTPObserver* rtp_observer_; + ViERTCPObserver* rtcp_observer_; + ViENetworkObserver* networkObserver_; + bool rtp_packet_timeout_; + bool using_packet_spread_; - // Registered members - Transport* _ptrExternalTransport; + Transport* external_transport_; - // Codec - bool _decoderReset; - bool _waitForKeyFrame; + bool decoder_reset_; + bool wait_for_key_frame_; + ThreadWrapper* decode_thread_; - // Decoder - ThreadWrapper* _ptrDecodeThread; + Encryption* external_encryption_; - //SRTP - using seperate pointers for encryption and decryption to support - // simultaneous operations. - SrtpModule* _ptrSrtpModuleEncryption; - SrtpModule* _ptrSrtpModuleDecryption; - Encryption* _ptrExternalEncryption; + ViEEffectFilter* effect_filter_; + bool color_enhancement_; - // Effect filter and color enhancement - ViEEffectFilter* _effectFilter; - bool _colorEnhancement; + // Time when RTT time was last reported to VCM JB. + TickTime vcm_rttreported_; - // Time when RTT time was last reported to VCM JB. - TickTime _vcmRTTReported; - - //Recording - ViEFileRecorder _fileRecorder; + ViEFileRecorder file_recorder_; }; -} // namespace webrtc -#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CHANNEL_H_ + +} // namespace webrtc + +#endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_H_