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 | |
| 11 | #ifndef WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_ |
| 12 | #define WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_ |
| 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 | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 17 | #include "webrtc/api/videotracksource.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 18 | #include "webrtc/base/asyncinvoker.h" |
| 19 | #include "webrtc/base/scoped_ptr.h" |
| 20 | #include "webrtc/base/sigslot.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 21 | #include "webrtc/media/base/videocapturer.h" |
| 22 | #include "webrtc/media/base/videocommon.h" |
| 23 | |
| 24 | // VideoCapturerTrackSource implements VideoTrackSourceInterface. It owns a |
| 25 | // cricket::VideoCapturer and make sure the camera is started at a resolution |
| 26 | // that honors the constraints. |
| 27 | // The state is set depending on the result of starting the capturer. |
| 28 | // If the constraint can't be met or the capturer fails to start, the state |
| 29 | // transition to kEnded, otherwise it transitions to kLive. |
| 30 | namespace webrtc { |
| 31 | |
| 32 | class MediaConstraintsInterface; |
| 33 | |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 34 | class VideoCapturerTrackSource : public VideoTrackSource, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 35 | public sigslot::has_slots<> { |
| 36 | public: |
| 37 | // Creates an instance of VideoCapturerTrackSource. |
| 38 | // VideoCapturerTrackSource take ownership of |capturer|. |
| 39 | // |constraints| can be NULL and in that case the camera is opened using a |
| 40 | // default resolution. |
| 41 | static rtc::scoped_refptr<VideoTrackSourceInterface> Create( |
| 42 | rtc::Thread* worker_thread, |
| 43 | cricket::VideoCapturer* capturer, |
| 44 | const webrtc::MediaConstraintsInterface* constraints, |
| 45 | bool remote); |
| 46 | |
| 47 | static rtc::scoped_refptr<VideoTrackSourceInterface> Create( |
| 48 | rtc::Thread* worker_thread, |
| 49 | cricket::VideoCapturer* capturer, |
| 50 | bool remote); |
| 51 | |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 52 | bool is_screencast() const override { |
| 53 | return video_capturer_->IsScreencast(); |
| 54 | } |
Per | c0d31e9 | 2016-03-31 17:23:39 +0200 | [diff] [blame] | 55 | rtc::Optional<bool> needs_denoising() const override { |
| 56 | return needs_denoising_; |
| 57 | } |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 58 | |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 59 | bool GetStats(Stats* stats) override; |
| 60 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 61 | void Stop() override; |
| 62 | void Restart() override; |
| 63 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 64 | protected: |
| 65 | VideoCapturerTrackSource(rtc::Thread* worker_thread, |
| 66 | cricket::VideoCapturer* capturer, |
| 67 | bool remote); |
| 68 | virtual ~VideoCapturerTrackSource(); |
| 69 | void Initialize(const webrtc::MediaConstraintsInterface* constraints); |
| 70 | |
| 71 | private: |
| 72 | void OnStateChange(cricket::VideoCapturer* capturer, |
| 73 | cricket::CaptureState capture_state); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 74 | |
| 75 | rtc::Thread* signaling_thread_; |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 76 | rtc::Thread* worker_thread_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 77 | rtc::AsyncInvoker invoker_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame^] | 78 | std::unique_ptr<cricket::VideoCapturer> video_capturer_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 79 | bool started_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 80 | cricket::VideoFormat format_; |
Per | c0d31e9 | 2016-03-31 17:23:39 +0200 | [diff] [blame] | 81 | rtc::Optional<bool> needs_denoising_; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace webrtc |
| 85 | |
| 86 | #endif // WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_ |