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