blob: a037f9eff6593a6e30e7a91503e2dfb543c0c881 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:031/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "test/vcm_capturer.h"
pbos@webrtc.org29d58392013-05-16 12:08:0312
Yves Gerey3e707812018-11-28 15:47:4913#include <stdint.h>
Jonas Olssona4d87372019-07-05 17:08:3314
Yves Gerey3e707812018-11-28 15:47:4915#include <memory>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "modules/video_capture/video_capture_factory.h"
Yves Gerey3e707812018-11-28 15:47:4918#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "rtc_base/logging.h"
Yves Gerey3e707812018-11-28 15:47:4920
pbos@webrtc.org29d58392013-05-16 12:08:0321namespace webrtc {
22namespace test {
23
Niels Möller3793bb42018-12-20 12:46:0624VcmCapturer::VcmCapturer() : vcm_(nullptr) {}
pbos@webrtc.org29d58392013-05-16 12:08:0325
Tarun Chawla8e857d12017-05-31 13:50:5726bool VcmCapturer::Init(size_t width,
27 size_t height,
28 size_t target_fps,
29 size_t capture_device_index) {
sprangc5d62e22017-04-03 06:53:0430 std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info(
31 VideoCaptureFactory::CreateDeviceInfo());
pbos@webrtc.org29d58392013-05-16 12:08:0332
33 char device_name[256];
34 char unique_name[256];
Tarun Chawla8e857d12017-05-31 13:50:5735 if (device_info->GetDeviceName(static_cast<uint32_t>(capture_device_index),
36 device_name, sizeof(device_name), unique_name,
37 sizeof(unique_name)) != 0) {
pbos@webrtc.org29d58392013-05-16 12:08:0338 Destroy();
39 return false;
40 }
41
nisseb29b9c82016-12-12 08:22:5642 vcm_ = webrtc::VideoCaptureFactory::Create(unique_name);
Johnny Lee7248b402019-01-28 16:29:2643 if (!vcm_) {
44 return false;
45 }
nisseb29b9c82016-12-12 08:22:5646 vcm_->RegisterCaptureDataCallback(this);
pbos@webrtc.org29d58392013-05-16 12:08:0347
pbos@webrtc.org375deb42013-05-21 09:32:2248 device_info->GetCapability(vcm_->CurrentDeviceName(), 0, capability_);
pbos@webrtc.org29d58392013-05-16 12:08:0349
50 capability_.width = static_cast<int32_t>(width);
51 capability_.height = static_cast<int32_t>(height);
52 capability_.maxFPS = static_cast<int32_t>(target_fps);
nisseeb44b392017-04-28 14:18:0553 capability_.videoType = VideoType::kI420;
pbos@webrtc.org29d58392013-05-16 12:08:0354
pbos@webrtc.org375deb42013-05-21 09:32:2255 if (vcm_->StartCapture(capability_) != 0) {
pbos@webrtc.org29d58392013-05-16 12:08:0356 Destroy();
57 return false;
58 }
59
sprangc5d62e22017-04-03 06:53:0460 RTC_CHECK(vcm_->CaptureStarted());
pbos@webrtc.org29d58392013-05-16 12:08:0361
62 return true;
63}
64
perkja49cbd32016-09-16 14:53:4165VcmCapturer* VcmCapturer::Create(size_t width,
Peter Boström4b91bd02015-06-26 04:58:1666 size_t height,
Tarun Chawla8e857d12017-05-31 13:50:5767 size_t target_fps,
68 size_t capture_device_index) {
sprangc5d62e22017-04-03 06:53:0469 std::unique_ptr<VcmCapturer> vcm_capturer(new VcmCapturer());
Tarun Chawla8e857d12017-05-31 13:50:5770 if (!vcm_capturer->Init(width, height, target_fps, capture_device_index)) {
Mirko Bonadei675513b2017-11-09 10:09:2571 RTC_LOG(LS_WARNING) << "Failed to create VcmCapturer(w = " << width
72 << ", h = " << height << ", fps = " << target_fps
73 << ")";
sprangc5d62e22017-04-03 06:53:0474 return nullptr;
pbos@webrtc.org29d58392013-05-16 12:08:0375 }
sprangc5d62e22017-04-03 06:53:0476 return vcm_capturer.release();
pbos@webrtc.org29d58392013-05-16 12:08:0377}
78
pbos@webrtc.org29d58392013-05-16 12:08:0379void VcmCapturer::Destroy() {
Peter Boström1d194412016-03-21 15:44:3180 if (!vcm_)
pbos@webrtc.org29d58392013-05-16 12:08:0381 return;
pbos@webrtc.org29d58392013-05-16 12:08:0382
pbos@webrtc.org375deb42013-05-21 09:32:2283 vcm_->StopCapture();
84 vcm_->DeRegisterCaptureDataCallback();
Peter Boström1d194412016-03-21 15:44:3185 // Release reference to VCM.
86 vcm_ = nullptr;
pbos@webrtc.org29d58392013-05-16 12:08:0387}
88
Yves Gerey665174f2018-06-19 13:03:0589VcmCapturer::~VcmCapturer() {
90 Destroy();
91}
pbos@webrtc.org29d58392013-05-16 12:08:0392
nisseb29b9c82016-12-12 08:22:5693void VcmCapturer::OnFrame(const VideoFrame& frame) {
Niels Möller3793bb42018-12-20 12:46:0694 TestVideoCapturer::OnFrame(frame);
pbos@webrtc.org29d58392013-05-16 12:08:0395}
96
Yves Gerey665174f2018-06-19 13:03:0597} // namespace test
98} // namespace webrtc