Chromium Code Reviews| Index: content/renderer/media_recorder/media_recorder_handler.cc |
| diff --git a/content/renderer/media_recorder/media_recorder_handler.cc b/content/renderer/media_recorder/media_recorder_handler.cc |
| index da7ebde5cb74b3ff89b727be19bf8a8eedf5b941..a87aba08abce628f2b25528f702dc2ae8fadbaa4 100644 |
| --- a/content/renderer/media_recorder/media_recorder_handler.cc |
| +++ b/content/renderer/media_recorder/media_recorder_handler.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/macros.h" |
| #include "base/strings/string_tokenizer.h" |
| #include "base/strings/string_util.h" |
| +#include "base/sys_info.h" |
| #include "content/child/scoped_web_callbacks.h" |
| #include "content/renderer/media/media_stream_audio_track.h" |
| #include "content/renderer/media/media_stream_track.h" |
| @@ -55,6 +56,23 @@ media::VideoCodec CodecIdToMediaVideoCodec(VideoTrackRecorder::CodecId id) { |
| return media::kUnknownVideoCodec; |
| } |
| +// Extracts the first recognised CodecId of |codecs| or CodecId::LAST if none |
| +// of them is known. |
| +VideoTrackRecorder::CodecId StringToCodecId(const blink::WebString& codecs) { |
| + const std::string& codecs_str = ToLowerASCII(codecs.Utf8()); |
| + |
| + if (codecs_str.find("vp8") != std::string::npos) |
| + return VideoTrackRecorder::CodecId::VP8; |
| + else if (codecs_str.find("vp9") != std::string::npos) |
| + return VideoTrackRecorder::CodecId::VP9; |
| +#if BUILDFLAG(RTC_USE_H264) |
| + else if (codecs_str.find("h264") != std::string::npos || |
| + codecs_str.find("avc1") != std::string::npos) |
| + return VideoTrackRecorder::CodecId::H264; |
| +#endif |
| + return VideoTrackRecorder::CodecId::LAST; |
| +} |
| + |
| void OnEncodingInfoError( |
| std::unique_ptr<WebMediaCapabilitiesQueryCallbacks> callbacks) { |
| callbacks->OnError(); |
| @@ -137,22 +155,13 @@ bool MediaRecorderHandler::Initialize( |
| } |
| // Once established that we support the codec(s), hunt then individually. |
| - const std::string& codecs_str = ToLowerASCII(codecs.Utf8()); |
| - if (codecs_str.find("vp8") != std::string::npos) |
| - codec_id_ = VideoTrackRecorder::CodecId::VP8; |
| - else if (codecs_str.find("vp9") != std::string::npos) |
| - codec_id_ = VideoTrackRecorder::CodecId::VP9; |
| -#if BUILDFLAG(RTC_USE_H264) |
| - else if (codecs_str.find("h264") != std::string::npos) |
| - codec_id_ = VideoTrackRecorder::CodecId::H264; |
| - else if (codecs_str.find("avc1") != std::string::npos) |
| - codec_id_ = VideoTrackRecorder::CodecId::H264; |
| -#endif |
| - else |
| - codec_id_ = VideoTrackRecorder::GetPreferredCodecId(); |
| + const VideoTrackRecorder::CodecId codec_id = StringToCodecId(codecs); |
| + codec_id_ = (codec_id != VideoTrackRecorder::CodecId::LAST) |
| + ? codec_id |
| + : VideoTrackRecorder::GetPreferredCodecId(); |
| - DVLOG_IF(1, codecs_str.empty()) << "Falling back to preferred codec id " |
| - << static_cast<int>(codec_id_); |
| + DVLOG_IF(1, codec_id == VideoTrackRecorder::CodecId::LAST) |
| + << "Falling back to preferred codec id " << static_cast<int>(codec_id_); |
| media_stream_ = media_stream; |
| DCHECK(client); |
| @@ -302,10 +311,37 @@ void MediaRecorderHandler::EncodingInfo( |
| codec = configuration.audio_configuration->codec; |
| } |
| - // See RFC 2231. https://tools.ietf.org/html/rfc2231 |
| info->supported = CanSupportMimeType(mime_type, codec); |
| - DVLOG(1) << "type: " << mime_type.Ascii() << ", codec:" << codec.Ascii() |
| - << " is" << (info->supported ? " supported" : " NOT supported"); |
| + |
| + if (configuration.video_configuration && info->supported) { |
| + const bool is_likely_accelerated = |
| + VideoTrackRecorder::CanUseAcceleratedEncoder( |
| + StringToCodecId(codec), configuration.video_configuration->width, |
| + configuration.video_configuration->height); |
| + |
| + // Encoding smoothness depends on a number of parameters, namely: frame |
| + // rate, resolution, hardware support availability, platform and |
| + // IsLowEndDevice(); to simplify calculations we compare the amount of |
| + // pixels per second (i.e. |resolution| times |framerate|). Software based |
| + // encoding on Desktop can run fine up and until HD resolution at 30fps, |
| + // whereas if IsLowEndDevice() we set the cut at VGA (note that either pixel |
| + // volumes would make use of hardware acceleration if available). |
| + const float kNumPixelsPerSecondSmoothnessThreshold = |
| + base::SysInfo::IsLowEndDevice() ? 640 * 480 * 30.0 : 1280 * 720 * 30.0; |
|
emircan
2017/05/01 17:12:29
Can we define this as constant at the top of this
mcasas
2017/05/01 20:18:44
Done.
|
| + const float pixels_per_second = |
| + configuration.video_configuration->width * |
| + configuration.video_configuration->height * |
| + configuration.video_configuration->framerate; |
| + info->smooth = is_likely_accelerated || |
| + pixels_per_second <= kNumPixelsPerSecondSmoothnessThreshold; |
| + |
| + // TODO(mcasas): revisit what |power_efficient| means |
| + // https://crbug.com/709181. |
| + info->power_efficient = info->smooth; |
| + } |
| + DVLOG(1) << "type: " << mime_type.Ascii() << ", params:" << codec.Ascii() |
| + << " is" << (info->supported ? " supported" : " NOT supported") |
| + << " and" << (info->smooth ? " smooth" : " NOT smooth"); |
| scoped_callbacks.PassCallbacks()->OnSuccess(std::move(info)); |
| } |