Delete WebRtcVideoCapturer and related classes.

Bug: webrtc:6353
Change-Id: Iee2d0d10bcfcb85aec81b426167d9e6a9485187f
Reviewed-on: https://webrtc-review.googlesource.com/c/115341
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26125}
This commit is contained in:
Niels Möller 2019-01-03 12:07:13 +01:00 committed by Commit Bot
parent 1dfc4d5065
commit fd87da7a4b
13 changed files with 0 additions and 979 deletions

View file

@ -21,7 +21,6 @@ CPPLINT_BLACKLIST = [
'examples/objc',
'media/base/streamparams.h',
'media/base/videocommon.h',
'media/engine/fakewebrtcdeviceinfo.h',
'media/sctp/sctptransport.cc',
'modules/audio_coding',
'modules/audio_device',

View file

@ -113,7 +113,6 @@ rtc_static_library("rtc_media_base") {
"base/videobroadcaster.h",
"base/videocapturer.cc",
"base/videocapturer.h",
"base/videocapturerfactory.h",
"base/videocommon.cc",
"base/videocommon.h",
"base/videosourcebase.cc",
@ -319,10 +318,6 @@ rtc_static_library("rtc_audio_video") {
"engine/simulcast.h",
"engine/webrtcmediaengine.cc",
"engine/webrtcmediaengine.h",
"engine/webrtcvideocapturer.cc",
"engine/webrtcvideocapturer.h",
"engine/webrtcvideocapturerfactory.cc",
"engine/webrtcvideocapturerfactory.h",
"engine/webrtcvideodecoderfactory.cc",
"engine/webrtcvideodecoderfactory.h",
"engine/webrtcvideoencoderfactory.cc",
@ -494,9 +489,6 @@ if (rtc_include_tests) {
"base/testutils.h",
"engine/fakewebrtccall.cc",
"engine/fakewebrtccall.h",
"engine/fakewebrtcdeviceinfo.h",
"engine/fakewebrtcvcmfactory.h",
"engine/fakewebrtcvideocapturemodule.h",
"engine/fakewebrtcvideoengine.cc",
"engine/fakewebrtcvideoengine.h",
]
@ -602,7 +594,6 @@ if (rtc_include_tests) {
"engine/simulcast_encoder_adapter_unittest.cc",
"engine/simulcast_unittest.cc",
"engine/webrtcmediaengine_unittest.cc",
"engine/webrtcvideocapturer_unittest.cc",
"engine/webrtcvideoencoderfactory_unittest.cc",
"engine/webrtcvideoengine_unittest.cc",
]

View file

@ -14,42 +14,9 @@
#include "api/video/video_frame.h"
#include "api/video/video_source_interface.h"
#include "media/base/videocapturer.h"
namespace cricket {
// Implementation of VideoCaptureListener.
VideoCapturerListener::VideoCapturerListener(VideoCapturer* capturer)
: capturer_(capturer),
last_capture_state_(CS_STARTING),
frame_count_(0),
frame_width_(0),
frame_height_(0),
resolution_changed_(false) {
capturer->SignalStateChange.connect(this,
&VideoCapturerListener::OnStateChange);
capturer->AddOrUpdateSink(this, rtc::VideoSinkWants());
}
VideoCapturerListener::~VideoCapturerListener() {
capturer_->RemoveSink(this);
}
void VideoCapturerListener::OnStateChange(VideoCapturer* capturer,
CaptureState result) {
last_capture_state_ = result;
}
void VideoCapturerListener::OnFrame(const webrtc::VideoFrame& frame) {
++frame_count_;
if (1 == frame_count_) {
frame_width_ = frame.width();
frame_height_ = frame.height();
} else if (frame_width_ != frame.width() || frame_height_ != frame.height()) {
resolution_changed_ = true;
}
}
cricket::StreamParams CreateSimStreamParams(
const std::string& cname,
const std::vector<uint32_t>& ssrcs) {

View file

@ -15,10 +15,8 @@
#include <vector>
#include "media/base/mediachannel.h"
#include "media/base/videocapturer.h"
#include "media/base/videocommon.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
namespace webrtc {
class VideoFrame;
@ -37,32 +35,6 @@ inline std::vector<T> MakeVector(const T a[], size_t s) {
}
#define MAKE_VECTOR(a) cricket::MakeVector(a, arraysize(a))
// Test helper for testing VideoCapturer implementations.
class VideoCapturerListener
: public sigslot::has_slots<>,
public rtc::VideoSinkInterface<webrtc::VideoFrame> {
public:
explicit VideoCapturerListener(VideoCapturer* cap);
~VideoCapturerListener();
CaptureState last_capture_state() const { return last_capture_state_; }
int frame_count() const { return frame_count_; }
int frame_width() const { return frame_width_; }
int frame_height() const { return frame_height_; }
bool resolution_changed() const { return resolution_changed_; }
void OnStateChange(VideoCapturer* capturer, CaptureState state);
void OnFrame(const webrtc::VideoFrame& frame) override;
private:
VideoCapturer* capturer_;
CaptureState last_capture_state_;
int frame_count_;
int frame_width_;
int frame_height_;
bool resolution_changed_;
};
// Checks whether |codecs| contains |codec|; checks using Codec::Matches().
template <class C>
bool ContainsMatchingCodec(const std::vector<C>& codecs, const C& codec) {

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_BASE_VIDEOCAPTURERFACTORY_H_
#define MEDIA_BASE_VIDEOCAPTURERFACTORY_H_
#include <memory>
#include "media/base/device.h"
namespace cricket {
class VideoCapturer;
class VideoDeviceCapturerFactory {
public:
VideoDeviceCapturerFactory() {}
virtual ~VideoDeviceCapturerFactory() {}
virtual std::unique_ptr<VideoCapturer> Create(const Device& device) = 0;
};
} // namespace cricket
#endif // MEDIA_BASE_VIDEOCAPTURERFACTORY_H_

View file

@ -1,116 +0,0 @@
/*
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_
#define MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_
#include <string>
#include <vector>
#include "media/engine/webrtcvideocapturer.h"
#include "rtc_base/stringutils.h"
// Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
class FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo {
public:
struct Device {
Device(const std::string& n, const std::string& i) : name(n), id(i) {}
std::string name;
std::string id;
std::string product;
std::vector<webrtc::VideoCaptureCapability> caps;
};
FakeWebRtcDeviceInfo() {}
void AddDevice(const std::string& device_name, const std::string& device_id) {
devices_.push_back(Device(device_name, device_id));
}
void AddCapability(const std::string& device_id,
const webrtc::VideoCaptureCapability& cap) {
Device* dev =
GetDeviceById(reinterpret_cast<const char*>(device_id.c_str()));
if (!dev)
return;
dev->caps.push_back(cap);
}
virtual uint32_t NumberOfDevices() {
return static_cast<int>(devices_.size());
}
virtual int32_t GetDeviceName(uint32_t device_num,
char* device_name,
uint32_t device_name_len,
char* device_id,
uint32_t device_id_len,
char* product_id,
uint32_t product_id_len) {
Device* dev = GetDeviceByIndex(device_num);
if (!dev)
return -1;
rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
dev->name.c_str());
rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
dev->id.c_str());
if (product_id) {
rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
dev->product.c_str());
}
return 0;
}
virtual int32_t NumberOfCapabilities(const char* device_id) {
Device* dev = GetDeviceById(device_id);
if (!dev)
return -1;
return static_cast<int32_t>(dev->caps.size());
}
virtual int32_t GetCapability(const char* device_id,
const uint32_t device_cap_num,
webrtc::VideoCaptureCapability& cap) {
Device* dev = GetDeviceById(device_id);
if (!dev)
return -1;
if (device_cap_num >= dev->caps.size())
return -1;
cap = dev->caps[device_cap_num];
return 0;
}
virtual int32_t GetOrientation(const char* device_id,
webrtc::VideoRotation& rotation) {
return -1; // not implemented
}
virtual int32_t GetBestMatchedCapability(
const char* device_id,
const webrtc::VideoCaptureCapability& requested,
webrtc::VideoCaptureCapability& resulting) {
return -1; // not implemented
}
virtual int32_t DisplayCaptureSettingsDialogBox(const char* device_id,
const char* dialog_title,
void* parent,
uint32_t x,
uint32_t y) {
return -1; // not implemented
}
Device* GetDeviceByIndex(size_t num) {
return (num < devices_.size()) ? &devices_[num] : NULL;
}
Device* GetDeviceById(const char* device_id) {
for (size_t i = 0; i < devices_.size(); ++i) {
if (devices_[i].id == reinterpret_cast<const char*>(device_id)) {
return &devices_[i];
}
}
return NULL;
}
private:
std::vector<Device> devices_;
};
#endif // MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_

View file

@ -1,42 +0,0 @@
/*
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_ENGINE_FAKEWEBRTCVCMFACTORY_H_
#define MEDIA_ENGINE_FAKEWEBRTCVCMFACTORY_H_
#include <vector>
#include "media/engine/fakewebrtcdeviceinfo.h"
#include "media/engine/fakewebrtcvideocapturemodule.h"
#include "media/engine/webrtcvideocapturer.h"
// Factory class to allow the fakes above to be injected into
// WebRtcVideoCapturer.
class FakeWebRtcVcmFactory : public cricket::WebRtcVcmFactoryInterface {
public:
virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
const char* device_id) {
if (!device_info.GetDeviceById(device_id))
return NULL;
rtc::scoped_refptr<FakeWebRtcVideoCaptureModule> module(
new rtc::RefCountedObject<FakeWebRtcVideoCaptureModule>());
modules.push_back(module);
return module;
}
virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() {
return &device_info;
}
virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) {
}
FakeWebRtcDeviceInfo device_info;
std::vector<rtc::scoped_refptr<FakeWebRtcVideoCaptureModule>> modules;
};
#endif // MEDIA_ENGINE_FAKEWEBRTCVCMFACTORY_H_

View file

@ -1,86 +0,0 @@
/*
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
#define MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
#include <vector>
#include "api/video/i420_buffer.h"
#include "media/engine/webrtcvideocapturer.h"
#include "rtc_base/task_queue_for_test.h"
// Fake class for mocking out webrtc::VideoCaptureModule.
class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule {
public:
FakeWebRtcVideoCaptureModule()
: callback_(NULL), running_(false) {}
~FakeWebRtcVideoCaptureModule() {}
void RegisterCaptureDataCallback(
rtc::VideoSinkInterface<webrtc::VideoFrame>* callback) override {
callback_ = callback;
}
void DeRegisterCaptureDataCallback() override { callback_ = NULL; }
int32_t StartCapture(const webrtc::VideoCaptureCapability& cap) override {
if (running_)
return -1;
cap_ = cap;
running_ = true;
return 0;
}
int32_t StopCapture() override {
running_ = false;
return 0;
}
const char* CurrentDeviceName() const override {
return NULL; // not implemented
}
bool CaptureStarted() override { return running_; }
int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override {
if (!running_)
return -1;
settings = cap_;
return 0;
}
int32_t SetCaptureRotation(webrtc::VideoRotation rotation) override {
return -1; // not implemented
}
bool SetApplyRotation(bool enable) override {
return true; // ignored
}
bool GetApplyRotation() override {
return true; // Rotation compensation is turned on.
}
void SendFrame(int w, int h) {
if (!running_ || !callback_)
return;
task_queue_.SendTask([this, w, h]() {
rtc::scoped_refptr<webrtc::I420Buffer> buffer =
webrtc::I420Buffer::Create(w, h);
// Initialize memory to satisfy DrMemory tests. See
// https://bugs.chromium.org/p/libyuv/issues/detail?id=377
buffer->InitializeData();
callback_->OnFrame(webrtc::VideoFrame(buffer, webrtc::kVideoRotation_0,
0 /* timestamp_us */));
});
}
const webrtc::VideoCaptureCapability& cap() const { return cap_; }
private:
rtc::test::TaskQueueForTest task_queue_{"FakeWebRtcVideoCaptureModule"};
rtc::VideoSinkInterface<webrtc::VideoFrame>* callback_;
bool running_;
webrtc::VideoCaptureCapability cap_;
};
#endif // MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_

View file

@ -1,346 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "media/engine/webrtcvideocapturer.h"
#include <stddef.h>
#include <cstdint>
#include <string>
#include "common_types.h" // NOLINT(build/include)
#include "modules/video_capture/video_capture_defines.h"
#include "modules/video_capture/video_capture_factory.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/thread.h"
#include "rtc_base/timeutils.h"
#if defined(WEBRTC_WIN)
#include "rtc_base/win32.h" // Need this to #include the impl files.
#endif // WEBRTC_WIN
#include "system_wrappers/include/field_trial.h"
namespace cricket {
namespace {
struct kVideoFourCCEntry {
uint32_t fourcc;
webrtc::VideoType webrtc_type;
};
// This indicates our format preferences and defines a mapping between
// webrtc::RawVideoType (from video_capture_defines.h) to our FOURCCs.
kVideoFourCCEntry kSupportedFourCCs[] = {
{FOURCC_I420, webrtc::VideoType::kI420}, // 12 bpp, no conversion.
{FOURCC_YV12, webrtc::VideoType::kYV12}, // 12 bpp, no conversion.
{FOURCC_YUY2, webrtc::VideoType::kYUY2}, // 16 bpp, fast conversion.
{FOURCC_UYVY, webrtc::VideoType::kUYVY}, // 16 bpp, fast conversion.
{FOURCC_NV12, webrtc::VideoType::kNV12}, // 12 bpp, fast conversion.
{FOURCC_NV21, webrtc::VideoType::kNV21}, // 12 bpp, fast conversion.
{FOURCC_MJPG, webrtc::VideoType::kMJPEG}, // compressed, slow conversion.
{FOURCC_ARGB, webrtc::VideoType::kARGB}, // 32 bpp, slow conversion.
{FOURCC_24BG, webrtc::VideoType::kRGB24}, // 24 bpp, slow conversion.
};
bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap,
VideoFormat* format) {
uint32_t fourcc = 0;
for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
if (kSupportedFourCCs[i].webrtc_type == cap.videoType) {
fourcc = kSupportedFourCCs[i].fourcc;
break;
}
}
if (fourcc == 0) {
return false;
}
format->fourcc = fourcc;
format->width = cap.width;
format->height = cap.height;
format->interval = VideoFormat::FpsToInterval(cap.maxFPS);
return true;
}
bool FormatToCapability(const VideoFormat& format,
webrtc::VideoCaptureCapability* cap) {
webrtc::VideoType webrtc_type = webrtc::VideoType::kUnknown;
for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
if (kSupportedFourCCs[i].fourcc == format.fourcc) {
webrtc_type = kSupportedFourCCs[i].webrtc_type;
break;
}
}
if (webrtc_type == webrtc::VideoType::kUnknown) {
return false;
}
cap->width = format.width;
cap->height = format.height;
cap->maxFPS = VideoFormat::IntervalToFps(format.interval);
cap->videoType = webrtc_type;
cap->interlaced = false;
return true;
}
} // namespace
class WebRtcVcmFactory : public WebRtcVcmFactoryInterface {
public:
virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
const char* device) {
return webrtc::VideoCaptureFactory::Create(device);
}
virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() {
return webrtc::VideoCaptureFactory::CreateDeviceInfo();
}
virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) {
delete info;
}
};
///////////////////////////////////////////////////////////////////////////
// Implementation of class WebRtcVideoCapturer
///////////////////////////////////////////////////////////////////////////
WebRtcVideoCapturer::WebRtcVideoCapturer()
: factory_(new WebRtcVcmFactory),
module_(nullptr),
captured_frames_(0),
start_thread_(nullptr) {}
WebRtcVideoCapturer::WebRtcVideoCapturer(WebRtcVcmFactoryInterface* factory)
: factory_(factory),
module_(nullptr),
captured_frames_(0),
start_thread_(nullptr) {}
WebRtcVideoCapturer::~WebRtcVideoCapturer() {}
bool WebRtcVideoCapturer::Init(const Device& device) {
RTC_DCHECK(!start_thread_);
if (module_) {
RTC_LOG(LS_ERROR) << "The capturer is already initialized";
return false;
}
webrtc::VideoCaptureModule::DeviceInfo* info = factory_->CreateDeviceInfo();
if (!info) {
return false;
}
// Find the desired camera, by name.
// In the future, comparing IDs will be more robust.
// TODO(juberti): Figure what's needed to allow this.
int num_cams = info->NumberOfDevices();
char vcm_id[256] = "";
bool found = false;
for (int index = 0; index < num_cams; ++index) {
char vcm_name[256];
if (info->GetDeviceName(index, vcm_name, arraysize(vcm_name), vcm_id,
arraysize(vcm_id)) != -1) {
if (device.name == reinterpret_cast<char*>(vcm_name)) {
found = true;
break;
}
}
}
if (!found) {
RTC_LOG(LS_WARNING) << "Failed to find capturer for id: " << device.id;
factory_->DestroyDeviceInfo(info);
return false;
}
// Enumerate the supported formats.
// TODO(juberti): Find out why this starts/stops the camera...
std::vector<VideoFormat> supported;
int32_t num_caps = info->NumberOfCapabilities(vcm_id);
for (int32_t i = 0; i < num_caps; ++i) {
webrtc::VideoCaptureCapability cap;
if (info->GetCapability(vcm_id, i, cap) != -1) {
VideoFormat format;
if (CapabilityToFormat(cap, &format)) {
supported.push_back(format);
} else {
RTC_LOG(LS_WARNING) << "Ignoring unsupported WebRTC capture format "
<< static_cast<int>(cap.videoType);
}
}
}
factory_->DestroyDeviceInfo(info);
if (supported.empty()) {
RTC_LOG(LS_ERROR) << "Failed to find usable formats for id: " << device.id;
return false;
}
module_ = factory_->Create(vcm_id);
if (!module_) {
RTC_LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id;
return false;
}
// It is safe to change member attributes now.
SetId(device.id);
SetSupportedFormats(supported);
return true;
}
bool WebRtcVideoCapturer::Init(
const rtc::scoped_refptr<webrtc::VideoCaptureModule>& module) {
RTC_DCHECK(!start_thread_);
if (module_) {
RTC_LOG(LS_ERROR) << "The capturer is already initialized";
return false;
}
if (!module) {
RTC_LOG(LS_ERROR) << "Invalid VCM supplied";
return false;
}
// TODO(juberti): Set id and formats.
module_ = module;
return true;
}
bool WebRtcVideoCapturer::GetBestCaptureFormat(const VideoFormat& desired,
VideoFormat* best_format) {
if (!best_format) {
return false;
}
if (!VideoCapturer::GetBestCaptureFormat(desired, best_format)) {
// We maybe using a manually injected VCM which doesn't support enum.
// Use the desired format as the best format.
best_format->width = desired.width;
best_format->height = desired.height;
best_format->fourcc = FOURCC_I420;
best_format->interval = desired.interval;
RTC_LOG(LS_INFO) << "Failed to find best capture format,"
<< " fall back to the requested format "
<< best_format->ToString();
}
return true;
}
void WebRtcVideoCapturer::OnSinkWantsChanged(const rtc::VideoSinkWants& wants) {
// Can't take lock here as this will cause deadlock with
// OnIncomingCapturedFrame. In fact, the whole method, including methods it
// calls, can't take lock.
RTC_DCHECK(module_);
if (webrtc::field_trial::FindFullName("WebRTC-CVO").find("Disabled") == 0)
return;
VideoCapturer::OnSinkWantsChanged(wants);
bool result = module_->SetApplyRotation(wants.rotation_applied);
RTC_CHECK(result);
return;
}
CaptureState WebRtcVideoCapturer::Start(const VideoFormat& capture_format) {
if (!module_) {
RTC_LOG(LS_ERROR) << "The capturer has not been initialized";
return CS_FAILED;
}
if (start_thread_) {
RTC_LOG(LS_ERROR) << "The capturer is already running";
RTC_DCHECK(start_thread_->IsCurrent())
<< "Trying to start capturer on different threads";
return CS_FAILED;
}
start_thread_ = rtc::Thread::Current();
captured_frames_ = 0;
SetCaptureFormat(&capture_format);
webrtc::VideoCaptureCapability cap;
if (!FormatToCapability(capture_format, &cap)) {
RTC_LOG(LS_ERROR) << "Invalid capture format specified";
return CS_FAILED;
}
int64_t start = rtc::TimeMillis();
module_->RegisterCaptureDataCallback(this);
if (module_->StartCapture(cap) != 0) {
RTC_LOG(LS_ERROR) << "Camera '" << GetId() << "' failed to start";
module_->DeRegisterCaptureDataCallback();
SetCaptureFormat(nullptr);
start_thread_ = nullptr;
return CS_FAILED;
}
RTC_LOG(LS_INFO) << "Camera '" << GetId() << "' started with format "
<< capture_format.ToString() << ", elapsed time "
<< rtc::TimeSince(start) << " ms";
SetCaptureState(CS_RUNNING);
return CS_STARTING;
}
void WebRtcVideoCapturer::Stop() {
if (!start_thread_) {
RTC_LOG(LS_ERROR) << "The capturer is already stopped";
return;
}
RTC_DCHECK(start_thread_);
RTC_DCHECK(start_thread_->IsCurrent());
if (IsRunning()) {
// The module is responsible for OnIncomingCapturedFrame being called, if
// we stop it we will get no further callbacks.
module_->StopCapture();
}
module_->DeRegisterCaptureDataCallback();
// TODO(juberti): Determine if the VCM exposes any drop stats we can use.
double drop_ratio = 0.0;
RTC_LOG(LS_INFO) << "Camera '" << GetId() << "' stopped after capturing "
<< captured_frames_ << " frames and dropping " << drop_ratio
<< "%";
SetCaptureFormat(NULL);
start_thread_ = nullptr;
SetCaptureState(CS_STOPPED);
}
bool WebRtcVideoCapturer::IsRunning() {
return (module_ != NULL && module_->CaptureStarted());
}
bool WebRtcVideoCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) {
if (!fourccs) {
return false;
}
fourccs->clear();
for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
fourccs->push_back(kSupportedFourCCs[i].fourcc);
}
return true;
}
void WebRtcVideoCapturer::OnFrame(const webrtc::VideoFrame& sample) {
// This can only happen between Start() and Stop().
RTC_DCHECK(start_thread_);
++captured_frames_;
// Log the size and pixel aspect ratio of the first captured frame.
if (1 == captured_frames_) {
RTC_LOG(LS_INFO) << "Captured frame size " << sample.width() << "x"
<< sample.height() << ". Expected format "
<< GetCaptureFormat()->ToString();
}
VideoCapturer::OnFrame(sample, sample.width(), sample.height());
}
} // namespace cricket

View file

@ -1,87 +0,0 @@
/*
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_
#define MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_
#include <stdint.h>
#include <memory>
#include <vector>
#include "api/video/video_frame.h"
#include "api/video/video_sink_interface.h"
#include "api/video/video_source_interface.h"
#include "media/base/device.h"
#include "media/base/videocapturer.h"
#include "media/base/videocommon.h"
#include "modules/video_capture/video_capture.h"
#include "rtc_base/scoped_ref_ptr.h"
#include "rtc_base/thread.h"
namespace cricket {
// Factory to allow injection of a VCM impl into WebRtcVideoCapturer.
// DeviceInfos do not have a Release() and therefore need an explicit Destroy().
class WebRtcVcmFactoryInterface {
public:
virtual ~WebRtcVcmFactoryInterface() {}
virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
const char* device) = 0;
virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() = 0;
virtual void DestroyDeviceInfo(
webrtc::VideoCaptureModule::DeviceInfo* info) = 0;
};
// WebRTC-based implementation of VideoCapturer.
class WebRtcVideoCapturer : public VideoCapturer,
public rtc::VideoSinkInterface<webrtc::VideoFrame> {
public:
WebRtcVideoCapturer();
explicit WebRtcVideoCapturer(WebRtcVcmFactoryInterface* factory);
virtual ~WebRtcVideoCapturer();
bool Init(const Device& device);
bool Init(const rtc::scoped_refptr<webrtc::VideoCaptureModule>& module);
// Override virtual methods of the parent class VideoCapturer.
bool GetBestCaptureFormat(const VideoFormat& desired,
VideoFormat* best_format) override;
CaptureState Start(const VideoFormat& capture_format) override;
void Stop() override;
bool IsRunning() override;
bool IsScreencast() const override { return false; }
protected:
void OnSinkWantsChanged(const rtc::VideoSinkWants& wants) override;
// Override virtual methods of the parent class VideoCapturer.
bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override;
private:
// Callback when a frame is captured by camera.
void OnFrame(const webrtc::VideoFrame& frame) override;
// Used to signal captured frames on the same thread as invoked Start().
// With WebRTC's current VideoCapturer implementations, this will mean a
// thread hop, but in other implementations (e.g. Chrome) it will be called
// directly from OnIncomingCapturedFrame.
// TODO(tommi): Remove this workaround when we've updated the WebRTC capturers
// to follow the same contract.
void SignalFrameCapturedOnStartThread(const webrtc::VideoFrame& frame);
std::unique_ptr<WebRtcVcmFactoryInterface> factory_;
rtc::scoped_refptr<webrtc::VideoCaptureModule> module_;
int captured_frames_;
std::vector<uint8_t> capture_buffer_;
rtc::Thread* start_thread_; // Set in Start(), unset in Stop();
};
} // namespace cricket
#endif // MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_

View file

@ -1,136 +0,0 @@
/*
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifdef HAVE_WEBRTC_VIDEO
#include <stdio.h>
#include <memory>
#include <vector>
#include "common_types.h" // NOLINT(build/include)
#include "media/base/testutils.h"
#include "media/base/videocommon.h"
#include "media/engine/fakewebrtcdeviceinfo.h"
#include "media/engine/fakewebrtcvcmfactory.h"
#include "media/engine/fakewebrtcvideocapturemodule.h"
#include "media/engine/webrtcvideocapturer.h"
// TODO(http://crbug.com/908819): Add this when Chromium android templates
// stop to consider *_module to have a special meaning. See media/BUILD.gn
// #include "modules/video_capture/video_capture_defines.h"
#include "rtc_base/gunit.h"
#include "test/gtest.h"
using cricket::VideoFormat;
static const char kTestDeviceName[] = "JuberTech FakeCam Q123";
static const char kTestDeviceId[] = "foo://bar/baz";
const VideoFormat kDefaultVideoFormat =
VideoFormat(640, 400, VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY);
class WebRtcVideoCapturerTest : public testing::Test {
public:
WebRtcVideoCapturerTest()
: factory_(new FakeWebRtcVcmFactory),
capturer_(new cricket::WebRtcVideoCapturer(factory_)) {
factory_->device_info.AddDevice(kTestDeviceName, kTestDeviceId);
// add a VGA/I420 capability
webrtc::VideoCaptureCapability vga;
vga.width = 640;
vga.height = 480;
vga.maxFPS = 30;
vga.videoType = webrtc::VideoType::kI420;
factory_->device_info.AddCapability(kTestDeviceId, vga);
}
protected:
FakeWebRtcVcmFactory* factory_; // owned by capturer_
std::unique_ptr<cricket::WebRtcVideoCapturer> capturer_;
};
TEST_F(WebRtcVideoCapturerTest, TestNotOpened) {
EXPECT_EQ("", capturer_->GetId());
EXPECT_TRUE(capturer_->GetSupportedFormats()->empty());
EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
EXPECT_FALSE(capturer_->IsRunning());
}
TEST_F(WebRtcVideoCapturerTest, TestBadInit) {
EXPECT_FALSE(capturer_->Init(cricket::Device("bad-name", "bad-id")));
EXPECT_FALSE(capturer_->IsRunning());
}
TEST_F(WebRtcVideoCapturerTest, TestInit) {
EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId)));
EXPECT_EQ(kTestDeviceId, capturer_->GetId());
EXPECT_TRUE(NULL != capturer_->GetSupportedFormats());
ASSERT_EQ(1U, capturer_->GetSupportedFormats()->size());
EXPECT_EQ(640, (*capturer_->GetSupportedFormats())[0].width);
EXPECT_EQ(480, (*capturer_->GetSupportedFormats())[0].height);
EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); // not started yet
EXPECT_FALSE(capturer_->IsRunning());
}
TEST_F(WebRtcVideoCapturerTest, TestInitVcm) {
EXPECT_TRUE(capturer_->Init(factory_->Create(kTestDeviceId)));
}
TEST_F(WebRtcVideoCapturerTest, TestCapture) {
EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId)));
cricket::VideoCapturerListener listener(capturer_.get());
cricket::VideoFormat format(capturer_->GetSupportedFormats()->at(0));
EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format));
EXPECT_TRUE(capturer_->IsRunning());
ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL);
EXPECT_EQ(format, *capturer_->GetCaptureFormat());
EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener.last_capture_state(), 1000);
factory_->modules[0]->SendFrame(640, 480);
EXPECT_TRUE_WAIT(listener.frame_count() > 0, 5000);
EXPECT_EQ(640, listener.frame_width());
EXPECT_EQ(480, listener.frame_height());
EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format));
capturer_->Stop();
EXPECT_FALSE(capturer_->IsRunning());
EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
EXPECT_EQ_WAIT(cricket::CS_STOPPED, listener.last_capture_state(), 1000);
}
TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) {
EXPECT_TRUE(capturer_->Init(factory_->Create(kTestDeviceId)));
cricket::VideoCapturerListener listener(capturer_.get());
EXPECT_TRUE(capturer_->GetSupportedFormats()->empty());
VideoFormat format;
EXPECT_TRUE(capturer_->GetBestCaptureFormat(kDefaultVideoFormat, &format));
EXPECT_EQ(kDefaultVideoFormat.width, format.width);
EXPECT_EQ(kDefaultVideoFormat.height, format.height);
EXPECT_EQ(kDefaultVideoFormat.interval, format.interval);
EXPECT_EQ(cricket::FOURCC_I420, format.fourcc);
EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format));
EXPECT_TRUE(capturer_->IsRunning());
ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL);
EXPECT_EQ(format, *capturer_->GetCaptureFormat());
EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener.last_capture_state(), 1000);
factory_->modules[0]->SendFrame(640, 480);
EXPECT_TRUE_WAIT(listener.frame_count() > 0, 5000);
EXPECT_EQ(640, listener.frame_width());
EXPECT_EQ(480, listener.frame_height());
EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format));
capturer_->Stop();
EXPECT_FALSE(capturer_->IsRunning());
EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
}
TEST_F(WebRtcVideoCapturerTest, TestCaptureWithoutInit) {
cricket::VideoFormat format;
EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format));
EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
EXPECT_FALSE(capturer_->IsRunning());
}
#endif // HAVE_WEBRTC_VIDEO

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#include <utility>
#include "media/engine/webrtcvideocapturer.h"
#include "media/engine/webrtcvideocapturerfactory.h"
namespace cricket {
std::unique_ptr<VideoCapturer> WebRtcVideoDeviceCapturerFactory::Create(
const Device& device) {
#ifdef HAVE_WEBRTC_VIDEO
std::unique_ptr<WebRtcVideoCapturer> capturer(new WebRtcVideoCapturer());
if (!capturer->Init(device)) {
return std::unique_ptr<VideoCapturer>();
}
return std::move(capturer);
#else
return std::unique_ptr<VideoCapturer>();
#endif
}
} // namespace cricket

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// TODO(pthatcher): Rename file to match class name.
#ifndef MEDIA_ENGINE_WEBRTCVIDEOCAPTURERFACTORY_H_
#define MEDIA_ENGINE_WEBRTCVIDEOCAPTURERFACTORY_H_
#include <memory>
#include "media/base/device.h"
#include "media/base/videocapturer.h"
#include "media/base/videocapturerfactory.h"
namespace cricket {
// Creates instances of cricket::WebRtcVideoCapturer.
class WebRtcVideoDeviceCapturerFactory : public VideoDeviceCapturerFactory {
public:
std::unique_ptr<VideoCapturer> Create(const Device& device) override;
};
} // namespace cricket
#endif // MEDIA_ENGINE_WEBRTCVIDEOCAPTURERFACTORY_H_