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

Side by Side Diff: content/public/renderer/media_stream_utils.cc

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE + Workaround to ensure MediaStreamAudioProcessor is destroyed on the main thread. Created 4 years, 7 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
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/media/audio_track_recorder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "content/public/renderer/media_stream_utils.h" 5 #include "content/public/renderer/media_stream_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "content/renderer/media/media_stream_audio_source.h" 14 #include "content/renderer/media/external_media_stream_audio_source.h"
15 #include "content/renderer/media/media_stream_video_capturer_source.h" 15 #include "content/renderer/media/media_stream_video_capturer_source.h"
16 #include "content/renderer/media/media_stream_video_source.h" 16 #include "content/renderer/media/media_stream_video_source.h"
17 #include "content/renderer/media/media_stream_video_track.h" 17 #include "content/renderer/media/media_stream_video_track.h"
18 #include "content/renderer/render_thread_impl.h"
19 #include "media/base/audio_capturer_source.h" 18 #include "media/base/audio_capturer_source.h"
20 #include "media/base/video_capturer_source.h" 19 #include "media/base/video_capturer_source.h"
21 #include "third_party/WebKit/public/platform/WebMediaStream.h" 20 #include "third_party/WebKit/public/platform/WebMediaStream.h"
22 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
23 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" 22 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
24 23
25 namespace content { 24 namespace content {
26 25
27 bool AddVideoTrackToMediaStream( 26 bool AddVideoTrackToMediaStream(
28 std::unique_ptr<media::VideoCapturerSource> video_source, 27 std::unique_ptr<media::VideoCapturerSource> video_source,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 DLOG(ERROR) << "Invalid audio parameters."; 75 DLOG(ERROR) << "Invalid audio parameters.";
77 return false; 76 return false;
78 } 77 }
79 78
80 blink::WebMediaStreamSource web_media_stream_source; 79 blink::WebMediaStreamSource web_media_stream_source;
81 const blink::WebString track_id = 80 const blink::WebString track_id =
82 blink::WebString::fromUTF8(base::GenerateGUID()); 81 blink::WebString::fromUTF8(base::GenerateGUID());
83 web_media_stream_source.initialize(track_id, 82 web_media_stream_source.initialize(track_id,
84 blink::WebMediaStreamSource::TypeAudio, 83 blink::WebMediaStreamSource::TypeAudio,
85 track_id, is_remote); 84 track_id, is_remote);
86 85 MediaStreamAudioSource* const media_stream_source =
87 MediaStreamAudioSource* media_stream_source(new MediaStreamAudioSource( 86 new ExternalMediaStreamAudioSource(std::move(audio_source), sample_rate,
88 -1, StreamDeviceInfo(), MediaStreamSource::SourceStoppedCallback(), 87 channel_layout, frames_per_buffer,
89 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory())); 88 is_remote);
90 89 // Takes ownership of |media_stream_source|.
91 blink::WebMediaConstraints constraints; 90 web_media_stream_source.setExtraData(media_stream_source);
92 constraints.initialize();
93 {
94 // TODO(miu): In an upcoming change, a source purposed for passing audio
95 // directly (i.e., without modification) will replace this "hacky" use of
96 // WebRtcAudioCapturer. http://crbug.com/577881
97 std::unique_ptr<WebRtcAudioCapturer> capturer(
98 WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(), constraints,
99 nullptr, media_stream_source));
100 capturer->SetCapturerSource(std::move(audio_source), params);
101 media_stream_source->SetAudioCapturer(std::move(capturer));
102 }
103 web_media_stream_source.setExtraData(
104 media_stream_source); // Takes ownership.
105 91
106 blink::WebMediaStreamTrack web_media_stream_track; 92 blink::WebMediaStreamTrack web_media_stream_track;
107 web_media_stream_track.initialize(web_media_stream_source); 93 web_media_stream_track.initialize(web_media_stream_source);
108 RenderThreadImpl::current() 94 if (!media_stream_source->ConnectToTrack(web_media_stream_track))
109 ->GetPeerConnectionDependencyFactory() 95 return false;
110 ->CreateLocalAudioTrack(web_media_stream_track);
111
112 web_media_stream->addTrack(web_media_stream_track); 96 web_media_stream->addTrack(web_media_stream_track);
113 return true; 97 return true;
114 } 98 }
115 99
116 const media::VideoCaptureFormat* GetCurrentVideoTrackFormat( 100 const media::VideoCaptureFormat* GetCurrentVideoTrackFormat(
117 const blink::WebMediaStreamTrack& video_track) { 101 const blink::WebMediaStreamTrack& video_track) {
118 if (video_track.isNull()) 102 if (video_track.isNull())
119 return nullptr; 103 return nullptr;
120 104
121 MediaStreamVideoSource* const source = 105 MediaStreamVideoSource* const source =
122 MediaStreamVideoSource::GetVideoSource(video_track.source()); 106 MediaStreamVideoSource::GetVideoSource(video_track.source());
123 if (!source) 107 if (!source)
124 return nullptr; 108 return nullptr;
125 109
126 return source->GetCurrentFormat(); 110 return source->GetCurrentFormat();
127 } 111 }
128 112
129 void RequestRefreshFrameFromVideoTrack( 113 void RequestRefreshFrameFromVideoTrack(
130 const blink::WebMediaStreamTrack& video_track) { 114 const blink::WebMediaStreamTrack& video_track) {
131 if (video_track.isNull()) 115 if (video_track.isNull())
132 return; 116 return;
133 MediaStreamVideoSource* const source = 117 MediaStreamVideoSource* const source =
134 MediaStreamVideoSource::GetVideoSource(video_track.source()); 118 MediaStreamVideoSource::GetVideoSource(video_track.source());
135 if (source) 119 if (source)
136 source->RequestRefreshFrame(); 120 source->RequestRefreshFrame();
137 } 121 }
138 122
139 } // namespace content 123 } // namespace content
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/media/audio_track_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698