Commit 4db73ade authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

Uses member variable for the callback of RemoveTrack()

This CL puts the callback of RemoveTrack() to a member variable rather
than passing as parameter to fix an issue that UserMediaClientImpl
sometimes cannot process request after MediaStreamVideoSource dies.

Bug: 972017, b/131272798
Test: Manually
Change-Id: I04dc594b23ce981f3443996be4a5ac3538770211
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1660394
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669588}
parent 28933ea6
...@@ -273,7 +273,7 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource ...@@ -273,7 +273,7 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource
void StartFrameMonitoring(); void StartFrameMonitoring();
void UpdateTrackSettings(MediaStreamVideoTrack* track, void UpdateTrackSettings(MediaStreamVideoTrack* track,
const VideoTrackAdapterSettings& adapter_settings); const VideoTrackAdapterSettings& adapter_settings);
void DidStopSource(base::OnceClosure callback, RestartResult result); void DidStopSource(RestartResult result);
State state_; State state_;
...@@ -322,6 +322,11 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource ...@@ -322,6 +322,11 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource
// size. // size.
bool enable_device_rotation_detection_ = false; bool enable_device_rotation_detection_ = false;
// Callback that needs to trigger after removing the track. If this object
// died before this callback is resolved, we still need to trigger the
// callback to notify the caller that the request is canceled.
base::OnceClosure remove_last_track_callback_;
// NOTE: Weak pointers must be invalidated before all other member variables. // NOTE: Weak pointers must be invalidated before all other member variables.
base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_; base::WeakPtrFactory<MediaStreamVideoSource> weak_factory_;
......
...@@ -44,6 +44,9 @@ MediaStreamVideoSource::MediaStreamVideoSource() ...@@ -44,6 +44,9 @@ MediaStreamVideoSource::MediaStreamVideoSource()
MediaStreamVideoSource::~MediaStreamVideoSource() { MediaStreamVideoSource::~MediaStreamVideoSource() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (remove_last_track_callback_) {
std::move(remove_last_track_callback_).Run();
}
} }
void MediaStreamVideoSource::AddTrack( void MediaStreamVideoSource::AddTrack(
...@@ -129,9 +132,9 @@ void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track, ...@@ -129,9 +132,9 @@ void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track,
// stopping a source with StopSource() can have side effects that affect // stopping a source with StopSource() can have side effects that affect
// sources created after that StopSource() call, but before the actual // sources created after that StopSource() call, but before the actual
// stop takes place. See https://crbug.com/778039. // stop takes place. See https://crbug.com/778039.
remove_last_track_callback_ = std::move(callback);
StopForRestart(WTF::Bind(&MediaStreamVideoSource::DidStopSource, StopForRestart(WTF::Bind(&MediaStreamVideoSource::DidStopSource,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr()));
std::move(callback)));
if (state_ == STOPPING_FOR_RESTART || state_ == STOPPED_FOR_RESTART) { if (state_ == STOPPING_FOR_RESTART || state_ == STOPPED_FOR_RESTART) {
// If the source supports restarting, it is necessary to call // If the source supports restarting, it is necessary to call
// FinalizeStopSource() to ensure the same behavior as StopSource(), // FinalizeStopSource() to ensure the same behavior as StopSource(),
...@@ -155,10 +158,9 @@ void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track, ...@@ -155,10 +158,9 @@ void MediaStreamVideoSource::RemoveTrack(MediaStreamVideoTrack* video_track,
} }
} }
void MediaStreamVideoSource::DidStopSource(base::OnceClosure callback, void MediaStreamVideoSource::DidStopSource(RestartResult result) {
RestartResult result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(callback); DCHECK(remove_last_track_callback_);
if (result == RestartResult::IS_STOPPED) { if (result == RestartResult::IS_STOPPED) {
state_ = ENDED; state_ = ENDED;
} }
...@@ -171,7 +173,7 @@ void MediaStreamVideoSource::DidStopSource(base::OnceClosure callback, ...@@ -171,7 +173,7 @@ void MediaStreamVideoSource::DidStopSource(base::OnceClosure callback,
"sending notification anyway"; "sending notification anyway";
StopSource(); StopSource();
} }
std::move(callback).Run(); std::move(remove_last_track_callback_).Run();
} }
void MediaStreamVideoSource::ReconfigureTrack( void MediaStreamVideoSource::ReconfigureTrack(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment