niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
niklas.enbom@webrtc.org | 5398d95 | 2012-03-26 08:11:25 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_file_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Henrik Kjellander | 0b9e29c | 2015-11-16 11:12:24 +0100 | [diff] [blame] | 13 | #include "webrtc/modules/media_file/media_file.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 15 | #include "webrtc/system_wrappers/include/trace.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 16 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 24 | VoEFile* VoEFile::GetInterface(VoiceEngine* voiceEngine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | #ifndef WEBRTC_VOICE_ENGINE_FILE_API |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 26 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | #else |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 28 | if (NULL == voiceEngine) { |
| 29 | return NULL; |
| 30 | } |
| 31 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 32 | s->AddRef(); |
| 33 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | #endif |
| 35 | } |
| 36 | |
| 37 | #ifdef WEBRTC_VOICE_ENGINE_FILE_API |
| 38 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 39 | VoEFileImpl::VoEFileImpl(voe::SharedData* shared) : _shared(shared) { |
| 40 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 41 | "VoEFileImpl::VoEFileImpl() - ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 44 | VoEFileImpl::~VoEFileImpl() { |
| 45 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 46 | "VoEFileImpl::~VoEFileImpl() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 49 | int 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 Pinto | 664cdaf | 2015-05-20 11:11:07 +0200 | [diff] [blame] | 62 | static_assert(1024 == FileWrapper::kMaxFileNameSize, ""); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 63 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 75 | return channelPtr->StartPlayingFileLocally(fileNameUTF8, loop, format, |
| 76 | startPointMs, volumeScaling, |
| 77 | stopPointMs, NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | int VoEFileImpl::StartPlayingFileLocally(int channel, |
| 81 | InStream* stream, |
| 82 | FileFormats format, |
| 83 | float volumeScaling, |
| 84 | int startPointMs, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 85 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 91 | if (!_shared->statistics().Initialized()) { |
| 92 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
| 93 | return -1; |
| 94 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 96 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 104 | return channelPtr->StartPlayingFileLocally(stream, format, startPointMs, |
| 105 | volumeScaling, stopPointMs, NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 108 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 125 | int VoEFileImpl::IsPlayingFileLocally(int channel) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 126 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | } |
| 139 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | int VoEFileImpl::StartPlayingFileAsMicrophone(int channel, |
| 141 | const char fileNameUTF8[1024], |
| 142 | bool loop, |
| 143 | bool mixWithMicrophone, |
| 144 | FileFormats format, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 145 | 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 Pinto | 664cdaf | 2015-05-20 11:11:07 +0200 | [diff] [blame] | 152 | static_assert(1024 == FileWrapper::kMaxFileNameSize, ""); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 153 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 185 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 197 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | int VoEFileImpl::StartPlayingFileAsMicrophone(int channel, |
| 201 | InStream* stream, |
| 202 | bool mixWithMicrophone, |
| 203 | FileFormats format, |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 204 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 209 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 210 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 241 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 251 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 252 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 255 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 274 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 275 | return channelPtr->StopPlayingFileAsMicrophone(); |
| 276 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 279 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 298 | return channelPtr->IsPlayingFileAsMicrophone(); |
| 299 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 302 | int 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 Pinto | 664cdaf | 2015-05-20 11:11:07 +0200 | [diff] [blame] | 310 | static_assert(1024 == FileWrapper::kMaxFileNameSize, ""); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 312 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 328 | return channelPtr->StartRecordingPlayout(fileNameUTF8, compression); |
| 329 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 332 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 352 | return channelPtr->StartRecordingPlayout(stream, compression); |
| 353 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 356 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 372 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 373 | return channelPtr->StopRecordingPlayout(); |
| 374 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 377 | int 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 Pinto | 664cdaf | 2015-05-20 11:11:07 +0200 | [diff] [blame] | 384 | static_assert(1024 == FileWrapper::kMaxFileNameSize, ""); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 385 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 386 | 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 | } |
solenberg | e313e02 | 2015-09-08 02:16:04 -0700 | [diff] [blame] | 396 | if (!_shared->audio_device()->Recording()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 397 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 411 | int VoEFileImpl::StartRecordingMicrophone(OutStream* stream, |
| 412 | CodecInst* compression) { |
| 413 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
| 414 | "StartRecordingMicrophone(stream, compression)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 415 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 416 | 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 | } |
solenberg | e313e02 | 2015-09-08 02:16:04 -0700 | [diff] [blame] | 426 | if (!_shared->audio_device()->Recording()) { |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 427 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 441 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 461 | } |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 462 | } |
braveyao@webrtc.org | 4de777b | 2012-06-15 02:37:53 +0000 | [diff] [blame] | 463 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 464 | 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.org | 4de777b | 2012-06-15 02:37:53 +0000 | [diff] [blame] | 469 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 470 | return err; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 471 | } |
| 472 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 473 | #endif // #ifdef WEBRTC_VOICE_ENGINE_FILE_API |
andrew@webrtc.org | eeaf3d1 | 2012-01-24 06:30:02 +0000 | [diff] [blame] | 474 | |
| 475 | } // namespace webrtc |