Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: third_party/WebKit/Source/modules/mediastream/MediaStreamTrack.cpp

Issue 2922733002: Propagate muted state from MediaStreamAudioSource into JS. (Closed)
Patch Set: Rebase: FakeAudioInputStream changes moved into earlier CL Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Ericsson AB. All rights reserved. 3 * Copyright (C) 2011 Ericsson AB. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } // namespace 57 } // namespace
58 58
59 MediaStreamTrack* MediaStreamTrack::Create(ExecutionContext* context, 59 MediaStreamTrack* MediaStreamTrack::Create(ExecutionContext* context,
60 MediaStreamComponent* component) { 60 MediaStreamComponent* component) {
61 return new MediaStreamTrack(context, component); 61 return new MediaStreamTrack(context, component);
62 } 62 }
63 63
64 MediaStreamTrack::MediaStreamTrack(ExecutionContext* context, 64 MediaStreamTrack::MediaStreamTrack(ExecutionContext* context,
65 MediaStreamComponent* component) 65 MediaStreamComponent* component)
66 : ContextLifecycleObserver(context), 66 : ContextLifecycleObserver(context),
67 ready_state_(MediaStreamSource::kReadyStateLive), 67 ready_state_(component->Source()->GetReadyState()),
68 is_iterating_registered_media_streams_(false), 68 is_iterating_registered_media_streams_(false),
69 stopped_(false), 69 stopped_(false),
70 component_(component), 70 component_(component),
71 // The source's constraints aren't yet initialized at creation time. 71 // The source's constraints aren't yet initialized at creation time.
72 constraints_() { 72 constraints_() {
73 component_->Source()->AddObserver(this); 73 component_->Source()->AddObserver(this);
74 74
75 // If the source is already non-live at this point, the observer won't have
76 // been called. Check the muted state manually.
77 if (ready_state_ == MediaStreamSource::kReadyStateMuted)
miu 2017/06/19 19:40:37 This code assumes MediaStreamComponent::muted_ is
ossu-chromium 2017/06/26 16:06:14 From what I could gather, that constructor is (un?
78 component_->SetMuted(true);
79
75 if (component_->Source() && 80 if (component_->Source() &&
76 component_->Source()->GetType() == MediaStreamSource::kTypeVideo) { 81 component_->Source()->GetType() == MediaStreamSource::kTypeVideo) {
77 // ImageCapture::create() only throws if |this| track is not of video type. 82 // ImageCapture::create() only throws if |this| track is not of video type.
78 NonThrowableExceptionState exception_state; 83 NonThrowableExceptionState exception_state;
79 image_capture_ = ImageCapture::Create(context, this, exception_state); 84 image_capture_ = ImageCapture::Create(context, this, exception_state);
80 } 85 }
81 } 86 }
82 87
83 MediaStreamTrack::~MediaStreamTrack() {} 88 MediaStreamTrack::~MediaStreamTrack() {}
84 89
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 181 }
177 } 182 }
178 183
179 component_->SetContentHint(translated_hint); 184 component_->SetContentHint(translated_hint);
180 } 185 }
181 186
182 String MediaStreamTrack::readyState() const { 187 String MediaStreamTrack::readyState() const {
183 if (Ended()) 188 if (Ended())
184 return "ended"; 189 return "ended";
185 190
191 // Although muted is tracked as a ReadyState, only "live" and "ended" are
192 // visible externally.
186 switch (ready_state_) { 193 switch (ready_state_) {
187 case MediaStreamSource::kReadyStateLive: 194 case MediaStreamSource::kReadyStateLive:
195 case MediaStreamSource::kReadyStateMuted:
188 return "live"; 196 return "live";
189 case MediaStreamSource::kReadyStateMuted:
190 return "muted";
191 case MediaStreamSource::kReadyStateEnded: 197 case MediaStreamSource::kReadyStateEnded:
192 return "ended"; 198 return "ended";
193 } 199 }
194 200
195 NOTREACHED(); 201 NOTREACHED();
196 return String(); 202 return String();
197 } 203 }
198 204
199 void MediaStreamTrack::stopTrack(ExceptionState& exception_state) { 205 void MediaStreamTrack::stopTrack(ExceptionState& exception_state) {
200 if (Ended()) 206 if (Ended())
201 return; 207 return;
202 208
203 ready_state_ = MediaStreamSource::kReadyStateEnded; 209 ready_state_ = MediaStreamSource::kReadyStateEnded;
miu 2017/06/19 19:40:37 Assigning to |ready_state_| here could be dangerou
ossu-chromium 2017/06/26 16:06:14 There's an if (Ended()) clause in SourceChangedSta
204 MediaStreamCenter::Instance().DidStopMediaStreamTrack(Component()); 210 MediaStreamCenter::Instance().DidStopMediaStreamTrack(Component());
205 DispatchEvent(Event::Create(EventTypeNames::ended)); 211 DispatchEvent(Event::Create(EventTypeNames::ended));
206 PropagateTrackEnded(); 212 PropagateTrackEnded();
207 } 213 }
208 214
209 MediaStreamTrack* MediaStreamTrack::clone(ScriptState* script_state) { 215 MediaStreamTrack* MediaStreamTrack::clone(ScriptState* script_state) {
210 // TODO(pbos): Make sure m_readyState and m_stopped carries over on cloned 216 // TODO(pbos): Make sure m_readyState and m_stopped carries over on cloned
211 // tracks. 217 // tracks.
212 MediaStreamComponent* cloned_component = Component()->Clone(); 218 MediaStreamComponent* cloned_component = Component()->Clone();
213 MediaStreamTrack* cloned_track = MediaStreamTrack::Create( 219 MediaStreamTrack* cloned_track = MediaStreamTrack::Create(
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 415
410 DEFINE_TRACE(MediaStreamTrack) { 416 DEFINE_TRACE(MediaStreamTrack) {
411 visitor->Trace(registered_media_streams_); 417 visitor->Trace(registered_media_streams_);
412 visitor->Trace(component_); 418 visitor->Trace(component_);
413 visitor->Trace(image_capture_); 419 visitor->Trace(image_capture_);
414 EventTargetWithInlineData::Trace(visitor); 420 EventTargetWithInlineData::Trace(visitor);
415 ContextLifecycleObserver::Trace(visitor); 421 ContextLifecycleObserver::Trace(visitor);
416 } 422 }
417 423
418 } // namespace blink 424 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698