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

Side by Side Diff: media/capture/video/video_capture_system_impl.cc

Issue 2787703004: [Mojo Video Capture] Fix VideoCaptureManager exposing implementation details to clients (Closed)
Patch Set: Rebase to April 5 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
« no previous file with comments | « media/capture/video/video_capture_system_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "media/capture/video/video_capture_system.h" 5 #include "media/capture/video/video_capture_system_impl.h"
6 6
7 #include "media/base/bind_to_current_loop.h" 7 #include "media/base/bind_to_current_loop.h"
8 8
9 namespace { 9 namespace {
10 10
11 // Compares two VideoCaptureFormat by checking smallest frame_size area, then 11 // Compares two VideoCaptureFormat by checking smallest frame_size area, then
12 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that 12 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that
13 // the first entry for a given resolution has the largest frame rate, as needed 13 // the first entry for a given resolution has the largest frame rate, as needed
14 // by the ConsolidateCaptureFormats() method. 14 // by the ConsolidateCaptureFormats() method.
15 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, 15 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 for (auto& format : *formats) { 50 for (auto& format : *formats) {
51 if (format.pixel_format != media::PIXEL_FORMAT_Y16) 51 if (format.pixel_format != media::PIXEL_FORMAT_Y16)
52 format.pixel_format = media::PIXEL_FORMAT_I420; 52 format.pixel_format = media::PIXEL_FORMAT_I420;
53 } 53 }
54 } 54 }
55 55
56 } // anonymous namespace 56 } // anonymous namespace
57 57
58 namespace media { 58 namespace media {
59 59
60 VideoCaptureSystem::VideoCaptureSystem( 60 VideoCaptureSystemImpl::VideoCaptureSystemImpl(
61 std::unique_ptr<VideoCaptureDeviceFactory> factory) 61 std::unique_ptr<VideoCaptureDeviceFactory> factory)
62 : factory_(std::move(factory)) { 62 : factory_(std::move(factory)) {
63 thread_checker_.DetachFromThread(); 63 thread_checker_.DetachFromThread();
64 } 64 }
65 65
66 VideoCaptureSystem::~VideoCaptureSystem() = default; 66 VideoCaptureSystemImpl::~VideoCaptureSystemImpl() = default;
67 67
68 void VideoCaptureSystem::GetDeviceInfosAsync( 68 void VideoCaptureSystemImpl::GetDeviceInfosAsync(
69 const DeviceInfoCallback& result_callback) { 69 const DeviceInfoCallback& result_callback) {
70 DCHECK(thread_checker_.CalledOnValidThread()); 70 DCHECK(thread_checker_.CalledOnValidThread());
71 // Use of Unretained() is safe assuming that |result_callback| has ownership 71 // Use of Unretained() is safe assuming that |result_callback| has ownership
72 // of |this|. 72 // of |this|.
73 factory_->EnumerateDeviceDescriptors(media::BindToCurrentLoop( 73 factory_->EnumerateDeviceDescriptors(media::BindToCurrentLoop(
74 base::Bind(&VideoCaptureSystem::OnDescriptorsReceived, 74 base::Bind(&VideoCaptureSystemImpl::OnDescriptorsReceived,
75 base::Unretained(this), result_callback))); 75 base::Unretained(this), result_callback)));
76 } 76 }
77 77
78 // Creates a VideoCaptureDevice object. Returns NULL if something goes wrong. 78 // Creates a VideoCaptureDevice object. Returns NULL if something goes wrong.
79 std::unique_ptr<VideoCaptureDevice> VideoCaptureSystem::CreateDevice( 79 std::unique_ptr<VideoCaptureDevice> VideoCaptureSystemImpl::CreateDevice(
80 const std::string& device_id) { 80 const std::string& device_id) {
81 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
82 const VideoCaptureDeviceInfo* device_info = LookupDeviceInfoFromId(device_id); 82 const VideoCaptureDeviceInfo* device_info = LookupDeviceInfoFromId(device_id);
83 if (!device_info) 83 if (!device_info)
84 return nullptr; 84 return nullptr;
85 return factory_->CreateDevice(device_info->descriptor); 85 return factory_->CreateDevice(device_info->descriptor);
86 } 86 }
87 87
88 void VideoCaptureSystem::OnDescriptorsReceived( 88 void VideoCaptureSystemImpl::OnDescriptorsReceived(
89 const DeviceInfoCallback& result_callback, 89 const DeviceInfoCallback& result_callback,
90 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors) { 90 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors) {
91 DCHECK(thread_checker_.CalledOnValidThread()); 91 DCHECK(thread_checker_.CalledOnValidThread());
92 // For devices for which we already have an entry in |devices_info_cache_|, 92 // For devices for which we already have an entry in |devices_info_cache_|,
93 // we do not want to query the |factory_| for supported formats again. We 93 // we do not want to query the |factory_| for supported formats again. We
94 // simply copy them from |devices_info_cache_|. 94 // simply copy them from |devices_info_cache_|.
95 std::vector<VideoCaptureDeviceInfo> new_devices_info_cache; 95 std::vector<VideoCaptureDeviceInfo> new_devices_info_cache;
96 new_devices_info_cache.reserve(descriptors->size()); 96 new_devices_info_cache.reserve(descriptors->size());
97 for (const auto& descriptor : *descriptors) { 97 for (const auto& descriptor : *descriptors) {
98 if (auto* cached_info = LookupDeviceInfoFromId(descriptor.device_id)) { 98 if (auto* cached_info = LookupDeviceInfoFromId(descriptor.device_id)) {
99 new_devices_info_cache.push_back(*cached_info); 99 new_devices_info_cache.push_back(*cached_info);
100 } else { 100 } else {
101 // Query for supported formats in order to create the entry. 101 // Query for supported formats in order to create the entry.
102 VideoCaptureDeviceInfo device_info(descriptor); 102 VideoCaptureDeviceInfo device_info(descriptor);
103 factory_->GetSupportedFormats(descriptor, &device_info.supported_formats); 103 factory_->GetSupportedFormats(descriptor, &device_info.supported_formats);
104 ConsolidateCaptureFormats(&device_info.supported_formats); 104 ConsolidateCaptureFormats(&device_info.supported_formats);
105 new_devices_info_cache.push_back(device_info); 105 new_devices_info_cache.push_back(device_info);
106 } 106 }
107 } 107 }
108 108
109 devices_info_cache_.swap(new_devices_info_cache); 109 devices_info_cache_.swap(new_devices_info_cache);
110 result_callback.Run(devices_info_cache_); 110 result_callback.Run(devices_info_cache_);
111 } 111 }
112 112
113 const VideoCaptureDeviceInfo* VideoCaptureSystem::LookupDeviceInfoFromId( 113 const VideoCaptureDeviceInfo* VideoCaptureSystemImpl::LookupDeviceInfoFromId(
114 const std::string& device_id) { 114 const std::string& device_id) {
115 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
116 auto iter = std::find_if( 116 auto iter = std::find_if(
117 devices_info_cache_.begin(), devices_info_cache_.end(), 117 devices_info_cache_.begin(), devices_info_cache_.end(),
118 [&device_id](const media::VideoCaptureDeviceInfo& device_info) { 118 [&device_id](const media::VideoCaptureDeviceInfo& device_info) {
119 return device_info.descriptor.device_id == device_id; 119 return device_info.descriptor.device_id == device_id;
120 }); 120 });
121 if (iter == devices_info_cache_.end()) 121 if (iter == devices_info_cache_.end())
122 return nullptr; 122 return nullptr;
123 return &(*iter); 123 return &(*iter);
124 } 124 }
125 125
126 } // namespace media 126 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/video_capture_system_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698