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 <list> |
perkj | 11e1805 | 2016-03-07 22:03:23 +0100 | [diff] [blame] | 15 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 16 | #include "webrtc/api/mediastreaminterface.h" |
| 17 | #include "webrtc/api/notifier.h" |
| 18 | #include "webrtc/api/videosourceinterface.h" |
| 19 | #include "webrtc/api/videotrackrenderers.h" |
| 20 | #include "webrtc/base/asyncinvoker.h" |
| 21 | #include "webrtc/base/scoped_ptr.h" |
| 22 | #include "webrtc/base/sigslot.h" |
| 23 | #include "webrtc/media/base/videosinkinterface.h" |
| 24 | #include "webrtc/media/base/videocapturer.h" |
| 25 | #include "webrtc/media/base/videocommon.h" |
| 26 | |
| 27 | // VideoCapturerTrackSource implements VideoTrackSourceInterface. It owns a |
| 28 | // cricket::VideoCapturer and make sure the camera is started at a resolution |
| 29 | // that honors the constraints. |
| 30 | // The state is set depending on the result of starting the capturer. |
| 31 | // If the constraint can't be met or the capturer fails to start, the state |
| 32 | // transition to kEnded, otherwise it transitions to kLive. |
| 33 | namespace webrtc { |
| 34 | |
| 35 | class MediaConstraintsInterface; |
| 36 | |
| 37 | class VideoCapturerTrackSource : public Notifier<VideoTrackSourceInterface>, |
| 38 | public sigslot::has_slots<> { |
| 39 | public: |
| 40 | // Creates an instance of VideoCapturerTrackSource. |
| 41 | // VideoCapturerTrackSource take ownership of |capturer|. |
| 42 | // |constraints| can be NULL and in that case the camera is opened using a |
| 43 | // default resolution. |
| 44 | static rtc::scoped_refptr<VideoTrackSourceInterface> Create( |
| 45 | rtc::Thread* worker_thread, |
| 46 | cricket::VideoCapturer* capturer, |
| 47 | const webrtc::MediaConstraintsInterface* constraints, |
| 48 | bool remote); |
| 49 | |
| 50 | static rtc::scoped_refptr<VideoTrackSourceInterface> Create( |
| 51 | rtc::Thread* worker_thread, |
| 52 | cricket::VideoCapturer* capturer, |
| 53 | bool remote); |
| 54 | |
| 55 | SourceState state() const override { return state_; } |
| 56 | bool remote() const override { return remote_; } |
| 57 | |
| 58 | virtual const cricket::VideoOptions* options() const { return &options_; } |
| 59 | |
| 60 | virtual cricket::VideoCapturer* GetVideoCapturer() { |
| 61 | return video_capturer_.get(); |
| 62 | } |
| 63 | |
| 64 | void Stop() override; |
| 65 | void Restart() override; |
| 66 | |
| 67 | void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
| 68 | const rtc::VideoSinkWants& wants) override; |
| 69 | void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; |
| 70 | |
| 71 | protected: |
| 72 | VideoCapturerTrackSource(rtc::Thread* worker_thread, |
| 73 | cricket::VideoCapturer* capturer, |
| 74 | bool remote); |
| 75 | virtual ~VideoCapturerTrackSource(); |
| 76 | void Initialize(const webrtc::MediaConstraintsInterface* constraints); |
| 77 | |
| 78 | private: |
| 79 | void OnStateChange(cricket::VideoCapturer* capturer, |
| 80 | cricket::CaptureState capture_state); |
| 81 | void SetState(SourceState new_state); |
| 82 | |
| 83 | rtc::Thread* signaling_thread_; |
| 84 | rtc::Thread* worker_thread_; |
| 85 | rtc::AsyncInvoker invoker_; |
| 86 | rtc::scoped_ptr<cricket::VideoCapturer> video_capturer_; |
| 87 | bool started_; |
| 88 | rtc::scoped_ptr<cricket::VideoRenderer> frame_input_; |
| 89 | |
| 90 | cricket::VideoFormat format_; |
| 91 | cricket::VideoOptions options_; |
| 92 | SourceState state_; |
| 93 | const bool remote_; |
| 94 | }; |
| 95 | |
| 96 | } // namespace webrtc |
| 97 | |
| 98 | #endif // WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_ |