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

Side by Side Diff: media/base/audio_renderer_mixer.h

Issue 2067863003: Mixing audio with different latency requirements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
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_BASE_AUDIO_RENDERER_MIXER_H_ 5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ 6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "media/base/audio_converter.h" 17 #include "media/base/audio_converter.h"
18 #include "media/base/audio_renderer_sink.h" 18 #include "media/base/audio_renderer_sink.h"
19 #include "media/base/loopback_audio_converter.h" 19 #include "media/base/loopback_audio_converter.h"
20 20
21 namespace media { 21 namespace media {
22 22
23 // Mixes a set of AudioConverter::InputCallbacks into a single output stream 23 // Mixes a set of AudioConverter::InputCallbacks into a single output stream
24 // which is funneled into a single shared AudioRendererSink; saving a bundle 24 // which is funneled into a single shared AudioRendererSink; saving a bundle
25 // on renderer side resources. 25 // on renderer side resources.
26 class MEDIA_EXPORT AudioRendererMixer 26 class MEDIA_EXPORT AudioRendererMixer
27 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { 27 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) {
28 public: 28 public:
29 AudioRendererMixer(const AudioParameters& output_params, 29 AudioRendererMixer(const AudioParameters& output_params,
30 scoped_refptr<AudioRendererSink> sink); 30 scoped_refptr<AudioRendererSink> sink,
31 const std::string& uma_histogram);
31 ~AudioRendererMixer() override; 32 ~AudioRendererMixer() override;
32 33
33 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. 34 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput.
34 void AddMixerInput(const AudioParameters& input_params, 35 void AddMixerInput(const AudioParameters& input_params,
35 AudioConverter::InputCallback* input); 36 AudioConverter::InputCallback* input);
36 void RemoveMixerInput(const AudioParameters& input_params, 37 void RemoveMixerInput(const AudioParameters& input_params,
37 AudioConverter::InputCallback* input); 38 AudioConverter::InputCallback* input);
38 39
39 // Since errors may occur even when no inputs are playing, an error callback 40 // Since errors may occur even when no inputs are playing, an error callback
40 // must be registered separately from adding a mixer input. The same callback 41 // must be registered separately from adding a mixer input. The same callback
41 // must be given to both the functions. 42 // must be given to both the functions.
42 void AddErrorCallback(const base::Closure& error_cb); 43 void AddErrorCallback(const base::Closure& error_cb);
43 void RemoveErrorCallback(const base::Closure& error_cb); 44 void RemoveErrorCallback(const base::Closure& error_cb);
44 45
45 void set_pause_delay_for_testing(base::TimeDelta delay) { 46 void set_pause_delay_for_testing(base::TimeDelta delay) {
46 pause_delay_ = delay; 47 pause_delay_ = delay;
47 } 48 }
48 49
49 OutputDeviceInfo GetOutputDeviceInfo(); 50 OutputDeviceInfo GetOutputDeviceInfo();
50 51
51 // Returns true if called on rendering thread, otherwise false. 52 // Returns true if called on rendering thread, otherwise false.
52 bool CurrentThreadIsRenderingThread(); 53 bool CurrentThreadIsRenderingThread();
53 54
55 AudioParameters GetOutputParamsForTesting() { return output_params_; };
56
54 private: 57 private:
58 class UMAMaxValueTracker;
59
55 // Maps input sample rate to the dedicated converter. 60 // Maps input sample rate to the dedicated converter.
56 using AudioConvertersMap = 61 using AudioConvertersMap =
57 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; 62 std::map<int, std::unique_ptr<LoopbackAudioConverter>>;
58 63
59 // AudioRendererSink::RenderCallback implementation. 64 // AudioRendererSink::RenderCallback implementation.
60 int Render(AudioBus* audio_bus, 65 int Render(AudioBus* audio_bus,
61 uint32_t frames_delayed, 66 uint32_t frames_delayed,
62 uint32_t frames_skipped) override; 67 uint32_t frames_skipped) override;
63 void OnRenderError() override; 68 void OnRenderError() override;
64 69
(...skipping 22 matching lines...) Expand all
87 // Master converter which mixes all the outputs from |converters_| as well as 92 // Master converter which mixes all the outputs from |converters_| as well as
88 // mixer inputs that are in the output sample rate. 93 // mixer inputs that are in the output sample rate.
89 AudioConverter master_converter_; 94 AudioConverter master_converter_;
90 95
91 // Handles physical stream pause when no inputs are playing. For latency 96 // Handles physical stream pause when no inputs are playing. For latency
92 // reasons we don't want to immediately pause the physical stream. 97 // reasons we don't want to immediately pause the physical stream.
93 base::TimeDelta pause_delay_; 98 base::TimeDelta pause_delay_;
94 base::TimeTicks last_play_time_; 99 base::TimeTicks last_play_time_;
95 bool playing_; 100 bool playing_;
96 101
102 // Tracks the maximum number of simultaneous mixer inputs and logs it into
103 // UMA histogram upon the destruction.
104 std::unique_ptr<UMAMaxValueTracker> input_count_tracker_;
105
97 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); 106 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer);
98 }; 107 };
99 108
100 } // namespace media 109 } // namespace media
101 110
102 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ 111 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698