blob: 4ef1228adad7b43c9c05adf6352c157e19596eb1 [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);
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000054 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +000055
tommi@webrtc.org851becd2012-04-04 14:57:19 +000056 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000057 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000058 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000059 return -1;
60 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +000061 voe::ScopedChannel sc(_shared->channel_manager(), channel);
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +000062 voe::Channel* channelPtr = sc.ChannelPtr();
niklase@google.com470e71d2011-07-07 08:21:25 +000063 if (channelPtr == NULL)
64 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000065 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000066 "GetPlayoutTimestamp() failed to locate channel");
67 return -1;
68 }
69 return channelPtr->GetPlayoutTimestamp(timestamp);
70}
71
72int VoEVideoSyncImpl::SetInitTimestamp(int channel,
73 unsigned int timestamp)
74{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000075 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000076 "SetInitTimestamp(channel=%d, timestamp=%lu)",
77 channel, timestamp);
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000078 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +000079
tommi@webrtc.org851becd2012-04-04 14:57:19 +000080 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000081 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000082 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000083 return -1;
84 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +000085 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000086 voe::Channel* channelPtr = sc.ChannelPtr();
87 if (channelPtr == NULL)
88 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000089 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000090 "SetInitTimestamp() failed to locate channel");
91 return -1;
92 }
93 return channelPtr->SetInitTimestamp(timestamp);
94}
95
96int VoEVideoSyncImpl::SetInitSequenceNumber(int channel,
97 short sequenceNumber)
98{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000099 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000100 "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)",
101 channel, sequenceNumber);
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000102 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000104 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000106 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 return -1;
108 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000109 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 voe::Channel* channelPtr = sc.ChannelPtr();
111 if (channelPtr == NULL)
112 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000113 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 "SetInitSequenceNumber() failed to locate channel");
115 return -1;
116 }
117 return channelPtr->SetInitSequenceNumber(sequenceNumber);
118}
119
120int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel,int delayMs)
121{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000122 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000123 "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)",
124 channel, delayMs);
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000125 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000127 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000129 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000130 return -1;
131 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000132 voe::ScopedChannel sc(_shared->channel_manager(), channel);
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +0000133 voe::Channel* channelPtr = sc.ChannelPtr();
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 if (channelPtr == NULL)
135 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000136 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000137 "SetMinimumPlayoutDelay() failed to locate channel");
138 return -1;
139 }
140 return channelPtr->SetMinimumPlayoutDelay(delayMs);
141}
142
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000143int VoEVideoSyncImpl::SetInitialPlayoutDelay(int channel, int delay_ms)
144{
145 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
146 "SetInitialPlayoutDelay(channel=%d, delay_ms=%d)",
147 channel, delay_ms);
148 ANDROID_NOT_SUPPORTED(_shared->statistics());
149 IPHONE_NOT_SUPPORTED(_shared->statistics());
150
151 if (!_shared->statistics().Initialized())
152 {
153 _shared->SetLastError(VE_NOT_INITED, kTraceError);
154 return -1;
155 }
156 voe::ScopedChannel sc(_shared->channel_manager(), channel);
157 voe::Channel* channel_ptr = sc.ChannelPtr();
158 if (channel_ptr == NULL)
159 {
160 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
161 "SetInitialPlayoutDelay() failed to locate channel");
162 return -1;
163 }
164 return channel_ptr->SetInitialPlayoutDelay(delay_ms);
165}
166
niklase@google.com470e71d2011-07-07 08:21:25 +0000167int VoEVideoSyncImpl::GetDelayEstimate(int channel, int& delayMs)
168{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000169 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000170 "GetDelayEstimate(channel=%d, delayMs=?)", channel);
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000171 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000172
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000173 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000175 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000176 return -1;
177 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000178 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179 voe::Channel* channelPtr = sc.ChannelPtr();
180 if (channelPtr == NULL)
181 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000182 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000183 "GetDelayEstimate() failed to locate channel");
184 return -1;
185 }
186 return channelPtr->GetDelayEstimate(delayMs);
187}
188
189int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs)
190{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000191 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000192 "GetPlayoutBufferSize(bufferMs=?)");
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000193 IPHONE_NOT_SUPPORTED(_shared->statistics());
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000195 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000196 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000197 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 return -1;
199 }
200 AudioDeviceModule::BufferType type
201 (AudioDeviceModule::kFixedBufferSize);
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000202 uint16_t sizeMS(0);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000203 if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000204 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000205 _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +0000206 "GetPlayoutBufferSize() failed to read buffer size");
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 return -1;
208 }
209 bufferMs = sizeMS;
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000210 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
211 VoEId(_shared->instance_id(), -1),
212 "GetPlayoutBufferSize() => bufferMs=%d", bufferMs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 return 0;
214}
215
tommi@webrtc.org9ff87db2012-01-19 15:05:36 +0000216int VoEVideoSyncImpl::GetRtpRtcp(int channel, RtpRtcp* &rtpRtcpModule)
niklase@google.com470e71d2011-07-07 08:21:25 +0000217{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000218 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000219 "GetRtpRtcp(channel=%i)", channel);
fischman@webrtc.orgf61e02c2013-02-20 23:13:46 +0000220
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000221 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000222 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000223 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000224 return -1;
225 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000226 voe::ScopedChannel sc(_shared->channel_manager(), channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000227 voe::Channel* channelPtr = sc.ChannelPtr();
228 if (channelPtr == NULL)
229 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000230 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000231 "GetPlayoutTimestamp() failed to locate channel");
232 return -1;
233 }
234 return channelPtr->GetRtpRtcp(rtpRtcpModule);
235}
236
237
238#endif // #ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
239
240} // namespace webrtc