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

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: 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
(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.
scherkus (not reviewing) 2012/09/10 14:25:32 bug etc? do we have DCHECKs / etc in place?
DaleCurtis 2012/09/10 14:53:51 Left it out since this falls under the resilience
36 class MEDIA_EXPORT AudioOutputResampler
37 : public AudioOutputDispatcher,
38 public AudioOutputStream::AudioSourceCallback {
39 public:
40 AudioOutputResampler(AudioManager* audio_manager,
41 const AudioParameters& input_params,
42 const AudioParameters& output_params,
43 const base::TimeDelta& close_delay);
44
45 // AudioOutputDispatcher interface.
46 virtual bool OpenStream() OVERRIDE;
47 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
48 AudioOutputProxy* stream_proxy) OVERRIDE;
49 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE;
50 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
51 double volume) OVERRIDE;
52 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE;
53 virtual void Shutdown() OVERRIDE;
54
55 // AudioSourceCallback interface.
56 virtual int OnMoreData(AudioBus* audio_bus,
57 AudioBuffersState buffers_state) OVERRIDE;
58 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
59 virtual void WaitTillDataReady() OVERRIDE;
60
61 private:
62 friend class base::RefCountedThreadSafe<AudioOutputResampler>;
63 virtual ~AudioOutputResampler();
64
65 // Called by MultiChannelResampler when more data is necessary.
66 void ProvideInput(AudioBus* audio_bus);
67
68 // Called by AudioPullFifo when more data is necessary.
69 void SourceCallback(AudioBus* audio_bus);
70
71 // Used by StopStream()/CloseStream()/Shutdown() to clear internal state.
72 // TODO(dalecurtis): Probably only one of these methods needs to call this,
73 // the rest should DCHECK()/CHECK() that the values were reset.
74 void Reset();
75
76 // Handles resampling.
77 scoped_ptr<MultiChannelResampler> resampler_;
78
79 // Dispatcher to proxy all AudioOutputDispatcher calls too.
80 scoped_refptr<AudioOutputDispatcher> dispatcher_;
81
82 // Source callback and associated lock.
83 base::Lock source_lock_;
84 AudioOutputStream::AudioSourceCallback* source_callback_;
scherkus (not reviewing) 2012/09/10 14:25:32 who owns this?
DaleCurtis 2012/09/10 14:53:51 Whoever called StartStream() (which in production
85
86 // Used to buffer data between the client and the output device in cases where
87 // the client buffer size is not the same as the output device buffer size.
88 scoped_ptr<AudioPullFifo> audio_fifo_;
89
90 // Ratio of input bytes to output bytes used to correct playback delay with
91 // regard to buffering and resampling.
92 double io_ratio_;
93
94 // Helper values for determining playback delay adjustment.
95 int input_bytes_per_frame_;
96 int output_bytes_per_frame_;
97
98 // Last AudioBuffersState object received via OnMoreData(), used to correct
99 // playback delay by ProvideInput() and passed on to |source_callback_|.
100 AudioBuffersState current_buffers_state_;
101
102 // Total number of bytes (in terms of output parameters) stored in resampler
103 // or FIFO buffers which have not been sent to the audio device.
104 int outstanding_audio_bytes_;
105
106 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler);
107 };
108
109 } // namespace media
110
111 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698