blob: 78613b03f5e90241da498d7b4312b20b0348bbc6 [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
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000013#include "webrtc/modules/media_file/interface/media_file.h"
14#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
15#include "webrtc/system_wrappers/interface/file_wrapper.h"
16#include "webrtc/system_wrappers/interface/trace.h"
17#include "webrtc/voice_engine/channel.h"
18#include "webrtc/voice_engine/include/voe_errors.h"
19#include "webrtc/voice_engine/output_mixer.h"
20#include "webrtc/voice_engine/transmit_mixer.h"
21#include "webrtc/voice_engine/voice_engine_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23namespace webrtc {
24
Jelena Marusic0d266052015-05-04 14:15:32 +020025VoEFile* VoEFile::GetInterface(VoiceEngine* voiceEngine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000026#ifndef WEBRTC_VOICE_ENGINE_FILE_API
Jelena Marusic0d266052015-05-04 14:15:32 +020027 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000028#else
Jelena Marusic0d266052015-05-04 14:15:32 +020029 if (NULL == voiceEngine) {
30 return NULL;
31 }
32 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
33 s->AddRef();
34 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000035#endif
36}
37
38#ifdef WEBRTC_VOICE_ENGINE_FILE_API
39
Jelena Marusic0d266052015-05-04 14:15:32 +020040VoEFileImpl::VoEFileImpl(voe::SharedData* shared) : _shared(shared) {
41 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
42 "VoEFileImpl::VoEFileImpl() - ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000043}
44
Jelena Marusic0d266052015-05-04 14:15:32 +020045VoEFileImpl::~VoEFileImpl() {
46 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
47 "VoEFileImpl::~VoEFileImpl() - dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000048}
49
Jelena Marusic0d266052015-05-04 14:15:32 +020050int VoEFileImpl::StartPlayingFileLocally(int channel,
51 const char fileNameUTF8[1024],
52 bool loop,
53 FileFormats format,
54 float volumeScaling,
55 int startPointMs,
56 int stopPointMs) {
57 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
58 "StartPlayingFileLocally(channel=%d, fileNameUTF8[]=%s, "
59 "loop=%d, format=%d, volumeScaling=%5.3f, startPointMs=%d,"
60 " stopPointMs=%d)",
61 channel, fileNameUTF8, loop, format, volumeScaling, startPointMs,
62 stopPointMs);
André Susano Pinto664cdaf2015-05-20 11:11:07 +020063 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
Jelena Marusic0d266052015-05-04 14:15:32 +020064 if (!_shared->statistics().Initialized()) {
65 _shared->SetLastError(VE_NOT_INITED, kTraceError);
66 return -1;
67 }
68 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
69 voe::Channel* channelPtr = ch.channel();
70 if (channelPtr == NULL) {
71 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
72 "StartPlayingFileLocally() failed to locate channel");
73 return -1;
74 }
niklase@google.com470e71d2011-07-07 08:21:25 +000075
Jelena Marusic0d266052015-05-04 14:15:32 +020076 return channelPtr->StartPlayingFileLocally(fileNameUTF8, loop, format,
77 startPointMs, volumeScaling,
78 stopPointMs, NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +000079}
80
81int VoEFileImpl::StartPlayingFileLocally(int channel,
82 InStream* stream,
83 FileFormats format,
84 float volumeScaling,
85 int startPointMs,
Jelena Marusic0d266052015-05-04 14:15:32 +020086 int stopPointMs) {
87 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
88 "StartPlayingFileLocally(channel=%d, stream, format=%d, "
89 "volumeScaling=%5.3f, startPointMs=%d, stopPointMs=%d)",
90 channel, format, volumeScaling, startPointMs, stopPointMs);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
Jelena Marusic0d266052015-05-04 14:15:32 +020092 if (!_shared->statistics().Initialized()) {
93 _shared->SetLastError(VE_NOT_INITED, kTraceError);
94 return -1;
95 }
niklase@google.com470e71d2011-07-07 08:21:25 +000096
Jelena Marusic0d266052015-05-04 14:15:32 +020097 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
98 voe::Channel* channelPtr = ch.channel();
99 if (channelPtr == NULL) {
100 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
101 "StartPlayingFileLocally() failed to locate channel");
102 return -1;
103 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
Jelena Marusic0d266052015-05-04 14:15:32 +0200105 return channelPtr->StartPlayingFileLocally(stream, format, startPointMs,
106 volumeScaling, stopPointMs, NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107}
108
Jelena Marusic0d266052015-05-04 14:15:32 +0200109int VoEFileImpl::StopPlayingFileLocally(int channel) {
110 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
111 "StopPlayingFileLocally()");
112 if (!_shared->statistics().Initialized()) {
113 _shared->SetLastError(VE_NOT_INITED, kTraceError);
114 return -1;
115 }
116 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
117 voe::Channel* channelPtr = ch.channel();
118 if (channelPtr == NULL) {
119 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
120 "StopPlayingFileLocally() failed to locate channel");
121 return -1;
122 }
123 return channelPtr->StopPlayingFileLocally();
niklase@google.com470e71d2011-07-07 08:21:25 +0000124}
125
Jelena Marusic0d266052015-05-04 14:15:32 +0200126int VoEFileImpl::IsPlayingFileLocally(int channel) {
127 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
128 "IsPlayingFileLocally(channel=%d)", channel);
129 if (!_shared->statistics().Initialized()) {
130 _shared->SetLastError(VE_NOT_INITED, kTraceError);
131 return -1;
132 }
133 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
134 voe::Channel* channelPtr = ch.channel();
135 if (channelPtr == NULL) {
136 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
137 "StopPlayingFileLocally() failed to locate channel");
138 return -1;
139 }
140 return channelPtr->IsPlayingFileLocally();
niklase@google.com470e71d2011-07-07 08:21:25 +0000141}
142
niklase@google.com470e71d2011-07-07 08:21:25 +0000143int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
144 const char fileNameUTF8[1024],
145 bool loop,
146 bool mixWithMicrophone,
147 FileFormats format,
Jelena Marusic0d266052015-05-04 14:15:32 +0200148 float volumeScaling) {
149 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
150 "StartPlayingFileAsMicrophone(channel=%d, fileNameUTF8=%s, "
151 "loop=%d, mixWithMicrophone=%d, format=%d, "
152 "volumeScaling=%5.3f)",
153 channel, fileNameUTF8, loop, mixWithMicrophone, format,
154 volumeScaling);
André Susano Pinto664cdaf2015-05-20 11:11:07 +0200155 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
Jelena Marusic0d266052015-05-04 14:15:32 +0200156 if (!_shared->statistics().Initialized()) {
157 _shared->SetLastError(VE_NOT_INITED, kTraceError);
158 return -1;
159 }
160
161 const uint32_t startPointMs(0);
162 const uint32_t stopPointMs(0);
163
164 if (channel == -1) {
165 int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone(
166 fileNameUTF8, loop, format, startPointMs, volumeScaling, stopPointMs,
167 NULL);
168 if (res) {
169 WEBRTC_TRACE(
170 kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
171 "StartPlayingFileAsMicrophone() failed to start playing file");
172 return (-1);
173 } else {
174 _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone);
175 return (0);
176 }
177 } else {
178 // Add file after demultiplexing <=> affects one channel only
179 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
180 voe::Channel* channelPtr = ch.channel();
181 if (channelPtr == NULL) {
182 _shared->SetLastError(
183 VE_CHANNEL_NOT_VALID, kTraceError,
184 "StartPlayingFileAsMicrophone() failed to locate channel");
185 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000186 }
187
Jelena Marusic0d266052015-05-04 14:15:32 +0200188 int res = channelPtr->StartPlayingFileAsMicrophone(
189 fileNameUTF8, loop, format, startPointMs, volumeScaling, stopPointMs,
190 NULL);
191 if (res) {
192 WEBRTC_TRACE(
193 kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
194 "StartPlayingFileAsMicrophone() failed to start playing file");
195 return -1;
196 } else {
197 channelPtr->SetMixWithMicStatus(mixWithMicrophone);
198 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000199 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200200 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000201}
202
203int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
204 InStream* stream,
205 bool mixWithMicrophone,
206 FileFormats format,
Jelena Marusic0d266052015-05-04 14:15:32 +0200207 float volumeScaling) {
208 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
209 "StartPlayingFileAsMicrophone(channel=%d, stream,"
210 " mixWithMicrophone=%d, format=%d, volumeScaling=%5.3f)",
211 channel, mixWithMicrophone, format, volumeScaling);
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
Jelena Marusic0d266052015-05-04 14:15:32 +0200213 if (!_shared->statistics().Initialized()) {
214 _shared->SetLastError(VE_NOT_INITED, kTraceError);
215 return -1;
216 }
217
218 const uint32_t startPointMs(0);
219 const uint32_t stopPointMs(0);
220
221 if (channel == -1) {
222 int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone(
223 stream, format, startPointMs, volumeScaling, stopPointMs, NULL);
224 if (res) {
225 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
226 "StartPlayingFileAsMicrophone() failed to start "
227 "playing stream");
228 return (-1);
229 } else {
230 _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone);
231 return (0);
232 }
233 } else {
234 // Add file after demultiplexing <=> affects one channel only
235 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
236 voe::Channel* channelPtr = ch.channel();
237 if (channelPtr == NULL) {
238 _shared->SetLastError(
239 VE_CHANNEL_NOT_VALID, kTraceError,
240 "StartPlayingFileAsMicrophone() failed to locate channel");
241 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 }
243
Jelena Marusic0d266052015-05-04 14:15:32 +0200244 int res = channelPtr->StartPlayingFileAsMicrophone(
245 stream, format, startPointMs, volumeScaling, stopPointMs, NULL);
246 if (res) {
247 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
248 "StartPlayingFileAsMicrophone() failed to start "
249 "playing stream");
250 return -1;
251 } else {
252 channelPtr->SetMixWithMicStatus(mixWithMicrophone);
253 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000254 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200255 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000256}
257
Jelena Marusic0d266052015-05-04 14:15:32 +0200258int VoEFileImpl::StopPlayingFileAsMicrophone(int channel) {
259 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
260 "StopPlayingFileAsMicrophone(channel=%d)", channel);
261 if (!_shared->statistics().Initialized()) {
262 _shared->SetLastError(VE_NOT_INITED, kTraceError);
263 return -1;
264 }
265 if (channel == -1) {
266 // Stop adding file before demultiplexing <=> affects all channels
267 return _shared->transmit_mixer()->StopPlayingFileAsMicrophone();
268 } else {
269 // Stop adding file after demultiplexing <=> affects one channel only
270 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
271 voe::Channel* channelPtr = ch.channel();
272 if (channelPtr == NULL) {
273 _shared->SetLastError(
274 VE_CHANNEL_NOT_VALID, kTraceError,
275 "StopPlayingFileAsMicrophone() failed to locate channel");
276 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000277 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200278 return channelPtr->StopPlayingFileAsMicrophone();
279 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000280}
281
Jelena Marusic0d266052015-05-04 14:15:32 +0200282int VoEFileImpl::IsPlayingFileAsMicrophone(int channel) {
283 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
284 "IsPlayingFileAsMicrophone(channel=%d)", channel);
285 if (!_shared->statistics().Initialized()) {
286 _shared->SetLastError(VE_NOT_INITED, kTraceError);
287 return -1;
288 }
289 if (channel == -1) {
290 return _shared->transmit_mixer()->IsPlayingFileAsMicrophone();
291 } else {
292 // Stop adding file after demultiplexing <=> affects one channel only
293 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
294 voe::Channel* channelPtr = ch.channel();
295 if (channelPtr == NULL) {
296 _shared->SetLastError(
297 VE_CHANNEL_NOT_VALID, kTraceError,
298 "IsPlayingFileAsMicrophone() failed to locate channel");
299 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000300 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200301 return channelPtr->IsPlayingFileAsMicrophone();
302 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000303}
304
Jelena Marusic0d266052015-05-04 14:15:32 +0200305int VoEFileImpl::StartRecordingPlayout(int channel,
306 const char* fileNameUTF8,
307 CodecInst* compression,
308 int maxSizeBytes) {
309 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
310 "StartRecordingPlayout(channel=%d, fileNameUTF8=%s, "
311 "compression, maxSizeBytes=%d)",
312 channel, fileNameUTF8, maxSizeBytes);
André Susano Pinto664cdaf2015-05-20 11:11:07 +0200313 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
Jelena Marusic0d266052015-05-04 14:15:32 +0200315 if (!_shared->statistics().Initialized()) {
316 _shared->SetLastError(VE_NOT_INITED, kTraceError);
317 return -1;
318 }
319 if (channel == -1) {
320 return _shared->output_mixer()->StartRecordingPlayout(fileNameUTF8,
321 compression);
322 } else {
323 // Add file after demultiplexing <=> affects one channel only
324 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
325 voe::Channel* channelPtr = ch.channel();
326 if (channelPtr == NULL) {
327 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
328 "StartRecordingPlayout() failed to locate channel");
329 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000330 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200331 return channelPtr->StartRecordingPlayout(fileNameUTF8, compression);
332 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000333}
334
Jelena Marusic0d266052015-05-04 14:15:32 +0200335int VoEFileImpl::StartRecordingPlayout(int channel,
336 OutStream* stream,
337 CodecInst* compression) {
338 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
339 "StartRecordingPlayout(channel=%d, stream, compression)",
340 channel);
341 if (!_shared->statistics().Initialized()) {
342 _shared->SetLastError(VE_NOT_INITED, kTraceError);
343 return -1;
344 }
345 if (channel == -1) {
346 return _shared->output_mixer()->StartRecordingPlayout(stream, compression);
347 } else {
348 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
349 voe::Channel* channelPtr = ch.channel();
350 if (channelPtr == NULL) {
351 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
352 "StartRecordingPlayout() failed to locate channel");
353 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200355 return channelPtr->StartRecordingPlayout(stream, compression);
356 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000357}
358
Jelena Marusic0d266052015-05-04 14:15:32 +0200359int VoEFileImpl::StopRecordingPlayout(int channel) {
360 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
361 "StopRecordingPlayout(channel=%d)", channel);
362 if (!_shared->statistics().Initialized()) {
363 _shared->SetLastError(VE_NOT_INITED, kTraceError);
364 return -1;
365 }
366 if (channel == -1) {
367 return _shared->output_mixer()->StopRecordingPlayout();
368 } else {
369 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
370 voe::Channel* channelPtr = ch.channel();
371 if (channelPtr == NULL) {
372 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
373 "StopRecordingPlayout() failed to locate channel");
374 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000375 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200376 return channelPtr->StopRecordingPlayout();
377 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000378}
379
Jelena Marusic0d266052015-05-04 14:15:32 +0200380int VoEFileImpl::StartRecordingMicrophone(const char* fileNameUTF8,
381 CodecInst* compression,
382 int maxSizeBytes) {
383 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
384 "StartRecordingMicrophone(fileNameUTF8=%s, compression, "
385 "maxSizeBytes=%d)",
386 fileNameUTF8, maxSizeBytes);
André Susano Pinto664cdaf2015-05-20 11:11:07 +0200387 static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
niklase@google.com470e71d2011-07-07 08:21:25 +0000388
Jelena Marusic0d266052015-05-04 14:15:32 +0200389 if (!_shared->statistics().Initialized()) {
390 _shared->SetLastError(VE_NOT_INITED, kTraceError);
391 return -1;
392 }
393 if (_shared->transmit_mixer()->StartRecordingMicrophone(fileNameUTF8,
394 compression)) {
395 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
396 "StartRecordingMicrophone() failed to start recording");
397 return -1;
398 }
399 if (_shared->audio_device()->Recording()) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 return 0;
Jelena Marusic0d266052015-05-04 14:15:32 +0200401 }
402 if (!_shared->ext_recording()) {
403 if (_shared->audio_device()->InitRecording() != 0) {
404 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
405 "StartRecordingMicrophone() failed to initialize recording");
406 return -1;
407 }
408 if (_shared->audio_device()->StartRecording() != 0) {
409 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
410 "StartRecordingMicrophone() failed to start recording");
411 return -1;
412 }
413 }
414 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000415}
416
Jelena Marusic0d266052015-05-04 14:15:32 +0200417int VoEFileImpl::StartRecordingMicrophone(OutStream* stream,
418 CodecInst* compression) {
419 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
420 "StartRecordingMicrophone(stream, compression)");
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
Jelena Marusic0d266052015-05-04 14:15:32 +0200422 if (!_shared->statistics().Initialized()) {
423 _shared->SetLastError(VE_NOT_INITED, kTraceError);
424 return -1;
425 }
426 if (_shared->transmit_mixer()->StartRecordingMicrophone(stream,
427 compression) == -1) {
428 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
429 "StartRecordingMicrophone() failed to start recording");
430 return -1;
431 }
432 if (_shared->audio_device()->Recording()) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000433 return 0;
Jelena Marusic0d266052015-05-04 14:15:32 +0200434 }
435 if (!_shared->ext_recording()) {
436 if (_shared->audio_device()->InitRecording() != 0) {
437 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
438 "StartRecordingMicrophone() failed to initialize recording");
439 return -1;
440 }
441 if (_shared->audio_device()->StartRecording() != 0) {
442 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
443 "StartRecordingMicrophone() failed to start recording");
444 return -1;
445 }
446 }
447 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000448}
449
Jelena Marusic0d266052015-05-04 14:15:32 +0200450int VoEFileImpl::StopRecordingMicrophone() {
451 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
452 "StopRecordingMicrophone()");
453 if (!_shared->statistics().Initialized()) {
454 _shared->SetLastError(VE_NOT_INITED, kTraceError);
455 return -1;
456 }
457
458 int err = 0;
459
460 // TODO(xians): consider removing Start/StopRecording() in
461 // Start/StopRecordingMicrophone() if no channel is recording.
462 if (_shared->NumOfSendingChannels() == 0 &&
463 _shared->audio_device()->Recording()) {
464 // Stop audio-device recording if no channel is recording
465 if (_shared->audio_device()->StopRecording() != 0) {
466 _shared->SetLastError(
467 VE_CANNOT_STOP_RECORDING, kTraceError,
468 "StopRecordingMicrophone() failed to stop recording");
469 err = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000470 }
Jelena Marusic0d266052015-05-04 14:15:32 +0200471 }
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000472
Jelena Marusic0d266052015-05-04 14:15:32 +0200473 if (_shared->transmit_mixer()->StopRecordingMicrophone() != 0) {
474 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_shared->instance_id(), -1),
475 "StopRecordingMicrophone() failed to stop recording to mixer");
476 err = -1;
477 }
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000478
Jelena Marusic0d266052015-05-04 14:15:32 +0200479 return err;
niklase@google.com470e71d2011-07-07 08:21:25 +0000480}
481
niklase@google.com470e71d2011-07-07 08:21:25 +0000482#endif // #ifdef WEBRTC_VOICE_ENGINE_FILE_API
andrew@webrtc.orgeeaf3d12012-01-24 06:30:02 +0000483
484} // namespace webrtc