blob: b0a2810b7656c15b206c621ab1c19be27bfda82a [file] [log] [blame]
perkj11e18052016-03-07 22:03:23 +01001/*
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
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
15
perkja3ede6c2016-03-08 01:27:48 +010016#include "webrtc/api/mediastreaminterface.h"
perkj0d3eef22016-03-09 02:39:17 +010017#include "webrtc/api/videotracksource.h"
perkja3ede6c2016-03-08 01:27:48 +010018#include "webrtc/base/asyncinvoker.h"
perkja3ede6c2016-03-08 01:27:48 +010019#include "webrtc/base/sigslot.h"
perkja3ede6c2016-03-08 01:27:48 +010020#include "webrtc/media/base/videocapturer.h"
21#include "webrtc/media/base/videocommon.h"
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.
29namespace webrtc {
30
31class MediaConstraintsInterface;
32
perkj0d3eef22016-03-09 02:39:17 +010033class VideoCapturerTrackSource : public VideoTrackSource,
perkja3ede6c2016-03-08 01:27:48 +010034 public sigslot::has_slots<> {
35 public:
36 // Creates an instance of VideoCapturerTrackSource.
37 // VideoCapturerTrackSource take ownership of |capturer|.
38 // |constraints| can be NULL and in that case the camera is opened using a
39 // default resolution.
40 static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
41 rtc::Thread* worker_thread,
42 cricket::VideoCapturer* capturer,
43 const webrtc::MediaConstraintsInterface* constraints,
44 bool remote);
45
46 static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
47 rtc::Thread* worker_thread,
48 cricket::VideoCapturer* capturer,
49 bool remote);
50
perkj0d3eef22016-03-09 02:39:17 +010051 bool is_screencast() const override {
52 return video_capturer_->IsScreencast();
53 }
Perc0d31e92016-03-31 17:23:39 +020054 rtc::Optional<bool> needs_denoising() const override {
55 return needs_denoising_;
56 }
perkj0d3eef22016-03-09 02:39:17 +010057
nissefcc640f2016-04-01 01:10:42 -070058 bool GetStats(Stats* stats) override;
59
perkja3ede6c2016-03-08 01:27:48 +010060 protected:
61 VideoCapturerTrackSource(rtc::Thread* worker_thread,
62 cricket::VideoCapturer* capturer,
63 bool remote);
64 virtual ~VideoCapturerTrackSource();
65 void Initialize(const webrtc::MediaConstraintsInterface* constraints);
66
67 private:
sakal859e8612016-09-06 02:25:08 -070068 void Stop();
69
perkja3ede6c2016-03-08 01:27:48 +010070 void OnStateChange(cricket::VideoCapturer* capturer,
71 cricket::CaptureState capture_state);
perkja3ede6c2016-03-08 01:27:48 +010072
73 rtc::Thread* signaling_thread_;
nisse5b68ab52016-04-07 07:45:54 -070074 rtc::Thread* worker_thread_;
perkja3ede6c2016-03-08 01:27:48 +010075 rtc::AsyncInvoker invoker_;
kwibergd1fe2812016-04-27 06:47:29 -070076 std::unique_ptr<cricket::VideoCapturer> video_capturer_;
perkja3ede6c2016-03-08 01:27:48 +010077 bool started_;
perkja3ede6c2016-03-08 01:27:48 +010078 cricket::VideoFormat format_;
Perc0d31e92016-03-31 17:23:39 +020079 rtc::Optional<bool> needs_denoising_;
perkja3ede6c2016-03-08 01:27:48 +010080};
81
82} // namespace webrtc
83
84#endif // WEBRTC_API_VIDEOCAPTURERTRACKSOURCE_H_