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