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

Side by Side Diff: extensions/renderer/api/display_source/wifi_display/wifi_display_media_manager.cc

Issue 1942713002: [chrome.displaySource][WiFi Display] Consider video encoder capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « no previous file | extensions/renderer/api/display_source/wifi_display/wifi_display_video_encoder.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "extensions/renderer/api/display_source/wifi_display/wifi_display_media _manager.h" 5 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_media _manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "content/public/common/service_registry.h" 10 #include "content/public/common/service_registry.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 format->frame_rate == table[i].frame_rate) { 277 format->frame_rate == table[i].frame_rate) {
278 result->rate_resolution = table[i].rr; 278 result->rate_resolution = table[i].rr;
279 result->type = type; 279 result->type = type;
280 return true; 280 return true;
281 } 281 }
282 } 282 }
283 } 283 }
284 return false; 284 return false;
285 } 285 }
286 286
287 bool FindOptimalFormat( 287 void FindCompatibleFormats(
288 const media::VideoCaptureFormat* capture_format, 288 const media::VideoCaptureFormat* capture_format,
289 const std::vector<wds::H264VideoCodec>& sink_supported_codecs, 289 const std::vector<wds::H264VideoCodec>& sink_supported_codecs,
290 wds::H264VideoFormat* result /*out*/) { 290 std::vector<wds::H264VideoFormat>* result /*out*/) {
291 DCHECK(result); 291 DCHECK(result);
292 for (const wds::H264VideoCodec& codec : sink_supported_codecs) { 292 for (const wds::H264VideoCodec& codec : sink_supported_codecs) {
293 wds::H264VideoFormat format;
293 bool found = 294 bool found =
294 FindRateResolution<wds::CEA>( 295 FindRateResolution<wds::CEA>(
295 capture_format, codec.cea_rr, cea_table, result) || 296 capture_format, codec.cea_rr, cea_table, &format) ||
296 FindRateResolution<wds::VESA>( 297 FindRateResolution<wds::VESA>(
297 capture_format, codec.vesa_rr, vesa_table, result) || 298 capture_format, codec.vesa_rr, vesa_table, &format) ||
298 FindRateResolution<wds::HH>( 299 FindRateResolution<wds::HH>(
299 capture_format, codec.hh_rr, hh_table, result); 300 capture_format, codec.hh_rr, hh_table, &format);
300 if (found) { 301 if (found) {
301 result->profile = codec.profile; 302 format.profile = codec.profile;
302 result->level = codec.level; 303 format.level = codec.level;
303 return true; 304 result->emplace_back(format);
304 } 305 }
305 } 306 }
306 return false;
307 } 307 }
308 308
309 } // namespace 309 } // namespace
310 310
311 wds::H264VideoFormat WiFiDisplayMediaManager::GetOptimalVideoFormat() const { 311 wds::H264VideoFormat WiFiDisplayMediaManager::GetOptimalVideoFormat() const {
312 return optimal_video_format_; 312 return optimal_video_format_;
313 } 313 }
314 314
315 namespace { 315 namespace {
316 316
(...skipping 24 matching lines...) Expand all
341 bool WiFiDisplayMediaManager::InitOptimalVideoFormat( 341 bool WiFiDisplayMediaManager::InitOptimalVideoFormat(
342 const wds::NativeVideoFormat& sink_native_format, 342 const wds::NativeVideoFormat& sink_native_format,
343 const std::vector<wds::H264VideoCodec>& sink_supported_codecs) { 343 const std::vector<wds::H264VideoCodec>& sink_supported_codecs) {
344 const media::VideoCaptureFormat* capture_format = 344 const media::VideoCaptureFormat* capture_format =
345 content::GetCurrentVideoTrackFormat(video_track_); 345 content::GetCurrentVideoTrackFormat(video_track_);
346 if (!capture_format) { 346 if (!capture_format) {
347 error_callback_.Run(kErrorNoVideoFormatData); 347 error_callback_.Run(kErrorNoVideoFormatData);
348 return false; 348 return false;
349 } 349 }
350 350
351 if (!FindOptimalFormat( 351 std::vector<wds::H264VideoFormat> compatible_formats;
352 capture_format, sink_supported_codecs, &optimal_video_format_)) { 352
353 FindCompatibleFormats(
354 capture_format, sink_supported_codecs, &compatible_formats);
355
356 if (compatible_formats.empty()) {
353 error_callback_.Run(kErrorSinkCannotPlayVideo); 357 error_callback_.Run(kErrorSinkCannotPlayVideo);
354 return false; 358 return false;
355 } 359 }
360
361 // The found compatible formats have the same frame rate and resolution but
362 // different video encoder profiles. Pick the appropriate profile from the
363 // supported by video encoder.
364 std::vector<wds::H264Profile> supported_profiles =
365 WiFiDisplayVideoEncoder::FindSupportedProfiles(
366 capture_format->frame_size,
367 capture_format->frame_rate);
368
369 if (supported_profiles.empty()) {
370 error_callback_.Run(kErrorSinkCannotPlayVideo);
371 return false;
372 }
373
374 bool profile_found = false;
375 for (wds::H264Profile profile : supported_profiles) {
376 if (profile_found)
377 break;
378
379 for (const auto& format : compatible_formats) {
380 if (format.profile == profile) {
381 optimal_video_format_ = format;
382 profile_found = true;
383 break;
384 }
385 }
386 }
387
388 if (!profile_found) {
389 error_callback_.Run(kErrorSinkCannotPlayVideo);
390 return false;
391 }
392
356 video_encoder_parameters_.frame_size = capture_format->frame_size; 393 video_encoder_parameters_.frame_size = capture_format->frame_size;
357 video_encoder_parameters_.frame_rate = 394 video_encoder_parameters_.frame_rate =
358 static_cast<int>(capture_format->frame_rate); 395 static_cast<int>(capture_format->frame_rate);
359 video_encoder_parameters_.bit_rate = GetBitRate(capture_format->frame_size); 396 video_encoder_parameters_.bit_rate = GetBitRate(capture_format->frame_size);
360 video_encoder_parameters_.profile = optimal_video_format_.profile; 397 video_encoder_parameters_.profile = optimal_video_format_.profile;
361 video_encoder_parameters_.level = optimal_video_format_.level; 398 video_encoder_parameters_.level = optimal_video_format_.level;
362 video_encoder_parameters_.create_memory_callback = 399 video_encoder_parameters_.create_memory_callback =
363 media::BindToCurrentLoop(base::Bind(&CreateVideoEncodeMemory)); 400 media::BindToCurrentLoop(base::Bind(&CreateVideoEncodeMemory));
364 video_encoder_parameters_.vea_create_callback = 401 video_encoder_parameters_.vea_create_callback =
365 media::BindToCurrentLoop( 402 media::BindToCurrentLoop(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 media::BindToCurrentLoop(on_completed)); 485 media::BindToCurrentLoop(on_completed));
449 } 486 }
450 487
451 void WiFiDisplayMediaManager::ConnectToRemoteService( 488 void WiFiDisplayMediaManager::ConnectToRemoteService(
452 WiFiDisplayMediaServiceRequest request) { 489 WiFiDisplayMediaServiceRequest request) {
453 DCHECK(content::RenderThread::Get()); 490 DCHECK(content::RenderThread::Get());
454 service_registry_->ConnectToRemoteService(std::move(request)); 491 service_registry_->ConnectToRemoteService(std::move(request));
455 } 492 }
456 493
457 } // namespace extensions 494 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api/display_source/wifi_display/wifi_display_video_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698