OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/video/capture/mac/video_capture_device_mac.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/time.h" | |
9 #include "media/video/capture/mac/video_capture_device_mac_qtkit.h" | |
10 | |
11 namespace media { | |
12 | |
13 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { | |
14 // Empty the name list. | |
15 device_names->clear(); | |
16 | |
17 // Get an array of devices. | |
18 NSArray* device_list = [[NSArray alloc] | |
dmac
2011/10/06 23:36:22
couple of things here:
a) no space between : and
mflodman_chromium_OOO
2011/10/07 13:03:51
Removed.
| |
19 initWithArray: [QTCaptureDevice | |
20 inputDevicesWithMediaType:QTMediaTypeVideo]]; | |
21 | |
22 for (unsigned int i = 0; i < device_list.count; ++i) { | |
dmac
2011/10/06 23:36:22
for (QTCaptureDevice *device in [QTCaptureDevice i
mflodman_chromium_OOO
2011/10/07 13:03:51
Done.
| |
23 QTCaptureDevice* capture_device = | |
24 static_cast<QTCaptureDevice*>([device_list objectAtIndex:i]); | |
25 if (capture_device) { | |
dmac
2011/10/06 23:36:22
capture_device won't be null.
mflodman_chromium_OOO
2011/10/07 13:03:51
Removed.
| |
26 Name name; | |
27 NSString* qt_device_name = [capture_device localizedDisplayName]; | |
28 name.device_name = [qt_device_name UTF8String]; | |
29 NSString* qt_unique_id = [capture_device uniqueID]; | |
30 name.unique_id = [qt_unique_id UTF8String]; | |
31 device_names->push_back(name); | |
32 } | |
33 } | |
34 } | |
35 | |
36 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { | |
37 VideoCaptureDeviceMac* capture_device = | |
38 new VideoCaptureDeviceMac(device_name); | |
39 if (!capture_device) { | |
40 return NULL; | |
dmac
2011/10/06 23:36:22
do you not want to at least LOG in either of these
mflodman_chromium_OOO
2011/10/07 13:03:51
Done, added LOG(ERROR) calls.
| |
41 } | |
42 if (!capture_device->Init()) { | |
43 delete capture_device; | |
44 return NULL; | |
45 } | |
46 return capture_device; | |
47 } | |
48 | |
49 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) | |
50 : device_name_(device_name), | |
51 observer_(NULL), | |
52 state_(kIdle), | |
53 capture_device_(NULL) { | |
54 } | |
55 | |
56 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { | |
57 if (capture_device_) { | |
58 [capture_device_ release]; | |
dmac
2011/10/06 23:36:22
no need to check capture_device_.
Just call [captu
mflodman_chromium_OOO
2011/10/07 13:03:51
Done.
| |
59 } | |
60 } | |
61 | |
62 void VideoCaptureDeviceMac::Allocate(int width, int height, int frame_rate, | |
63 EventHandler* observer) { | |
64 if (state_ != kIdle) { | |
65 return; | |
66 } | |
67 if (![capture_device_ setCaptureDevice:device_name_.device_name.c_str()]) { | |
68 SetErrorState("Could not open capture device."); | |
69 return; | |
70 } | |
71 if ([capture_device_ setCaptureHeight:height | |
72 AndWidth:width | |
73 AndFrameRate:frame_rate] == NO) { | |
74 SetErrorState("Could not configure capture device."); | |
75 return; | |
76 } | |
77 | |
78 observer_ = observer; | |
79 state_ = kAllocated; | |
80 Capability current_settings; | |
81 current_settings.color = kARGB; | |
82 current_settings.width = width; | |
83 current_settings.height = height; | |
84 current_settings.frame_rate = frame_rate; | |
85 | |
86 observer_->OnFrameInfo(current_settings); | |
87 return; | |
dmac
2011/10/06 23:36:22
no need for return at end
mflodman_chromium_OOO
2011/10/07 13:03:51
Done.
| |
88 } | |
89 | |
90 void VideoCaptureDeviceMac::Start() { | |
91 if (state_ != kAllocated) { | |
92 return; | |
93 } | |
94 if (![capture_device_ startCapture]) { | |
95 SetErrorState("Could not start capture device."); | |
96 return; | |
97 } | |
98 state_ = kCapturing; | |
99 } | |
100 | |
101 void VideoCaptureDeviceMac::Stop() { | |
102 if (state_ != kCapturing) { | |
103 return; | |
104 } | |
105 [capture_device_ stopCapture]; | |
106 state_ = kAllocated; | |
107 } | |
108 | |
109 void VideoCaptureDeviceMac::DeAllocate() { | |
110 if (state_ != kAllocated && state_ != kCapturing) { | |
111 return; | |
112 } | |
113 if (state_ == kCapturing) { | |
114 [capture_device_ stopCapture]; | |
115 } | |
116 [capture_device_ removeCaptureDevice]; | |
117 state_ = kIdle; | |
118 } | |
119 | |
120 const VideoCaptureDevice::Name& VideoCaptureDeviceMac::device_name() { | |
121 return device_name_; | |
122 } | |
123 | |
124 bool VideoCaptureDeviceMac::Init() { | |
125 capture_device_ = [[VideoCaptureDeviceMacQTKit alloc] init]; | |
dmac
2011/10/06 23:36:22
if folks call init twice we are going to leak a ca
mflodman_chromium_OOO
2011/10/07 13:03:51
Done, added new state + DCHECK.
| |
126 if (capture_device_ == NULL) { | |
127 return false; | |
128 } | |
129 [capture_device_ registerReceiver:this]; | |
130 return true; | |
131 } | |
132 | |
133 int VideoCaptureDeviceMac::IncomingFrame(void* video_frame, | |
134 int video_frame_length, | |
135 const Capability& frame_info) { | |
136 observer_->OnIncomingCapturedFrame(static_cast<uint8*>(video_frame), | |
137 video_frame_length, | |
138 base::Time::Now()); | |
139 return 0; | |
140 } | |
141 | |
142 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { | |
143 DLOG(ERROR) << reason; | |
144 state_ = kError; | |
145 observer_->OnError(); | |
146 } | |
147 | |
148 } // namespace media | |
OLD | NEW |