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

Side by Side Diff: webrtc/test/vcm_capturer.cc

Issue 2716643002: Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: Comments Created 3 years, 9 months 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
« no previous file with comments | « webrtc/test/vcm_capturer.h ('k') | webrtc/test/video_capturer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/logging.h"
13 #include "webrtc/modules/video_capture/video_capture_factory.h" 14 #include "webrtc/modules/video_capture/video_capture_factory.h"
14 #include "webrtc/video_send_stream.h" 15 #include "webrtc/video_send_stream.h"
15 16
16 namespace webrtc { 17 namespace webrtc {
17 namespace test { 18 namespace test {
18 19
19 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(NULL) {} 20 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(nullptr) {}
20 21
21 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) { 22 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) {
22 VideoCaptureModule::DeviceInfo* device_info = 23 std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info(
23 VideoCaptureFactory::CreateDeviceInfo(); 24 VideoCaptureFactory::CreateDeviceInfo());
24 25
25 char device_name[256]; 26 char device_name[256];
26 char unique_name[256]; 27 char unique_name[256];
27 if (device_info->GetDeviceName(0, device_name, sizeof(device_name), 28 if (device_info->GetDeviceName(0, device_name, sizeof(device_name),
28 unique_name, sizeof(unique_name)) != 29 unique_name, sizeof(unique_name)) !=
29 0) { 30 0) {
30 Destroy(); 31 Destroy();
31 return false; 32 return false;
32 } 33 }
33 34
34 vcm_ = webrtc::VideoCaptureFactory::Create(unique_name); 35 vcm_ = webrtc::VideoCaptureFactory::Create(unique_name);
35 vcm_->RegisterCaptureDataCallback(this); 36 vcm_->RegisterCaptureDataCallback(this);
36 37
37 device_info->GetCapability(vcm_->CurrentDeviceName(), 0, capability_); 38 device_info->GetCapability(vcm_->CurrentDeviceName(), 0, capability_);
38 delete device_info;
39 39
40 capability_.width = static_cast<int32_t>(width); 40 capability_.width = static_cast<int32_t>(width);
41 capability_.height = static_cast<int32_t>(height); 41 capability_.height = static_cast<int32_t>(height);
42 capability_.maxFPS = static_cast<int32_t>(target_fps); 42 capability_.maxFPS = static_cast<int32_t>(target_fps);
43 capability_.rawType = kVideoI420; 43 capability_.rawType = kVideoI420;
44 44
45 if (vcm_->StartCapture(capability_) != 0) { 45 if (vcm_->StartCapture(capability_) != 0) {
46 Destroy(); 46 Destroy();
47 return false; 47 return false;
48 } 48 }
49 49
50 assert(vcm_->CaptureStarted()); 50 RTC_CHECK(vcm_->CaptureStarted());
51 51
52 return true; 52 return true;
53 } 53 }
54 54
55 VcmCapturer* VcmCapturer::Create(size_t width, 55 VcmCapturer* VcmCapturer::Create(size_t width,
56 size_t height, 56 size_t height,
57 size_t target_fps) { 57 size_t target_fps) {
58 VcmCapturer* vcm_capturer = new VcmCapturer(); 58 std::unique_ptr<VcmCapturer> vcm_capturer(new VcmCapturer());
59 if (!vcm_capturer->Init(width, height, target_fps)) { 59 if (!vcm_capturer->Init(width, height, target_fps)) {
60 // TODO(pbos): Log a warning that this failed. 60 LOG(LS_WARNING) << "Failed to create VcmCapturer(w = " << width
61 delete vcm_capturer; 61 << ", h = " << height << ", fps = " << target_fps << ")";
62 return NULL; 62 return nullptr;
63 } 63 }
64 return vcm_capturer; 64 return vcm_capturer.release();
65 } 65 }
66 66
67 67
68 void VcmCapturer::Start() { 68 void VcmCapturer::Start() {
69 rtc::CritScope lock(&crit_); 69 rtc::CritScope lock(&crit_);
70 started_ = true; 70 started_ = true;
71 } 71 }
72 72
73 void VcmCapturer::Stop() { 73 void VcmCapturer::Stop() {
74 rtc::CritScope lock(&crit_); 74 rtc::CritScope lock(&crit_);
75 started_ = false; 75 started_ = false;
76 } 76 }
77 77
78 void VcmCapturer::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, 78 void VcmCapturer::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
79 const rtc::VideoSinkWants& wants) { 79 const rtc::VideoSinkWants& wants) {
80 rtc::CritScope lock(&crit_); 80 rtc::CritScope lock(&crit_);
81 RTC_CHECK(!sink_ || sink_ == sink); 81 RTC_CHECK(!sink_ || sink_ == sink);
82 sink_ = sink; 82 sink_ = sink;
83 VideoCapturer::AddOrUpdateSink(sink, wants);
83 } 84 }
84 85
85 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { 86 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
86 rtc::CritScope lock(&crit_); 87 rtc::CritScope lock(&crit_);
87 RTC_CHECK(sink_ == sink); 88 RTC_CHECK(sink_ == sink);
88 sink_ = nullptr; 89 sink_ = nullptr;
89 } 90 }
90 91
91 void VcmCapturer::Destroy() { 92 void VcmCapturer::Destroy() {
92 if (!vcm_) 93 if (!vcm_)
93 return; 94 return;
94 95
95 vcm_->StopCapture(); 96 vcm_->StopCapture();
96 vcm_->DeRegisterCaptureDataCallback(); 97 vcm_->DeRegisterCaptureDataCallback();
97 // Release reference to VCM. 98 // Release reference to VCM.
98 vcm_ = nullptr; 99 vcm_ = nullptr;
99 } 100 }
100 101
101 VcmCapturer::~VcmCapturer() { Destroy(); } 102 VcmCapturer::~VcmCapturer() { Destroy(); }
102 103
103 void VcmCapturer::OnFrame(const VideoFrame& frame) { 104 void VcmCapturer::OnFrame(const VideoFrame& frame) {
104 rtc::CritScope lock(&crit_); 105 rtc::CritScope lock(&crit_);
105 if (started_ && sink_) 106 if (started_ && sink_) {
106 sink_->OnFrame(frame); 107 rtc::Optional<VideoFrame> out_frame = AdaptFrame(frame);
108 if (out_frame)
109 sink_->OnFrame(*out_frame);
110 }
107 } 111 }
108 112
109 } // test 113 } // test
110 } // webrtc 114 } // webrtc
OLDNEW
« no previous file with comments | « webrtc/test/vcm_capturer.h ('k') | webrtc/test/video_capturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698