Commit 41ffde71 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Chromium LUCI CQ

[BreakoutBox] Use weak pointer in MediaStreamVideoTrackUnderlyingSink

Replace the raw pointer to a PushableMediaStreamVideoSource with
a weak pointer.

Bug: 1162036
Change-Id: I9b786cfd3800f8e37daabacf039e6b12e2423f76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610036
Auto-Submit: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarThomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840551}
parent bdac3cef
...@@ -12,7 +12,7 @@ namespace blink { ...@@ -12,7 +12,7 @@ namespace blink {
MediaStreamVideoTrackUnderlyingSink::MediaStreamVideoTrackUnderlyingSink( MediaStreamVideoTrackUnderlyingSink::MediaStreamVideoTrackUnderlyingSink(
PushableMediaStreamVideoSource* source) PushableMediaStreamVideoSource* source)
: source_(source) {} : source_(source->GetWeakPtr()) {}
ScriptPromise MediaStreamVideoTrackUnderlyingSink::start( ScriptPromise MediaStreamVideoTrackUnderlyingSink::start(
ScriptState* script_state, ScriptState* script_state,
...@@ -39,14 +39,16 @@ ScriptPromise MediaStreamVideoTrackUnderlyingSink::write( ...@@ -39,14 +39,16 @@ ScriptPromise MediaStreamVideoTrackUnderlyingSink::write(
return ScriptPromise(); return ScriptPromise();
} }
if (!source_->running()) { PushableMediaStreamVideoSource* pushable_source =
static_cast<PushableMediaStreamVideoSource*>(source_.get());
if (!pushable_source || !pushable_source->running()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"Stream closed"); "Stream closed");
return ScriptPromise(); return ScriptPromise();
} }
base::TimeTicks estimated_capture_time = base::TimeTicks::Now(); base::TimeTicks estimated_capture_time = base::TimeTicks::Now();
source_->PushFrame(video_frame->frame(), estimated_capture_time); pushable_source->PushFrame(video_frame->frame(), estimated_capture_time);
// Invalidate the JS |video_frame|. Otherwise, the media frames might not be // Invalidate the JS |video_frame|. Otherwise, the media frames might not be
// released, which would leak resources and also cause some MediaStream // released, which would leak resources and also cause some MediaStream
// sources such as cameras to drop frames. // sources such as cameras to drop frames.
...@@ -59,14 +61,16 @@ ScriptPromise MediaStreamVideoTrackUnderlyingSink::abort( ...@@ -59,14 +61,16 @@ ScriptPromise MediaStreamVideoTrackUnderlyingSink::abort(
ScriptState* script_state, ScriptState* script_state,
ScriptValue reason, ScriptValue reason,
ExceptionState& exception_state) { ExceptionState& exception_state) {
source_->StopSource(); if (source_)
source_->StopSource();
return ScriptPromise::CastUndefined(script_state); return ScriptPromise::CastUndefined(script_state);
} }
ScriptPromise MediaStreamVideoTrackUnderlyingSink::close( ScriptPromise MediaStreamVideoTrackUnderlyingSink::close(
ScriptState* script_state, ScriptState* script_state,
ExceptionState& exception_state) { ExceptionState& exception_state) {
source_->StopSource(); if (source_)
source_->StopSource();
return ScriptPromise::CastUndefined(script_state); return ScriptPromise::CastUndefined(script_state);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace blink { namespace blink {
class MediaStreamVideoSource;
class PushableMediaStreamVideoSource; class PushableMediaStreamVideoSource;
class MODULES_EXPORT MediaStreamVideoTrackUnderlyingSink class MODULES_EXPORT MediaStreamVideoTrackUnderlyingSink
...@@ -34,7 +35,7 @@ class MODULES_EXPORT MediaStreamVideoTrackUnderlyingSink ...@@ -34,7 +35,7 @@ class MODULES_EXPORT MediaStreamVideoTrackUnderlyingSink
ExceptionState& exception_state) override; ExceptionState& exception_state) override;
private: private:
PushableMediaStreamVideoSource* source_; base::WeakPtr<MediaStreamVideoSource> source_;
}; };
} // namespace blink } // namespace blink
......
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