Line data Source code
1 : /*
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 "webrtc/voice_engine/voe_video_sync_impl.h"
12 :
13 : #include "webrtc/system_wrappers/include/trace.h"
14 : #include "webrtc/voice_engine/channel.h"
15 : #include "webrtc/voice_engine/include/voe_errors.h"
16 : #include "webrtc/voice_engine/voice_engine_impl.h"
17 :
18 : namespace webrtc {
19 :
20 0 : VoEVideoSync* VoEVideoSync::GetInterface(VoiceEngine* voiceEngine) {
21 0 : if (NULL == voiceEngine) {
22 0 : return NULL;
23 : }
24 0 : VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
25 0 : s->AddRef();
26 0 : return s;
27 : }
28 :
29 0 : VoEVideoSyncImpl::VoEVideoSyncImpl(voe::SharedData* shared) : _shared(shared) {
30 : WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
31 : "VoEVideoSyncImpl::VoEVideoSyncImpl() - ctor");
32 0 : }
33 :
34 0 : VoEVideoSyncImpl::~VoEVideoSyncImpl() {
35 : WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
36 : "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor");
37 0 : }
38 :
39 0 : int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel,
40 : unsigned int& timestamp) {
41 0 : if (!_shared->statistics().Initialized()) {
42 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
43 0 : return -1;
44 : }
45 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
46 0 : voe::Channel* channel_ptr = ch.channel();
47 0 : if (channel_ptr == NULL) {
48 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
49 0 : "GetPlayoutTimestamp() failed to locate channel");
50 0 : return -1;
51 : }
52 0 : return channel_ptr->GetPlayoutTimestamp(timestamp);
53 : }
54 :
55 0 : int VoEVideoSyncImpl::SetInitTimestamp(int channel, unsigned int timestamp) {
56 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
57 : "SetInitTimestamp(channel=%d, timestamp=%lu)", channel,
58 : timestamp);
59 :
60 0 : if (!_shared->statistics().Initialized()) {
61 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
62 0 : return -1;
63 : }
64 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
65 0 : voe::Channel* channelPtr = ch.channel();
66 0 : if (channelPtr == NULL) {
67 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
68 0 : "SetInitTimestamp() failed to locate channel");
69 0 : return -1;
70 : }
71 0 : return channelPtr->SetInitTimestamp(timestamp);
72 : }
73 :
74 0 : int VoEVideoSyncImpl::SetInitSequenceNumber(int channel, short sequenceNumber) {
75 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
76 : "SetInitSequenceNumber(channel=%d, sequenceNumber=%hd)", channel,
77 : sequenceNumber);
78 :
79 0 : if (!_shared->statistics().Initialized()) {
80 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
81 0 : return -1;
82 : }
83 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
84 0 : voe::Channel* channelPtr = ch.channel();
85 0 : if (channelPtr == NULL) {
86 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
87 0 : "SetInitSequenceNumber() failed to locate channel");
88 0 : return -1;
89 : }
90 0 : return channelPtr->SetInitSequenceNumber(sequenceNumber);
91 : }
92 :
93 0 : int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel, int delayMs) {
94 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
95 : "SetMinimumPlayoutDelay(channel=%d, delayMs=%d)", channel,
96 : delayMs);
97 :
98 0 : if (!_shared->statistics().Initialized()) {
99 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
100 0 : return -1;
101 : }
102 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
103 0 : voe::Channel* channelPtr = ch.channel();
104 0 : if (channelPtr == NULL) {
105 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
106 0 : "SetMinimumPlayoutDelay() failed to locate channel");
107 0 : return -1;
108 : }
109 0 : return channelPtr->SetMinimumPlayoutDelay(delayMs);
110 : }
111 :
112 0 : int VoEVideoSyncImpl::SetCurrentSyncOffset(int channel, int offsetMs)
113 : {
114 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
115 : "SetCurrentSyncOffset(channel=%d, offsetMs=%d)",
116 : channel, offsetMs);
117 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
118 0 : voe::Channel* channelPtr = ch.channel();
119 0 : if (channelPtr == NULL)
120 : {
121 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
122 0 : "SetCurrentSyncOffset() failed to locate channel");
123 0 : return -1;
124 : }
125 0 : channelPtr->SetCurrentSyncOffset(offsetMs);
126 0 : return 0;
127 : }
128 :
129 0 : int VoEVideoSyncImpl::GetDelayEstimate(int channel,
130 : int* jitter_buffer_delay_ms,
131 : int* playout_buffer_delay_ms,
132 : int* avsync_offset_ms) {
133 0 : if (!_shared->statistics().Initialized()) {
134 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
135 0 : return -1;
136 : }
137 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
138 0 : voe::Channel* channelPtr = ch.channel();
139 0 : if (channelPtr == NULL) {
140 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
141 0 : "GetDelayEstimate() failed to locate channel");
142 0 : return -1;
143 : }
144 0 : if (!channelPtr->GetDelayEstimate(jitter_buffer_delay_ms,
145 : playout_buffer_delay_ms,
146 : avsync_offset_ms)) {
147 0 : return -1;
148 : }
149 0 : return 0;
150 : }
151 :
152 0 : int VoEVideoSyncImpl::GetPlayoutBufferSize(int& bufferMs) {
153 0 : if (!_shared->statistics().Initialized()) {
154 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
155 0 : return -1;
156 : }
157 0 : AudioDeviceModule::BufferType type(AudioDeviceModule::kFixedBufferSize);
158 0 : uint16_t sizeMS(0);
159 0 : if (_shared->audio_device()->PlayoutBuffer(&type, &sizeMS) != 0) {
160 0 : _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
161 0 : "GetPlayoutBufferSize() failed to read buffer size");
162 0 : return -1;
163 : }
164 0 : bufferMs = sizeMS;
165 0 : return 0;
166 : }
167 :
168 0 : int VoEVideoSyncImpl::GetRtpRtcp(int channel,
169 : RtpRtcp** rtpRtcpModule,
170 : RtpReceiver** rtp_receiver) {
171 0 : if (!_shared->statistics().Initialized()) {
172 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
173 0 : return -1;
174 : }
175 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
176 0 : voe::Channel* channelPtr = ch.channel();
177 0 : if (channelPtr == NULL) {
178 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
179 0 : "GetPlayoutTimestamp() failed to locate channel");
180 0 : return -1;
181 : }
182 0 : return channelPtr->GetRtpRtcp(rtpRtcpModule, rtp_receiver);
183 : }
184 :
185 0 : int VoEVideoSyncImpl::GetLeastRequiredDelayMs(int channel) const {
186 0 : if (!_shared->statistics().Initialized()) {
187 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
188 0 : return -1;
189 : }
190 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
191 0 : voe::Channel* channel_ptr = ch.channel();
192 0 : if (channel_ptr == NULL) {
193 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
194 0 : "GetLeastRequiredDelayMs() failed to locate channel");
195 0 : return -1;
196 : }
197 0 : return channel_ptr->LeastRequiredDelayMs();
198 : }
199 :
200 : } // namespace webrtc
|