blob: bed1be94dbb27559789d141eecf0e120c8b2f40e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
wu@webrtc.org967bfff2013-09-19 05:49:50 +000028#include "talk/app/webrtc/videosource.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30#include <vector>
glaznev@webrtc.org3472dcd2014-09-10 19:24:57 +000031#include <cstdlib>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33#include "talk/app/webrtc/mediaconstraintsinterface.h"
34#include "talk/session/media/channelmanager.h"
35
36using cricket::CaptureState;
37using webrtc::MediaConstraintsInterface;
38using webrtc::MediaSourceInterface;
39
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040namespace {
41
42const double kRoundingTruncation = 0.0005;
43
44enum {
45 MSG_VIDEOCAPTURESTATECONNECT,
46 MSG_VIDEOCAPTURESTATEDISCONNECT,
47 MSG_VIDEOCAPTURESTATECHANGE,
48};
49
50// Default resolution. If no constraint is specified, this is the resolution we
51// will use.
wu@webrtc.org967bfff2013-09-19 05:49:50 +000052static const cricket::VideoFormatPod kDefaultFormat =
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053 {640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY};
54
55// List of formats used if the camera doesn't support capability enumeration.
56static const cricket::VideoFormatPod kVideoFormats[] = {
57 {1920, 1080, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
58 {1280, 720, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
59 {960, 720, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
60 {640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
61 {640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
62 {320, 240, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY},
63 {320, 180, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY}
64};
65
66MediaSourceInterface::SourceState
67GetReadyState(cricket::CaptureState state) {
68 switch (state) {
69 case cricket::CS_STARTING:
70 return MediaSourceInterface::kInitializing;
71 case cricket::CS_RUNNING:
72 return MediaSourceInterface::kLive;
73 case cricket::CS_FAILED:
74 case cricket::CS_NO_DEVICE:
75 case cricket::CS_STOPPED:
76 return MediaSourceInterface::kEnded;
77 case cricket::CS_PAUSED:
78 return MediaSourceInterface::kMuted;
79 default:
80 ASSERT(false && "GetReadyState unknown state");
81 }
82 return MediaSourceInterface::kEnded;
83}
84
85void SetUpperLimit(int new_limit, int* original_limit) {
86 if (*original_limit < 0 || new_limit < *original_limit)
87 *original_limit = new_limit;
88}
89
90// Updates |format_upper_limit| from |constraint|.
91// If constraint.maxFoo is smaller than format_upper_limit.foo,
92// set format_upper_limit.foo to constraint.maxFoo.
93void SetUpperLimitFromConstraint(
94 const MediaConstraintsInterface::Constraint& constraint,
95 cricket::VideoFormat* format_upper_limit) {
96 if (constraint.key == MediaConstraintsInterface::kMaxWidth) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000097 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 SetUpperLimit(value, &(format_upper_limit->width));
99 } else if (constraint.key == MediaConstraintsInterface::kMaxHeight) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000100 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 SetUpperLimit(value, &(format_upper_limit->height));
102 }
103}
104
105// Fills |format_out| with the max width and height allowed by |constraints|.
106void FromConstraintsForScreencast(
107 const MediaConstraintsInterface::Constraints& constraints,
108 cricket::VideoFormat* format_out) {
109 typedef MediaConstraintsInterface::Constraints::const_iterator
110 ConstraintsIterator;
111
112 cricket::VideoFormat upper_limit(-1, -1, 0, 0);
113 for (ConstraintsIterator constraints_it = constraints.begin();
114 constraints_it != constraints.end(); ++constraints_it)
115 SetUpperLimitFromConstraint(*constraints_it, &upper_limit);
116
117 if (upper_limit.width >= 0)
118 format_out->width = upper_limit.width;
119 if (upper_limit.height >= 0)
120 format_out->height = upper_limit.height;
121}
122
123// Returns true if |constraint| is fulfilled. |format_out| can differ from
124// |format_in| if the format is changed by the constraint. Ie - the frame rate
125// can be changed by setting maxFrameRate.
126bool NewFormatWithConstraints(
127 const MediaConstraintsInterface::Constraint& constraint,
128 const cricket::VideoFormat& format_in,
129 bool mandatory,
130 cricket::VideoFormat* format_out) {
131 ASSERT(format_out != NULL);
132 *format_out = format_in;
133
134 if (constraint.key == MediaConstraintsInterface::kMinWidth) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000135 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 return (value <= format_in.width);
137 } else if (constraint.key == MediaConstraintsInterface::kMaxWidth) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000138 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 return (value >= format_in.width);
140 } else if (constraint.key == MediaConstraintsInterface::kMinHeight) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 return (value <= format_in.height);
143 } else if (constraint.key == MediaConstraintsInterface::kMaxHeight) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000144 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 return (value >= format_in.height);
146 } else if (constraint.key == MediaConstraintsInterface::kMinFrameRate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 return (value <= cricket::VideoFormat::IntervalToFps(format_in.interval));
149 } else if (constraint.key == MediaConstraintsInterface::kMaxFrameRate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000150 int value = rtc::FromString<int>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 if (value == 0) {
152 if (mandatory) {
153 // TODO(ronghuawu): Convert the constraint value to float when sub-1fps
154 // is supported by the capturer.
155 return false;
156 } else {
157 value = 1;
158 }
159 }
Magnus Jedvert6ec1f922015-08-28 11:40:59 +0200160 if (value <= cricket::VideoFormat::IntervalToFps(format_in.interval))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 format_out->interval = cricket::VideoFormat::FpsToInterval(value);
Magnus Jedvert6ec1f922015-08-28 11:40:59 +0200162 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 } else if (constraint.key == MediaConstraintsInterface::kMinAspectRatio) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 double value = rtc::FromString<double>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 // The aspect ratio in |constraint.value| has been converted to a string and
166 // back to a double, so it may have a rounding error.
167 // E.g if the value 1/3 is converted to a string, the string will not have
168 // infinite length.
169 // We add a margin of 0.0005 which is high enough to detect the same aspect
170 // ratio but small enough to avoid matching wrong aspect ratios.
171 double ratio = static_cast<double>(format_in.width) / format_in.height;
172 return (value <= ratio + kRoundingTruncation);
173 } else if (constraint.key == MediaConstraintsInterface::kMaxAspectRatio) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000174 double value = rtc::FromString<double>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 double ratio = static_cast<double>(format_in.width) / format_in.height;
176 // Subtract 0.0005 to avoid rounding problems. Same as above.
177 const double kRoundingTruncation = 0.0005;
178 return (value >= ratio - kRoundingTruncation);
buildbot@webrtc.org81ddc782014-10-14 22:39:24 +0000179 } else if (constraint.key == MediaConstraintsInterface::kNoiseReduction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 // These are actually options, not constraints, so they can be satisfied
181 // regardless of the format.
182 return true;
183 }
184 LOG(LS_WARNING) << "Found unknown MediaStream constraint. Name:"
185 << constraint.key << " Value:" << constraint.value;
186 return false;
187}
188
189// Removes cricket::VideoFormats from |formats| that don't meet |constraint|.
190void FilterFormatsByConstraint(
191 const MediaConstraintsInterface::Constraint& constraint,
192 bool mandatory,
193 std::vector<cricket::VideoFormat>* formats) {
194 std::vector<cricket::VideoFormat>::iterator format_it =
195 formats->begin();
196 while (format_it != formats->end()) {
197 // Modify the format_it to fulfill the constraint if possible.
198 // Delete it otherwise.
199 if (!NewFormatWithConstraints(constraint, (*format_it),
200 mandatory, &(*format_it))) {
201 format_it = formats->erase(format_it);
202 } else {
203 ++format_it;
204 }
205 }
206}
207
208// Returns a vector of cricket::VideoFormat that best match |constraints|.
209std::vector<cricket::VideoFormat> FilterFormats(
210 const MediaConstraintsInterface::Constraints& mandatory,
211 const MediaConstraintsInterface::Constraints& optional,
212 const std::vector<cricket::VideoFormat>& supported_formats) {
213 typedef MediaConstraintsInterface::Constraints::const_iterator
214 ConstraintsIterator;
215 std::vector<cricket::VideoFormat> candidates = supported_formats;
216
217 for (ConstraintsIterator constraints_it = mandatory.begin();
218 constraints_it != mandatory.end(); ++constraints_it)
219 FilterFormatsByConstraint(*constraints_it, true, &candidates);
220
221 if (candidates.size() == 0)
222 return candidates;
223
224 // Ok - all mandatory checked and we still have a candidate.
225 // Let's try filtering using the optional constraints.
226 for (ConstraintsIterator constraints_it = optional.begin();
227 constraints_it != optional.end(); ++constraints_it) {
228 std::vector<cricket::VideoFormat> current_candidates = candidates;
229 FilterFormatsByConstraint(*constraints_it, false, &current_candidates);
230 if (current_candidates.size() > 0) {
231 candidates = current_candidates;
232 }
233 }
234
235 // We have done as good as we can to filter the supported resolutions.
236 return candidates;
237}
238
239// Find the format that best matches the default video size.
240// Constraints are optional and since the performance of a video call
241// might be bad due to bitrate limitations, CPU, and camera performance,
242// it is better to select a resolution that is as close as possible to our
243// default and still meets the contraints.
244const cricket::VideoFormat& GetBestCaptureFormat(
245 const std::vector<cricket::VideoFormat>& formats) {
246 ASSERT(formats.size() > 0);
247
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000248 int default_area = kDefaultFormat.width * kDefaultFormat.height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249
250 std::vector<cricket::VideoFormat>::const_iterator it = formats.begin();
251 std::vector<cricket::VideoFormat>::const_iterator best_it = formats.begin();
glaznev@webrtc.org3472dcd2014-09-10 19:24:57 +0000252 int best_diff_area = std::abs(default_area - it->width * it->height);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200253 int64_t best_diff_interval = kDefaultFormat.interval;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 for (; it != formats.end(); ++it) {
glaznev@webrtc.org3472dcd2014-09-10 19:24:57 +0000255 int diff_area = std::abs(default_area - it->width * it->height);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200256 int64_t diff_interval = std::abs(kDefaultFormat.interval - it->interval);
glaznev@webrtc.org3472dcd2014-09-10 19:24:57 +0000257 if (diff_area < best_diff_area ||
258 (diff_area == best_diff_area && diff_interval < best_diff_interval)) {
259 best_diff_area = diff_area;
260 best_diff_interval = diff_interval;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 best_it = it;
262 }
263 }
264 return *best_it;
265}
266
267// Set |option| to the highest-priority value of |key| in the constraints.
268// Return false if the key is mandatory, and the value is invalid.
269bool ExtractOption(const MediaConstraintsInterface* all_constraints,
kwiberg102c6a62015-10-30 02:47:38 -0700270 const std::string& key,
271 rtc::Maybe<bool>* option) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 size_t mandatory = 0;
273 bool value;
274 if (FindConstraint(all_constraints, key, &value, &mandatory)) {
kwiberg102c6a62015-10-30 02:47:38 -0700275 *option = rtc::Maybe<bool>(value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 return true;
277 }
278
279 return mandatory == 0;
280}
281
282// Search |all_constraints| for known video options. Apply all options that are
283// found with valid values, and return false if any mandatory video option was
284// found with an invalid value.
285bool ExtractVideoOptions(const MediaConstraintsInterface* all_constraints,
286 cricket::VideoOptions* options) {
287 bool all_valid = true;
288
289 all_valid &= ExtractOption(all_constraints,
290 MediaConstraintsInterface::kNoiseReduction,
291 &(options->video_noise_reduction));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292
293 return all_valid;
294}
295
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000296class FrameInputWrapper : public cricket::VideoRenderer {
297 public:
298 explicit FrameInputWrapper(cricket::VideoCapturer* capturer)
299 : capturer_(capturer) {
300 ASSERT(capturer_ != NULL);
301 }
302
303 virtual ~FrameInputWrapper() {}
304
305 // VideoRenderer implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000306 bool SetSize(int width, int height, int reserved) override { return true; }
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000307
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000308 bool RenderFrame(const cricket::VideoFrame* frame) override {
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000309 if (!capturer_->IsRunning()) {
310 return true;
311 }
312
313 // This signal will be made on media engine render thread. The clients
314 // of this signal should have no assumptions on what thread this signal
315 // come from.
316 capturer_->SignalVideoFrame(capturer_, frame);
317 return true;
318 }
319
320 private:
321 cricket::VideoCapturer* capturer_;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000322
henrikg3c089d72015-09-16 05:37:44 -0700323 RTC_DISALLOW_COPY_AND_ASSIGN(FrameInputWrapper);
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000324};
325
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326} // anonymous namespace
327
328namespace webrtc {
329
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000330rtc::scoped_refptr<VideoSource> VideoSource::Create(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 cricket::ChannelManager* channel_manager,
332 cricket::VideoCapturer* capturer,
333 const webrtc::MediaConstraintsInterface* constraints) {
334 ASSERT(channel_manager != NULL);
335 ASSERT(capturer != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000336 rtc::scoped_refptr<VideoSource> source(
337 new rtc::RefCountedObject<VideoSource>(channel_manager,
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000338 capturer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 source->Initialize(constraints);
340 return source;
341}
342
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000343VideoSource::VideoSource(cricket::ChannelManager* channel_manager,
344 cricket::VideoCapturer* capturer)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 : channel_manager_(channel_manager),
346 video_capturer_(capturer),
347 state_(kInitializing) {
348 channel_manager_->SignalVideoCaptureStateChange.connect(
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000349 this, &VideoSource::OnStateChange);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350}
351
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000352VideoSource::~VideoSource() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 channel_manager_->StopVideoCapture(video_capturer_.get(), format_);
354 channel_manager_->SignalVideoCaptureStateChange.disconnect(this);
355}
356
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000357void VideoSource::Initialize(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 const webrtc::MediaConstraintsInterface* constraints) {
359
hbos@webrtc.org1e642632015-02-25 09:49:41 +0000360 std::vector<cricket::VideoFormat> formats =
361 channel_manager_->GetSupportedFormats(video_capturer_.get());
362 if (formats.empty()) {
363 if (video_capturer_->IsScreencast()) {
364 // The screen capturer can accept any resolution and we will derive the
365 // format from the constraints if any.
366 // Note that this only affects tab capturing, not desktop capturing,
367 // since the desktop capturer does not respect the VideoFormat passed in.
368 formats.push_back(cricket::VideoFormat(kDefaultFormat));
369 } else {
370 // The VideoCapturer implementation doesn't support capability
371 // enumeration. We need to guess what the camera supports.
372 for (int i = 0; i < ARRAY_SIZE(kVideoFormats); ++i) {
373 formats.push_back(cricket::VideoFormat(kVideoFormats[i]));
374 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 }
376 }
377
378 if (constraints) {
379 MediaConstraintsInterface::Constraints mandatory_constraints =
380 constraints->GetMandatory();
381 MediaConstraintsInterface::Constraints optional_constraints;
382 optional_constraints = constraints->GetOptional();
383
384 if (video_capturer_->IsScreencast()) {
385 // Use the maxWidth and maxHeight allowed by constraints for screencast.
386 FromConstraintsForScreencast(mandatory_constraints, &(formats[0]));
387 }
388
389 formats = FilterFormats(mandatory_constraints, optional_constraints,
390 formats);
391 }
392
393 if (formats.size() == 0) {
394 LOG(LS_WARNING) << "Failed to find a suitable video format.";
395 SetState(kEnded);
396 return;
397 }
398
399 cricket::VideoOptions options;
400 if (!ExtractVideoOptions(constraints, &options)) {
401 LOG(LS_WARNING) << "Could not satisfy mandatory options.";
402 SetState(kEnded);
403 return;
404 }
405 options_.SetAll(options);
406
407 format_ = GetBestCaptureFormat(formats);
408 // Start the camera with our best guess.
409 // TODO(perkj): Should we try again with another format it it turns out that
410 // the camera doesn't produce frames with the correct format? Or will
411 // cricket::VideCapturer be able to re-scale / crop to the requested
412 // resolution?
413 if (!channel_manager_->StartVideoCapture(video_capturer_.get(), format_)) {
414 SetState(kEnded);
415 return;
416 }
417 // Initialize hasn't succeeded until a successful state change has occurred.
418}
419
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000420cricket::VideoRenderer* VideoSource::FrameInput() {
421 // Defer creation of frame_input_ until it's needed, e.g. the local video
422 // sources will never need it.
423 if (!frame_input_) {
424 frame_input_.reset(new FrameInputWrapper(video_capturer_.get()));
425 }
426 return frame_input_.get();
427}
428
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000429void VideoSource::Stop() {
430 channel_manager_->StopVideoCapture(video_capturer_.get(), format_);
431}
432
433void VideoSource::Restart() {
434 if (!channel_manager_->StartVideoCapture(video_capturer_.get(), format_)) {
435 SetState(kEnded);
436 return;
437 }
438 for(cricket::VideoRenderer* sink : sinks_) {
439 channel_manager_->AddVideoRenderer(video_capturer_.get(), sink);
440 }
441}
442
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000443void VideoSource::AddSink(cricket::VideoRenderer* output) {
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000444 sinks_.push_back(output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 channel_manager_->AddVideoRenderer(video_capturer_.get(), output);
446}
447
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000448void VideoSource::RemoveSink(cricket::VideoRenderer* output) {
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000449 sinks_.remove(output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 channel_manager_->RemoveVideoRenderer(video_capturer_.get(), output);
451}
452
453// OnStateChange listens to the ChannelManager::SignalVideoCaptureStateChange.
454// This signal is triggered for all video capturers. Not only the one we are
455// interested in.
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000456void VideoSource::OnStateChange(cricket::VideoCapturer* capturer,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 cricket::CaptureState capture_state) {
458 if (capturer == video_capturer_.get()) {
459 SetState(GetReadyState(capture_state));
460 }
461}
462
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000463void VideoSource::SetState(SourceState new_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 if (VERIFY(state_ != new_state)) {
465 state_ = new_state;
466 FireOnChanged();
467 }
468}
469
470} // namespace webrtc