Bug 1384831. P3 - let HLSResource notify HLSDecoder directly without going through MediaResourceCallback. r=kikuo

We can't use MediaResourceCallback since HLSDecoder will not inherit ChannelMediaDecoder.

MozReview-Commit-ID: BzKatvYU90Y

--HG--
extra : rebase_source : a3fea763ef5f484fd1e455add4e6e6c91277aff1
extra : source : a9332539c0bc1ef81286b0e119250c3fce84101b
This commit is contained in:
JW Wang 2017-07-26 23:26:17 +08:00
parent 197591cec8
commit e72f601403
4 changed files with 28 additions and 11 deletions

View File

@ -19,6 +19,17 @@
namespace mozilla {
void
HLSDecoder::Shutdown()
{
MOZ_ASSERT(NS_IsMainThread());
auto resource = static_cast<HLSResource*>(mResource.get());
if (resource) {
resource->Detach();
}
ChannelMediaDecoder::Shutdown();
}
MediaDecoderStateMachine*
HLSDecoder::CreateStateMachine()
{
@ -73,7 +84,7 @@ HLSDecoder::Load(nsIChannel* aChannel,
return rv;
}
mResource = new HLSResource(mResourceCallback, aChannel, uri);
mResource = new HLSResource(this, aChannel, uri);
rv = MediaShutdownManager::Instance().Register(this);
if (NS_WARN_IF(NS_FAILED(rv))) {

View File

@ -21,6 +21,8 @@ public:
{
}
void Shutdown() override;
ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) override;
MediaDecoderStateMachine* CreateStateMachine() override;

View File

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "HLSDecoder.h"
#include "HLSResource.h"
#include "HLSUtils.h"
@ -42,10 +43,10 @@ HLSResourceCallbacksSupport::OnError(int aErrorCode)
}
}
HLSResource::HLSResource(MediaResourceCallback* aCallback,
HLSResource::HLSResource(HLSDecoder* aDecoder,
nsIChannel* aChannel,
nsIURI* aURI)
: mCallback(aCallback)
: mDecoder(aDecoder)
, mChannel(aChannel)
, mURI(aURI)
{
@ -64,19 +65,21 @@ HLSResource::HLSResource(MediaResourceCallback* aCallback,
void
HLSResource::onDataAvailable()
{
MOZ_ASSERT(mCallback);
HLS_DEBUG("HLSResource", "onDataAvailable");
mCallback->NotifyDataArrived();
if (mDecoder) {
mDecoder->NotifyDataArrived();
}
}
void
HLSResource::onError(int aErrorCode)
{
MOZ_ASSERT(mCallback);
HLS_DEBUG("HLSResource", "onError(%d)", aErrorCode);
// Since HLS source should be from the Internet, we treat all resource errors
// from GeckoHlsPlayer as network errors.
mCallback->NotifyNetworkError();
if (mDecoder) {
mDecoder->NetworkError();
}
}
void HLSResource::Suspend(bool aCloseImmediately)

View File

@ -18,6 +18,7 @@ using namespace mozilla::java;
namespace mozilla {
class HLSDecoder;
class HLSResource;
class HLSResourceCallbacksSupport
@ -42,9 +43,7 @@ private:
class HLSResource final : public MediaResource
{
public:
HLSResource(MediaResourceCallback* aCallback,
nsIChannel* aChannel,
nsIURI* aURI);
HLSResource(HLSDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI);
~HLSResource();
nsresult Close() override { return NS_OK; }
void Suspend(bool aCloseImmediately) override;
@ -100,6 +99,8 @@ public:
return mHLSResourceWrapper;
}
void Detach() { mDecoder = nullptr; }
private:
friend class HLSResourceCallbacksSupport;
@ -117,7 +118,7 @@ private:
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
RefPtr<MediaResourceCallback> mCallback;
HLSDecoder* mDecoder;
nsCOMPtr<nsIChannel> mChannel;
nsCOMPtr<nsIURI> mURI;
java::GeckoHLSResourceWrapper::GlobalRef mHLSResourceWrapper;