blob: 339fba146624a194a4074d892eb843296feee151 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
niklas.enbom@webrtc.org5398d952012-03-26 08:11:25 +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_file_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
Henrik Kjellander0b9e29c2015-11-16 11:12:24 +010013#include "webrtc/modules/media_file/media_file.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010014#include "webrtc/system_wrappers/include/file_wrapper.h"
15#include "webrtc/system_wrappers/include/trace.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000016#include "webrtc/voice_engine/channel.h"
17#include "webrtc/voice_engine/include/voe_errors.h"
18#include "webrtc/voice_engine/output_mixer.h"
19#include "webrtc/voice_engine/transmit_mixer.h"
20#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22namespace webrtc {
23
Jelena Marusic0d266052015-05-04 14:15:32 +020024VoEFile* VoEFile::GetInterface(VoiceEngine* voiceEngine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000025#ifndef WEBRTC_VOICE_ENGINE_FILE_API
Jelena Marusic0d266052015-05-04 14:15:32 +020026 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000027#else
Jelena Marusic0d266052015-05-04 14:15:32 +020028 if (NULL == voiceEngine) {
29 return NULL;
30 }
31 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
32 s->AddRef();
33 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000034#endif
35}
36
37#ifdef WEBRTC_VOICE_ENGINE_FILE_API
38
Jelena Marusic0d266052015-05-04 14:15:32 +020039VoEFileImpl::VoEFileImpl(voe::SharedData* shared) : _shared(shared) {
40 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
41 "VoEFileImpl::VoEFileImpl() - ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000042}
43
Jelena Marusic0d266052015-05-04 14:15:32 +020044VoEFileImpl::~VoEFileImpl() {
45 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
46 "VoEFileImpl::~VoEFileImpl() - dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000047}
48
Jelena Marusic0d266052015-05-04 14:15:32 +020049int VoEFileImpl::StartPlayingFileLocally(int channel,
50 const char fileNameUTF8[1024],
51 bool loop,
52 FileFormats format,
53 float volumeScaling,
54 int startPointMs,
55 int stopPointMs) {
56 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
57 "StartPlayingFileLocally(channel=%d, fileNameUTF8[]=%s, "
58 "loop=%d, format=%d, volumeScaling=%5.3f, startPointMs=%d,"
59 " stopPointMs=%d)",
60 channel, fileNameUTF8, loop, format, volumeScaling, startPointMs,
61 stopPointMs);
André Susano Pinto664cdaf2015-05-20 11:11:07 +020062 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
Jelena Marusic0d266052015-05-04 14:15:32 +020063 if (!_shared->statistics().Initialized()) {
64 _shared->SetLastError(VE_NOT_INITED, kTraceError);
65 return -1;
66 }
67 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
68 voe::Channel* channelPtr = ch.channel();
69 if (channelPtr == NULL) {
70 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
71 "StartPlayingFileLocally() failed to locate channel");
72 return -1;
73 }
niklase@google.com470e71d2011-07-07 08:21:25 +000074
Jelena Marusic0d266052015-05-04 14:15:32 +020075 return channelPtr->StartPlayingFileLocally(fileNameUTF8, loop, format,
76 startPointMs, volumeScaling,
77 stopPointMs, NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +000078}
79
80int VoEFileImpl::StartPlayingFileLocally(int channel,
81 InStream* stream,
82 FileFormats format,
83 float volumeScaling,
84 int startPointMs,
Jelena Marusic0d266052015-05-04 14:15:32 +020085 int stopPointMs) {
86 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
87 "StartPlayingFileLocally(channel=%d, stream, format=%d, "
88 "volumeScaling=%5.3f, startPointMs=%d, stopPointMs=%d)",
89 channel, format, volumeScaling, startPointMs, stopPointMs);
niklase@google.com470e71d2011-07-07 08:21:25 +000090
Jelena Marusic0d266052015-05-04 14:15:32 +020091 if (!_shared->statistics().Initialized()) {
92 _shared->SetLastError(VE_NOT_INITED, kTraceError);
93 return -1;
94 }
niklase@google.com470e71d2011-07-07 08:21:25 +000095
Jelena Marusic0d266052015-05-04 14:15:32 +020096 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
97 voe::Channel* channelPtr = ch.channel();
98 if (channelPtr == NULL) {
99 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
100 "StartPlayingFileLocally() failed to locate channel");
101 return -1;
102 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
Jelena Marusic0d266052015-05-04 14:15:32 +0200104 return channelPtr->StartPlayingFileLocally(stream, format, startPointMs,
105 volumeScaling, stopPointMs, NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000106}
107
Jelena Marusic0d266052015-05-04 14:15:32 +0200108int VoEFileImpl::StopPlayingFileLocally(int channel) {
109 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
110 "StopPlayingFileLocally()");
111 if (!_shared->statistics().Initialized()) {
112 _shared->SetLastError(VE_NOT_INITED, kTraceError);
113 return -1;
114 }
115 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
116 voe::Channel* channelPtr = ch.channel();
117 if (channelPtr == NULL) {
118 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
119 "StopPlayingFileLocally() failed to locate channel");
120 return -1;
121 }
122 return channelPtr->StopPlayingFileLocally();
niklase@google.com470e71d2011-07-07 08:21:25 +0000123}
124
Jelena Marusic0d266052015-05-04 14:15:32 +0200125int VoEFileImpl::IsPlayingFileLocally(int channel) {
Jelena Marusic0d266052015-05-04 14:15:32 +0200126 if (!_shared->statistics().Initialized()) {
127 _shared->SetLastError(VE_NOT_INITED, kTraceError);
128 return -1;
129 }
130 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
131 voe::Channel* channelPtr = ch.channel();
132 if (channelPtr == NULL) {
133 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
134 "StopPlayingFileLocally() failed to locate channel");
135 return -1;
136 }
137 return channelPtr->IsPlayingFileLocally();
niklase@google.com470e71d2011-07-07 08:21:25 +0000138}
139
niklase@google.com470e71d2011-07-07 08:21:25 +0000140int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
141 const char fileNameUTF8[1024],
142 bool loop,
143 bool mixWithMicrophone,
144 FileFormats format,
Jelena Marusic0d266052015-05-04 14:15:32 +0200145 float volumeScaling) {
146 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
147 "StartPlayingFileAsMicrophone(channel=%d, fileNameUTF8=%s, "
148 "loop=%d, mixWithMicrophone=%d, format=%d, "
149 "volumeScaling=%5.3f)",
150 channel, fileNameUTF8, loop, mixWithMicrophone, format,
151 volumeScaling);
André Susano Pinto664cdaf2015-05-20 11:11:07 +0200152 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
Jelena Marusic0d266052015-05-04 14:15:32 +0200153 if (!_shared->statistics().Initialized()) {
154 _shared->SetLastError(VE_NOT_INITED, kTraceError);
155 return -1;
156 }
157
158 const uint32_t startPointMs(0);
159 const uint32_t stopPointMs(0);
160
161 if (channel == -1) {
162 int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone(
163 fileNameUTF8, loop, format, startPointMs, volumeScaling, stopPointMs,
164 NULL);
165 if (res) {
166 WEBRTC_TRACE(
167 kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
168 "StartPlayingFileAsMicrophone() failed to start playing file");
169 return (-1);
170 } else {
171 _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone);
172 return (0);
173 }
174 } else {
175 // Add file after demultiplexing <=> affects one channel only
176 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
177 voe::Channel* channelPtr = ch.channel();
178 if (channelPtr == NULL) {
179 _shared->SetLastError(
180 VE_CHANNEL_NOT_VALID, kTraceError,
181 "StartPlayingFileAsMicrophone() failed to locate channel");
182 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000183 }
184
Jelena Marusic0d266052015-05-04 14:15:32 +0200185 int res = channelPtr->StartPlayingFileAsMicrophone(
186 fileNameUTF8, loop, format, startPointMs, volumeScaling, stopPointMs,
187 NULL);
188 if (res) {
189 WEBRTC_TRACE(
190 kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
191 "StartPlayingFileAsMicrophone() failed to start playing file");
192 return -1;
193 } else {
194 channelPtr->SetMixWithMicStatus(mixWithMicrophone);
195 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000196 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200197 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000198}
199
200int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
201 InStream* stream,
202 bool mixWithMicrophone,
203 FileFormats format,
Jelena Marusic0d266052015-05-04 14:15:32 +0200204 float volumeScaling) {
205 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
206 "StartPlayingFileAsMicrophone(channel=%d, stream,"
207 " mixWithMicrophone=%d, format=%d, volumeScaling=%5.3f)",
208 channel, mixWithMicrophone, format, volumeScaling);
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
Jelena Marusic0d266052015-05-04 14:15:32 +0200210 if (!_shared->statistics().Initialized()) {
211 _shared->SetLastError(VE_NOT_INITED, kTraceError);
212 return -1;
213 }
214
215 const uint32_t startPointMs(0);
216 const uint32_t stopPointMs(0);
217
218 if (channel == -1) {
219 int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone(
220 stream, format, startPointMs, volumeScaling, stopPointMs, NULL);
221 if (res) {
222 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
223 "StartPlayingFileAsMicrophone() failed to start "
224 "playing stream");
225 return (-1);
226 } else {
227 _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone);
228 return (0);
229 }
230 } else {
231 // Add file after demultiplexing <=> affects one channel only
232 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
233 voe::Channel* channelPtr = ch.channel();
234 if (channelPtr == NULL) {
235 _shared->SetLastError(
236 VE_CHANNEL_NOT_VALID, kTraceError,
237 "StartPlayingFileAsMicrophone() failed to locate channel");
238 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000239 }
240
Jelena Marusic0d266052015-05-04 14:15:32 +0200241 int res = channelPtr->StartPlayingFileAsMicrophone(
242 stream, format, startPointMs, volumeScaling, stopPointMs, NULL);
243 if (res) {
244 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
245 "StartPlayingFileAsMicrophone() failed to start "
246 "playing stream");
247 return -1;
248 } else {
249 channelPtr->SetMixWithMicStatus(mixWithMicrophone);
250 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200252 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000253}
254
Jelena Marusic0d266052015-05-04 14:15:32 +0200255int VoEFileImpl::StopPlayingFileAsMicrophone(int channel) {
256 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
257 "StopPlayingFileAsMicrophone(channel=%d)", channel);
258 if (!_shared->statistics().Initialized()) {
259 _shared->SetLastError(VE_NOT_INITED, kTraceError);
260 return -1;
261 }
262 if (channel == -1) {
263 // Stop adding file before demultiplexing <=> affects all channels
264 return _shared->transmit_mixer()->StopPlayingFileAsMicrophone();
265 } else {
266 // Stop adding file after demultiplexing <=> affects one channel only
267 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
268 voe::Channel* channelPtr = ch.channel();
269 if (channelPtr == NULL) {
270 _shared->SetLastError(
271 VE_CHANNEL_NOT_VALID, kTraceError,
272 "StopPlayingFileAsMicrophone() failed to locate channel");
273 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200275 return channelPtr->StopPlayingFileAsMicrophone();
276 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000277}
278
Jelena Marusic0d266052015-05-04 14:15:32 +0200279int VoEFileImpl::IsPlayingFileAsMicrophone(int channel) {
280 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
281 "IsPlayingFileAsMicrophone(channel=%d)", channel);
282 if (!_shared->statistics().Initialized()) {
283 _shared->SetLastError(VE_NOT_INITED, kTraceError);
284 return -1;
285 }
286 if (channel == -1) {
287 return _shared->transmit_mixer()->IsPlayingFileAsMicrophone();
288 } else {
289 // Stop adding file after demultiplexing <=> affects one channel only
290 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
291 voe::Channel* channelPtr = ch.channel();
292 if (channelPtr == NULL) {
293 _shared->SetLastError(
294 VE_CHANNEL_NOT_VALID, kTraceError,
295 "IsPlayingFileAsMicrophone() failed to locate channel");
296 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000297 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200298 return channelPtr->IsPlayingFileAsMicrophone();
299 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000300}
301
Jelena Marusic0d266052015-05-04 14:15:32 +0200302int VoEFileImpl::StartRecordingPlayout(int channel,
303 const char* fileNameUTF8,
304 CodecInst* compression,
305 int maxSizeBytes) {
306 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
307 "StartRecordingPlayout(channel=%d, fileNameUTF8=%s, "
308 "compression, maxSizeBytes=%d)",
309 channel, fileNameUTF8, maxSizeBytes);
André Susano Pinto664cdaf2015-05-20 11:11:07 +0200310 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
niklase@google.com470e71d2011-07-07 08:21:25 +0000311
Jelena Marusic0d266052015-05-04 14:15:32 +0200312 if (!_shared->statistics().Initialized()) {
313 _shared->SetLastError(VE_NOT_INITED, kTraceError);
314 return -1;
315 }
316 if (channel == -1) {
317 return _shared->output_mixer()->StartRecordingPlayout(fileNameUTF8,
318 compression);
319 } else {
320 // Add file after demultiplexing <=> affects one channel only
321 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
322 voe::Channel* channelPtr = ch.channel();
323 if (channelPtr == NULL) {
324 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
325 "StartRecordingPlayout() failed to locate channel");
326 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000327 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200328 return channelPtr->StartRecordingPlayout(fileNameUTF8, compression);
329 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000330}
331
Jelena Marusic0d266052015-05-04 14:15:32 +0200332int VoEFileImpl::StartRecordingPlayout(int channel,
333 OutStream* stream,
334 CodecInst* compression) {
335 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
336 "StartRecordingPlayout(channel=%d, stream, compression)",
337 channel);
338 if (!_shared->statistics().Initialized()) {
339 _shared->SetLastError(VE_NOT_INITED, kTraceError);
340 return -1;
341 }
342 if (channel == -1) {
343 return _shared->output_mixer()->StartRecordingPlayout(stream, compression);
344 } else {
345 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
346 voe::Channel* channelPtr = ch.channel();
347 if (channelPtr == NULL) {
348 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
349 "StartRecordingPlayout() failed to locate channel");
350 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000351 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200352 return channelPtr->StartRecordingPlayout(stream, compression);
353 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000354}
355
Jelena Marusic0d266052015-05-04 14:15:32 +0200356int VoEFileImpl::StopRecordingPlayout(int channel) {
357 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
358 "StopRecordingPlayout(channel=%d)", channel);
359 if (!_shared->statistics().Initialized()) {
360 _shared->SetLastError(VE_NOT_INITED, kTraceError);
361 return -1;
362 }
363 if (channel == -1) {
364 return _shared->output_mixer()->StopRecordingPlayout();
365 } else {
366 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
367 voe::Channel* channelPtr = ch.channel();
368 if (channelPtr == NULL) {
369 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
370 "StopRecordingPlayout() failed to locate channel");
371 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000372 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200373 return channelPtr->StopRecordingPlayout();
374 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000375}
376
Jelena Marusic0d266052015-05-04 14:15:32 +0200377int VoEFileImpl::StartRecordingMicrophone(const char* fileNameUTF8,
378 CodecInst* compression,
379 int maxSizeBytes) {
380 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
381 "StartRecordingMicrophone(fileNameUTF8=%s, compression, "
382 "maxSizeBytes=%d)",
383 fileNameUTF8, maxSizeBytes);
André Susano Pinto664cdaf2015-05-20 11:11:07 +0200384 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
niklase@google.com470e71d2011-07-07 08:21:25 +0000385
Jelena Marusic0d266052015-05-04 14:15:32 +0200386 if (!_shared->statistics().Initialized()) {
387 _shared->SetLastError(VE_NOT_INITED, kTraceError);
388 return -1;
389 }
390 if (_shared->transmit_mixer()->StartRecordingMicrophone(fileNameUTF8,
391 compression)) {
392 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
393 "StartRecordingMicrophone() failed to start recording");
394 return -1;
395 }
solenberge313e022015-09-08 02:16:04 -0700396 if (!_shared->audio_device()->Recording()) {
Jelena Marusic0d266052015-05-04 14:15:32 +0200397 if (_shared->audio_device()->InitRecording() != 0) {
398 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
399 "StartRecordingMicrophone() failed to initialize recording");
400 return -1;
401 }
402 if (_shared->audio_device()->StartRecording() != 0) {
403 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
404 "StartRecordingMicrophone() failed to start recording");
405 return -1;
406 }
407 }
408 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000409}
410
Jelena Marusic0d266052015-05-04 14:15:32 +0200411int VoEFileImpl::StartRecordingMicrophone(OutStream* stream,
412 CodecInst* compression) {
413 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
414 "StartRecordingMicrophone(stream, compression)");
niklase@google.com470e71d2011-07-07 08:21:25 +0000415
Jelena Marusic0d266052015-05-04 14:15:32 +0200416 if (!_shared->statistics().Initialized()) {
417 _shared->SetLastError(VE_NOT_INITED, kTraceError);
418 return -1;
419 }
420 if (_shared->transmit_mixer()->StartRecordingMicrophone(stream,
421 compression) == -1) {
422 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
423 "StartRecordingMicrophone() failed to start recording");
424 return -1;
425 }
solenberge313e022015-09-08 02:16:04 -0700426 if (!_shared->audio_device()->Recording()) {
Jelena Marusic0d266052015-05-04 14:15:32 +0200427 if (_shared->audio_device()->InitRecording() != 0) {
428 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
429 "StartRecordingMicrophone() failed to initialize recording");
430 return -1;
431 }
432 if (_shared->audio_device()->StartRecording() != 0) {
433 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
434 "StartRecordingMicrophone() failed to start recording");
435 return -1;
436 }
437 }
438 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000439}
440
Jelena Marusic0d266052015-05-04 14:15:32 +0200441int VoEFileImpl::StopRecordingMicrophone() {
442 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
443 "StopRecordingMicrophone()");
444 if (!_shared->statistics().Initialized()) {
445 _shared->SetLastError(VE_NOT_INITED, kTraceError);
446 return -1;
447 }
448
449 int err = 0;
450
451 // TODO(xians): consider removing Start/StopRecording() in
452 // Start/StopRecordingMicrophone() if no channel is recording.
453 if (_shared->NumOfSendingChannels() == 0 &&
454 _shared->audio_device()->Recording()) {
455 // Stop audio-device recording if no channel is recording
456 if (_shared->audio_device()->StopRecording() != 0) {
457 _shared->SetLastError(
458 VE_CANNOT_STOP_RECORDING, kTraceError,
459 "StopRecordingMicrophone() failed to stop recording");
460 err = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000461 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200462 }
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000463
Jelena Marusic0d266052015-05-04 14:15:32 +0200464 if (_shared->transmit_mixer()->StopRecordingMicrophone() != 0) {
465 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
466 "StopRecordingMicrophone() failed to stop recording to mixer");
467 err = -1;
468 }
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000469
Jelena Marusic0d266052015-05-04 14:15:32 +0200470 return err;
niklase@google.com470e71d2011-07-07 08:21:25 +0000471}
472
niklase@google.com470e71d2011-07-07 08:21:25 +0000473#endif // #ifdef WEBRTC_VOICE_ENGINE_FILE_API
andrew@webrtc.orgeeaf3d12012-01-24 06:30:02 +0000474
475} // namespace webrtc