| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_AUDIO_OUTPUT_RESAMPLER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // | 25 // |
| 26 // The FIFO and resampler are only used when necessary. To be clear: | 26 // The FIFO and resampler are only used when necessary. To be clear: |
| 27 // - The resampler is only used if the input and output sample rates differ. | 27 // - The resampler is only used if the input and output sample rates differ. |
| 28 // - The FIFO is only used if the input and output frame sizes differ or if | 28 // - The FIFO is only used if the input and output frame sizes differ or if |
| 29 // the resampler is used. | 29 // the resampler is used. |
| 30 // | 30 // |
| 31 // AOR works by intercepting the AudioSourceCallback provided to StartStream() | 31 // AOR works by intercepting the AudioSourceCallback provided to StartStream() |
| 32 // and redirecting to the appropriate resampling or FIFO callback which passes | 32 // and redirecting to the appropriate resampling or FIFO callback which passes |
| 33 // through to the original callback only when necessary. | 33 // through to the original callback only when necessary. |
| 34 // | 34 // |
| 35 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to |
| 36 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output |
| 37 // parameters. |
| 38 // TODO(dalecurtis): Ideally the low latency path will be as reliable as the |
| 39 // high latency path once we have channel mixing and support querying for the |
| 40 // hardware's configured bit depth. Monitor the UMA stats for fallback and |
| 41 // remove fallback support once it's stable. http://crbug.com/148418 |
| 42 // |
| 35 // Currently channel downmixing and upmixing is not supported. | 43 // Currently channel downmixing and upmixing is not supported. |
| 36 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 | 44 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 |
| 37 class MEDIA_EXPORT AudioOutputResampler | 45 class MEDIA_EXPORT AudioOutputResampler |
| 38 : public AudioOutputDispatcher, | 46 : public AudioOutputDispatcher, |
| 39 public AudioOutputStream::AudioSourceCallback { | 47 public AudioOutputStream::AudioSourceCallback { |
| 40 public: | 48 public: |
| 41 AudioOutputResampler(AudioManager* audio_manager, | 49 AudioOutputResampler(AudioManager* audio_manager, |
| 42 const AudioParameters& input_params, | 50 const AudioParameters& input_params, |
| 43 const AudioParameters& output_params, | 51 const AudioParameters& output_params, |
| 44 const base::TimeDelta& close_delay); | 52 const base::TimeDelta& close_delay); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 virtual int OnMoreIOData(AudioBus* source, | 67 virtual int OnMoreIOData(AudioBus* source, |
| 60 AudioBus* dest, | 68 AudioBus* dest, |
| 61 AudioBuffersState buffers_state) OVERRIDE; | 69 AudioBuffersState buffers_state) OVERRIDE; |
| 62 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; | 70 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; |
| 63 virtual void WaitTillDataReady() OVERRIDE; | 71 virtual void WaitTillDataReady() OVERRIDE; |
| 64 | 72 |
| 65 private: | 73 private: |
| 66 friend class base::RefCountedThreadSafe<AudioOutputResampler>; | 74 friend class base::RefCountedThreadSafe<AudioOutputResampler>; |
| 67 virtual ~AudioOutputResampler(); | 75 virtual ~AudioOutputResampler(); |
| 68 | 76 |
| 77 // Used to initialize the FIFO and resamplers. |
| 78 void Initialize(); |
| 79 |
| 69 // Called by MultiChannelResampler when more data is necessary. | 80 // Called by MultiChannelResampler when more data is necessary. |
| 70 void ProvideInput(AudioBus* audio_bus); | 81 void ProvideInput(AudioBus* audio_bus); |
| 71 | 82 |
| 72 // Called by AudioPullFifo when more data is necessary. Requires | 83 // Called by AudioPullFifo when more data is necessary. Requires |
| 73 // |source_lock_| to have been acquired. | 84 // |source_lock_| to have been acquired. |
| 74 void SourceCallback_Locked(AudioBus* audio_bus); | 85 void SourceCallback_Locked(AudioBus* audio_bus); |
| 75 | 86 |
| 76 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state. | 87 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state. |
| 77 // TODO(dalecurtis): Probably only one of these methods needs to call this, | 88 // TODO(dalecurtis): Probably only one of these methods needs to call this, |
| 78 // the rest should DCHECK()/CHECK() that the values were reset. | 89 // the rest should DCHECK()/CHECK() that the values were reset. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 // Used to buffer data between the client and the output device in cases where | 102 // Used to buffer data between the client and the output device in cases where |
| 92 // the client buffer size is not the same as the output device buffer size. | 103 // the client buffer size is not the same as the output device buffer size. |
| 93 // Bound to SourceCallback_Locked() so must only be used when |source_lock_| | 104 // Bound to SourceCallback_Locked() so must only be used when |source_lock_| |
| 94 // has already been acquired. | 105 // has already been acquired. |
| 95 scoped_ptr<AudioPullFifo> audio_fifo_; | 106 scoped_ptr<AudioPullFifo> audio_fifo_; |
| 96 | 107 |
| 97 // Ratio of input bytes to output bytes used to correct playback delay with | 108 // Ratio of input bytes to output bytes used to correct playback delay with |
| 98 // regard to buffering and resampling. | 109 // regard to buffering and resampling. |
| 99 double io_ratio_; | 110 double io_ratio_; |
| 100 | 111 |
| 101 // Helper values for determining playback delay adjustment. | 112 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. |
| 102 int input_bytes_per_frame_; | 113 base::TimeDelta close_delay_; |
| 103 int output_bytes_per_frame_; | |
| 104 | 114 |
| 105 // Last AudioBuffersState object received via OnMoreData(), used to correct | 115 // Last AudioBuffersState object received via OnMoreData(), used to correct |
| 106 // playback delay by ProvideInput() and passed on to |source_callback_|. | 116 // playback delay by ProvideInput() and passed on to |source_callback_|. |
| 107 AudioBuffersState current_buffers_state_; | 117 AudioBuffersState current_buffers_state_; |
| 108 | 118 |
| 109 // Total number of bytes (in terms of output parameters) stored in resampler | 119 // Total number of bytes (in terms of output parameters) stored in resampler |
| 110 // or FIFO buffers which have not been sent to the audio device. | 120 // or FIFO buffers which have not been sent to the audio device. |
| 111 int outstanding_audio_bytes_; | 121 int outstanding_audio_bytes_; |
| 112 | 122 |
| 123 // AudioParameters used to setup the output stream. |
| 124 AudioParameters output_params_; |
| 125 |
| 113 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); | 126 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); |
| 114 }; | 127 }; |
| 115 | 128 |
| 116 } // namespace media | 129 } // namespace media |
| 117 | 130 |
| 118 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 131 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| OLD | NEW |