Refactored ViEEncryptionImpl, ViECodecImpl and removed unused SRTP hooks/APIs in ViEEncrption.

Review URL: http://webrtc-codereview.appspot.com/331004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1262 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2011-12-21 09:29:28 +00:00
parent 898f881e32
commit c12686c2d0
5 changed files with 762 additions and 1594 deletions

View File

@ -29,11 +29,6 @@ class VideoEngine;
class WEBRTC_DLLEXPORT ViEEncryption class WEBRTC_DLLEXPORT ViEEncryption
{ {
public: public:
enum
{
kMaxSrtpKeyLength = 30
};
// Factory for the ViEEncryption subAPI and increases an internal reference // Factory for the ViEEncryption subAPI and increases an internal reference
// counter if successful. Returns NULL if the API is not supported or if // counter if successful. Returns NULL if the API is not supported or if
// construction fails. // construction fails.
@ -45,35 +40,6 @@ public:
// for all sub-API:s before the VideoEngine object can be safely deleted. // for all sub-API:s before the VideoEngine object can be safely deleted.
virtual int Release() = 0; virtual int Release() = 0;
// This function enables SRTP on send packets for a specific channel.
virtual int EnableSRTPSend(const int videoChannel,
const CipherTypes cipherType,
const unsigned int cipherKeyLength,
const AuthenticationTypes authType,
const unsigned int authKeyLength,
const unsigned int authTagLength,
const SecurityLevels level,
const unsigned char key[kMaxSrtpKeyLength],
const bool useForRTCP = false) = 0;
// This function disables SRTP for the specified channel.
virtual int DisableSRTPSend(const int videoChannel) = 0;
// This function enables SRTP on the received packets for a specific
// channel.
virtual int EnableSRTPReceive(const int videoChannel,
const CipherTypes cipherType,
const unsigned int cipherKeyLength,
const AuthenticationTypes authType,
const unsigned int authKeyLength,
const unsigned int authTagLength,
const SecurityLevels level,
const unsigned char key[kMaxSrtpKeyLength],
const bool useForRTCP = false) = 0;
// This function disables SRTP on received packets for a specific channel.
virtual int DisableSRTPReceive(const int videoChannel) = 0;
// This function registers a encryption derived instance and enables // This function registers a encryption derived instance and enables
// external encryption for the specified channel. // external encryption for the specified channel.
virtual int RegisterExternalEncryption(const int videoChannel, virtual int RegisterExternalEncryption(const int videoChannel,

File diff suppressed because it is too large Load Diff

View File

@ -8,105 +8,71 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
/* #ifndef WEBRTC_VIDEO_ENGINE_VIE_CODEC_IMPL_H_
* vie_codec_impl.h #define WEBRTC_VIDEO_ENGINE_VIE_CODEC_IMPL_H_
*/
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CODEC_IMPL_H_
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CODEC_IMPL_H_
#include "vie_defines.h"
#include "typedefs.h" #include "typedefs.h"
#include "vie_ref_count.h" #include "video_engine/main/interface/vie_codec.h"
#include "vie_shared_data.h" #include "video_engine/vie_defines.h"
#include "vie_codec.h" #include "video_engine/vie_ref_count.h"
#include "video_engine/vie_shared_data.h"
namespace webrtc namespace webrtc {
{
// ---------------------------------------------------------------------------- class ViECodecImpl
// ViECodecImpl : public virtual ViESharedData,
// ---------------------------------------------------------------------------- public ViECodec,
public ViERefCount {
public:
virtual int Release();
class ViECodecImpl : public virtual ViESharedData, // Implements ViECodec.
public ViECodec, virtual int NumberOfCodecs() const;
public ViERefCount virtual int GetCodec(const unsigned char list_number,
{ VideoCodec& video_codec) const;
public: virtual int SetSendCodec(const int video_channel,
virtual int Release(); const VideoCodec& video_codec);
virtual int GetSendCodec(const int video_channel,
VideoCodec& video_codec) const;
virtual int SetReceiveCodec(const int video_channel,
const VideoCodec& video_codec);
virtual int GetReceiveCodec(const int video_channel,
VideoCodec& video_codec) const;
virtual int GetCodecConfigParameters(
const int video_channel,
unsigned char config_parameters[kConfigParameterSize],
unsigned char& config_parameters_size) const;
virtual int SetImageScaleStatus(const int video_channel, const bool enable);
virtual int GetSendCodecStastistics(const int video_channel,
unsigned int& key_frames,
unsigned int& delta_frames) const;
virtual int GetReceiveCodecStastistics(const int video_channel,
unsigned int& key_frames,
unsigned int& delta_frames) const;
virtual unsigned int GetDiscardedPackets(const int video_channel) const;
virtual int SetKeyFrameRequestCallbackStatus(const int video_channel,
const bool enable);
virtual int SetSignalKeyPacketLossStatus(const int video_channel,
const bool enable,
const bool only_key_frames = false);
virtual int RegisterEncoderObserver(const int video_channel,
ViEEncoderObserver& observer);
virtual int DeregisterEncoderObserver(const int video_channel);
virtual int RegisterDecoderObserver(const int video_channel,
ViEDecoderObserver& observer);
virtual int DeregisterDecoderObserver(const int video_channel);
virtual int SendKeyFrame(const int video_channel);
virtual int WaitForFirstKeyFrame(const int video_channel, const bool wait);
virtual int SetInverseH263Logic(int video_channel, bool enable);
// Available codecs protected:
virtual int NumberOfCodecs() const; ViECodecImpl();
virtual ~ViECodecImpl();
virtual int GetCodec(const unsigned char listNumber, private:
VideoCodec& videoCodec) const; bool CodecValid(const VideoCodec& video_codec);
// Codec settings
virtual int SetSendCodec(const int videoChannel,
const VideoCodec& videoCodec);
virtual int GetSendCodec(const int videoChannel,
VideoCodec& videoCodec) const;
virtual int SetReceiveCodec(const int videoChannel,
const VideoCodec& videoCodec);
virtual int GetReceiveCodec(const int videoChannel,
VideoCodec& videoCodec) const;
virtual int GetCodecConfigParameters(
const int videoChannel,
unsigned char configParameters[kConfigParameterSize],
unsigned char& configParametersSize) const;
// Input image scaling
virtual int SetImageScaleStatus(const int videoChannel, const bool enable);
// Codec statistics
virtual int GetSendCodecStastistics(const int videoChannel,
unsigned int& keyFrames,
unsigned int& deltaFrames) const;
virtual int GetReceiveCodecStastistics(const int videoChannel,
unsigned int& keyFrames,
unsigned int& deltaFrames) const;
virtual unsigned int GetDiscardedPackets(const int videoChannel) const;
// Callbacks
virtual int SetKeyFrameRequestCallbackStatus(const int videoChannel,
const bool enable);
virtual int SetSignalKeyPacketLossStatus(const int videoChannel,
const bool enable,
const bool onlyKeyFrames = false);
virtual int RegisterEncoderObserver(const int videoChannel,
ViEEncoderObserver& observer);
virtual int DeregisterEncoderObserver(const int videoChannel);
virtual int RegisterDecoderObserver(const int videoChannel,
ViEDecoderObserver& observer);
virtual int DeregisterDecoderObserver(const int videoChannel);
// Key frame settings
virtual int SendKeyFrame(const int videoChannel);
virtual int WaitForFirstKeyFrame(const int videoChannel, const bool wait);
// H263 Specific
virtual int SetInverseH263Logic(int videoChannel, bool enable);
protected:
ViECodecImpl();
virtual ~ViECodecImpl();
private:
bool CodecValid(const VideoCodec& videoCodec);
}; };
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CODEC_IMPL_H_ } // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_VIE_CODEC_IMPL_H_

View File

@ -8,536 +8,99 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
/* #include "video_engine/vie_encryption_impl.h"
* vie_encryption_impl.cc
*/
#include "vie_encryption_impl.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_impl.h"
// Defines namespace webrtc {
#include "vie_defines.h"
#include "vie_errors.h"
#include "vie_channel.h"
#include "vie_channel_manager.h"
#include "trace.h" ViEEncryption* ViEEncryption::GetInterface(VideoEngine* video_engine) {
#include "vie_impl.h"
#ifdef WEBRTC_SRTP
#include "SrtpModule.h"
#endif
namespace webrtc
{
// ----------------------------------------------------------------------------
// GetInterface
// ----------------------------------------------------------------------------
ViEEncryption* ViEEncryption::GetInterface(VideoEngine* videoEngine)
{
#ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API #ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API
if (videoEngine == NULL) if (video_engine == NULL) {
{
return NULL;
}
VideoEngineImpl* vieImpl = reinterpret_cast<VideoEngineImpl*> (videoEngine);
ViEEncryptionImpl* vieEncryptionImpl = vieImpl;
(*vieEncryptionImpl)++; // Increase ref count
return vieEncryptionImpl;
#else
return NULL; return NULL;
}
VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
ViEEncryptionImpl* vie_encryption_impl = vie_impl;
// Increase ref count.
(*vie_encryption_impl)++;
return vie_encryption_impl;
#else
return NULL;
#endif #endif
} }
// ---------------------------------------------------------------------------- int ViEEncryptionImpl::Release() {
// Release WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_,
//
// Releases the interface, i.e. reduces the reference counter. The number of
// remaining references is returned, -1 if released too many times.
// ----------------------------------------------------------------------------
int ViEEncryptionImpl::Release()
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, instance_id_,
"ViEEncryptionImpl::Release()"); "ViEEncryptionImpl::Release()");
(*this)--; // Decrease ref count // Decrease ref count.
(*this)--;
WebRtc_Word32 refCount = GetCount(); WebRtc_Word32 ref_count = GetCount();
if (refCount < 0) if (ref_count < 0) {
{ WEBRTC_TRACE(kTraceWarning, kTraceVideo, instance_id_,
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, instance_id_, "ViEEncryptionImpl release too many times");
"ViEEncryptionImpl release too many times"); SetLastError(kViEAPIDoesNotExist);
SetLastError(kViEAPIDoesNotExist); return -1;
return -1; }
} WEBRTC_TRACE(kTraceInfo, kTraceVideo, instance_id_,
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, instance_id_, "ViEEncryptionImpl reference count: %d", ref_count);
"ViEEncryptionImpl reference count: %d", refCount); return ref_count;
return refCount;
} }
// ---------------------------------------------------------------------------- ViEEncryptionImpl::ViEEncryptionImpl() {
// Constructor WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_,
// ----------------------------------------------------------------------------
ViEEncryptionImpl::ViEEncryptionImpl()
{
WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, instance_id_,
"ViEEncryptionImpl::ViEEncryptionImpl() Ctor"); "ViEEncryptionImpl::ViEEncryptionImpl() Ctor");
} }
// ---------------------------------------------------------------------------- ViEEncryptionImpl::~ViEEncryptionImpl() {
// Destructor WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_,
// ----------------------------------------------------------------------------
ViEEncryptionImpl::~ViEEncryptionImpl()
{
WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, instance_id_,
"ViEEncryptionImpl::~ViEEncryptionImpl() Dtor"); "ViEEncryptionImpl::~ViEEncryptionImpl() Dtor");
} }
// ============================================================================ int ViEEncryptionImpl::RegisterExternalEncryption(const int video_channel,
// SRTP Encryption& encryption) {
// ============================================================================ WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel),
"RegisterExternalEncryption(video_channel=%d)", video_channel);
// ---------------------------------------------------------------------------- ViEChannelManagerScoped cs(channel_manager_);
// EnableSRTPSend ViEChannel* vie_channel = cs.Channel(video_channel);
// if (vie_channel == NULL) {
// ---------------------------------------------------------------------------- WEBRTC_TRACE(kTraceError, kTraceVideo,
ViEId(instance_id_, video_channel), "%s: No channel %d",
int ViEEncryptionImpl::EnableSRTPSend( __FUNCTION__, video_channel);
const int videoChannel, const CipherTypes cipherType, SetLastError(kViEEncryptionInvalidChannelId);
const unsigned int cipherKeyLength, const AuthenticationTypes authType,
const unsigned int authKeyLength, const unsigned int authTagLength,
const SecurityLevels level, const unsigned char key[kViEMaxSrtpKeyLength],
const bool useForRTCP)
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo, instance_id_,
"EnableSRTPSend(channel=%d, cipherType=%d, cipherKeyLength=%d, "
"authType=%d, authKeyLength=%d, authTagLength=%d, level=%d, "
"key=?, RTCP=%s",
videoChannel, cipherType, cipherKeyLength, authType,
authKeyLength, authTagLength, level,
useForRTCP ? "true" : "false");
#ifdef WEBRTC_SRTP
if (!IsInitialized())
{
SetLastError(kViENotInitialized);
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_),
"%s - ViE instance %d not initialized", __FUNCTION__,
instance_id_);
return -1;
}
bool cipherAllZero = (kCipherNull == cipherType) && (0 == cipherKeyLength);
bool authAllZero = (kAuthNull == authType) &&
(0 == authKeyLength) &&
(0 == authTagLength);
// 1. For no protection all cipher and auth must be zero
// 2. For encryption only all auth must be zero
// 3. For authentication only all cipher must be zero
if (((kNoProtection == level) && (!cipherAllZero || !authAllZero))
|| ((kEncryption == level) && !authAllZero)
|| ((kAuthentication == level) && !cipherAllZero))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, instance_id_,
" Invalid input argument");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
// 16 <= cipherKeyLength <= 256
if (((kEncryption == level) || (kEncryptionAndAuthentication == level))
&& ((cipherKeyLength < kViEMinSrtpEncryptLength)
|| (cipherKeyLength > kViEMaxSrtpEncryptLength)))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, instance_id_,
" Invalid cipher key length");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
// For HMAC_SHA1 auth:
// authKeyLength <= 20, authTagLength <= 20
if (((kAuthentication == level) || (kEncryptionAndAuthentication == level))
&& (kAuthHmacSha1 == authType)
&& ((authKeyLength > kViEMaxSrtpAuthSh1Length)
|| (authTagLength > kViEMaxSrtpAuthSh1Length)))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, instance_id_,
" Invalid auth key or tag length");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
// For NULL auth:
// authKeyLength <= 256, authTagLength <= 12
if (((kAuthentication == level) || (kEncryptionAndAuthentication == level))
&& (kAuthNull == authType)
&& ((authKeyLength > kViEMaxSrtpKeyAuthNullLength)
|| (authTagLength > kViEMaxSrtpTagAuthNullLength)))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, instance_id_,
" Invalid auth key or tag length");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
if (!key)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, instance_id_,
" key NULL pointer");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
const SrtpModule::CipherTypes cipher_type =
static_cast<const SrtpModule::CipherTypes> (cipherType);
const SrtpModule::AuthenticationTypes auth_type =
static_cast<const SrtpModule::AuthenticationTypes> (authType);
const SrtpModule::SecurityLevels security_level =
static_cast<const SrtpModule::SecurityLevels> (level);
ViEChannelManagerScoped cs(channel_manager_);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViEEncryptionInvalidChannelId);
return -1;
}
if (0 != vieChannel->EnableSRTPSend(cipher_type, cipherKeyLength, auth_type,
authKeyLength, authTagLength,
security_level, key, useForRTCP))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, instance_id_,
"Failed to configure SRTP Encryption for sending");
SetLastError(kViEEncryptionUnknownError);
return -1;
}
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, instance_id_,
"SRTP Enabled for sending");
return 0;
#else
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVoice,
ViEId(instance_id_, videoChannel),
" _SRTP is undefined => _lastError = %d",
LastErrorInternal());
SetLastError(kViEEncryptionSrtpNotSupported);
return -1; return -1;
#endif }
} if (vie_channel->RegisterExternalEncryption(&encryption) != 0) {
SetLastError(kViEEncryptionUnknownError);
// ----------------------------------------------------------------------------
// DisableSRTPSend
//
// ----------------------------------------------------------------------------
int ViEEncryptionImpl::DisableSRTPSend(const int videoChannel)
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"DisableSRTPSend(videoChannel=%d)", videoChannel);
#ifdef WEBRTC_SRTP
ViEChannelManagerScoped cs(channel_manager_);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViEEncryptionInvalidChannelId);
return -1;
}
if (0 != vieChannel->DisableSRTPSend())
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"Failed to Disable SRTP Encryption for sending");
SetLastError(kViEEncryptionUnknownError);
return -1;
}
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"SRTP Disabled for sending");
return 0;
#else
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVoice,
ViEId(instance_id_, videoChannel),
" _SRTP is undefined => _lastError = %d",
LastErrorInternal());
SetLastError(kViEEncryptionSrtpNotSupported);
return -1; return -1;
#endif }
return 0;
} }
// ---------------------------------------------------------------------------- int ViEEncryptionImpl::DeregisterExternalEncryption(const int video_channel) {
// EnableSRTPReceive WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel),
// "RegisterExternalEncryption(video_channel=%d)", video_channel);
// ----------------------------------------------------------------------------
int ViEEncryptionImpl::EnableSRTPReceive( ViEChannelManagerScoped cs(channel_manager_);
const int videoChannel, const CipherTypes cipherType, ViEChannel* vie_channel = cs.Channel(video_channel);
const unsigned int cipherKeyLength, const AuthenticationTypes authType, if (vie_channel == NULL) {
const unsigned int authKeyLength, const unsigned int authTagLength, WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
const SecurityLevels level, "%s: No channel %d", __FUNCTION__, video_channel);
const unsigned char key[kViEMaxSrtpKeyLength], const bool useForRTCP) SetLastError(kViEEncryptionInvalidChannelId);
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"EnableSRTPReceive(channel=%d, cipherType=%d, "
"cipherKeyLength=%d, authType=%d, authKeyLength=%d, "
"authTagLength=%d, level=%d, key=?, RTCP=%s)",
videoChannel, cipherType, cipherKeyLength, authType,
authKeyLength, authTagLength, level,
useForRTCP ? "true" : "false");
#ifdef WEBRTC_SRTP
if (!IsInitialized())
{
SetLastError(kViENotInitialized);
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(instance_id_),
"%s - ViE instance %d not initialized", __FUNCTION__,
instance_id_);
return -1;
}
bool cipherAllZero = (kCipherNull == cipherType) && (0 == cipherKeyLength);
bool authAllZero = (kAuthNull == authType)
&& (0 == authKeyLength)
&& (0 == authTagLength);
// 1. For no protection all cipher and auth must be zero
// 2. For encryption only all auth must be zero
// 3. For authentication only all cipher must be zero
if (((kNoProtection == level) && (!cipherAllZero || !authAllZero)) ||
((kEncryption == level) && !authAllZero) ||
((kAuthentication == level) && !cipherAllZero))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
" Invalid input argument");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
// 16 <= cipherKeyLength <= 256
if (((kEncryption == level) || (kEncryptionAndAuthentication == level))
&& ((cipherKeyLength < kViEMinSrtpEncryptLength)
|| (cipherKeyLength > kViEMaxSrtpEncryptLength)))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
" Invalid cipher key length");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
// For HMAC_SHA1 auth:
// authKeyLength <= 20, authTagLength <= 20
if (((kAuthentication == level) || (kEncryptionAndAuthentication == level))
&& (kAuthHmacSha1 == authType)
&& ((authKeyLength > kViEMaxSrtpAuthSh1Length)
|| (authTagLength > kViEMaxSrtpAuthSh1Length)))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
" Invalid auth key or tag length");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
// For NULL auth:
// authKeyLength <= 256, authTagLength <= 12
if (((kAuthentication == level) || (kEncryptionAndAuthentication == level))
&& (kAuthNull == authType)
&& ((authKeyLength > kViEMaxSrtpKeyAuthNullLength)
|| (authTagLength > kViEMaxSrtpTagAuthNullLength)))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
" Invalid auth key or tag length");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
if (!key)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), " key NULL pointer");
SetLastError(kViEEncryptionInvalidSrtpParameter);
return -1;
}
const SrtpModule::CipherTypes cipher_type =
static_cast<const SrtpModule::CipherTypes> (cipherType);
const SrtpModule::AuthenticationTypes auth_type =
static_cast<const SrtpModule::AuthenticationTypes> (authType);
const SrtpModule::SecurityLevels security_level =
static_cast<const SrtpModule::SecurityLevels> (level);
ViEChannelManagerScoped cs(channel_manager_);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViEEncryptionInvalidChannelId);
return -1;
}
if (0 != vieChannel->EnableSRTPReceive(cipher_type, cipherKeyLength,
auth_type, authKeyLength,
authTagLength, security_level, key,
useForRTCP))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"Failed to configure SRTP Encryption for receiving");
SetLastError(kViEEncryptionUnknownError);
return -1;
}
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"SRTP Enabled for receiving");
return 0;
#else
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVoice,
ViEId(instance_id_, videoChannel),
" _SRTP is undefined => _lastError = %d",
LastErrorInternal());
SetLastError(kViEEncryptionSrtpNotSupported);
return -1; return -1;
#endif }
}
// ---------------------------------------------------------------------------- if (vie_channel->DeRegisterExternalEncryption() != 0) {
// DisableSRTPReceive SetLastError(kViEEncryptionUnknownError);
//
// ----------------------------------------------------------------------------
int ViEEncryptionImpl::DisableSRTPReceive(const int videoChannel)
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"DisableSRTPReceive(videoChannel=%d)", videoChannel);
#ifdef WEBRTC_SRTP
ViEChannelManagerScoped cs(channel_manager_);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViEEncryptionInvalidChannelId);
return -1;
}
if (0 != vieChannel->DisableSRTPReceive())
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"Failed to Disable SRTP Encryption for receiving");
SetLastError(kViEEncryptionUnknownError);
return -1;
}
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "SRTP Disabled for receiving");
return 0;
#else
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVoice,
ViEId(instance_id_, videoChannel),
" _SRTP is undefined => _lastError = %d",
LastErrorInternal());
SetLastError(kViEEncryptionSrtpNotSupported);
return -1; return -1;
#endif }
return 0;
} }
// ============================================================================ } // namespace webrtc
// External encryption
// ============================================================================
// ----------------------------------------------------------------------------
// RegisterExternalEncryption
//
// ----------------------------------------------------------------------------
int ViEEncryptionImpl::RegisterExternalEncryption(const int videoChannel,
Encryption& encryption)
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"RegisterExternalEncryption(videoChannel=%d)", videoChannel);
ViEChannelManagerScoped cs(channel_manager_);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViEEncryptionInvalidChannelId);
return -1;
}
if (vieChannel->RegisterExternalEncryption(&encryption) != 0)
{
SetLastError(kViEEncryptionUnknownError);
return -1;
}
return 0;
}
// ----------------------------------------------------------------------------
// DeregisterExternalEncryption
//
// ----------------------------------------------------------------------------
int ViEEncryptionImpl::DeregisterExternalEncryption(const int videoChannel)
{
WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel),
"RegisterExternalEncryption(videoChannel=%d)", videoChannel);
ViEChannelManagerScoped cs(channel_manager_);
ViEChannel* vieChannel = cs.Channel(videoChannel);
if (vieChannel == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
ViEId(instance_id_, videoChannel), "%s: No channel %d",
__FUNCTION__, videoChannel);
SetLastError(kViEEncryptionInvalidChannelId);
return -1;
}
if (vieChannel->DeRegisterExternalEncryption() != 0)
{
SetLastError(kViEEncryptionUnknownError);
return -1;
}
return 0;
}
} // namespace webrtc

View File

@ -8,68 +8,33 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
/* #ifndef WEBRTC_VIDEO_ENGINE_VIE_ENCRYPTION_IMPL_H_
* vie_encryption_impl.h #define WEBRTC_VIDEO_ENGINE_VIE_ENCRYPTION_IMPL_H_
*/
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCRYPTION_IMPL_H_
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCRYPTION_IMPL_H_
#include "vie_defines.h"
#include "typedefs.h" #include "typedefs.h"
#include "vie_ref_count.h" #include "video_engine/main/interface/vie_encryption.h"
#include "vie_encryption.h" #include "video_engine/vie_ref_count.h"
#include "vie_shared_data.h" #include "video_engine/vie_shared_data.h"
namespace webrtc namespace webrtc {
{
// ---------------------------------------------------------------------------- class ViEEncryptionImpl
// ViEEncryptionImpl : public virtual ViESharedData,
// ---------------------------------------------------------------------------- public ViEEncryption,
public ViERefCount {
public:
virtual int Release();
class ViEEncryptionImpl : public virtual ViESharedData, // Implements ViEEncryption.
public ViEEncryption, virtual int RegisterExternalEncryption(const int video_channel,
public ViERefCount Encryption& encryption);
{ virtual int DeregisterExternalEncryption(const int video_channel);
public:
virtual int Release();
// SRTP calls protected:
virtual int EnableSRTPSend(const int videoChannel, ViEEncryptionImpl();
const CipherTypes cipherType, virtual ~ViEEncryptionImpl();
const unsigned int cipherKeyLength,
const AuthenticationTypes authType,
const unsigned int authKeyLength,
const unsigned int authTagLength,
const SecurityLevels level,
const unsigned char key[kViEMaxSrtpKeyLength],
const bool useForRTCP);
virtual int DisableSRTPSend(const int videoChannel);
virtual int EnableSRTPReceive(const int videoChannel,
const CipherTypes cipherType,
const unsigned int cipherKeyLength,
const AuthenticationTypes authType,
const unsigned int authKeyLength,
const unsigned int authTagLength,
const SecurityLevels level,
const unsigned char key[kViEMaxSrtpKeyLength],
const bool useForRTCP);
virtual int DisableSRTPReceive(const int videoChannel);
// External encryption
virtual int RegisterExternalEncryption(const int videoChannel,
Encryption& encryption);
virtual int DeregisterExternalEncryption(const int videoChannel);
protected:
ViEEncryptionImpl();
virtual ~ViEEncryptionImpl();
}; };
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCRYPTION_IMPL_H_ } // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_VIE_ENCRYPTION_IMPL_H_