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

Side by Side Diff: content/renderer/media_recorder/media_recorder_handler.cc

Issue 2811103006: Media Capabilities encoding: Blink pass-thru and skeleton renderer/ impl (Closed)
Patch Set: haraken@ comments Created 3 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
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/renderer/media_recorder/media_recorder_handler.h" 5 #include "content/renderer/media_recorder/media_recorder_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_tokenizer.h" 13 #include "base/strings/string_tokenizer.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "content/child/scoped_web_callbacks.h"
15 #include "content/renderer/media/media_stream_audio_track.h" 16 #include "content/renderer/media/media_stream_audio_track.h"
16 #include "content/renderer/media/media_stream_track.h" 17 #include "content/renderer/media/media_stream_track.h"
17 #include "content/renderer/media/webrtc_uma_histograms.h" 18 #include "content/renderer/media/webrtc_uma_histograms.h"
18 #include "content/renderer/media_recorder/audio_track_recorder.h" 19 #include "content/renderer/media_recorder/audio_track_recorder.h"
19 #include "media/base/audio_bus.h" 20 #include "media/base/audio_bus.h"
20 #include "media/base/audio_parameters.h" 21 #include "media/base/audio_parameters.h"
21 #include "media/base/bind_to_current_loop.h" 22 #include "media/base/bind_to_current_loop.h"
22 #include "media/base/mime_util.h" 23 #include "media/base/mime_util.h"
23 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
24 #include "media/muxers/webm_muxer.h" 25 #include "media/muxers/webm_muxer.h"
25 #include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h" 26 #include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h"
26 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 27 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
27 #include "third_party/WebKit/public/platform/WebString.h" 28 #include "third_party/WebKit/public/platform/WebString.h"
29 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebMedia Configuration.h"
28 30
29 using base::TimeDelta; 31 using base::TimeDelta;
30 using base::TimeTicks; 32 using base::TimeTicks;
31 using base::ToLowerASCII; 33 using base::ToLowerASCII;
32 34
33 namespace content { 35 namespace content {
34 36
37 using blink::WebMediaCapabilitiesQueryCallbacks;
38
35 namespace { 39 namespace {
36 40
37 media::VideoCodec CodecIdToMediaVideoCodec(VideoTrackRecorder::CodecId id) { 41 media::VideoCodec CodecIdToMediaVideoCodec(VideoTrackRecorder::CodecId id) {
38 switch (id) { 42 switch (id) {
39 case VideoTrackRecorder::CodecId::VP8: 43 case VideoTrackRecorder::CodecId::VP8:
40 return media::kCodecVP8; 44 return media::kCodecVP8;
41 case VideoTrackRecorder::CodecId::VP9: 45 case VideoTrackRecorder::CodecId::VP9:
42 return media::kCodecVP9; 46 return media::kCodecVP9;
43 #if BUILDFLAG(RTC_USE_H264) 47 #if BUILDFLAG(RTC_USE_H264)
44 case VideoTrackRecorder::CodecId::H264: 48 case VideoTrackRecorder::CodecId::H264:
45 return media::kCodecH264; 49 return media::kCodecH264;
46 #endif 50 #endif
47 case VideoTrackRecorder::CodecId::LAST: 51 case VideoTrackRecorder::CodecId::LAST:
48 return media::kUnknownVideoCodec; 52 return media::kUnknownVideoCodec;
49 } 53 }
50 NOTREACHED() << "Unsupported codec"; 54 NOTREACHED() << "Unsupported codec";
51 return media::kUnknownVideoCodec; 55 return media::kUnknownVideoCodec;
52 } 56 }
53 57
58 void OnEncodingInfoError(
59 std::unique_ptr<WebMediaCapabilitiesQueryCallbacks> callbacks) {
60 callbacks->OnError();
61 }
62
54 } // anonymous namespace 63 } // anonymous namespace
55 64
56 MediaRecorderHandler::MediaRecorderHandler() 65 MediaRecorderHandler::MediaRecorderHandler()
57 : video_bits_per_second_(0), 66 : video_bits_per_second_(0),
58 audio_bits_per_second_(0), 67 audio_bits_per_second_(0),
59 codec_id_(VideoTrackRecorder::CodecId::VP8), 68 codec_id_(VideoTrackRecorder::CodecId::VP8),
60 recording_(false), 69 recording_(false),
61 client_(nullptr), 70 client_(nullptr),
62 weak_factory_(this) {} 71 weak_factory_(this) {}
63 72
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 269 DCHECK(main_render_thread_checker_.CalledOnValidThread());
261 DCHECK(!recording_); 270 DCHECK(!recording_);
262 recording_ = true; 271 recording_ = true;
263 for (const auto& video_recorder : video_recorders_) 272 for (const auto& video_recorder : video_recorders_)
264 video_recorder->Resume(); 273 video_recorder->Resume();
265 for (const auto& audio_recorder : audio_recorders_) 274 for (const auto& audio_recorder : audio_recorders_)
266 audio_recorder->Resume(); 275 audio_recorder->Resume();
267 webm_muxer_->Resume(); 276 webm_muxer_->Resume();
268 } 277 }
269 278
279 void MediaRecorderHandler::EncodingInfo(
280 const blink::WebMediaConfiguration& configuration,
281 std::unique_ptr<blink::WebMediaCapabilitiesQueryCallbacks> callbacks) {
282 DCHECK(main_render_thread_checker_.CalledOnValidThread());
283 DCHECK(configuration.video_configuration ||
284 configuration.audio_configuration);
285
286 ScopedWebCallbacks<WebMediaCapabilitiesQueryCallbacks> scoped_callbacks =
287 make_scoped_web_callbacks(callbacks.release(),
288 base::Bind(&OnEncodingInfoError));
289
290 std::unique_ptr<blink::WebMediaCapabilitiesInfo> info(
291 new blink::WebMediaCapabilitiesInfo());
292
293 // TODO(mcasas): Support the case when both video and audio configurations are
294 // specified: https://crbug.com/709181.
295 std::string content_type;
296 if (configuration.video_configuration)
297 content_type = configuration.video_configuration->content_type.Ascii();
298 else
299 content_type = configuration.audio_configuration->content_type.Ascii();
300
301 // |content_type| should be of the form "bla;codecs=foo", where "bla" is the
302 // type and "codecs=foo" is the parameter ("foo" is the parameter value), see
303 // RFC 2231 [1]. CanSupportMimeType() operates on type and parameter value.
304 // [1] https://tools.ietf.org/html/rfc2231
305 base::StringTokenizer mime_tokenizer(content_type, ";");
306 blink::WebString web_type;
307 blink::WebString web_codecs;
308 if (mime_tokenizer.GetNext())
309 web_type = blink::WebString::FromASCII(mime_tokenizer.token());
310 if (mime_tokenizer.GetNext()) {
311 const std::string parameters = mime_tokenizer.token();
312 base::StringTokenizer parameter_tokenizer(parameters, "=");
313 if (parameter_tokenizer.GetNext() &&
314 base::ToLowerASCII(parameter_tokenizer.token()) == "codecs" &&
315 parameter_tokenizer.GetNext()) {
316 web_codecs = blink::WebString::FromASCII(parameter_tokenizer.token());
317 }
318 }
319
320 info->supported = CanSupportMimeType(web_type, web_codecs);
321 DVLOG(1) << "type: " << web_type.Ascii() << ", params:" << web_codecs.Ascii()
322 << " is" << (info->supported ? " supported" : " NOT supported");
323
324 scoped_callbacks.PassCallbacks()->OnSuccess(std::move(info));
325 }
326
270 void MediaRecorderHandler::OnEncodedVideo( 327 void MediaRecorderHandler::OnEncodedVideo(
271 const media::WebmMuxer::VideoParameters& params, 328 const media::WebmMuxer::VideoParameters& params,
272 std::unique_ptr<std::string> encoded_data, 329 std::unique_ptr<std::string> encoded_data,
273 std::unique_ptr<std::string> encoded_alpha, 330 std::unique_ptr<std::string> encoded_alpha,
274 TimeTicks timestamp, 331 TimeTicks timestamp,
275 bool is_key_frame) { 332 bool is_key_frame) {
276 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 333 DCHECK(main_render_thread_checker_.CalledOnValidThread());
277 334
278 if (UpdateTracksAndCheckIfChanged()) { 335 if (UpdateTracksAndCheckIfChanged()) {
279 client_->OnError("Amount of tracks in MediaStream has changed."); 336 client_->OnError("Amount of tracks in MediaStream has changed.");
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 recorder->OnData(audio_bus, timestamp); 432 recorder->OnData(audio_bus, timestamp);
376 } 433 }
377 434
378 void MediaRecorderHandler::SetAudioFormatForTesting( 435 void MediaRecorderHandler::SetAudioFormatForTesting(
379 const media::AudioParameters& params) { 436 const media::AudioParameters& params) {
380 for (const auto& recorder : audio_recorders_) 437 for (const auto& recorder : audio_recorders_)
381 recorder->OnSetFormat(params); 438 recorder->OnSetFormat(params);
382 } 439 }
383 440
384 } // namespace content 441 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698