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

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

Issue 2764133002: Revert of Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: 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"
14 #include "webrtc/modules/video_capture/video_capture_factory.h" 13 #include "webrtc/modules/video_capture/video_capture_factory.h"
15 #include "webrtc/video_send_stream.h" 14 #include "webrtc/video_send_stream.h"
16 15
17 namespace webrtc { 16 namespace webrtc {
18 namespace test { 17 namespace test {
19 18
20 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(nullptr) {} 19 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(NULL) {}
21 20
22 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) { 21 bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) {
23 std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info( 22 VideoCaptureModule::DeviceInfo* device_info =
24 VideoCaptureFactory::CreateDeviceInfo()); 23 VideoCaptureFactory::CreateDeviceInfo();
25 24
26 char device_name[256]; 25 char device_name[256];
27 char unique_name[256]; 26 char unique_name[256];
28 if (device_info->GetDeviceName(0, device_name, sizeof(device_name), 27 if (device_info->GetDeviceName(0, device_name, sizeof(device_name),
29 unique_name, sizeof(unique_name)) != 28 unique_name, sizeof(unique_name)) !=
30 0) { 29 0) {
31 Destroy(); 30 Destroy();
32 return false; 31 return false;
33 } 32 }
34 33
35 vcm_ = webrtc::VideoCaptureFactory::Create(unique_name); 34 vcm_ = webrtc::VideoCaptureFactory::Create(unique_name);
36 vcm_->RegisterCaptureDataCallback(this); 35 vcm_->RegisterCaptureDataCallback(this);
37 36
38 device_info->GetCapability(vcm_->CurrentDeviceName(), 0, capability_); 37 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 RTC_CHECK(vcm_->CaptureStarted()); 50 assert(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 std::unique_ptr<VcmCapturer> vcm_capturer(new VcmCapturer()); 58 VcmCapturer* vcm_capturer = new VcmCapturer();
59 if (!vcm_capturer->Init(width, height, target_fps)) { 59 if (!vcm_capturer->Init(width, height, target_fps)) {
60 LOG(LS_WARNING) << "Failed to create VcmCapturer(w = " << width 60 // TODO(pbos): Log a warning that this failed.
61 << ", h = " << height << ", fps = " << target_fps << ")"; 61 delete vcm_capturer;
62 return nullptr; 62 return NULL;
63 } 63 }
64 return vcm_capturer.release(); 64 return vcm_capturer;
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);
84 } 83 }
85 84
86 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { 85 void VcmCapturer::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
87 rtc::CritScope lock(&crit_); 86 rtc::CritScope lock(&crit_);
88 RTC_CHECK(sink_ == sink); 87 RTC_CHECK(sink_ == sink);
89 sink_ = nullptr; 88 sink_ = nullptr;
90 } 89 }
91 90
92 void VcmCapturer::Destroy() { 91 void VcmCapturer::Destroy() {
93 if (!vcm_) 92 if (!vcm_)
94 return; 93 return;
95 94
96 vcm_->StopCapture(); 95 vcm_->StopCapture();
97 vcm_->DeRegisterCaptureDataCallback(); 96 vcm_->DeRegisterCaptureDataCallback();
98 // Release reference to VCM. 97 // Release reference to VCM.
99 vcm_ = nullptr; 98 vcm_ = nullptr;
100 } 99 }
101 100
102 VcmCapturer::~VcmCapturer() { Destroy(); } 101 VcmCapturer::~VcmCapturer() { Destroy(); }
103 102
104 void VcmCapturer::OnFrame(const VideoFrame& frame) { 103 void VcmCapturer::OnFrame(const VideoFrame& frame) {
105 rtc::CritScope lock(&crit_); 104 rtc::CritScope lock(&crit_);
106 if (started_ && sink_) { 105 if (started_ && sink_)
107 rtc::Optional<VideoFrame> out_frame = AdaptFrame(frame); 106 sink_->OnFrame(frame);
108 if (out_frame)
109 sink_->OnFrame(*out_frame);
110 }
111 } 107 }
112 108
113 } // test 109 } // test
114 } // webrtc 110 } // 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