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

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

Issue 2716643002: Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: windows warning 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
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/api/video/i420_buffer.h"
14 #include "webrtc/media/base/videoadapter.h"
13 #include "webrtc/modules/video_capture/video_capture_factory.h" 15 #include "webrtc/modules/video_capture/video_capture_factory.h"
14 #include "webrtc/video_send_stream.h" 16 #include "webrtc/video_send_stream.h"
15 17
16 namespace webrtc { 18 namespace webrtc {
17 namespace test { 19 namespace test {
18 20
19 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(NULL) {} 21 VcmCapturer::VcmCapturer()
22 : started_(false),
23 sink_(nullptr),
24 vcm_(nullptr),
25 video_adpter_(new cricket::VideoAdapter()) {}
20 26
21 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) { 27 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) {
22 VideoCaptureModule::DeviceInfo* device_info = 28 VideoCaptureModule::DeviceInfo* device_info =
23 VideoCaptureFactory::CreateDeviceInfo(); 29 VideoCaptureFactory::CreateDeviceInfo();
24 30
25 char device_name[256]; 31 char device_name[256];
26 char unique_name[256]; 32 char unique_name[256];
27 if (device_info->GetDeviceName(0, device_name, sizeof(device_name), 33 if (device_info->GetDeviceName(0, device_name, sizeof(device_name),
28 unique_name, sizeof(unique_name)) != 34 unique_name, sizeof(unique_name)) !=
29 0) { 35 0) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void VcmCapturer::Stop() { 79 void VcmCapturer::Stop() {
74 rtc::CritScope lock(&crit_); 80 rtc::CritScope lock(&crit_);
75 started_ = false; 81 started_ = false;
76 } 82 }
77 83
78 void VcmCapturer::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, 84 void VcmCapturer::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
79 const rtc::VideoSinkWants& wants) { 85 const rtc::VideoSinkWants& wants) {
80 rtc::CritScope lock(&crit_); 86 rtc::CritScope lock(&crit_);
81 RTC_CHECK(!sink_ || sink_ == sink); 87 RTC_CHECK(!sink_ || sink_ == sink);
82 sink_ = sink; 88 sink_ = sink;
89 video_adpter_->OnResolutionFramerateRequest(
90 wants.target_pixel_count, wants.max_pixel_count, wants.max_framerate_fps);
83 } 91 }
84 92
85 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { 93 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
86 rtc::CritScope lock(&crit_); 94 rtc::CritScope lock(&crit_);
87 RTC_CHECK(sink_ == sink); 95 RTC_CHECK(sink_ == sink);
88 sink_ = nullptr; 96 sink_ = nullptr;
89 } 97 }
90 98
91 void VcmCapturer::Destroy() { 99 void VcmCapturer::Destroy() {
92 if (!vcm_) 100 if (!vcm_)
93 return; 101 return;
94 102
95 vcm_->StopCapture(); 103 vcm_->StopCapture();
96 vcm_->DeRegisterCaptureDataCallback(); 104 vcm_->DeRegisterCaptureDataCallback();
97 // Release reference to VCM. 105 // Release reference to VCM.
98 vcm_ = nullptr; 106 vcm_ = nullptr;
99 } 107 }
100 108
101 VcmCapturer::~VcmCapturer() { Destroy(); } 109 VcmCapturer::~VcmCapturer() { Destroy(); }
102 110
103 void VcmCapturer::OnFrame(const VideoFrame& frame) { 111 void VcmCapturer::OnFrame(const VideoFrame& frame) {
104 rtc::CritScope lock(&crit_); 112 rtc::CritScope lock(&crit_);
105 if (started_ && sink_) 113 if (started_ && sink_) {
114 int cropped_width = 0;
115 int cropped_height = 0;
116 int out_width = 0;
117 int out_height = 0;
118 if (!video_adpter_->AdaptFrameResolution(
119 frame.width(), frame.height(), frame.timestamp_us() * 1000,
120 &cropped_width, &cropped_height, &out_width, &out_height)) {
121 return;
122 }
123
124 if (out_height != frame.height() || out_width != frame.width()) {
125 rtc::scoped_refptr<I420Buffer> scaled_buffer =
126 I420Buffer::Create(out_width, out_height);
127 scaled_buffer->ScaleFrom(*frame.video_frame_buffer().get());
128 VideoFrame adapted_frame(scaled_buffer, kVideoRotation_0,
129 frame.timestamp_us());
130 sink_->OnFrame(adapted_frame);
131 return;
132 }
kthelgason 2017/03/14 10:01:20 Is it possible to share this logic somewhere so we
sprang_webrtc 2017/03/14 14:15:02 Done. Also did some general cleanup in this class
133
106 sink_->OnFrame(frame); 134 sink_->OnFrame(frame);
135 }
107 } 136 }
108 137
109 } // test 138 } // test
110 } // webrtc 139 } // webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698