blob: b0910c318c482d51626373744cf36b429f1625b0 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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 "voe_video_sync_impl.h"
12
turaj@webrtc.orgead8a5b2013-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"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +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 }
30 VoiceEngineImpl* s = reinterpret_cast<VoiceEngineImpl*>(voiceEngine);
31 s->AddRef();
32 return s;
33#endif
34}
35
36#ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API
37
38VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared)
39{
40 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
41 "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor");
42}
43
44VoEVideoSyncImpl::~VoEVideoSyncImpl()
45{
46 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
47 "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor");
48}
49
50int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel, unsigned int& timestamp)
51{
52 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
53 "GetPlayoutTimestamp(channel=%d, timestamp=?)", channel);
54 ANDROID_NOT_SUPPORTED(_shared->statistics());
55 IPHONE_NOT_SUPPORTED(_shared->statistics());
56
57 if (!_shared->statistics().Initialized())
58 {
59 _shared->SetLastError(VE_NOT_INITED, kTraceError);
60 return -1;
61 }
62 voe::ScopedChannel sc(_shared->channel_manager(), channel);
63 voe::Channel* channelPtr = sc.ChannelPtr();
64 if (channelPtr == NULL)
65 {
66 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
67 "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{
76 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
77 "SetInitTimestamp(channel=%d, timestamp=%lu)",
78 channel, timestamp);
79 ANDROID_NOT_SUPPORTED(_shared->statistics());
80 IPHONE_NOT_SUPPORTED(_shared->statistics());
81
82 if (!_shared->statistics().Initialized())
83 {
84 _shared->SetLastError(VE_NOT_INITED, kTraceError);
85 return -1;
86 }
87 voe::ScopedChannel sc(_shared->channel_manager(), channel);
88 voe::Channel* channelPtr = sc.ChannelPtr();
89 if (channelPtr == NULL)
90 {
91 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
92 "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{
101 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
102 "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)",
103 channel, sequenceNumber);
104 ANDROID_NOT_SUPPORTED(_shared->statistics());
105 IPHONE_NOT_SUPPORTED(_shared->statistics());
106
107 if (!_shared->statistics().Initialized())
108 {
109 _shared->SetLastError(VE_NOT_INITED, kTraceError);
110 return -1;
111 }
112 voe::ScopedChannel sc(_shared->channel_manager(), channel);
113 voe::Channel* channelPtr = sc.ChannelPtr();
114 if (channelPtr == NULL)
115 {
116 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
117 "SetInitSequenceNumber() failed to locate channel");
118 return -1;
119 }
120 return channelPtr->SetInitSequenceNumber(sequenceNumber);
121}
122
123int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel,int delayMs)
124{
125 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
126 "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)",
127 channel, delayMs);
128 ANDROID_NOT_SUPPORTED(_shared->statistics());
129 IPHONE_NOT_SUPPORTED(_shared->statistics());
130
131 if (!_shared->statistics().Initialized())
132 {
133 _shared->SetLastError(VE_NOT_INITED, kTraceError);
134 return -1;
135 }
136 voe::ScopedChannel sc(_shared->channel_manager(), channel);
137 voe::Channel* channelPtr = sc.ChannelPtr();
138 if (channelPtr == NULL)
139 {
140 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
141 "SetMinimumPlayoutDelay() failed to locate channel");
142 return -1;
143 }
144 return channelPtr->SetMinimumPlayoutDelay(delayMs);
145}
146
turaj@webrtc.orgead8a5b2013-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
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000171int VoEVideoSyncImpl::GetDelayEstimate(int channel, int& delayMs)
172{
173 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
174 "GetDelayEstimate(channel=%d, delayMs=?)", channel);
175 ANDROID_NOT_SUPPORTED(_shared->statistics());
176 IPHONE_NOT_SUPPORTED(_shared->statistics());
177
178 if (!_shared->statistics().Initialized())
179 {
180 _shared->SetLastError(VE_NOT_INITED, kTraceError);
181 return -1;
182 }
183 voe::ScopedChannel sc(_shared->channel_manager(), channel);
184 voe::Channel* channelPtr = sc.ChannelPtr();
185 if (channelPtr == NULL)
186 {
187 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
188 "GetDelayEstimate() failed to locate channel");
189 return -1;
190 }
191 return channelPtr->GetDelayEstimate(delayMs);
192}
193
194int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs)
195{
196 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
197 "GetPlayoutBufferSize(bufferMs=?)");
198 ANDROID_NOT_SUPPORTED(_shared->statistics());
199 IPHONE_NOT_SUPPORTED(_shared->statistics());
200
201 if (!_shared->statistics().Initialized())
202 {
203 _shared->SetLastError(VE_NOT_INITED, kTraceError);
204 return -1;
205 }
206 AudioDeviceModule::BufferType type
207 (AudioDeviceModule::kFixedBufferSize);
208 WebRtc_UWord16 sizeMS(0);
209 if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0)
210 {
211 _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
212 "GetPlayoutBufferSize() failed to read buffer size");
213 return -1;
214 }
215 bufferMs = sizeMS;
216 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
217 VoEId(_shared->instance_id(), -1),
218 "GetPlayoutBufferSize() => bufferMs=%d", bufferMs);
219 return 0;
220}
221
222int VoEVideoSyncImpl::GetRtpRtcp(int channel, RtpRtcp* &rtpRtcpModule)
223{
224 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
225 "GetRtpRtcp(channel=%i)", channel);
226
227 if (!_shared->statistics().Initialized())
228 {
229 _shared->SetLastError(VE_NOT_INITED, kTraceError);
230 return -1;
231 }
232 voe::ScopedChannel sc(_shared->channel_manager(), channel);
233 voe::Channel* channelPtr = sc.ChannelPtr();
234 if (channelPtr == NULL)
235 {
236 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
237 "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