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 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_PC_VIDEOCAPTURERTRACKSOURCE_H_ |
| 12 | #define WEBRTC_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 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 16 | #include "webrtc/api/mediastreaminterface.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 17 | #include "webrtc/base/asyncinvoker.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 18 | #include "webrtc/base/sigslot.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 19 | #include "webrtc/media/base/videocapturer.h" |
| 20 | #include "webrtc/media/base/videocommon.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 21 | #include "webrtc/pc/videotracksource.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 | |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 50 | bool is_screencast() const override { |
| 51 | return video_capturer_->IsScreencast(); |
| 52 | } |
Per | c0d31e9 | 2016-03-31 17:23:39 +0200 | [diff] [blame] | 53 | rtc::Optional<bool> needs_denoising() const override { |
| 54 | return needs_denoising_; |
| 55 | } |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 56 | |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 57 | bool GetStats(Stats* stats) override; |
| 58 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 59 | protected: |
| 60 | VideoCapturerTrackSource(rtc::Thread* worker_thread, |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 61 | std::unique_ptr<cricket::VideoCapturer> capturer, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 62 | bool remote); |
| 63 | virtual ~VideoCapturerTrackSource(); |
| 64 | void Initialize(const webrtc::MediaConstraintsInterface* constraints); |
| 65 | |
| 66 | private: |
sakal | 859e861 | 2016-09-06 02:25:08 -0700 | [diff] [blame] | 67 | void Stop(); |
| 68 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 69 | void OnStateChange(cricket::VideoCapturer* capturer, |
| 70 | cricket::CaptureState capture_state); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 71 | |
| 72 | rtc::Thread* signaling_thread_; |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 73 | rtc::Thread* worker_thread_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 74 | rtc::AsyncInvoker invoker_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 75 | std::unique_ptr<cricket::VideoCapturer> video_capturer_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 76 | bool started_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 77 | cricket::VideoFormat format_; |
Per | c0d31e9 | 2016-03-31 17:23:39 +0200 | [diff] [blame] | 78 | rtc::Optional<bool> needs_denoising_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace webrtc |
| 82 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 83 | #endif // WEBRTC_PC_VIDEOCAPTURERTRACKSOURCE_H_ |