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

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

Issue 1721273002: MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mcasas's 1st round comments, plus REBASE. Created 4 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h"
15 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/renderer/media/media_stream_audio_level_calculator.h"
16 #include "third_party/webrtc/api/mediastreamtrack.h" 16 #include "third_party/webrtc/api/mediastreamtrack.h"
17 #include "third_party/webrtc/media/base/audiorenderer.h" 17 #include "third_party/webrtc/media/base/audiorenderer.h"
18 18
19 namespace cricket { 19 namespace cricket {
20 class AudioRenderer; 20 class AudioRenderer;
21 } 21 }
22 22
23 namespace webrtc { 23 namespace webrtc {
24 class AudioSourceInterface; 24 class AudioSourceInterface;
25 class AudioProcessorInterface; 25 class AudioProcessorInterface;
26 } 26 }
27 27
28 namespace content { 28 namespace content {
29 29
30 class MediaStreamAudioProcessor; 30 class MediaStreamAudioProcessor;
31 class WebRtcAudioSinkAdapter; 31 class WebRtcAudioSinkAdapter;
32 class WebRtcLocalAudioTrack; 32 class WebRtcLocalAudioTrack;
33 33
34 // Provides an implementation of the webrtc::AudioTrackInterface that can be
35 // bound/unbound to/from a MediaStreamAudioTrack. In other words, this is an
36 // adapter that sits between the media stream object graph and WebRtc's object
37 // graph and proxies between the two.
34 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter 38 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter
35 : NON_EXPORTED_BASE( 39 : NON_EXPORTED_BASE(
36 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { 40 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) {
37 public: 41 public:
38 static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create( 42 static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create(
39 const std::string& label, 43 const std::string& label,
40 webrtc::AudioSourceInterface* track_source); 44 webrtc::AudioSourceInterface* track_source);
41 45
42 WebRtcLocalAudioTrackAdapter( 46 WebRtcLocalAudioTrackAdapter(
43 const std::string& label, 47 const std::string& label,
44 webrtc::AudioSourceInterface* track_source, 48 webrtc::AudioSourceInterface* track_source,
45 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread); 49 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_task_runner);
46 50
47 ~WebRtcLocalAudioTrackAdapter() override; 51 ~WebRtcLocalAudioTrackAdapter() override;
48 52
49 void Initialize(WebRtcLocalAudioTrack* owner); 53 void Initialize(WebRtcLocalAudioTrack* owner);
50 54
51 // Called on the audio thread by the WebRtcLocalAudioTrack to set the signal 55 // Set the object that provides shared access to the current audio signal
52 // level of the audio data. 56 // level. This method may only be called once, before the audio data flow
53 void SetSignalLevel(int signal_level); 57 // starts.
58 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level);
54 59
55 // Method called by the WebRtcLocalAudioTrack to set the processor that 60 // Method called by the WebRtcLocalAudioTrack to set the processor that
56 // applies signal processing on the data of the track. 61 // applies signal processing on the data of the track.
57 // This class will keep a reference of the |processor|. 62 // This class will keep a reference of the |processor|.
58 // Called on the main render thread. 63 // Called on the main render thread.
64 // This method may only be called once, before the audio data flow starts.
59 void SetAudioProcessor( 65 void SetAudioProcessor(
60 const scoped_refptr<MediaStreamAudioProcessor>& processor); 66 const scoped_refptr<MediaStreamAudioProcessor>& processor);
61 67
62 // webrtc::MediaStreamTrack implementation. 68 // webrtc::MediaStreamTrack implementation.
63 std::string kind() const override; 69 std::string kind() const override;
64 bool set_enabled(bool enable) override; 70 bool set_enabled(bool enable) override;
65 71
66 private: 72 private:
67 // webrtc::AudioTrackInterface implementation. 73 // webrtc::AudioTrackInterface implementation.
68 void AddSink(webrtc::AudioTrackSinkInterface* sink) override; 74 void AddSink(webrtc::AudioTrackSinkInterface* sink) override;
69 void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override; 75 void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override;
70 bool GetSignalLevel(int* level) override; 76 bool GetSignalLevel(int* level) override;
71 rtc::scoped_refptr<webrtc::AudioProcessorInterface> GetAudioProcessor() 77 rtc::scoped_refptr<webrtc::AudioProcessorInterface> GetAudioProcessor()
72 override; 78 override;
73 webrtc::AudioSourceInterface* GetSource() const override; 79 webrtc::AudioSourceInterface* GetSource() const override;
74 80
75 // Weak reference. 81 // Weak reference.
76 WebRtcLocalAudioTrack* owner_; 82 WebRtcLocalAudioTrack* owner_;
77 83
78 // The source of the audio track which handles the audio constraints. 84 // The source of the audio track which handles the audio constraints.
79 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. 85 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack.
80 rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_; 86 rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_;
81 87
82 // Libjingle's signaling thread. 88 // Libjingle's signaling thread.
83 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_; 89 const scoped_refptr<base::SingleThreadTaskRunner> signaling_task_runner_;
84 90
85 // The audio processsor that applies audio processing on the data of audio 91 // The audio processsor that applies audio processing on the data of audio
86 // track. 92 // track.
87 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; 93 scoped_refptr<MediaStreamAudioProcessor> audio_processor_;
88 94
89 // A vector of WebRtc VoE channels that the capturer sends data to.
90 std::vector<int> voe_channels_;
91
92 // A vector of the peer connection sink adapters which receive the audio data 95 // A vector of the peer connection sink adapters which receive the audio data
93 // from the audio track. 96 // from the audio track.
94 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; 97 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_;
95 98
96 // The amplitude of the signal. 99 // Thread-safe accessor to current audio signal level.
97 int signal_level_; 100 scoped_refptr<MediaStreamAudioLevelCalculator::Level> level_;
98
99 // Thread checker for libjingle's signaling thread.
100 base::ThreadChecker signaling_thread_checker_;
101 base::ThreadChecker capture_thread_;
102
103 // Protects |voe_channels_|, |audio_processor_| and |signal_level_|.
104 mutable base::Lock lock_;
105 }; 101 };
106 102
107 } // namespace content 103 } // namespace content
108 104
109 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ 105 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698