andrew@webrtc.org | a7b57da | 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 | |
| 11 | #include "voe_video_sync_impl.h" |
| 12 | |
| 13 | #include "channel.h" |
| 14 | #include "critical_section_wrapper.h" |
| 15 | #include "trace.h" |
| 16 | #include "voe_errors.h" |
| 17 | #include "voice_engine_impl.h" |
| 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 | } |
| 30 | VoiceEngineImpl* s = reinterpret_cast<VoiceEngineImpl*>(voiceEngine); |
| 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); |
| 54 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 55 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 56 | |
| 57 | if (!_shared->statistics().Initialized()) |
| 58 | { |
| 59 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 60 | return -1; |
| 61 | } |
| 62 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 63 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 64 | if (channelPtr == NULL) |
| 65 | { |
| 66 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 67 | "GetPlayoutTimestamp() failed to locate channel"); |
| 68 | return -1; |
| 69 | } |
| 70 | return channelPtr->GetPlayoutTimestamp(timestamp); |
| 71 | } |
| 72 | |
| 73 | int VoEVideoSyncImpl::SetInitTimestamp(int channel, |
| 74 | unsigned int timestamp) |
| 75 | { |
| 76 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 77 | "SetInitTimestamp(channel=%d, timestamp=%lu)", |
| 78 | channel, timestamp); |
| 79 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 80 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 81 | |
| 82 | if (!_shared->statistics().Initialized()) |
| 83 | { |
| 84 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 85 | return -1; |
| 86 | } |
| 87 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 88 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 89 | if (channelPtr == NULL) |
| 90 | { |
| 91 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 92 | "SetInitTimestamp() failed to locate channel"); |
| 93 | return -1; |
| 94 | } |
| 95 | return channelPtr->SetInitTimestamp(timestamp); |
| 96 | } |
| 97 | |
| 98 | int VoEVideoSyncImpl::SetInitSequenceNumber(int channel, |
| 99 | short sequenceNumber) |
| 100 | { |
| 101 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 102 | "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)", |
| 103 | channel, sequenceNumber); |
| 104 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 105 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 106 | |
| 107 | if (!_shared->statistics().Initialized()) |
| 108 | { |
| 109 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 110 | return -1; |
| 111 | } |
| 112 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 113 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 114 | if (channelPtr == NULL) |
| 115 | { |
| 116 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 117 | "SetInitSequenceNumber() failed to locate channel"); |
| 118 | return -1; |
| 119 | } |
| 120 | return channelPtr->SetInitSequenceNumber(sequenceNumber); |
| 121 | } |
| 122 | |
| 123 | int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel,int delayMs) |
| 124 | { |
| 125 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 126 | "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)", |
| 127 | channel, delayMs); |
| 128 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 129 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 130 | |
| 131 | if (!_shared->statistics().Initialized()) |
| 132 | { |
| 133 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 134 | return -1; |
| 135 | } |
| 136 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 137 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 138 | if (channelPtr == NULL) |
| 139 | { |
| 140 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 141 | "SetMinimumPlayoutDelay() failed to locate channel"); |
| 142 | return -1; |
| 143 | } |
| 144 | return channelPtr->SetMinimumPlayoutDelay(delayMs); |
| 145 | } |
| 146 | |
| 147 | int VoEVideoSyncImpl::GetDelayEstimate(int channel, int& delayMs) |
| 148 | { |
| 149 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 150 | "GetDelayEstimate(channel=%d, delayMs=?)", channel); |
| 151 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 152 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 153 | |
| 154 | if (!_shared->statistics().Initialized()) |
| 155 | { |
| 156 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 157 | return -1; |
| 158 | } |
| 159 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 160 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 161 | if (channelPtr == NULL) |
| 162 | { |
| 163 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 164 | "GetDelayEstimate() failed to locate channel"); |
| 165 | return -1; |
| 166 | } |
| 167 | return channelPtr->GetDelayEstimate(delayMs); |
| 168 | } |
| 169 | |
| 170 | int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) |
| 171 | { |
| 172 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 173 | "GetPlayoutBufferSize(bufferMs=?)"); |
| 174 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
| 175 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
| 176 | |
| 177 | if (!_shared->statistics().Initialized()) |
| 178 | { |
| 179 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 180 | return -1; |
| 181 | } |
| 182 | AudioDeviceModule::BufferType type |
| 183 | (AudioDeviceModule::kFixedBufferSize); |
| 184 | WebRtc_UWord16 sizeMS(0); |
| 185 | if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0) |
| 186 | { |
| 187 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 188 | "GetPlayoutBufferSize() failed to read buffer size"); |
| 189 | return -1; |
| 190 | } |
| 191 | bufferMs = sizeMS; |
| 192 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 193 | VoEId(_shared->instance_id(), -1), |
| 194 | "GetPlayoutBufferSize() => bufferMs=%d", bufferMs); |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | int VoEVideoSyncImpl::GetRtpRtcp(int channel, RtpRtcp* &rtpRtcpModule) |
| 199 | { |
| 200 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 201 | "GetRtpRtcp(channel=%i)", channel); |
| 202 | |
| 203 | if (!_shared->statistics().Initialized()) |
| 204 | { |
| 205 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 206 | return -1; |
| 207 | } |
| 208 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
| 209 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 210 | if (channelPtr == NULL) |
| 211 | { |
| 212 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 213 | "GetPlayoutTimestamp() failed to locate channel"); |
| 214 | return -1; |
| 215 | } |
| 216 | return channelPtr->GetRtpRtcp(rtpRtcpModule); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | #endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API |
| 221 | |
| 222 | } // namespace webrtc |