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

Side by Side Diff: content/renderer/media/webrtc_audio_processor.h

Issue 54383003: Added an "enable-audio-processor" flag and WebRtcAudioProcessor class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed the comments. Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_
7
8 #include "base/synchronization/lock.h"
9 #include "base/threading/thread_checker.h"
10 #include "content/common/content_export.h"
11 #include "media/base/audio_converter.h"
12 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
13 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h "
14 #include "third_party/webrtc/modules/interface/module_common_types.h"
15
16 namespace media {
17 class AudioBus;
18 class AudioFifo;
19 class AudioParameters;
20 } // namespace media
21
22 namespace webrtc {
23 class AudioFrame;
24 }
25
26 namespace content {
27
28 // This class owns an object of webrtc::AudioProcessing which contains signal
29 // processing components like AGC, AEC and NS. It enables the components based
30 // on the constraints, processes the data and outputs it in a unit of 10 ms
31 // data chunk.
32 class CONTENT_EXPORT WebRtcAudioProcessor {
33 public:
34 explicit WebRtcAudioProcessor(
35 const webrtc::MediaConstraintsInterface* constraints);
36 ~WebRtcAudioProcessor();
37
38 // Pushes capture data in |audio_source| to the internal FIFO.
39 // Called on the capture audio thread.
40 void PushCaptureData(media::AudioBus* audio_source);
41
42 // Processes a block of 10 ms data from the internal FIFO and outputs it via
43 // |out|.
44 // Returns true if the internal FIFO has at least 10ms data for processing,
45 // otherwise false.
46 // Called on the capture audio thread.
47 bool ProcessAndConsumeData(int capture_audio_delay_ms,
48 int volume,
49 bool key_pressed,
50 int16** out);
Jói 2013/11/08 13:36:40 The semantics of |out| need to be documented.
no longer working on chromium 2013/11/08 15:39:30 Done.
51
52 // Called when the format of the capture data has changed.
53 // Called on the main render thread.
54 void SetCaptureFormat(const media::AudioParameters& source_params);
55
56 // Push the render audio to WebRtc::AudioProcessing for analysis. This is
57 // needed iff echo processing is enabled.
58 // Called on the render audio thread.
59 void PushRenderData(const int16* render_audio,
Jói 2013/11/08 13:36:40 The semantics of |render_audio| need to be documen
no longer working on chromium 2013/11/08 15:39:30 adding a comment like: // |render_audio| is the po
Jói 2013/11/08 16:44:22 Looks good.
60 int sample_rate,
61 int number_of_channels,
62 int number_of_frames,
63 int render_delay_ms);
64
65 // The audio format of the output from the processor.
66 const media::AudioParameters& OutputFormat() const;
67
68 // Accessor to check if the audio processing is enabled or not.
69 bool has_audio_processing() const { return audio_processing_.get() != NULL; }
70
71 private:
72 class WebRtcAudioConverter;
73
74 // Helper to initialize the WebRtc AudioProcessing.
75 void InitializeAudioProcessingModule(
76 const webrtc::MediaConstraintsInterface* constraints);
77
78 // Helper to initialize the render converter.
79 void InitializeRenderConverterIfNeeded(int sample_rate,
80 int number_of_channels,
81 int frames_per_buffer);
82
83 // Called by ProcessAndConsumeData().
84 void ProcessData(webrtc::AudioFrame* audio_frame,
85 int audio_delay_milliseconds,
86 int volume,
87 bool key_pressed);
88
89 // Called when the processor is going away.
90 void StopAudioProcessing();
91
92 // Cached value for the render delay latency.
93 int render_delay_ms_;
94
95 // Protects |render_delay_ms_|.
96 // TODO(xians): Can we get rid of the lock?
Jói 2013/11/08 13:36:40 It looks like you just need base::subtle::NoBarrie
no longer working on chromium 2013/11/08 15:39:30 Dale would like to change all the xxx_ms into base
Jói 2013/11/08 16:44:22 Your private cache could be an int64 that gets shi
DaleCurtis 2013/11/08 21:00:48 I think avoiding lock contention (which may be an
no longer working on chromium 2013/11/11 14:35:25 Thanks for the tips. I am happy to change it to At
no longer working on chromium 2013/11/11 14:35:25 Done with changing the internal member to Atomic32
97 mutable base::Lock lock_;
98
99 // WebRtc AudioProcessing module which does AEC, AGC, NS, HighPass filter,
100 // ..etc.
101 scoped_ptr<webrtc::AudioProcessing> audio_processing_;
102
103 // Converter used for the down-mixing and resampling of the capture data.
104 scoped_ptr<WebRtcAudioConverter> capture_converter_;
105
106 // AudioFrame used to hold the output of |capture_converter_|.
107 webrtc::AudioFrame capture_frame_;
108
109 // Converter used for the down-mixing and resampling of the render data when
110 // the AEC is enabled.
111 scoped_ptr<WebRtcAudioConverter> render_converter_;
112
113 // AudioFrame used to hold the output of |render_converter_|.
114 webrtc::AudioFrame render_frame_;
115
116 // Data bus to help converting interleaved data to an AudioBus.
117 scoped_ptr<media::AudioBus> render_data_bus_;
118
119 // Used to DCHECK that some methods are called on the correct thread.
Jói 2013/11/08 13:36:40 Document which thread that is, since you do so for
no longer working on chromium 2013/11/08 15:39:30 Done.
120 base::ThreadChecker thread_checker_;
121
122 // Used to DCHECK that some methods are called on the capture audio thread.
123 base::ThreadChecker capture_thread_checker_;
124 bool capture_thread_detach_;
125
126 // Used to DCHECK that PushRenderData() is called on the render audio thread.
127 base::ThreadChecker render_thread_checker_;
128 bool render_thread_detach_;
129 };
130
131 } // namespace content
132
133 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698