mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
cf112f4b88
So we reduce the number of unimplemented methods in the sub-classes of MediaResource. MozReview-Commit-ID: EAmUEv9WQk8 --HG-- extra : rebase_source : deed5fd089e8c42a5a6ab0546e0781d0061591e5
118 lines
2.9 KiB
C++
118 lines
2.9 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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"
|
|
|
|
using namespace mozilla::java;
|
|
|
|
namespace mozilla {
|
|
|
|
HLSResourceCallbacksSupport::HLSResourceCallbacksSupport(HLSResource* aResource)
|
|
{
|
|
MOZ_ASSERT(aResource);
|
|
mResource = aResource;
|
|
}
|
|
|
|
void
|
|
HLSResourceCallbacksSupport::Detach()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mResource = nullptr;
|
|
}
|
|
|
|
void
|
|
HLSResourceCallbacksSupport::OnDataArrived()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (mResource) {
|
|
mResource->onDataAvailable();
|
|
}
|
|
}
|
|
|
|
void
|
|
HLSResourceCallbacksSupport::OnError(int aErrorCode)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (mResource) {
|
|
mResource->onError(aErrorCode);
|
|
}
|
|
}
|
|
|
|
HLSResource::HLSResource(HLSDecoder* aDecoder,
|
|
nsIChannel* aChannel,
|
|
nsIURI* aURI)
|
|
: mDecoder(aDecoder)
|
|
, mChannel(aChannel)
|
|
, mURI(aURI)
|
|
{
|
|
nsCString spec;
|
|
nsresult rv = aURI->GetSpec(spec);
|
|
(void)rv;
|
|
HLSResourceCallbacksSupport::Init();
|
|
mJavaCallbacks = GeckoHLSResourceWrapper::Callbacks::New();
|
|
mCallbackSupport = new HLSResourceCallbacksSupport(this);
|
|
HLSResourceCallbacksSupport::AttachNative(mJavaCallbacks, mCallbackSupport);
|
|
mHLSResourceWrapper = java::GeckoHLSResourceWrapper::Create(NS_ConvertUTF8toUTF16(spec),
|
|
mJavaCallbacks);
|
|
MOZ_ASSERT(mHLSResourceWrapper);
|
|
}
|
|
|
|
void
|
|
HLSResource::onDataAvailable()
|
|
{
|
|
HLS_DEBUG("HLSResource", "onDataAvailable");
|
|
if (mDecoder) {
|
|
mDecoder->NotifyDataArrived();
|
|
}
|
|
}
|
|
|
|
void
|
|
HLSResource::onError(int aErrorCode)
|
|
{
|
|
HLS_DEBUG("HLSResource", "onError(%d)", aErrorCode);
|
|
// Since HLS source should be from the Internet, we treat all resource errors
|
|
// from GeckoHlsPlayer as network errors.
|
|
if (mDecoder) {
|
|
mDecoder->NetworkError();
|
|
}
|
|
}
|
|
|
|
void
|
|
HLSResource::Suspend()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Don't call on non-main thread");
|
|
HLS_DEBUG("HLSResource", "Should suspend the resource fetching.");
|
|
mHLSResourceWrapper->Suspend();
|
|
}
|
|
|
|
void HLSResource::Resume()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Don't call on non-main thread");
|
|
HLS_DEBUG("HLSResource", "Should resume the resource fetching.");
|
|
mHLSResourceWrapper->Resume();
|
|
}
|
|
|
|
HLSResource::~HLSResource()
|
|
{
|
|
HLS_DEBUG("HLSResource", "~HLSResource()");
|
|
if (mCallbackSupport) {
|
|
mCallbackSupport->Detach();
|
|
mCallbackSupport = nullptr;
|
|
}
|
|
if (mHLSResourceWrapper) {
|
|
mHLSResourceWrapper->Destroy();
|
|
mHLSResourceWrapper = nullptr;
|
|
}
|
|
if (mJavaCallbacks) {
|
|
HLSResourceCallbacksSupport::DisposeNative(mJavaCallbacks);
|
|
mJavaCallbacks = nullptr;
|
|
}
|
|
}
|
|
|
|
} // namespace mozilla
|