blob: b80323f6b0c50c15b301ee59bf6686b1441323a7 [file] [log] [blame]
perkj11e18052016-03-07 22:03:23 +01001/*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_VIDEOCAPTURERTRACKSOURCE_H_
12#define PC_VIDEOCAPTURERTRACKSOURCE_H_
perkj11e18052016-03-07 22:03:23 +010013
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/mediastreaminterface.h"
17#include "media/base/videocapturer.h"
18#include "media/base/videocommon.h"
19#include "pc/videotracksource.h"
20#include "rtc_base/asyncinvoker.h"
21#include "rtc_base/sigslot.h"
perkja3ede6c2016-03-08 01:27:48 +010022
23// VideoCapturerTrackSource implements VideoTrackSourceInterface. It owns a
24// cricket::VideoCapturer and make sure the camera is started at a resolution
25// that honors the constraints.
26// The state is set depending on the result of starting the capturer.
27// If the constraint can't be met or the capturer fails to start, the state
28// transition to kEnded, otherwise it transitions to kLive.
29namespace webrtc {
30
31class MediaConstraintsInterface;
32
perkj0d3eef22016-03-09 02:39:17 +010033class VideoCapturerTrackSource : public VideoTrackSource,
perkja3ede6c2016-03-08 01:27:48 +010034 public sigslot::has_slots<> {
35 public:
deadbeef39e14da2017-02-13 09:49:58 -080036 // Creates an instance of VideoCapturerTrackSource from |capturer|.
perkja3ede6c2016-03-08 01:27:48 +010037 // |constraints| can be NULL and in that case the camera is opened using a
38 // default resolution.
39 static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
40 rtc::Thread* worker_thread,
deadbeef112b2e92017-02-10 20:13:37 -080041 std::unique_ptr<cricket::VideoCapturer> capturer,
perkja3ede6c2016-03-08 01:27:48 +010042 const webrtc::MediaConstraintsInterface* constraints,
43 bool remote);
44
45 static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
46 rtc::Thread* worker_thread,
deadbeef112b2e92017-02-10 20:13:37 -080047 std::unique_ptr<cricket::VideoCapturer> capturer,
perkja3ede6c2016-03-08 01:27:48 +010048 bool remote);
49
deadbeeff15fb452017-02-25 13:37:59 -080050 bool is_screencast() const final { return video_capturer_->IsScreencast(); }
51 rtc::Optional<bool> needs_denoising() const final { return needs_denoising_; }
perkj0d3eef22016-03-09 02:39:17 +010052
deadbeeff15fb452017-02-25 13:37:59 -080053 bool GetStats(Stats* stats) final;
nissefcc640f2016-04-01 01:10:42 -070054
perkja3ede6c2016-03-08 01:27:48 +010055 protected:
56 VideoCapturerTrackSource(rtc::Thread* worker_thread,
deadbeef112b2e92017-02-10 20:13:37 -080057 std::unique_ptr<cricket::VideoCapturer> capturer,
perkja3ede6c2016-03-08 01:27:48 +010058 bool remote);
59 virtual ~VideoCapturerTrackSource();
60 void Initialize(const webrtc::MediaConstraintsInterface* constraints);
61
62 private:
sakal859e8612016-09-06 02:25:08 -070063 void Stop();
64
perkja3ede6c2016-03-08 01:27:48 +010065 void OnStateChange(cricket::VideoCapturer* capturer,
66 cricket::CaptureState capture_state);
perkja3ede6c2016-03-08 01:27:48 +010067
68 rtc::Thread* signaling_thread_;
nisse5b68ab52016-04-07 07:45:54 -070069 rtc::Thread* worker_thread_;
perkja3ede6c2016-03-08 01:27:48 +010070 rtc::AsyncInvoker invoker_;
kwibergd1fe2812016-04-27 06:47:29 -070071 std::unique_ptr<cricket::VideoCapturer> video_capturer_;
perkja3ede6c2016-03-08 01:27:48 +010072 bool started_;
perkja3ede6c2016-03-08 01:27:48 +010073 cricket::VideoFormat format_;
Perc0d31e92016-03-31 17:23:39 +020074 rtc::Optional<bool> needs_denoising_;
perkja3ede6c2016-03-08 01:27:48 +010075};
76
77} // namespace webrtc
78
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // PC_VIDEOCAPTURERTRACKSOURCE_H_