andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
pbos@webrtc.org | 471ae72 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_video_sync_impl.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 12 | |
turaj@webrtc.org | ead8a5b | 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" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +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 | b9e5a3d | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 30 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 31 | s->AddRef(); |
| 32 | return s; |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 37 | |
| 38 | VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared) |
| 39 | { |
| 40 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 41 | "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor"); |
| 42 | } |
| 43 | |
| 44 | VoEVideoSyncImpl::~VoEVideoSyncImpl() |
| 45 | { |
| 46 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 47 | "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor"); |
| 48 | } |
| 49 | |
| 50 | int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel, unsigned int& timestamp) |
| 51 | { |
| 52 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 53 | "GetPlayoutTimestamp(channel=%d, timestamp=?)", channel); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 54 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 55 | |
| 56 | if (!_shared->statistics().Initialized()) |
| 57 | { |
| 58 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 59 | return -1; |
| 60 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 61 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 62 | voe::Channel* channel_ptr = ch.channel(); |
| 63 | if (channel_ptr == NULL) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 64 | { |
| 65 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 66 | "GetPlayoutTimestamp() failed to locate channel"); |
| 67 | return -1; |
| 68 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 69 | return channel_ptr->GetPlayoutTimestamp(timestamp); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int VoEVideoSyncImpl::SetInitTimestamp(int channel, |
| 73 | unsigned int timestamp) |
| 74 | { |
| 75 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 76 | "SetInitTimestamp(channel=%d, timestamp=%lu)", |
| 77 | channel, timestamp); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 78 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 79 | |
| 80 | if (!_shared->statistics().Initialized()) |
| 81 | { |
| 82 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 83 | return -1; |
| 84 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 85 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 86 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 87 | if (channelPtr == NULL) |
| 88 | { |
| 89 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 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 | { |
| 99 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 100 | "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)", |
| 101 | channel, sequenceNumber); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 102 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 103 | |
| 104 | if (!_shared->statistics().Initialized()) |
| 105 | { |
| 106 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 107 | return -1; |
| 108 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 109 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 110 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 111 | if (channelPtr == NULL) |
| 112 | { |
| 113 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 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 | { |
| 122 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 123 | "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)", |
| 124 | channel, delayMs); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 125 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 126 | |
| 127 | if (!_shared->statistics().Initialized()) |
| 128 | { |
| 129 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 130 | return -1; |
| 131 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 132 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 133 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 134 | if (channelPtr == NULL) |
| 135 | { |
| 136 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 137 | "SetMinimumPlayoutDelay() failed to locate channel"); |
| 138 | return -1; |
| 139 | } |
| 140 | return channelPtr->SetMinimumPlayoutDelay(delayMs); |
| 141 | } |
| 142 | |
turaj@webrtc.org | ead8a5b | 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); |
turaj@webrtc.org | ead8a5b | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 148 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 149 | |
| 150 | if (!_shared->statistics().Initialized()) |
| 151 | { |
| 152 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 153 | return -1; |
| 154 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 155 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 156 | voe::Channel* channelPtr = ch.channel(); |
| 157 | if (channelPtr == NULL) |
turaj@webrtc.org | ead8a5b | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 158 | { |
| 159 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 160 | "SetInitialPlayoutDelay() failed to locate channel"); |
| 161 | return -1; |
| 162 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 163 | return channelPtr->SetInitialPlayoutDelay(delay_ms); |
turaj@webrtc.org | ead8a5b | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 164 | } |
| 165 | |
pwestin@webrtc.org | f272497 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 166 | int VoEVideoSyncImpl::GetDelayEstimate(int channel, |
| 167 | int* jitter_buffer_delay_ms, |
| 168 | int* playout_buffer_delay_ms) { |
| 169 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 170 | "GetDelayEstimate(channel=%d, delayMs=?)", channel); |
| 171 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 172 | |
pwestin@webrtc.org | f272497 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 173 | if (!_shared->statistics().Initialized()) { |
| 174 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 175 | return -1; |
| 176 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 177 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 178 | voe::Channel* channelPtr = ch.channel(); |
pwestin@webrtc.org | f272497 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 179 | if (channelPtr == NULL) { |
| 180 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 181 | "GetDelayEstimate() failed to locate channel"); |
| 182 | return -1; |
| 183 | } |
| 184 | if (!channelPtr->GetDelayEstimate(jitter_buffer_delay_ms, |
| 185 | playout_buffer_delay_ms)) { |
| 186 | return -1; |
| 187 | } |
| 188 | return 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) |
| 192 | { |
| 193 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 194 | "GetPlayoutBufferSize(bufferMs=?)"); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 195 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 196 | |
| 197 | if (!_shared->statistics().Initialized()) |
| 198 | { |
| 199 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 200 | return -1; |
| 201 | } |
| 202 | AudioDeviceModule::BufferType type |
| 203 | (AudioDeviceModule::kFixedBufferSize); |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 204 | uint16_t sizeMS(0); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 205 | if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0) |
| 206 | { |
| 207 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 208 | "GetPlayoutBufferSize() failed to read buffer size"); |
| 209 | return -1; |
| 210 | } |
| 211 | bufferMs = sizeMS; |
| 212 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 213 | VoEId(_shared->instance_id(), -1), |
| 214 | "GetPlayoutBufferSize() => bufferMs=%d", bufferMs); |
| 215 | return 0; |
| 216 | } |
| 217 | |
wu@webrtc.org | 7fc75bb | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 218 | int VoEVideoSyncImpl::GetRtpRtcp(int channel, RtpRtcp** rtpRtcpModule, |
| 219 | RtpReceiver** rtp_receiver) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 220 | { |
| 221 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 222 | "GetRtpRtcp(channel=%i)", channel); |
fischman@webrtc.org | 59b3a4c | 2013-02-20 23:13:46 +0000 | [diff] [blame] | 223 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 224 | if (!_shared->statistics().Initialized()) |
| 225 | { |
| 226 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 227 | return -1; |
| 228 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 229 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 230 | voe::Channel* channelPtr = ch.channel(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 231 | if (channelPtr == NULL) |
| 232 | { |
| 233 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 234 | "GetPlayoutTimestamp() failed to locate channel"); |
| 235 | return -1; |
| 236 | } |
wu@webrtc.org | 7fc75bb | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 237 | return channelPtr->GetRtpRtcp(rtpRtcpModule, rtp_receiver); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 238 | } |
| 239 | |
turaj@webrtc.org | d557734 | 2013-05-22 20:39:43 +0000 | [diff] [blame] | 240 | int VoEVideoSyncImpl::GetLeastRequiredDelayMs(int channel) const { |
| 241 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 242 | "GetLeastRequiredDelayMS(channel=%d)", channel); |
| 243 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 244 | |
| 245 | if (!_shared->statistics().Initialized()) { |
| 246 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 247 | return -1; |
| 248 | } |
pbos@webrtc.org | b3ada15 | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 249 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 250 | voe::Channel* channel_ptr = ch.channel(); |
turaj@webrtc.org | d557734 | 2013-05-22 20:39:43 +0000 | [diff] [blame] | 251 | if (channel_ptr == NULL) { |
| 252 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 253 | "GetLeastRequiredDelayMs() failed to locate channel"); |
| 254 | return -1; |
| 255 | } |
| 256 | return channel_ptr->least_required_delay_ms(); |
| 257 | } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 258 | |
| 259 | #endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 260 | |
| 261 | } // namespace webrtc |