2017-05-05 11:40:29 +03:00
|
|
|
/* -*- 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"
|
2017-06-14 12:47:11 +03:00
|
|
|
#include "HLSResource.h"
|
2017-05-05 11:40:29 +03:00
|
|
|
#include "HLSUtils.h"
|
|
|
|
#include "MediaContainerType.h"
|
|
|
|
#include "MediaDecoderStateMachine.h"
|
|
|
|
#include "MediaFormatReader.h"
|
|
|
|
#include "MediaPrefs.h"
|
2017-06-30 05:11:42 +03:00
|
|
|
#include "MediaShutdownManager.h"
|
|
|
|
#include "nsNetUtil.h"
|
2017-05-05 11:40:29 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
MediaDecoderStateMachine*
|
|
|
|
HLSDecoder::CreateStateMachine()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-06-14 12:47:11 +03:00
|
|
|
MediaResource* resource = GetResource();
|
|
|
|
MOZ_ASSERT(resource);
|
|
|
|
auto resourceWrapper = static_cast<HLSResource*>(resource)->GetResourceWrapper();
|
|
|
|
MOZ_ASSERT(resourceWrapper);
|
2017-05-05 11:40:29 +03:00
|
|
|
mReader =
|
|
|
|
new MediaFormatReader(this,
|
2017-06-14 12:47:11 +03:00
|
|
|
new HLSDemuxer(resourceWrapper->GetPlayerId()),
|
2017-05-05 11:40:29 +03:00
|
|
|
GetVideoFrameContainer());
|
|
|
|
|
|
|
|
return new MediaDecoderStateMachine(this, mReader);
|
|
|
|
}
|
|
|
|
|
2017-06-20 13:10:27 +03:00
|
|
|
ChannelMediaDecoder*
|
2017-05-05 11:40:29 +03:00
|
|
|
HLSDecoder::Clone(MediaDecoderInit& aInit)
|
|
|
|
{
|
|
|
|
if (!IsEnabled()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new HLSDecoder(aInit);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HLSDecoder::IsEnabled()
|
|
|
|
{
|
|
|
|
return MediaPrefs::HLSEnabled() && (jni::GetAPIVersion() >= 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HLSDecoder::IsSupportedType(const MediaContainerType& aContainerType)
|
|
|
|
{
|
2017-05-31 13:37:23 +03:00
|
|
|
return IsEnabled() &&
|
|
|
|
DecoderTraits::IsHttpLiveStreamingType(aContainerType);
|
2017-05-05 11:40:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 05:11:42 +03:00
|
|
|
nsresult
|
|
|
|
HLSDecoder::Load(nsIChannel* aChannel,
|
|
|
|
bool aIsPrivateBrowsing,
|
|
|
|
nsIStreamListener**)
|
|
|
|
{
|
|
|
|
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(mResourceCallback, 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::Load(MediaResource*)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("Clone is not supported");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:40:29 +03:00
|
|
|
} // namespace mozilla
|