blob: cad762aaa4263ac280a7ebcdf77fa4fcd21240e8 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tommi@webrtc.org851becd2012-04-04 14:57:19 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "voe_encryption_impl.h"
12
13
14#include "channel.h"
15#include "critical_section_wrapper.h"
16#include "trace.h"
17#include "voe_errors.h"
18#include "voice_engine_impl.h"
19
20namespace webrtc {
21
22VoEEncryption* VoEEncryption::GetInterface(VoiceEngine* voiceEngine)
23{
24#ifndef WEBRTC_VOICE_ENGINE_ENCRYPTION_API
25 return NULL;
26#else
27 if (NULL == voiceEngine)
28 {
29 return NULL;
30 }
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000031 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:22 +000032 s->AddRef();
33 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000034#endif
35}
36
37#ifdef WEBRTC_VOICE_ENGINE_ENCRYPTION_API
38
tommi@webrtc.org851becd2012-04-04 14:57:19 +000039VoEEncryptionImpl::VoEEncryptionImpl(voe::SharedData* shared) : _shared(shared)
niklase@google.com470e71d2011-07-07 08:21:25 +000040{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000041 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000042 "VoEEncryptionImpl::VoEEncryptionImpl() - ctor");
43}
44
45VoEEncryptionImpl::~VoEEncryptionImpl()
46{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000047 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000048 "VoEEncryptionImpl::~VoEEncryptionImpl() - dtor");
49}
50
niklase@google.com470e71d2011-07-07 08:21:25 +000051int VoEEncryptionImpl::RegisterExternalEncryption(int channel,
52 Encryption& encryption)
53{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000054 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000055 "RegisterExternalEncryption(channel=%d, encryption=0x%x)",
56 channel, &encryption);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000057 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000058 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000059 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000060 return -1;
61 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +000062 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000063 voe::Channel* channelPtr = sc.ChannelPtr();
64 if (channelPtr == NULL)
65 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000066 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000067 "RegisterExternalEncryption() failed to locate channel");
68 return -1;
69 }
70 return channelPtr->RegisterExternalEncryption(encryption);
71}
72
73int VoEEncryptionImpl::DeRegisterExternalEncryption(int channel)
74{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000075 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000076 "DeRegisterExternalEncryption(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000077 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000078 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000079 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000080 return -1;
81 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +000082 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000083 voe::Channel* channelPtr = sc.ChannelPtr();
84 if (channelPtr == NULL)
85 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000086 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000087 "DeRegisterExternalEncryption() failed to locate channel");
88 return -1;
89 }
90 return channelPtr->DeRegisterExternalEncryption();
91}
92
93#endif // #ifdef WEBRTC_VOICE_ENGINE_ENCRYPTION_API
94
95// EOF
96} // namespace webrtc