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

Side by Side Diff: webrtc/media/engine/webrtcvideocapturer.cc

Issue 2534553002: Replace VideoCaptureDataCallback by VideoSinkInterface. (Closed)
Patch Set: Break overlong lines. Created 4 years 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 /* 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 29 matching lines...) Expand all
40 { FOURCC_NV12, webrtc::kVideoNV12 }, // 12 bpp, fast conversion. 40 { FOURCC_NV12, webrtc::kVideoNV12 }, // 12 bpp, fast conversion.
41 { FOURCC_NV21, webrtc::kVideoNV21 }, // 12 bpp, fast conversion. 41 { FOURCC_NV21, webrtc::kVideoNV21 }, // 12 bpp, fast conversion.
42 { FOURCC_MJPG, webrtc::kVideoMJPEG }, // compressed, slow conversion. 42 { FOURCC_MJPG, webrtc::kVideoMJPEG }, // compressed, slow conversion.
43 { FOURCC_ARGB, webrtc::kVideoARGB }, // 32 bpp, slow conversion. 43 { FOURCC_ARGB, webrtc::kVideoARGB }, // 32 bpp, slow conversion.
44 { FOURCC_24BG, webrtc::kVideoRGB24 }, // 24 bpp, slow conversion. 44 { FOURCC_24BG, webrtc::kVideoRGB24 }, // 24 bpp, slow conversion.
45 }; 45 };
46 46
47 class WebRtcVcmFactory : public WebRtcVcmFactoryInterface { 47 class WebRtcVcmFactory : public WebRtcVcmFactoryInterface {
48 public: 48 public:
49 virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create( 49 virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
50 int id,
51 const char* device) { 50 const char* device) {
52 return webrtc::VideoCaptureFactory::Create(id, device); 51 return webrtc::VideoCaptureFactory::Create(device);
53 } 52 }
54 virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo(int id) { 53 virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() {
55 return webrtc::VideoCaptureFactory::CreateDeviceInfo(id); 54 return webrtc::VideoCaptureFactory::CreateDeviceInfo();
56 } 55 }
57 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) { 56 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) {
58 delete info; 57 delete info;
59 } 58 }
60 }; 59 };
61 60
62 static bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap, 61 static bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap,
63 VideoFormat* format) { 62 VideoFormat* format) {
64 uint32_t fourcc = 0; 63 uint32_t fourcc = 0;
65 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { 64 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 121
123 WebRtcVideoCapturer::~WebRtcVideoCapturer() {} 122 WebRtcVideoCapturer::~WebRtcVideoCapturer() {}
124 123
125 bool WebRtcVideoCapturer::Init(const Device& device) { 124 bool WebRtcVideoCapturer::Init(const Device& device) {
126 RTC_DCHECK(!start_thread_); 125 RTC_DCHECK(!start_thread_);
127 if (module_) { 126 if (module_) {
128 LOG(LS_ERROR) << "The capturer is already initialized"; 127 LOG(LS_ERROR) << "The capturer is already initialized";
129 return false; 128 return false;
130 } 129 }
131 130
132 webrtc::VideoCaptureModule::DeviceInfo* info = factory_->CreateDeviceInfo(0); 131 webrtc::VideoCaptureModule::DeviceInfo* info = factory_->CreateDeviceInfo();
133 if (!info) { 132 if (!info) {
134 return false; 133 return false;
135 } 134 }
136 135
137 // Find the desired camera, by name. 136 // Find the desired camera, by name.
138 // In the future, comparing IDs will be more robust. 137 // In the future, comparing IDs will be more robust.
139 // TODO(juberti): Figure what's needed to allow this. 138 // TODO(juberti): Figure what's needed to allow this.
140 int num_cams = info->NumberOfDevices(); 139 int num_cams = info->NumberOfDevices();
141 char vcm_id[256] = ""; 140 char vcm_id[256] = "";
142 bool found = false; 141 bool found = false;
(...skipping 29 matching lines...) Expand all
172 } 171 }
173 } 172 }
174 } 173 }
175 factory_->DestroyDeviceInfo(info); 174 factory_->DestroyDeviceInfo(info);
176 175
177 if (supported.empty()) { 176 if (supported.empty()) {
178 LOG(LS_ERROR) << "Failed to find usable formats for id: " << device.id; 177 LOG(LS_ERROR) << "Failed to find usable formats for id: " << device.id;
179 return false; 178 return false;
180 } 179 }
181 180
182 module_ = factory_->Create(0, vcm_id); 181 module_ = factory_->Create(vcm_id);
183 if (!module_) { 182 if (!module_) {
184 LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id; 183 LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id;
185 return false; 184 return false;
186 } 185 }
187 186
188 // It is safe to change member attributes now. 187 // It is safe to change member attributes now.
189 SetId(device.id); 188 SetId(device.id);
190 SetSupportedFormats(supported); 189 SetSupportedFormats(supported);
191 190
192 return true; 191 return true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 265
267 SetCaptureFormat(&capture_format); 266 SetCaptureFormat(&capture_format);
268 267
269 webrtc::VideoCaptureCapability cap; 268 webrtc::VideoCaptureCapability cap;
270 if (!FormatToCapability(capture_format, &cap)) { 269 if (!FormatToCapability(capture_format, &cap)) {
271 LOG(LS_ERROR) << "Invalid capture format specified"; 270 LOG(LS_ERROR) << "Invalid capture format specified";
272 return CS_FAILED; 271 return CS_FAILED;
273 } 272 }
274 273
275 int64_t start = rtc::TimeMillis(); 274 int64_t start = rtc::TimeMillis();
276 module_->RegisterCaptureDataCallback(*this); 275 module_->RegisterCaptureDataCallback(this);
277 if (module_->StartCapture(cap) != 0) { 276 if (module_->StartCapture(cap) != 0) {
278 LOG(LS_ERROR) << "Camera '" << GetId() << "' failed to start"; 277 LOG(LS_ERROR) << "Camera '" << GetId() << "' failed to start";
279 module_->DeRegisterCaptureDataCallback(); 278 module_->DeRegisterCaptureDataCallback();
280 async_invoker_.reset(); 279 async_invoker_.reset();
281 SetCaptureFormat(nullptr); 280 SetCaptureFormat(nullptr);
282 start_thread_ = nullptr; 281 start_thread_ = nullptr;
283 return CS_FAILED; 282 return CS_FAILED;
284 } 283 }
285 284
286 LOG(LS_INFO) << "Camera '" << GetId() << "' started with format " 285 LOG(LS_INFO) << "Camera '" << GetId() << "' started with format "
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 return false; 329 return false;
331 } 330 }
332 331
333 fourccs->clear(); 332 fourccs->clear();
334 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { 333 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
335 fourccs->push_back(kSupportedFourCCs[i].fourcc); 334 fourccs->push_back(kSupportedFourCCs[i].fourcc);
336 } 335 }
337 return true; 336 return true;
338 } 337 }
339 338
340 void WebRtcVideoCapturer::OnIncomingCapturedFrame( 339 void WebRtcVideoCapturer::OnFrame(
341 const int32_t id,
342 const webrtc::VideoFrame& sample) { 340 const webrtc::VideoFrame& sample) {
343 // This can only happen between Start() and Stop(). 341 // This can only happen between Start() and Stop().
344 RTC_DCHECK(start_thread_); 342 RTC_DCHECK(start_thread_);
345 RTC_DCHECK(async_invoker_); 343 RTC_DCHECK(async_invoker_);
346 344
347 ++captured_frames_; 345 ++captured_frames_;
348 // Log the size and pixel aspect ratio of the first captured frame. 346 // Log the size and pixel aspect ratio of the first captured frame.
349 if (1 == captured_frames_) { 347 if (1 == captured_frames_) {
350 LOG(LS_INFO) << "Captured frame size " 348 LOG(LS_INFO) << "Captured frame size "
351 << sample.width() << "x" << sample.height() 349 << sample.width() << "x" << sample.height()
352 << ". Expected format " << GetCaptureFormat()->ToString(); 350 << ". Expected format " << GetCaptureFormat()->ToString();
353 } 351 }
354 352
355 OnFrame(sample, sample.width(), sample.height()); 353 VideoCapturer::OnFrame(sample, sample.width(), sample.height());
356 }
357
358 void WebRtcVideoCapturer::OnCaptureDelayChanged(const int32_t id,
359 const int32_t delay) {
360 LOG(LS_INFO) << "Capture delay changed to " << delay << " ms";
361 } 354 }
362 355
363 } // namespace cricket 356 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideocapturer.h ('k') | webrtc/media/engine/webrtcvideocapturer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698