Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | |
| 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "base/time.h" | |
| 12 #include "media/audio/audio_io.h" | |
| 13 #include "media/audio/audio_manager.h" | |
| 14 #include "media/audio/audio_output_dispatcher.h" | |
| 15 #include "media/audio/audio_parameters.h" | |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 class AudioPullFifo; | |
| 20 class MultiChannelResampler; | |
| 21 | |
| 22 // AudioOutputResampler is a browser-side resampling and rebuffering solution | |
| 23 // which ensures audio data is always output at given parameters. | |
|
henrika (OOO until Aug 14)
2012/09/10 12:41:17
No restrictions what so ever?
scherkus (not reviewing)
2012/09/10 12:47:47
might be worth having a little ascii diagram to sh
DaleCurtis
2012/09/10 14:05:51
Done.
DaleCurtis
2012/09/10 14:05:51
Just channel mixing. Added a comment.
| |
| 24 class MEDIA_EXPORT AudioOutputResampler | |
| 25 : public AudioOutputDispatcher, | |
| 26 public AudioOutputStream::AudioSourceCallback { | |
| 27 public: | |
| 28 AudioOutputResampler(AudioManager* audio_manager, | |
| 29 const AudioParameters& input_params, | |
| 30 const AudioParameters& output_params, | |
| 31 const base::TimeDelta& close_delay); | |
| 32 | |
| 33 // AudioOutputDispatcher interface. | |
| 34 virtual bool OpenStream() OVERRIDE; | |
| 35 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback, | |
| 36 AudioOutputProxy* stream_proxy) OVERRIDE; | |
| 37 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE; | |
| 38 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy, | |
| 39 double volume) OVERRIDE; | |
| 40 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE; | |
| 41 virtual void Shutdown() OVERRIDE; | |
| 42 | |
| 43 // AudioSourceCallback interface. | |
| 44 virtual int OnMoreData(AudioBus* audio_bus, | |
| 45 AudioBuffersState buffers_state) OVERRIDE; | |
| 46 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; | |
| 47 virtual void WaitTillDataReady() OVERRIDE; | |
| 48 | |
| 49 private: | |
| 50 friend class base::RefCountedThreadSafe<AudioOutputResampler>; | |
| 51 virtual ~AudioOutputResampler(); | |
| 52 | |
| 53 // Called by MultiChannelResampler when more data is necessary. | |
| 54 void ProvideInput(AudioBus* audio_bus); | |
| 55 | |
| 56 // Called by AudioPullFifo when more data is necessary. | |
| 57 void SourceCallback(AudioBus* audio_bus); | |
| 58 | |
| 59 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state. | |
| 60 // TODO(dalecurtis): Probably only one of these methods needs to call this, | |
| 61 // the rest should DCHECK()/CHECK() that the values were reset. | |
| 62 void Reset(); | |
| 63 | |
| 64 // Handles resampling. | |
| 65 scoped_ptr<MultiChannelResampler> resampler_; | |
| 66 | |
| 67 // Dispatcher to proxy all AudioOutputDispatcher calls too. | |
| 68 scoped_refptr<AudioOutputDispatcher> dispatcher_; | |
| 69 | |
| 70 // Source callback and associated lock. | |
| 71 base::Lock source_lock_; | |
| 72 AudioOutputStream::AudioSourceCallback* source_callback_; | |
| 73 | |
| 74 // Used to buffer data between the client and the output device in cases where | |
| 75 // the client buffer size is not the same as the output device buffer size. | |
| 76 scoped_ptr<AudioPullFifo> audio_fifo_; | |
| 77 | |
| 78 // Ratio of input bytes to output bytes used to correct playback delay with | |
| 79 // regard to buffering and resampling. | |
| 80 double io_ratio_; | |
| 81 | |
| 82 // Helper values for determining playback delay adjustment. | |
| 83 int input_bytes_per_frame_; | |
| 84 int output_bytes_per_frame_; | |
| 85 | |
| 86 // Last AudioBuffersState object received via OnMoreData(), used to correct | |
| 87 // playback delay by ProvideInput() and passed on to |source_callback_|. | |
| 88 AudioBuffersState current_buffers_state_; | |
| 89 | |
| 90 // Total number of bytes (in terms of output parameters) stored in resampler | |
| 91 // or FIFO buffers which have not been sent to the audio device. | |
| 92 int outstanding_audio_bytes_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); | |
| 95 }; | |
| 96 | |
| 97 } // namespace media | |
| 98 | |
| 99 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ | |
| OLD | NEW |