mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
d1af43433c
- Bug 1187817. Part 1 - Move Set{Volume,PlaybackRate,PreservesPitch} to the audio thread. r=kinetik. (a234a7080)
- Bug 1187817. Part 2 - remove unused code. r=kinetik. (836c52a19)
- Bug 1187763. Part 1 - move while loop out of WaitingForAudioToPlay(). r=kinetik. (a80d70f87)
- Bug 1187763. Part 2 - extract some code of AudioLoop() into its own function. r=kinetik. (275b8bfb6)
- Bug 1187763. Part 3 - refactor AudioSink::AudioLoop into a series of events. r=kinetik (7eb3f506f)
- Bug 1187817. Part 3 - move SetPlaying to the audio thread. r=kinetik. (0fef85968)
- Bug 1187817. Part 4 - move some code in Shutdown to the audio thread. r=kinetik. (8c73fbe6d)
- Bug 1187817. Part 5 - assert some code in the audio thread and don't enter the monitor. r=kinetik. (64de4616f)
- move include (f842b4b1e)
- Bug 1163486 - Update test to use new MP4Demuxer. r=bholley (b853be477)
- Bug 1190496 - Namespace the SharedThreadPool.h include. r=cpearce (196d25d42)
- Bug 1190496 - Hoist SharedThreadPool into xpcom. r=froydnj (3dad8176f)
- Bug 1190492 - Hoist AbstractThread and TaskDispatcher to xpcom. r=froydnj (c3329fa29)
- bug 1166107 documentation of mWaitForInternalDrain thread access r=gerald (f762764b1)
- correct comment (b623b2959)
- revert demuxer check from promise reject to assert like in 1156708 (f540b270c)
- more chekcs back to asserts (7e82a0f99)
- space (733bd85a3)
- Bug 1188220: Allow disabling HW acceleration even when SharedDecoderManager isn't used. r=cpearce (909a86682)
- bug 1161903 ensure pending DrainComplete is not run after Flush() r=cpearce (648cabbb7)
- Bug 1158089 - Fall back to d3d9 DXVA if d3d11 initialization fails. r=cpearce (84b3a8e6d)
255 lines
5.7 KiB
C++
255 lines
5.7 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 "SharedDecoderManager.h"
|
|
|
|
namespace mozilla {
|
|
|
|
class SharedDecoderCallback : public MediaDataDecoderCallback
|
|
{
|
|
public:
|
|
explicit SharedDecoderCallback(SharedDecoderManager* aManager)
|
|
: mManager(aManager)
|
|
{
|
|
}
|
|
|
|
virtual void Output(MediaData* aData) override
|
|
{
|
|
if (mManager->mActiveCallback) {
|
|
mManager->mActiveCallback->Output(aData);
|
|
}
|
|
}
|
|
virtual void Error() override
|
|
{
|
|
if (mManager->mActiveCallback) {
|
|
mManager->mActiveCallback->Error();
|
|
}
|
|
}
|
|
virtual void InputExhausted() override
|
|
{
|
|
if (mManager->mActiveCallback) {
|
|
mManager->mActiveCallback->InputExhausted();
|
|
}
|
|
}
|
|
virtual void DrainComplete() override
|
|
{
|
|
if (mManager->mActiveCallback) {
|
|
mManager->DrainComplete();
|
|
}
|
|
}
|
|
virtual void ReleaseMediaResources() override
|
|
{
|
|
if (mManager->mActiveCallback) {
|
|
mManager->mActiveCallback->ReleaseMediaResources();
|
|
}
|
|
}
|
|
|
|
SharedDecoderManager* mManager;
|
|
};
|
|
|
|
SharedDecoderManager::SharedDecoderManager()
|
|
: mTaskQueue(new FlushableTaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER)))
|
|
, mActiveProxy(nullptr)
|
|
, mActiveCallback(nullptr)
|
|
, mWaitForInternalDrain(false)
|
|
, mMonitor("SharedDecoderManager")
|
|
, mDecoderReleasedResources(false)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread()); // taskqueue must be created on main thread.
|
|
mCallback = new SharedDecoderCallback(this);
|
|
}
|
|
|
|
SharedDecoderManager::~SharedDecoderManager()
|
|
{
|
|
}
|
|
|
|
already_AddRefed<MediaDataDecoder>
|
|
SharedDecoderManager::CreateVideoDecoder(
|
|
PlatformDecoderModule* aPDM,
|
|
const VideoInfo& aConfig,
|
|
layers::LayersBackend aLayersBackend,
|
|
layers::ImageContainer* aImageContainer,
|
|
FlushableTaskQueue* aVideoTaskQueue,
|
|
MediaDataDecoderCallback* aCallback)
|
|
{
|
|
if (!mDecoder) {
|
|
mLayersBackend = aLayersBackend;
|
|
mImageContainer = aImageContainer;
|
|
// We use the manager's task queue for the decoder, rather than the one
|
|
// passed in, so that none of the objects sharing the decoder can shutdown
|
|
// the task queue while we're potentially still using it for a *different*
|
|
// object also sharing the decoder.
|
|
mDecoder =
|
|
aPDM->CreateDecoder(aConfig,
|
|
mTaskQueue,
|
|
mCallback,
|
|
mLayersBackend,
|
|
mImageContainer);
|
|
if (!mDecoder) {
|
|
mPDM = nullptr;
|
|
return nullptr;
|
|
}
|
|
nsresult rv = mDecoder->Init();
|
|
if (NS_FAILED(rv)) {
|
|
mDecoder = nullptr;
|
|
return nullptr;
|
|
}
|
|
mPDM = aPDM;
|
|
}
|
|
|
|
nsRefPtr<SharedDecoderProxy> proxy(new SharedDecoderProxy(this, aCallback));
|
|
return proxy.forget();
|
|
}
|
|
|
|
void
|
|
SharedDecoderManager::DisableHardwareAcceleration()
|
|
{
|
|
MOZ_ASSERT(mPDM);
|
|
mPDM->DisableHardwareAcceleration();
|
|
}
|
|
|
|
bool
|
|
SharedDecoderManager::Recreate(const VideoInfo& aConfig)
|
|
{
|
|
mDecoder->Flush();
|
|
mDecoder->Shutdown();
|
|
mDecoder = mPDM->CreateDecoder(aConfig,
|
|
mTaskQueue,
|
|
mCallback,
|
|
mLayersBackend,
|
|
mImageContainer);
|
|
if (!mDecoder) {
|
|
return false;
|
|
}
|
|
nsresult rv = mDecoder->Init();
|
|
return rv == NS_OK;
|
|
}
|
|
|
|
void
|
|
SharedDecoderManager::Select(SharedDecoderProxy* aProxy)
|
|
{
|
|
if (mActiveProxy == aProxy) {
|
|
return;
|
|
}
|
|
SetIdle(mActiveProxy);
|
|
|
|
mActiveProxy = aProxy;
|
|
mActiveCallback = aProxy->mCallback;
|
|
}
|
|
|
|
void
|
|
SharedDecoderManager::SetIdle(MediaDataDecoder* aProxy)
|
|
{
|
|
if (aProxy && mActiveProxy == aProxy) {
|
|
{
|
|
MonitorAutoLock mon(mMonitor);
|
|
mWaitForInternalDrain = true;
|
|
// We don't want to hold the lock while calling Drain() as some
|
|
// platform implementations call DrainComplete() immediately.
|
|
}
|
|
nsresult rv = mActiveProxy->Drain();
|
|
if (NS_SUCCEEDED(rv)) {
|
|
MonitorAutoLock mon(mMonitor);
|
|
while (mWaitForInternalDrain) {
|
|
mon.Wait();
|
|
}
|
|
}
|
|
mActiveProxy->Flush();
|
|
mActiveProxy = nullptr;
|
|
}
|
|
}
|
|
|
|
void
|
|
SharedDecoderManager::DrainComplete()
|
|
{
|
|
{
|
|
MonitorAutoLock mon(mMonitor);
|
|
if (mWaitForInternalDrain) {
|
|
mWaitForInternalDrain = false;
|
|
mon.NotifyAll();
|
|
return;
|
|
}
|
|
}
|
|
mActiveCallback->DrainComplete();
|
|
}
|
|
|
|
void
|
|
SharedDecoderManager::Shutdown()
|
|
{
|
|
if (mDecoder) {
|
|
mDecoder->Shutdown();
|
|
mDecoder = nullptr;
|
|
}
|
|
mPDM = nullptr;
|
|
if (mTaskQueue) {
|
|
mTaskQueue->BeginShutdown();
|
|
mTaskQueue->AwaitShutdownAndIdle();
|
|
mTaskQueue = nullptr;
|
|
}
|
|
}
|
|
|
|
SharedDecoderProxy::SharedDecoderProxy(SharedDecoderManager* aManager,
|
|
MediaDataDecoderCallback* aCallback)
|
|
: mManager(aManager)
|
|
, mCallback(aCallback)
|
|
{
|
|
}
|
|
|
|
SharedDecoderProxy::~SharedDecoderProxy()
|
|
{
|
|
Shutdown();
|
|
}
|
|
|
|
nsresult
|
|
SharedDecoderProxy::Init()
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
SharedDecoderProxy::Input(MediaRawData* aSample)
|
|
{
|
|
if (mManager->mActiveProxy != this) {
|
|
mManager->Select(this);
|
|
}
|
|
return mManager->mDecoder->Input(aSample);
|
|
}
|
|
|
|
nsresult
|
|
SharedDecoderProxy::Flush()
|
|
{
|
|
if (mManager->mActiveProxy == this) {
|
|
return mManager->mDecoder->Flush();
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
SharedDecoderProxy::Drain()
|
|
{
|
|
if (mManager->mActiveProxy == this) {
|
|
return mManager->mDecoder->Drain();
|
|
} else {
|
|
mCallback->DrainComplete();
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
SharedDecoderProxy::Shutdown()
|
|
{
|
|
mManager->SetIdle(this);
|
|
return NS_OK;
|
|
}
|
|
|
|
bool
|
|
SharedDecoderProxy::IsHardwareAccelerated() const
|
|
{
|
|
return mManager->mDecoder->IsHardwareAccelerated();
|
|
}
|
|
|
|
} // namespace mozilla
|