Delete unused downloads page asset.
[chromium-blink-merge.git] / media / base / audio_renderer_mixer.h
blob9bc383934d4e43a9a764ff5eb052fbeb7e286452
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>
9 #include <string>
11 #include "base/synchronization/lock.h"
12 #include "base/time/time.h"
13 #include "media/base/audio_converter.h"
14 #include "media/base/audio_renderer_sink.h"
16 namespace media {
18 // Mixes a set of AudioConverter::InputCallbacks into a single output stream
19 // which is funneled into a single shared AudioRendererSink; saving a bundle
20 // on renderer side resources.
21 class MEDIA_EXPORT AudioRendererMixer
22 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) {
23 public:
24 AudioRendererMixer(const AudioParameters& input_params,
25 const AudioParameters& output_params,
26 const scoped_refptr<AudioRendererSink>& sink);
27 ~AudioRendererMixer() override;
29 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput.
30 void AddMixerInput(AudioConverter::InputCallback* input);
31 void RemoveMixerInput(AudioConverter::InputCallback* input);
33 // Since errors may occur even when no inputs are playing, an error callback
34 // must be registered separately from adding a mixer input. The same callback
35 // must be given to both the functions.
36 void AddErrorCallback(const base::Closure& error_cb);
37 void RemoveErrorCallback(const base::Closure& error_cb);
39 void set_pause_delay_for_testing(base::TimeDelta delay) {
40 pause_delay_ = delay;
43 // TODO(guidou): remove this method. The output device of a mixer should
44 // never be switched, as it may result in a discrepancy between the output
45 // parameters of the new device and the output parameters with which the
46 // mixer was initialized. See crbug.com/506507
47 OutputDevice* GetOutputDevice();
49 private:
50 // AudioRendererSink::RenderCallback implementation.
51 int Render(AudioBus* audio_bus, int audio_delay_milliseconds) override;
52 void OnRenderError() override;
54 // Output sink for this mixer.
55 scoped_refptr<AudioRendererSink> audio_sink_;
57 // ---------------[ All variables below protected by |lock_| ]---------------
58 base::Lock lock_;
60 // List of error callbacks used by this mixer.
61 typedef std::list<base::Closure> ErrorCallbackList;
62 ErrorCallbackList error_callbacks_;
64 // Handles mixing and resampling between input and output parameters.
65 AudioConverter audio_converter_;
67 // Handles physical stream pause when no inputs are playing. For latency
68 // reasons we don't want to immediately pause the physical stream.
69 base::TimeDelta pause_delay_;
70 base::TimeTicks last_play_time_;
71 bool playing_;
73 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer);
76 } // namespace media
78 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_