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

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

Issue 218763007: Update MediaStreamTrack::Stop to latest draft. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments and added tests. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_AUDIO_CAPTURER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "content/common/media/media_stream_options.h" 17 #include "content/common/media/media_stream_options.h"
18 #include "content/renderer/media/tagged_list.h" 18 #include "content/renderer/media/tagged_list.h"
19 #include "media/audio/audio_input_device.h" 19 #include "media/audio/audio_input_device.h"
20 #include "media/base/audio_capturer_source.h" 20 #include "media/base/audio_capturer_source.h"
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
22 22
23 namespace media { 23 namespace media {
24 class AudioBus; 24 class AudioBus;
25 } 25 }
26 26
27 namespace content { 27 namespace content {
28 28
29 class MediaStreamAudioProcessor; 29 class MediaStreamAudioProcessor;
30 class MediaStreamAudioSource;
30 class WebRtcAudioDeviceImpl; 31 class WebRtcAudioDeviceImpl;
31 class WebRtcLocalAudioRenderer; 32 class WebRtcLocalAudioRenderer;
32 class WebRtcLocalAudioTrack; 33 class WebRtcLocalAudioTrack;
33 34
34 // This class manages the capture data flow by getting data from its 35 // This class manages the capture data flow by getting data from its
35 // |source_|, and passing it to its |tracks_|. 36 // |source_|, and passing it to its |tracks_|.
36 // The threading model for this class is rather complex since it will be 37 // The threading model for this class is rather complex since it will be
37 // created on the main render thread, captured data is provided on a dedicated 38 // created on the main render thread, captured data is provided on a dedicated
38 // AudioInputDevice thread, and methods can be called either on the Libjingle 39 // AudioInputDevice thread, and methods can be called either on the Libjingle
39 // thread or on the main render thread but also other client threads 40 // thread or on the main render thread but also other client threads
40 // if an alternative AudioCapturerSource has been set. 41 // if an alternative AudioCapturerSource has been set.
41 class CONTENT_EXPORT WebRtcAudioCapturer 42 class CONTENT_EXPORT WebRtcAudioCapturer
42 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>, 43 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>,
43 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { 44 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) {
44 public: 45 public:
45 // Used to construct the audio capturer. |render_view_id| specifies the 46 // Used to construct the audio capturer. |render_view_id| specifies the
46 // render view consuming audio for capture, |render_view_id| as -1 is used 47 // render view consuming audio for capture, |render_view_id| as -1 is used
47 // by the unittests to skip creating a source via 48 // by the unittests to skip creating a source via
48 // AudioDeviceFactory::NewInputDevice(), and allow injecting their own source 49 // AudioDeviceFactory::NewInputDevice(), and allow injecting their own source
49 // via SetCapturerSourceForTesting() at a later state. |device_info| 50 // via SetCapturerSourceForTesting() at a later state. |device_info|
50 // contains all the device information that the capturer is created for. 51 // contains all the device information that the capturer is created for.
51 // |constraints| contains the settings for audio processing. 52 // |constraints| contains the settings for audio processing.
52 // TODO(xians): Implement the interface for the audio source and move the 53 // TODO(xians): Implement the interface for the audio source and move the
53 // |constraints| to ApplyConstraints(). 54 // |constraints| to ApplyConstraints().
54 // Called on the main render thread. 55 // Called on the main render thread.
55 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer( 56 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer(
56 int render_view_id, 57 int render_view_id,
57 const StreamDeviceInfo& device_info, 58 const StreamDeviceInfo& device_info,
58 const blink::WebMediaConstraints& constraints, 59 const blink::WebMediaConstraints& constraints,
59 WebRtcAudioDeviceImpl* audio_device); 60 WebRtcAudioDeviceImpl* audio_device,
61 MediaStreamAudioSource* audio_source);
60 62
61 63
62 // Add a audio track to the sinks of the capturer. 64 // Add a audio track to the sinks of the capturer.
63 // WebRtcAudioDeviceImpl calls this method on the main render thread but 65 // WebRtcAudioDeviceImpl calls this method on the main render thread but
64 // other clients may call it from other threads. The current implementation 66 // other clients may call it from other threads. The current implementation
65 // does not support multi-thread calling. 67 // does not support multi-thread calling.
66 // The first AddTrack will implicitly trigger the Start() of this object. 68 // The first AddTrack will implicitly trigger the Start() of this object.
67 void AddTrack(WebRtcLocalAudioTrack* track); 69 void AddTrack(WebRtcLocalAudioTrack* track);
68 70
69 // Remove a audio track from the sinks of the capturer. 71 // Remove a audio track from the sinks of the capturer.
(...skipping 22 matching lines...) Expand all
92 // device exists. 94 // device exists.
93 bool GetPairedOutputParameters(int* session_id, 95 bool GetPairedOutputParameters(int* session_id,
94 int* output_sample_rate, 96 int* output_sample_rate,
95 int* output_frames_per_buffer) const; 97 int* output_frames_per_buffer) const;
96 98
97 const std::string& device_id() const { return device_info_.device.id; } 99 const std::string& device_id() const { return device_info_.device.id; }
98 int session_id() const { return device_info_.session_id; } 100 int session_id() const { return device_info_.session_id; }
99 101
100 // Stops recording audio. This method will empty its track lists since 102 // Stops recording audio. This method will empty its track lists since
101 // stopping the capturer will implicitly invalidate all its tracks. 103 // stopping the capturer will implicitly invalidate all its tracks.
102 // This method is exposed to the public because the media stream track can 104 // This method is exposed to the public because the MediaStreamAudioSource can
103 // call Stop() on its source. 105 // call Stop()
104 void Stop(); 106 void Stop();
105 107
106 // Called by the WebAudioCapturerSource to get the audio processing params. 108 // Called by the WebAudioCapturerSource to get the audio processing params.
107 // This function is triggered by provideInput() on the WebAudio audio thread, 109 // This function is triggered by provideInput() on the WebAudio audio thread,
108 // TODO(xians): Remove after moving APM from WebRtc to Chrome. 110 // TODO(xians): Remove after moving APM from WebRtc to Chrome.
109 void GetAudioProcessingParams(base::TimeDelta* delay, int* volume, 111 void GetAudioProcessingParams(base::TimeDelta* delay, int* volume,
110 bool* key_pressed); 112 bool* key_pressed);
111 113
112 // Used by the unittests to inject their own source to the capturer. 114 // Used by the unittests to inject their own source to the capturer.
113 void SetCapturerSourceForTesting( 115 void SetCapturerSourceForTesting(
114 const scoped_refptr<media::AudioCapturerSource>& source, 116 const scoped_refptr<media::AudioCapturerSource>& source,
115 media::AudioParameters params); 117 media::AudioParameters params);
116 118
117 void StartAecDump(const base::PlatformFile& aec_dump_file); 119 void StartAecDump(const base::PlatformFile& aec_dump_file);
118 void StopAecDump(); 120 void StopAecDump();
119 121
120 protected: 122 protected:
121 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; 123 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>;
122 virtual ~WebRtcAudioCapturer(); 124 virtual ~WebRtcAudioCapturer();
123 125
124 private: 126 private:
125 class TrackOwner; 127 class TrackOwner;
126 typedef TaggedList<TrackOwner> TrackList; 128 typedef TaggedList<TrackOwner> TrackList;
127 129
128 WebRtcAudioCapturer(int render_view_id, 130 WebRtcAudioCapturer(int render_view_id,
129 const StreamDeviceInfo& device_info, 131 const StreamDeviceInfo& device_info,
130 const blink::WebMediaConstraints& constraints, 132 const blink::WebMediaConstraints& constraints,
131 WebRtcAudioDeviceImpl* audio_device); 133 WebRtcAudioDeviceImpl* audio_device,
134 MediaStreamAudioSource* audio_source);
132 135
133 // AudioCapturerSource::CaptureCallback implementation. 136 // AudioCapturerSource::CaptureCallback implementation.
134 // Called on the AudioInputDevice audio thread. 137 // Called on the AudioInputDevice audio thread.
135 virtual void Capture(media::AudioBus* audio_source, 138 virtual void Capture(media::AudioBus* audio_source,
136 int audio_delay_milliseconds, 139 int audio_delay_milliseconds,
137 double volume, 140 double volume,
138 bool key_pressed) OVERRIDE; 141 bool key_pressed) OVERRIDE;
139 virtual void OnCaptureError() OVERRIDE; 142 virtual void OnCaptureError() OVERRIDE;
140 143
141 // Initializes the default audio capturing source using the provided render 144 // Initializes the default audio capturing source using the provided render
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 base::TimeDelta audio_delay_; 203 base::TimeDelta audio_delay_;
201 bool key_pressed_; 204 bool key_pressed_;
202 205
203 // Flag to help deciding if the data needs audio processing. 206 // Flag to help deciding if the data needs audio processing.
204 bool need_audio_processing_; 207 bool need_audio_processing_;
205 208
206 // Raw pointer to the WebRtcAudioDeviceImpl, which is valid for the lifetime 209 // Raw pointer to the WebRtcAudioDeviceImpl, which is valid for the lifetime
207 // of RenderThread. 210 // of RenderThread.
208 WebRtcAudioDeviceImpl* audio_device_; 211 WebRtcAudioDeviceImpl* audio_device_;
209 212
213 // Raw pointer to the MediaStreamAudioSource object that holds a reference
214 // to this WebRtcAudioCapturer.
215 // Since |audio_source_| is owned by a blink::WebMediaStreamSource object and
216 // blink guarantee that the blink::WebMediaStreamSource outlives any
tommi (sloooow) - chröme 2014/04/03 08:53:16 guarantees
perkj_chrome 2014/04/03 11:58:34 Done.
217 // blink::WebMediaStreamTrack connected to the source, |audio_source_| is
218 // guaranteed to exist as long as a WebRtcLocalAudioTrack is connected to this
219 // WebRtcAudioCapturer.
220 MediaStreamAudioSource* const audio_source_;
221
210 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); 222 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer);
211 }; 223 };
212 224
213 } // namespace content 225 } // namespace content
214 226
215 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ 227 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698