niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 11 | #include "video_engine/vie_encryption_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 13 | #include "system_wrappers/interface/trace.h" |
mflodman@webrtc.org | a4863db | 2011-12-22 08:51:52 +0000 | [diff] [blame] | 14 | #include "video_engine/include/vie_errors.h" |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 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" |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 19 | #include "video_engine/vie_shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 23 | ViEEncryption* ViEEncryption::GetInterface(VideoEngine* video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | #ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 25 | if (video_engine == NULL) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | return NULL; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 27 | } |
| 28 | VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine); |
| 29 | ViEEncryptionImpl* vie_encryption_impl = vie_impl; |
| 30 | // Increase ref count. |
| 31 | (*vie_encryption_impl)++; |
| 32 | return vie_encryption_impl; |
| 33 | #else |
| 34 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | #endif |
| 36 | } |
| 37 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 38 | int ViEEncryptionImpl::Release() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 39 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | "ViEEncryptionImpl::Release()"); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 41 | // Decrease ref count. |
| 42 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 44 | int32_t ref_count = GetCount(); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 45 | if (ref_count < 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 46 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 47 | "ViEEncryptionImpl release too many times"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 48 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 49 | return -1; |
| 50 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 51 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 52 | "ViEEncryptionImpl reference count: %d", ref_count); |
| 53 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | } |
| 55 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 56 | ViEEncryptionImpl::ViEEncryptionImpl(ViESharedData* shared_data) |
| 57 | : shared_data_(shared_data) { |
| 58 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | "ViEEncryptionImpl::ViEEncryptionImpl() Ctor"); |
| 60 | } |
| 61 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 62 | ViEEncryptionImpl::~ViEEncryptionImpl() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 63 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | "ViEEncryptionImpl::~ViEEncryptionImpl() Dtor"); |
| 65 | } |
| 66 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 67 | int ViEEncryptionImpl::RegisterExternalEncryption(const int video_channel, |
| 68 | Encryption& encryption) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 69 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 70 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 71 | "RegisterExternalEncryption(video_channel=%d)", video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 73 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 74 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 75 | if (vie_channel == NULL) { |
| 76 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 77 | ViEId(shared_data_->instance_id(), video_channel), |
| 78 | "%s: No channel %d", __FUNCTION__, video_channel); |
| 79 | shared_data_->SetLastError(kViEEncryptionInvalidChannelId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | return -1; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 81 | } |
| 82 | if (vie_channel->RegisterExternalEncryption(&encryption) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 83 | shared_data_->SetLastError(kViEEncryptionUnknownError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | return -1; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 85 | } |
| 86 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 89 | int ViEEncryptionImpl::DeregisterExternalEncryption(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 90 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 91 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 92 | "RegisterExternalEncryption(video_channel=%d)", video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 94 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 95 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 96 | if (vie_channel == NULL) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 97 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 98 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 99 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 100 | shared_data_->SetLastError(kViEEncryptionInvalidChannelId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | return -1; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 102 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 104 | if (vie_channel->DeRegisterExternalEncryption() != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 105 | shared_data_->SetLastError(kViEEncryptionUnknownError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | return -1; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 107 | } |
| 108 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | } |
| 110 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 111 | } // namespace webrtc |