mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
Bug 1497175 - Have DOMMediaStream::TrackPort::BlockSourceTrackId() return a promise. r=pehrsons
Differential Revision: https://phabricator.services.mozilla.com/D8010 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
8ce38b2a13
commit
7cc33e93cf
@ -90,14 +90,12 @@ TrackID DOMMediaStream::TrackPort::GetSourceTrackId() const {
|
||||
return mInputPort ? mInputPort->GetSourceTrackId() : TRACK_INVALID;
|
||||
}
|
||||
|
||||
already_AddRefed<Pledge<bool>> DOMMediaStream::TrackPort::BlockSourceTrackId(
|
||||
RefPtr<GenericPromise> DOMMediaStream::TrackPort::BlockSourceTrackId(
|
||||
TrackID aTrackId, BlockingMode aBlockingMode) {
|
||||
if (mInputPort) {
|
||||
return mInputPort->BlockSourceTrackId(aTrackId, aBlockingMode);
|
||||
if (!mInputPort) {
|
||||
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
|
||||
}
|
||||
auto rejected = MakeRefPtr<Pledge<bool>>();
|
||||
rejected->Reject(NS_ERROR_FAILURE);
|
||||
return rejected.forget();
|
||||
return mInputPort->BlockSourceTrackId(aTrackId, aBlockingMode);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(DOMMediaStream::TrackPort, mTrack)
|
||||
@ -828,9 +826,8 @@ already_AddRefed<MediaStreamTrack> DOMMediaStream::CloneDOMTrack(
|
||||
// For extra suspenders, make sure that we don't forward data by mistake
|
||||
// to the clone when the original has already ended.
|
||||
// We only block END_EXISTING to allow any pending clones to end.
|
||||
RefPtr<Pledge<bool, nsresult>> blockingPledge =
|
||||
inputPort->BlockSourceTrackId(inputTrackID, BlockingMode::END_EXISTING);
|
||||
Unused << blockingPledge;
|
||||
Unused << inputPort->BlockSourceTrackId(inputTrackID,
|
||||
BlockingMode::END_EXISTING);
|
||||
}
|
||||
|
||||
return newTrack.forget();
|
||||
@ -1042,13 +1039,14 @@ nsresult DOMMediaStream::DispatchTrackEvent(
|
||||
void DOMMediaStream::BlockPlaybackTrack(TrackPort* aTrack) {
|
||||
MOZ_ASSERT(aTrack);
|
||||
++mTracksPendingRemoval;
|
||||
RefPtr<Pledge<bool>> p = aTrack->BlockSourceTrackId(
|
||||
aTrack->GetTrack()->mTrackID, BlockingMode::CREATION);
|
||||
RefPtr<DOMMediaStream> self = this;
|
||||
p->Then([self](const bool& aIgnore) { self->NotifyPlaybackTrackBlocked(); },
|
||||
[](const nsresult& aIgnore) {
|
||||
NS_ERROR("Could not remove track from MSG");
|
||||
});
|
||||
RefPtr<DOMMediaStream> that = this;
|
||||
aTrack
|
||||
->BlockSourceTrackId(aTrack->GetTrack()->mTrackID, BlockingMode::CREATION)
|
||||
->Then(GetCurrentThreadSerialEventTarget(), __func__,
|
||||
[this, that](bool aIgnore) { NotifyPlaybackTrackBlocked(); },
|
||||
[](const nsresult& aIgnore) {
|
||||
NS_ERROR("Could not remove track from MSG");
|
||||
});
|
||||
}
|
||||
|
||||
void DOMMediaStream::NotifyPlaybackTrackBlocked() {
|
||||
|
@ -49,11 +49,6 @@ class ImageContainer;
|
||||
class OverlayImage;
|
||||
} // namespace layers
|
||||
|
||||
namespace media {
|
||||
template <typename V, typename E>
|
||||
class Pledge;
|
||||
} // namespace media
|
||||
|
||||
#define NS_DOMMEDIASTREAM_IID \
|
||||
{ \
|
||||
0x8cb65468, 0x66c0, 0x444e, { \
|
||||
@ -276,11 +271,11 @@ class DOMMediaStream
|
||||
|
||||
/**
|
||||
* Blocks aTrackId from going into mInputPort unless the port has been
|
||||
* destroyed. Returns a pledge that gets resolved when the MediaStreamGraph
|
||||
* destroyed. Returns a promise that gets resolved when the MediaStreamGraph
|
||||
* has applied the block in the playback stream.
|
||||
*/
|
||||
already_AddRefed<media::Pledge<bool, nsresult>> BlockSourceTrackId(
|
||||
TrackID aTrackId, BlockingMode aBlockingMode);
|
||||
RefPtr<GenericPromise> BlockSourceTrackId(TrackID aTrackId,
|
||||
BlockingMode aBlockingMode);
|
||||
|
||||
private:
|
||||
RefPtr<MediaInputPort> mInputPort;
|
||||
|
@ -3011,7 +3011,7 @@ void MediaInputPort::BlockSourceTrackIdImpl(TrackID aTrackId,
|
||||
Pair<TrackID, BlockingMode>(aTrackId, aBlockingMode));
|
||||
}
|
||||
|
||||
already_AddRefed<Pledge<bool>> MediaInputPort::BlockSourceTrackId(
|
||||
RefPtr<GenericPromise> MediaInputPort::BlockSourceTrackId(
|
||||
TrackID aTrackId, BlockingMode aBlockingMode) {
|
||||
class Message : public ControlMessage {
|
||||
public:
|
||||
@ -3038,15 +3038,17 @@ already_AddRefed<Pledge<bool>> MediaInputPort::BlockSourceTrackId(
|
||||
|
||||
MOZ_ASSERT(IsTrackIDExplicit(aTrackId), "Only explicit TrackID is allowed");
|
||||
|
||||
auto pledge = MakeRefPtr<Pledge<bool>>();
|
||||
nsCOMPtr<nsIRunnable> runnable = NewRunnableFrom([pledge]() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
pledge->Resolve(true);
|
||||
return NS_OK;
|
||||
});
|
||||
MozPromiseHolder<GenericPromise> holder;
|
||||
RefPtr<GenericPromise> p = holder.Ensure(__func__);
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
NewRunnableFrom([h = std::move(holder)]() mutable {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
h.Resolve(true, __func__);
|
||||
return NS_OK;
|
||||
});
|
||||
GraphImpl()->AppendMessage(
|
||||
MakeUnique<Message>(this, aTrackId, aBlockingMode, runnable.forget()));
|
||||
return pledge.forget();
|
||||
return p;
|
||||
}
|
||||
|
||||
already_AddRefed<MediaInputPort> ProcessedMediaStream::AllocateInputPort(
|
||||
|
@ -49,11 +49,6 @@ namespace dom {
|
||||
enum class AudioContextOperation;
|
||||
}
|
||||
|
||||
namespace media {
|
||||
template <typename V, typename E>
|
||||
class Pledge;
|
||||
}
|
||||
|
||||
/*
|
||||
* MediaStreamGraph is a framework for synchronized audio/video processing
|
||||
* and playback. It is designed to be used by other browser components such as
|
||||
@ -966,8 +961,8 @@ class MediaInputPort final {
|
||||
* Returns a pledge that resolves on the main thread after the track block has
|
||||
* been applied by the MSG.
|
||||
*/
|
||||
already_AddRefed<media::Pledge<bool, nsresult>> BlockSourceTrackId(
|
||||
TrackID aTrackId, BlockingMode aBlockingMode);
|
||||
RefPtr<GenericPromise> BlockSourceTrackId(TrackID aTrackId,
|
||||
BlockingMode aBlockingMode);
|
||||
|
||||
private:
|
||||
void BlockSourceTrackIdImpl(TrackID aTrackId, BlockingMode aBlockingMode);
|
||||
|
@ -308,9 +308,7 @@ void MediaStreamTrack::Stop() {
|
||||
DOMMediaStream::TrackPort* port = mOwningStream->FindOwnedTrackPort(*this);
|
||||
MOZ_ASSERT(port,
|
||||
"A MediaStreamTrack must exist in its owning DOMMediaStream");
|
||||
RefPtr<Pledge<bool>> p =
|
||||
port->BlockSourceTrackId(mInputTrackID, BlockingMode::CREATION);
|
||||
Unused << p;
|
||||
Unused << port->BlockSourceTrackId(mInputTrackID, BlockingMode::CREATION);
|
||||
|
||||
mReadyState = MediaStreamTrackState::Ended;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user