| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_AUDIO_MAC_AUDIO_OUTPUT_MAC_H_ | 5 #ifndef MEDIA_AUDIO_MAC_AUDIO_OUTPUT_MAC_H_ |
| 6 #define MEDIA_AUDIO_MAC_AUDIO_OUTPUT_MAC_H_ | 6 #define MEDIA_AUDIO_MAC_AUDIO_OUTPUT_MAC_H_ |
| 7 | 7 |
| 8 #include <AudioToolbox/AudioFormat.h> | 8 #include <AudioToolbox/AudioFormat.h> |
| 9 #include <AudioToolbox/AudioQueue.h> | 9 #include <AudioToolbox/AudioQueue.h> |
| 10 | 10 |
| 11 #include "media/audio/audio_io.h" | 11 #include "media/audio/audio_io.h" |
| 12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
| 13 | 13 |
| 14 class AudioManagerMac; | 14 class AudioManagerMac; |
| 15 | 15 |
| 16 // Implementation of AudioOuputStream for Mac OS X using the audio queue service | 16 // Implementation of AudioOuputStream for Mac OS X using the audio queue service |
| 17 // present in OS 10.5 and later. Audioqueue is the successor to the SoundManager | 17 // present in OS 10.5 and later. Audioqueue is the successor to the SoundManager |
| 18 // services but it is supported in 64 bits. | 18 // services but it is supported in 64 bits. |
| 19 class PCMQueueOutAudioOutputStream : public AudioOutputStream { | 19 class PCMQueueOutAudioOutputStream : public AudioOutputStream { |
| 20 public: | 20 public: |
| 21 // The ctor takes all the usual parameters, plus |manager| which is the | 21 // The ctor takes all the usual parameters, plus |manager| which is the |
| 22 // the audio manager who is creating this object. | 22 // the audio manager who is creating this object. |
| 23 PCMQueueOutAudioOutputStream(AudioManagerMac* manager, | 23 PCMQueueOutAudioOutputStream(AudioManagerMac* manager, |
| 24 AudioParameters params); | 24 AudioParameters params); |
| 25 // The dtor is typically called by the AudioManager only and it is usually | 25 // The dtor is typically called by the AudioManager only and it is usually |
| 26 // triggered by calling AudioOutputStream::Close(). | 26 // triggered by calling AudioOutputStream::Close(). |
| 27 virtual ~PCMQueueOutAudioOutputStream(); | 27 virtual ~PCMQueueOutAudioOutputStream(); |
| 28 | 28 |
| 29 // Implementation of AudioOutputStream. | 29 // Implementation of AudioOutputStream. |
| 30 virtual bool Open(uint32 packet_size); | 30 virtual bool Open(); |
| 31 virtual void Close(); | 31 virtual void Close(); |
| 32 virtual void Start(AudioSourceCallback* callback); | 32 virtual void Start(AudioSourceCallback* callback); |
| 33 virtual void Stop(); | 33 virtual void Stop(); |
| 34 virtual void SetVolume(double volume); | 34 virtual void SetVolume(double volume); |
| 35 virtual void GetVolume(double* volume); | 35 virtual void GetVolume(double* volume); |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 // The audio is double buffered. | 38 // The audio is double buffered. |
| 39 static const uint32 kNumBuffers = 2; | 39 static const uint32 kNumBuffers = 2; |
| 40 | 40 |
| 41 // The OS calls back here when an audio buffer has been processed. | 41 // The OS calls back here when an audio buffer has been processed. |
| 42 static void RenderCallback(void* p_this, AudioQueueRef queue, | 42 static void RenderCallback(void* p_this, AudioQueueRef queue, |
| 43 AudioQueueBufferRef buffer); | 43 AudioQueueBufferRef buffer); |
| 44 // Called when an error occurs. | 44 // Called when an error occurs. |
| 45 void HandleError(OSStatus err); | 45 void HandleError(OSStatus err); |
| 46 | 46 |
| 47 // Structure that holds the stream format details such as bitrate. | 47 // Structure that holds the stream format details such as bitrate. |
| 48 AudioStreamBasicDescription format_; | 48 AudioStreamBasicDescription format_; |
| 49 // Handle to the OS audio queue object. | 49 // Handle to the OS audio queue object. |
| 50 AudioQueueRef audio_queue_; | 50 AudioQueueRef audio_queue_; |
| 51 // Array of pointers to the OS managed audio buffers. | 51 // Array of pointers to the OS managed audio buffers. |
| 52 AudioQueueBufferRef buffer_[kNumBuffers]; | 52 AudioQueueBufferRef buffer_[kNumBuffers]; |
| 53 // Pointer to the object that will provide the audio samples. | 53 // Pointer to the object that will provide the audio samples. |
| 54 AudioSourceCallback* source_; | 54 AudioSourceCallback* source_; |
| 55 // Our creator, the audio manager needs to be notified when we close. | 55 // Our creator, the audio manager needs to be notified when we close. |
| 56 AudioManagerMac* manager_; | 56 AudioManagerMac* manager_; |
| 57 // Packet size in bytes. |
| 58 uint32 packet_size_; |
| 57 // Number of bytes for making a silence buffer. | 59 // Number of bytes for making a silence buffer. |
| 58 int silence_bytes_; | 60 int silence_bytes_; |
| 59 // Volume level from 0 to 1. | 61 // Volume level from 0 to 1. |
| 60 float volume_; | 62 float volume_; |
| 61 // Number of bytes yet to be played in audio buffer. | 63 // Number of bytes yet to be played in audio buffer. |
| 62 uint32 pending_bytes_; | 64 uint32 pending_bytes_; |
| 63 | 65 |
| 64 DISALLOW_COPY_AND_ASSIGN(PCMQueueOutAudioOutputStream); | 66 DISALLOW_COPY_AND_ASSIGN(PCMQueueOutAudioOutputStream); |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 #endif // MEDIA_AUDIO_MAC_AUDIO_OUTPUT_MAC_H_ | 69 #endif // MEDIA_AUDIO_MAC_AUDIO_OUTPUT_MAC_H_ |
| OLD | NEW |