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 #import <QTKit/QTKit.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/time.h" | |
11 #include "media/video/capture/mac/video_capture_device_mac_qtkit.h" | |
12 | |
13 namespace media { | |
14 | |
15 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { | |
16 // Loop through all available devices and add to |device_names|. | |
17 device_names->clear(); | |
18 // TODO(mflodman) Return name and id as NSArray* instead of QTCaptureDevice*. | |
19 for (QTCaptureDevice* device in [VideoCaptureDeviceMacQTKit deviceNames]) { | |
20 Name name; | |
21 NSString* qt_device_name = [device localizedDisplayName]; | |
22 name.device_name = [qt_device_name UTF8String]; | |
23 NSString* qt_unique_id = [device uniqueID]; | |
24 name.unique_id = [qt_unique_id UTF8String]; | |
25 device_names->push_back(name); | |
26 } | |
27 } | |
28 | |
29 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { | |
30 VideoCaptureDeviceMac* capture_device = | |
31 new VideoCaptureDeviceMac(device_name); | |
scherkus (not reviewing)
2011/10/07 17:17:55
indent by 2 more spaces
mflodman_chromium_OOO
2011/10/10 12:56:52
Done.
| |
32 if (!capture_device) { | |
scherkus (not reviewing)
2011/10/07 17:17:55
is this checking for a failed memory allocation?
mflodman_chromium_OOO
2011/10/10 12:56:52
Ok, thanks for the info. Removed.
It was done lik
| |
33 LOG(ERROR) << "Could not create VideoCaptureDevice instance."; | |
34 return NULL; | |
35 } | |
36 if (!capture_device->Init()) { | |
37 LOG(ERROR) << "Could not initialize VideoCaptureDevice."; | |
38 delete capture_device; | |
39 return NULL; | |
40 } | |
41 return capture_device; | |
42 } | |
43 | |
44 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) | |
scherkus (not reviewing)
2011/10/07 17:17:55
could you re-order the functions to match header f
mflodman_chromium_OOO
2011/10/10 12:56:52
The only disorder I see is the static VideoCapture
| |
45 : device_name_(device_name), | |
46 observer_(NULL), | |
47 state_(kNotInitialized), | |
48 capture_device_(NULL) { | |
49 } | |
50 | |
51 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { | |
52 [capture_device_ release]; | |
scherkus (not reviewing)
2011/10/07 17:17:55
I'm an ObjC noob, but is it OK to call release on
dmac
2011/10/07 17:38:55
Technically it's a "nil" object, and yes it is ;-)
| |
53 } | |
54 | |
55 void VideoCaptureDeviceMac::Allocate(int width, int height, int frame_rate, | |
56 EventHandler* observer) { | |
57 if (state_ != kIdle) { | |
58 return; | |
scherkus (not reviewing)
2011/10/07 17:17:55
is it an error to call Allocate if we're not idle?
mflodman_chromium_OOO
2011/10/10 12:56:52
Linux and Win returns, instead of DCHECK, and it i
| |
59 } | |
60 | |
61 observer_ = observer; | |
62 NSString* deviceId = | |
63 [NSString stringWithUTF8String:device_name_.unique_id.c_str()]; | |
mflodman_chromium_OOO
2011/10/07 15:15:29
I'll change this to make it autorelease instead.
dmac
2011/10/07 17:38:55
I'm confused, as this is already autoreleased
mflodman_chromium_OOO
2011/10/10 12:56:52
And you're probably confused since I was confused
| |
64 | |
65 if (![capture_device_ setCaptureDevice:deviceId]) { | |
66 SetErrorState("Could not open capture device."); | |
67 return; | |
68 } | |
69 if ([capture_device_ setCaptureCapabilities:height:width:frame_rate] == NO) { | |
70 SetErrorState("Could not configure capture device."); | |
71 return; | |
72 } | |
73 | |
74 state_ = kAllocated; | |
75 Capability current_settings; | |
76 current_settings.color = kARGB; | |
77 current_settings.width = width; | |
78 current_settings.height = height; | |
79 current_settings.frame_rate = frame_rate; | |
80 | |
81 observer_->OnFrameInfo(current_settings); | |
82 } | |
83 | |
84 void VideoCaptureDeviceMac::Start() { | |
85 if (state_ != kAllocated) { | |
scherkus (not reviewing)
2011/10/07 17:17:55
ditto for error / DCHECK-worthiness
mflodman_chromium_OOO
2011/10/10 12:56:52
Done.
| |
86 return; | |
87 } | |
88 if (![capture_device_ startCapture]) { | |
89 SetErrorState("Could not start capture device."); | |
90 return; | |
91 } | |
92 state_ = kCapturing; | |
93 } | |
94 | |
95 void VideoCaptureDeviceMac::Stop() { | |
96 if (state_ != kCapturing) { | |
scherkus (not reviewing)
2011/10/07 17:17:55
ditto for error / DCHECK-worthiness
mflodman_chromium_OOO
2011/10/10 12:56:52
Done.
| |
97 return; | |
98 } | |
99 [capture_device_ stopCapture]; | |
100 state_ = kAllocated; | |
101 } | |
102 | |
103 void VideoCaptureDeviceMac::DeAllocate() { | |
104 if (state_ != kAllocated && state_ != kCapturing) { | |
scherkus (not reviewing)
2011/10/07 17:17:55
ditto for error / DCHECK-worthiness
mflodman_chromium_OOO
2011/10/10 12:56:52
DeAllocate will actually be called twice in most c
| |
105 return; | |
106 } | |
107 if (state_ == kCapturing) { | |
108 [capture_device_ stopCapture]; | |
109 } | |
110 [capture_device_ setCaptureDevice:nil]; | |
111 state_ = kIdle; | |
112 } | |
113 | |
114 const VideoCaptureDevice::Name& VideoCaptureDeviceMac::device_name() { | |
115 return device_name_; | |
116 } | |
117 | |
118 bool VideoCaptureDeviceMac::Init() { | |
dmac
2011/10/07 17:38:55
From an API point of view, does it make sense to h
mflodman_chromium_OOO
2011/10/10 12:56:52
The QTKit code is written right now to match Linux
| |
119 DCHECK(state_ == kNotInitialized); | |
scherkus (not reviewing)
2011/10/07 17:17:55
DCHECK_EQ
mflodman_chromium_OOO
2011/10/10 12:56:52
Done.
| |
120 capture_device_ = [[VideoCaptureDeviceMacQTKit alloc] init]; | |
121 if (capture_device_ == NULL) { | |
122 return false; | |
123 } | |
124 [capture_device_ setFrameReceiver:this]; | |
125 state_ = kIdle; | |
126 return true; | |
127 } | |
128 | |
129 int VideoCaptureDeviceMac::IncomingFrame(void* video_frame, | |
130 int video_frame_length, | |
131 const Capability& frame_info) { | |
132 observer_->OnIncomingCapturedFrame(static_cast<uint8*>(video_frame), | |
133 video_frame_length, | |
134 base::Time::Now()); | |
135 return 0; | |
136 } | |
137 | |
138 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { | |
139 DLOG(ERROR) << reason; | |
140 state_ = kError; | |
141 observer_->OnError(); | |
142 } | |
143 | |
144 } // namespace media | |
OLD | NEW |