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
134 lines
3.0 KiB
C++
134 lines
3.0 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 "AndroidBridge.h"
|
|
#include "DecoderTraits.h"
|
|
#include "HLSDemuxer.h"
|
|
#include "HLSResource.h"
|
|
#include "HLSUtils.h"
|
|
#include "MediaContainerType.h"
|
|
#include "MediaDecoderStateMachine.h"
|
|
#include "MediaFormatReader.h"
|
|
#include "MediaPrefs.h"
|
|
#include "MediaShutdownManager.h"
|
|
#include "nsNetUtil.h"
|
|
|
|
namespace mozilla {
|
|
|
|
MediaResource*
|
|
HLSDecoder::GetResource() const
|
|
{
|
|
return mResource;
|
|
}
|
|
|
|
void
|
|
HLSDecoder::Shutdown()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (mResource) {
|
|
mResource->Detach();
|
|
}
|
|
MediaDecoder::Shutdown();
|
|
}
|
|
|
|
MediaDecoderStateMachine*
|
|
HLSDecoder::CreateStateMachine()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mResource);
|
|
auto resourceWrapper = mResource->GetResourceWrapper();
|
|
MOZ_ASSERT(resourceWrapper);
|
|
MediaFormatReaderInit init;
|
|
init.mVideoFrameContainer = GetVideoFrameContainer();
|
|
init.mKnowsCompositor = GetCompositor();
|
|
init.mCrashHelper = GetOwner()->CreateGMPCrashHelper();
|
|
init.mFrameStats = mFrameStats;
|
|
mReader =
|
|
new MediaFormatReader(init, new HLSDemuxer(resourceWrapper->GetPlayerId()));
|
|
|
|
return new MediaDecoderStateMachine(this, mReader);
|
|
}
|
|
|
|
bool
|
|
HLSDecoder::IsEnabled()
|
|
{
|
|
return MediaPrefs::HLSEnabled() && (jni::GetAPIVersion() >= 16);
|
|
}
|
|
|
|
bool
|
|
HLSDecoder::IsSupportedType(const MediaContainerType& aContainerType)
|
|
{
|
|
return IsEnabled() &&
|
|
DecoderTraits::IsHttpLiveStreamingType(aContainerType);
|
|
}
|
|
|
|
nsresult
|
|
HLSDecoder::Load(nsIChannel* aChannel)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(!mResource);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
mResource = new HLSResource(this, aChannel, uri);
|
|
|
|
rv = MediaShutdownManager::Instance().Register(this);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
SetStateMachine(CreateStateMachine());
|
|
NS_ENSURE_TRUE(GetStateMachine(), NS_ERROR_FAILURE);
|
|
|
|
return InitializeStateMachine();
|
|
}
|
|
|
|
nsresult
|
|
HLSDecoder::Play()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
HLS_DEBUG("HLSDecoder", "MediaElement called Play");
|
|
auto resourceWrapper = mResource->GetResourceWrapper();
|
|
resourceWrapper->Play();
|
|
return MediaDecoder::Play();
|
|
}
|
|
|
|
void
|
|
HLSDecoder::Pause()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
HLS_DEBUG("HLSDecoder", "MediaElement called Pause");
|
|
auto resourceWrapper = mResource->GetResourceWrapper();
|
|
resourceWrapper->Pause();
|
|
return MediaDecoder::Pause();
|
|
}
|
|
|
|
void
|
|
HLSDecoder::Suspend()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (mResource) {
|
|
mResource->Suspend();
|
|
}
|
|
}
|
|
|
|
void
|
|
HLSDecoder::Resume()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (mResource) {
|
|
mResource->Resume();
|
|
}
|
|
}
|
|
|
|
} // namespace mozilla
|