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

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: fixed the comment in content_switches.cc 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/atomicops.h"
9 #include "base/synchronization/lock.h"
10 #include "base/threading/thread_checker.h"
11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
13 #include "media/base/audio_converter.h"
14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
15 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h "
16 #include "third_party/webrtc/modules/interface/module_common_types.h"
17
18 namespace media {
19 class AudioBus;
20 class AudioFifo;
21 class AudioParameters;
22 } // namespace media
23
24 namespace webrtc {
25 class AudioFrame;
26 }
27
28 namespace content {
29
30 // This class owns an object of webrtc::AudioProcessing which contains signal
31 // processing components like AGC, AEC and NS. It enables the components based
32 // on the getUserMedia constraints, processes the data and outputs it in a unit
33 // of 10 ms data chunk.
34 class CONTENT_EXPORT WebRtcAudioProcessor {
35 public:
36 explicit WebRtcAudioProcessor(
37 const webrtc::MediaConstraintsInterface* constraints);
38 ~WebRtcAudioProcessor();
39
40 // Pushes capture data in |audio_source| to the internal FIFO.
41 // Called on the capture audio thread.
42 void PushCaptureData(media::AudioBus* audio_source);
43
44 // Processes a block of 10 ms data from the internal FIFO and outputs it via
45 // |out|. |out| is the address of the pointer that will be pointed to
46 // the post-processed data if the method is returning a true. The lifetime
47 // of the data represeted by |out| is guaranteed to outlive the method call.
48 // Returns true if the internal FIFO has at least 10 ms data for processing,
49 // otherwise false.
50 // |capture_delay|, |volume| and |key_pressed| will be passed to
51 // webrtc::AudioProcessing to help processing the data.
52 // Called on the capture audio thread.
53 bool ProcessAndConsumeData(base::TimeDelta capture_delay,
54 int volume,
55 bool key_pressed,
56 int16** out);
57
58 // Called when the format of the capture data has changed.
59 // This has to be called before PushCaptureData() and ProcessAndConsumeData().
60 // Called on the main render thread.
61 void SetCaptureFormat(const media::AudioParameters& source_params);
62
63 // Push the render audio to WebRtc::AudioProcessing for analysis. This is
64 // needed iff echo processing is enabled.
65 // |render_audio| is the pointer to the render audio data, its format
66 // is specified by |sample_rate|, |number_of_channels| and |number_of_frames|.
67 // Called on the render audio thread.
68 void PushRenderData(const int16* render_audio,
69 int sample_rate,
70 int number_of_channels,
71 int number_of_frames,
72 base::TimeDelta render_delay);
73
74 // The audio format of the output from the processor.
75 const media::AudioParameters& OutputFormat() const;
76
77 // Accessor to check if the audio processing is enabled or not.
78 bool has_audio_processing() const { return audio_processing_.get() != NULL; }
79
80 private:
81 class WebRtcAudioConverter;
82
83 // Helper to initialize the WebRtc AudioProcessing.
84 void InitializeAudioProcessingModule(
85 const webrtc::MediaConstraintsInterface* constraints);
86
87 // Helper to initialize the render converter.
88 void InitializeRenderConverterIfNeeded(int sample_rate,
89 int number_of_channels,
90 int frames_per_buffer);
91
92 // Called by ProcessAndConsumeData().
93 void ProcessData(webrtc::AudioFrame* audio_frame,
94 base::TimeDelta capture_delay,
95 int volume,
96 bool key_pressed);
97
98 // Called when the processor is going away.
99 void StopAudioProcessing();
100
101 // Cached value for the render delay latency.
102 volatile base::subtle::Atomic32 render_delay_ms_;
piman 2013/11/12 19:51:27 Shouldn't need volatile if you use the proper func
no longer working on chromium 2013/11/13 17:19:34 Done.
103
104 // WebRtc AudioProcessing module which does AEC, AGC, NS, HighPass filter,
105 // ..etc.
106 scoped_ptr<webrtc::AudioProcessing> audio_processing_;
107
108 // Converter used for the down-mixing and resampling of the capture data.
109 scoped_ptr<WebRtcAudioConverter> capture_converter_;
110
111 // AudioFrame used to hold the output of |capture_converter_|.
112 webrtc::AudioFrame capture_frame_;
113
114 // Converter used for the down-mixing and resampling of the render data when
115 // the AEC is enabled.
116 scoped_ptr<WebRtcAudioConverter> render_converter_;
117
118 // AudioFrame used to hold the output of |render_converter_|.
119 webrtc::AudioFrame render_frame_;
120
121 // Data bus to help converting interleaved data to an AudioBus.
122 scoped_ptr<media::AudioBus> render_data_bus_;
123
124 // Used to DCHECK that some methods are called on the main render thread.
125 base::ThreadChecker main_thread_checker_;
126
127 // Used to DCHECK that some methods are called on the capture audio thread.
128 base::ThreadChecker capture_thread_checker_;
129
130 // Used to DCHECK that PushRenderData() is called on the render audio thread.
131 base::ThreadChecker render_thread_checker_;
132 };
133
134 } // namespace content
135
136 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698