| 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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" | |
| 13 #include "base/time.h" | 12 #include "base/time.h" |
| 14 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 15 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
| 16 #include "media/audio/audio_output_dispatcher.h" | 15 #include "media/audio/audio_output_dispatcher.h" |
| 17 #include "media/audio/audio_parameters.h" | 16 #include "media/audio/audio_parameters.h" |
| 18 | 17 |
| 19 namespace media { | 18 namespace media { |
| 20 | 19 |
| 21 class OnMoreDataResampler; | 20 class OnMoreDataResampler; |
| 22 | 21 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to | 35 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to |
| 37 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output | 36 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output |
| 38 // parameters. | 37 // parameters. |
| 39 // TODO(dalecurtis): Ideally the low latency path will be as reliable as the | 38 // TODO(dalecurtis): Ideally the low latency path will be as reliable as the |
| 40 // high latency path once we have channel mixing and support querying for the | 39 // high latency path once we have channel mixing and support querying for the |
| 41 // hardware's configured bit depth. Monitor the UMA stats for fallback and | 40 // hardware's configured bit depth. Monitor the UMA stats for fallback and |
| 42 // remove fallback support once it's stable. http://crbug.com/148418 | 41 // remove fallback support once it's stable. http://crbug.com/148418 |
| 43 // | 42 // |
| 44 // Currently channel downmixing and upmixing is not supported. | 43 // Currently channel downmixing and upmixing is not supported. |
| 45 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 | 44 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762 |
| 46 class MEDIA_EXPORT AudioOutputResampler | 45 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { |
| 47 : public AudioOutputDispatcher { | |
| 48 public: | 46 public: |
| 49 AudioOutputResampler(AudioManager* audio_manager, | 47 AudioOutputResampler(AudioManager* audio_manager, |
| 50 const AudioParameters& input_params, | 48 const AudioParameters& input_params, |
| 51 const AudioParameters& output_params, | 49 const AudioParameters& output_params, |
| 52 const base::TimeDelta& close_delay); | 50 const base::TimeDelta& close_delay); |
| 53 | 51 |
| 54 // AudioOutputDispatcher interface. | 52 // AudioOutputDispatcher interface. |
| 55 virtual bool OpenStream() OVERRIDE; | 53 virtual bool OpenStream() OVERRIDE; |
| 56 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | 54 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback, |
| 57 AudioOutputProxy* stream_proxy) OVERRIDE; | 55 AudioOutputProxy* stream_proxy) OVERRIDE; |
| 58 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE; | 56 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE; |
| 59 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy, | 57 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy, |
| 60 double volume) OVERRIDE; | 58 double volume) OVERRIDE; |
| 61 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE; | 59 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE; |
| 62 virtual void Shutdown() OVERRIDE; | 60 virtual void Shutdown() OVERRIDE; |
| 63 | 61 |
| 64 private: | 62 private: |
| 65 friend class base::RefCountedThreadSafe<AudioOutputResampler>; | 63 friend class base::RefCountedThreadSafe<AudioOutputResampler>; |
| 66 virtual ~AudioOutputResampler(); | 64 virtual ~AudioOutputResampler(); |
| 67 | 65 |
| 68 // Used to initialize the FIFO and resamplers. | 66 // Used to initialize the FIFO and resamplers. |
| 69 void Initialize(); | 67 void Initialize(); |
| 70 | 68 |
| 71 // Dispatcher to proxy all AudioOutputDispatcher calls too. | 69 // Dispatcher to proxy all AudioOutputDispatcher calls too. |
| 72 scoped_refptr<AudioOutputDispatcher> dispatcher_; | 70 scoped_refptr<AudioOutputDispatcher> dispatcher_; |
| 73 | 71 |
| 74 // Vector of each outstanding OnMoreDataResampler object. A new instance is | 72 // Map of outstanding OnMoreDataResampler objects. A new object is created |
| 75 // created on every StartStream() call. Access must be locked. | 73 // on every StartStream() call and destroyed on CloseStream(). |
| 76 typedef std::map<AudioOutputProxy*, OnMoreDataResampler*> CallbackMap; | 74 typedef std::map<AudioOutputProxy*, OnMoreDataResampler*> CallbackMap; |
| 77 CallbackMap callbacks_; | 75 CallbackMap callbacks_; |
| 78 base::Lock callbacks_lock_; | |
| 79 | 76 |
| 80 // Ratio of input bytes to output bytes used to correct playback delay with | 77 // Ratio of input bytes to output bytes used to correct playback delay with |
| 81 // regard to buffering and resampling. | 78 // regard to buffering and resampling. |
| 82 double io_ratio_; | 79 double io_ratio_; |
| 83 | 80 |
| 84 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. | 81 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. |
| 85 base::TimeDelta close_delay_; | 82 base::TimeDelta close_delay_; |
| 86 | 83 |
| 87 // AudioParameters used to setup the output stream. | 84 // AudioParameters used to setup the output stream. |
| 88 AudioParameters output_params_; | 85 AudioParameters output_params_; |
| 89 | 86 |
| 87 // Whether any streams have been opened through |dispatcher_|, if so we can't |
| 88 // fallback on future OpenStream() failures. |
| 89 bool streams_opened_; |
| 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); | 91 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace media | 94 } // namespace media |
| 94 | 95 |
| 95 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | 96 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ |
| OLD | NEW |