blob: 022322c7732035052179554c37874cb0e3f7fccb [file] [log] [blame]
Chung-Cheng Lou9bf59422012-03-02 15:53:23 -08001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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 "video_engine/vie_encryption_impl.h"
12
13#include "system_wrappers/interface/trace.h"
14#include "video_engine/include/vie_errors.h"
15#include "video_engine/vie_channel.h"
16#include "video_engine/vie_channel_manager.h"
17#include "video_engine/vie_defines.h"
18#include "video_engine/vie_impl.h"
19
20namespace webrtc {
21
22ViEEncryption* ViEEncryption::GetInterface(VideoEngine* video_engine) {
23#ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API
24 if (video_engine == NULL) {
25 return NULL;
26 }
27 VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
28 ViEEncryptionImpl* vie_encryption_impl = vie_impl;
29 // Increase ref count.
30 (*vie_encryption_impl)++;
31 return vie_encryption_impl;
32#else
33 return NULL;
34#endif
35}
36
37int ViEEncryptionImpl::Release() {
38 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_,
39 "ViEEncryptionImpl::Release()");
40 // Decrease ref count.
41 (*this)--;
42
43 WebRtc_Word32 ref_count = GetCount();
44 if (ref_count < 0) {
45 WEBRTC_TRACE(kTraceWarning, kTraceVideo, instance_id_,
46 "ViEEncryptionImpl release too many times");
47 SetLastError(kViEAPIDoesNotExist);
48 return -1;
49 }
50 WEBRTC_TRACE(kTraceInfo, kTraceVideo, instance_id_,
51 "ViEEncryptionImpl reference count: %d", ref_count);
52 return ref_count;
53}
54
55ViEEncryptionImpl::ViEEncryptionImpl() {
56 WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_,
57 "ViEEncryptionImpl::ViEEncryptionImpl() Ctor");
58}
59
60ViEEncryptionImpl::~ViEEncryptionImpl() {
61 WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_,
62 "ViEEncryptionImpl::~ViEEncryptionImpl() Dtor");
63}
64
65int ViEEncryptionImpl::RegisterExternalEncryption(const int video_channel,
66 Encryption& encryption) {
67 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel),
68 "RegisterExternalEncryption(video_channel=%d)", video_channel);
69
70 ViEChannelManagerScoped cs(channel_manager_);
71 ViEChannel* vie_channel = cs.Channel(video_channel);
72 if (vie_channel == NULL) {
73 WEBRTC_TRACE(kTraceError, kTraceVideo,
74 ViEId(instance_id_, video_channel), "%s: No channel %d",
75 __FUNCTION__, video_channel);
76 SetLastError(kViEEncryptionInvalidChannelId);
77 return -1;
78 }
79 if (vie_channel->RegisterExternalEncryption(&encryption) != 0) {
80 SetLastError(kViEEncryptionUnknownError);
81 return -1;
82 }
83 return 0;
84}
85
86int ViEEncryptionImpl::DeregisterExternalEncryption(const int video_channel) {
87 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_, video_channel),
88 "RegisterExternalEncryption(video_channel=%d)", video_channel);
89
90 ViEChannelManagerScoped cs(channel_manager_);
91 ViEChannel* vie_channel = cs.Channel(video_channel);
92 if (vie_channel == NULL) {
93 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
94 "%s: No channel %d", __FUNCTION__, video_channel);
95 SetLastError(kViEEncryptionInvalidChannelId);
96 return -1;
97 }
98
99 if (vie_channel->DeRegisterExternalEncryption() != 0) {
100 SetLastError(kViEEncryptionUnknownError);
101 return -1;
102 }
103 return 0;
104}
105
106} // namespace webrtc