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

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

Issue 11410012: Collapse AudioRendererMixer and OnMoreDataResampler into AudioTransform. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: First draft. Created 8 years, 1 month 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 | Annotate | Revision Log
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 <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/time.h" 12 #include "base/time.h"
13 #include "media/audio/audio_io.h" 13 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_manager.h" 14 #include "media/audio/audio_manager.h"
15 #include "media/audio/audio_output_dispatcher.h" 15 #include "media/audio/audio_output_dispatcher.h"
16 #include "media/audio/audio_parameters.h" 16 #include "media/audio/audio_parameters.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 class OnMoreDataResampler; 20 class OnMoreDataTransform;
Chris Rogers 2012/11/14 23:50:49 OnMoreDataTransform sounds a bit awkward, how abou
DaleCurtis 2012/11/16 23:51:05 Done.
21 21
22 // AudioOutputResampler is a browser-side resampling and rebuffering solution 22 // AudioOutputResampler is a browser-side resampling and rebuffering solution
23 // which ensures audio data is always output at given parameters. The rough 23 // which ensures audio data is always output at given parameters. The rough
24 // flow is: Client -> [FIFO] -> [Resampler] -> Output Device. 24 // flow is: Client -> [FIFO] -> [Resampler] -> Output Device.
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 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 36 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output
37 // parameters. 37 // parameters.
38 // 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
39 // 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
40 // 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
41 // remove fallback support once it's stable. http://crbug.com/148418 41 // remove fallback support once it's stable. http://crbug.com/148418
42 //
43 // Currently channel downmixing and upmixing is not supported.
44 // TODO(dalecurtis): Add channel remixing. http://crbug.com/138762
45 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { 42 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher {
46 public: 43 public:
47 AudioOutputResampler(AudioManager* audio_manager, 44 AudioOutputResampler(AudioManager* audio_manager,
48 const AudioParameters& input_params, 45 const AudioParameters& input_params,
49 const AudioParameters& output_params, 46 const AudioParameters& output_params,
50 const base::TimeDelta& close_delay); 47 const base::TimeDelta& close_delay);
51 48
52 // AudioOutputDispatcher interface. 49 // AudioOutputDispatcher interface.
53 virtual bool OpenStream() OVERRIDE; 50 virtual bool OpenStream() OVERRIDE;
54 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback, 51 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
55 AudioOutputProxy* stream_proxy) OVERRIDE; 52 AudioOutputProxy* stream_proxy) OVERRIDE;
56 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE; 53 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE;
57 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy, 54 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
58 double volume) OVERRIDE; 55 double volume) OVERRIDE;
59 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE; 56 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE;
60 virtual void Shutdown() OVERRIDE; 57 virtual void Shutdown() OVERRIDE;
61 58
62 private: 59 private:
63 friend class base::RefCountedThreadSafe<AudioOutputResampler>; 60 friend class base::RefCountedThreadSafe<AudioOutputResampler>;
64 virtual ~AudioOutputResampler(); 61 virtual ~AudioOutputResampler();
65 62
66 // Used to initialize the FIFO and resamplers. 63 // Used to initialize and reinitialize |dispatcher_|.
67 void Initialize(); 64 void Initialize();
68 65
69 // Dispatcher to proxy all AudioOutputDispatcher calls too. 66 // Dispatcher to proxy all AudioOutputDispatcher calls too.
70 scoped_refptr<AudioOutputDispatcher> dispatcher_; 67 scoped_refptr<AudioOutputDispatcher> dispatcher_;
71 68
72 // Map of outstanding OnMoreDataResampler objects. A new object is created 69 // Map of outstanding OnMoreDataTransform objects. A new object is created
73 // on every StartStream() call and destroyed on CloseStream(). 70 // on every StartStream() call and destroyed on CloseStream().
74 typedef std::map<AudioOutputProxy*, OnMoreDataResampler*> CallbackMap; 71 typedef std::map<AudioOutputProxy*, OnMoreDataTransform*> CallbackMap;
75 CallbackMap callbacks_; 72 CallbackMap callbacks_;
76 73
77 // Ratio of input bytes to output bytes used to correct playback delay with
78 // regard to buffering and resampling.
79 double io_ratio_;
80
81 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. 74 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly.
82 base::TimeDelta close_delay_; 75 base::TimeDelta close_delay_;
83 76
84 // AudioParameters used to setup the output stream. 77 // AudioParameters used to setup the output stream.
85 AudioParameters output_params_; 78 AudioParameters output_params_;
86 79
87 // Whether any streams have been opened through |dispatcher_|, if so we can't 80 // Whether any streams have been opened through |dispatcher_|, if so we can't
88 // fallback on future OpenStream() failures. 81 // fallback on future OpenStream() failures.
89 bool streams_opened_; 82 bool streams_opened_;
90 83
91 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); 84 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler);
92 }; 85 };
93 86
94 } // namespace media 87 } // namespace media
95 88
96 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ 89 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_output_resampler.cc » ('j') | media/audio/audio_output_resampler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698