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 | |
| 11 | #include "voe_file_impl.h" |
| 12 | |
| 13 | #include "channel.h" |
| 14 | #include "critical_section_wrapper.h" |
| 15 | #include "file_wrapper.h" |
| 16 | #include "media_file.h" |
| 17 | #include "output_mixer.h" |
| 18 | #include "trace.h" |
| 19 | #include "transmit_mixer.h" |
| 20 | #include "voe_errors.h" |
| 21 | #include "voice_engine_impl.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | VoEFile* 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.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 34 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 35 | s->AddRef(); |
| 36 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | #endif |
| 38 | } |
| 39 | |
| 40 | #ifdef WEBRTC_VOICE_ENGINE_FILE_API |
| 41 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 42 | VoEFileImpl::VoEFileImpl(voe::SharedData* shared) : _shared(shared) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 44 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | "VoEFileImpl::VoEFileImpl() - ctor"); |
| 46 | } |
| 47 | |
| 48 | VoEFileImpl::~VoEFileImpl() |
| 49 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 50 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | "VoEFileImpl::~VoEFileImpl() - dtor"); |
| 52 | } |
| 53 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | int 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.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 62 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | "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.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 69 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 71 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | return -1; |
| 73 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 74 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 76 | if (channelPtr == NULL) |
| 77 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 78 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | "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 | |
| 92 | int VoEFileImpl::StartPlayingFileLocally(int channel, |
| 93 | InStream* stream, |
| 94 | FileFormats format, |
| 95 | float volumeScaling, |
| 96 | int startPointMs, |
| 97 | int stopPointMs) |
| 98 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 99 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | "StartPlayingFileLocally(channel=%d, stream, format=%d, " |
| 101 | "volumeScaling=%5.3f, startPointMs=%d, stopPointMs=%d)", |
| 102 | channel, format, volumeScaling, startPointMs, stopPointMs); |
| 103 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 104 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 106 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | return -1; |
| 108 | } |
| 109 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 110 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 112 | if (channelPtr == NULL) |
| 113 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 114 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | "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 | |
| 127 | int VoEFileImpl::StopPlayingFileLocally(int channel) |
| 128 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 129 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | "StopPlayingFileLocally()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 131 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 133 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | return -1; |
| 135 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 136 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 138 | if (channelPtr == NULL) |
| 139 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 140 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | "StopPlayingFileLocally() failed to locate channel"); |
| 142 | return -1; |
| 143 | } |
| 144 | return channelPtr->StopPlayingFileLocally(); |
| 145 | } |
| 146 | |
| 147 | int VoEFileImpl::IsPlayingFileLocally(int channel) |
| 148 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 149 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | "IsPlayingFileLocally(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 151 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 153 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | return -1; |
| 155 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 156 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 158 | if (channelPtr == NULL) |
| 159 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 160 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | "StopPlayingFileLocally() failed to locate channel"); |
| 162 | return -1; |
| 163 | } |
| 164 | return channelPtr->IsPlayingFileLocally(); |
| 165 | } |
| 166 | |
| 167 | int VoEFileImpl::ScaleLocalFilePlayout(int channel, float scale) |
| 168 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 169 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 170 | "ScaleLocalFilePlayout(channel=%d, scale=%5.3f)", |
| 171 | channel, scale); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 172 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 174 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | return -1; |
| 176 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 177 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 179 | if (channelPtr == NULL) |
| 180 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 181 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | "StopPlayingFileLocally() failed to locate channel"); |
| 183 | return -1; |
| 184 | } |
| 185 | return channelPtr->ScaleLocalFilePlayout(scale); |
| 186 | } |
| 187 | |
| 188 | int VoEFileImpl::StartPlayingFileAsMicrophone(int channel, |
| 189 | const char fileNameUTF8[1024], |
| 190 | bool loop, |
| 191 | bool mixWithMicrophone, |
| 192 | FileFormats format, |
| 193 | float volumeScaling) |
| 194 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 195 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | "StartPlayingFileAsMicrophone(channel=%d, fileNameUTF8=%s, " |
| 197 | "loop=%d, mixWithMicrophone=%d, format=%d, " |
| 198 | "volumeScaling=%5.3f)", |
| 199 | channel, fileNameUTF8, loop, mixWithMicrophone, format, |
| 200 | volumeScaling); |
| 201 | assert(1024 == FileWrapper::kMaxFileNameSize); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 202 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 204 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | return -1; |
| 206 | } |
| 207 | |
| 208 | const WebRtc_UWord32 startPointMs(0); |
| 209 | const WebRtc_UWord32 stopPointMs(0); |
| 210 | |
| 211 | if (channel == -1) |
| 212 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 213 | int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | fileNameUTF8, |
| 215 | loop, |
| 216 | format, |
| 217 | startPointMs, |
| 218 | volumeScaling, |
| 219 | stopPointMs, |
| 220 | NULL); |
| 221 | if (res) |
| 222 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 223 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 224 | VoEId(_shared->instance_id(), -1), |
| 225 | "StartPlayingFileAsMicrophone() failed to start playing file"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 226 | return(-1); |
| 227 | } |
| 228 | else |
| 229 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 230 | _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | return(0); |
| 232 | } |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | // Add file after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 237 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 238 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 239 | if (channelPtr == NULL) |
| 240 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 241 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | "StartPlayingFileAsMicrophone() failed to locate channel"); |
| 243 | return -1; |
| 244 | } |
| 245 | |
| 246 | int res = channelPtr->StartPlayingFileAsMicrophone(fileNameUTF8, |
| 247 | loop, |
| 248 | format, |
| 249 | startPointMs, |
| 250 | volumeScaling, |
| 251 | stopPointMs, |
| 252 | NULL); |
| 253 | if (res) |
| 254 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 255 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 256 | VoEId(_shared->instance_id(), -1), |
| 257 | "StartPlayingFileAsMicrophone() failed to start playing file"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | return -1; |
| 259 | } |
| 260 | else |
| 261 | { |
| 262 | channelPtr->SetMixWithMicStatus(mixWithMicrophone); |
| 263 | return 0; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | int VoEFileImpl::StartPlayingFileAsMicrophone(int channel, |
| 269 | InStream* stream, |
| 270 | bool mixWithMicrophone, |
| 271 | FileFormats format, |
| 272 | float volumeScaling) |
| 273 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 274 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 275 | "StartPlayingFileAsMicrophone(channel=%d, stream," |
| 276 | " mixWithMicrophone=%d, format=%d, volumeScaling=%5.3f)", |
| 277 | channel, mixWithMicrophone, format, volumeScaling); |
| 278 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 279 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 280 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 281 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 282 | return -1; |
| 283 | } |
| 284 | |
| 285 | const WebRtc_UWord32 startPointMs(0); |
| 286 | const WebRtc_UWord32 stopPointMs(0); |
| 287 | |
| 288 | if (channel == -1) |
| 289 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 290 | int res = _shared->transmit_mixer()->StartPlayingFileAsMicrophone( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 291 | stream, |
| 292 | format, |
| 293 | startPointMs, |
| 294 | volumeScaling, |
| 295 | stopPointMs, |
| 296 | NULL); |
| 297 | if (res) |
| 298 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 299 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 300 | VoEId(_shared->instance_id(), -1), |
| 301 | "StartPlayingFileAsMicrophone() failed to start " |
| 302 | "playing stream"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | return(-1); |
| 304 | } |
| 305 | else |
| 306 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 307 | _shared->transmit_mixer()->SetMixWithMicStatus(mixWithMicrophone); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | return(0); |
| 309 | } |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | // Add file after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 314 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 315 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 316 | if (channelPtr == NULL) |
| 317 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 318 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 319 | "StartPlayingFileAsMicrophone() failed to locate channel"); |
| 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | int res = channelPtr->StartPlayingFileAsMicrophone( |
| 324 | stream, format, startPointMs, volumeScaling, stopPointMs, NULL); |
| 325 | if (res) |
| 326 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 327 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 328 | VoEId(_shared->instance_id(), -1), |
| 329 | "StartPlayingFileAsMicrophone() failed to start " |
| 330 | "playing stream"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 331 | return -1; |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | channelPtr->SetMixWithMicStatus(mixWithMicrophone); |
| 336 | return 0; |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | int VoEFileImpl::StopPlayingFileAsMicrophone(int channel) |
| 342 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 343 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 344 | "StopPlayingFileAsMicrophone(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 345 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 346 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 347 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | return -1; |
| 349 | } |
| 350 | if (channel == -1) |
| 351 | { |
| 352 | // Stop adding file before demultiplexing <=> affects all channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 353 | return _shared->transmit_mixer()->StopPlayingFileAsMicrophone(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | } |
| 355 | else |
| 356 | { |
| 357 | // Stop adding file after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 358 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 359 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 360 | if (channelPtr == NULL) |
| 361 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 362 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 363 | "StopPlayingFileAsMicrophone() failed to locate channel"); |
| 364 | return -1; |
| 365 | } |
| 366 | return channelPtr->StopPlayingFileAsMicrophone(); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | int VoEFileImpl::IsPlayingFileAsMicrophone(int channel) |
| 371 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 372 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | "IsPlayingFileAsMicrophone(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 374 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 375 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 376 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 377 | return -1; |
| 378 | } |
| 379 | if (channel == -1) |
| 380 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 381 | return _shared->transmit_mixer()->IsPlayingFileAsMicrophone(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 382 | } |
| 383 | else |
| 384 | { |
| 385 | // Stop adding file after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 386 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 387 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 388 | if (channelPtr == NULL) |
| 389 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 390 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 391 | "IsPlayingFileAsMicrophone() failed to locate channel"); |
| 392 | return -1; |
| 393 | } |
| 394 | return channelPtr->IsPlayingFileAsMicrophone(); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | int VoEFileImpl::ScaleFileAsMicrophonePlayout(int channel, float scale) |
| 399 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 400 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 401 | "ScaleFileAsMicrophonePlayout(channel=%d, scale=%5.3f)", |
| 402 | channel, scale); |
| 403 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 404 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 405 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 406 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 407 | return -1; |
| 408 | } |
| 409 | if (channel == -1) |
| 410 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 411 | return _shared->transmit_mixer()->ScaleFileAsMicrophonePlayout(scale); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 412 | } |
| 413 | else |
| 414 | { |
| 415 | // Stop adding file after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 416 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 417 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 418 | if (channelPtr == NULL) |
| 419 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 420 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | "IsPlayingFileAsMicrophone() failed to locate channel"); |
| 422 | return -1; |
| 423 | } |
| 424 | return channelPtr->ScaleFileAsMicrophonePlayout(scale); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | int VoEFileImpl::StartRecordingPlayout( |
| 429 | int channel, const char* fileNameUTF8, CodecInst* compression, |
| 430 | int maxSizeBytes) |
| 431 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 432 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | "StartRecordingPlayout(channel=%d, fileNameUTF8=%s, " |
| 434 | "compression, maxSizeBytes=%d)", |
| 435 | channel, fileNameUTF8, maxSizeBytes); |
| 436 | assert(1024 == FileWrapper::kMaxFileNameSize); |
| 437 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 438 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 440 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 441 | return -1; |
| 442 | } |
| 443 | if (channel == -1) |
| 444 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 445 | return _shared->output_mixer()->StartRecordingPlayout |
niklas.enbom@webrtc.org | 5398d95 | 2012-03-26 08:11:25 +0000 | [diff] [blame] | 446 | (fileNameUTF8, compression); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 447 | } |
| 448 | else |
| 449 | { |
| 450 | // Add file after demultiplexing <=> affects one channel only |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 451 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 452 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 453 | if (channelPtr == NULL) |
| 454 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 455 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 456 | "StartRecordingPlayout() failed to locate channel"); |
| 457 | return -1; |
| 458 | } |
| 459 | return channelPtr->StartRecordingPlayout(fileNameUTF8, compression); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | int VoEFileImpl::StartRecordingPlayout( |
| 464 | int channel, OutStream* stream, CodecInst* compression) |
| 465 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 466 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 467 | "StartRecordingPlayout(channel=%d, stream, compression)", |
| 468 | channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 469 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 470 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 471 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 472 | return -1; |
| 473 | } |
| 474 | if (channel == -1) |
| 475 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 476 | return _shared->output_mixer()-> |
| 477 | StartRecordingPlayout(stream, compression); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 478 | } |
| 479 | else |
| 480 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 481 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 482 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 483 | if (channelPtr == NULL) |
| 484 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 485 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 486 | "StartRecordingPlayout() failed to locate channel"); |
| 487 | return -1; |
| 488 | } |
| 489 | return channelPtr->StartRecordingPlayout(stream, compression); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | int VoEFileImpl::StopRecordingPlayout(int channel) |
| 494 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 495 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 496 | "StopRecordingPlayout(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 497 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 498 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 499 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 500 | return -1; |
| 501 | } |
| 502 | if (channel == -1) |
| 503 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 504 | return _shared->output_mixer()->StopRecordingPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 505 | } |
| 506 | else |
| 507 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 508 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 509 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 510 | if (channelPtr == NULL) |
| 511 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 512 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 513 | "StopRecordingPlayout() failed to locate channel"); |
| 514 | return -1; |
| 515 | } |
| 516 | return channelPtr->StopRecordingPlayout(); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | int VoEFileImpl::StartRecordingMicrophone( |
| 521 | const char* fileNameUTF8, CodecInst* compression, int maxSizeBytes) |
| 522 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 523 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 524 | "StartRecordingMicrophone(fileNameUTF8=%s, compression, " |
| 525 | "maxSizeBytes=%d)", fileNameUTF8, maxSizeBytes); |
| 526 | assert(1024 == FileWrapper::kMaxFileNameSize); |
| 527 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 528 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 529 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 530 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 531 | return -1; |
| 532 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 533 | if (_shared->transmit_mixer()->StartRecordingMicrophone(fileNameUTF8, |
| 534 | compression)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 535 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 536 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 537 | VoEId(_shared->instance_id(), -1), |
| 538 | "StartRecordingMicrophone() failed to start recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 539 | return -1; |
| 540 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 541 | if (_shared->audio_device()->Recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 542 | { |
| 543 | return 0; |
| 544 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 545 | if (!_shared->ext_recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 546 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 547 | if (_shared->audio_device()->InitRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 548 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 549 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 550 | VoEId(_shared->instance_id(), -1), |
| 551 | "StartRecordingMicrophone() failed to initialize recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 552 | return -1; |
| 553 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 554 | if (_shared->audio_device()->StartRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 555 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 556 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 557 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 558 | "StartRecordingMicrophone() failed to start recording"); |
| 559 | return -1; |
| 560 | } |
| 561 | } |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | int VoEFileImpl::StartRecordingMicrophone( |
| 566 | OutStream* stream, CodecInst* compression) |
| 567 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 568 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 569 | "StartRecordingMicrophone(stream, compression)"); |
| 570 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 571 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 572 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 573 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 574 | return -1; |
| 575 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 576 | if (_shared->transmit_mixer()->StartRecordingMicrophone(stream, |
| 577 | compression) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 578 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 579 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 580 | VoEId(_shared->instance_id(), -1), |
| 581 | "StartRecordingMicrophone() failed to start recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 582 | return -1; |
| 583 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 584 | if (_shared->audio_device()->Recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 585 | { |
| 586 | return 0; |
| 587 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 588 | if (!_shared->ext_recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 589 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 590 | if (_shared->audio_device()->InitRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 591 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 592 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 593 | VoEId(_shared->instance_id(), -1), |
| 594 | "StartRecordingMicrophone() failed to initialize recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 595 | return -1; |
| 596 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 597 | if (_shared->audio_device()->StartRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 598 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 599 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 600 | VoEId(_shared->instance_id(), -1), |
| 601 | "StartRecordingMicrophone() failed to start recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 602 | return -1; |
| 603 | } |
| 604 | } |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | int VoEFileImpl::StopRecordingMicrophone() |
| 609 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 610 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 611 | "StopRecordingMicrophone()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 612 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 613 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 614 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 615 | return -1; |
| 616 | } |
braveyao@webrtc.org | 4de777b | 2012-06-15 02:37:53 +0000 | [diff] [blame] | 617 | |
| 618 | int err = 0; |
| 619 | |
| 620 | // TODO(xians): consider removing Start/StopRecording() in |
| 621 | // Start/StopRecordingMicrophone() if no channel is recording. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 622 | if (_shared->NumOfSendingChannels() == 0 && |
| 623 | _shared->audio_device()->Recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 624 | { |
| 625 | // Stop audio-device recording if no channel is recording |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 626 | if (_shared->audio_device()->StopRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 627 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 628 | _shared->SetLastError(VE_CANNOT_STOP_RECORDING, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 629 | "StopRecordingMicrophone() failed to stop recording"); |
braveyao@webrtc.org | 4de777b | 2012-06-15 02:37:53 +0000 | [diff] [blame] | 630 | err = -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
braveyao@webrtc.org | 4de777b | 2012-06-15 02:37:53 +0000 | [diff] [blame] | 633 | |
| 634 | if (_shared->transmit_mixer()->StopRecordingMicrophone() != 0) |
| 635 | { |
| 636 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 637 | VoEId(_shared->instance_id(), -1), |
| 638 | "StopRecordingMicrophone() failed to stop recording to mixer"); |
| 639 | err = -1; |
| 640 | } |
| 641 | |
| 642 | return err; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 643 | } |
| 644 | |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 645 | // TODO(andrew): a cursory inspection suggests there's a large amount of |
| 646 | // overlap in these convert functions which could be refactored to a helper. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 647 | int VoEFileImpl::ConvertPCMToWAV(const char* fileNameInUTF8, |
| 648 | const char* fileNameOutUTF8) |
| 649 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 650 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 651 | "ConvertPCMToWAV(fileNameInUTF8=%s, fileNameOutUTF8=%s)", |
| 652 | fileNameInUTF8, fileNameOutUTF8); |
| 653 | |
| 654 | // Create file player object |
| 655 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer( |
| 656 | -1, |
| 657 | kFileFormatPcm16kHzFile)); |
| 658 | |
| 659 | int res=playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0, NULL); |
| 660 | if (res) |
| 661 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 662 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 663 | "ConvertPCMToWAV failed to create player object"); |
| 664 | playerObj.StopPlayingFile(); |
| 665 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 666 | return -1; |
| 667 | } |
| 668 | |
| 669 | // Create file recorder object |
| 670 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 671 | -1, kFileFormatWavFile)); |
| 672 | |
| 673 | CodecInst codecInst; |
| 674 | strncpy(codecInst.plname,"L16",32); |
| 675 | codecInst.channels = 1; |
| 676 | codecInst.rate = 256000; |
| 677 | codecInst.plfreq = 16000; |
| 678 | codecInst.pltype = 94; |
| 679 | codecInst.pacsize = 160; |
| 680 | |
| 681 | res = recObj.StartRecordingAudioFile(fileNameOutUTF8,codecInst,0); |
| 682 | if (res) |
| 683 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 684 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 685 | "ConvertPCMToWAV failed to create recorder object"); |
| 686 | playerObj.StopPlayingFile(); |
| 687 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 688 | recObj.StopRecording(); |
| 689 | FileRecorder::DestroyFileRecorder(&recObj); |
| 690 | return -1; |
| 691 | } |
| 692 | |
| 693 | // Run throught the file |
| 694 | AudioFrame audioFrame; |
| 695 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 696 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 697 | const WebRtc_UWord32 frequency = 16000; |
| 698 | |
| 699 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 700 | { |
| 701 | if(decLength!=frequency/100) |
| 702 | { |
| 703 | // This is an OK way to end |
| 704 | break; |
| 705 | } |
| 706 | |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 707 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 708 | (WebRtc_UWord16)decLength, |
| 709 | frequency, AudioFrame::kNormalSpeech, |
| 710 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 711 | |
| 712 | res=recObj.RecordAudioToFile(audioFrame); |
| 713 | if(res) |
| 714 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 715 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 716 | VoEId(_shared->instance_id(), -1), |
| 717 | "ConvertPCMToWAV failed during conversion (write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | playerObj.StopPlayingFile(); |
| 722 | recObj.StopRecording(); |
| 723 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 724 | FileRecorder::DestroyFileRecorder(&recObj); |
| 725 | |
| 726 | return res; |
| 727 | } |
| 728 | |
| 729 | int VoEFileImpl::ConvertPCMToWAV(InStream* streamIn, OutStream* streamOut) |
| 730 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 731 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 732 | "ConvertPCMToWAV(streamIn, streamOut)"); |
| 733 | |
| 734 | if ((streamIn == NULL) || (streamOut == NULL)) |
| 735 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 736 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 737 | VoEId(_shared->instance_id(), -1), "invalid stream handles"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 738 | return (-1); |
| 739 | } |
| 740 | |
| 741 | // Create file player object |
| 742 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(-1, |
| 743 | kFileFormatPcm16kHzFile)); |
| 744 | int res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL); |
| 745 | if (res) |
| 746 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 747 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 748 | "ConvertPCMToWAV failed to create player object"); |
| 749 | playerObj.StopPlayingFile(); |
| 750 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 751 | return -1; |
| 752 | } |
| 753 | |
| 754 | // Create file recorder object |
| 755 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder(-1, |
| 756 | kFileFormatWavFile)); |
| 757 | CodecInst codecInst; |
| 758 | strncpy(codecInst.plname, "L16", 32); |
| 759 | codecInst.channels = 1; |
| 760 | codecInst.rate = 256000; |
| 761 | codecInst.plfreq = 16000; |
| 762 | codecInst.pltype = 94; |
| 763 | codecInst.pacsize = 160; |
| 764 | res = recObj.StartRecordingAudioFile(*streamOut,codecInst,0); |
| 765 | if (res) |
| 766 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 767 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 768 | "ConvertPCMToWAV failed to create recorder object"); |
| 769 | playerObj.StopPlayingFile(); |
| 770 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 771 | recObj.StopRecording(); |
| 772 | FileRecorder::DestroyFileRecorder(&recObj); |
| 773 | return -1; |
| 774 | } |
| 775 | |
| 776 | // Run throught the file |
| 777 | AudioFrame audioFrame; |
| 778 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 779 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 780 | const WebRtc_UWord32 frequency = 16000; |
| 781 | |
| 782 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 783 | { |
| 784 | if(decLength!=frequency/100) |
| 785 | { |
| 786 | // This is an OK way to end |
| 787 | break; |
| 788 | } |
| 789 | |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 790 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 791 | (WebRtc_UWord16)decLength, frequency, |
| 792 | AudioFrame::kNormalSpeech, |
| 793 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 794 | |
| 795 | res=recObj.RecordAudioToFile(audioFrame); |
| 796 | if(res) |
| 797 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 798 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 799 | VoEId(_shared->instance_id(), -1), |
| 800 | "ConvertPCMToWAV failed during conversion (write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | playerObj.StopPlayingFile(); |
| 805 | recObj.StopRecording(); |
| 806 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 807 | FileRecorder::DestroyFileRecorder(&recObj); |
| 808 | |
| 809 | return res; |
| 810 | } |
| 811 | |
| 812 | int VoEFileImpl::ConvertWAVToPCM(const char* fileNameInUTF8, |
| 813 | const char* fileNameOutUTF8) |
| 814 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 815 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 816 | "ConvertWAVToPCM(fileNameInUTF8=%s, fileNameOutUTF8=%s)", |
| 817 | fileNameInUTF8, fileNameOutUTF8); |
| 818 | |
| 819 | // Create file player object |
| 820 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(-1, |
| 821 | kFileFormatWavFile)); |
| 822 | int res = playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0,NULL); |
| 823 | if (res) |
| 824 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 825 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 826 | "ConvertWAVToPCM failed to create player object"); |
| 827 | playerObj.StopPlayingFile(); |
| 828 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 829 | return -1; |
| 830 | } |
| 831 | |
| 832 | // Create file recorder object |
| 833 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 834 | -1, kFileFormatPcm16kHzFile)); |
| 835 | |
| 836 | CodecInst codecInst; |
| 837 | strncpy(codecInst.plname,"L16",32); |
| 838 | codecInst.channels = 1; |
| 839 | codecInst.rate = 256000; |
| 840 | codecInst.plfreq = 16000; |
| 841 | codecInst.pltype = 94; |
| 842 | codecInst.pacsize = 160; |
| 843 | |
| 844 | res = recObj.StartRecordingAudioFile(fileNameOutUTF8,codecInst,0); |
| 845 | if (res) |
| 846 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 847 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 848 | "ConvertWAVToPCM failed to create recorder object"); |
| 849 | playerObj.StopPlayingFile(); |
| 850 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 851 | recObj.StopRecording(); |
| 852 | FileRecorder::DestroyFileRecorder(&recObj); |
| 853 | return -1; |
| 854 | } |
| 855 | |
| 856 | // Run throught the file |
| 857 | AudioFrame audioFrame; |
| 858 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 859 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 860 | const WebRtc_UWord32 frequency = 16000; |
| 861 | |
| 862 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 863 | { |
| 864 | if(decLength!=frequency/100) |
| 865 | { |
| 866 | // This is an OK way to end |
| 867 | break; |
| 868 | } |
| 869 | |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 870 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 871 | (WebRtc_UWord16)decLength, |
| 872 | frequency, AudioFrame::kNormalSpeech, |
| 873 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 874 | |
| 875 | res=recObj.RecordAudioToFile(audioFrame); |
| 876 | if(res) |
| 877 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 878 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 879 | VoEId(_shared->instance_id(), -1), |
| 880 | "ConvertWAVToPCM failed during conversion (write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
| 884 | playerObj.StopPlayingFile(); |
| 885 | recObj.StopRecording(); |
| 886 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 887 | FileRecorder::DestroyFileRecorder(&recObj); |
| 888 | |
| 889 | return res; |
| 890 | } |
| 891 | |
| 892 | int VoEFileImpl::ConvertWAVToPCM(InStream* streamIn, OutStream* streamOut) |
| 893 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 894 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 895 | "ConvertWAVToPCM(streamIn, streamOut)"); |
| 896 | |
| 897 | if ((streamIn == NULL) || (streamOut == NULL)) |
| 898 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 899 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 900 | VoEId(_shared->instance_id(), -1), "invalid stream handles"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 901 | return (-1); |
| 902 | } |
| 903 | |
| 904 | // Create file player object |
| 905 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(-1, |
| 906 | kFileFormatWavFile)); |
| 907 | int res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL); |
| 908 | if (res) |
| 909 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 910 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 911 | "ConvertWAVToPCM failed to create player object"); |
| 912 | playerObj.StopPlayingFile(); |
| 913 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 914 | return -1; |
| 915 | } |
| 916 | |
| 917 | // Create file recorder object |
| 918 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 919 | -1, kFileFormatPcm16kHzFile)); |
| 920 | |
| 921 | CodecInst codecInst; |
| 922 | strncpy(codecInst.plname,"L16",32); |
| 923 | codecInst.channels = 1; |
| 924 | codecInst.rate = 256000; |
| 925 | codecInst.plfreq = 16000; |
| 926 | codecInst.pltype = 94; |
| 927 | codecInst.pacsize = 160; |
| 928 | |
| 929 | res = recObj.StartRecordingAudioFile(*streamOut,codecInst,0); |
| 930 | if (res) |
| 931 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 932 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 933 | "ConvertWAVToPCM failed to create recorder object"); |
| 934 | playerObj.StopPlayingFile(); |
| 935 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 936 | recObj.StopRecording(); |
| 937 | FileRecorder::DestroyFileRecorder(&recObj); |
| 938 | return -1; |
| 939 | } |
| 940 | |
| 941 | // Run throught the file |
| 942 | AudioFrame audioFrame; |
| 943 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 944 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 945 | const WebRtc_UWord32 frequency = 16000; |
| 946 | |
| 947 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 948 | { |
| 949 | if(decLength!=frequency/100) |
| 950 | { |
| 951 | // This is an OK way to end |
| 952 | break; |
| 953 | } |
| 954 | |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 955 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 956 | (WebRtc_UWord16)decLength, frequency, |
| 957 | AudioFrame::kNormalSpeech, |
| 958 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 959 | |
| 960 | res=recObj.RecordAudioToFile(audioFrame); |
| 961 | if(res) |
| 962 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 963 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 964 | VoEId(_shared->instance_id(), -1), |
| 965 | "ConvertWAVToPCM failed during conversion (write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
| 969 | playerObj.StopPlayingFile(); |
| 970 | recObj.StopRecording(); |
| 971 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 972 | FileRecorder::DestroyFileRecorder(&recObj); |
| 973 | |
| 974 | return res; |
| 975 | } |
| 976 | |
| 977 | int VoEFileImpl::ConvertPCMToCompressed(const char* fileNameInUTF8, |
| 978 | const char* fileNameOutUTF8, |
| 979 | CodecInst* compression) |
| 980 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 981 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 982 | "ConvertPCMToCompressed(fileNameInUTF8=%s, fileNameOutUTF8=%s" |
| 983 | ", compression)", fileNameInUTF8, fileNameOutUTF8); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 984 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 985 | " compression: plname=%s, plfreq=%d, pacsize=%d", |
| 986 | compression->plname, compression->plfreq, |
| 987 | compression->pacsize); |
| 988 | |
| 989 | // Create file player object |
| 990 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer( |
| 991 | -1, |
| 992 | kFileFormatPcm16kHzFile)); |
| 993 | int res = playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0, NULL); |
| 994 | if (res) |
| 995 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 996 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 997 | "ConvertPCMToCompressed failed to create player object"); |
| 998 | // Clean up and shutdown the file player |
| 999 | playerObj.StopPlayingFile(); |
| 1000 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1001 | return -1; |
| 1002 | } |
| 1003 | |
| 1004 | // Create file recorder object |
| 1005 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 1006 | -1, |
| 1007 | kFileFormatCompressedFile)); |
| 1008 | res = recObj.StartRecordingAudioFile(fileNameOutUTF8, *compression,0); |
| 1009 | if (res) |
| 1010 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1011 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1012 | "ConvertPCMToCompressed failed to create recorder object"); |
| 1013 | playerObj.StopPlayingFile(); |
| 1014 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1015 | recObj.StopRecording(); |
| 1016 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1017 | return -1; |
| 1018 | } |
| 1019 | |
| 1020 | // Run throught the file |
| 1021 | AudioFrame audioFrame; |
| 1022 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 1023 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1024 | const WebRtc_UWord32 frequency = 16000; |
| 1025 | |
| 1026 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 1027 | { |
| 1028 | if(decLength!=frequency/100) |
| 1029 | { |
| 1030 | // This is an OK way to end |
| 1031 | break; |
| 1032 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 1033 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 1034 | (WebRtc_UWord16)decLength, |
| 1035 | frequency, AudioFrame::kNormalSpeech, |
| 1036 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1037 | |
| 1038 | res=recObj.RecordAudioToFile(audioFrame); |
| 1039 | if(res) |
| 1040 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1041 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1042 | VoEId(_shared->instance_id(), -1), |
| 1043 | "ConvertPCMToCompressed failed during conversion " |
| 1044 | "(write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | playerObj.StopPlayingFile(); |
| 1049 | recObj.StopRecording(); |
| 1050 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1051 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1052 | |
| 1053 | return res; |
| 1054 | } |
| 1055 | |
| 1056 | int VoEFileImpl::ConvertPCMToCompressed(InStream* streamIn, |
| 1057 | OutStream* streamOut, |
| 1058 | CodecInst* compression) |
| 1059 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1060 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1061 | "ConvertPCMToCompressed(streamIn, streamOut, compression)"); |
| 1062 | |
| 1063 | if ((streamIn == NULL) || (streamOut == NULL)) |
| 1064 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1065 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1066 | VoEId(_shared->instance_id(), -1), "invalid stream handles"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1067 | return (-1); |
| 1068 | } |
| 1069 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1070 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1071 | " compression: plname=%s, plfreq=%d, pacsize=%d", |
| 1072 | compression->plname, compression->plfreq, |
| 1073 | compression->pacsize); |
| 1074 | |
| 1075 | // Create file player object |
| 1076 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer( |
| 1077 | -1, kFileFormatPcm16kHzFile)); |
| 1078 | |
| 1079 | int res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL); |
| 1080 | if (res) |
| 1081 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1082 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1083 | "ConvertPCMToCompressed failed to create player object"); |
| 1084 | playerObj.StopPlayingFile(); |
| 1085 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1086 | return -1; |
| 1087 | } |
| 1088 | |
| 1089 | // Create file recorder object |
| 1090 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 1091 | -1, kFileFormatCompressedFile)); |
| 1092 | res = recObj.StartRecordingAudioFile(*streamOut,*compression,0); |
| 1093 | if (res) |
| 1094 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1095 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1096 | "ConvertPCMToCompressed failed to create recorder object"); |
| 1097 | playerObj.StopPlayingFile(); |
| 1098 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1099 | recObj.StopRecording(); |
| 1100 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1101 | return -1; |
| 1102 | } |
| 1103 | |
| 1104 | // Run throught the file |
| 1105 | AudioFrame audioFrame; |
| 1106 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 1107 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1108 | const WebRtc_UWord32 frequency = 16000; |
| 1109 | |
| 1110 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 1111 | { |
| 1112 | if(decLength!=frequency/100) |
| 1113 | { |
| 1114 | // This is an OK way to end |
| 1115 | break; |
| 1116 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 1117 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 1118 | (WebRtc_UWord16)decLength, |
| 1119 | frequency, AudioFrame::kNormalSpeech, |
| 1120 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1121 | |
| 1122 | res=recObj.RecordAudioToFile(audioFrame); |
| 1123 | if(res) |
| 1124 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1125 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1126 | VoEId(_shared->instance_id(), -1), |
| 1127 | "ConvertPCMToCompressed failed during conversion " |
| 1128 | "(write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | playerObj.StopPlayingFile(); |
| 1133 | recObj.StopRecording(); |
| 1134 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1135 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1136 | |
| 1137 | return res; |
| 1138 | } |
| 1139 | |
| 1140 | int VoEFileImpl::ConvertCompressedToPCM(const char* fileNameInUTF8, |
| 1141 | const char* fileNameOutUTF8) |
| 1142 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1143 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1144 | "ConvertCompressedToPCM(fileNameInUTF8=%s," |
| 1145 | " fileNameOutUTF8=%s)", |
| 1146 | fileNameInUTF8, fileNameOutUTF8); |
| 1147 | |
| 1148 | // Create file player object |
| 1149 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer( |
| 1150 | -1, kFileFormatCompressedFile)); |
| 1151 | |
| 1152 | int res = playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0,NULL); |
| 1153 | if (res) |
| 1154 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1155 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1156 | "ConvertCompressedToPCM failed to create player object"); |
| 1157 | playerObj.StopPlayingFile(); |
| 1158 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1159 | return -1; |
| 1160 | } |
| 1161 | |
| 1162 | // Create file recorder object |
| 1163 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 1164 | -1, kFileFormatPcm16kHzFile)); |
| 1165 | |
| 1166 | CodecInst codecInst; |
| 1167 | strncpy(codecInst.plname,"L16",32); |
| 1168 | codecInst.channels = 1; |
| 1169 | codecInst.rate = 256000; |
| 1170 | codecInst.plfreq = 16000; |
| 1171 | codecInst.pltype = 94; |
| 1172 | codecInst.pacsize = 160; |
| 1173 | |
| 1174 | res = recObj.StartRecordingAudioFile(fileNameOutUTF8,codecInst,0); |
| 1175 | if (res) |
| 1176 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1177 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1178 | "ConvertCompressedToPCM failed to create recorder object"); |
| 1179 | playerObj.StopPlayingFile(); |
| 1180 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1181 | recObj.StopRecording(); |
| 1182 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1183 | return -1; |
| 1184 | } |
| 1185 | |
| 1186 | // Run throught the file |
| 1187 | AudioFrame audioFrame; |
| 1188 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 1189 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1190 | const WebRtc_UWord32 frequency = 16000; |
| 1191 | |
| 1192 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 1193 | { |
| 1194 | if(decLength!=frequency/100) |
| 1195 | { |
| 1196 | // This is an OK way to end |
| 1197 | break; |
| 1198 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 1199 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 1200 | (WebRtc_UWord16)decLength, |
| 1201 | frequency, |
| 1202 | AudioFrame::kNormalSpeech, |
| 1203 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1204 | |
| 1205 | res=recObj.RecordAudioToFile(audioFrame); |
| 1206 | if(res) |
| 1207 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1208 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1209 | VoEId(_shared->instance_id(), -1), |
| 1210 | "ConvertCompressedToPCM failed during conversion " |
| 1211 | "(write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | playerObj.StopPlayingFile(); |
| 1216 | recObj.StopRecording(); |
| 1217 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1218 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1219 | |
| 1220 | return res; |
| 1221 | } |
| 1222 | |
| 1223 | int VoEFileImpl::ConvertCompressedToPCM(InStream* streamIn, |
| 1224 | OutStream* streamOut) |
| 1225 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1226 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1227 | "ConvertCompressedToPCM(file, file);"); |
| 1228 | |
| 1229 | if ((streamIn == NULL) || (streamOut == NULL)) |
| 1230 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1231 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1232 | VoEId(_shared->instance_id(), -1), "invalid stream handles"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1233 | return (-1); |
| 1234 | } |
| 1235 | |
| 1236 | // Create file player object |
| 1237 | FilePlayer& playerObj(*FilePlayer::CreateFilePlayer( |
| 1238 | -1, kFileFormatCompressedFile)); |
| 1239 | int res; |
| 1240 | |
| 1241 | res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL); |
| 1242 | if (res) |
| 1243 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1244 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1245 | "ConvertCompressedToPCM failed to create player object"); |
| 1246 | playerObj.StopPlayingFile(); |
| 1247 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1248 | return -1; |
| 1249 | } |
| 1250 | |
| 1251 | // Create file recorder object |
| 1252 | FileRecorder& recObj(*FileRecorder::CreateFileRecorder( |
| 1253 | -1, kFileFormatPcm16kHzFile)); |
| 1254 | |
| 1255 | CodecInst codecInst; |
| 1256 | strncpy(codecInst.plname,"L16",32); |
| 1257 | codecInst.channels = 1; |
| 1258 | codecInst.rate = 256000; |
| 1259 | codecInst.plfreq = 16000; |
| 1260 | codecInst.pltype = 94; |
| 1261 | codecInst.pacsize = 160; |
| 1262 | |
| 1263 | res = recObj.StartRecordingAudioFile(*streamOut,codecInst,0); |
| 1264 | if (res) |
| 1265 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1266 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1267 | "ConvertCompressedToPCM failed to create recorder object"); |
| 1268 | playerObj.StopPlayingFile(); |
| 1269 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1270 | recObj.StopRecording(); |
| 1271 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1272 | return -1; |
| 1273 | } |
| 1274 | |
| 1275 | // Run throught the file |
| 1276 | AudioFrame audioFrame; |
| 1277 | WebRtc_Word16 decodedData[160]; |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 1278 | int decLength=0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1279 | const WebRtc_UWord32 frequency = 16000; |
| 1280 | |
| 1281 | while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency)) |
| 1282 | { |
| 1283 | if(decLength!=frequency/100) |
| 1284 | { |
| 1285 | // This is an OK way to end |
| 1286 | break; |
| 1287 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 1288 | audioFrame.UpdateFrame(-1, 0, decodedData, |
| 1289 | (WebRtc_UWord16)decLength, |
| 1290 | frequency, |
| 1291 | AudioFrame::kNormalSpeech, |
| 1292 | AudioFrame::kVadActive); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1293 | |
| 1294 | res=recObj.RecordAudioToFile(audioFrame); |
| 1295 | if(res) |
| 1296 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1297 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1298 | VoEId(_shared->instance_id(), -1), |
| 1299 | "ConvertCompressedToPCM failed during conversion " |
| 1300 | "(write frame)"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | playerObj.StopPlayingFile(); |
| 1305 | recObj.StopRecording(); |
| 1306 | FilePlayer::DestroyFilePlayer(&playerObj); |
| 1307 | FileRecorder::DestroyFileRecorder(&recObj); |
| 1308 | |
| 1309 | return res; |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | int VoEFileImpl::GetFileDuration(const char* fileNameUTF8, |
| 1314 | int& durationMs, |
| 1315 | FileFormats format) |
| 1316 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1317 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1318 | "GetFileDuration(fileNameUTF8=%s, format=%d)", |
| 1319 | fileNameUTF8, format); |
| 1320 | |
| 1321 | // Create a dummy file module for this |
| 1322 | MediaFile * fileModule=MediaFile::CreateMediaFile(-1); |
| 1323 | |
| 1324 | // Temp container of the right format |
| 1325 | WebRtc_UWord32 duration; |
| 1326 | int res=fileModule->FileDurationMs(fileNameUTF8,duration,format); |
| 1327 | if (res) |
| 1328 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1329 | _shared->SetLastError(VE_BAD_FILE, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1330 | "GetFileDuration() failed measure file duration"); |
| 1331 | return -1; |
| 1332 | } |
| 1333 | durationMs = duration; |
| 1334 | MediaFile::DestroyMediaFile(fileModule); |
| 1335 | fileModule = NULL; |
| 1336 | |
| 1337 | return(res); |
| 1338 | } |
| 1339 | |
| 1340 | int VoEFileImpl::GetPlaybackPosition(int channel, int& positionMs) |
| 1341 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1342 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1343 | "GetPlaybackPosition(channel=%d)", channel); |
| 1344 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1345 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1346 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1347 | if (channelPtr == NULL) |
| 1348 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1349 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1350 | "GetPlaybackPosition() failed to locate channel"); |
| 1351 | return -1; |
| 1352 | } |
| 1353 | return channelPtr->GetLocalPlayoutPosition(positionMs); |
| 1354 | } |
| 1355 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1356 | #endif // #ifdef WEBRTC_VOICE_ENGINE_FILE_API |
andrew@webrtc.org | eeaf3d1 | 2012-01-24 06:30:02 +0000 | [diff] [blame] | 1357 | |
| 1358 | } // namespace webrtc |