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

Side by Side Diff: content/renderer/media/webrtc/processed_local_audio_source.h

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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
(Empty)
1 // Copyright 2016 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_PROCESSED_LOCAL_AUDIO_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/synchronization/lock.h"
10 #include "content/common/media/media_stream_options.h"
11 #include "content/renderer/media/media_stream_audio_level_calculator.h"
12 #include "content/renderer/media/media_stream_audio_source.h"
13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
14 #include "media/base/audio_capturer_source.h"
15 #include "third_party/webrtc/api/mediastreaminterface.h"
16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
17
18 namespace media {
19 class AudioInputDevice;
20 } // namespace media
21
22 namespace content {
23
24 class MediaStreamAudioProcessor;
25
26 // Represents a local source of audio data that is routed through the WebRTC
27 // audio pipeline for post-processing. Owns a media::AudioInputDevice and the
28 // MediaStreamProcessor that modifies its audio. Modified audio is delivered to
29 // WebRtcLocalAudioTracks.
30 class CONTENT_EXPORT ProcessedLocalAudioSource
31 : NON_EXPORTED_BASE(public MediaStreamAudioSource),
32 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) {
33 public:
34 // |consumer_render_frame_id| references the RenderFrame that will consume the
35 // audio data. Audio parameters and (optionally) a pre-existing audio session
36 // ID are read from |device_info|. |factory| must outlive this instance.
37 ProcessedLocalAudioSource(int consumer_render_frame_id,
38 const StreamDeviceInfo& device_info,
39 PeerConnectionDependencyFactory* factory);
40
41 ~ProcessedLocalAudioSource() final;
42
43 // If |source| is an instance of ProcessedLocalAudioSource, return a
44 // type-casted pointer to it. Otherwise, return null.
45 static ProcessedLocalAudioSource* From(MediaStreamAudioSource* source);
46
47 // Non-browser unit tests cannot provide RenderFrame implementations at
48 // run-time. This is used to skip the otherwise mandatory check for a valid
49 // render frame ID when the source is started.
50 void SetAllowInvalidRenderFrameIdForTesting(bool allowed) {
51 allow_invalid_render_frame_id_for_testing_ = allowed;
52 }
53
54 // Gets/Sets source constraints. Using this is optional, but must be done
55 // before the first call to ConnectToTrack().
56 blink::WebMediaConstraints source_constraints() const { return constraints_; }
57 void SetSourceConstraints(const blink::WebMediaConstraints& constraints);
58
59 // Not valid until after the source is started (when the first track is
60 // connected).
61 webrtc::AudioSourceInterface* rtc_source() const { return rtc_source_.get(); }
62
63 // Thread-safe volume accessors used by WebRtcAudioDeviceImpl.
64 void SetVolume(int volume);
65 int Volume() const;
66 int MaxVolume() const;
67
68 // Thread-safe accessor for querying the audio format prior to processing.
69 // TODO(phoglund): Think over the implications of this accessor and if we can
70 // remove it.
71 media::AudioParameters GetInputAudioParameters() const;
72
73 protected:
74 // MediaStreamAudioSource implementation.
75 void* GetClassIdentifier() const final;
76 void DoStopSource() final;
77 scoped_ptr<MediaStreamAudioTrack> CreateMediaStreamAudioTrack(
78 const std::string& id) final;
79 bool EnsureSourceIsStarted() final;
80
81 // AudioCapturerSource::CaptureCallback implementation.
82 void Capture(const media::AudioBus* audio_bus,
83 int audio_delay_milliseconds,
84 double volume,
85 bool key_pressed) override;
86 void OnCaptureError(const std::string& message) override;
87
88 private:
89 // The RenderFrame that will consume the audio data. Used when creating
90 // AudioInputDevices via the AudioDeviceFactory.
91 const int consumer_render_frame_id_;
92
93 PeerConnectionDependencyFactory* const pc_factory_;
94
95 // Constraints used when initializing and starting the source.
96 blink::WebMediaConstraints constraints_;
97
98 // Audio processor doing processing like FIFO, AGC, AEC and NS. Its output
99 // data is in a unit of 10 ms data chunk. Created by EnsureSourceIsStarted().
100 scoped_refptr<MediaStreamAudioProcessor> audio_processor_;
101
102 // The device created by the AudioDeviceFactory in EnsureSourceIsStarted().
103 // This is set once, and should never be changed again to avoid a
104 // thread-race condition in the SetVolume() method.
105 scoped_refptr<media::AudioInputDevice> input_device_;
106
107 // Holder for WebRTC audio pipeline objects. Created in
108 // EnsureSourceIsStarted().
109 scoped_refptr<webrtc::AudioSourceInterface> rtc_source_;
110
111 // Protects data elements from concurrent access when using the volume methods .
112 mutable base::Lock volume_lock_;
113
114 // Stores latest microphone volume received in a CaptureData() callback.
115 // Range is [0, 255].
116 int exposed_volume_;
117
118 // Used to calculate the signal level that shows in the UI.
119 MediaStreamAudioLevelCalculator level_calculator_;
120
121 bool allow_invalid_render_frame_id_for_testing_;
122
123 DISALLOW_COPY_AND_ASSIGN(ProcessedLocalAudioSource);
124 };
125
126 } // namespace content
127
128 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698