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