Mailbox support for texture layers.
[chromium-blink-merge.git] / media / audio / mac / audio_input_mac.h
blob1f9856f18c182593d2ba8bdf8eb0a8d8c8559de2
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.
5 #ifndef MEDIA_AUDIO_MAC_AUDIO_INPUT_MAC_H_
6 #define MEDIA_AUDIO_MAC_AUDIO_INPUT_MAC_H_
8 #include <AudioToolbox/AudioQueue.h>
9 #include <AudioToolbox/AudioFormat.h>
11 #include "base/compiler_specific.h"
12 #include "base/time.h"
13 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_parameters.h"
16 namespace media {
18 class AudioManagerBase;
20 // Implementation of AudioInputStream for Mac OS X using the audio queue service
21 // present in OS 10.5 and later. Design reflects PCMQueueOutAudioOutputStream.
22 class PCMQueueInAudioInputStream : public AudioInputStream {
23 public:
24 // Parameters as per AudioManager::MakeAudioInputStream.
25 PCMQueueInAudioInputStream(AudioManagerBase* manager,
26 const AudioParameters& params);
27 virtual ~PCMQueueInAudioInputStream();
29 // Implementation of AudioInputStream.
30 virtual bool Open() OVERRIDE;
31 virtual void Start(AudioInputCallback* callback) OVERRIDE;
32 virtual void Stop() OVERRIDE;
33 virtual void Close() OVERRIDE;
34 virtual double GetMaxVolume() OVERRIDE;
35 virtual void SetVolume(double volume) OVERRIDE;
36 virtual double GetVolume() OVERRIDE;
37 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
38 virtual bool GetAutomaticGainControl() OVERRIDE;
40 private:
41 // Issue the OnError to |callback_|;
42 void HandleError(OSStatus err);
44 // Allocates and prepares the memory that will be used for recording.
45 bool SetupBuffers();
47 // Sends a buffer to the audio driver for recording.
48 OSStatus QueueNextBuffer(AudioQueueBufferRef audio_buffer);
50 // Callback from OS, delegates to non-static version below.
51 static void HandleInputBufferStatic(
52 void* data,
53 AudioQueueRef audio_queue,
54 AudioQueueBufferRef audio_buffer,
55 const AudioTimeStamp* start_time,
56 UInt32 num_packets,
57 const AudioStreamPacketDescription* desc);
59 // Handles callback from OS. Will be called on OS internal thread.
60 void HandleInputBuffer(AudioQueueRef audio_queue,
61 AudioQueueBufferRef audio_buffer,
62 const AudioTimeStamp* start_time,
63 UInt32 num_packets,
64 const AudioStreamPacketDescription* packet_desc);
66 static const int kNumberBuffers = 3;
68 // Manager that owns this stream, used for closing down.
69 AudioManagerBase* manager_;
70 // We use the callback mostly to periodically supply the recorded audio data.
71 AudioInputCallback* callback_;
72 // Structure that holds the stream format details such as bitrate.
73 AudioStreamBasicDescription format_;
74 // Handle to the OS audio queue object.
75 AudioQueueRef audio_queue_;
76 // Size of each of the buffers in |audio_buffers_|
77 uint32 buffer_size_bytes_;
78 // True iff Start() has been called successfully.
79 bool started_;
80 // Used to determine if we need to slow down |callback_| calls.
81 base::Time last_fill_;
83 DISALLOW_COPY_AND_ASSIGN(PCMQueueInAudioInputStream);
86 } // namespace media
88 #endif // MEDIA_AUDIO_MAC_AUDIO_INPUT_MAC_H_