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

Side by Side Diff: media/capture/video/win/video_capture_device_mf_win.cc

Issue 2169013002: Change class VideoCaptureDevice::Name to struct VideoCaptureDeviceDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build errors Created 4 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/win/video_capture_device_mf_win.h" 5 #include "media/capture/video/win/video_capture_device_mf_win.h"
6 6
7 #include <mfapi.h> 7 #include <mfapi.h>
8 #include <mferror.h> 8 #include <mferror.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/win/scoped_co_mem.h" 18 #include "base/win/scoped_co_mem.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "media/capture/video/win/capability_list_win.h" 20 #include "media/capture/video/win/capability_list_win.h"
21 21
22 using base::win::ScopedCoMem; 22 using base::win::ScopedCoMem;
23 using base::win::ScopedComPtr; 23 using base::win::ScopedComPtr;
24 24
25 namespace media { 25 namespace media {
26 26
27 // In Windows device identifiers, the USB VID and PID are preceded by the string
28 // "vid_" or "pid_". The identifiers are each 4 bytes long.
29 const char kVidPrefix[] = "vid_"; // Also contains '\0'.
30 const char kPidPrefix[] = "pid_"; // Also contains '\0'.
31 const size_t kVidPidSize = 4;
32
33 static bool GetFrameSize(IMFMediaType* type, gfx::Size* frame_size) { 27 static bool GetFrameSize(IMFMediaType* type, gfx::Size* frame_size) {
34 UINT32 width32, height32; 28 UINT32 width32, height32;
35 if (FAILED(MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width32, &height32))) 29 if (FAILED(MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width32, &height32)))
36 return false; 30 return false;
37 frame_size->SetSize(width32, height32); 31 frame_size->SetSize(width32, height32);
38 return true; 32 return true;
39 } 33 }
40 34
41 static bool GetFrameRate(IMFMediaType* type, float* frame_rate) { 35 static bool GetFrameRate(IMFMediaType* type, float* frame_rate) {
42 UINT32 numerator, denominator; 36 UINT32 numerator, denominator;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 for (const auto& kFormat : kFormatMap) { 175 for (const auto& kFormat : kFormatMap) {
182 if (kFormat.guid == guid) { 176 if (kFormat.guid == guid) {
183 *format = kFormat.format; 177 *format = kFormat.format;
184 return true; 178 return true;
185 } 179 }
186 } 180 }
187 181
188 return false; 182 return false;
189 } 183 }
190 184
191 const std::string VideoCaptureDevice::Name::GetModel() const { 185 VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin(
192 const size_t vid_prefix_size = sizeof(kVidPrefix) - 1; 186 const VideoCaptureDeviceDescriptor& device_descriptor)
193 const size_t pid_prefix_size = sizeof(kPidPrefix) - 1; 187 : descriptor_(device_descriptor), capture_(0) {
194 const size_t vid_location = unique_id_.find(kVidPrefix);
195 if (vid_location == std::string::npos ||
196 vid_location + vid_prefix_size + kVidPidSize > unique_id_.size()) {
197 return std::string();
198 }
199 const size_t pid_location = unique_id_.find(kPidPrefix);
200 if (pid_location == std::string::npos ||
201 pid_location + pid_prefix_size + kVidPidSize > unique_id_.size()) {
202 return std::string();
203 }
204 std::string id_vendor =
205 unique_id_.substr(vid_location + vid_prefix_size, kVidPidSize);
206 std::string id_product =
207 unique_id_.substr(pid_location + pid_prefix_size, kVidPidSize);
208 return id_vendor + ":" + id_product;
209 }
210
211 VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin(const Name& device_name)
212 : name_(device_name), capture_(0) {
213 DetachFromThread(); 188 DetachFromThread();
214 } 189 }
215 190
216 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { 191 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() {
217 DCHECK(CalledOnValidThread()); 192 DCHECK(CalledOnValidThread());
218 } 193 }
219 194
220 bool VideoCaptureDeviceMFWin::Init( 195 bool VideoCaptureDeviceMFWin::Init(
221 const base::win::ScopedComPtr<IMFMediaSource>& source) { 196 const base::win::ScopedComPtr<IMFMediaSource>& source) {
222 DCHECK(CalledOnValidThread()); 197 DCHECK(CalledOnValidThread());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 HRESULT hr) { 306 HRESULT hr) {
332 if (client_.get()) { 307 if (client_.get()) {
333 client_->OnError( 308 client_->OnError(
334 from_here, 309 from_here,
335 base::StringPrintf("VideoCaptureDeviceMFWin: %s", 310 base::StringPrintf("VideoCaptureDeviceMFWin: %s",
336 logging::SystemErrorCodeToString(hr).c_str())); 311 logging::SystemErrorCodeToString(hr).c_str()));
337 } 312 }
338 } 313 }
339 314
340 } // namespace media 315 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/win/video_capture_device_mf_win.h ('k') | media/capture/video/win/video_capture_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698