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

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: 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
284 ScopedWebCallbacks<WebMediaCapabilitiesQueryCallbacks> scoped_callbacks =
285 make_scoped_web_callbacks(callbacks.release(),
286 base::Bind(&OnEncodingInfoError));
287
288 if (!configuration.video_configuration && !configuration.audio_configuration)
289 return;
mlamouri (slow - plz ping) 2017/04/18 12:24:35 That should not happen.
mcasas 2017/04/18 21:41:51 The current code allows for this to happen. What d
290
291 std::unique_ptr<blink::WebMediaCapabilitiesInfo> info(
292 new blink::WebMediaCapabilitiesInfo());
293
294 std::string content_type;
295 if (configuration.video_configuration)
296 content_type = configuration.video_configuration->content_type.Ascii();
297 else
298 content_type = configuration.audio_configuration->content_type.Ascii();
mlamouri (slow - plz ping) 2017/04/18 12:24:35 what if there is audio and video?
mcasas 2017/04/18 21:41:51 TODO :-)
299
300 // |content_type| should be of the form "bla;codecs=foo", where "bla" is the
301 // type and "codecs=foo" is the parameter ("foo" is the parameter value), see
302 // RFC 2231 [1]. CanSupportMimeType() operates on type and parameter value.
303 // [1] https://tools.ietf.org/html/rfc2231
304 base::StringTokenizer mime_tokenizer(content_type, ";");
305 blink::WebString web_type;
306 blink::WebString web_codecs;
307 if (mime_tokenizer.GetNext())
308 web_type = blink::WebString::FromASCII(mime_tokenizer.token());
309 if (mime_tokenizer.GetNext()) {
310 const std::string parameters = mime_tokenizer.token();
311 base::StringTokenizer parameter_tokenizer(parameters, "=");
312 if (parameter_tokenizer.GetNext() &&
313 base::ToLowerASCII(parameter_tokenizer.token()) == "codecs" &&
314 parameter_tokenizer.GetNext()) {
315 web_codecs = blink::WebString::FromASCII(parameter_tokenizer.token());
316 }
317 }
mlamouri (slow - plz ping) 2017/04/18 12:24:35 I think most of this is going to be moved to Blink
mcasas 2017/04/18 21:41:51 That'd be great but for that we'd need to split W
mlamouri (slow - plz ping) 2017/04/20 13:37:13 chcunningham@ has a CL for that. Worse case I gues
318
319 info->supported = CanSupportMimeType(web_type, web_codecs);
320 DVLOG(1) << "type: " << web_type.Ascii() << ", params:" << web_codecs.Ascii()
321 << " is" << (info->supported ? " supported" : " NOT supported");
322
323 scoped_callbacks.PassCallbacks()->OnSuccess(std::move(info));
324 }
325
270 void MediaRecorderHandler::OnEncodedVideo( 326 void MediaRecorderHandler::OnEncodedVideo(
271 const media::WebmMuxer::VideoParameters& params, 327 const media::WebmMuxer::VideoParameters& params,
272 std::unique_ptr<std::string> encoded_data, 328 std::unique_ptr<std::string> encoded_data,
273 std::unique_ptr<std::string> encoded_alpha, 329 std::unique_ptr<std::string> encoded_alpha,
274 TimeTicks timestamp, 330 TimeTicks timestamp,
275 bool is_key_frame) { 331 bool is_key_frame) {
276 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 332 DCHECK(main_render_thread_checker_.CalledOnValidThread());
277 333
278 if (UpdateTracksAndCheckIfChanged()) { 334 if (UpdateTracksAndCheckIfChanged()) {
279 client_->OnError("Amount of tracks in MediaStream has changed."); 335 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); 431 recorder->OnData(audio_bus, timestamp);
376 } 432 }
377 433
378 void MediaRecorderHandler::SetAudioFormatForTesting( 434 void MediaRecorderHandler::SetAudioFormatForTesting(
379 const media::AudioParameters& params) { 435 const media::AudioParameters& params) {
380 for (const auto& recorder : audio_recorders_) 436 for (const auto& recorder : audio_recorders_)
381 recorder->OnSetFormat(params); 437 recorder->OnSetFormat(params);
382 } 438 }
383 439
384 } // namespace content 440 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698