Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 case VideoTrackRecorder::CodecId::H264: | 48 case VideoTrackRecorder::CodecId::H264: |
| 49 return media::kCodecH264; | 49 return media::kCodecH264; |
| 50 #endif | 50 #endif |
| 51 case VideoTrackRecorder::CodecId::LAST: | 51 case VideoTrackRecorder::CodecId::LAST: |
| 52 return media::kUnknownVideoCodec; | 52 return media::kUnknownVideoCodec; |
| 53 } | 53 } |
| 54 NOTREACHED() << "Unsupported codec"; | 54 NOTREACHED() << "Unsupported codec"; |
| 55 return media::kUnknownVideoCodec; | 55 return media::kUnknownVideoCodec; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Extracts the first recognised CodecId of |codecs| or CodecId::LAST if none | |
| 59 // of them is known. | |
| 60 VideoTrackRecorder::CodecId StringToCodecId(const blink::WebString& codecs) { | |
| 61 const std::string& codecs_str = ToLowerASCII(codecs.Utf8()); | |
| 62 | |
| 63 if (codecs_str.find("vp8") != std::string::npos) | |
| 64 return VideoTrackRecorder::CodecId::VP8; | |
| 65 else if (codecs_str.find("vp9") != std::string::npos) | |
| 66 return VideoTrackRecorder::CodecId::VP9; | |
| 67 #if BUILDFLAG(RTC_USE_H264) | |
|
emircan
2017/04/25 02:04:30
We should use IS_H264_SUPPORTED as the android cl
| |
| 68 else if (codecs_str.find("h264") != std::string::npos || | |
| 69 codecs_str.find("avc1") != std::string::npos) | |
| 70 return VideoTrackRecorder::CodecId::H264; | |
| 71 #endif | |
| 72 return VideoTrackRecorder::CodecId::LAST; | |
| 73 } | |
| 74 | |
| 58 void OnEncodingInfoError( | 75 void OnEncodingInfoError( |
| 59 std::unique_ptr<WebMediaCapabilitiesQueryCallbacks> callbacks) { | 76 std::unique_ptr<WebMediaCapabilitiesQueryCallbacks> callbacks) { |
| 60 callbacks->OnError(); | 77 callbacks->OnError(); |
| 61 } | 78 } |
| 62 | 79 |
| 63 } // anonymous namespace | 80 } // anonymous namespace |
| 64 | 81 |
| 65 MediaRecorderHandler::MediaRecorderHandler() | 82 MediaRecorderHandler::MediaRecorderHandler() |
| 66 : video_bits_per_second_(0), | 83 : video_bits_per_second_(0), |
| 67 audio_bits_per_second_(0), | 84 audio_bits_per_second_(0), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 // Save histogram data so we can see how much MediaStream Recorder is used. | 147 // Save histogram data so we can see how much MediaStream Recorder is used. |
| 131 // The histogram counts the number of calls to the JS API. | 148 // The histogram counts the number of calls to the JS API. |
| 132 UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); | 149 UpdateWebRTCMethodCount(WEBKIT_MEDIA_STREAM_RECORDER); |
| 133 | 150 |
| 134 if (!CanSupportMimeType(type, codecs)) { | 151 if (!CanSupportMimeType(type, codecs)) { |
| 135 DLOG(ERROR) << "Unsupported " << type.Utf8() << ";codecs=" << codecs.Utf8(); | 152 DLOG(ERROR) << "Unsupported " << type.Utf8() << ";codecs=" << codecs.Utf8(); |
| 136 return false; | 153 return false; |
| 137 } | 154 } |
| 138 | 155 |
| 139 // Once established that we support the codec(s), hunt then individually. | 156 // Once established that we support the codec(s), hunt then individually. |
| 140 const std::string& codecs_str = ToLowerASCII(codecs.Utf8()); | 157 const VideoTrackRecorder::CodecId codec_id = StringToCodecId(codecs); |
| 141 if (codecs_str.find("vp8") != std::string::npos) | 158 codec_id_ = (codec_id != VideoTrackRecorder::CodecId::LAST) |
| 142 codec_id_ = VideoTrackRecorder::CodecId::VP8; | 159 ? codec_id |
| 143 else if (codecs_str.find("vp9") != std::string::npos) | 160 : VideoTrackRecorder::GetPreferredCodecId(); |
| 144 codec_id_ = VideoTrackRecorder::CodecId::VP9; | |
| 145 #if defined(IS_H264_SUPPORTED) | |
| 146 else if (codecs_str.find("h264") != std::string::npos) | |
| 147 codec_id_ = VideoTrackRecorder::CodecId::H264; | |
| 148 else if (codecs_str.find("avc1") != std::string::npos) | |
| 149 codec_id_ = VideoTrackRecorder::CodecId::H264; | |
| 150 #endif | |
| 151 else | |
| 152 codec_id_ = VideoTrackRecorder::GetPreferredCodecId(); | |
| 153 | 161 |
| 154 DVLOG_IF(1, codecs_str.empty()) << "Falling back to preferred codec id " | 162 DVLOG_IF(1, codec_id == VideoTrackRecorder::CodecId::LAST) |
| 155 << static_cast<int>(codec_id_); | 163 << "Falling back to preferred codec id " << static_cast<int>(codec_id_); |
| 156 | 164 |
| 157 media_stream_ = media_stream; | 165 media_stream_ = media_stream; |
| 158 DCHECK(client); | 166 DCHECK(client); |
| 159 client_ = client; | 167 client_ = client; |
| 160 | 168 |
| 161 audio_bits_per_second_ = audio_bits_per_second; | 169 audio_bits_per_second_ = audio_bits_per_second; |
| 162 video_bits_per_second_ = video_bits_per_second; | 170 video_bits_per_second_ = video_bits_per_second; |
| 163 return true; | 171 return true; |
| 164 } | 172 } |
| 165 | 173 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 const std::string parameters = mime_tokenizer.token(); | 319 const std::string parameters = mime_tokenizer.token(); |
| 312 base::StringTokenizer parameter_tokenizer(parameters, "="); | 320 base::StringTokenizer parameter_tokenizer(parameters, "="); |
| 313 if (parameter_tokenizer.GetNext() && | 321 if (parameter_tokenizer.GetNext() && |
| 314 base::ToLowerASCII(parameter_tokenizer.token()) == "codecs" && | 322 base::ToLowerASCII(parameter_tokenizer.token()) == "codecs" && |
| 315 parameter_tokenizer.GetNext()) { | 323 parameter_tokenizer.GetNext()) { |
| 316 web_codecs = blink::WebString::FromASCII(parameter_tokenizer.token()); | 324 web_codecs = blink::WebString::FromASCII(parameter_tokenizer.token()); |
| 317 } | 325 } |
| 318 } | 326 } |
| 319 | 327 |
| 320 info->supported = CanSupportMimeType(web_type, web_codecs); | 328 info->supported = CanSupportMimeType(web_type, web_codecs); |
| 329 | |
| 330 if (configuration.video_configuration && info->supported) { | |
| 331 info->smooth = VideoTrackRecorder::IsEncodingLikelyAccelerated( | |
|
chcunningham
2017/04/24 20:58:17
Please build this out more to consider system spec
emircan
2017/04/25 02:04:30
We do not have power metrics currently, so we can
mcasas
2017/04/25 18:16:07
Please note that IsEncodingLikelyAccelerated() inc
chcunningham
2017/04/25 18:52:52
Totally fine for the initial implementation to be
| |
| 332 StringToCodecId(web_codecs), configuration.video_configuration->width, | |
| 333 configuration.video_configuration->height); | |
| 334 info->power_efficient = info->smooth; | |
| 335 } | |
| 321 DVLOG(1) << "type: " << web_type.Ascii() << ", params:" << web_codecs.Ascii() | 336 DVLOG(1) << "type: " << web_type.Ascii() << ", params:" << web_codecs.Ascii() |
| 322 << " is" << (info->supported ? " supported" : " NOT supported"); | 337 << " is" << (info->supported ? " supported" : " NOT supported") |
| 338 << " and" << (info->smooth ? " smooth" : " NOT smooth"); | |
| 323 | 339 |
| 324 scoped_callbacks.PassCallbacks()->OnSuccess(std::move(info)); | 340 scoped_callbacks.PassCallbacks()->OnSuccess(std::move(info)); |
| 325 } | 341 } |
| 326 | 342 |
| 327 void MediaRecorderHandler::OnEncodedVideo( | 343 void MediaRecorderHandler::OnEncodedVideo( |
| 328 const media::WebmMuxer::VideoParameters& params, | 344 const media::WebmMuxer::VideoParameters& params, |
| 329 std::unique_ptr<std::string> encoded_data, | 345 std::unique_ptr<std::string> encoded_data, |
| 330 std::unique_ptr<std::string> encoded_alpha, | 346 std::unique_ptr<std::string> encoded_alpha, |
| 331 TimeTicks timestamp, | 347 TimeTicks timestamp, |
| 332 bool is_key_frame) { | 348 bool is_key_frame) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 recorder->OnData(audio_bus, timestamp); | 448 recorder->OnData(audio_bus, timestamp); |
| 433 } | 449 } |
| 434 | 450 |
| 435 void MediaRecorderHandler::SetAudioFormatForTesting( | 451 void MediaRecorderHandler::SetAudioFormatForTesting( |
| 436 const media::AudioParameters& params) { | 452 const media::AudioParameters& params) { |
| 437 for (const auto& recorder : audio_recorders_) | 453 for (const auto& recorder : audio_recorders_) |
| 438 recorder->OnSetFormat(params); | 454 recorder->OnSetFormat(params); |
| 439 } | 455 } |
| 440 | 456 |
| 441 } // namespace content | 457 } // namespace content |
| OLD | NEW |