OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_API_VIDEOSOURCE_H_ | 11 // TODO(perkj): Remove this file once Chrome build files doesn't depend on it. |
12 #define WEBRTC_API_VIDEOSOURCE_H_ | |
13 | |
14 #include <list> | |
15 | |
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 // VideoSource implements VideoSourceInterface. 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 VideoSource : public Notifier<VideoSourceInterface>, | |
38 public sigslot::has_slots<> { | |
39 public: | |
40 // Creates an instance of VideoSource. | |
41 // VideoSource 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<VideoSource> Create( | |
45 rtc::Thread* worker_thread, | |
46 cricket::VideoCapturer* capturer, | |
47 const webrtc::MediaConstraintsInterface* constraints, | |
48 bool remote); | |
49 | |
50 // Note that the non-constraints version does not have the ability to | |
51 // select configuration based on width, height, aspect ratio or frame rate. | |
52 static rtc::scoped_refptr<VideoSource> Create( | |
53 rtc::Thread* worker_thread, | |
54 cricket::VideoCapturer* capturer, | |
55 bool remote); | |
56 | |
57 SourceState state() const override { return state_; } | |
58 bool remote() const override { return remote_; } | |
59 | |
60 virtual const cricket::VideoOptions* options() const { return &options_; } | |
61 | |
62 virtual cricket::VideoCapturer* GetVideoCapturer() { | |
63 return video_capturer_.get(); | |
64 } | |
65 | |
66 void Stop() override; | |
67 void Restart() override; | |
68 | |
69 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | |
70 const rtc::VideoSinkWants& wants) override; | |
71 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; | |
72 | |
73 protected: | |
74 VideoSource(rtc::Thread* worker_thread, | |
75 cricket::VideoCapturer* capturer, | |
76 bool remote); | |
77 virtual ~VideoSource(); | |
78 void Initialize(const webrtc::MediaConstraintsInterface* constraints); | |
79 | |
80 private: | |
81 void OnStateChange(cricket::VideoCapturer* capturer, | |
82 cricket::CaptureState capture_state); | |
83 void SetState(SourceState new_state); | |
84 | |
85 rtc::Thread* signaling_thread_; | |
86 rtc::Thread* worker_thread_; | |
87 rtc::AsyncInvoker invoker_; | |
88 rtc::scoped_ptr<cricket::VideoCapturer> video_capturer_; | |
89 bool started_; | |
90 rtc::scoped_ptr<cricket::VideoRenderer> frame_input_; | |
91 | |
92 cricket::VideoFormat format_; | |
93 cricket::VideoOptions options_; | |
94 SourceState state_; | |
95 const bool remote_; | |
96 }; | |
97 | |
98 } // namespace webrtc | |
99 | |
100 #endif // WEBRTC_API_VIDEOSOURCE_H_ | |
OLD | NEW |