Bug 1079616 - Dispatch PushBlobRunnable in RequestData function, and remove CreateAndDispatchBlobEventRunnable. r=roc
--- a/content/media/MediaRecorder.cpp
+++ b/content/media/MediaRecorder.cpp
@@ -381,16 +381,29 @@ public:
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE(mTrackUnionStream, NS_ERROR_FAILURE);
mTrackUnionStream->ChangeExplicitBlockerCount(-1);
return NS_OK;
}
+ nsresult RequestData()
+ {
+ LOG(PR_LOG_DEBUG, ("Session.RequestData"));
+ MOZ_ASSERT(NS_IsMainThread());
+
+ if (NS_FAILED(NS_DispatchToMainThread(new PushBlobRunnable(this)))) {
+ MOZ_ASSERT(false, "RequestData NS_DispatchToMainThread failed");
+ return NS_ERROR_FAILURE;
+ }
+
+ return NS_OK;
+ }
+
already_AddRefed<nsIDOMBlob> GetEncodedData()
{
MOZ_ASSERT(NS_IsMainThread());
return mEncodedBufferCache->ExtractBlob(mRecorder->GetParentObject(),
mMimeType);
}
bool IsEncoderError()
@@ -811,47 +824,27 @@ MediaRecorder::Resume(ErrorResult& aResu
nsresult rv = mSessions.LastElement()->Resume();
if (NS_FAILED(rv)) {
NotifyError(rv);
return;
}
mState = RecordingState::Recording;
}
-class CreateAndDispatchBlobEventRunnable : public nsRunnable {
- nsCOMPtr<nsIDOMBlob> mBlob;
- nsRefPtr<MediaRecorder> mRecorder;
-public:
- CreateAndDispatchBlobEventRunnable(already_AddRefed<nsIDOMBlob>&& aBlob,
- MediaRecorder* aRecorder)
- : mBlob(aBlob), mRecorder(aRecorder)
- { }
-
- NS_IMETHOD
- Run();
-};
-
-NS_IMETHODIMP
-CreateAndDispatchBlobEventRunnable::Run()
-{
- return mRecorder->CreateAndDispatchBlobEvent(mBlob.forget());
-}
-
void
MediaRecorder::RequestData(ErrorResult& aResult)
{
if (mState != RecordingState::Recording) {
aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
MOZ_ASSERT(mSessions.Length() > 0);
- if (NS_FAILED(NS_DispatchToMainThread(
- new CreateAndDispatchBlobEventRunnable(
- mSessions.LastElement()->GetEncodedData(), this)))) {
- MOZ_ASSERT(false, "NS_DispatchToMainThread CreateAndDispatchBlobEventRunnable failed");
+ nsresult rv = mSessions.LastElement()->RequestData();
+ if (NS_FAILED(rv)) {
+ NotifyError(rv);
}
}
JSObject*
MediaRecorder::WrapObject(JSContext* aCx)
{
return MediaRecorderBinding::Wrap(aCx, this);
}
--- a/content/media/MediaRecorder.h
+++ b/content/media/MediaRecorder.h
@@ -37,17 +37,16 @@ class AudioNode;
* When the recorder starts, it creates a "Media Encoder" thread to read data from MediaEncoder object and store buffer in EncodedBufferCache object.
* Also extract the encoded data and create blobs on every timeslice passed from start function or RequestData function called by UA.
*/
class MediaRecorder : public DOMEventTargetHelper,
public nsIDocumentActivity
{
class Session;
- friend class CreateAndDispatchBlobEventRunnable;
public:
MediaRecorder(DOMMediaStream& aSourceMediaStream, nsPIDOMWindow* aOwnerWindow);
MediaRecorder(AudioNode& aSrcAudioNode, uint32_t aSrcOutput, nsPIDOMWindow* aOwnerWindow);
// nsWrapperCache
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;