blob: 95e9d21b3917d73004e3fc9c405785e4a338b388 [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
25VoEFile* VoEFile::GetInterface(VoiceEngine* voiceEngine)
26{
27#ifndef WEBRTC_VOICE_ENGINE_FILE_API
28 return NULL;
29#else
30 if (NULL == voiceEngine)
31 {
32 return NULL;
33 }
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000034 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:22 +000035 s->AddRef();
36 return s;
niklase@google.com470e71d2011-07-07 08:21:25 +000037#endif
38}
39
40#ifdef WEBRTC_VOICE_ENGINE_FILE_API
41
tommi@webrtc.org851becd2012-04-04 14:57:19 +000042VoEFileImpl::VoEFileImpl(voe::SharedData* shared) : _shared(shared)
niklase@google.com470e71d2011-07-07 08:21:25 +000043{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000044 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000045 "VoEFileImpl::VoEFileImpl() - ctor");
46}
47
48VoEFileImpl::~VoEFileImpl()
49{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000050 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000051 "VoEFileImpl::~VoEFileImpl() - dtor");
52}
53
niklase@google.com470e71d2011-07-07 08:21:25 +000054int VoEFileImpl::StartPlayingFileLocally(
55 int channel,
56 const char fileNameUTF8[1024],
57 bool loop, FileFormats format,
58 float volumeScaling,
59 int startPointMs,
60 int stopPointMs)
61{
tommi@webrtc.org851becd2012-04-04 14:57:19 +000062 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +000063 "StartPlayingFileLocally(channel=%d, fileNameUTF8[]=%s, "
64 "loop=%d, format=%d, volumeScaling=%5.3f, startPointMs=%d,"
65 " stopPointMs=%d)",
66 channel, fileNameUTF8, loop, format, volumeScaling,
67 startPointMs, stopPointMs);
68 assert(1024 == FileWrapper::kMaxFileNameSize);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000069 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +000070 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000071 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +000072 return -1;
73 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000074 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
75 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +000076 if (channelPtr == NULL)
77 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000078 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +000079 "StartPlayingFileLocally() failed to locate channel");
80 return -1;
81 }
82
83 return channelPtr->StartPlayingFileLocally(fileNameUTF8,
84 loop,
85 format,
86 startPointMs,
87 volumeScaling,
88 stopPointMs,
89 NULL);
90}
91
92int VoEFileImpl::StartPlayingFileLocally(int channel,
93 InStream* stream,
94 FileFormats format,
95 float volumeScaling,
96 int startPointMs,
97 int stopPointMs)
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 "StartPlayingFileLocally(channel=%d, stream, format=%d, "
101 "volumeScaling=%5.3f, startPointMs=%d, stopPointMs=%d)",
102 channel, format, volumeScaling, startPointMs, stopPointMs);
103
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 }
109
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000110 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
111 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 if (channelPtr == NULL)
113 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000114 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 "StartPlayingFileLocally() failed to locate channel");
116 return -1;
117 }
118
119 return channelPtr->StartPlayingFileLocally(stream,
120 format,
121 startPointMs,
122 volumeScaling,
123 stopPointMs,
124 NULL);
125}
126
127int VoEFileImpl::StopPlayingFileLocally(int channel)
128{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000129 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000130 "StopPlayingFileLocally()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000131 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000132 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000133 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 return -1;
135 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000136 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
137 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000138 if (channelPtr == NULL)
139 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000140 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000141 "StopPlayingFileLocally() failed to locate channel");
142 return -1;
143 }
144 return channelPtr->StopPlayingFileLocally();
145}
146
147int VoEFileImpl::IsPlayingFileLocally(int channel)
148{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000149 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000150 "IsPlayingFileLocally(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000151 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000152 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000153 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000154 return -1;
155 }
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000156 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
157 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 if (channelPtr == NULL)
159 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000160 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000161 "StopPlayingFileLocally() failed to locate channel");
162 return -1;
163 }
164 return channelPtr->IsPlayingFileLocally();
165}
166
niklase@google.com470e71d2011-07-07 08:21:25 +0000167int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
168 const char fileNameUTF8[1024],
169 bool loop,
170 bool mixWithMicrophone,
171 FileFormats format,
172 float volumeScaling)
173{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000174 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 "StartPlayingFileAsMicrophone(channel=%d, fileNameUTF8=%s, "
176 "loop=%d, mixWithMicrophone=%d, format=%d, "
177 "volumeScaling=%5.3f)",
178 channel, fileNameUTF8, loop, mixWithMicrophone, format,
179 volumeScaling);
180 assert(1024 == FileWrapper::kMaxFileNameSize);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000181 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000182 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000183 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 return -1;
185 }
186
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000187 const uint32_t startPointMs(0);
188 const uint32_t stopPointMs(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
190 if (channel == -1)
191 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000192 int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone(
niklase@google.com470e71d2011-07-07 08:21:25 +0000193 fileNameUTF8,
194 loop,
195 format,
196 startPointMs,
197 volumeScaling,
198 stopPointMs,
199 NULL);
200 if (res)
201 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000202 WEBRTC_TRACE(kTraceError, kTraceVoice,
203 VoEId(_shared->instance_id(), -1),
204 "StartPlayingFileAsMicrophone() failed to start playing file");
niklase@google.com470e71d2011-07-07 08:21:25 +0000205 return(-1);
206 }
207 else
208 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000209 _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone);
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 return(0);
211 }
212 }
213 else
214 {
215 // Add file after demultiplexing <=> affects one channel only
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000216 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
217 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000218 if (channelPtr == NULL)
219 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000220 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000221 "StartPlayingFileAsMicrophone() failed to locate channel");
222 return -1;
223 }
224
225 int res = channelPtr->StartPlayingFileAsMicrophone(fileNameUTF8,
226 loop,
227 format,
228 startPointMs,
229 volumeScaling,
230 stopPointMs,
231 NULL);
232 if (res)
233 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000234 WEBRTC_TRACE(kTraceError, kTraceVoice,
235 VoEId(_shared->instance_id(), -1),
236 "StartPlayingFileAsMicrophone() failed to start playing file");
niklase@google.com470e71d2011-07-07 08:21:25 +0000237 return -1;
238 }
239 else
240 {
241 channelPtr->SetMixWithMicStatus(mixWithMicrophone);
242 return 0;
243 }
244 }
245}
246
247int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
248 InStream* stream,
249 bool mixWithMicrophone,
250 FileFormats format,
251 float volumeScaling)
252{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000253 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000254 "StartPlayingFileAsMicrophone(channel=%d, stream,"
255 " mixWithMicrophone=%d, format=%d, volumeScaling=%5.3f)",
256 channel, mixWithMicrophone, format, volumeScaling);
257
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000258 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000259 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000260 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000261 return -1;
262 }
263
pbos@webrtc.org6141e132013-04-09 10:09:10 +0000264 const uint32_t startPointMs(0);
265 const uint32_t stopPointMs(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000266
267 if (channel == -1)
268 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000269 int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone(
niklase@google.com470e71d2011-07-07 08:21:25 +0000270 stream,
271 format,
272 startPointMs,
273 volumeScaling,
274 stopPointMs,
275 NULL);
276 if (res)
277 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000278 WEBRTC_TRACE(kTraceError, kTraceVoice,
279 VoEId(_shared->instance_id(), -1),
280 "StartPlayingFileAsMicrophone() failed to start "
281 "playing stream");
niklase@google.com470e71d2011-07-07 08:21:25 +0000282 return(-1);
283 }
284 else
285 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000286 _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone);
niklase@google.com470e71d2011-07-07 08:21:25 +0000287 return(0);
288 }
289 }
290 else
291 {
292 // Add file after demultiplexing <=> affects one channel only
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000293 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
294 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000295 if (channelPtr == NULL)
296 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000297 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000298 "StartPlayingFileAsMicrophone() failed to locate channel");
299 return -1;
300 }
301
302 int res = channelPtr->StartPlayingFileAsMicrophone(
303 stream, format, startPointMs, volumeScaling, stopPointMs, NULL);
304 if (res)
305 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000306 WEBRTC_TRACE(kTraceError, kTraceVoice,
307 VoEId(_shared->instance_id(), -1),
308 "StartPlayingFileAsMicrophone() failed to start "
309 "playing stream");
niklase@google.com470e71d2011-07-07 08:21:25 +0000310 return -1;
311 }
312 else
313 {
314 channelPtr->SetMixWithMicStatus(mixWithMicrophone);
315 return 0;
316 }
317 }
318}
319
320int VoEFileImpl::StopPlayingFileAsMicrophone(int channel)
321{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000322 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000323 "StopPlayingFileAsMicrophone(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000324 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000325 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000326 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000327 return -1;
328 }
329 if (channel == -1)
330 {
331 // Stop adding file before demultiplexing <=> affects all channels
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000332 return _shared->transmit_mixer()->StopPlayingFileAsMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000333 }
334 else
335 {
336 // Stop adding file after demultiplexing <=> affects one channel only
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000337 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
338 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000339 if (channelPtr == NULL)
340 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000341 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000342 "StopPlayingFileAsMicrophone() failed to locate channel");
343 return -1;
344 }
345 return channelPtr->StopPlayingFileAsMicrophone();
346 }
347}
348
349int VoEFileImpl::IsPlayingFileAsMicrophone(int channel)
350{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000351 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000352 "IsPlayingFileAsMicrophone(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000353 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000355 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 return -1;
357 }
358 if (channel == -1)
359 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000360 return _shared->transmit_mixer()->IsPlayingFileAsMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000361 }
362 else
363 {
364 // Stop adding file after demultiplexing <=> affects one channel only
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000365 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
366 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000367 if (channelPtr == NULL)
368 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000369 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000370 "IsPlayingFileAsMicrophone() failed to locate channel");
371 return -1;
372 }
373 return channelPtr->IsPlayingFileAsMicrophone();
374 }
375}
376
niklase@google.com470e71d2011-07-07 08:21:25 +0000377int VoEFileImpl::StartRecordingPlayout(
378 int channel, const char* fileNameUTF8, CodecInst* compression,
379 int maxSizeBytes)
380{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000381 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000382 "StartRecordingPlayout(channel=%d, fileNameUTF8=%s, "
383 "compression, maxSizeBytes=%d)",
384 channel, fileNameUTF8, maxSizeBytes);
385 assert(1024 == FileWrapper::kMaxFileNameSize);
386
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000387 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000388 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000389 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000390 return -1;
391 }
392 if (channel == -1)
393 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000394 return _shared->output_mixer()->StartRecordingPlayout
niklas.enbom@webrtc.org5398d952012-03-26 08:11:25 +0000395 (fileNameUTF8, compression);
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 }
397 else
398 {
399 // Add file after demultiplexing <=> affects one channel only
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000400 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
401 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000402 if (channelPtr == NULL)
403 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000404 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 "StartRecordingPlayout() failed to locate channel");
406 return -1;
407 }
408 return channelPtr->StartRecordingPlayout(fileNameUTF8, compression);
409 }
410}
411
412int VoEFileImpl::StartRecordingPlayout(
413 int channel, OutStream* stream, CodecInst* compression)
414{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000415 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000416 "StartRecordingPlayout(channel=%d, stream, compression)",
417 channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000418 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000419 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000420 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000421 return -1;
422 }
423 if (channel == -1)
424 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000425 return _shared->output_mixer()->
426 StartRecordingPlayout(stream, compression);
niklase@google.com470e71d2011-07-07 08:21:25 +0000427 }
428 else
429 {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000430 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
431 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000432 if (channelPtr == NULL)
433 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000434 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000435 "StartRecordingPlayout() failed to locate channel");
436 return -1;
437 }
438 return channelPtr->StartRecordingPlayout(stream, compression);
439 }
440}
441
442int VoEFileImpl::StopRecordingPlayout(int channel)
443{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000444 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 "StopRecordingPlayout(channel=%d)", channel);
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000446 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000447 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000448 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000449 return -1;
450 }
451 if (channel == -1)
452 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000453 return _shared->output_mixer()->StopRecordingPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000454 }
455 else
456 {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +0000457 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
458 voe::Channel* channelPtr = ch.channel();
niklase@google.com470e71d2011-07-07 08:21:25 +0000459 if (channelPtr == NULL)
460 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000461 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000462 "StopRecordingPlayout() failed to locate channel");
463 return -1;
464 }
465 return channelPtr->StopRecordingPlayout();
466 }
467}
468
469int VoEFileImpl::StartRecordingMicrophone(
470 const char* fileNameUTF8, CodecInst* compression, int maxSizeBytes)
471{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000472 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000473 "StartRecordingMicrophone(fileNameUTF8=%s, compression, "
474 "maxSizeBytes=%d)", fileNameUTF8, maxSizeBytes);
475 assert(1024 == FileWrapper::kMaxFileNameSize);
476
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000477 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000478 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000479 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000480 return -1;
481 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000482 if (_shared->transmit_mixer()->StartRecordingMicrophone(fileNameUTF8,
483 compression))
niklase@google.com470e71d2011-07-07 08:21:25 +0000484 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000485 WEBRTC_TRACE(kTraceError, kTraceVoice,
486 VoEId(_shared->instance_id(), -1),
487 "StartRecordingMicrophone() failed to start recording");
niklase@google.com470e71d2011-07-07 08:21:25 +0000488 return -1;
489 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000490 if (_shared->audio_device()->Recording())
niklase@google.com470e71d2011-07-07 08:21:25 +0000491 {
492 return 0;
493 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000494 if (!_shared->ext_recording())
niklase@google.com470e71d2011-07-07 08:21:25 +0000495 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000496 if (_shared->audio_device()->InitRecording() != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000497 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000498 WEBRTC_TRACE(kTraceError, kTraceVoice,
499 VoEId(_shared->instance_id(), -1),
500 "StartRecordingMicrophone() failed to initialize recording");
niklase@google.com470e71d2011-07-07 08:21:25 +0000501 return -1;
502 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000503 if (_shared->audio_device()->StartRecording() != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000504 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000505 WEBRTC_TRACE(kTraceError, kTraceVoice,
506 VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000507 "StartRecordingMicrophone() failed to start recording");
508 return -1;
509 }
510 }
511 return 0;
512}
513
514int VoEFileImpl::StartRecordingMicrophone(
515 OutStream* stream, CodecInst* compression)
516{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000517 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000518 "StartRecordingMicrophone(stream, compression)");
519
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000520 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000521 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000522 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000523 return -1;
524 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000525 if (_shared->transmit_mixer()->StartRecordingMicrophone(stream,
526 compression) == -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000527 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000528 WEBRTC_TRACE(kTraceError, kTraceVoice,
529 VoEId(_shared->instance_id(), -1),
530 "StartRecordingMicrophone() failed to start recording");
niklase@google.com470e71d2011-07-07 08:21:25 +0000531 return -1;
532 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000533 if (_shared->audio_device()->Recording())
niklase@google.com470e71d2011-07-07 08:21:25 +0000534 {
535 return 0;
536 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000537 if (!_shared->ext_recording())
niklase@google.com470e71d2011-07-07 08:21:25 +0000538 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000539 if (_shared->audio_device()->InitRecording() != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000540 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000541 WEBRTC_TRACE(kTraceError, kTraceVoice,
542 VoEId(_shared->instance_id(), -1),
543 "StartRecordingMicrophone() failed to initialize recording");
niklase@google.com470e71d2011-07-07 08:21:25 +0000544 return -1;
545 }
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000546 if (_shared->audio_device()->StartRecording() != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000547 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000548 WEBRTC_TRACE(kTraceError, kTraceVoice,
549 VoEId(_shared->instance_id(), -1),
550 "StartRecordingMicrophone() failed to start recording");
niklase@google.com470e71d2011-07-07 08:21:25 +0000551 return -1;
552 }
553 }
554 return 0;
555}
556
557int VoEFileImpl::StopRecordingMicrophone()
558{
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000559 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
niklase@google.com470e71d2011-07-07 08:21:25 +0000560 "StopRecordingMicrophone()");
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000561 if (!_shared->statistics().Initialized())
niklase@google.com470e71d2011-07-07 08:21:25 +0000562 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000563 _shared->SetLastError(VE_NOT_INITED, kTraceError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000564 return -1;
565 }
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000566
567 int err = 0;
568
569 // TODO(xians): consider removing Start/StopRecording() in
570 // Start/StopRecordingMicrophone() if no channel is recording.
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000571 if (_shared->NumOfSendingChannels() == 0 &&
572 _shared->audio_device()->Recording())
niklase@google.com470e71d2011-07-07 08:21:25 +0000573 {
574 // Stop audio-device recording if no channel is recording
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000575 if (_shared->audio_device()->StopRecording() != 0)
niklase@google.com470e71d2011-07-07 08:21:25 +0000576 {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000577 _shared->SetLastError(VE_CANNOT_STOP_RECORDING, kTraceError,
niklase@google.com470e71d2011-07-07 08:21:25 +0000578 "StopRecordingMicrophone() failed to stop recording");
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000579 err = -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000580 }
581 }
braveyao@webrtc.org4de777b2012-06-15 02:37:53 +0000582
583 if (_shared->transmit_mixer()->StopRecordingMicrophone() != 0)
584 {
585 WEBRTC_TRACE(kTraceError, kTraceVoice,
586 VoEId(_shared->instance_id(), -1),
587 "StopRecordingMicrophone() failed to stop recording to mixer");
588 err = -1;
589 }
590
591 return err;
niklase@google.com470e71d2011-07-07 08:21:25 +0000592}
593
niklase@google.com470e71d2011-07-07 08:21:25 +0000594#endif // #ifdef WEBRTC_VOICE_ENGINE_FILE_API
andrew@webrtc.orgeeaf3d12012-01-24 06:30:02 +0000595
596} // namespace webrtc