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

Side by Side Diff: media/audio/ios/audio_manager_ios.mm

Issue 10907110: Create iOS Audio Manager implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to reviews Created 8 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 | « media/audio/ios/audio_manager_ios.h ('k') | media/audio/ios/audio_manager_ios_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/ios/audio_manager_ios.h"
6
7 #import <AudioToolbox/AudioToolbox.h>
8
9 #include "base/sys_info.h"
10 #include "media/audio/fake_audio_input_stream.h"
11 #include "media/audio/mac/audio_input_mac.h"
12 #include "media/base/limits.h"
13
14 namespace media {
15
16 enum {
DaleCurtis 2012/09/07 12:55:58 nit: We generally place this all on one line for a
blundell 2012/09/07 13:03:21 Done.
17 kMaxInputChannels = 2,
18 };
19
20 AudioManagerIOS::AudioManagerIOS() {
21 }
22
23 AudioManagerIOS::~AudioManagerIOS() {
24 Shutdown();
25 }
26
27 bool AudioManagerIOS::HasAudioOutputDevices() {
28 return false;
29 }
30
31 bool AudioManagerIOS::HasAudioInputDevices() {
32 if (!InitAudioSession())
33 return false;
34 // Note that the |kAudioSessionProperty_AudioInputAvailable| property is a
35 // 32-bit integer, not a boolean (http://developer.apple.com/library/ios/#docu mentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/referen ce.html).
stuartmorgan 2012/09/07 12:47:34 Remove this link; Apple's docs are notorious for c
blundell 2012/09/07 12:53:06 Done.
36 UInt32 property_size;
37 OSStatus error =
38 AudioSessionGetPropertySize(kAudioSessionProperty_AudioInputAvailable,
39 &property_size);
40 if (error != kAudioSessionNoError)
41 return false;
42 UInt32 audio_input_is_available = false;
43 DCHECK(property_size == sizeof(audio_input_is_available));
44 error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable,
45 &property_size,
46 &audio_input_is_available);
47 return error == kAudioSessionNoError ? audio_input_is_available : false;
48 }
49
50 AudioOutputStream* AudioManagerIOS::MakeAudioOutputStream(
51 const AudioParameters& params) {
52 NOTIMPLEMENTED(); // Only input is supported on iOS.
53 return NULL;
54 }
55
56 AudioInputStream* AudioManagerIOS::MakeAudioInputStream(
57 const AudioParameters& params, const std::string& device_id) {
58 // Current line of iOS devices has only one audio input.
59 // Ignore the device_id (unittest uses a test value in it).
60 if (!params.IsValid() || (params.channels() > kMaxInputChannels))
61 return NULL;
62
63 if (params.format() == AudioParameters::AUDIO_MOCK)
64 return FakeAudioInputStream::MakeFakeStream(this, params);
65 else if (params.format() == AudioParameters::AUDIO_PCM_LINEAR)
66 return new PCMQueueInAudioInputStream(this, params);
67 return NULL;
68 }
69
70 AudioOutputStream* AudioManagerIOS::MakeLinearOutputStream(
71 const AudioParameters& params) {
72 NOTIMPLEMENTED(); // Only input is supported on iOS.
73 return NULL;
74 }
75
76 AudioOutputStream* AudioManagerIOS::MakeLowLatencyOutputStream(
77 const AudioParameters& params) {
78 NOTIMPLEMENTED(); // Only input is supported on iOS.
79 return NULL;
80 }
81
82 AudioInputStream* AudioManagerIOS::MakeLinearInputStream(
83 const AudioParameters& params, const std::string& device_id) {
84 return MakeAudioInputStream(params, device_id);
85 }
86
87 AudioInputStream* AudioManagerIOS::MakeLowLatencyInputStream(
88 const AudioParameters& params, const std::string& device_id) {
89 NOTIMPLEMENTED(); // Only linear audio input is supported on iOS.
90 return MakeAudioInputStream(params, device_id);
91 }
92
93 // Called by the stream when it has been released by calling Close().
94 void AudioManagerIOS::ReleaseOutputStream(AudioOutputStream* stream) {
95 NOTIMPLEMENTED(); // Only input is supported on iOS.
96 }
97
98 // Called by the stream when it has been released by calling Close().
99 void AudioManagerIOS::ReleaseInputStream(AudioInputStream* stream) {
100 delete stream;
101 }
102
103 // Initializes the audio session, returning a bool indicating whether
104 // initialization was successful. Should only be called once.
105 static bool InitAudioSessionInternal() {
DaleCurtis 2012/09/07 12:55:58 nit: static functions at the top of the file.
blundell 2012/09/07 13:03:21 Done.
106 OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL);
107 DCHECK(error != kAudioSessionAlreadyInitialized);
108 return error == kAudioSessionNoError;
109 }
110
111 bool AudioManagerIOS::InitAudioSession() {
112 static const bool kSessionInitialized = InitAudioSessionInternal();
113 return kSessionInitialized;
114 }
115
116 // static
117 AudioManager* CreateAudioManager() {
118 return new AudioManagerIOS();
119 }
120
121 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/ios/audio_manager_ios.h ('k') | media/audio/ios/audio_manager_ios_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698