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

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: android test fix 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
« no previous file with comments | « media/base/audio_latency_unittest.cc ('k') | media/base/audio_renderer_mixer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 typedef base::Callback<void(int)> UmaLogCallback;
30
29 AudioRendererMixer(const AudioParameters& output_params, 31 AudioRendererMixer(const AudioParameters& output_params,
30 scoped_refptr<AudioRendererSink> sink); 32 scoped_refptr<AudioRendererSink> sink,
33 const UmaLogCallback& log_callback);
31 ~AudioRendererMixer() override; 34 ~AudioRendererMixer() override;
32 35
33 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. 36 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput.
34 void AddMixerInput(const AudioParameters& input_params, 37 void AddMixerInput(const AudioParameters& input_params,
35 AudioConverter::InputCallback* input); 38 AudioConverter::InputCallback* input);
36 void RemoveMixerInput(const AudioParameters& input_params, 39 void RemoveMixerInput(const AudioParameters& input_params,
37 AudioConverter::InputCallback* input); 40 AudioConverter::InputCallback* input);
38 41
39 // Since errors may occur even when no inputs are playing, an error callback 42 // 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 43 // must be registered separately from adding a mixer input. The same callback
41 // must be given to both the functions. 44 // must be given to both the functions.
42 void AddErrorCallback(const base::Closure& error_cb); 45 void AddErrorCallback(const base::Closure& error_cb);
43 void RemoveErrorCallback(const base::Closure& error_cb); 46 void RemoveErrorCallback(const base::Closure& error_cb);
44 47
45 void set_pause_delay_for_testing(base::TimeDelta delay) { 48 void set_pause_delay_for_testing(base::TimeDelta delay) {
46 pause_delay_ = delay; 49 pause_delay_ = delay;
47 } 50 }
48 51
49 OutputDeviceInfo GetOutputDeviceInfo(); 52 OutputDeviceInfo GetOutputDeviceInfo();
50 53
51 // Returns true if called on rendering thread, otherwise false. 54 // Returns true if called on rendering thread, otherwise false.
52 bool CurrentThreadIsRenderingThread(); 55 bool CurrentThreadIsRenderingThread();
53 56
57 const AudioParameters& GetOutputParamsForTesting() { return output_params_; };
58
54 private: 59 private:
60 class UMAMaxValueTracker;
61
55 // Maps input sample rate to the dedicated converter. 62 // Maps input sample rate to the dedicated converter.
56 using AudioConvertersMap = 63 using AudioConvertersMap =
57 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; 64 std::map<int, std::unique_ptr<LoopbackAudioConverter>>;
58 65
59 // AudioRendererSink::RenderCallback implementation. 66 // AudioRendererSink::RenderCallback implementation.
60 int Render(AudioBus* audio_bus, 67 int Render(AudioBus* audio_bus,
61 uint32_t frames_delayed, 68 uint32_t frames_delayed,
62 uint32_t frames_skipped) override; 69 uint32_t frames_skipped) override;
63 void OnRenderError() override; 70 void OnRenderError() override;
64 71
(...skipping 22 matching lines...) Expand all
87 // Master converter which mixes all the outputs from |converters_| as well as 94 // Master converter which mixes all the outputs from |converters_| as well as
88 // mixer inputs that are in the output sample rate. 95 // mixer inputs that are in the output sample rate.
89 AudioConverter master_converter_; 96 AudioConverter master_converter_;
90 97
91 // Handles physical stream pause when no inputs are playing. For latency 98 // Handles physical stream pause when no inputs are playing. For latency
92 // reasons we don't want to immediately pause the physical stream. 99 // reasons we don't want to immediately pause the physical stream.
93 base::TimeDelta pause_delay_; 100 base::TimeDelta pause_delay_;
94 base::TimeTicks last_play_time_; 101 base::TimeTicks last_play_time_;
95 bool playing_; 102 bool playing_;
96 103
104 // Tracks the maximum number of simultaneous mixer inputs and logs it into
105 // UMA histogram upon the destruction.
106 std::unique_ptr<UMAMaxValueTracker> input_count_tracker_;
107
97 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); 108 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer);
98 }; 109 };
99 110
100 } // namespace media 111 } // namespace media
101 112
102 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ 113 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
OLDNEW
« no previous file with comments | « media/base/audio_latency_unittest.cc ('k') | media/base/audio_renderer_mixer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698