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

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

Issue 10918098: Introduce AudioOutputResampler for browser side resampling. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. 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
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/audio_output_resampler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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. The rough
24 // flow is: Client -> [FIFO] -> [Resampler] -> Output Device.
25 //
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.
28 // - The FIFO is only used if the input and output frame sizes differ or if
29 // the resampler is used.
30 //
31 // AOR works by intercepting the AudioSourceCallback provided to StartStream()
32 // and redirecting to the appropriate resampling or FIFO callback which passes
33 // through to the original callback only when necessary.
34 //
35 // Currently channel downmixing and upmixing is not supported.
36 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762
37 class MEDIA_EXPORT AudioOutputResampler
38 : public AudioOutputDispatcher,
39 public AudioOutputStream::AudioSourceCallback {
40 public:
41 AudioOutputResampler(AudioManager* audio_manager,
42 const AudioParameters& input_params,
43 const AudioParameters& output_params,
44 const base::TimeDelta& close_delay);
45
46 // AudioOutputDispatcher interface.
47 virtual bool OpenStream() OVERRIDE;
48 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
49 AudioOutputProxy* stream_proxy) OVERRIDE;
50 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE;
51 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
52 double volume) OVERRIDE;
53 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE;
54 virtual void Shutdown() OVERRIDE;
55
56 // AudioSourceCallback interface.
57 virtual int OnMoreData(AudioBus* audio_bus,
58 AudioBuffersState buffers_state) OVERRIDE;
59 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
60 virtual void WaitTillDataReady() OVERRIDE;
61
62 private:
63 friend class base::RefCountedThreadSafe<AudioOutputResampler>;
64 virtual ~AudioOutputResampler();
65
66 // Called by MultiChannelResampler when more data is necessary.
67 void ProvideInput(AudioBus* audio_bus);
68
69 // Called by AudioPullFifo when more data is necessary.
70 void SourceCallback(AudioBus* audio_bus);
71
72 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state.
73 // TODO(dalecurtis): Probably only one of these methods needs to call this,
74 // the rest should DCHECK()/CHECK() that the values were reset.
75 void Reset();
76
77 // Handles resampling.
78 scoped_ptr<MultiChannelResampler> resampler_;
79
80 // Dispatcher to proxy all AudioOutputDispatcher calls too.
81 scoped_refptr<AudioOutputDispatcher> dispatcher_;
82
83 // Source callback and associated lock.
84 base::Lock source_lock_;
85 AudioOutputStream::AudioSourceCallback* source_callback_;
86
87 // Used to buffer data between the client and the output device in cases where
88 // the client buffer size is not the same as the output device buffer size.
89 scoped_ptr<AudioPullFifo> audio_fifo_;
90
91 // Ratio of input bytes to output bytes used to correct playback delay with
92 // regard to buffering and resampling.
93 double io_ratio_;
94
95 // Helper values for determining playback delay adjustment.
96 int input_bytes_per_frame_;
97 int output_bytes_per_frame_;
98
99 // Last AudioBuffersState object received via OnMoreData(), used to correct
100 // playback delay by ProvideInput() and passed on to |source_callback_|.
101 AudioBuffersState current_buffers_state_;
102
103 // Total number of bytes (in terms of output parameters) stored in resampler
104 // or FIFO buffers which have not been sent to the audio device.
105 int outstanding_audio_bytes_;
106
107 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler);
108 };
109
110 } // namespace media
111
112 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_
OLDNEW
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/audio_output_resampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698