niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_video_sync_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 13 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 14 | #include "webrtc/system_wrappers/interface/trace.h" |
| 15 | #include "webrtc/voice_engine/channel.h" |
| 16 | #include "webrtc/voice_engine/include/voe_errors.h" |
| 17 | #include "webrtc/voice_engine/voice_engine_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | VoEVideoSync* VoEVideoSync::GetInterface(VoiceEngine* voiceEngine) |
| 22 | { |
| 23 | #ifndef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 24 | return NULL; |
| 25 | #else |
| 26 | if (NULL == voiceEngine) |
| 27 | { |
| 28 | return NULL; |
| 29 | } |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 30 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 31 | s->AddRef(); |
| 32 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | #endif |
| 34 | } |
| 35 | |
| 36 | #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 37 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 38 | VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 40 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor"); |
| 42 | } |
| 43 | |
| 44 | VoEVideoSyncImpl::~VoEVideoSyncImpl() |
| 45 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 46 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor"); |
| 48 | } |
| 49 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel, unsigned int& timestamp) |
| 51 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 52 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | "GetPlayoutTimestamp(channel=%d, timestamp=?)", channel); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 54 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 56 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 58 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | return -1; |
| 60 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 61 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
tommi@webrtc.org | 9ff87db | 2012-01-19 15:05:36 +0000 | [diff] [blame] | 62 | voe::Channel* channelPtr = sc.ChannelPtr(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | if (channelPtr == NULL) |
| 64 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 65 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | "GetPlayoutTimestamp() failed to locate channel"); |
| 67 | return -1; |
| 68 | } |
| 69 | return channelPtr->GetPlayoutTimestamp(timestamp); |
| 70 | } |
| 71 | |
| 72 | int VoEVideoSyncImpl::SetInitTimestamp(int channel, |
| 73 | unsigned int timestamp) |
| 74 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 75 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | "SetInitTimestamp(channel=%d, timestamp=%lu)", |
| 77 | channel, timestamp); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 78 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 80 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 82 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | return -1; |
| 84 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 85 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 87 | if (channelPtr == NULL) |
| 88 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 89 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | "SetInitTimestamp() failed to locate channel"); |
| 91 | return -1; |
| 92 | } |
| 93 | return channelPtr->SetInitTimestamp(timestamp); |
| 94 | } |
| 95 | |
| 96 | int VoEVideoSyncImpl::SetInitSequenceNumber(int channel, |
| 97 | short sequenceNumber) |
| 98 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 99 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)", |
| 101 | channel, sequenceNumber); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 102 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 104 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 106 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | return -1; |
| 108 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 109 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 111 | if (channelPtr == NULL) |
| 112 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 113 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | "SetInitSequenceNumber() failed to locate channel"); |
| 115 | return -1; |
| 116 | } |
| 117 | return channelPtr->SetInitSequenceNumber(sequenceNumber); |
| 118 | } |
| 119 | |
| 120 | int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel,int delayMs) |
| 121 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 122 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)", |
| 124 | channel, delayMs); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 125 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 127 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 129 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | return -1; |
| 131 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 132 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
tommi@webrtc.org | 9ff87db | 2012-01-19 15:05:36 +0000 | [diff] [blame] | 133 | voe::Channel* channelPtr = sc.ChannelPtr(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | if (channelPtr == NULL) |
| 135 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 136 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | "SetMinimumPlayoutDelay() failed to locate channel"); |
| 138 | return -1; |
| 139 | } |
| 140 | return channelPtr->SetMinimumPlayoutDelay(delayMs); |
| 141 | } |
| 142 | |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 143 | int VoEVideoSyncImpl::SetInitialPlayoutDelay(int channel, int delay_ms) |
| 144 | { |
| 145 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 146 | "SetInitialPlayoutDelay(channel=%d, delay_ms=%d)", |
| 147 | channel, delay_ms); |
| 148 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 149 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 150 | |
| 151 | if (!_shared->statistics().Initialized()) |
| 152 | { |
| 153 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 154 | return -1; |
| 155 | } |
| 156 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 157 | voe::Channel* channel_ptr = sc.ChannelPtr(); |
| 158 | if (channel_ptr == NULL) |
| 159 | { |
| 160 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 161 | "SetInitialPlayoutDelay() failed to locate channel"); |
| 162 | return -1; |
| 163 | } |
| 164 | return channel_ptr->SetInitialPlayoutDelay(delay_ms); |
| 165 | } |
| 166 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 167 | int VoEVideoSyncImpl::GetDelayEstimate(int channel, |
| 168 | int* jitter_buffer_delay_ms, |
| 169 | int* playout_buffer_delay_ms) { |
| 170 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 171 | "GetDelayEstimate(channel=%d, delayMs=?)", channel); |
| 172 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 174 | if (!_shared->statistics().Initialized()) { |
| 175 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 176 | return -1; |
| 177 | } |
| 178 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 179 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 180 | if (channelPtr == NULL) { |
| 181 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 182 | "GetDelayEstimate() failed to locate channel"); |
| 183 | return -1; |
| 184 | } |
| 185 | if (!channelPtr->GetDelayEstimate(jitter_buffer_delay_ms, |
| 186 | playout_buffer_delay_ms)) { |
| 187 | return -1; |
| 188 | } |
| 189 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) |
| 193 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 194 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | "GetPlayoutBufferSize(bufferMs=?)"); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 196 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 198 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 200 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | return -1; |
| 202 | } |
| 203 | AudioDeviceModule::BufferType type |
| 204 | (AudioDeviceModule::kFixedBufferSize); |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 205 | uint16_t sizeMS(0); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 206 | if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 208 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
tommi@webrtc.org | 9ff87db | 2012-01-19 15:05:36 +0000 | [diff] [blame] | 209 | "GetPlayoutBufferSize() failed to read buffer size"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | return -1; |
| 211 | } |
| 212 | bufferMs = sizeMS; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 213 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 214 | VoEId(_shared->instance_id(), -1), |
| 215 | "GetPlayoutBufferSize() => bufferMs=%d", bufferMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
tommi@webrtc.org | 9ff87db | 2012-01-19 15:05:36 +0000 | [diff] [blame] | 219 | int VoEVideoSyncImpl::GetRtpRtcp(int channel, RtpRtcp* &rtpRtcpModule) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 221 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 222 | "GetRtpRtcp(channel=%i)", channel); |
fischman@webrtc.org | f61e02c | 2013-02-20 23:13:46 +0000 | [diff] [blame] | 223 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 224 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 225 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 226 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | return -1; |
| 228 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 229 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 231 | if (channelPtr == NULL) |
| 232 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 233 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 234 | "GetPlayoutTimestamp() failed to locate channel"); |
| 235 | return -1; |
| 236 | } |
| 237 | return channelPtr->GetRtpRtcp(rtpRtcpModule); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | #endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 242 | |
| 243 | } // namespace webrtc |