Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm

Issue 3004053002: Experimental patch for delaying mic permission dialog in AppRTCMobile
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_device_ios.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 VoiceProcessingAudioUnit::~VoiceProcessingAudioUnit() { 79 VoiceProcessingAudioUnit::~VoiceProcessingAudioUnit() {
80 DisposeAudioUnit(); 80 DisposeAudioUnit();
81 } 81 }
82 82
83 const UInt32 VoiceProcessingAudioUnit::kBytesPerSample = 2; 83 const UInt32 VoiceProcessingAudioUnit::kBytesPerSample = 2;
84 84
85 bool VoiceProcessingAudioUnit::Init() { 85 bool VoiceProcessingAudioUnit::Init() {
86 RTC_DCHECK_EQ(state_, kInitRequired); 86 RTC_DCHECK_EQ(state_, kInitRequired);
87 RTCLog(@"Init");
87 88
88 // Create an audio component description to identify the Voice Processing 89 // Create an audio component description to identify the Voice Processing
89 // I/O audio unit. 90 // I/O audio unit.
90 AudioComponentDescription vpio_unit_description; 91 AudioComponentDescription vpio_unit_description;
91 vpio_unit_description.componentType = kAudioUnitType_Output; 92 vpio_unit_description.componentType = kAudioUnitType_Output;
92 vpio_unit_description.componentSubType = kAudioUnitSubType_VoiceProcessingIO; 93 vpio_unit_description.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
93 vpio_unit_description.componentManufacturer = kAudioUnitManufacturer_Apple; 94 vpio_unit_description.componentManufacturer = kAudioUnitManufacturer_Apple;
94 vpio_unit_description.componentFlags = 0; 95 vpio_unit_description.componentFlags = 0;
95 vpio_unit_description.componentFlagsMask = 0; 96 vpio_unit_description.componentFlagsMask = 0;
96 97
97 // Obtain an audio unit instance given the description. 98 // Obtain an audio unit instance given the description.
98 AudioComponent found_vpio_unit_ref = 99 AudioComponent found_vpio_unit_ref =
99 AudioComponentFindNext(nullptr, &vpio_unit_description); 100 AudioComponentFindNext(nullptr, &vpio_unit_description);
100 101
101 // Create a Voice Processing IO audio unit. 102 // Create a Voice Processing IO audio unit.
102 OSStatus result = noErr; 103 OSStatus result = noErr;
103 result = AudioComponentInstanceNew(found_vpio_unit_ref, &vpio_unit_); 104 result = AudioComponentInstanceNew(found_vpio_unit_ref, &vpio_unit_);
104 if (result != noErr) { 105 if (result != noErr) {
105 vpio_unit_ = nullptr; 106 vpio_unit_ = nullptr;
106 RTCLogError(@"AudioComponentInstanceNew failed. Error=%ld.", (long)result); 107 RTCLogError(@"AudioComponentInstanceNew failed. Error=%ld.", (long)result);
107 return false; 108 return false;
108 } 109 }
109 110
110 // Enable input on the input scope of the input element.
111 UInt32 enable_input = 1;
112 result = AudioUnitSetProperty(vpio_unit_, kAudioOutputUnitProperty_EnableIO,
113 kAudioUnitScope_Input, kInputBus, &enable_input,
114 sizeof(enable_input));
115 if (result != noErr) {
116 DisposeAudioUnit();
117 RTCLogError(@"Failed to enable input on input scope of input element. "
118 "Error=%ld.",
119 (long)result);
120 return false;
121 }
122
123 // Enable output on the output scope of the output element. 111 // Enable output on the output scope of the output element.
124 UInt32 enable_output = 1; 112 UInt32 enable_output = 1;
125 result = AudioUnitSetProperty(vpio_unit_, kAudioOutputUnitProperty_EnableIO, 113 result = AudioUnitSetProperty(vpio_unit_, kAudioOutputUnitProperty_EnableIO,
126 kAudioUnitScope_Output, kOutputBus, 114 kAudioUnitScope_Output, kOutputBus,
127 &enable_output, sizeof(enable_output)); 115 &enable_output, sizeof(enable_output));
128 if (result != noErr) { 116 if (result != noErr) {
129 DisposeAudioUnit(); 117 DisposeAudioUnit();
130 RTCLogError(@"Failed to enable output on output scope of output element. " 118 RTCLogError(@"Failed to enable output on output scope of output element. "
131 "Error=%ld.", 119 "Error=%ld.",
132 (long)result); 120 (long)result);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 175
188 VoiceProcessingAudioUnit::State VoiceProcessingAudioUnit::GetState() const { 176 VoiceProcessingAudioUnit::State VoiceProcessingAudioUnit::GetState() const {
189 return state_; 177 return state_;
190 } 178 }
191 179
192 bool VoiceProcessingAudioUnit::Initialize(Float64 sample_rate) { 180 bool VoiceProcessingAudioUnit::Initialize(Float64 sample_rate) {
193 RTC_DCHECK_GE(state_, kUninitialized); 181 RTC_DCHECK_GE(state_, kUninitialized);
194 RTCLog(@"Initializing audio unit with sample rate: %f", sample_rate); 182 RTCLog(@"Initializing audio unit with sample rate: %f", sample_rate);
195 183
196 OSStatus result = noErr; 184 OSStatus result = noErr;
185
186 // Enable input on the input scope of the input element.
187 UInt32 enable_input = 1;
188 result = AudioUnitSetProperty(vpio_unit_, kAudioOutputUnitProperty_EnableIO,
189 kAudioUnitScope_Input, kInputBus, &enable_input,
190 sizeof(enable_input));
191 if (result != noErr) {
192 DisposeAudioUnit();
193 RTCLogError(@"Failed to enable input on input scope of input element. "
194 "Error=%ld.",
195 (long)result);
196 return false;
197 }
198
197 AudioStreamBasicDescription format = GetFormat(sample_rate); 199 AudioStreamBasicDescription format = GetFormat(sample_rate);
198 UInt32 size = sizeof(format); 200 UInt32 size = sizeof(format);
199 #if !defined(NDEBUG) 201 #if !defined(NDEBUG)
200 LogStreamDescription(format); 202 LogStreamDescription(format);
201 #endif 203 #endif
202 204
203 // Set the format on the output scope of the input element/bus. 205 // Set the format on the output scope of the input element/bus.
204 result = 206 result =
205 AudioUnitSetProperty(vpio_unit_, kAudioUnitProperty_StreamFormat, 207 AudioUnitSetProperty(vpio_unit_, kAudioUnitProperty_StreamFormat,
206 kAudioUnitScope_Output, kInputBus, &format, size); 208 kAudioUnitScope_Output, kInputBus, &format, size);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 OSStatus result = AudioComponentInstanceDispose(vpio_unit_); 450 OSStatus result = AudioComponentInstanceDispose(vpio_unit_);
449 if (result != noErr) { 451 if (result != noErr) {
450 RTCLogError(@"AudioComponentInstanceDispose failed. Error=%ld.", 452 RTCLogError(@"AudioComponentInstanceDispose failed. Error=%ld.",
451 (long)result); 453 (long)result);
452 } 454 }
453 vpio_unit_ = nullptr; 455 vpio_unit_ = nullptr;
454 } 456 }
455 } 457 }
456 458
457 } // namespace webrtc 459 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_device_ios.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698