blob: 7df460312f283e0f5e03e41ac37de7269821dec5 [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
11#include "voe_video_sync_impl.h"
12
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +000013#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
14#include "webrtc/system_wrappers/interface/trace.h"
15#include "webrtc/voice_engine/channel.h"
16#include "webrtc/voice_engine/include/voe_errors.h"
17#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
20
21VoEVideoSync* 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 }
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000030 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:22 +000031 s->AddRef();
32 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000033#endif
34}
35
36#ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
37
tommi@webrtc.org851becd2012-04-04 14:57:19 +000038VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared)
niklase@google.com470e71d2011-07-07 08:21:25 +000039{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000040 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000041 "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor");
42}
43
44VoEVideoSyncImpl::~VoEVideoSyncImpl()
45{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000046 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000047 "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor");
48}
49
niklase@google.com470e71d2011-07-07 08:21:25 +000050int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel, unsigned int& timestamp)
51{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000052 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000053 "GetPlayoutTimestamp(channel=%d, timestamp=?)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000054 ANDROID_NOT_SUPPORTED(_shared->statistics());
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000055 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +000056
tommi@webrtc.org851becd2012-04-04 14:57:19 +000057 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000058 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000059 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000060 return -1;
61 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +000062 voe::ScopedChannel sc(_shared->channel_manager(), channel);
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +000063 voe::Channel* channelPtr = sc.ChannelPtr();
niklase@google.com470e71d2011-07-07 08:21:25 +000064 if (channelPtr == NULL)
65 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000066 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000067 "GetPlayoutTimestamp() failed to locate channel");
68 return -1;
69 }
70 return channelPtr->GetPlayoutTimestamp(timestamp);
71}
72
73int VoEVideoSyncImpl::SetInitTimestamp(int channel,
74 unsigned int timestamp)
75{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000076 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000077 "SetInitTimestamp(channel=%d, timestamp=%lu)",
78 channel, timestamp);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000079 ANDROID_NOT_SUPPORTED(_shared->statistics());
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000080 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +000081
tommi@webrtc.org851becd2012-04-04 14:57:19 +000082 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000083 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000084 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000085 return -1;
86 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +000087 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000088 voe::Channel* channelPtr = sc.ChannelPtr();
89 if (channelPtr == NULL)
90 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000091 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000092 "SetInitTimestamp() failed to locate channel");
93 return -1;
94 }
95 return channelPtr->SetInitTimestamp(timestamp);
96}
97
98int VoEVideoSyncImpl::SetInitSequenceNumber(int channel,
99 short sequenceNumber)
100{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000101 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)",
103 channel, sequenceNumber);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000104 ANDROID_NOT_SUPPORTED(_shared->statistics());
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000105 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000107 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000109 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 return -1;
111 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000112 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000113 voe::Channel* channelPtr = sc.ChannelPtr();
114 if (channelPtr == NULL)
115 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000116 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 "SetInitSequenceNumber() failed to locate channel");
118 return -1;
119 }
120 return channelPtr->SetInitSequenceNumber(sequenceNumber);
121}
122
123int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel,int delayMs)
124{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000125 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000126 "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)",
127 channel, delayMs);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000128 ANDROID_NOT_SUPPORTED(_shared->statistics());
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000129 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000131 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000132 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000133 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 return -1;
135 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000136 voe::ScopedChannel sc(_shared->channel_manager(), channel);
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +0000137 voe::Channel* channelPtr = sc.ChannelPtr();
niklase@google.com470e71d2011-07-07 08:21:25 +0000138 if (channelPtr == NULL)
139 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000140 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000141 "SetMinimumPlayoutDelay() failed to locate channel");
142 return -1;
143 }
144 return channelPtr->SetMinimumPlayoutDelay(delayMs);
145}
146
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000147int VoEVideoSyncImpl::SetInitialPlayoutDelay(int channel, int delay_ms)
148{
149 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
150 "SetInitialPlayoutDelay(channel=%d, delay_ms=%d)",
151 channel, delay_ms);
152 ANDROID_NOT_SUPPORTED(_shared->statistics());
153 IPHONE_NOT_SUPPORTED(_shared->statistics());
154
155 if (!_shared->statistics().Initialized())
156 {
157 _shared->SetLastError(VE_NOT_INITED, kTraceError);
158 return -1;
159 }
160 voe::ScopedChannel sc(_shared->channel_manager(), channel);
161 voe::Channel* channel_ptr = sc.ChannelPtr();
162 if (channel_ptr == NULL)
163 {
164 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
165 "SetInitialPlayoutDelay() failed to locate channel");
166 return -1;
167 }
168 return channel_ptr->SetInitialPlayoutDelay(delay_ms);
169}
170
niklase@google.com470e71d2011-07-07 08:21:25 +0000171int VoEVideoSyncImpl::GetDelayEstimate(int channel, int& delayMs)
172{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000173 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 "GetDelayEstimate(channel=%d, delayMs=?)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000175 ANDROID_NOT_SUPPORTED(_shared->statistics());
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000176 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000178 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000179 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000180 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000181 return -1;
182 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000183 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 voe::Channel* channelPtr = sc.ChannelPtr();
185 if (channelPtr == NULL)
186 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000187 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000188 "GetDelayEstimate() failed to locate channel");
189 return -1;
190 }
191 return channelPtr->GetDelayEstimate(delayMs);
192}
193
194int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs)
195{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000196 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000197 "GetPlayoutBufferSize(bufferMs=?)");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000198 ANDROID_NOT_SUPPORTED(_shared->statistics());
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000199 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000201 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000202 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000203 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000204 return -1;
205 }
206 AudioDeviceModule::BufferType type
207 (AudioDeviceModule::kFixedBufferSize);
208 WebRtc_UWord16 sizeMS(0);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000209 if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000211 _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +0000212 "GetPlayoutBufferSize() failed to read buffer size");
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 return -1;
214 }
215 bufferMs = sizeMS;
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000216 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
217 VoEId(_shared->instance_id(), -1),
218 "GetPlayoutBufferSize() => bufferMs=%d", bufferMs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000219 return 0;
220}
221
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +0000222int VoEVideoSyncImpl::GetRtpRtcp(int channel, RtpRtcp* &rtpRtcpModule)
niklase@google.com470e71d2011-07-07 08:21:25 +0000223{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000224 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000225 "GetRtpRtcp(channel=%i)", channel);
226
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000227 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000229 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230 return -1;
231 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000232 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000233 voe::Channel* channelPtr = sc.ChannelPtr();
234 if (channelPtr == NULL)
235 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000236 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000237 "GetPlayoutTimestamp() failed to locate channel");
238 return -1;
239 }
240 return channelPtr->GetRtpRtcp(rtpRtcpModule);
241}
242
243
244#endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
245
246} // namespace webrtc