| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
| 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 "webrtc/voice_engine/voe_external_media_impl.h" | |
| 12 | |
| 13 #include "webrtc/audio/utility/audio_frame_operations.h" | |
| 14 #include "webrtc/system_wrappers/include/trace.h" | |
| 15 #include "webrtc/voice_engine/channel.h" | |
| 16 #include "webrtc/voice_engine/include/voe_errors.h" | |
| 17 #include "webrtc/voice_engine/output_mixer.h" | |
| 18 #include "webrtc/voice_engine/transmit_mixer.h" | |
| 19 #include "webrtc/voice_engine/voice_engine_impl.h" | |
| 20 | |
| 21 namespace webrtc { | |
| 22 | |
| 23 VoEExternalMedia* VoEExternalMedia::GetInterface(VoiceEngine* voiceEngine) { | |
| 24 if (NULL == voiceEngine) { | |
| 25 return NULL; | |
| 26 } | |
| 27 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); | |
| 28 s->AddRef(); | |
| 29 return s; | |
| 30 } | |
| 31 | |
| 32 VoEExternalMediaImpl::VoEExternalMediaImpl(voe::SharedData* shared) | |
| 33 : | |
| 34 #ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT | |
| 35 playout_delay_ms_(0), | |
| 36 #endif | |
| 37 shared_(shared) { | |
| 38 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(shared_->instance_id(), -1), | |
| 39 "VoEExternalMediaImpl() - ctor"); | |
| 40 } | |
| 41 | |
| 42 VoEExternalMediaImpl::~VoEExternalMediaImpl() { | |
| 43 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(shared_->instance_id(), -1), | |
| 44 "~VoEExternalMediaImpl() - dtor"); | |
| 45 } | |
| 46 | |
| 47 int VoEExternalMediaImpl::RegisterExternalMediaProcessing( | |
| 48 int channel, | |
| 49 ProcessingTypes type, | |
| 50 VoEMediaProcess& processObject) { | |
| 51 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(shared_->instance_id(), -1), | |
| 52 "RegisterExternalMediaProcessing(channel=%d, type=%d, " | |
| 53 "processObject=0x%x)", | |
| 54 channel, type, &processObject); | |
| 55 if (!shared_->statistics().Initialized()) { | |
| 56 shared_->SetLastError(VE_NOT_INITED, kTraceError); | |
| 57 return -1; | |
| 58 } | |
| 59 switch (type) { | |
| 60 case kPlaybackPerChannel: | |
| 61 case kRecordingPerChannel: { | |
| 62 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); | |
| 63 voe::Channel* channelPtr = ch.channel(); | |
| 64 if (channelPtr == NULL) { | |
| 65 shared_->SetLastError( | |
| 66 VE_CHANNEL_NOT_VALID, kTraceError, | |
| 67 "RegisterExternalMediaProcessing() failed to locate " | |
| 68 "channel"); | |
| 69 return -1; | |
| 70 } | |
| 71 return channelPtr->RegisterExternalMediaProcessing(type, processObject); | |
| 72 } | |
| 73 case kPlaybackAllChannelsMixed: { | |
| 74 return shared_->output_mixer()->RegisterExternalMediaProcessing( | |
| 75 processObject); | |
| 76 } | |
| 77 case kRecordingAllChannelsMixed: | |
| 78 case kRecordingPreprocessing: { | |
| 79 return shared_->transmit_mixer()->RegisterExternalMediaProcessing( | |
| 80 &processObject, type); | |
| 81 } | |
| 82 } | |
| 83 return -1; | |
| 84 } | |
| 85 | |
| 86 int VoEExternalMediaImpl::DeRegisterExternalMediaProcessing( | |
| 87 int channel, | |
| 88 ProcessingTypes type) { | |
| 89 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(shared_->instance_id(), -1), | |
| 90 "DeRegisterExternalMediaProcessing(channel=%d)", channel); | |
| 91 if (!shared_->statistics().Initialized()) { | |
| 92 shared_->SetLastError(VE_NOT_INITED, kTraceError); | |
| 93 return -1; | |
| 94 } | |
| 95 switch (type) { | |
| 96 case kPlaybackPerChannel: | |
| 97 case kRecordingPerChannel: { | |
| 98 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); | |
| 99 voe::Channel* channelPtr = ch.channel(); | |
| 100 if (channelPtr == NULL) { | |
| 101 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | |
| 102 "RegisterExternalMediaProcessing() " | |
| 103 "failed to locate channel"); | |
| 104 return -1; | |
| 105 } | |
| 106 return channelPtr->DeRegisterExternalMediaProcessing(type); | |
| 107 } | |
| 108 case kPlaybackAllChannelsMixed: { | |
| 109 return shared_->output_mixer()->DeRegisterExternalMediaProcessing(); | |
| 110 } | |
| 111 case kRecordingAllChannelsMixed: | |
| 112 case kRecordingPreprocessing: { | |
| 113 return shared_->transmit_mixer()->DeRegisterExternalMediaProcessing(type); | |
| 114 } | |
| 115 } | |
| 116 return -1; | |
| 117 } | |
| 118 | |
| 119 int VoEExternalMediaImpl::GetAudioFrame(int channel, int desired_sample_rate_hz, | |
| 120 AudioFrame* frame) { | |
| 121 if (!shared_->statistics().Initialized()) { | |
| 122 shared_->SetLastError(VE_NOT_INITED, kTraceError); | |
| 123 return -1; | |
| 124 } | |
| 125 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); | |
| 126 voe::Channel* channelPtr = ch.channel(); | |
| 127 if (channelPtr == NULL) { | |
| 128 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | |
| 129 "GetAudioFrame() failed to locate channel"); | |
| 130 return -1; | |
| 131 } | |
| 132 if (!channelPtr->ExternalMixing()) { | |
| 133 shared_->SetLastError(VE_INVALID_OPERATION, kTraceError, | |
| 134 "GetAudioFrame() was called on channel that is not" | |
| 135 " externally mixed."); | |
| 136 return -1; | |
| 137 } | |
| 138 if (!channelPtr->Playing()) { | |
| 139 shared_->SetLastError( | |
| 140 VE_INVALID_OPERATION, kTraceError, | |
| 141 "GetAudioFrame() was called on channel that is not playing."); | |
| 142 return -1; | |
| 143 } | |
| 144 if (desired_sample_rate_hz == -1) { | |
| 145 shared_->SetLastError(VE_BAD_ARGUMENT, kTraceError, | |
| 146 "GetAudioFrame() was called with bad sample rate."); | |
| 147 return -1; | |
| 148 } | |
| 149 frame->sample_rate_hz_ = | |
| 150 desired_sample_rate_hz == 0 ? -1 : desired_sample_rate_hz; | |
| 151 auto ret = channelPtr->GetAudioFrameWithMuted(channel, frame); | |
| 152 if (ret == MixerParticipant::AudioFrameInfo::kMuted) { | |
| 153 AudioFrameOperations::Mute(frame); | |
| 154 } | |
| 155 return ret == MixerParticipant::AudioFrameInfo::kError ? -1 : 0; | |
| 156 } | |
| 157 | |
| 158 int VoEExternalMediaImpl::SetExternalMixing(int channel, bool enable) { | |
| 159 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, | |
| 160 VoEId(shared_->instance_id(), channel), | |
| 161 "SetExternalMixing(channel=%d, enable=%d)", channel, enable); | |
| 162 if (!shared_->statistics().Initialized()) { | |
| 163 shared_->SetLastError(VE_NOT_INITED, kTraceError); | |
| 164 return -1; | |
| 165 } | |
| 166 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); | |
| 167 voe::Channel* channelPtr = ch.channel(); | |
| 168 if (channelPtr == NULL) { | |
| 169 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | |
| 170 "SetExternalMixing() failed to locate channel"); | |
| 171 return -1; | |
| 172 } | |
| 173 return channelPtr->SetExternalMixing(enable); | |
| 174 } | |
| 175 | |
| 176 } // namespace webrtc | |
| OLD | NEW |