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

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

Issue 2570923002: Makes AudioOutputDispatcher non-ref-counted. (Closed)
Patch Set: Created 4 years 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 <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
14 #include "media/audio/audio_io.h" 13 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_manager.h" 14 #include "media/audio/audio_manager.h"
16 #include "media/audio/audio_output_dispatcher_impl.h" 15 #include "media/audio/audio_output_dispatcher_impl.h"
17 #include "media/base/audio_parameters.h" 16 #include "media/base/audio_parameters.h"
18 17
19 namespace media { 18 namespace media {
20 19
21 class OnMoreDataConverter; 20 class OnMoreDataConverter;
22 21
23 // AudioOutputResampler is a browser-side resampling and buffering solution 22 // AudioOutputResampler is a browser-side resampling and buffering solution
24 // which ensures audio data is always output at given parameters. See the 23 // which ensures audio data is always output at given parameters. See the
25 // AudioConverter class for details on the conversion process. 24 // AudioConverter class for details on the conversion process.
26 // 25 //
27 // AOR works by intercepting the AudioSourceCallback provided to StartStream() 26 // AOR works by intercepting the AudioSourceCallback provided to StartStream()
28 // and redirecting it through an AudioConverter instance. 27 // and redirecting it through an AudioConverter instance.
29 // 28 //
30 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to 29 // AOR will automatically fall back from AUDIO_PCM_LOW_LATENCY to
31 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output 30 // AUDIO_PCM_LINEAR if the output device fails to open at the requested output
32 // parameters. If opening still fails, it will fallback to AUDIO_FAKE. 31 // parameters. If opening still fails, it will fallback to AUDIO_FAKE.
33 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher { 32 class MEDIA_EXPORT AudioOutputResampler : public AudioOutputDispatcher {
34 public: 33 public:
35 AudioOutputResampler(AudioManager* audio_manager, 34 AudioOutputResampler(AudioManager* audio_manager,
36 const AudioParameters& input_params, 35 const AudioParameters& input_params,
37 const AudioParameters& output_params, 36 const AudioParameters& output_params,
38 const std::string& output_device_id, 37 const std::string& output_device_id,
39 const base::TimeDelta& close_delay); 38 const base::TimeDelta& close_delay);
39 ~AudioOutputResampler() override;
40 40
41 // AudioOutputDispatcher interface. 41 // AudioOutputDispatcher interface.
42 bool OpenStream() override; 42 bool OpenStream() override;
43 bool StartStream(AudioOutputStream::AudioSourceCallback* callback, 43 bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
44 AudioOutputProxy* stream_proxy) override; 44 AudioOutputProxy* stream_proxy) override;
45 void StopStream(AudioOutputProxy* stream_proxy) override; 45 void StopStream(AudioOutputProxy* stream_proxy) override;
46 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override; 46 void StreamVolumeSet(AudioOutputProxy* stream_proxy, double volume) override;
47 void CloseStream(AudioOutputProxy* stream_proxy) override; 47 void CloseStream(AudioOutputProxy* stream_proxy) override;
48 void Shutdown() override;
49 48
50 private: 49 private:
51 friend class base::RefCountedThreadSafe<AudioOutputResampler>;
52 ~AudioOutputResampler() override;
53
54 // Converts low latency based output parameters into high latency 50 // Converts low latency based output parameters into high latency
55 // appropriate output parameters in error situations. 51 // appropriate output parameters in error situations.
56 void SetupFallbackParams(); 52 void SetupFallbackParams();
57 53
58 // Used to reinitialize |dispatcher_|. 54 // Used to reinitialize |dispatcher_|.
59 void Reinitialize(); 55 void Reinitialize();
60 56
61 // Used to initialize |dispatcher_|. 57 // Used to initialize |dispatcher_|.
62 void Initialize(); 58 void Initialize();
63 59
64 // Dispatcher to proxy all AudioOutputDispatcher calls too. 60 // Dispatcher to proxy all AudioOutputDispatcher calls too.
65 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_; 61 std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_;
66 62
67 // Map of outstanding OnMoreDataConverter objects. A new object is created 63 // Map of outstanding OnMoreDataConverter objects. A new object is created
68 // on every StartStream() call and destroyed on CloseStream(). 64 // on every StartStream() call and destroyed on CloseStream().
69 typedef std::map<AudioOutputProxy*, OnMoreDataConverter*> CallbackMap; 65 typedef std::map<AudioOutputProxy*, OnMoreDataConverter*> CallbackMap;
70 CallbackMap callbacks_; 66 CallbackMap callbacks_;
71 67
72 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly. 68 // Used by AudioOutputDispatcherImpl; kept so we can reinitialize on the fly.
73 base::TimeDelta close_delay_; 69 base::TimeDelta close_delay_;
74 70
75 // AudioParameters used to setup the output stream; changed upon fallback. 71 // AudioParameters used to setup the output stream; changed upon fallback.
(...skipping 11 matching lines...) Expand all
87 // have been created within |close_delay_|. Without this, audio may be lost 83 // have been created within |close_delay_|. Without this, audio may be lost
88 // to a fake stream indefinitely for transient errors. 84 // to a fake stream indefinitely for transient errors.
89 base::Timer reinitialize_timer_; 85 base::Timer reinitialize_timer_;
90 86
91 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler); 87 DISALLOW_COPY_AND_ASSIGN(AudioOutputResampler);
92 }; 88 };
93 89
94 } // namespace media 90 } // namespace media
95 91
96 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_ 92 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_RESAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698