Bug 1395802. P1 - add AbstractMainThread() to MediaResourceCallback.
This is required by P3 to preserve the ordering. E.g. we want
mChannelStatistics.AddBytes() to happen before the new data is consumed
by the decoder and is made observable to the main thread. Using
SystemGroup::Dispatch() won't guarantee the ordering.
MozReview-Commit-ID: 7MP0CzTGpOs
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -40,16 +40,22 @@ ChannelMediaDecoder::ResourceCallback::D
MOZ_ASSERT(NS_IsMainThread());
if (mDecoder) {
mDecoder = nullptr;
mTimer->Cancel();
mTimer = nullptr;
}
}
+AbstractThread*
+ChannelMediaDecoder::ResourceCallback::AbstractMainThread() const
+{
+ return mAbstractMainThread;
+}
+
MediaDecoderOwner*
ChannelMediaDecoder::ResourceCallback::GetMediaOwner() const
{
MOZ_ASSERT(NS_IsMainThread());
return mDecoder ? mDecoder->GetOwner() : nullptr;
}
void
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -31,16 +31,17 @@ class ChannelMediaDecoder : public Media
explicit ResourceCallback(AbstractThread* aMainThread);
// Start to receive notifications from ResourceCallback.
void Connect(ChannelMediaDecoder* aDecoder);
// Called upon shutdown to stop receiving notifications.
void Disconnect();
private:
/* MediaResourceCallback functions */
+ AbstractThread* AbstractMainThread() const override;
MediaDecoderOwner* GetMediaOwner() const override;
void NotifyNetworkError() override;
void NotifyDataArrived() override;
void NotifyDataEnded(nsresult aStatus) override;
void NotifyPrincipalChanged() override;
void NotifySuspendedStatusChanged(bool aSuspendedByCache) override;
void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) override;
--- a/dom/media/MediaResourceCallback.h
+++ b/dom/media/MediaResourceCallback.h
@@ -7,32 +7,36 @@
#ifndef MediaResourceCallback_h_
#define MediaResourceCallback_h_
#include "nsError.h"
#include "nsISupportsImpl.h"
namespace mozilla {
+class AbstractThread;
class MediaDecoderOwner;
class MediaResource;
/**
* A callback used by MediaResource (sub-classes like FileMediaResource,
* RtspMediaResource, and ChannelMediaResource) to notify various events.
* Currently this is implemented by MediaDecoder only.
*
* Since this class has no pure virtual function, it is convenient to write
* gtests for the readers without using a mock MediaResource when you don't
* care about the events notified by the MediaResource.
*/
class MediaResourceCallback {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaResourceCallback);
+ // Return an abstract thread on which to run main thread runnables.
+ virtual AbstractThread* AbstractMainThread() const { return nullptr; }
+
// Returns a weak reference to the media decoder owner.
virtual MediaDecoderOwner* GetMediaOwner() const { return nullptr; }
// Notify that a network error is encountered.
virtual void NotifyNetworkError() {}
// Notify that data arrives on the stream and is read into the cache.
virtual void NotifyDataArrived() {}