perkj | 11e1805 | 2016-03-07 22:03:23 +0100 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_VIDEOCAPTURERTRACKSOURCE_H_ |
| 12 | #define PC_VIDEOCAPTURERTRACKSOURCE_H_ |
perkj | 11e1805 | 2016-03-07 22:03:23 +0100 | [diff] [blame] | 13 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #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" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 22 | |
| 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. |
| 29 | namespace webrtc { |
| 30 | |
| 31 | class MediaConstraintsInterface; |
| 32 | |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 33 | class VideoCapturerTrackSource : public VideoTrackSource, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 34 | public sigslot::has_slots<> { |
| 35 | public: |
deadbeef | 39e14da | 2017-02-13 09:49:58 -0800 | [diff] [blame] | 36 | // Creates an instance of VideoCapturerTrackSource from |capturer|. |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 37 | // |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, |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 41 | std::unique_ptr<cricket::VideoCapturer> capturer, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 42 | const webrtc::MediaConstraintsInterface* constraints, |
| 43 | bool remote); |
| 44 | |
| 45 | static rtc::scoped_refptr<VideoTrackSourceInterface> Create( |
| 46 | rtc::Thread* worker_thread, |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 47 | std::unique_ptr<cricket::VideoCapturer> capturer, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 48 | bool remote); |
| 49 | |
deadbeef | f15fb45 | 2017-02-25 13:37:59 -0800 | [diff] [blame] | 50 | bool is_screencast() const final { return video_capturer_->IsScreencast(); } |
| 51 | rtc::Optional<bool> needs_denoising() const final { return needs_denoising_; } |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 52 | |
deadbeef | f15fb45 | 2017-02-25 13:37:59 -0800 | [diff] [blame] | 53 | bool GetStats(Stats* stats) final; |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 54 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 55 | protected: |
| 56 | VideoCapturerTrackSource(rtc::Thread* worker_thread, |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 57 | std::unique_ptr<cricket::VideoCapturer> capturer, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 58 | bool remote); |
| 59 | virtual ~VideoCapturerTrackSource(); |
| 60 | void Initialize(const webrtc::MediaConstraintsInterface* constraints); |
| 61 | |
| 62 | private: |
sakal | 859e861 | 2016-09-06 02:25:08 -0700 | [diff] [blame] | 63 | void Stop(); |
| 64 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 65 | void OnStateChange(cricket::VideoCapturer* capturer, |
| 66 | cricket::CaptureState capture_state); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 67 | |
| 68 | rtc::Thread* signaling_thread_; |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 69 | rtc::Thread* worker_thread_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 70 | rtc::AsyncInvoker invoker_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 71 | std::unique_ptr<cricket::VideoCapturer> video_capturer_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 72 | bool started_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 73 | cricket::VideoFormat format_; |
Per | c0d31e9 | 2016-03-31 17:23:39 +0200 | [diff] [blame] | 74 | rtc::Optional<bool> needs_denoising_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace webrtc |
| 78 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 79 | #endif // PC_VIDEOCAPTURERTRACKSOURCE_H_ |