OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
11 #include "webrtc/test/vcm_capturer.h" | 11 #include "webrtc/test/vcm_capturer.h" |
12 | 12 |
13 #include "webrtc/modules/video_capture/video_capture_factory.h" | 13 #include "webrtc/modules/video_capture/video_capture_factory.h" |
14 #include "webrtc/video_send_stream.h" | 14 #include "webrtc/video_send_stream.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 namespace test { | 17 namespace test { |
18 | 18 |
19 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(NULL) {} | 19 VcmCapturer::VcmCapturer(webrtc::VideoCaptureInput* input) |
| 20 : VideoCapturer(input), started_(false), vcm_(NULL) { |
| 21 } |
20 | 22 |
21 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) { | 23 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) { |
22 VideoCaptureModule::DeviceInfo* device_info = | 24 VideoCaptureModule::DeviceInfo* device_info = |
23 VideoCaptureFactory::CreateDeviceInfo(42); // Any ID (42) will do. | 25 VideoCaptureFactory::CreateDeviceInfo(42); // Any ID (42) will do. |
24 | 26 |
25 char device_name[256]; | 27 char device_name[256]; |
26 char unique_name[256]; | 28 char unique_name[256]; |
27 if (device_info->GetDeviceName(0, device_name, sizeof(device_name), | 29 if (device_info->GetDeviceName(0, device_name, sizeof(device_name), |
28 unique_name, sizeof(unique_name)) != | 30 unique_name, sizeof(unique_name)) != |
29 0) { | 31 0) { |
(...skipping 15 matching lines...) Expand all Loading... |
45 if (vcm_->StartCapture(capability_) != 0) { | 47 if (vcm_->StartCapture(capability_) != 0) { |
46 Destroy(); | 48 Destroy(); |
47 return false; | 49 return false; |
48 } | 50 } |
49 | 51 |
50 assert(vcm_->CaptureStarted()); | 52 assert(vcm_->CaptureStarted()); |
51 | 53 |
52 return true; | 54 return true; |
53 } | 55 } |
54 | 56 |
55 VcmCapturer* VcmCapturer::Create(size_t width, | 57 VcmCapturer* VcmCapturer::Create(VideoCaptureInput* input, |
| 58 size_t width, |
56 size_t height, | 59 size_t height, |
57 size_t target_fps) { | 60 size_t target_fps) { |
58 VcmCapturer* vcm_capturer = new VcmCapturer(); | 61 VcmCapturer* vcm_capturer = new VcmCapturer(input); |
59 if (!vcm_capturer->Init(width, height, target_fps)) { | 62 if (!vcm_capturer->Init(width, height, target_fps)) { |
60 // TODO(pbos): Log a warning that this failed. | 63 // TODO(pbos): Log a warning that this failed. |
61 delete vcm_capturer; | 64 delete vcm_capturer; |
62 return NULL; | 65 return NULL; |
63 } | 66 } |
64 return vcm_capturer; | 67 return vcm_capturer; |
65 } | 68 } |
66 | 69 |
67 | 70 |
68 void VcmCapturer::Start() { | 71 void VcmCapturer::Start() { |
69 rtc::CritScope lock(&crit_); | 72 rtc::CritScope lock(&crit_); |
70 started_ = true; | 73 started_ = true; |
71 } | 74 } |
72 | 75 |
73 void VcmCapturer::Stop() { | 76 void VcmCapturer::Stop() { |
74 rtc::CritScope lock(&crit_); | 77 rtc::CritScope lock(&crit_); |
75 started_ = false; | 78 started_ = false; |
76 } | 79 } |
77 | 80 |
78 void VcmCapturer::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, | |
79 const rtc::VideoSinkWants& wants) { | |
80 rtc::CritScope lock(&crit_); | |
81 RTC_CHECK(!sink_); | |
82 sink_ = sink; | |
83 } | |
84 | |
85 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { | |
86 rtc::CritScope lock(&crit_); | |
87 RTC_CHECK(sink_ == sink); | |
88 sink_ = nullptr; | |
89 } | |
90 | |
91 void VcmCapturer::Destroy() { | 81 void VcmCapturer::Destroy() { |
92 if (!vcm_) | 82 if (!vcm_) |
93 return; | 83 return; |
94 | 84 |
95 vcm_->StopCapture(); | 85 vcm_->StopCapture(); |
96 vcm_->DeRegisterCaptureDataCallback(); | 86 vcm_->DeRegisterCaptureDataCallback(); |
97 // Release reference to VCM. | 87 // Release reference to VCM. |
98 vcm_ = nullptr; | 88 vcm_ = nullptr; |
99 } | 89 } |
100 | 90 |
101 VcmCapturer::~VcmCapturer() { Destroy(); } | 91 VcmCapturer::~VcmCapturer() { Destroy(); } |
102 | 92 |
103 void VcmCapturer::OnIncomingCapturedFrame(const int32_t id, | 93 void VcmCapturer::OnIncomingCapturedFrame(const int32_t id, |
104 const VideoFrame& frame) { | 94 const VideoFrame& frame) { |
105 rtc::CritScope lock(&crit_); | 95 rtc::CritScope lock(&crit_); |
106 if (started_ && sink_) | 96 if (started_) |
107 sink_->OnFrame(frame); | 97 input_->IncomingCapturedFrame(frame); |
108 } | 98 } |
109 | 99 |
110 void VcmCapturer::OnCaptureDelayChanged(const int32_t id, const int32_t delay) { | 100 void VcmCapturer::OnCaptureDelayChanged(const int32_t id, const int32_t delay) { |
111 } | 101 } |
112 } // test | 102 } // test |
113 } // webrtc | 103 } // webrtc |
OLD | NEW |