--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -193,48 +193,16 @@ NS_IMPL_RELEASE_INHERITED(MediaRecorder,
* 3) MediaRecorder::Stop is called by user or the document is going to
* inactive or invisible.
*/
class MediaRecorder::Session: public PrincipalChangeObserver<MediaStreamTrack>,
public DOMMediaStream::TrackListener
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Session)
- // Main thread task.
- // Create a blob event and send back to client.
- class PushBlobRunnable : public Runnable
- {
- public:
- explicit PushBlobRunnable(Session* aSession)
- : Runnable("dom::MediaRecorder::Session::PushBlobRunnable")
- , mSession(aSession)
- { }
-
- NS_IMETHOD Run() override
- {
- LOG(LogLevel::Debug, ("Session.PushBlobRunnable s=(%p)", mSession.get()));
- MOZ_ASSERT(NS_IsMainThread());
-
- RefPtr<MediaRecorder> recorder = mSession->mRecorder;
- if (!recorder) {
- return NS_OK;
- }
-
- nsresult rv = recorder->CreateAndDispatchBlobEvent(mSession->GetEncodedData());
- if (NS_FAILED(rv)) {
- recorder->NotifyError(rv);
- }
-
- return NS_OK;
- }
-
- private:
- RefPtr<Session> mSession;
- };
-
// Notify encoder error, run in main thread task. (Bug 1095381)
class EncoderErrorNotifierRunnable : public Runnable
{
public:
explicit EncoderErrorNotifierRunnable(Session* aSession)
: Runnable("dom::MediaRecorder::Session::EncoderErrorNotifierRunnable")
, mSession(aSession)
{ }
@@ -348,17 +316,16 @@ class MediaRecorder::Session: public Pri
}
protected:
RefPtr<TaskQueue> mEncoderThread;
RefPtr<Session> mSession;
};
friend class EncoderErrorNotifierRunnable;
- friend class PushBlobRunnable;
friend class TracksAvailableCallback;
public:
Session(MediaRecorder* aRecorder, int32_t aTimeSlice)
: mRecorder(aRecorder)
, mTimeSlice(aTimeSlice)
, mStopIssued(false)
, mIsStartEventFired(false)
@@ -478,19 +445,19 @@ public:
return NS_OK;
}
nsresult RequestData()
{
LOG(LogLevel::Debug, ("Session.RequestData"));
MOZ_ASSERT(NS_IsMainThread());
- if (NS_FAILED(NS_DispatchToMainThread(new PushBlobRunnable(this)))) {
+ if (NS_FAILED(NS_DispatchToMainThread(NewRunnableMethod(
+ "dom::MediaRecorder:Session::PushBlob", this, &Session::PushBlob)))) {
MOZ_ASSERT(false, "RequestData NS_DispatchToMainThread failed");
- return NS_ERROR_FAILURE;
}
return NS_OK;
}
already_AddRefed<nsIDOMBlob> GetEncodedData()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -520,20 +487,40 @@ public:
private:
// Only Destroy() is allowed to delete Session object on main thread.
virtual ~Session()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mShutdownPromise);
LOG(LogLevel::Debug, ("Session.~Session (%p)", this));
}
+
+ // Main thread task.
+ // Create a blob event and send back to client.
+ void PushBlob()
+ {
+ LOG(LogLevel::Debug, ("Session.PushBlob s=(%p)", this));
+ MOZ_ASSERT(NS_IsMainThread());
+
+ if (!mRecorder) {
+ // We're defensive just in case, but this shouldn't happen
+ MOZ_ASSERT_UNREACHABLE("PushBlob() called on already shutdown session");
+ return;
+ }
+
+ nsresult rv = mRecorder->CreateAndDispatchBlobEvent(GetEncodedData());
+ if (NS_FAILED(rv)) {
+ mRecorder->NotifyError(rv);
+ }
+ }
+
// Pull encoded media data from MediaEncoder and put into EncodedBufferCache.
// Destroy this session object in the end of this function.
// If the bool aForceFlush is true, we will force to dispatch a
- // PushBlobRunnable to main thread.
+ // PushBlob to main thread.
void Extract(bool aForceFlush)
{
MOZ_ASSERT(mEncoderThread->IsCurrentThreadIn());
LOG(LogLevel::Debug, ("Session.Extract %p", this));
AUTO_PROFILER_LABEL("MediaRecorder::Session::Extract", OTHER);
@@ -557,21 +544,23 @@ private:
// need a flush.
bool pushBlob = aForceFlush;
if (!pushBlob &&
mTimeSlice > 0 &&
(TimeStamp::Now()-mLastBlobTimeStamp).ToMilliseconds() > mTimeSlice) {
pushBlob = true;
}
if (pushBlob) {
- if (NS_FAILED(NS_DispatchToMainThread(new PushBlobRunnable(this)))) {
- MOZ_ASSERT(false, "NS_DispatchToMainThread PushBlobRunnable failed");
- } else {
- mLastBlobTimeStamp = TimeStamp::Now();
+ if (NS_FAILED(NS_DispatchToMainThread(
+ NewRunnableMethod("dom::MediaRecorder:Session::PushBlob",
+ this,
+ &Session::PushBlob)))) {
+ MOZ_ASSERT(false, "RequestData NS_DispatchToMainThread failed");
}
+ mLastBlobTimeStamp = TimeStamp::Now();
}
}
// Perform the steps needed to destroy a session. May reenter as this
// function needs to stop the recorder before the session can be properly
// shut down.
void Destroy()
{
@@ -878,18 +867,21 @@ private:
NS_DispatchToMainThread(
NewRunnableMethod<nsresult>("dom::MediaRecorder::NotifyError",
mRecorder,
&MediaRecorder::NotifyError,
rv));
}
if (rv != NS_ERROR_DOM_SECURITY_ERR) {
// Don't push a blob if there was a security error.
- if (NS_FAILED(NS_DispatchToMainThread(new PushBlobRunnable(this)))) {
- MOZ_ASSERT(false, "NS_DispatchToMainThread PushBlobRunnable failed");
+ if (NS_FAILED(NS_DispatchToMainThread(
+ NewRunnableMethod("dom::MediaRecorder:Session::PushBlob",
+ this,
+ &Session::PushBlob)))) {
+ MOZ_ASSERT(false, "RequestData NS_DispatchToMainThread failed");
}
}
if (NS_FAILED(NS_DispatchToMainThread(NewRunnableMethod(
"dom::MediaRecorder:Session::Destroy", this, &Session::Destroy)))) {
MOZ_ASSERT(false, "NS_DispatchToMainThread DestroyRunnable failed");
}
mNeedSessionEndTask = false;
}