Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(696)

Side by Side Diff: media/audio/audio_output_resampler.h

Issue 10909151: Automatically fall back to non-low latency on open() failure. (Closed) Base URL: http://git.chromium.org/chromium/src.git@resampler2
Patch Set: Rebase. Comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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. |record_stats| indicates if
78 // UMA statistics should be recorded about the hardware configuration.
79 void Initialize(bool record_stats);
80
69 // Called by MultiChannelResampler when more data is necessary. 81 // Called by MultiChannelResampler when more data is necessary.
70 void ProvideInput(AudioBus* audio_bus); 82 void ProvideInput(AudioBus* audio_bus);
71 83
72 // Called by AudioPullFifo when more data is necessary. Requires 84 // Called by AudioPullFifo when more data is necessary. Requires
73 // |source_lock_| to have been acquired. 85 // |source_lock_| to have been acquired.
74 void SourceCallback_Locked(AudioBus* audio_bus); 86 void SourceCallback_Locked(AudioBus* audio_bus);
75 87
76 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state. 88 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state.
77 // TODO(dalecurtis): Probably only one of these methods needs to call this, 89 // TODO(dalecurtis): Probably only one of these methods needs to call this,
78 // the rest should DCHECK()/CHECK() that the values were reset. 90 // the rest should DCHECK()/CHECK() that the values were reset.
(...skipping 12 matching lines...) Expand all
91 // Used to buffer data between the client and the output device in cases where 103 // 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. 104 // 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_| 105 // Bound to SourceCallback_Locked() so must only be used when |source_lock_|
94 // has already been acquired. 106 // has already been acquired.
95 scoped_ptr<AudioPullFifo> audio_fifo_; 107 scoped_ptr<AudioPullFifo> audio_fifo_;
96 108
97 // Ratio of input bytes to output bytes used to correct playback delay with 109 // Ratio of input bytes to output bytes used to correct playback delay with
98 // regard to buffering and resampling. 110 // regard to buffering and resampling.
99 double io_ratio_; 111 double io_ratio_;
100 112
101 // Helper values for determining playback delay adjustment. 113 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly.
102 int input_bytes_per_frame_; 114 base::TimeDelta close_delay_;
103 int output_bytes_per_frame_;
104 115
105 // Last AudioBuffersState object received via OnMoreData(), used to correct 116 // Last AudioBuffersState object received via OnMoreData(), used to correct
106 // playback delay by ProvideInput() and passed on to |source_callback_|. 117 // playback delay by ProvideInput() and passed on to |source_callback_|.
107 AudioBuffersState current_buffers_state_; 118 AudioBuffersState current_buffers_state_;
108 119
109 // Total number of bytes (in terms of output parameters) stored in resampler 120 // 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. 121 // or FIFO buffers which have not been sent to the audio device.
111 int outstanding_audio_bytes_; 122 int outstanding_audio_bytes_;
112 123
124 // AudioParameters used to setup the output stream.
125 AudioParameters output_params_;
126
113 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); 127 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler);
114 }; 128 };
115 129
116 } // namespace media 130 } // namespace media
117 131
118 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ 132 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698