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

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 most of Dale's 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);
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,
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 ProcessAndConsume10MsData().
84 void ProcessData(int audio_delay_milliseconds,
85 int volume,
86 bool key_pressed);
87
88 // Called when the processor is going away.
89 void StopAudioProcessing();
90
91 // Cached value for the render delay latency.
92 int render_delay_ms_;
93
94 // Protects |render_delay_ms_|.
95 // TODO(xians): Can we get rid of the lock?
96 mutable base::Lock lock_;
97
98 // WebRtc AudioProcessing module which does AEC, AGC, NS, HighPass filter,
99 // ..etc.
100 scoped_ptr<webrtc::AudioProcessing> audio_processing_;
101
102 // Converter used for the down-mixing and resampling of the capture data.
103 scoped_ptr<WebRtcAudioConverter> capture_converter_;
104
105 // Converter used for the down-mixing and resampling of the render data when
106 // the AEC is enabled.
107 scoped_ptr<WebRtcAudioConverter> render_converter_;
108
109 // Data bus to help converting interleaved data to an AudioBus.
110 scoped_ptr<media::AudioBus> render_data_bus_;
111
112 // Used to DCHECK that some methods are called on the correct thread.
113 base::ThreadChecker thread_checker_;
114 };
115
116 } // namespace content
117
118 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698