зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1721443 - Implement gtest helper TakeN that return a MozPromise wrapping the first N events from a MediaEventSource. r=bwc
Differential Revision: https://phabricator.services.mozilla.com/D129625
This commit is contained in:
Родитель
65194e6db4
Коммит
3a56135915
|
@ -6,9 +6,10 @@
|
|||
#define WAITFOR_H_
|
||||
|
||||
#include "MediaEventSource.h"
|
||||
#include "MediaUtils.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/SpinEventLoopUntil.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -81,6 +82,36 @@ void WaitUntil(MediaEventSource<T>& aEvent, const CallbackFunction& aF) {
|
|||
listener.Disconnect();
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
using TakeNPromise = MozPromise<std::vector<std::tuple<Args...>>, bool, true>;
|
||||
|
||||
template <ListenerPolicy Lp, typename... Args>
|
||||
auto TakeN(MediaEventSourceImpl<Lp, Args...>& aEvent, size_t aN)
|
||||
-> RefPtr<TakeNPromise<Args...>> {
|
||||
using Storage = std::vector<std::tuple<Args...>>;
|
||||
using Promise = TakeNPromise<Args...>;
|
||||
using Values = media::Refcountable<Storage>;
|
||||
using Listener = media::Refcountable<MediaEventListener>;
|
||||
RefPtr<Values> values = MakeRefPtr<Values>();
|
||||
values->reserve(aN);
|
||||
RefPtr<Listener> listener = MakeRefPtr<Listener>();
|
||||
auto promise = InvokeAsync(
|
||||
AbstractThread::GetCurrent(), __func__, [values, aN]() mutable {
|
||||
SpinEventLoopUntil<ProcessFailureBehavior::IgnoreAndContinue>(
|
||||
"TakeN(MediaEventSourceImpl<Lp, Args...>& aEvent, size_t aN)"_ns,
|
||||
[&] { return values->size() == aN; });
|
||||
return Promise::CreateAndResolve(std::move(*values), __func__);
|
||||
});
|
||||
*listener = aEvent.Connect(AbstractThread::GetCurrent(),
|
||||
[values, listener, aN](Args... aValue) {
|
||||
values->push_back({aValue...});
|
||||
if (values->size() == aN) {
|
||||
listener->Disconnect();
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper that, given that canonicals have just been updated on the current
|
||||
* thread, will block its execution until mirrors and their watchers have
|
||||
|
|
|
@ -10,6 +10,7 @@ DEFINES["ENABLE_SET_CUBEB_BACKEND"] = True
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
"/dom/media/mediasink",
|
||||
"/dom/media/systemservices",
|
||||
"/dom/media/webrtc/common/",
|
||||
"/third_party/libwebrtc",
|
||||
"/third_party/libwebrtc/third_party/abseil-cpp",
|
||||
|
|
|
@ -22,6 +22,7 @@ if (
|
|||
LOCAL_INCLUDES += [
|
||||
"/dom/media",
|
||||
"/dom/media/gtest",
|
||||
"/dom/media/systemservices",
|
||||
"/dom/media/webrtc",
|
||||
"/dom/media/webrtc/common",
|
||||
"/dom/media/webrtc/common/time_profiling",
|
||||
|
|
Загрузка…
Ссылка в новой задаче