OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 { FOURCC_UYVY, webrtc::kVideoUYVY }, // 16 bpp, fast conversion. | 45 { FOURCC_UYVY, webrtc::kVideoUYVY }, // 16 bpp, fast conversion. |
46 { FOURCC_NV12, webrtc::kVideoNV12 }, // 12 bpp, fast conversion. | 46 { FOURCC_NV12, webrtc::kVideoNV12 }, // 12 bpp, fast conversion. |
47 { FOURCC_NV21, webrtc::kVideoNV21 }, // 12 bpp, fast conversion. | 47 { FOURCC_NV21, webrtc::kVideoNV21 }, // 12 bpp, fast conversion. |
48 { FOURCC_MJPG, webrtc::kVideoMJPEG }, // compressed, slow conversion. | 48 { FOURCC_MJPG, webrtc::kVideoMJPEG }, // compressed, slow conversion. |
49 { FOURCC_ARGB, webrtc::kVideoARGB }, // 32 bpp, slow conversion. | 49 { FOURCC_ARGB, webrtc::kVideoARGB }, // 32 bpp, slow conversion. |
50 { FOURCC_24BG, webrtc::kVideoRGB24 }, // 24 bpp, slow conversion. | 50 { FOURCC_24BG, webrtc::kVideoRGB24 }, // 24 bpp, slow conversion. |
51 }; | 51 }; |
52 | 52 |
53 class WebRtcVcmFactory : public WebRtcVcmFactoryInterface { | 53 class WebRtcVcmFactory : public WebRtcVcmFactoryInterface { |
54 public: | 54 public: |
55 virtual webrtc::VideoCaptureModule* Create(int id, const char* device) { | 55 virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create( |
| 56 int id, |
| 57 const char* device) { |
56 return webrtc::VideoCaptureFactory::Create(id, device); | 58 return webrtc::VideoCaptureFactory::Create(id, device); |
57 } | 59 } |
58 virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo(int id) { | 60 virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo(int id) { |
59 return webrtc::VideoCaptureFactory::CreateDeviceInfo(id); | 61 return webrtc::VideoCaptureFactory::CreateDeviceInfo(id); |
60 } | 62 } |
61 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) { | 63 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) { |
62 delete info; | 64 delete info; |
63 } | 65 } |
64 }; | 66 }; |
65 | 67 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 123 |
122 WebRtcVideoCapturer::WebRtcVideoCapturer(WebRtcVcmFactoryInterface* factory) | 124 WebRtcVideoCapturer::WebRtcVideoCapturer(WebRtcVcmFactoryInterface* factory) |
123 : factory_(factory), | 125 : factory_(factory), |
124 module_(nullptr), | 126 module_(nullptr), |
125 captured_frames_(0), | 127 captured_frames_(0), |
126 start_thread_(nullptr), | 128 start_thread_(nullptr), |
127 async_invoker_(nullptr) { | 129 async_invoker_(nullptr) { |
128 set_frame_factory(new WebRtcVideoFrameFactory()); | 130 set_frame_factory(new WebRtcVideoFrameFactory()); |
129 } | 131 } |
130 | 132 |
131 WebRtcVideoCapturer::~WebRtcVideoCapturer() { | 133 WebRtcVideoCapturer::~WebRtcVideoCapturer() {} |
132 if (module_) { | |
133 module_->Release(); | |
134 } | |
135 } | |
136 | 134 |
137 bool WebRtcVideoCapturer::Init(const Device& device) { | 135 bool WebRtcVideoCapturer::Init(const Device& device) { |
138 RTC_DCHECK(!start_thread_); | 136 RTC_DCHECK(!start_thread_); |
139 if (module_) { | 137 if (module_) { |
140 LOG(LS_ERROR) << "The capturer is already initialized"; | 138 LOG(LS_ERROR) << "The capturer is already initialized"; |
141 return false; | 139 return false; |
142 } | 140 } |
143 | 141 |
144 webrtc::VideoCaptureModule::DeviceInfo* info = factory_->CreateDeviceInfo(0); | 142 webrtc::VideoCaptureModule::DeviceInfo* info = factory_->CreateDeviceInfo(0); |
145 if (!info) { | 143 if (!info) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return false; | 189 return false; |
192 } | 190 } |
193 | 191 |
194 module_ = factory_->Create(0, vcm_id); | 192 module_ = factory_->Create(0, vcm_id); |
195 if (!module_) { | 193 if (!module_) { |
196 LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id; | 194 LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id; |
197 return false; | 195 return false; |
198 } | 196 } |
199 | 197 |
200 // It is safe to change member attributes now. | 198 // It is safe to change member attributes now. |
201 module_->AddRef(); | |
202 SetId(device.id); | 199 SetId(device.id); |
203 SetSupportedFormats(supported); | 200 SetSupportedFormats(supported); |
204 | 201 |
205 return true; | 202 return true; |
206 } | 203 } |
207 | 204 |
208 bool WebRtcVideoCapturer::Init(webrtc::VideoCaptureModule* module) { | 205 bool WebRtcVideoCapturer::Init( |
| 206 const rtc::scoped_refptr<webrtc::VideoCaptureModule>& module) { |
209 RTC_DCHECK(!start_thread_); | 207 RTC_DCHECK(!start_thread_); |
210 if (module_) { | 208 if (module_) { |
211 LOG(LS_ERROR) << "The capturer is already initialized"; | 209 LOG(LS_ERROR) << "The capturer is already initialized"; |
212 return false; | 210 return false; |
213 } | 211 } |
214 if (!module) { | 212 if (!module) { |
215 LOG(LS_ERROR) << "Invalid VCM supplied"; | 213 LOG(LS_ERROR) << "Invalid VCM supplied"; |
216 return false; | 214 return false; |
217 } | 215 } |
218 // TODO(juberti): Set id and formats. | 216 // TODO(juberti): Set id and formats. |
219 (module_ = module)->AddRef(); | 217 module_ = module; |
220 return true; | 218 return true; |
221 } | 219 } |
222 | 220 |
223 bool WebRtcVideoCapturer::GetBestCaptureFormat(const VideoFormat& desired, | 221 bool WebRtcVideoCapturer::GetBestCaptureFormat(const VideoFormat& desired, |
224 VideoFormat* best_format) { | 222 VideoFormat* best_format) { |
225 if (!best_format) { | 223 if (!best_format) { |
226 return false; | 224 return false; |
227 } | 225 } |
228 | 226 |
229 if (!VideoCapturer::GetBestCaptureFormat(desired, best_format)) { | 227 if (!VideoCapturer::GetBestCaptureFormat(desired, best_format)) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 pixel_width = 1; | 415 pixel_width = 1; |
418 pixel_height = 1; | 416 pixel_height = 1; |
419 // Convert units from VideoFrame RenderTimeMs to CapturedFrame (nanoseconds). | 417 // Convert units from VideoFrame RenderTimeMs to CapturedFrame (nanoseconds). |
420 time_stamp = sample.render_time_ms() * rtc::kNumNanosecsPerMillisec; | 418 time_stamp = sample.render_time_ms() * rtc::kNumNanosecsPerMillisec; |
421 data_size = rtc::checked_cast<uint32_t>(length); | 419 data_size = rtc::checked_cast<uint32_t>(length); |
422 data = buffer; | 420 data = buffer; |
423 rotation = sample.rotation(); | 421 rotation = sample.rotation(); |
424 } | 422 } |
425 | 423 |
426 } // namespace cricket | 424 } // namespace cricket |
OLD | NEW |