blob: 792b97ff0883f7157a9f11f9cff622a9885b23b3 [file] [log] [blame]
pbos@webrtc.org2a9108f2013-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
pbos@webrtc.org24e20892013-10-28 16:32:0111#include "webrtc/test/vcm_capturer.h"
pbos@webrtc.org2a9108f2013-05-16 12:08:0312
Henrik Kjellandere22c7db2015-11-12 11:46:0913#include "webrtc/modules/video_capture/video_capture_factory.h"
pbos@webrtc.org24e20892013-10-28 16:32:0114#include "webrtc/video_send_stream.h"
pbos@webrtc.org2a9108f2013-05-16 12:08:0315
16namespace webrtc {
17namespace test {
18
Peter Boströmd5d98ba2015-06-26 04:58:1619VcmCapturer::VcmCapturer(webrtc::VideoCaptureInput* input)
20 : VideoCapturer(input), started_(false), vcm_(NULL) {
21}
pbos@webrtc.org2a9108f2013-05-16 12:08:0322
23bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) {
24 VideoCaptureModule::DeviceInfo* device_info =
25 VideoCaptureFactory::CreateDeviceInfo(42); // Any ID (42) will do.
26
27 char device_name[256];
28 char unique_name[256];
29 if (device_info->GetDeviceName(0, device_name, sizeof(device_name),
30 unique_name, sizeof(unique_name)) !=
31 0) {
32 Destroy();
33 return false;
34 }
35
pbos@webrtc.org61697122013-05-21 09:32:2236 vcm_ = webrtc::VideoCaptureFactory::Create(0, unique_name);
37 vcm_->RegisterCaptureDataCallback(*this);
pbos@webrtc.org2a9108f2013-05-16 12:08:0338
pbos@webrtc.org61697122013-05-21 09:32:2239 device_info->GetCapability(vcm_->CurrentDeviceName(), 0, capability_);
pbos@webrtc.org2a9108f2013-05-16 12:08:0340 delete device_info;
41
42 capability_.width = static_cast<int32_t>(width);
43 capability_.height = static_cast<int32_t>(height);
44 capability_.maxFPS = static_cast<int32_t>(target_fps);
45 capability_.rawType = kVideoI420;
46
pbos@webrtc.org61697122013-05-21 09:32:2247 if (vcm_->StartCapture(capability_) != 0) {
pbos@webrtc.org2a9108f2013-05-16 12:08:0348 Destroy();
49 return false;
50 }
51
pbos@webrtc.org61697122013-05-21 09:32:2252 assert(vcm_->CaptureStarted());
pbos@webrtc.org2a9108f2013-05-16 12:08:0353
54 return true;
55}
56
Peter Boströmd5d98ba2015-06-26 04:58:1657VcmCapturer* VcmCapturer::Create(VideoCaptureInput* input,
58 size_t width,
59 size_t height,
pbos@webrtc.org2a9108f2013-05-16 12:08:0360 size_t target_fps) {
Peter Boström62c9eff2015-10-23 12:45:5561 VcmCapturer* vcm_capturer = new VcmCapturer(input);
62 if (!vcm_capturer->Init(width, height, target_fps)) {
pbos@webrtc.org2a9108f2013-05-16 12:08:0363 // TODO(pbos): Log a warning that this failed.
Peter Boström62c9eff2015-10-23 12:45:5564 delete vcm_capturer;
pbos@webrtc.org2a9108f2013-05-16 12:08:0365 return NULL;
66 }
Peter Boström62c9eff2015-10-23 12:45:5567 return vcm_capturer;
pbos@webrtc.org2a9108f2013-05-16 12:08:0368}
69
70
Peter Boström62c9eff2015-10-23 12:45:5571void VcmCapturer::Start() {
72 rtc::CritScope lock(&crit_);
73 started_ = true;
74}
pbos@webrtc.org2a9108f2013-05-16 12:08:0375
Peter Boström62c9eff2015-10-23 12:45:5576void VcmCapturer::Stop() {
77 rtc::CritScope lock(&crit_);
78 started_ = false;
79}
pbos@webrtc.org2a9108f2013-05-16 12:08:0380
81void VcmCapturer::Destroy() {
Peter Boströmaec92fa2016-03-21 15:44:3182 if (!vcm_)
pbos@webrtc.org2a9108f2013-05-16 12:08:0383 return;
pbos@webrtc.org2a9108f2013-05-16 12:08:0384
pbos@webrtc.org61697122013-05-21 09:32:2285 vcm_->StopCapture();
86 vcm_->DeRegisterCaptureDataCallback();
Peter Boströmaec92fa2016-03-21 15:44:3187 // Release reference to VCM.
88 vcm_ = nullptr;
pbos@webrtc.org2a9108f2013-05-16 12:08:0389}
90
91VcmCapturer::~VcmCapturer() { Destroy(); }
92
93void VcmCapturer::OnIncomingCapturedFrame(const int32_t id,
Miguel Casas-Sanchez3ca60f32015-05-30 00:21:4094 const VideoFrame& frame) {
Peter Boström62c9eff2015-10-23 12:45:5595 rtc::CritScope lock(&crit_);
pbos@webrtc.orgc33d37c2013-12-11 16:26:1696 if (started_)
perkj@webrtc.orgbddb5882015-03-18 09:51:0597 input_->IncomingCapturedFrame(frame);
pbos@webrtc.org2a9108f2013-05-16 12:08:0398}
99
pbos@webrtc.org2a9108f2013-05-16 12:08:03100void VcmCapturer::OnCaptureDelayChanged(const int32_t id, const int32_t delay) {
101}
102} // test
103} // webrtc