From 8da2417c9d61fbe71994ea8b837c9d2e4986bbde Mon Sep 17 00:00:00 2001 From: "mflodman@webrtc.org" Date: Mon, 19 Dec 2011 14:18:41 +0000 Subject: [PATCH] Refactored ViERenderImpl and ViERTP_RTCPImpl. Review URL: http://webrtc-codereview.appspot.com/329005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1232 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/interface/vie_rtp_rtcp.h | 6 +- src/video_engine/vie_render_impl.cc | 857 +++---- src/video_engine/vie_render_impl.h | 98 +- src/video_engine/vie_rtp_rtcp_impl.cc | 2081 ++++++----------- src/video_engine/vie_rtp_rtcp_impl.h | 240 +- 5 files changed, 1246 insertions(+), 2036 deletions(-) diff --git a/src/video_engine/main/interface/vie_rtp_rtcp.h b/src/video_engine/main/interface/vie_rtp_rtcp.h index 69118d6159..f63689861b 100644 --- a/src/video_engine/main/interface/vie_rtp_rtcp.h +++ b/src/video_engine/main/interface/vie_rtp_rtcp.h @@ -162,7 +162,7 @@ public: // This function gets the RTCP status for the specified channel. virtual int GetRTCPStatus(const int videoChannel, - ViERTCPMode& rtcpMode) = 0; + ViERTCPMode& rtcpMode) const = 0; // This function sets the RTCP canonical name (CNAME) for the RTCP reports // on a specific channel. @@ -172,7 +172,7 @@ public: // This function gets the RTCP canonical name (CNAME) for the RTCP reports // sent the specified channel. virtual int GetRTCPCName(const int videoChannel, - char rtcpCName[KMaxRTCPCNameLength]) = 0; + char rtcpCName[KMaxRTCPCNameLength]) const = 0; // This function gets the RTCP canonical name (CNAME) for the RTCP reports // received on the specified channel. @@ -260,7 +260,7 @@ public: // This function gets the RTP keep-alive status. virtual int GetRTPKeepAliveStatus( const int videoChannel, bool& enabled, char& unkownPayloadType, - unsigned int& deltaTransmitTimeSeconds) = 0; + unsigned int& deltaTransmitTimeSeconds) const = 0; // This function enables capturing of RTP packets to a binary file on a // specific channel and for a given direction. The file can later be diff --git a/src/video_engine/vie_render_impl.cc b/src/video_engine/vie_render_impl.cc index 68cad97810..24eba8f768 100644 --- a/src/video_engine/vie_render_impl.cc +++ b/src/video_engine/vie_render_impl.cc @@ -8,557 +8,386 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * vie_render_impl.cc - */ +#include "video_engine/vie_render_impl.h" -#include "vie_render_impl.h" - -// Defines #include "engine_configurations.h" -#include "vie_defines.h" - -#include "trace.h" -#include "video_render.h" -#include "video_render_defines.h" -#include "vie_errors.h" -#include "vie_impl.h" -#include "vie_capturer.h" -#include "vie_channel.h" -#include "vie_frame_provider_base.h" -#include "vie_channel_manager.h" -#include "vie_input_manager.h" -#include "vie_render_manager.h" +#include "modules/video_render/main/interface/video_render.h" +#include "modules/video_render/main/interface/video_render_defines.h" +#include "system_wrappers/interface/trace.h" +#include "video_engine/main/interface/vie_errors.h" +#include "video_engine/vie_capturer.h" +#include "video_engine/vie_channel.h" +#include "video_engine/vie_channel_manager.h" +#include "video_engine/vie_defines.h" +#include "video_engine/vie_frame_provider_base.h" +#include "video_engine/vie_impl.h" +#include "video_engine/vie_input_manager.h" +#include "video_engine/vie_render_manager.h" #include "video_engine/vie_renderer.h" -namespace webrtc -{ +namespace webrtc { -// ---------------------------------------------------------------------------- -// GetInterface -// ---------------------------------------------------------------------------- - -ViERender* ViERender::GetInterface(VideoEngine* videoEngine) -{ +ViERender* ViERender::GetInterface(VideoEngine* video_engine) { #ifdef WEBRTC_VIDEO_ENGINE_RENDER_API - if (videoEngine == NULL) - { - return NULL; - } - VideoEngineImpl* vieImpl = reinterpret_cast (videoEngine); - ViERenderImpl* vieRenderImpl = vieImpl; - (*vieRenderImpl)++; // Increase ref count - - return vieRenderImpl; -#else + if (!video_engine) { return NULL; + } + VideoEngineImpl* vie_impl = reinterpret_cast(video_engine); + ViERenderImpl* vie_render_impl = vie_impl; + // Increase ref count. + (*vie_render_impl)++; + return vie_render_impl; +#else + return NULL; #endif } -// ---------------------------------------------------------------------------- -// Release -// -// Releases the interface, i.e. reduces the reference counter. The number of -// remaining references is returned, -1 if released too many times. -// ---------------------------------------------------------------------------- - -int ViERenderImpl::Release() -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, instance_id_, - "ViERender::Release()"); - (*this)--; // Decrease ref count - - WebRtc_Word32 refCount = GetCount(); - if (refCount < 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, instance_id_, - "ViERender release too many times"); - // SetLastError() - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, instance_id_, - "ViERender reference count: %d", refCount); - return refCount; +int ViERenderImpl::Release() { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_, + "ViERender::Release()"); + // Decrease ref count + (*this)--; + WebRtc_Word32 ref_count = GetCount(); + if (ref_count < 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, instance_id_, + "ViERender release too many times"); + return -1; + } + WEBRTC_TRACE(kTraceInfo, kTraceVideo, instance_id_, + "ViERender reference count: %d", ref_count); + return ref_count; } -// ---------------------------------------------------------------------------- -// Constructor -// ---------------------------------------------------------------------------- - -ViERenderImpl::ViERenderImpl() -{ - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, instance_id_, - "ViERenderImpl::ViERenderImpl() Ctor"); +ViERenderImpl::ViERenderImpl() { + WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_, + "ViERenderImpl::ViERenderImpl() Ctor"); } -// ---------------------------------------------------------------------------- -// Destructor -// ---------------------------------------------------------------------------- - -ViERenderImpl::~ViERenderImpl() -{ - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, instance_id_, - "ViERenderImpl::~ViERenderImpl() Dtor"); +ViERenderImpl::~ViERenderImpl() { + WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_, + "ViERenderImpl::~ViERenderImpl() Dtor"); } -// ============================================================================ -// Registration of render module -// ============================================================================ - -// ---------------------------------------------------------------------------- -// RegisterVideoRenderModule -// -// Registers a video render module, must be called before -// AddRenderer is called for an input stream associated -// with the same window as the module. -// ---------------------------------------------------------------------------- - int ViERenderImpl::RegisterVideoRenderModule( - VideoRender& renderModule) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(instance_id_), - "%s (&renderModule: %p)", __FUNCTION__, &renderModule); - - if (render_manager_.RegisterVideoRenderModule(renderModule) != 0) - { - // Error logging is done in RegisterVideoRenderModule - SetLastError(kViERenderUnknownError); - return -1; - } - - return 0; + VideoRender& render_module) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), + "%s (&render_module: %p)", __FUNCTION__, &render_module); + if (render_manager_.RegisterVideoRenderModule(render_module) != 0) { + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// DeRegisterVideoRenderModule -// -// De-registers a video render module, must be called after -// RemoveRenderer has been called for all input streams associated -// with the same window as the module. -// ---------------------------------------------------------------------------- - int ViERenderImpl::DeRegisterVideoRenderModule( - VideoRender& renderModule) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(instance_id_), - "%s (&renderModule: %p)", __FUNCTION__, &renderModule); - if (render_manager_.DeRegisterVideoRenderModule(renderModule) != 0) - { - // Error logging is done in DeRegisterVideoRenderModule - SetLastError(kViERenderUnknownError); - return -1; - } - - return 0; + VideoRender& render_module) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), + "%s (&render_module: %p)", __FUNCTION__, &render_module); + if (render_manager_.DeRegisterVideoRenderModule(render_module) != 0) { + // Error logging is done in ViERenderManager::DeRegisterVideoRenderModule. + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; } -// ============================================================================ -// Add renderer -// ============================================================================ - -int ViERenderImpl::AddRenderer(const int renderId, void* window, - const unsigned int zOrder, const float left, +int ViERenderImpl::AddRenderer(const int render_id, void* window, + const unsigned int z_order, const float left, const float top, const float right, - const float bottom) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(instance_id_), - "%s (renderId: %d, window: 0x%p, zOrder: %u, left: %f, " - "top: %f, right: %f, bottom: %f)", - __FUNCTION__, renderId, window, zOrder, left, top, right, - bottom); - if (!Initialized()) - { - SetLastError(kViENotInitialized); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s - ViE instance %d not initialized", __FUNCTION__, - instance_id_); - return -1; + const float bottom) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), + "%s (render_id: %d, window: 0x%p, z_order: %u, left: %f, " + "top: %f, right: %f, bottom: %f)", + __FUNCTION__, render_id, window, z_order, left, top, right, + bottom); + if (!Initialized()) { + SetLastError(kViENotInitialized); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s - ViE instance %d not initialized", __FUNCTION__, + instance_id_); + return -1; + } + { + ViERenderManagerScoped rs(render_manager_); + if (rs.Renderer(render_id) != NULL) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s - Renderer already exist %d.", __FUNCTION__, + render_id); + SetLastError(kViERenderAlreadyExists); + return -1; } + } + if (render_id >= kViEChannelIdBase && render_id <= kViEChannelIdMax) { + // This is a channel. + ViEChannelManagerScoped cm(channel_manager_); + ViEFrameProviderBase* frame_provider = cm.Channel(render_id); + if (!frame_provider) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s: FrameProvider id %d doesn't exist", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + ViERenderer* renderer = render_manager_.AddRenderStream(render_id, + window, z_order, + left, top, + right, bottom); + if (!renderer) { + SetLastError(kViERenderUnknownError); + return -1; + } + return frame_provider->RegisterFrameCallback(render_id, renderer); + } else { + // Camera or file. + ViEInputManagerScoped is(input_manager_); + ViEFrameProviderBase* frame_provider = is.FrameProvider(render_id); + if (!frame_provider) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s: FrameProvider id %d doesn't exist", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + ViERenderer* renderer = render_manager_.AddRenderStream(render_id, + window, z_order, + left, top, + right, bottom); + if (!renderer) { + SetLastError(kViERenderUnknownError); + return -1; + } + return frame_provider->RegisterFrameCallback(render_id, renderer); + } + SetLastError(kViERenderInvalidRenderId); + return -1; +} - { // Check if the renderer exist already - ViERenderManagerScoped rs(render_manager_); - if (rs.Renderer(renderId) != NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s - Renderer already exist %d.", __FUNCTION__, - renderId); - SetLastError(kViERenderAlreadyExists); - return -1; - } - } +int ViERenderImpl::RemoveRenderer(const int render_id) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), + "%s(render_id: %d)", __FUNCTION__, render_id); + if (!Initialized()) { + SetLastError(kViENotInitialized); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s - ViE instance %d not initialized", __FUNCTION__, + instance_id_); + return -1; + } - if (renderId >= kViEChannelIdBase && renderId <= kViEChannelIdMax) - { - // This is a channel - ViEChannelManagerScoped cm(channel_manager_); - ViEFrameProviderBase* frameProvider = cm.Channel(renderId); - if (frameProvider == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s: FrameProvider id %d doesn't exist", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - ViERenderer* renderer = render_manager_.AddRenderStream(renderId, - window, zOrder, - left, top, - right, bottom); - if (renderer == NULL) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return frameProvider->RegisterFrameCallback(renderId, renderer); + ViERenderer* renderer = NULL; + { + ViERenderManagerScoped rs(render_manager_); + renderer = rs.Renderer(render_id); + if (!renderer) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(instance_id_), + "%s No render exist with render_id: %d", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; } - else // camera or file - { - ViEInputManagerScoped is(input_manager_); - ViEFrameProviderBase* frameProvider = is.FrameProvider(renderId); - if (frameProvider == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s: FrameProvider id %d doesn't exist", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - ViERenderer* renderer = render_manager_.AddRenderStream(renderId, - window, zOrder, - left, top, - right, bottom); - if (renderer == NULL) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return frameProvider->RegisterFrameCallback(renderId, renderer); + // Leave the scope lock since we don't want to lock two managers + // simultanousely. + } + if (render_id >= kViEChannelIdBase && render_id <= kViEChannelIdMax) { + // This is a channel. + ViEChannelManagerScoped cm(channel_manager_); + ViEChannel* channel = cm.Channel(render_id); + if (!channel) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(instance_id_), + "%s: no channel with id %d exists ", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; } + channel->DeregisterFrameCallback(renderer); + } else { + // Provider owned by inputmanager, i.e. file or capture device. + ViEInputManagerScoped is(input_manager_); + ViEFrameProviderBase* provider = is.FrameProvider(render_id); + if (!provider) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(instance_id_), + "%s: no provider with id %d exists ", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + provider->DeregisterFrameCallback(renderer); + } + if (render_manager_.RemoveRenderStream(render_id) != 0) { + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; +} + +int ViERenderImpl::StartRender(const int render_id) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, render_id), + "%s(channel: %d)", __FUNCTION__, render_id); + ViERenderManagerScoped rs(render_manager_); + ViERenderer* renderer = rs.Renderer(render_id); + if (!renderer) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, render_id), + "%s: No renderer with render Id %d exist.", __FUNCTION__, + render_id); SetLastError(kViERenderInvalidRenderId); return -1; - + } + if (renderer->StartRender() != 0) { + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; } -int ViERenderImpl::RemoveRenderer(const int renderId) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(instance_id_), - "%s(renderId: %d)", __FUNCTION__, renderId); - if (!Initialized()) - { - SetLastError(kViENotInitialized); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s - ViE instance %d not initialized", __FUNCTION__, - instance_id_); - return -1; - } - - ViERenderer* renderer = NULL; - { - ViERenderManagerScoped rs(render_manager_); - renderer = rs.Renderer(renderId); - if (!renderer) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, ViEId(instance_id_), - "%s No render exist with renderId: %d", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - } // Leave the scope lock since we don't want to lock two managers - // simultanousely - - if (renderId >= kViEChannelIdBase && renderId <= kViEChannelIdMax) - { - // This is a channel - ViEChannelManagerScoped cm(channel_manager_); - ViEChannel* channel = cm.Channel(renderId); - if (!channel) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, ViEId(instance_id_), - "%s: no channel with id %d exists ", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - channel->DeregisterFrameCallback(renderer); - } - else //Provider owned by inputmanager - ie file or capture device - { - ViEInputManagerScoped is(input_manager_); - ViEFrameProviderBase* provider = is.FrameProvider(renderId); - if (!provider) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, ViEId(instance_id_), - "%s: no provider with id %d exists ", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - provider->DeregisterFrameCallback(renderer); - - } - if (render_manager_.RemoveRenderStream(renderId) != 0) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return 0; +int ViERenderImpl::StopRender(const int render_id) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, render_id), + "%s(channel: %d)", __FUNCTION__, render_id); + ViERenderManagerScoped rs(render_manager_); + ViERenderer* renderer = rs.Renderer(render_id); + if (!renderer) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, render_id), + "%s: No renderer with render_id %d exist.", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + if (renderer->StopRender() != 0) { + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; } -// ============================================================================ -// Start/stop -// ============================================================================ - -// ---------------------------------------------------------------------------- -// StartRender -// -// Starts rendering the stream from the channel -// ---------------------------------------------------------------------------- - -int ViERenderImpl::StartRender(const int renderId) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), "%s(channel: %d)", __FUNCTION__, - renderId); - - ViERenderManagerScoped rs(render_manager_); - ViERenderer* ptrRender = rs.Renderer(renderId); - if (ptrRender == NULL) - { - // No renderer for this channel - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), - "%s: No renderer with render Id %d exist.", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - - if (ptrRender->StartRender() != 0) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// StopRender -// -// Stop rendering a stream -// ---------------------------------------------------------------------------- - -int ViERenderImpl::StopRender(const int renderId) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), "%s(channel: %d)", __FUNCTION__, - renderId); - - ViERenderManagerScoped rs(render_manager_); - ViERenderer* ptrRender = rs.Renderer(renderId); - if (ptrRender == NULL) - { - // No renderer for this channel - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), - "%s: No renderer with renderId %d exist.", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - if (ptrRender->StopRender() != 0) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return 0; -} - -// ============================================================================ -// Stream configurations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// ConfigureRender -// -// Reconfigures an already added render stream -// ---------------------------------------------------------------------------- - -int ViERenderImpl::ConfigureRender(int renderId, const unsigned int zOrder, +int ViERenderImpl::ConfigureRender(int render_id, const unsigned int z_order, const float left, const float top, - const float right, const float bottom) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, ViEId(instance_id_, renderId), - "%s(channel: %d)", __FUNCTION__, renderId); - - ViERenderManagerScoped rs(render_manager_); - ViERenderer* ptrRender = rs.Renderer(renderId); - if (ptrRender == NULL) - { - // No renderer for this channel - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), - "%s: No renderer with renderId %d exist.", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - - if (ptrRender->ConfigureRenderer(zOrder, left, top, right, bottom) != 0) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// MirrorRenderStream -// -// Enables mirror rendering -// ---------------------------------------------------------------------------- - -int ViERenderImpl::MirrorRenderStream(const int renderId, const bool enable, - const bool mirrorXAxis, - const bool mirrorYAxis) -{ - ViERenderManagerScoped rs(render_manager_); - ViERenderer* ptrRender = rs.Renderer(renderId); - if (ptrRender == NULL) - { - // No renderer for this channel - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), - "%s: No renderer with renderId %d exist.", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - if (ptrRender->EnableMirroring(renderId, enable, mirrorXAxis, mirrorYAxis) - != 0) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return 0; -} - -// ============================================================================ -// External render -// ============================================================================ - - -// ---------------------------------------------------------------------------- -// -// -// AddRenderer -// ---------------------------------------------------------------------------- - -int ViERenderImpl::AddRenderer(const int renderId, - webrtc::RawVideoType videoInputFormat, - ExternalRenderer* externalRenderer) -{ - // check if the client requested a format that we can convert the frames to - if (videoInputFormat != webrtc::kVideoI420 - && videoInputFormat != webrtc::kVideoYV12 - && videoInputFormat != webrtc::kVideoYUY2 - && videoInputFormat != webrtc::kVideoUYVY - && videoInputFormat != webrtc::kVideoARGB - && videoInputFormat != webrtc::kVideoRGB24 - && videoInputFormat != webrtc::kVideoRGB565 - && videoInputFormat != webrtc::kVideoARGB4444 - && videoInputFormat != webrtc::kVideoARGB1555) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, renderId), - "%s: Unsupported video frame format requested", - __FUNCTION__, renderId); - SetLastError(kViERenderInvalidFrameFormat); - return -1; - } - - if (!Initialized()) - { - SetLastError(kViENotInitialized); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s - ViE instance %d not initialized", __FUNCTION__, - instance_id_); - return -1; - } - - { // Check if the renderer exist already - ViERenderManagerScoped rs(render_manager_); - if (rs.Renderer(renderId) != NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s - Renderer already exist %d.", __FUNCTION__, - renderId); - SetLastError(kViERenderAlreadyExists); - return -1; - } - } - - if (renderId >= kViEChannelIdBase && renderId <= kViEChannelIdMax) - { - // This is a channel - ViEChannelManagerScoped cm(channel_manager_); - ViEFrameProviderBase* frameProvider = cm.Channel(renderId); - if (frameProvider == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s: FrameProvider id %d doesn't exist", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - ViERenderer* ptrRender = render_manager_.AddRenderStream(renderId, NULL, - 0, 0.0f, 0.0f, - 1.0f, 1.0f); - if (ptrRender == NULL) - { - SetLastError(kViERenderUnknownError); - return -1; - } - if (-1 == ptrRender->SetExternalRenderer(renderId, videoInputFormat, - externalRenderer)) - { - SetLastError(kViERenderUnknownError); - return -1; - } - - return frameProvider->RegisterFrameCallback(renderId, ptrRender); - } - else // camera or file - { - ViEInputManagerScoped is(input_manager_); - ViEFrameProviderBase* frameProvider = is.FrameProvider(renderId); - if (frameProvider == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_), - "%s: FrameProvider id %d doesn't exist", __FUNCTION__, - renderId); - SetLastError(kViERenderInvalidRenderId); - return -1; - } - ViERenderer* ptrRender = render_manager_.AddRenderStream(renderId, NULL, - 0, 0.0f, 0.0f, - 1.0f, 1.0f); - if (ptrRender == NULL) - { - SetLastError(kViERenderUnknownError); - return -1; - } - if (-1 == ptrRender->SetExternalRenderer(renderId, videoInputFormat, - externalRenderer)) - { - SetLastError(kViERenderUnknownError); - return -1; - } - return frameProvider->RegisterFrameCallback(renderId, ptrRender); - } + const float right, const float bottom) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, render_id), + "%s(channel: %d)", __FUNCTION__, render_id); + ViERenderManagerScoped rs(render_manager_); + ViERenderer* renderer = rs.Renderer(render_id); + if (!renderer) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, render_id), + "%s: No renderer with render_id %d exist.", __FUNCTION__, + render_id); SetLastError(kViERenderInvalidRenderId); return -1; + } + if (renderer->ConfigureRenderer(z_order, left, top, right, bottom) != 0) { + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; } -} // namespace webrtc +int ViERenderImpl::MirrorRenderStream(const int render_id, const bool enable, + const bool mirror_xaxis, + const bool mirror_yaxis) { + ViERenderManagerScoped rs(render_manager_); + ViERenderer* renderer = rs.Renderer(render_id); + if (!renderer) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, render_id), + "%s: No renderer with render_id %d exist.", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + if (renderer->EnableMirroring(render_id, enable, mirror_xaxis, mirror_yaxis) + != 0) { + SetLastError(kViERenderUnknownError); + return -1; + } + return 0; +} + +int ViERenderImpl::AddRenderer(const int render_id, + RawVideoType video_input_format, + ExternalRenderer* external_renderer) { + // Check if the client requested a format that we can convert the frames to. + if (video_input_format != kVideoI420 && + video_input_format != kVideoYV12 && + video_input_format != kVideoYUY2 && + video_input_format != kVideoUYVY && + video_input_format != kVideoARGB && + video_input_format != kVideoRGB24 && + video_input_format != kVideoRGB565 && + video_input_format != kVideoARGB4444 && + video_input_format != kVideoARGB1555) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, render_id), + "%s: Unsupported video frame format requested", + __FUNCTION__, render_id); + SetLastError(kViERenderInvalidFrameFormat); + return -1; + } + if (!Initialized()) { + SetLastError(kViENotInitialized); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s - ViE instance %d not initialized", __FUNCTION__, + instance_id_); + return -1; + } + { + // Verify the renderer exists. + ViERenderManagerScoped rs(render_manager_); + if (!rs.Renderer(render_id)) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s - Renderer already exist %d.", __FUNCTION__, + render_id); + SetLastError(kViERenderAlreadyExists); + return -1; + } + } + if (render_id >= kViEChannelIdBase && render_id <= kViEChannelIdMax) { + // This is a channel. + ViEChannelManagerScoped cm(channel_manager_); + ViEFrameProviderBase* frame_provider = cm.Channel(render_id); + if (!frame_provider) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s: FrameProvider id %d doesn't exist", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + ViERenderer* renderer = render_manager_.AddRenderStream(render_id, NULL, + 0, 0.0f, 0.0f, + 1.0f, 1.0f); + if (!renderer) { + SetLastError(kViERenderUnknownError); + return -1; + } + if (renderer->SetExternalRenderer(render_id, video_input_format, + external_renderer) == -1) { + SetLastError(kViERenderUnknownError); + return -1; + } + + return frame_provider->RegisterFrameCallback(render_id, renderer); + } else { + // Camera or file. + ViEInputManagerScoped is(input_manager_); + ViEFrameProviderBase* frame_provider = is.FrameProvider(render_id); + if (!frame_provider) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), + "%s: FrameProvider id %d doesn't exist", __FUNCTION__, + render_id); + SetLastError(kViERenderInvalidRenderId); + return -1; + } + ViERenderer* renderer = render_manager_.AddRenderStream(render_id, NULL, + 0, 0.0f, 0.0f, + 1.0f, 1.0f); + if (!renderer) { + SetLastError(kViERenderUnknownError); + return -1; + } + if (renderer->SetExternalRenderer(render_id, video_input_format, + external_renderer) == -1) { + SetLastError(kViERenderUnknownError); + return -1; + } + return frame_provider->RegisterFrameCallback(render_id, renderer); + } + SetLastError(kViERenderInvalidRenderId); + return -1; +} + +} // namespace webrtc diff --git a/src/video_engine/vie_render_impl.h b/src/video_engine/vie_render_impl.h index 2d1bd3653c..43dac1bb5b 100644 --- a/src/video_engine/vie_render_impl.h +++ b/src/video_engine/vie_render_impl.h @@ -8,70 +8,46 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * vie_render_impl.h - */ - -#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RENDER_IMPL_H_ -#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RENDER_IMPL_H_ - -#include "vie_defines.h" +#ifndef WEBRTC_VIDEO_ENGINE_VIE_RENDER_IMPL_H_ +#define WEBRTC_VIDEO_ENGINE_VIE_RENDER_IMPL_H_ +#include "modules/video_render/main/interface/video_render_defines.h" #include "typedefs.h" -#include "video_render_defines.h" -#include "vie_ref_count.h" -#include "vie_render.h" -#include "vie_shared_data.h" +#include "video_engine/main/interface/vie_render.h" +#include "video_engine/vie_ref_count.h" +#include "video_engine/vie_shared_data.h" -namespace webrtc -{ +namespace webrtc { -// ---------------------------------------------------------------------------- -// ViERenderImpl -// ---------------------------------------------------------------------------- +class ViERenderImpl + : public virtual ViESharedData, + public ViERender, + public ViERefCount { + public: + // Implements ViERender + virtual int Release(); + virtual int RegisterVideoRenderModule(VideoRender& render_module); + virtual int DeRegisterVideoRenderModule(VideoRender& render_module); + virtual int AddRenderer(const int render_id, void* window, + const unsigned int z_order, const float left, + const float top, const float right, + const float bottom); + virtual int RemoveRenderer(const int render_id); + virtual int StartRender(const int render_id); + virtual int StopRender(const int render_id); + virtual int ConfigureRender(int render_id, const unsigned int z_order, + const float left, const float top, + const float right, const float bottom); + virtual int MirrorRenderStream(const int render_id, const bool enable, + const bool mirror_xaxis, + const bool mirror_yaxis); + virtual int AddRenderer(const int render_id, RawVideoType video_input_format, + ExternalRenderer* renderer); -class ViERenderImpl: public virtual ViESharedData, - public ViERender, - public ViERefCount -{ -public: - virtual int Release(); - - // Registration of render module - virtual int RegisterVideoRenderModule(VideoRender& renderModule); - - virtual int DeRegisterVideoRenderModule( - VideoRender& renderModule); - - // Add/remove renderer - virtual int AddRenderer(const int renderId, void* window, - const unsigned int zOrder, const float left, - const float top, const float right, - const float bottom); - - virtual int RemoveRenderer(const int renderId); - - // Start/stop - virtual int StartRender(const int renderId); - - virtual int StopRender(const int renderId); - - virtual int ConfigureRender(int renderId, const unsigned int zOrder, - const float left, const float top, - const float right, const float bottom); - - virtual int MirrorRenderStream(const int renderId, const bool enable, - const bool mirrorXAxis, - const bool mirrorYAxis); - - // External render - virtual int AddRenderer(const int renderId, - webrtc::RawVideoType videoInputFormat, - ExternalRenderer* renderer); - -protected: - ViERenderImpl(); - virtual ~ViERenderImpl(); + protected: + ViERenderImpl(); + virtual ~ViERenderImpl(); }; -} // namespace webrtc -#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RENDER_IMPL_H_ + +} // namespace webrtc +#endif // WEBRTC_VIDEO_ENGINE_VIE_RENDER_IMPL_H_ diff --git a/src/video_engine/vie_rtp_rtcp_impl.cc b/src/video_engine/vie_rtp_rtcp_impl.cc index 58a0a337ed..78ffaa05fd 100644 --- a/src/video_engine/vie_rtp_rtcp_impl.cc +++ b/src/video_engine/vie_rtp_rtcp_impl.cc @@ -8,1369 +8,816 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * vie_rtp_rtcp_impl.cc - */ +#include "video_engine/vie_rtp_rtcp_impl.h" -#include "vie_rtp_rtcp_impl.h" - -// Defines #include "engine_configurations.h" -#include "vie_defines.h" +#include "system_wrappers/interface/file_wrapper.h" +#include "system_wrappers/interface/trace.h" +#include "video_engine/main/interface/vie_errors.h" +#include "video_engine/vie_channel.h" +#include "video_engine/vie_channel_manager.h" +#include "video_engine/vie_defines.h" +#include "video_engine/vie_encoder.h" +#include "video_engine/vie_impl.h" -#include "vie_errors.h" -#include "file_wrapper.h" -#include "trace.h" -#include "vie_impl.h" -#include "vie_channel.h" -#include "vie_channel_manager.h" -#include "vie_encoder.h" +namespace webrtc { -namespace webrtc -{ +// Helper methods for converting between module format and ViE API format. -// ---------------------------------------------------------------------------- -// GetInterface -// ---------------------------------------------------------------------------- +static RTCPMethod ViERTCPModeToRTCPMethod(ViERTCPMode api_mode) { + switch (api_mode) { + case kRtcpNone: + return kRtcpOff; -ViERTP_RTCP* ViERTP_RTCP::GetInterface(VideoEngine* videoEngine) -{ + case kRtcpCompound_RFC4585: + return kRtcpCompound; + + case kRtcpNonCompound_RFC5506: + return kRtcpNonCompound; + + default: + assert(false); + return kRtcpOff; + } +} + +static ViERTCPMode RTCPMethodToViERTCPMode(RTCPMethod module_method) { + switch (module_method) { + case kRtcpOff: + return kRtcpNone; + + case kRtcpCompound: + return kRtcpCompound_RFC4585; + + case kRtcpNonCompound: + return kRtcpNonCompound_RFC5506; + + default: + assert(false); + return kRtcpNone; + } +} + +static KeyFrameRequestMethod APIRequestToModuleRequest( + ViEKeyFrameRequestMethod api_method) { + switch (api_method) { + case kViEKeyFrameRequestNone: + return kKeyFrameReqFirRtp; + + case kViEKeyFrameRequestPliRtcp: + return kKeyFrameReqPliRtcp; + + case kViEKeyFrameRequestFirRtp: + return kKeyFrameReqFirRtp; + + case kViEKeyFrameRequestFirRtcp: + return kKeyFrameReqFirRtcp; + + default: + assert(false); + return kKeyFrameReqFirRtp; + } +} + +ViERTP_RTCP* ViERTP_RTCP::GetInterface(VideoEngine* video_engine) { #ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API - if (videoEngine == NULL) - { - return NULL; - } - VideoEngineImpl* vieImpl = reinterpret_cast (videoEngine); - ViERTP_RTCPImpl* vieRTPImpl = vieImpl; - (*vieRTPImpl)++; // Increase ref count - - return vieRTPImpl; -#else + if (!video_engine) { return NULL; + } + VideoEngineImpl* vie_impl = reinterpret_cast(video_engine); + ViERTP_RTCPImpl* vie_rtpimpl = vie_impl; + // Increase ref count. + (*vie_rtpimpl)++; + return vie_rtpimpl; +#else + return NULL; #endif } -// ---------------------------------------------------------------------------- -// Release -// -// Releases the interface, i.e. reduces the reference counter. The number of -// remaining references is returned, -1 if released too many times. -// ---------------------------------------------------------------------------- +int ViERTP_RTCPImpl::Release() { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_, + "ViERTP_RTCP::Release()"); + // Decrease ref count. + (*this)--; -int ViERTP_RTCPImpl::Release() -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, instance_id_, - "ViERTP_RTCP::Release()"); - (*this)--; // Decrease ref count - - WebRtc_Word32 refCount = GetCount(); - if (refCount < 0) - { - WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, instance_id_, - "ViERTP_RTCP release too many times"); - SetLastError(kViEAPIDoesNotExist); - return -1; - } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, instance_id_, - "ViERTP_RTCP reference count: %d", refCount); - return refCount; + WebRtc_Word32 ref_count = GetCount(); + if (ref_count < 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVideo, instance_id_, + "ViERTP_RTCP release too many times"); + SetLastError(kViEAPIDoesNotExist); + return -1; + } + WEBRTC_TRACE(kTraceInfo, kTraceVideo, instance_id_, + "ViERTP_RTCP reference count: %d", ref_count); + return ref_count; } -// ---------------------------------------------------------------------------- -// Constructor -// ---------------------------------------------------------------------------- - -ViERTP_RTCPImpl::ViERTP_RTCPImpl() -{ - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, instance_id_, - "ViERTP_RTCPImpl::ViERTP_RTCPImpl() Ctor"); +ViERTP_RTCPImpl::ViERTP_RTCPImpl() { + WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_, + "ViERTP_RTCPImpl::ViERTP_RTCPImpl() Ctor"); } -// ---------------------------------------------------------------------------- -// Destructor -// ---------------------------------------------------------------------------- - -ViERTP_RTCPImpl::~ViERTP_RTCPImpl() -{ - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, instance_id_, - "ViERTP_RTCPImpl::~ViERTP_RTCPImpl() Dtor"); +ViERTP_RTCPImpl::~ViERTP_RTCPImpl() { + WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_, + "ViERTP_RTCPImpl::~ViERTP_RTCPImpl() Dtor"); } -// ============================================================================ -// SSRC/CSRC -// ============================================================================ - -// ---------------------------------------------------------------------------- -// SetLocalSSRC -// -// Sets the SSRC on the outgoing stream -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetLocalSSRC(const int videoChannel, +int ViERTP_RTCPImpl::SetLocalSSRC(const int video_channel, const unsigned int SSRC, const StreamType usage, - const unsigned char simulcastIdx) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, - webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, SSRC: %d)", - __FUNCTION__, videoChannel, SSRC); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, - webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", - __FUNCTION__, videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - if (ptrViEChannel->SetSSRC(SSRC, usage, simulcastIdx) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// GetLocalSSRC -// -// Gets the SSRC of the outgoing stream -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetLocalSSRC(const int videoChannel, - unsigned int& SSRC) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d, SSRC: %d)", - __FUNCTION__, videoChannel, SSRC); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->GetLocalSSRC((WebRtc_UWord32&) SSRC) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; - -} - -int ViERTP_RTCPImpl::SetRemoteSSRCType(const int videoChannel, - const StreamType usage, - const unsigned int SSRC) const -{ - // TODO(pwestin) add support for RTX - return -1; -} - -// ---------------------------------------------------------------------------- -// GetRemoteSSRC -// -// Gets the SSRC of the incoming stream -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetRemoteSSRC(const int videoChannel, - unsigned int& SSRC) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel, SSRC); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->GetRemoteSSRC((WebRtc_UWord32&) SSRC) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// GetRemoteCSRCs -// -// Gets the CSRC of the incoming stream -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetRemoteCSRCs(const int videoChannel, - unsigned int CSRCs[kRtpCsrcSize]) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->GetRemoteCSRC(CSRCs) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// SetStartSequenceNumber -// -// Sets the starting sequence number, instead of a random number. -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetStartSequenceNumber(const int videoChannel, - unsigned short sequenceNumber) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, sequenceNumber: %u)", __FUNCTION__, - videoChannel, sequenceNumber); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - if (ptrViEChannel->Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d already sending.", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpAlreadySending); - return -1; - } - - if (ptrViEChannel->SetStartSequenceNumber(sequenceNumber) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ============================================================================ -// RTCP -// ============================================================================ - -// ---------------------------------------------------------------------------- -// SetRTCPStatus -// -// Sets the RTCP status for the channel -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetRTCPStatus(const int videoChannel, - const ViERTCPMode rtcpMode) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_,videoChannel), "%s(channel: %d, mode: %d)", - __FUNCTION__, videoChannel, rtcpMode); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - RTCPMethod moduleMode = ViERTCPModeToRTCPMethod(rtcpMode); - - if (ptrViEChannel->SetRTCPMode(moduleMode) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; - -} - -// ---------------------------------------------------------------------------- -// GetRTCPStatus -// -// Gets the RTCP status for the specified channel -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetRTCPStatus(const int videoChannel, - ViERTCPMode& rtcpMode) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel, rtcpMode); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - RTCPMethod moduleMode = kRtcpOff; - if (ptrViEChannel->GetRTCPMode(moduleMode) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: could not get current RTCP mode", __FUNCTION__); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - - rtcpMode = RTCPMethodToViERTCPMode(moduleMode); - return 0; -} - -// ---------------------------------------------------------------------------- -// SetRTCPCName -// -// Specifies what CName to use -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetRTCPCName(const int videoChannel, - const char rtcpCName[KMaxRTCPCNameLength]) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d, name: %s)", - __FUNCTION__, videoChannel, rtcpCName); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d already sending.", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpAlreadySending); - return -1; - } - - if (ptrViEChannel->SetRTCPCName(rtcpCName) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; - -} - -// ---------------------------------------------------------------------------- -// GetRTCPCName -// -// Gets the set CName -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetRTCPCName(const int videoChannel, - char rtcpCName[KMaxRTCPCNameLength]) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - if (ptrViEChannel->GetRTCPCName(rtcpCName) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; - -} - -// ---------------------------------------------------------------------------- -// GetRemoteRTCPCName -// -// Gets the CName of for the incoming stream -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetRemoteRTCPCName(const int videoChannel, - char rtcpCName[KMaxRTCPCNameLength]) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - if (ptrViEChannel->GetRemoteRTCPCName(rtcpCName) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// SendApplicationDefinedRTCPPacket -// -// From RFC 3550: -// -// 6.7 APP: Application-Defined RTCP Packet -// -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// |V=2|P| subtype | PT=APP=204 | length | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | SSRC/CSRC | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | name (ASCII) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | application-dependent data ... -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// -// The APP packet is intended for experimental use as new applications -// and new features are developed, without requiring packet type value -// registration. APP packets with unrecognized names SHOULD be ignored. -// After testing and if wider use is justified, it is RECOMMENDED that -// each APP packet be redefined without the subtype and name fields and -// registered with IANA using an RTCP packet type. -// -// version (V), padding (P), length: -// As described for the SR packet (see Section 6.4.1). -// -// subtype: 5 bits -// May be used as a subtype to allow a set of APP packets to be -// defined under one unique name, or for any application-dependent -// data. -// -// packet type (PT): 8 bits -// Contains the constant 204 to identify this as an RTCP APP packet. -// -// name: 4 octets -// A name chosen by the person defining the set of APP packets to be -// unique with respect to other APP packets this application might -// receive. The application creator might choose to use the -// application name, and then coordinate the allocation of subtype -// values to others who want to define new packet types for the -// application. Alternatively, it is RECOMMENDED that others choose -// a name based on the entity they represent, then coordinate the use -// of the name within that entity. The name is interpreted as a -// sequence of four ASCII characters, with uppercase and lowercase -// characters treated as distinct. -// -// application-dependent data: variable length -// Application-dependent data may or may not appear in an APP packet. -// It is interpreted by the application and not RTP itself. It MUST -// be a multiple of 32 bits long. -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SendApplicationDefinedRTCPPacket( - const int videoChannel, const unsigned char subType, unsigned int name, - const char* data, unsigned short dataLengthInBytes) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, subType: %c, name: %d, data: x, length: %u)", - __FUNCTION__, videoChannel, subType, name, dataLengthInBytes); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - if (!ptrViEChannel->Sending()) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d not sending", __FUNCTION__, videoChannel); - SetLastError(kViERtpRtcpNotSending); - return -1; - } - RTCPMethod method; - if (ptrViEChannel->GetRTCPMode(method) != 0 || method == kRtcpOff) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: RTCP disabled on channel %d.", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpRtcpDisabled); - return -1; - } - - if (ptrViEChannel->SendApplicationDefinedRTCPPacket( - subType, name, (const WebRtc_UWord8 *) data, dataLengthInBytes) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// SetNACKStatus -// -// Enables NACK for the specified channel -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetNACKStatus(const int videoChannel, const bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, enable: %d)", __FUNCTION__, videoChannel, - enable); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - // Update the channel status - if (ptrViEChannel->SetNACKStatus(enable) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: failed for channel %d", __FUNCTION__, videoChannel); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - - // Update the encoder - ViEEncoder* ptrViEEncoder = cs.Encoder(videoChannel); - if (ptrViEEncoder == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Could not get encoder for channel %d", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - ptrViEEncoder->UpdateProtectionMethod(); - - return 0; -} - -// ---------------------------------------------------------------------------- -// SetFECStatus -// -// Enables/disables FEC and sets the payloadtypes -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetFECStatus(const int videoChannel, const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC) -{ - - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, enable: %d, payloadTypeRED: %u, " - "payloadTypeFEC: %u)", - __FUNCTION__, videoChannel, enable, payloadTypeRED, - payloadTypeFEC); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - // Update the channel status - if (ptrViEChannel->SetFECStatus(enable, payloadTypeRED, payloadTypeFEC) - != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: failed for channel %d", __FUNCTION__, videoChannel); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - - // Update the encoder - ViEEncoder* ptrViEEncoder = cs.Encoder(videoChannel); - if (ptrViEEncoder == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Could not get encoder for channel %d", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - ptrViEEncoder->UpdateProtectionMethod(); - return 0; -} - -// ---------------------------------------------------------------------------- -// SetHybridNACKFECStatus -// -// Enables/disables hybrid NACK/FEC and sets the payloadtypes -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetHybridNACKFECStatus(const int videoChannel, - const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, enable: %d, payloadTypeRED: %u, " - "payloadTypeFEC: %u)", - __FUNCTION__, videoChannel, enable, payloadTypeRED, - payloadTypeFEC); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - // Update the channel status with hybrid NACK FEC mode - if (ptrViEChannel->SetHybridNACKFECStatus(enable, payloadTypeRED, - payloadTypeFEC) != 0) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: failed for channel %d", __FUNCTION__, videoChannel); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - - // Update the encoder - ViEEncoder* ptrViEEncoder = cs.Encoder(videoChannel); - if (ptrViEEncoder == NULL) - { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Could not get encoder for channel %d", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - ptrViEEncoder->UpdateProtectionMethod(); - return 0; -} - -// ---------------------------------------------------------------------------- -// SetKeyFrameRequestMethod -// -// Sets the key frame request method to use -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetKeyFrameRequestMethod( - const int videoChannel, const ViEKeyFrameRequestMethod method) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, method: %d)", __FUNCTION__, videoChannel, - method); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - KeyFrameRequestMethod moduleMethod = APIRequestToModuleRequest(method); - if (ptrViEChannel->SetKeyFrameRequestMethod(moduleMethod) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// SetTMMBRStatus -// -// Enables/disables TTMBR -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::SetTMMBRStatus(const int videoChannel, const bool enable) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, enable: %d)", __FUNCTION__, videoChannel, - enable); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->EnableTMMBR(enable) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ============================================================================ -// Statistics -// ============================================================================ - -// ---------------------------------------------------------------------------- -// GetReceivedRTCPStatistics -// -// Gets statistics received in from remote side -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetReceivedRTCPStatistics( - const int videoChannel, unsigned short& fractionLost, - unsigned int& cumulativeLost, unsigned int& extendedMax, - unsigned int& jitter, int& rttMs) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->GetReceivedRtcpStatistics( - (WebRtc_UWord16&) fractionLost, (WebRtc_UWord32&) cumulativeLost, - (WebRtc_UWord32&) extendedMax, (WebRtc_UWord32&) jitter, - (WebRtc_Word32&) rttMs) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// GetSentRTCPStatistics -// -// Gets statistics sent in RTCP to the remote side -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetSentRTCPStatistics(const int videoChannel, - unsigned short& fractionLost, - unsigned int& cumulativeLost, - unsigned int& extendedMax, - unsigned int& jitter, - int& rttMs) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->GetSendRtcpStatistics((WebRtc_UWord16&) fractionLost, - (WebRtc_UWord32&) cumulativeLost, - (WebRtc_UWord32&) extendedMax, - (WebRtc_UWord32&) jitter, - (WebRtc_Word32&) rttMs) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// GetRTCPStatistics -// -// Gets statistics about sent/received rtp packets -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::GetRTPStatistics(const int videoChannel, - unsigned int& bytesSent, - unsigned int& packetsSent, - unsigned int& bytesReceived, - unsigned int& packetsReceived) const -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->GetRtpStatistics((WebRtc_UWord32&) bytesSent, - (WebRtc_UWord32&) packetsSent, - (WebRtc_UWord32&) bytesReceived, - (WebRtc_UWord32&) packetsReceived) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; -} - -// The function gets bandwidth usage statistics from the sent RTP streams. -int ViERTP_RTCPImpl::GetBandwidthUsage(const int videoChannel, - unsigned int& totalBitrateSent, - unsigned int& videoBitrateSent, - unsigned int& fecBitrateSent, - unsigned int& nackBitrateSent) const { - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - + const unsigned char simulcast_idx) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, SSRC: %d)", __FUNCTION__, video_channel, SSRC); ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) { + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->SetSSRC(SSRC, usage, simulcast_idx) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetLocalSSRC(const int video_channel, + unsigned int& SSRC) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, SSRC: %d)", __FUNCTION__, video_channel, SSRC); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetLocalSSRC((WebRtc_UWord32&) SSRC) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::SetRemoteSSRCType(const int video_channel, + const StreamType usage, + const unsigned int SSRC) const { + // TODO(pwestin) add support for RTX. + return -1; +} + +int ViERTP_RTCPImpl::GetRemoteSSRC(const int video_channel, + unsigned int& SSRC) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel, SSRC); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetRemoteSSRC(SSRC) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetRemoteCSRCs(const int video_channel, + unsigned int CSRCs[kRtpCsrcSize]) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetRemoteCSRC(CSRCs) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::SetStartSequenceNumber(const int video_channel, + unsigned short sequence_number) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, sequence_number: %u)", __FUNCTION__, + video_channel, sequence_number); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d already sending.", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpAlreadySending); + return -1; + } + if (vie_channel->SetStartSequenceNumber(sequence_number) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::SetRTCPStatus(const int video_channel, + const ViERTCPMode rtcp_mode) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, mode: %d)", __FUNCTION__, video_channel, + rtcp_mode); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); SetLastError(kViERtpRtcpInvalidChannelId); return -1; } - ptrViEChannel->GetBandwidthUsage( - static_cast(totalBitrateSent), - static_cast(videoBitrateSent), - static_cast(fecBitrateSent), + RTCPMethod module_mode = ViERTCPModeToRTCPMethod(rtcp_mode); + if (vie_channel->SetRTCPMode(module_mode) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetRTCPStatus(const int video_channel, + ViERTCPMode& rtcp_mode) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel, rtcp_mode); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + RTCPMethod module_mode = kRtcpOff; + if (vie_channel->GetRTCPMode(module_mode) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: could not get current RTCP mode", __FUNCTION__); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + rtcp_mode = RTCPMethodToViERTCPMode(module_mode); + return 0; +} + +int ViERTP_RTCPImpl::SetRTCPCName(const int video_channel, + const char rtcp_cname[KMaxRTCPCNameLength]) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, name: %s)", __FUNCTION__, video_channel, + rtcp_cname); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d already sending.", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpAlreadySending); + return -1; + } + if (vie_channel->SetRTCPCName(rtcp_cname) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetRTCPCName(const int video_channel, + char rtcp_cname[KMaxRTCPCNameLength]) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetRTCPCName(rtcp_cname) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetRemoteRTCPCName( + const int video_channel, + char rtcp_cname[KMaxRTCPCNameLength]) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetRemoteRTCPCName(rtcp_cname) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::SendApplicationDefinedRTCPPacket( + const int video_channel, + const unsigned char sub_type, + unsigned int name, + const char* data, + unsigned short data_length_in_bytes) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, sub_type: %c, name: %d, data: x, length: %u)", + __FUNCTION__, video_channel, sub_type, name, + data_length_in_bytes); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (!vie_channel->Sending()) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d not sending", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpNotSending); + return -1; + } + RTCPMethod method; + if (vie_channel->GetRTCPMode(method) != 0 || method == kRtcpOff) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: RTCP disabled on channel %d.", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpRtcpDisabled); + return -1; + } + if (vie_channel->SendApplicationDefinedRTCPPacket( + sub_type, name, reinterpret_cast(data), + data_length_in_bytes) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::SetNACKStatus(const int video_channel, const bool enable) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel, + enable); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->SetNACKStatus(enable) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: failed for channel %d", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + + // Update the encoder + ViEEncoder* vie_encoder = cs.Encoder(video_channel); + if (!vie_encoder) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Could not get encoder for channel %d", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + vie_encoder->UpdateProtectionMethod(); + return 0; +} + +int ViERTP_RTCPImpl::SetFECStatus(const int video_channel, const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, enable: %d, payload_typeRED: %u, " + "payloadTypeFEC: %u)", + __FUNCTION__, video_channel, enable, payload_typeRED, + payload_typeFEC); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->SetFECStatus(enable, payload_typeRED, + payload_typeFEC) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: failed for channel %d", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + // Update the encoder. + ViEEncoder* vie_encoder = cs.Encoder(video_channel); + if (!vie_encoder) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Could not get encoder for channel %d", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + vie_encoder->UpdateProtectionMethod(); + return 0; +} + +int ViERTP_RTCPImpl::SetHybridNACKFECStatus( + const int video_channel, + const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, enable: %d, payload_typeRED: %u, " + "payloadTypeFEC: %u)", + __FUNCTION__, video_channel, enable, payload_typeRED, + payload_typeFEC); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + + // Update the channel status with hybrid NACK FEC mode. + if (vie_channel->SetHybridNACKFECStatus(enable, payload_typeRED, + payload_typeFEC) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: failed for channel %d", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + + // Update the encoder. + ViEEncoder* vie_encoder = cs.Encoder(video_channel); + if (!vie_encoder) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Could not get encoder for channel %d", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + vie_encoder->UpdateProtectionMethod(); + return 0; +} + +int ViERTP_RTCPImpl::SetKeyFrameRequestMethod( + const int video_channel, + const ViEKeyFrameRequestMethod method) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, method: %d)", __FUNCTION__, video_channel, + method); + + // Get the channel. + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + KeyFrameRequestMethod module_method = APIRequestToModuleRequest(method); + if (vie_channel->SetKeyFrameRequestMethod(module_method) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::SetTMMBRStatus(const int video_channel, + const bool enable) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel, + enable); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->EnableTMMBR(enable) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetReceivedRTCPStatistics(const int video_channel, + unsigned short& fraction_lost, + unsigned int& cumulative_lost, + unsigned int& extended_max, + unsigned int& jitter, + int& rtt_ms) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetReceivedRtcpStatistics( + static_cast(fraction_lost), + static_cast(cumulative_lost), + static_cast(extended_max), + static_cast(jitter), + static_cast(rtt_ms)) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetSentRTCPStatistics(const int video_channel, + unsigned short& fraction_lost, + unsigned int& cumulative_lost, + unsigned int& extended_max, + unsigned int& jitter, + int& rtt_ms) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + + if (vie_channel->GetSendRtcpStatistics( + static_cast(fraction_lost), + static_cast(cumulative_lost), + static_cast(extended_max), + static_cast(jitter), + static_cast(rtt_ms)) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetRTPStatistics(const int video_channel, + unsigned int& bytes_sent, + unsigned int& packets_sent, + unsigned int& bytes_received, + unsigned int& packets_received) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->GetRtpStatistics( + static_cast(bytes_sent), + static_cast(packets_sent), + static_cast(bytes_received), + static_cast(packets_received)) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; +} + +int ViERTP_RTCPImpl::GetBandwidthUsage(const int video_channel, + unsigned int& total_bitrate_sent, + unsigned int& video_bitrate_sent, + unsigned int& fec_bitrate_sent, + unsigned int& nackBitrateSent) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + vie_channel->GetBandwidthUsage( + static_cast(total_bitrate_sent), + static_cast(video_bitrate_sent), + static_cast(fec_bitrate_sent), static_cast(nackBitrateSent)); return 0; } -// ============================================================================ -// Keep alive -// ============================================================================ - -// ---------------------------------------------------------------------------- -// SetRTPKeepAliveStatus -// -// Enable/disable RTP keepaliv packets on a non-sending channel -// ---------------------------------------------------------------------------- - int ViERTP_RTCPImpl::SetRTPKeepAliveStatus( - const int videoChannel, bool enable, const char unknownPayloadType, - const unsigned int deltaTransmitTimeSeconds) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, enable: %d, unknownPayloadType: %d, " - "deltaTransmitTimeMS: %ul)", - __FUNCTION__, videoChannel, enable, (int) unknownPayloadType, - deltaTransmitTimeSeconds); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - WebRtc_UWord16 deltaTransmitTimeMs = 1000 * deltaTransmitTimeSeconds; - if (ptrViEChannel->SetKeepAliveStatus(enable, unknownPayloadType, - deltaTransmitTimeMs) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; + const int video_channel, + bool enable, + const char unknown_payload_type, + const unsigned int delta_transmit_time_seconds) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, enable: %d, unknown_payload_type: %d, " + "deltaTransmitTimeMS: %ul)", + __FUNCTION__, video_channel, enable, + static_cast(unknown_payload_type), + delta_transmit_time_seconds); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, + ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, + video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + WebRtc_UWord16 delta_transmit_time_ms = 1000 * delta_transmit_time_seconds; + if (vie_channel->SetKeepAliveStatus(enable, unknown_payload_type, + delta_transmit_time_ms) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// GetRTPKeepAliveStatus -// ---------------------------------------------------------------------------- - int ViERTP_RTCPImpl::GetRTPKeepAliveStatus( - const int videoChannel, bool& enabled, char& unknownPayloadType, - unsigned int& deltaTransmitTimeSeconds) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); + const int video_channel, + bool& enabled, + char& unknown_payload_type, + unsigned int& delta_transmit_time_seconds) const { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - WebRtc_UWord16 deltaTimeMs = 0; - int retVal = ptrViEChannel->GetKeepAliveStatus(enabled, unknownPayloadType, - deltaTimeMs); - deltaTransmitTimeSeconds = deltaTimeMs / 1000; - if (retVal != 0) - { - SetLastError(kViERtpRtcpUnknownError); - } - return retVal; + WebRtc_UWord16 delta_time_ms = 0; + int ret_val = vie_channel->GetKeepAliveStatus(enabled, unknown_payload_type, + delta_time_ms); + delta_transmit_time_seconds = delta_time_ms / 1000; + if (ret_val != 0) { + SetLastError(kViERtpRtcpUnknownError); + } + return ret_val; } -// ============================================================================ -// Dump RTP stream, for debug purpose -// ============================================================================ - -// ---------------------------------------------------------------------------- -// StartRTPDump -// -// SAves all incoming/outgoing packets to a file -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::StartRTPDump(const int videoChannel, - const char fileNameUTF8[1024], - RTPDirections direction) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, fileName: %s, direction: %d)", __FUNCTION__, - videoChannel, fileNameUTF8, direction); - - assert(FileWrapper::kMaxFileNameSize == 1024); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->StartRTPDump(fileNameUTF8, direction) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; +int ViERTP_RTCPImpl::StartRTPDump(const int video_channel, + const char file_nameUTF8[1024], + RTPDirections direction) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, file_name: %s, direction: %d)", __FUNCTION__, + video_channel, file_nameUTF8, direction); + assert(FileWrapper::kMaxFileNameSize == 1024); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->StartRTPDump(file_nameUTF8, direction) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// StopRTPDump -// -// Stops the RTP dump -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::StopRTPDump(const int videoChannel, - RTPDirections direction) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s(channel: %d, direction: %d)", __FUNCTION__, videoChannel, - direction); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->StopRTPDump(direction) != 0) - { - SetLastError(kViERtpRtcpUnknownError); - return -1; - } - return 0; +int ViERTP_RTCPImpl::StopRTPDump(const int video_channel, + RTPDirections direction) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d, direction: %d)", __FUNCTION__, video_channel, + direction); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->StopRTPDump(direction) != 0) { + SetLastError(kViERtpRtcpUnknownError); + return -1; + } + return 0; } -// ============================================================================ -// Callback -// ============================================================================ - -// ---------------------------------------------------------------------------- -// RegisterRTPObserver -// -// -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::RegisterRTPObserver(const int videoChannel, - ViERTPObserver& observer) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->RegisterRtpObserver(&observer) != 0) - { - SetLastError(kViERtpRtcpObserverAlreadyRegistered); - return -1; - } - return 0; +int ViERTP_RTCPImpl::RegisterRTPObserver(const int video_channel, + ViERTPObserver& observer) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->RegisterRtpObserver(&observer) != 0) { + SetLastError(kViERtpRtcpObserverAlreadyRegistered); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// DeregisterRTPObserver -// -// Deregisters a set observer -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::DeregisterRTPObserver(const int videoChannel) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->RegisterRtpObserver(NULL) != 0) - { - SetLastError(kViERtpRtcpObserverNotRegistered); - return -1; - } - return 0; -} -// ---------------------------------------------------------------------------- -// RegisterRTCPObserver -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::RegisterRTCPObserver(const int videoChannel, - ViERTCPObserver& observer) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - } - - if (ptrViEChannel->RegisterRtcpObserver(&observer) != 0) - { - SetLastError(kViERtpRtcpObserverAlreadyRegistered); - return -1; - } - return 0; +int ViERTP_RTCPImpl::DeregisterRTPObserver(const int video_channel) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, + ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->RegisterRtpObserver(NULL) != 0) { + SetLastError(kViERtpRtcpObserverNotRegistered); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// DeregisterRTCPObserver -// ---------------------------------------------------------------------------- - -int ViERTP_RTCPImpl::DeregisterRTCPObserver(const int videoChannel) -{ - WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), "%s(channel: %d)", - __FUNCTION__, videoChannel); - - // Get the channel - ViEChannelManagerScoped cs(channel_manager_); - ViEChannel* ptrViEChannel = cs.Channel(videoChannel); - if (ptrViEChannel == NULL) - { - // The channel doesn't exists - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, - ViEId(instance_id_, videoChannel), - "%s: Channel %d doesn't exist", __FUNCTION__, - videoChannel); - SetLastError(kViERtpRtcpInvalidChannelId); - return -1; - - } - - if (ptrViEChannel->RegisterRtcpObserver(NULL) != 0) - { - SetLastError(kViERtpRtcpObserverNotRegistered); - return -1; - } - return 0; +int ViERTP_RTCPImpl::RegisterRTCPObserver(const int video_channel, + ViERTCPObserver& observer) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->RegisterRtcpObserver(&observer) != 0) { + SetLastError(kViERtpRtcpObserverAlreadyRegistered); + return -1; + } + return 0; } -// ============================================================================ -// Prsivate methods -// ============================================================================ - -// ---------------------------------------------------------------------------- -// ViERTCPModeToRTCPMethod -// -// Help method for converting API mode to Module mode -// ---------------------------------------------------------------------------- - -RTCPMethod ViERTP_RTCPImpl::ViERTCPModeToRTCPMethod(ViERTCPMode apiMode) -{ - switch (apiMode) - { - case kRtcpNone: - return kRtcpOff; - - case kRtcpCompound_RFC4585: - return kRtcpCompound; - - case kRtcpNonCompound_RFC5506: - return kRtcpNonCompound; - - default: - assert(false); - return kRtcpOff; - } +int ViERTP_RTCPImpl::DeregisterRTCPObserver(const int video_channel) { + WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel), + "%s(channel: %d)", __FUNCTION__, video_channel); + ViEChannelManagerScoped cs(channel_manager_); + ViEChannel* vie_channel = cs.Channel(video_channel); + if (!vie_channel) { + WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel), + "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); + SetLastError(kViERtpRtcpInvalidChannelId); + return -1; + } + if (vie_channel->RegisterRtcpObserver(NULL) != 0) { + SetLastError(kViERtpRtcpObserverNotRegistered); + return -1; + } + return 0; } -// ---------------------------------------------------------------------------- -// RTCPMethodToViERTCPMode -// -// Help method for converting API mode to Module mode -// ---------------------------------------------------------------------------- - -ViERTCPMode ViERTP_RTCPImpl::RTCPMethodToViERTCPMode(RTCPMethod moduleMethod) -{ - switch (moduleMethod) - { - case kRtcpOff: - return kRtcpNone; - - case kRtcpCompound: - return kRtcpCompound_RFC4585; - - case kRtcpNonCompound: - return kRtcpNonCompound_RFC5506; - - default: - assert(false); - return kRtcpNone; - } -} - -KeyFrameRequestMethod ViERTP_RTCPImpl::APIRequestToModuleRequest( - ViEKeyFrameRequestMethod apiMethod) -{ - switch (apiMethod) - { - case kViEKeyFrameRequestNone: - return kKeyFrameReqFirRtp; - - case kViEKeyFrameRequestPliRtcp: - return kKeyFrameReqPliRtcp; - - case kViEKeyFrameRequestFirRtp: - return kKeyFrameReqFirRtp; - - case kViEKeyFrameRequestFirRtcp: - return kKeyFrameReqFirRtcp; - - default: - assert(false); - return kKeyFrameReqFirRtp; - } -} -} // namespace webrtc +} // namespace webrtc diff --git a/src/video_engine/vie_rtp_rtcp_impl.h b/src/video_engine/vie_rtp_rtcp_impl.h index 5c3a479cd0..2bd6e45e00 100644 --- a/src/video_engine/vie_rtp_rtcp_impl.h +++ b/src/video_engine/vie_rtp_rtcp_impl.h @@ -8,150 +8,108 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * vie_rtp_rtcp_impl.h - */ +#ifndef WEBRTC_VIDEO_ENGINE_VIE_RTP_RTCP_IMPL_H_ +#define WEBRTC_VIDEO_ENGINE_VIE_RTP_RTCP_IMPL_H_ -#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RTP_RTCP_IMPL_H_ -#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RTP_RTCP_IMPL_H_ - -#include "vie_defines.h" - -#include "rtp_rtcp_defines.h" +#include "modules/rtp_rtcp/interface/rtp_rtcp_defines.h" #include "typedefs.h" -#include "vie_ref_count.h" -#include "vie_rtp_rtcp.h" -#include "vie_shared_data.h" +#include "video_engine/main/interface/vie_rtp_rtcp.h" +#include "video_engine/vie_ref_count.h" +#include "video_engine/vie_shared_data.h" -namespace webrtc -{ +namespace webrtc { -// ---------------------------------------------------------------------------- -// ViERTP_RTCPImpl -// ---------------------------------------------------------------------------- +class ViERTP_RTCPImpl + : public virtual ViESharedData, + public ViERTP_RTCP, + public ViERefCount { + public: + // Implements ViERTP_RTCP + virtual int Release(); + virtual int SetLocalSSRC(const int video_channel, + const unsigned int SSRC, + const StreamType usage, + const unsigned char simulcast_idx); + virtual int GetLocalSSRC(const int video_channel, unsigned int& SSRC) const; + virtual int SetRemoteSSRCType(const int video_channel, + const StreamType usage, + const unsigned int SSRC) const; + virtual int GetRemoteSSRC(const int video_channel, unsigned int& SSRC) const; + virtual int GetRemoteCSRCs(const int video_channel, + unsigned int CSRCs[kRtpCsrcSize]) const; + virtual int SetStartSequenceNumber(const int video_channel, + unsigned short sequence_number); + virtual int SetRTCPStatus(const int video_channel, + const ViERTCPMode rtcp_mode); + virtual int GetRTCPStatus(const int video_channel, + ViERTCPMode& rtcp_mode) const; + virtual int SetRTCPCName(const int video_channel, + const char rtcp_cname[KMaxRTCPCNameLength]); + virtual int GetRTCPCName(const int video_channel, + char rtcp_cname[KMaxRTCPCNameLength]) const; + virtual int GetRemoteRTCPCName(const int video_channel, + char rtcp_cname[KMaxRTCPCNameLength]) const; + virtual int SendApplicationDefinedRTCPPacket( + const int video_channel, + const unsigned char sub_type, + unsigned int name, + const char* data, + unsigned short data_length_in_bytes); + virtual int SetNACKStatus(const int video_channel, const bool enable); + virtual int SetFECStatus(const int video_channel, const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC); + virtual int SetHybridNACKFECStatus(const int video_channel, const bool enable, + const unsigned char payload_typeRED, + const unsigned char payload_typeFEC); + virtual int SetKeyFrameRequestMethod(const int video_channel, + const ViEKeyFrameRequestMethod method); + virtual int SetTMMBRStatus(const int video_channel, const bool enable); + virtual int GetReceivedRTCPStatistics(const int video_channel, + unsigned short& fraction_lost, + unsigned int& cumulative_lost, + unsigned int& extended_max, + unsigned int& jitter, + int& rtt_ms) const; + virtual int GetSentRTCPStatistics(const int video_channel, + unsigned short& fraction_lost, + unsigned int& cumulative_lost, + unsigned int& extended_max, + unsigned int& jitter, int& rtt_ms) const; + virtual int GetRTPStatistics(const int video_channel, + unsigned int& bytes_sent, + unsigned int& packets_sent, + unsigned int& bytes_received, + unsigned int& packets_received) const; + virtual int GetBandwidthUsage(const int video_channel, + unsigned int& total_bitrate_sent, + unsigned int& video_bitrate_sent, + unsigned int& fec_bitrate_sent, + unsigned int& nackBitrateSent) const; + virtual int SetRTPKeepAliveStatus( + const int video_channel, bool enable, const char unknown_payload_type, + const unsigned int delta_transmit_time_seconds); + virtual int GetRTPKeepAliveStatus( + const int video_channel, + bool& enabled, + char& unkown_payload_type, + unsigned int& delta_transmit_time_seconds) const; + virtual int StartRTPDump(const int video_channel, + const char file_nameUTF8[1024], + RTPDirections direction); + virtual int StopRTPDump(const int video_channel, RTPDirections direction); + virtual int RegisterRTPObserver(const int video_channel, + ViERTPObserver& observer); + virtual int DeregisterRTPObserver(const int video_channel); + virtual int RegisterRTCPObserver(const int video_channel, + ViERTCPObserver& observer); + virtual int DeregisterRTCPObserver(const int video_channel); -class ViERTP_RTCPImpl : public virtual ViESharedData, - public ViERTP_RTCP, - public ViERefCount -{ -public: - virtual int Release(); - - // SSRC/CSRC - virtual int SetLocalSSRC(const int videoChannel, - const unsigned int SSRC, - const StreamType usage, - const unsigned char simulcastIdx); - - virtual int GetLocalSSRC(const int videoChannel, unsigned int& SSRC) const; - - virtual int SetRemoteSSRCType(const int videoChannel, - const StreamType usage, - const unsigned int SSRC) const; - - virtual int GetRemoteSSRC(const int videoChannel, unsigned int& SSRC) const; - - virtual int GetRemoteCSRCs(const int videoChannel, - unsigned int CSRCs[kRtpCsrcSize]) const; - - virtual int SetStartSequenceNumber(const int videoChannel, - unsigned short sequenceNumber); - - // RTCP - virtual int SetRTCPStatus(const int videoChannel, - const ViERTCPMode rtcpMode); - - virtual int GetRTCPStatus(const int videoChannel, ViERTCPMode& rtcpMode); - - virtual int SetRTCPCName(const int videoChannel, - const char rtcpCName[KMaxRTCPCNameLength]); - - virtual int GetRTCPCName(const int videoChannel, - char rtcpCName[KMaxRTCPCNameLength]); - - virtual int GetRemoteRTCPCName(const int videoChannel, - char rtcpCName[KMaxRTCPCNameLength]) const; - - virtual int - SendApplicationDefinedRTCPPacket(const int videoChannel, - const unsigned char subType, - unsigned int name, const char* data, - unsigned short dataLengthInBytes); - - virtual int SetNACKStatus(const int videoChannel, const bool enable); - - virtual int SetFECStatus(const int videoChannel, const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC); - virtual int SetHybridNACKFECStatus(const int videoChannel, const bool enable, - const unsigned char payloadTypeRED, - const unsigned char payloadTypeFEC); - - virtual int SetKeyFrameRequestMethod(const int videoChannel, - const ViEKeyFrameRequestMethod method); - - virtual int SetTMMBRStatus(const int videoChannel, const bool enable); - - // Statistics - virtual int GetReceivedRTCPStatistics( - const int videoChannel, unsigned short& fractionLost, - unsigned int& cumulativeLost, unsigned int& extendedMax, - unsigned int& jitter, int& rttMs) const; - - virtual int GetSentRTCPStatistics(const int videoChannel, - unsigned short& fractionLost, - unsigned int& cumulativeLost, - unsigned int& extendedMax, - unsigned int& jitter, int& rttMs) const; - - virtual int GetRTPStatistics(const int videoChannel, - unsigned int& bytesSent, - unsigned int& packetsSent, - unsigned int& bytesReceived, - unsigned int& packetsReceived) const; - - virtual int GetBandwidthUsage(const int videoChannel, - unsigned int& totalBitrateSent, - unsigned int& videoBitrateSent, - unsigned int& fecBitrateSent, - unsigned int& nackBitrateSent) const; - - // Keep alive - virtual int SetRTPKeepAliveStatus( - const int videoChannel, bool enable, const char unknownPayloadType, - const unsigned int deltaTransmitTimeSeconds); - - virtual int GetRTPKeepAliveStatus(const int videoChannel, bool& enabled, - char& unkownPayloadType, - unsigned int& deltaTransmitTimeSeconds); - - // Dump RTP stream, for debug purpose - virtual int StartRTPDump(const int videoChannel, - const char fileNameUTF8[1024], - RTPDirections direction); - - virtual int StopRTPDump(const int videoChannel, RTPDirections direction); - - // Callbacks - virtual int RegisterRTPObserver(const int videoChannel, - ViERTPObserver& observer); - - virtual int DeregisterRTPObserver(const int videoChannel); - - virtual int RegisterRTCPObserver(const int videoChannel, - ViERTCPObserver& observer); - - virtual int DeregisterRTCPObserver(const int videoChannel); - -protected: - ViERTP_RTCPImpl(); - virtual ~ViERTP_RTCPImpl(); - -private: - RTCPMethod ViERTCPModeToRTCPMethod(ViERTCPMode apiMode); - ViERTCPMode RTCPMethodToViERTCPMode(RTCPMethod moduleMethod); - KeyFrameRequestMethod - APIRequestToModuleRequest(const ViEKeyFrameRequestMethod apiMethod); + protected: + ViERTP_RTCPImpl(); + virtual ~ViERTP_RTCPImpl(); }; -} // namespace webrtc -#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_RTP_RTCP_IMPL_H_ + +} // namespace webrtc + +#endif // WEBRTC_VIDEO_ENGINE_VIE_RTP_RTCP_IMPL_H_