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 <CoreAudio/CoreAudio.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 AudioOutputStream for Mac OS X using the | |
19 // CoreAudio AudioHardware API suitable for low-latency unified 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 class AudioHardwareUnifiedStream : public AudioOutputStream { | |
27 public: | |
28 // The ctor takes all the usual parameters, plus |manager| which is the | |
29 // the audio manager who is creating this object. | |
30 AudioHardwareUnifiedStream(AudioManagerMac* manager, | |
31 const AudioParameters& params); | |
32 // The dtor is typically called by the AudioManager only and it is usually | |
33 // triggered by calling AudioOutputStream::Close(). | |
34 virtual ~AudioHardwareUnifiedStream(); | |
35 | |
36 // Implementation of AudioOutputStream. | |
37 virtual bool Open() OVERRIDE; | |
38 virtual void Close() OVERRIDE; | |
39 virtual void Start(AudioSourceCallback* callback) OVERRIDE; | |
40 virtual void Stop() OVERRIDE; | |
41 virtual void SetVolume(double volume) OVERRIDE; | |
42 virtual void GetVolume(double* volume) OVERRIDE; | |
43 | |
44 int input_channels() const { return input_channels_; } | |
45 int output_channels() const { return output_channels_; } | |
46 | |
47 private: | |
48 OSStatus Render(AudioDeviceID device, | |
49 const AudioTimeStamp* now, | |
50 const AudioBufferList* input_data, | |
51 const AudioTimeStamp* input_time, | |
52 AudioBufferList* output_data, | |
53 const AudioTimeStamp* output_time); | |
54 | |
55 static OSStatus RenderProc(AudioDeviceID device, | |
56 const AudioTimeStamp* now, | |
57 const AudioBufferList* input_data, | |
58 const AudioTimeStamp* input_time, | |
59 AudioBufferList* output_data, | |
60 const AudioTimeStamp* output_time, | |
61 void* user_data); | |
62 | |
63 // Our creator, the audio manager needs to be notified when we close. | |
64 AudioManagerMac* manager_; | |
65 | |
66 // Pointer to the object that will provide the audio samples. | |
67 AudioSourceCallback* source_; | |
68 | |
69 // Structure that holds the stream format details such as bitrate. | |
70 AudioStreamBasicDescription format_; | |
71 | |
72 // Hardware buffer size. | |
73 int number_of_frames_; | |
74 | |
75 // Number of audio channels provided to the client via OnMoreIOData(). | |
76 int client_input_channels_; | |
77 | |
78 // Volume level from 0 to 1. | |
79 float volume_; | |
80 | |
81 // Number of input and output channels queried from the hardware. | |
82 int input_channels_; | |
83 int output_channels_; | |
84 int input_channels_per_frame_; | |
85 int output_channels_per_frame_; | |
86 | |
87 AudioDeviceIOProcID io_proc_id_; | |
88 AudioDeviceID device_; | |
89 bool is_playing_; | |
90 | |
91 // Intermediate buffers used with call to OnMoreIOData(). | |
92 scoped_ptr<AudioBus> input_bus_; | |
93 scoped_ptr<AudioBus> output_bus_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(AudioHardwareUnifiedStream); | |
96 }; | |
97 | |
98 } // namespace media | |
99 | |
100 #endif // MEDIA_AUDIO_MAC_AUDIO_UNIFIED_MAC_H_ | |
OLD | NEW |