OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 #ifndef MEDIA_AUDIO_MAC_AUDIO_UNIFIED_MAC_H_ | |
6 #define MEDIA_AUDIO_MAC_AUDIO_UNIFIED_MAC_H_ | |
7 | |
8 #include <AudioUnit/AudioUnit.h> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "media/audio/audio_io.h" | |
12 #include "media/audio/audio_parameters.h" | |
13 | |
14 namespace media { | |
15 | |
16 class AudioManagerMac; | |
17 | |
18 // Implementation of AudioOuputStream for Mac OS X using the | |
19 // CoreAudio AudioHardware API suitable for low-latency synchronized audio I/O | |
20 // when using devices which support *both* input and output | |
21 // in the same driver. This is the case with professional | |
22 // USB and Firewire devices. | |
23 // | |
24 // Please note that it's required to first get the native sample-rate of the | |
25 // default output device and use that sample-rate when creating this object. | |
26 | |
scherkus (not reviewing)
2012/09/11 12:22:25
nit: remove blank line
Chris Rogers
2012/09/14 19:17:59
Done.
| |
27 class AudioHardwareUnifiedStream : public AudioOutputStream { | |
28 public: | |
29 // The ctor takes all the usual parameters, plus |manager| which is the | |
30 // the audio manager who is creating this object. | |
31 AudioHardwareUnifiedStream(AudioManagerMac* manager, | |
32 const AudioParameters& params); | |
33 // The dtor is typically called by the AudioManager only and it is usually | |
34 // triggered by calling AudioOutputStream::Close(). | |
35 virtual ~AudioHardwareUnifiedStream(); | |
36 | |
37 // Implementation of AudioOutputStream. | |
38 virtual bool Open() OVERRIDE; | |
39 virtual void Close() OVERRIDE; | |
40 virtual void Start(AudioSourceCallback* callback) OVERRIDE; | |
41 virtual void Stop() OVERRIDE; | |
42 virtual void SetVolume(double volume) OVERRIDE; | |
43 virtual void GetVolume(double* volume) OVERRIDE; | |
44 | |
45 int input_channels() const { return input_channels_; } | |
46 int output_channels() const { return output_channels_; } | |
47 | |
48 private: | |
49 OSStatus Render(AudioDeviceID device, | |
50 const AudioTimeStamp* now, | |
51 const AudioBufferList* input_data, | |
52 const AudioTimeStamp* input_time, | |
53 AudioBufferList* output_data, | |
54 const AudioTimeStamp* output_time); | |
55 | |
56 static OSStatus RenderProc(AudioDeviceID device, | |
57 const AudioTimeStamp* now, | |
58 const AudioBufferList* input_data, | |
59 const AudioTimeStamp* input_time, | |
60 AudioBufferList* output_data, | |
61 const AudioTimeStamp* output_time, | |
62 void* user_data); | |
63 | |
64 // Our creator, the audio manager needs to be notified when we close. | |
65 AudioManagerMac* manager_; | |
66 | |
67 // Pointer to the object that will provide the audio samples. | |
68 AudioSourceCallback* source_; | |
69 | |
70 // Structure that holds the stream format details such as bitrate. | |
71 AudioStreamBasicDescription format_; | |
72 | |
73 // Hardware buffer size. | |
74 int number_of_frames_; | |
75 | |
76 // Number of audio channels provided to the client via OnMoreIOData(). | |
77 int client_input_channels_; | |
78 | |
79 // Volume level from 0 to 1. | |
80 float volume_; | |
81 | |
82 // Number of input and output channels queried from the hardware. | |
83 int input_channels_; | |
84 int output_channels_; | |
85 int input_channels_per_frame_; | |
86 int output_channels_per_frame_; | |
87 | |
88 AudioDeviceIOProcID io_proc_id_; | |
89 AudioDeviceID device_; | |
90 bool is_playing_; | |
91 | |
92 // Intermediate buffers used with call to OnMoreIOData(). | |
93 scoped_ptr<AudioBus> input_bus_; | |
94 scoped_ptr<AudioBus> output_bus_; | |
95 | |
96 static int kDefaultInputChannels; | |
scherkus (not reviewing)
2012/09/11 12:22:25
oh whoops -- I mean this can be compilation-unit s
Chris Rogers
2012/09/14 19:17:59
Done.
| |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(AudioHardwareUnifiedStream); | |
99 }; | |
100 | |
101 } // namespace media | |
102 | |
103 #endif // MEDIA_AUDIO_MAC_AUDIO_UNIFIED_MAC_H_ | |
OLD | NEW |