2015-01-20 21:36:13 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
|
2015-01-20 21:36:13 +00:00
|
|
|
*
|
2016-02-07 20:46:45 -08:00
|
|
|
* 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.
|
2015-01-20 21:36:13 +00:00
|
|
|
*/
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_
|
|
|
|
|
#define MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-02-26 03:00:35 -08:00
|
|
|
#include <memory>
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_video/libyuv/include/webrtc_libyuv.h"
|
|
|
|
|
#include "media/base/device.h"
|
|
|
|
|
#include "media/base/videocapturer.h"
|
|
|
|
|
#include "modules/video_capture/video_capture.h"
|
|
|
|
|
#include "rtc_base/asyncinvoker.h"
|
|
|
|
|
#include "rtc_base/messagehandler.h"
|
|
|
|
|
#include "rtc_base/scoped_ref_ptr.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
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() {}
|
2016-03-22 17:17:39 +01:00
|
|
|
virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
|
|
|
|
|
const char* device) = 0;
|
2016-12-12 00:22:56 -08:00
|
|
|
virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() = 0;
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual void DestroyDeviceInfo(
|
|
|
|
|
webrtc::VideoCaptureModule::DeviceInfo* info) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// WebRTC-based implementation of VideoCapturer.
|
|
|
|
|
class WebRtcVideoCapturer : public VideoCapturer,
|
2016-12-12 00:22:56 -08:00
|
|
|
public rtc::VideoSinkInterface<webrtc::VideoFrame> {
|
2013-07-10 00:45:36 +00:00
|
|
|
public:
|
|
|
|
|
WebRtcVideoCapturer();
|
|
|
|
|
explicit WebRtcVideoCapturer(WebRtcVcmFactoryInterface* factory);
|
|
|
|
|
virtual ~WebRtcVideoCapturer();
|
|
|
|
|
|
|
|
|
|
bool Init(const Device& device);
|
2016-03-22 17:17:39 +01:00
|
|
|
bool Init(const rtc::scoped_refptr<webrtc::VideoCaptureModule>& module);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Override virtual methods of the parent class VideoCapturer.
|
2016-02-12 13:30:57 +01:00
|
|
|
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; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
protected:
|
2016-02-12 13:30:57 +01:00
|
|
|
void OnSinkWantsChanged(const rtc::VideoSinkWants& wants) override;
|
2013-07-10 00:45:36 +00:00
|
|
|
// Override virtual methods of the parent class VideoCapturer.
|
2016-04-29 06:09:15 -07:00
|
|
|
bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Callback when a frame is captured by camera.
|
2016-12-12 00:22:56 -08:00
|
|
|
void OnFrame(const webrtc::VideoFrame& frame) override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-02-19 17:43:25 +00:00
|
|
|
// 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.
|
2015-10-24 11:14:46 -07:00
|
|
|
void SignalFrameCapturedOnStartThread(const webrtc::VideoFrame& frame);
|
2015-02-19 17:43:25 +00:00
|
|
|
|
2016-02-26 03:00:35 -08:00
|
|
|
std::unique_ptr<WebRtcVcmFactoryInterface> factory_;
|
2016-03-22 17:17:39 +01:00
|
|
|
rtc::scoped_refptr<webrtc::VideoCaptureModule> module_;
|
2013-07-10 00:45:36 +00:00
|
|
|
int captured_frames_;
|
2013-11-05 23:45:14 +00:00
|
|
|
std::vector<uint8_t> capture_buffer_;
|
2015-02-19 17:43:25 +00:00
|
|
|
rtc::Thread* start_thread_; // Set in Start(), unset in Stop();
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|
|
|
|
|
|
2017-10-31 09:53:08 -07:00
|
|
|
#endif // MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_
|