blob: 44f3e225f9f7bf6e5b9922a53c5c67717461fb42 [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 }
160 if (value <= cricket::VideoFormat::IntervalToFps(format_in.interval)) {
161 format_out->interval = cricket::VideoFormat::FpsToInterval(value);
162 return true;
163 } else {
164 return false;
165 }
166 } else if (constraint.key == MediaConstraintsInterface::kMinAspectRatio) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000167 double value = rtc::FromString<double>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 // The aspect ratio in |constraint.value| has been converted to a string and
169 // back to a double, so it may have a rounding error.
170 // E.g if the value 1/3 is converted to a string, the string will not have
171 // infinite length.
172 // We add a margin of 0.0005 which is high enough to detect the same aspect
173 // ratio but small enough to avoid matching wrong aspect ratios.
174 double ratio = static_cast<double>(format_in.width) / format_in.height;
175 return (value <= ratio + kRoundingTruncation);
176 } else if (constraint.key == MediaConstraintsInterface::kMaxAspectRatio) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000177 double value = rtc::FromString<double>(constraint.value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 double ratio = static_cast<double>(format_in.width) / format_in.height;
179 // Subtract 0.0005 to avoid rounding problems. Same as above.
180 const double kRoundingTruncation = 0.0005;
181 return (value >= ratio - kRoundingTruncation);
buildbot@webrtc.org81ddc782014-10-14 22:39:24 +0000182 } else if (constraint.key == MediaConstraintsInterface::kNoiseReduction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 // These are actually options, not constraints, so they can be satisfied
184 // regardless of the format.
185 return true;
186 }
187 LOG(LS_WARNING) << "Found unknown MediaStream constraint. Name:"
188 << constraint.key << " Value:" << constraint.value;
189 return false;
190}
191
192// Removes cricket::VideoFormats from |formats| that don't meet |constraint|.
193void FilterFormatsByConstraint(
194 const MediaConstraintsInterface::Constraint& constraint,
195 bool mandatory,
196 std::vector<cricket::VideoFormat>* formats) {
197 std::vector<cricket::VideoFormat>::iterator format_it =
198 formats->begin();
199 while (format_it != formats->end()) {
200 // Modify the format_it to fulfill the constraint if possible.
201 // Delete it otherwise.
202 if (!NewFormatWithConstraints(constraint, (*format_it),
203 mandatory, &(*format_it))) {
204 format_it = formats->erase(format_it);
205 } else {
206 ++format_it;
207 }
208 }
209}
210
211// Returns a vector of cricket::VideoFormat that best match |constraints|.
212std::vector<cricket::VideoFormat> FilterFormats(
213 const MediaConstraintsInterface::Constraints& mandatory,
214 const MediaConstraintsInterface::Constraints& optional,
215 const std::vector<cricket::VideoFormat>& supported_formats) {
216 typedef MediaConstraintsInterface::Constraints::const_iterator
217 ConstraintsIterator;
218 std::vector<cricket::VideoFormat> candidates = supported_formats;
219
220 for (ConstraintsIterator constraints_it = mandatory.begin();
221 constraints_it != mandatory.end(); ++constraints_it)
222 FilterFormatsByConstraint(*constraints_it, true, &candidates);
223
224 if (candidates.size() == 0)
225 return candidates;
226
227 // Ok - all mandatory checked and we still have a candidate.
228 // Let's try filtering using the optional constraints.
229 for (ConstraintsIterator constraints_it = optional.begin();
230 constraints_it != optional.end(); ++constraints_it) {
231 std::vector<cricket::VideoFormat> current_candidates = candidates;
232 FilterFormatsByConstraint(*constraints_it, false, &current_candidates);
233 if (current_candidates.size() > 0) {
234 candidates = current_candidates;
235 }
236 }
237
238 // We have done as good as we can to filter the supported resolutions.
239 return candidates;
240}
241
242// Find the format that best matches the default video size.
243// Constraints are optional and since the performance of a video call
244// might be bad due to bitrate limitations, CPU, and camera performance,
245// it is better to select a resolution that is as close as possible to our
246// default and still meets the contraints.
247const cricket::VideoFormat& GetBestCaptureFormat(
248 const std::vector<cricket::VideoFormat>& formats) {
249 ASSERT(formats.size() > 0);
250
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000251 int default_area = kDefaultFormat.width * kDefaultFormat.height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252
253 std::vector<cricket::VideoFormat>::const_iterator it = formats.begin();
254 std::vector<cricket::VideoFormat>::const_iterator best_it = formats.begin();
glaznev@webrtc.org3472dcd2014-09-10 19:24:57 +0000255 int best_diff_area = std::abs(default_area - it->width * it->height);
256 int64 best_diff_interval = kDefaultFormat.interval;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 for (; it != formats.end(); ++it) {
glaznev@webrtc.org3472dcd2014-09-10 19:24:57 +0000258 int diff_area = std::abs(default_area - it->width * it->height);
259 int64 diff_interval = std::abs(kDefaultFormat.interval - it->interval);
260 if (diff_area < best_diff_area ||
261 (diff_area == best_diff_area && diff_interval < best_diff_interval)) {
262 best_diff_area = diff_area;
263 best_diff_interval = diff_interval;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 best_it = it;
265 }
266 }
267 return *best_it;
268}
269
270// Set |option| to the highest-priority value of |key| in the constraints.
271// Return false if the key is mandatory, and the value is invalid.
272bool ExtractOption(const MediaConstraintsInterface* all_constraints,
273 const std::string& key, cricket::Settable<bool>* option) {
274 size_t mandatory = 0;
275 bool value;
276 if (FindConstraint(all_constraints, key, &value, &mandatory)) {
277 option->Set(value);
278 return true;
279 }
280
281 return mandatory == 0;
282}
283
284// Search |all_constraints| for known video options. Apply all options that are
285// found with valid values, and return false if any mandatory video option was
286// found with an invalid value.
287bool ExtractVideoOptions(const MediaConstraintsInterface* all_constraints,
288 cricket::VideoOptions* options) {
289 bool all_valid = true;
290
291 all_valid &= ExtractOption(all_constraints,
292 MediaConstraintsInterface::kNoiseReduction,
293 &(options->video_noise_reduction));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294
295 return all_valid;
296}
297
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000298class FrameInputWrapper : public cricket::VideoRenderer {
299 public:
300 explicit FrameInputWrapper(cricket::VideoCapturer* capturer)
301 : capturer_(capturer) {
302 ASSERT(capturer_ != NULL);
303 }
304
305 virtual ~FrameInputWrapper() {}
306
307 // VideoRenderer implementation.
308 virtual bool SetSize(int width, int height, int reserved) OVERRIDE {
309 return true;
310 }
311
312 virtual bool RenderFrame(const cricket::VideoFrame* frame) OVERRIDE {
313 if (!capturer_->IsRunning()) {
314 return true;
315 }
316
317 // This signal will be made on media engine render thread. The clients
318 // of this signal should have no assumptions on what thread this signal
319 // come from.
320 capturer_->SignalVideoFrame(capturer_, frame);
321 return true;
322 }
323
324 private:
325 cricket::VideoCapturer* capturer_;
326 int width_;
327 int height_;
328
329 DISALLOW_COPY_AND_ASSIGN(FrameInputWrapper);
330};
331
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332} // anonymous namespace
333
334namespace webrtc {
335
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000336rtc::scoped_refptr<VideoSource> VideoSource::Create(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 cricket::ChannelManager* channel_manager,
338 cricket::VideoCapturer* capturer,
339 const webrtc::MediaConstraintsInterface* constraints) {
340 ASSERT(channel_manager != NULL);
341 ASSERT(capturer != NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000342 rtc::scoped_refptr<VideoSource> source(
343 new rtc::RefCountedObject<VideoSource>(channel_manager,
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000344 capturer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 source->Initialize(constraints);
346 return source;
347}
348
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000349VideoSource::VideoSource(cricket::ChannelManager* channel_manager,
350 cricket::VideoCapturer* capturer)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 : channel_manager_(channel_manager),
352 video_capturer_(capturer),
353 state_(kInitializing) {
354 channel_manager_->SignalVideoCaptureStateChange.connect(
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000355 this, &VideoSource::OnStateChange);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356}
357
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000358VideoSource::~VideoSource() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 channel_manager_->StopVideoCapture(video_capturer_.get(), format_);
360 channel_manager_->SignalVideoCaptureStateChange.disconnect(this);
361}
362
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000363void VideoSource::Initialize(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 const webrtc::MediaConstraintsInterface* constraints) {
365
366 std::vector<cricket::VideoFormat> formats;
367 if (video_capturer_->GetSupportedFormats() &&
368 video_capturer_->GetSupportedFormats()->size() > 0) {
369 formats = *video_capturer_->GetSupportedFormats();
370 } else if (video_capturer_->IsScreencast()) {
371 // The screen capturer can accept any resolution and we will derive the
372 // format from the constraints if any.
373 // Note that this only affects tab capturing, not desktop capturing,
374 // since desktop capturer does not respect the VideoFormat passed in.
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000375 formats.push_back(cricket::VideoFormat(kDefaultFormat));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 } else {
377 // The VideoCapturer implementation doesn't support capability enumeration.
378 // We need to guess what the camera support.
379 for (int i = 0; i < ARRAY_SIZE(kVideoFormats); ++i) {
380 formats.push_back(cricket::VideoFormat(kVideoFormats[i]));
381 }
382 }
383
384 if (constraints) {
385 MediaConstraintsInterface::Constraints mandatory_constraints =
386 constraints->GetMandatory();
387 MediaConstraintsInterface::Constraints optional_constraints;
388 optional_constraints = constraints->GetOptional();
389
390 if (video_capturer_->IsScreencast()) {
391 // Use the maxWidth and maxHeight allowed by constraints for screencast.
392 FromConstraintsForScreencast(mandatory_constraints, &(formats[0]));
393 }
394
395 formats = FilterFormats(mandatory_constraints, optional_constraints,
396 formats);
397 }
398
399 if (formats.size() == 0) {
400 LOG(LS_WARNING) << "Failed to find a suitable video format.";
401 SetState(kEnded);
402 return;
403 }
404
405 cricket::VideoOptions options;
406 if (!ExtractVideoOptions(constraints, &options)) {
407 LOG(LS_WARNING) << "Could not satisfy mandatory options.";
408 SetState(kEnded);
409 return;
410 }
411 options_.SetAll(options);
412
413 format_ = GetBestCaptureFormat(formats);
414 // Start the camera with our best guess.
415 // TODO(perkj): Should we try again with another format it it turns out that
416 // the camera doesn't produce frames with the correct format? Or will
417 // cricket::VideCapturer be able to re-scale / crop to the requested
418 // resolution?
419 if (!channel_manager_->StartVideoCapture(video_capturer_.get(), format_)) {
420 SetState(kEnded);
421 return;
422 }
423 // Initialize hasn't succeeded until a successful state change has occurred.
424}
425
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000426cricket::VideoRenderer* VideoSource::FrameInput() {
427 // Defer creation of frame_input_ until it's needed, e.g. the local video
428 // sources will never need it.
429 if (!frame_input_) {
430 frame_input_.reset(new FrameInputWrapper(video_capturer_.get()));
431 }
432 return frame_input_.get();
433}
434
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000435void VideoSource::Stop() {
436 channel_manager_->StopVideoCapture(video_capturer_.get(), format_);
437}
438
439void VideoSource::Restart() {
440 if (!channel_manager_->StartVideoCapture(video_capturer_.get(), format_)) {
441 SetState(kEnded);
442 return;
443 }
444 for(cricket::VideoRenderer* sink : sinks_) {
445 channel_manager_->AddVideoRenderer(video_capturer_.get(), sink);
446 }
447}
448
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000449void VideoSource::AddSink(cricket::VideoRenderer* output) {
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000450 sinks_.push_back(output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 channel_manager_->AddVideoRenderer(video_capturer_.get(), output);
452}
453
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000454void VideoSource::RemoveSink(cricket::VideoRenderer* output) {
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000455 sinks_.remove(output);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 channel_manager_->RemoveVideoRenderer(video_capturer_.get(), output);
457}
458
459// OnStateChange listens to the ChannelManager::SignalVideoCaptureStateChange.
460// This signal is triggered for all video capturers. Not only the one we are
461// interested in.
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000462void VideoSource::OnStateChange(cricket::VideoCapturer* capturer,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 cricket::CaptureState capture_state) {
464 if (capturer == video_capturer_.get()) {
465 SetState(GetReadyState(capture_state));
466 }
467}
468
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000469void VideoSource::SetState(SourceState new_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 if (VERIFY(state_ != new_state)) {
471 state_ = new_state;
472 FireOnChanged();
473 }
474}
475
476} // namespace webrtc