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 | |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 13 | #include "webrtc/system_wrappers/include/trace.h" |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 14 | #include "webrtc/voice_engine/channel.h" |
| 15 | #include "webrtc/voice_engine/include/voe_errors.h" |
| 16 | #include "webrtc/voice_engine/voice_engine_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 20 | VoEVideoSync* VoEVideoSync::GetInterface(VoiceEngine* voiceEngine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #ifndef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 22 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | #else |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 24 | if (NULL == voiceEngine) { |
| 25 | return NULL; |
| 26 | } |
| 27 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 28 | s->AddRef(); |
| 29 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | #endif |
| 31 | } |
| 32 | |
| 33 | #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 34 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 35 | VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared) { |
| 36 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 37 | "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 40 | VoEVideoSyncImpl::~VoEVideoSyncImpl() { |
| 41 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 42 | "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 45 | int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel, |
| 46 | unsigned int& timestamp) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 47 | if (!_shared->statistics().Initialized()) { |
| 48 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 49 | return -1; |
| 50 | } |
| 51 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 52 | voe::Channel* channel_ptr = ch.channel(); |
| 53 | if (channel_ptr == NULL) { |
| 54 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 55 | "GetPlayoutTimestamp() failed to locate channel"); |
| 56 | return -1; |
| 57 | } |
| 58 | return channel_ptr->GetPlayoutTimestamp(timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 61 | int VoEVideoSyncImpl::SetInitTimestamp(int channel, unsigned int timestamp) { |
| 62 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 63 | "SetInitTimestamp(channel=%d, timestamp=%lu)", channel, |
| 64 | timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 66 | if (!_shared->statistics().Initialized()) { |
| 67 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 68 | return -1; |
| 69 | } |
| 70 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 71 | voe::Channel* channelPtr = ch.channel(); |
| 72 | if (channelPtr == NULL) { |
| 73 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 74 | "SetInitTimestamp() failed to locate channel"); |
| 75 | return -1; |
| 76 | } |
| 77 | return channelPtr->SetInitTimestamp(timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 80 | int VoEVideoSyncImpl::SetInitSequenceNumber(int channel, short sequenceNumber) { |
| 81 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 82 | "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)", channel, |
| 83 | sequenceNumber); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 85 | if (!_shared->statistics().Initialized()) { |
| 86 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 87 | return -1; |
| 88 | } |
| 89 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 90 | voe::Channel* channelPtr = ch.channel(); |
| 91 | if (channelPtr == NULL) { |
| 92 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 93 | "SetInitSequenceNumber() failed to locate channel"); |
| 94 | return -1; |
| 95 | } |
| 96 | return channelPtr->SetInitSequenceNumber(sequenceNumber); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 99 | int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel, int delayMs) { |
| 100 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 101 | "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)", channel, |
| 102 | delayMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 104 | if (!_shared->statistics().Initialized()) { |
| 105 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 106 | return -1; |
| 107 | } |
| 108 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 109 | voe::Channel* channelPtr = ch.channel(); |
| 110 | if (channelPtr == NULL) { |
| 111 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 112 | "SetMinimumPlayoutDelay() failed to locate channel"); |
| 113 | return -1; |
| 114 | } |
| 115 | return channelPtr->SetMinimumPlayoutDelay(delayMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | } |
| 117 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 118 | int VoEVideoSyncImpl::GetDelayEstimate(int channel, |
| 119 | int* jitter_buffer_delay_ms, |
| 120 | int* playout_buffer_delay_ms) { |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 121 | if (!_shared->statistics().Initialized()) { |
| 122 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 123 | return -1; |
| 124 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 125 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 126 | voe::Channel* channelPtr = ch.channel(); |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 127 | if (channelPtr == NULL) { |
| 128 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 129 | "GetDelayEstimate() failed to locate channel"); |
| 130 | return -1; |
| 131 | } |
| 132 | if (!channelPtr->GetDelayEstimate(jitter_buffer_delay_ms, |
| 133 | playout_buffer_delay_ms)) { |
| 134 | return -1; |
| 135 | } |
| 136 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 139 | int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 140 | if (!_shared->statistics().Initialized()) { |
| 141 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 142 | return -1; |
| 143 | } |
| 144 | AudioDeviceModule::BufferType type(AudioDeviceModule::kFixedBufferSize); |
| 145 | uint16_t sizeMS(0); |
| 146 | if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0) { |
| 147 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 148 | "GetPlayoutBufferSize() failed to read buffer size"); |
| 149 | return -1; |
| 150 | } |
| 151 | bufferMs = sizeMS; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 152 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 155 | int VoEVideoSyncImpl::GetRtpRtcp(int channel, |
| 156 | RtpRtcp** rtpRtcpModule, |
| 157 | RtpReceiver** rtp_receiver) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 158 | if (!_shared->statistics().Initialized()) { |
| 159 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 160 | return -1; |
| 161 | } |
| 162 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 163 | voe::Channel* channelPtr = ch.channel(); |
| 164 | if (channelPtr == NULL) { |
| 165 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 166 | "GetPlayoutTimestamp() failed to locate channel"); |
| 167 | return -1; |
| 168 | } |
| 169 | return channelPtr->GetRtpRtcp(rtpRtcpModule, rtp_receiver); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 170 | } |
| 171 | |
turaj@webrtc.org | e46c8d3 | 2013-05-22 20:39:43 +0000 | [diff] [blame] | 172 | int VoEVideoSyncImpl::GetLeastRequiredDelayMs(int channel) const { |
turaj@webrtc.org | e46c8d3 | 2013-05-22 20:39:43 +0000 | [diff] [blame] | 173 | if (!_shared->statistics().Initialized()) { |
| 174 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 175 | return -1; |
| 176 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 177 | voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
| 178 | voe::Channel* channel_ptr = ch.channel(); |
turaj@webrtc.org | e46c8d3 | 2013-05-22 20:39:43 +0000 | [diff] [blame] | 179 | if (channel_ptr == NULL) { |
| 180 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 181 | "GetLeastRequiredDelayMs() failed to locate channel"); |
| 182 | return -1; |
| 183 | } |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 184 | return channel_ptr->LeastRequiredDelayMs(); |
turaj@webrtc.org | e46c8d3 | 2013-05-22 20:39:43 +0000 | [diff] [blame] | 185 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
| 187 | #endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 188 | |
| 189 | } // namespace webrtc |