blob: 03d69b4b8c4544c90bf07af4cdd6226b69f37d84 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tommi@webrtc.org851becd2012-04-04 14:57:19 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org956aa7e2013-05-21 13:52:32 +000011#include "webrtc/voice_engine/voe_video_sync_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
Henrik Kjellander98f53512015-10-28 18:17:40 +010013#include "webrtc/system_wrappers/include/trace.h"
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000014#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.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
19
Jelena Marusic0d266052015-05-04 14:15:32 +020020VoEVideoSync* VoEVideoSync::GetInterface(VoiceEngine* voiceEngine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000021#ifndef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
Jelena Marusic0d266052015-05-04 14:15:32 +020022 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000023#else
Jelena Marusic0d266052015-05-04 14:15:32 +020024 if (NULL == voiceEngine) {
25 return NULL;
26 }
27 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
28 s->AddRef();
29 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000030#endif
31}
32
33#ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
34
Jelena Marusic0d266052015-05-04 14:15:32 +020035VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared) {
36 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
37 "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000038}
39
Jelena Marusic0d266052015-05-04 14:15:32 +020040VoEVideoSyncImpl::~VoEVideoSyncImpl() {
41 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
42 "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000043}
44
Jelena Marusic0d266052015-05-04 14:15:32 +020045int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel,
46 unsigned int& timestamp) {
Jelena Marusic0d266052015-05-04 14:15:32 +020047 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.com470e71d2011-07-07 08:21:25 +000059}
60
Jelena Marusic0d266052015-05-04 14:15:32 +020061int 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.com470e71d2011-07-07 08:21:25 +000065
Jelena Marusic0d266052015-05-04 14:15:32 +020066 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.com470e71d2011-07-07 08:21:25 +000078}
79
Jelena Marusic0d266052015-05-04 14:15:32 +020080int 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.com470e71d2011-07-07 08:21:25 +000084
Jelena Marusic0d266052015-05-04 14:15:32 +020085 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.com470e71d2011-07-07 08:21:25 +000097}
98
Jelena Marusic0d266052015-05-04 14:15:32 +020099int 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.com470e71d2011-07-07 08:21:25 +0000103
Jelena Marusic0d266052015-05-04 14:15:32 +0200104 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.com470e71d2011-07-07 08:21:25 +0000116}
117
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000118int VoEVideoSyncImpl::GetDelayEstimate(int channel,
119 int* jitter_buffer_delay_ms,
120 int* playout_buffer_delay_ms) {
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000121 if (!_shared->statistics().Initialized()) {
122 _shared->SetLastError(VE_NOT_INITED, kTraceError);
123 return -1;
124 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000125 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
126 voe::Channel* channelPtr = ch.channel();
pwestin@webrtc.org1de01352013-04-11 20:23:35 +0000127 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.com470e71d2011-07-07 08:21:25 +0000137}
138
Jelena Marusic0d266052015-05-04 14:15:32 +0200139int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) {
Jelena Marusic0d266052015-05-04 14:15:32 +0200140 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 Marusic0d266052015-05-04 14:15:32 +0200152 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000153}
154
Jelena Marusic0d266052015-05-04 14:15:32 +0200155int VoEVideoSyncImpl::GetRtpRtcp(int channel,
156 RtpRtcp** rtpRtcpModule,
157 RtpReceiver** rtp_receiver) {
Jelena Marusic0d266052015-05-04 14:15:32 +0200158 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.com470e71d2011-07-07 08:21:25 +0000170}
171
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000172int VoEVideoSyncImpl::GetLeastRequiredDelayMs(int channel) const {
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000173 if (!_shared->statistics().Initialized()) {
174 _shared->SetLastError(VE_NOT_INITED, kTraceError);
175 return -1;
176 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000177 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
178 voe::Channel* channel_ptr = ch.channel();
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000179 if (channel_ptr == NULL) {
180 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
181 "GetLeastRequiredDelayMs() failed to locate channel");
182 return -1;
183 }
deadbeef74375882015-08-13 12:09:10 -0700184 return channel_ptr->LeastRequiredDelayMs();
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +0000185}
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
187#endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
188
189} // namespace webrtc