2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-04-04 14:57:19 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/voice_engine/voe_video_sync_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/trace.h"
|
2013-02-12 21:42:18 +00:00
|
|
|
#include "webrtc/voice_engine/channel.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_errors.h"
|
|
|
|
|
#include "webrtc/voice_engine/voice_engine_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
VoEVideoSync* VoEVideoSync::GetInterface(VoiceEngine* voiceEngine) {
|
2011-07-07 08:21:25 +00:00
|
|
|
#ifndef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
|
2015-05-04 14:15:32 +02:00
|
|
|
return NULL;
|
2011-07-07 08:21:25 +00:00
|
|
|
#else
|
2015-05-04 14:15:32 +02:00
|
|
|
if (NULL == voiceEngine) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
|
|
|
|
|
s->AddRef();
|
|
|
|
|
return s;
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared) {
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
VoEVideoSyncImpl::~VoEVideoSyncImpl() {
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel,
|
|
|
|
|
unsigned int& timestamp) {
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channel_ptr = ch.channel();
|
|
|
|
|
if (channel_ptr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"GetPlayoutTimestamp() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channel_ptr->GetPlayoutTimestamp(timestamp);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoEVideoSyncImpl::SetInitTimestamp(int channel, unsigned int timestamp) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"SetInitTimestamp(channel=%d, timestamp=%lu)", channel,
|
|
|
|
|
timestamp);
|
|
|
|
|
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
|
|
|
|
if (channelPtr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"SetInitTimestamp() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->SetInitTimestamp(timestamp);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoEVideoSyncImpl::SetInitSequenceNumber(int channel, short sequenceNumber) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)", channel,
|
|
|
|
|
sequenceNumber);
|
|
|
|
|
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
|
|
|
|
if (channelPtr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"SetInitSequenceNumber() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->SetInitSequenceNumber(sequenceNumber);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel, int delayMs) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"SetMinimumPlayoutDelay(channel=%d, delayMs=%d)", channel,
|
|
|
|
|
delayMs);
|
|
|
|
|
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
|
|
|
|
if (channelPtr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"SetMinimumPlayoutDelay() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->SetMinimumPlayoutDelay(delayMs);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-11 20:23:35 +00:00
|
|
|
int VoEVideoSyncImpl::GetDelayEstimate(int channel,
|
|
|
|
|
int* jitter_buffer_delay_ms,
|
|
|
|
|
int* playout_buffer_delay_ms) {
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2013-04-11 20:23:35 +00:00
|
|
|
if (channelPtr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"GetDelayEstimate() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!channelPtr->GetDelayEstimate(jitter_buffer_delay_ms,
|
|
|
|
|
playout_buffer_delay_ms)) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) {
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
AudioDeviceModule::BufferType type(AudioDeviceModule::kFixedBufferSize);
|
|
|
|
|
uint16_t sizeMS(0);
|
|
|
|
|
if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0) {
|
|
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
|
|
|
|
|
"GetPlayoutBufferSize() failed to read buffer size");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
bufferMs = sizeMS;
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoEVideoSyncImpl::GetRtpRtcp(int channel,
|
|
|
|
|
RtpRtcp** rtpRtcpModule,
|
|
|
|
|
RtpReceiver** rtp_receiver) {
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
|
|
|
|
if (channelPtr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"GetPlayoutTimestamp() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->GetRtpRtcp(rtpRtcpModule, rtp_receiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-22 20:39:43 +00:00
|
|
|
int VoEVideoSyncImpl::GetLeastRequiredDelayMs(int channel) const {
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channel_ptr = ch.channel();
|
2013-05-22 20:39:43 +00:00
|
|
|
if (channel_ptr == NULL) {
|
|
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"GetLeastRequiredDelayMs() failed to locate channel");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-08-13 12:09:10 -07:00
|
|
|
return channel_ptr->LeastRequiredDelayMs();
|
2013-05-22 20:39:43 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|