OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Implementation notes: |
| 6 // |
| 7 // - It is recommended to first acquire the native sample rate of the default |
| 8 // output device and then use the same rate when creating this object. |
| 9 // Use AUAudioOutputStream::HardwareSampleRate() to retrieve the sample rate. |
| 10 // - Calling Close() also leads to self destruction. |
| 11 // - The latency consists of two parts: 1, hardware latency, which includes |
| 12 // Audio Unit latency, audio device latency and audio stream latency; 2, |
| 13 // the delay between now and the scheduled time stamp that tells when the |
| 14 // data we are providing is going to hit the hardware. |
| 15 // |
5 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_OUTPUT_MAC_H_ | 16 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_OUTPUT_MAC_H_ |
6 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_OUTPUT_MAC_H_ | 17 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_OUTPUT_MAC_H_ |
7 | 18 |
8 #include <AudioUnit/AudioUnit.h> | 19 #include <AudioUnit/AudioUnit.h> |
9 | 20 |
| 21 #include "base/memory/scoped_ptr.h" |
10 #include "media/audio/audio_io.h" | 22 #include "media/audio/audio_io.h" |
11 #include "media/audio/audio_parameters.h" | 23 #include "media/audio/audio_parameters.h" |
12 | 24 |
13 class AudioManagerMac; | 25 class AudioManagerMac; |
14 | 26 |
15 // Implementation of AudioOuputStream for Mac OS X using the | 27 // Implementation of AudioOuputStream for Mac OS X using the |
16 // default output Audio Unit present in OS 10.4 and later. | 28 // default output Audio Unit present in OS 10.4 and later. |
17 // The default output Audio Unit is for low-latency audio I/O. | 29 // The default output Audio Unit is for low-latency audio I/O. |
18 class AUAudioOutputStream : public AudioOutputStream { | 30 class AUAudioOutputStream : public AudioOutputStream { |
19 public: | 31 public: |
(...skipping 17 matching lines...) Expand all Loading... |
37 | 49 |
38 private: | 50 private: |
39 // DefaultOutputUnit callback. | 51 // DefaultOutputUnit callback. |
40 static OSStatus InputProc(void* user_data, | 52 static OSStatus InputProc(void* user_data, |
41 AudioUnitRenderActionFlags* flags, | 53 AudioUnitRenderActionFlags* flags, |
42 const AudioTimeStamp* time_stamp, | 54 const AudioTimeStamp* time_stamp, |
43 UInt32 bus_number, | 55 UInt32 bus_number, |
44 UInt32 number_of_frames, | 56 UInt32 number_of_frames, |
45 AudioBufferList* io_data); | 57 AudioBufferList* io_data); |
46 | 58 |
47 OSStatus Render(UInt32 number_of_frames, AudioBufferList* io_data); | 59 OSStatus Render(UInt32 number_of_frames, AudioBufferList* io_data, |
| 60 const AudioTimeStamp* output_time_stamp); |
48 | 61 |
49 // Sets up the stream format for the default output Audio Unit. | 62 // Sets up the stream format for the default output Audio Unit. |
50 bool Configure(); | 63 bool Configure(); |
51 | 64 |
| 65 // Gets playout device hardware latency. |
| 66 void UpdateHardwareLatency(); |
| 67 |
| 68 // Updates estimated playout latency value. |
| 69 void UpdatePlayoutLatency(const AudioTimeStamp* output_time_stamp); |
| 70 |
52 // Our creator, the audio manager needs to be notified when we close. | 71 // Our creator, the audio manager needs to be notified when we close. |
53 AudioManagerMac* manager_; | 72 AudioManagerMac* manager_; |
54 | 73 |
55 size_t number_of_frames_; | 74 size_t number_of_frames_; |
56 | 75 |
57 // Pointer to the object that will provide the audio samples. | 76 // Pointer to the object that will provide the audio samples. |
58 AudioSourceCallback* source_; | 77 AudioSourceCallback* source_; |
59 | 78 |
60 // Structure that holds the stream format details such as bitrate. | 79 // Structure that holds the stream format details such as bitrate. |
61 AudioStreamBasicDescription format_; | 80 AudioStreamBasicDescription format_; |
62 | 81 |
63 // The default output Audio Unit which talks to the audio hardware. | 82 // The default output Audio Unit which talks to the audio hardware. |
64 AudioUnit output_unit_; | 83 AudioUnit output_unit_; |
65 | 84 |
| 85 // The UID refers to the output audio device. |
| 86 AudioDeviceID output_device_id_; |
| 87 |
66 // Volume level from 0 to 1. | 88 // Volume level from 0 to 1. |
67 float volume_; | 89 float volume_; |
68 | 90 |
| 91 // Playout hardware latency in millisecond, the value is updated when |
| 92 // initiating the output Audio Unit. |
| 93 uint32 hardware_latency_ms_; |
| 94 |
| 95 // Playout estimated latency in millisecond. |
| 96 uint32 playout_latency_ms_; |
| 97 |
69 DISALLOW_COPY_AND_ASSIGN(AUAudioOutputStream); | 98 DISALLOW_COPY_AND_ASSIGN(AUAudioOutputStream); |
70 }; | 99 }; |
71 | 100 |
72 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_OUTPUT_MAC_H_ | 101 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_OUTPUT_MAC_H_ |
OLD | NEW |