[Extensions Toolbar] Make the ExtensionToolbarModel icon count more stable
[chromium-blink-merge.git] / media / base / audio_renderer_mixer.h
blob35ed484976fdb83ee4975b955c10a5e3a296b131
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.
5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
8 #include <map>
10 #include "base/synchronization/lock.h"
11 #include "base/time/time.h"
12 #include "media/base/audio_converter.h"
13 #include "media/base/audio_renderer_sink.h"
15 namespace media {
17 // Mixes a set of AudioConverter::InputCallbacks into a single output stream
18 // which is funneled into a single shared AudioRendererSink; saving a bundle
19 // on renderer side resources.
20 class MEDIA_EXPORT AudioRendererMixer
21 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) {
22 public:
23 AudioRendererMixer(const AudioParameters& input_params,
24 const AudioParameters& output_params,
25 const scoped_refptr<AudioRendererSink>& sink);
26 ~AudioRendererMixer() override;
28 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput.
29 void AddMixerInput(AudioConverter::InputCallback* input);
30 void RemoveMixerInput(AudioConverter::InputCallback* input);
32 // Since errors may occur even when no inputs are playing, an error callback
33 // must be registered separately from adding a mixer input. The same callback
34 // must be given to both the functions.
35 void AddErrorCallback(const base::Closure& error_cb);
36 void RemoveErrorCallback(const base::Closure& error_cb);
38 void set_pause_delay_for_testing(base::TimeDelta delay) {
39 pause_delay_ = delay;
42 private:
43 // AudioRendererSink::RenderCallback implementation.
44 int Render(AudioBus* audio_bus, int audio_delay_milliseconds) override;
45 void OnRenderError() override;
47 // Output sink for this mixer.
48 scoped_refptr<AudioRendererSink> audio_sink_;
50 // ---------------[ All variables below protected by |lock_| ]---------------
51 base::Lock lock_;
53 // List of error callbacks used by this mixer.
54 typedef std::list<base::Closure> ErrorCallbackList;
55 ErrorCallbackList error_callbacks_;
57 // Handles mixing and resampling between input and output parameters.
58 AudioConverter audio_converter_;
60 // Handles physical stream pause when no inputs are playing. For latency
61 // reasons we don't want to immediately pause the physical stream.
62 base::TimeDelta pause_delay_;
63 base::TimeTicks last_play_time_;
64 bool playing_;
66 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer);
69 } // namespace media
71 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_