2015-05-18 08:40:32 +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/. */
|
|
|
|
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "MediaFormatReader.h"
|
|
|
|
|
2018-08-17 18:52:47 +03:00
|
|
|
#include "AllocationPolicy.h"
|
2019-02-28 23:10:17 +03:00
|
|
|
#include "GeckoProfiler.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
#include "MediaData.h"
|
|
|
|
#include "MediaInfo.h"
|
2016-05-27 09:33:48 +03:00
|
|
|
#include "VideoFrameContainer.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "VideoUtils.h"
|
2016-11-29 08:03:36 +03:00
|
|
|
#include "mozilla/AbstractThread.h"
|
2016-11-28 13:08:01 +03:00
|
|
|
#include "mozilla/CDMProxy.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2017-12-06 01:36:50 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2016-11-28 13:08:01 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/SharedThreadPool.h"
|
2018-03-20 01:48:56 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2018-06-07 15:50:10 +03:00
|
|
|
#include "mozilla/TaskQueue.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2017-01-26 15:56:46 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-11-28 13:08:01 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsPrintfCString.h"
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
#include <algorithm>
|
2017-08-31 12:56:17 +03:00
|
|
|
#include <map>
|
2016-10-28 12:43:19 +03:00
|
|
|
#include <queue>
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-05-31 07:18:12 +03:00
|
|
|
using namespace mozilla::media;
|
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
static mozilla::LazyLogModule sFormatDecoderLog("MediaFormatReader");
|
2016-07-24 15:30:07 +03:00
|
|
|
mozilla::LazyLogModule gMediaDemuxerLog("MediaDemuxer");
|
2015-11-15 16:49:01 +03:00
|
|
|
|
2017-10-13 08:31:59 +03:00
|
|
|
#define LOG(arg, ...) \
|
|
|
|
DDMOZ_LOG(sFormatDecoderLog, mozilla::LogLevel::Debug, "::%s: " arg, \
|
|
|
|
__func__, ##__VA_ARGS__)
|
|
|
|
#define LOGV(arg, ...) \
|
|
|
|
DDMOZ_LOG(sFormatDecoderLog, mozilla::LogLevel::Verbose, "::%s: " arg, \
|
|
|
|
__func__, ##__VA_ARGS__)
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-03-01 06:58:39 +03:00
|
|
|
#define NS_DispatchToMainThread(...) CompileError_UseAbstractMainThreadInstead
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2017-08-31 12:56:17 +03:00
|
|
|
typedef void* MediaDataDecoderID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This helper class is used to report telemetry of the time used to recover a
|
|
|
|
* decoder from GPU crash.
|
|
|
|
* It uses MediaDecoderOwnerID to identify which video we're dealing with.
|
|
|
|
* It uses MediaDataDecoderID to make sure that the old MediaDataDecoder has
|
|
|
|
* been deleted and we're already recovered.
|
|
|
|
* It reports two recovery times, one is calculated from GPU crashed (that is,
|
|
|
|
* the time when VideoDecoderChild::ActorDestory() is called) and the other is
|
|
|
|
* calculated from the MFR is notified with NS_ERROR_DOM_MEDIA_NEED_NEW_DECODER
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
class GPUProcessCrashTelemetryLogger {
|
|
|
|
struct GPUCrashData {
|
|
|
|
GPUCrashData(MediaDataDecoderID aMediaDataDecoderID,
|
|
|
|
mozilla::TimeStamp aGPUCrashTime,
|
|
|
|
mozilla::TimeStamp aErrorNotifiedTime)
|
|
|
|
: mMediaDataDecoderID(aMediaDataDecoderID),
|
|
|
|
mGPUCrashTime(aGPUCrashTime),
|
|
|
|
mErrorNotifiedTime(aErrorNotifiedTime) {
|
|
|
|
MOZ_ASSERT(mMediaDataDecoderID);
|
|
|
|
MOZ_ASSERT(!mGPUCrashTime.IsNull());
|
|
|
|
MOZ_ASSERT(!mErrorNotifiedTime.IsNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaDataDecoderID mMediaDataDecoderID;
|
|
|
|
mozilla::TimeStamp mGPUCrashTime;
|
|
|
|
mozilla::TimeStamp mErrorNotifiedTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void RecordGPUCrashData(MediaDecoderOwnerID aMediaDecoderOwnerID,
|
|
|
|
MediaDataDecoderID aMediaDataDecoderID,
|
|
|
|
const TimeStamp& aGPUCrashTime,
|
|
|
|
const TimeStamp& aErrorNotifiedTime) {
|
|
|
|
MOZ_ASSERT(aMediaDecoderOwnerID);
|
|
|
|
MOZ_ASSERT(aMediaDataDecoderID);
|
|
|
|
MOZ_ASSERT(!aGPUCrashTime.IsNull());
|
|
|
|
MOZ_ASSERT(!aErrorNotifiedTime.IsNull());
|
2017-10-16 09:03:04 +03:00
|
|
|
StaticMutexAutoLock lock(sGPUCrashMapMutex);
|
2017-08-31 12:56:17 +03:00
|
|
|
auto it = sGPUCrashDataMap.find(aMediaDecoderOwnerID);
|
|
|
|
if (it == sGPUCrashDataMap.end()) {
|
|
|
|
sGPUCrashDataMap.insert(std::make_pair(
|
|
|
|
aMediaDecoderOwnerID, GPUCrashData(aMediaDataDecoderID, aGPUCrashTime,
|
|
|
|
aErrorNotifiedTime)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReportTelemetry(MediaDecoderOwnerID aMediaDecoderOwnerID,
|
|
|
|
MediaDataDecoderID aMediaDataDecoderID) {
|
|
|
|
MOZ_ASSERT(aMediaDecoderOwnerID);
|
|
|
|
MOZ_ASSERT(aMediaDataDecoderID);
|
2017-10-16 09:03:04 +03:00
|
|
|
StaticMutexAutoLock lock(sGPUCrashMapMutex);
|
2017-08-31 12:56:17 +03:00
|
|
|
auto it = sGPUCrashDataMap.find(aMediaDecoderOwnerID);
|
|
|
|
if (it != sGPUCrashDataMap.end() &&
|
|
|
|
it->second.mMediaDataDecoderID != aMediaDataDecoderID) {
|
|
|
|
Telemetry::AccumulateTimeDelta(
|
|
|
|
Telemetry::VIDEO_HW_DECODER_CRASH_RECOVERY_TIME_SINCE_GPU_CRASHED_MS,
|
|
|
|
it->second.mGPUCrashTime);
|
|
|
|
Telemetry::AccumulateTimeDelta(
|
|
|
|
Telemetry::VIDEO_HW_DECODER_CRASH_RECOVERY_TIME_SINCE_MFR_NOTIFIED_MS,
|
|
|
|
it->second.mErrorNotifiedTime);
|
|
|
|
sGPUCrashDataMap.erase(aMediaDecoderOwnerID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static std::map<MediaDecoderOwnerID, GPUCrashData> sGPUCrashDataMap;
|
2017-10-16 09:03:04 +03:00
|
|
|
static StaticMutex sGPUCrashMapMutex;
|
2017-08-31 12:56:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
std::map<MediaDecoderOwnerID, GPUProcessCrashTelemetryLogger::GPUCrashData>
|
|
|
|
GPUProcessCrashTelemetryLogger::sGPUCrashDataMap;
|
2017-10-16 09:03:04 +03:00
|
|
|
StaticMutex GPUProcessCrashTelemetryLogger::sGPUCrashMapMutex;
|
2017-08-31 12:56:17 +03:00
|
|
|
|
2017-02-17 13:30:39 +03:00
|
|
|
/**
|
|
|
|
* This class addresses the concern of bug 1339310 comment 4 where the Widevine
|
|
|
|
* CDM doesn't support running multiple instances of a video decoder at once per
|
|
|
|
* CDM instance by sequencing the order of decoder creation and shutdown. Note
|
|
|
|
* this class addresses a different concern from that of GlobalAllocPolicy which
|
|
|
|
* controls a system-wide number of decoders while this class control a per-MFR
|
|
|
|
* number (which is one per CDM requirement).
|
|
|
|
*/
|
|
|
|
class LocalAllocPolicy {
|
|
|
|
using TrackType = TrackInfo::TrackType;
|
|
|
|
using Promise = GlobalAllocPolicy::Promise;
|
|
|
|
using Token = GlobalAllocPolicy::Token;
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(LocalAllocPolicy)
|
|
|
|
|
|
|
|
public:
|
|
|
|
LocalAllocPolicy(TrackType aTrack, TaskQueue* aOwnerThread)
|
|
|
|
: mTrack(aTrack), mOwnerThread(aOwnerThread) {}
|
|
|
|
|
|
|
|
// Acquire a token for decoder creation. Note the resolved token will
|
|
|
|
// aggregate a GlobalAllocPolicy token to comply to its policy. Note
|
|
|
|
// this function shouldn't be called again until the returned promise
|
|
|
|
// is resolved or rejected.
|
|
|
|
RefPtr<Promise> Alloc();
|
|
|
|
|
|
|
|
// Cancel the request to GlobalAllocPolicy and reject the current token
|
|
|
|
// request. Note this must happen before mOwnerThread->BeginShutdown().
|
|
|
|
void Cancel();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* An RAII class to manage LocalAllocPolicy::mDecoderLimit.
|
|
|
|
*/
|
|
|
|
class AutoDeallocToken : public Token {
|
|
|
|
public:
|
|
|
|
explicit AutoDeallocToken(LocalAllocPolicy* aOwner) : mOwner(aOwner) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mOwner->mDecoderLimit > 0);
|
|
|
|
--mOwner->mDecoderLimit;
|
|
|
|
}
|
|
|
|
// Aggregate a GlobalAllocPolicy token to present a single instance of
|
|
|
|
// Token to the client so the client doesn't have to deal with
|
|
|
|
// GlobalAllocPolicy and LocalAllocPolicy separately.
|
|
|
|
void Append(Token* aToken) { mToken = aToken; }
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2017-02-17 13:30:39 +03:00
|
|
|
private:
|
|
|
|
// Release tokens allocated from GlobalAllocPolicy and LocalAllocPolicy
|
|
|
|
// and process next token request if any.
|
|
|
|
~AutoDeallocToken() {
|
|
|
|
mToken = nullptr; // Dealloc the global token.
|
|
|
|
++mOwner->mDecoderLimit; // Dealloc the local token.
|
|
|
|
mOwner->ProcessRequest(); // Process next pending request.
|
|
|
|
}
|
|
|
|
RefPtr<LocalAllocPolicy> mOwner;
|
|
|
|
RefPtr<Token> mToken;
|
|
|
|
};
|
|
|
|
|
|
|
|
~LocalAllocPolicy() {}
|
|
|
|
void ProcessRequest();
|
|
|
|
|
|
|
|
int mDecoderLimit = 1;
|
|
|
|
const TrackType mTrack;
|
|
|
|
RefPtr<TaskQueue> mOwnerThread;
|
|
|
|
MozPromiseHolder<Promise> mPendingPromise;
|
|
|
|
MozPromiseRequestHolder<Promise> mTokenRequest;
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<LocalAllocPolicy::Promise> LocalAllocPolicy::Alloc() {
|
|
|
|
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPendingPromise.IsEmpty());
|
|
|
|
RefPtr<Promise> p = mPendingPromise.Ensure(__func__);
|
|
|
|
if (mDecoderLimit > 0) {
|
|
|
|
ProcessRequest();
|
|
|
|
}
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalAllocPolicy::ProcessRequest() {
|
|
|
|
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mDecoderLimit > 0);
|
|
|
|
|
|
|
|
// No pending request.
|
|
|
|
if (mPendingPromise.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<AutoDeallocToken> token = new AutoDeallocToken(this);
|
|
|
|
RefPtr<LocalAllocPolicy> self = this;
|
|
|
|
|
|
|
|
GlobalAllocPolicy::Instance(mTrack)
|
|
|
|
.Alloc()
|
|
|
|
->Then(mOwnerThread, __func__,
|
2017-05-11 03:30:39 +03:00
|
|
|
[self, token](RefPtr<Token> aToken) {
|
2017-02-17 13:30:39 +03:00
|
|
|
self->mTokenRequest.Complete();
|
|
|
|
token->Append(aToken);
|
|
|
|
self->mPendingPromise.Resolve(token, __func__);
|
|
|
|
},
|
|
|
|
[self, token]() {
|
|
|
|
self->mTokenRequest.Complete();
|
|
|
|
self->mPendingPromise.Reject(true, __func__);
|
|
|
|
})
|
|
|
|
->Track(mTokenRequest);
|
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2017-02-17 13:30:39 +03:00
|
|
|
void LocalAllocPolicy::Cancel() {
|
|
|
|
MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
|
|
|
|
mPendingPromise.RejectIfExists(true, __func__);
|
|
|
|
mTokenRequest.DisconnectIfExists();
|
|
|
|
}
|
|
|
|
|
2017-02-17 14:29:43 +03:00
|
|
|
/**
|
|
|
|
* This class tracks shutdown promises to ensure all decoders are shut down
|
|
|
|
* completely before MFR continues the rest of the shutdown procedure.
|
|
|
|
*/
|
|
|
|
class MediaFormatReader::ShutdownPromisePool {
|
|
|
|
public:
|
|
|
|
ShutdownPromisePool()
|
|
|
|
: mOnShutdownComplete(new ShutdownPromise::Private(__func__)) {}
|
|
|
|
|
|
|
|
// Return a promise which will be resolved when all the tracking promises
|
|
|
|
// are resolved. Note no more promises should be added for tracking once
|
|
|
|
// this function is called.
|
|
|
|
RefPtr<ShutdownPromise> Shutdown();
|
|
|
|
|
|
|
|
// Track a shutdown promise.
|
|
|
|
void Track(RefPtr<ShutdownPromise> aPromise);
|
|
|
|
|
|
|
|
// Shut down a decoder and track its shutdown promise.
|
|
|
|
void ShutdownDecoder(already_AddRefed<MediaDataDecoder> aDecoder) {
|
|
|
|
Track(RefPtr<MediaDataDecoder>(aDecoder)->Shutdown());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mShutdown = false;
|
|
|
|
const RefPtr<ShutdownPromise::Private> mOnShutdownComplete;
|
|
|
|
nsTHashtable<nsRefPtrHashKey<ShutdownPromise>> mPromises;
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<ShutdownPromise> MediaFormatReader::ShutdownPromisePool::Shutdown() {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mShutdown);
|
|
|
|
mShutdown = true;
|
|
|
|
if (mPromises.Count() == 0) {
|
|
|
|
mOnShutdownComplete->Resolve(true, __func__);
|
|
|
|
}
|
|
|
|
return mOnShutdownComplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::ShutdownPromisePool::Track(
|
|
|
|
RefPtr<ShutdownPromise> aPromise) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mShutdown);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mPromises.Contains(aPromise));
|
|
|
|
mPromises.PutEntry(aPromise);
|
|
|
|
aPromise->Then(AbstractThread::GetCurrent(), __func__, [aPromise, this]() {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPromises.Contains(aPromise));
|
|
|
|
mPromises.RemoveEntry(aPromise);
|
|
|
|
if (mShutdown && mPromises.Count() == 0) {
|
|
|
|
mOnShutdownComplete->Resolve(true, __func__);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-24 12:27:42 +03:00
|
|
|
void MediaFormatReader::DecoderData::ShutdownDecoder() {
|
|
|
|
MutexAutoLock lock(mMutex);
|
2017-02-26 17:51:22 +03:00
|
|
|
|
|
|
|
if (!mDecoder) {
|
|
|
|
// No decoder to shut down.
|
|
|
|
return;
|
2017-02-24 12:27:42 +03:00
|
|
|
}
|
2017-02-26 17:51:22 +03:00
|
|
|
|
|
|
|
if (mFlushing) {
|
|
|
|
// Flush is is in action. Shutdown will be initiated after flush completes.
|
2017-02-27 04:56:36 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mShutdownPromise);
|
|
|
|
mOwner->mShutdownPromisePool->Track(mShutdownPromise->Ensure(__func__));
|
|
|
|
// The order of decoder creation and shutdown is handled by LocalAllocPolicy
|
|
|
|
// and ShutdownPromisePool. MFR can now reset these members to a fresh state
|
|
|
|
// and be ready to create new decoders again without explicitly waiting for
|
|
|
|
// flush/shutdown to complete.
|
|
|
|
mShutdownPromise = nullptr;
|
|
|
|
mFlushing = false;
|
2017-02-26 17:51:22 +03:00
|
|
|
} else {
|
|
|
|
// No flush is in action. We can shut down the decoder now.
|
|
|
|
mOwner->mShutdownPromisePool->Track(mDecoder->Shutdown());
|
|
|
|
}
|
|
|
|
|
|
|
|
// mShutdownPromisePool will handle the order of decoder shutdown so
|
|
|
|
// we can forget mDecoder and be ready to create a new one.
|
2017-02-24 12:27:42 +03:00
|
|
|
mDecoder = nullptr;
|
2017-09-01 15:25:28 +03:00
|
|
|
mDescription = NS_LITERAL_CSTRING("shutdown");
|
2019-02-22 12:18:18 +03:00
|
|
|
mOwner->ScheduleUpdate(mType == MediaData::Type::AUDIO_DATA
|
2017-02-26 17:51:22 +03:00
|
|
|
? TrackType::kAudioTrack
|
|
|
|
: TrackType::kVideoTrack);
|
2017-02-24 12:27:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::DecoderData::Flush() {
|
|
|
|
if (mFlushing || mFlushed) {
|
|
|
|
// Flush still pending or already flushed, nothing more to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDecodeRequest.DisconnectIfExists();
|
|
|
|
mDrainRequest.DisconnectIfExists();
|
|
|
|
mDrainState = DrainState::None;
|
|
|
|
CancelWaitingForKey();
|
|
|
|
mOutput.Clear();
|
|
|
|
mNumSamplesInput = 0;
|
|
|
|
mNumSamplesOutput = 0;
|
|
|
|
mSizeOfQueue = 0;
|
|
|
|
if (mDecoder) {
|
2019-02-22 12:18:18 +03:00
|
|
|
TrackType type = mType == MediaData::Type::AUDIO_DATA
|
|
|
|
? TrackType::kAudioTrack
|
|
|
|
: TrackType::kVideoTrack;
|
2017-02-24 12:27:42 +03:00
|
|
|
mFlushing = true;
|
2017-02-27 04:56:36 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mShutdownPromise);
|
|
|
|
mShutdownPromise = new SharedShutdownPromiseHolder();
|
|
|
|
RefPtr<SharedShutdownPromiseHolder> p = mShutdownPromise;
|
|
|
|
RefPtr<MediaDataDecoder> d = mDecoder;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX2("MediaFormatReader::DecoderData", this, DDLogCategory::Log,
|
|
|
|
"flushing", DDNoValue{});
|
|
|
|
mDecoder->Flush()->Then(
|
|
|
|
mOwner->OwnerThread(), __func__,
|
|
|
|
[type, this, p, d]() {
|
|
|
|
DDLOGEX2("MediaFormatReader::DecoderData", this, DDLogCategory::Log,
|
|
|
|
"flushed", DDNoValue{});
|
|
|
|
if (!p->IsEmpty()) {
|
|
|
|
// Shutdown happened before flush completes.
|
|
|
|
// Let's continue to shut down the decoder. Note
|
|
|
|
// we don't access |this| because this decoder
|
|
|
|
// is no longer managed by MFR::DecoderData.
|
|
|
|
d->Shutdown()->ChainTo(p->Steal(), __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mFlushing = false;
|
|
|
|
mShutdownPromise = nullptr;
|
|
|
|
mOwner->ScheduleUpdate(type);
|
|
|
|
},
|
|
|
|
[type, this, p, d](const MediaResult& aError) {
|
|
|
|
DDLOGEX2("MediaFormatReader::DecoderData", this, DDLogCategory::Log,
|
|
|
|
"flush_error", aError);
|
|
|
|
if (!p->IsEmpty()) {
|
|
|
|
d->Shutdown()->ChainTo(p->Steal(), __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mFlushing = false;
|
|
|
|
mShutdownPromise = nullptr;
|
|
|
|
mOwner->NotifyError(type, aError);
|
|
|
|
});
|
2017-02-24 12:27:42 +03:00
|
|
|
}
|
|
|
|
mFlushed = true;
|
|
|
|
}
|
|
|
|
|
2016-10-26 12:37:19 +03:00
|
|
|
class MediaFormatReader::DecoderFactory {
|
|
|
|
using InitPromise = MediaDataDecoder::InitPromise;
|
2017-02-17 11:06:45 +03:00
|
|
|
using TokenPromise = GlobalAllocPolicy::Promise;
|
|
|
|
using Token = GlobalAllocPolicy::Token;
|
2016-10-26 12:37:19 +03:00
|
|
|
|
|
|
|
public:
|
2017-02-17 09:48:42 +03:00
|
|
|
explicit DecoderFactory(MediaFormatReader* aOwner)
|
2017-02-17 13:30:39 +03:00
|
|
|
: mAudio(aOwner->mAudio, TrackInfo::kAudioTrack, aOwner->OwnerThread()),
|
|
|
|
mVideo(aOwner->mVideo, TrackInfo::kVideoTrack, aOwner->OwnerThread()),
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
mOwner(WrapNotNull(aOwner)) {
|
|
|
|
DecoderDoctorLogger::LogConstruction("MediaFormatReader::DecoderFactory",
|
|
|
|
this);
|
|
|
|
DecoderDoctorLogger::LinkParentAndChild(
|
|
|
|
aOwner, "decoder factory", "MediaFormatReader::DecoderFactory", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~DecoderFactory() {
|
|
|
|
DecoderDoctorLogger::LogDestruction("MediaFormatReader::DecoderFactory",
|
|
|
|
this);
|
|
|
|
}
|
2017-02-17 09:48:42 +03:00
|
|
|
|
2016-10-26 12:37:19 +03:00
|
|
|
void CreateDecoder(TrackType aTrack);
|
2017-02-17 14:29:43 +03:00
|
|
|
|
|
|
|
// Shutdown any decoder pending initialization and reset mAudio/mVideo to its
|
|
|
|
// pristine state so CreateDecoder() is ready to be called again immediately.
|
|
|
|
void ShutdownDecoder(TrackType aTrack) {
|
2017-09-04 12:27:43 +03:00
|
|
|
MOZ_ASSERT(aTrack == TrackInfo::kAudioTrack ||
|
|
|
|
aTrack == TrackInfo::kVideoTrack);
|
2017-01-26 15:56:46 +03:00
|
|
|
auto& data = aTrack == TrackInfo::kAudioTrack ? mAudio : mVideo;
|
2017-02-17 13:30:39 +03:00
|
|
|
data.mPolicy->Cancel();
|
2017-01-26 15:56:46 +03:00
|
|
|
data.mTokenRequest.DisconnectIfExists();
|
|
|
|
data.mInitRequest.DisconnectIfExists();
|
2017-02-17 14:29:43 +03:00
|
|
|
if (data.mDecoder) {
|
|
|
|
mOwner->mShutdownPromisePool->ShutdownDecoder(data.mDecoder.forget());
|
2017-01-26 15:56:46 +03:00
|
|
|
}
|
2017-02-17 14:29:43 +03:00
|
|
|
data.mStage = Stage::None;
|
|
|
|
MOZ_ASSERT(!data.mToken);
|
2017-01-26 15:56:46 +03:00
|
|
|
}
|
2016-10-26 12:37:19 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum class Stage : int8_t { None, WaitForToken, CreateDecoder, WaitForInit };
|
|
|
|
|
|
|
|
struct Data {
|
2017-02-17 13:30:39 +03:00
|
|
|
Data(DecoderData& aOwnerData, TrackType aTrack, TaskQueue* aThread)
|
2017-02-17 09:48:42 +03:00
|
|
|
: mOwnerData(aOwnerData),
|
|
|
|
mTrack(aTrack),
|
2017-02-17 13:30:39 +03:00
|
|
|
mPolicy(new LocalAllocPolicy(aTrack, aThread)) {}
|
2017-02-17 09:48:42 +03:00
|
|
|
DecoderData& mOwnerData;
|
|
|
|
const TrackType mTrack;
|
2017-02-17 13:30:39 +03:00
|
|
|
RefPtr<LocalAllocPolicy> mPolicy;
|
2016-10-26 12:37:19 +03:00
|
|
|
Stage mStage = Stage::None;
|
2016-10-27 10:16:06 +03:00
|
|
|
RefPtr<Token> mToken;
|
2016-10-26 12:37:19 +03:00
|
|
|
RefPtr<MediaDataDecoder> mDecoder;
|
2017-01-26 15:56:46 +03:00
|
|
|
MozPromiseRequestHolder<TokenPromise> mTokenRequest;
|
|
|
|
MozPromiseRequestHolder<InitPromise> mInitRequest;
|
2016-10-26 12:37:19 +03:00
|
|
|
} mAudio, mVideo;
|
|
|
|
|
2017-02-17 10:14:53 +03:00
|
|
|
void RunStage(Data& aData);
|
2017-02-17 10:17:22 +03:00
|
|
|
MediaResult DoCreateDecoder(Data& aData);
|
2017-02-17 10:21:46 +03:00
|
|
|
void DoInitDecoder(Data& aData);
|
2016-10-26 12:37:19 +03:00
|
|
|
|
2017-02-17 09:48:42 +03:00
|
|
|
// guaranteed to be valid by the owner.
|
|
|
|
const NotNull<MediaFormatReader*> mOwner;
|
2016-10-26 12:37:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void MediaFormatReader::DecoderFactory::CreateDecoder(TrackType aTrack) {
|
2017-09-04 12:27:43 +03:00
|
|
|
MOZ_ASSERT(aTrack == TrackInfo::kAudioTrack ||
|
|
|
|
aTrack == TrackInfo::kVideoTrack);
|
2017-02-17 10:14:53 +03:00
|
|
|
RunStage(aTrack == TrackInfo::kAudioTrack ? mAudio : mVideo);
|
2016-10-26 12:37:19 +03:00
|
|
|
}
|
|
|
|
|
2017-02-17 10:14:53 +03:00
|
|
|
void MediaFormatReader::DecoderFactory::RunStage(Data& aData) {
|
|
|
|
switch (aData.mStage) {
|
2016-10-26 12:37:19 +03:00
|
|
|
case Stage::None: {
|
2017-02-17 10:14:53 +03:00
|
|
|
MOZ_ASSERT(!aData.mToken);
|
2017-02-17 13:30:39 +03:00
|
|
|
aData.mPolicy->Alloc()
|
2016-10-27 10:16:06 +03:00
|
|
|
->Then(mOwner->OwnerThread(), __func__,
|
2017-05-11 03:30:39 +03:00
|
|
|
[this, &aData](RefPtr<Token> aToken) {
|
2017-02-17 10:14:53 +03:00
|
|
|
aData.mTokenRequest.Complete();
|
2017-05-11 03:30:39 +03:00
|
|
|
aData.mToken = aToken.forget();
|
2017-02-17 10:14:53 +03:00
|
|
|
aData.mStage = Stage::CreateDecoder;
|
|
|
|
RunStage(aData);
|
2016-10-27 10:16:06 +03:00
|
|
|
},
|
2017-02-17 10:14:53 +03:00
|
|
|
[&aData]() {
|
|
|
|
aData.mTokenRequest.Complete();
|
|
|
|
aData.mStage = Stage::None;
|
|
|
|
})
|
|
|
|
->Track(aData.mTokenRequest);
|
|
|
|
aData.mStage = Stage::WaitForToken;
|
2016-10-27 10:16:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stage::WaitForToken: {
|
2017-02-17 10:14:53 +03:00
|
|
|
MOZ_ASSERT(!aData.mToken);
|
|
|
|
MOZ_ASSERT(aData.mTokenRequest.Exists());
|
2016-10-27 10:16:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stage::CreateDecoder: {
|
2017-02-17 10:14:53 +03:00
|
|
|
MOZ_ASSERT(aData.mToken);
|
|
|
|
MOZ_ASSERT(!aData.mDecoder);
|
|
|
|
MOZ_ASSERT(!aData.mInitRequest.Exists());
|
2016-10-26 12:37:19 +03:00
|
|
|
|
2017-02-17 10:17:22 +03:00
|
|
|
MediaResult rv = DoCreateDecoder(aData);
|
2016-10-26 12:37:19 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error constructing decoders");
|
2017-02-17 10:14:53 +03:00
|
|
|
aData.mToken = nullptr;
|
|
|
|
aData.mStage = Stage::None;
|
2017-09-21 14:25:05 +03:00
|
|
|
aData.mOwnerData.mDescription = rv.Description();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX2("MediaFormatReader::DecoderFactory", this, DDLogCategory::Log,
|
|
|
|
"create_decoder_error", rv);
|
2017-02-17 10:14:53 +03:00
|
|
|
mOwner->NotifyError(aData.mTrack, rv);
|
2016-10-26 12:37:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-17 18:52:47 +03:00
|
|
|
aData.mDecoder =
|
|
|
|
new AllocationWrapper(aData.mDecoder.forget(), aData.mToken.forget());
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LinkParentAndChild(
|
|
|
|
aData.mDecoder.get(), "decoder", "MediaFormatReader::DecoderFactory",
|
|
|
|
this);
|
|
|
|
|
2017-02-17 10:21:46 +03:00
|
|
|
DoInitDecoder(aData);
|
2017-02-17 10:14:53 +03:00
|
|
|
aData.mStage = Stage::WaitForInit;
|
2016-10-26 12:37:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stage::WaitForInit: {
|
2017-02-17 10:14:53 +03:00
|
|
|
MOZ_ASSERT(aData.mDecoder);
|
|
|
|
MOZ_ASSERT(aData.mInitRequest.Exists());
|
2016-10-26 12:37:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:17:22 +03:00
|
|
|
MediaResult MediaFormatReader::DecoderFactory::DoCreateDecoder(Data& aData) {
|
|
|
|
auto& ownerData = aData.mOwnerData;
|
2018-05-27 19:42:25 +03:00
|
|
|
auto& decoder = mOwner->GetDecoderData(aData.mTrack);
|
|
|
|
auto& platform =
|
|
|
|
decoder.IsEncrypted() ? mOwner->mEncryptedPlatform : mOwner->mPlatform;
|
2016-10-26 12:37:19 +03:00
|
|
|
|
2018-05-27 19:42:25 +03:00
|
|
|
if (!platform) {
|
|
|
|
platform = new PDMFactory();
|
|
|
|
if (decoder.IsEncrypted()) {
|
2016-10-26 12:37:19 +03:00
|
|
|
MOZ_ASSERT(mOwner->mCDMProxy);
|
2018-05-27 19:42:25 +03:00
|
|
|
platform->SetCDMProxy(mOwner->mCDMProxy);
|
2016-10-26 12:37:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 03:14:02 +03:00
|
|
|
// Media playback is not supported when recording or replaying. See bug
|
|
|
|
// 1304146.
|
|
|
|
if (recordreplay::IsRecordingOrReplaying()) {
|
|
|
|
return MediaResult(
|
|
|
|
NS_ERROR_DOM_MEDIA_FATAL_ERR,
|
|
|
|
nsPrintfCString("error creating %s decoder: "
|
|
|
|
"media playback is disabled while recording/replaying",
|
|
|
|
TrackTypeToStr(aData.mTrack)));
|
|
|
|
}
|
|
|
|
|
2017-09-21 14:25:05 +03:00
|
|
|
// result may not be updated by PDMFactory::CreateDecoder, as such it must be
|
|
|
|
// initialized to a fatal error by default.
|
|
|
|
MediaResult result =
|
|
|
|
MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
|
|
|
|
nsPrintfCString("error creating %s decoder",
|
|
|
|
TrackTypeToStr(aData.mTrack)));
|
|
|
|
|
2017-02-17 10:17:22 +03:00
|
|
|
switch (aData.mTrack) {
|
2016-10-26 12:37:19 +03:00
|
|
|
case TrackInfo::kAudioTrack: {
|
2018-05-27 19:42:25 +03:00
|
|
|
aData.mDecoder = platform->CreateDecoder(
|
2018-05-26 22:21:45 +03:00
|
|
|
{*ownerData.GetCurrentInfo()->GetAsAudioInfo(), ownerData.mTaskQueue,
|
2016-10-26 12:37:19 +03:00
|
|
|
mOwner->mCrashHelper,
|
2017-09-08 16:45:38 +03:00
|
|
|
CreateDecoderParams::UseNullDecoder(ownerData.mIsNullDecode),
|
2017-02-17 10:17:22 +03:00
|
|
|
&result, TrackInfo::kAudioTrack,
|
2017-01-27 13:48:00 +03:00
|
|
|
&mOwner->OnTrackWaitingForKeyProducer()});
|
2016-10-26 12:37:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TrackType::kVideoTrack: {
|
|
|
|
// Decoders use the layers backend to decide if they can use hardware
|
|
|
|
// decoding, so specify LAYERS_NONE if we want to forcibly disable it.
|
2018-10-04 12:43:24 +03:00
|
|
|
using Option = CreateDecoderParams::Option;
|
|
|
|
using OptionSet = CreateDecoderParams::OptionSet;
|
|
|
|
|
2018-05-27 19:42:25 +03:00
|
|
|
aData.mDecoder = platform->CreateDecoder(
|
2018-05-26 22:21:45 +03:00
|
|
|
{*ownerData.GetCurrentInfo()->GetAsVideoInfo(), ownerData.mTaskQueue,
|
2017-09-12 22:20:09 +03:00
|
|
|
mOwner->mKnowsCompositor, mOwner->GetImageContainer(),
|
|
|
|
mOwner->mCrashHelper,
|
|
|
|
CreateDecoderParams::UseNullDecoder(ownerData.mIsNullDecode),
|
|
|
|
&result, TrackType::kVideoTrack,
|
|
|
|
&mOwner->OnTrackWaitingForKeyProducer(),
|
2018-10-04 12:43:24 +03:00
|
|
|
CreateDecoderParams::VideoFrameRate(ownerData.mMeanRate.Mean()),
|
|
|
|
OptionSet(ownerData.mHardwareDecodingDisabled
|
|
|
|
? Option::HardwareDecoderNotAllowed
|
|
|
|
: Option::Default)});
|
2016-10-26 12:37:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:17:22 +03:00
|
|
|
if (aData.mDecoder) {
|
2017-01-26 15:56:46 +03:00
|
|
|
return NS_OK;
|
2016-10-26 12:37:19 +03:00
|
|
|
}
|
|
|
|
|
2017-09-21 14:25:05 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_FAILED(result), "PDM returned an invalid error code");
|
2017-09-13 10:38:06 +03:00
|
|
|
|
2016-10-26 12:37:19 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:21:46 +03:00
|
|
|
void MediaFormatReader::DecoderFactory::DoInitDecoder(Data& aData) {
|
|
|
|
auto& ownerData = aData.mOwnerData;
|
2016-10-26 12:37:19 +03:00
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX2("MediaFormatReader::DecoderFactory", this, DDLogCategory::Log,
|
|
|
|
"initialize_decoder", DDNoValue{});
|
2017-02-17 10:21:46 +03:00
|
|
|
aData.mDecoder->Init()
|
2017-01-26 15:56:46 +03:00
|
|
|
->Then(mOwner->OwnerThread(), __func__,
|
2017-02-17 10:21:46 +03:00
|
|
|
[this, &aData, &ownerData](TrackType aTrack) {
|
|
|
|
aData.mInitRequest.Complete();
|
|
|
|
aData.mStage = Stage::None;
|
2017-01-26 15:56:46 +03:00
|
|
|
MutexAutoLock lock(ownerData.mMutex);
|
2017-02-17 10:21:46 +03:00
|
|
|
ownerData.mDecoder = aData.mDecoder.forget();
|
2017-01-26 15:56:46 +03:00
|
|
|
ownerData.mDescription =
|
|
|
|
ownerData.mDecoder->GetDescriptionName();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX2("MediaFormatReader::DecoderFactory", this,
|
|
|
|
DDLogCategory::Log, "decoder_initialized", DDNoValue{});
|
|
|
|
DecoderDoctorLogger::LinkParentAndChild(
|
|
|
|
"MediaFormatReader::DecoderData", &ownerData, "decoder",
|
|
|
|
ownerData.mDecoder.get());
|
2017-01-26 15:56:46 +03:00
|
|
|
mOwner->SetVideoDecodeThreshold();
|
|
|
|
mOwner->ScheduleUpdate(aTrack);
|
|
|
|
},
|
2017-02-17 10:21:46 +03:00
|
|
|
[this, &aData, &ownerData](const MediaResult& aError) {
|
|
|
|
aData.mInitRequest.Complete();
|
2017-01-26 15:56:46 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!ownerData.mDecoder,
|
|
|
|
"Can't have a decoder already set");
|
2017-02-17 10:21:46 +03:00
|
|
|
aData.mStage = Stage::None;
|
2017-02-17 14:29:43 +03:00
|
|
|
mOwner->mShutdownPromisePool->ShutdownDecoder(
|
|
|
|
aData.mDecoder.forget());
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX2("MediaFormatReader::DecoderFactory", this,
|
|
|
|
DDLogCategory::Log, "initialize_decoder_error", aError);
|
2017-02-17 14:29:43 +03:00
|
|
|
mOwner->NotifyError(aData.mTrack, aError);
|
2017-01-26 15:56:46 +03:00
|
|
|
})
|
2017-02-17 10:21:46 +03:00
|
|
|
->Track(aData.mInitRequest);
|
2016-10-26 12:37:19 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
// DemuxerProxy ensures that the original main demuxer is only ever accessed
|
|
|
|
// via its own dedicated task queue.
|
|
|
|
// This ensure that the reader's taskqueue will never blocked while a demuxer
|
|
|
|
// is itself blocked attempting to access the MediaCache or the MediaResource.
|
|
|
|
class MediaFormatReader::DemuxerProxy {
|
|
|
|
using TrackType = TrackInfo::TrackType;
|
|
|
|
class Wrapper;
|
|
|
|
|
|
|
|
public:
|
2017-03-01 08:02:29 +03:00
|
|
|
explicit DemuxerProxy(MediaDataDemuxer* aDemuxer)
|
2018-06-07 15:50:10 +03:00
|
|
|
: mTaskQueue(
|
|
|
|
new TaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
|
|
|
|
"DemuxerProxy::mTaskQueue")),
|
2016-11-28 13:08:01 +03:00
|
|
|
mData(new Data(aDemuxer)) {
|
|
|
|
MOZ_COUNT_CTOR(DemuxerProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
~DemuxerProxy() { MOZ_COUNT_DTOR(DemuxerProxy); }
|
2017-01-26 20:17:15 +03:00
|
|
|
|
|
|
|
RefPtr<ShutdownPromise> Shutdown() {
|
2016-11-28 13:08:01 +03:00
|
|
|
RefPtr<Data> data = mData.forget();
|
2017-01-26 20:17:15 +03:00
|
|
|
return InvokeAsync(mTaskQueue, __func__, [data]() {
|
2016-11-28 13:08:01 +03:00
|
|
|
// We need to clear our reference to the demuxer now. So that in the event
|
|
|
|
// the init promise wasn't resolved, such as what can happen with the
|
|
|
|
// mediasource demuxer that is waiting on more data, it will force the
|
|
|
|
// init promise to be rejected.
|
2017-01-26 20:17:15 +03:00
|
|
|
data->mDemuxer = nullptr;
|
2017-04-13 10:42:52 +03:00
|
|
|
data->mAudioDemuxer = nullptr;
|
|
|
|
data->mVideoDemuxer = nullptr;
|
2017-01-26 20:17:15 +03:00
|
|
|
return ShutdownPromise::CreateAndResolve(true, __func__);
|
|
|
|
});
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MediaDataDemuxer::InitPromise> Init();
|
|
|
|
|
|
|
|
Wrapper* GetTrackDemuxer(TrackType aTrack, uint32_t aTrackNumber) {
|
|
|
|
MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
|
|
|
|
|
|
|
|
switch (aTrack) {
|
|
|
|
case TrackInfo::kAudioTrack:
|
|
|
|
return mData->mAudioDemuxer;
|
|
|
|
case TrackInfo::kVideoTrack:
|
|
|
|
return mData->mVideoDemuxer;
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetNumberTracks(TrackType aTrack) const {
|
|
|
|
MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
|
|
|
|
|
|
|
|
switch (aTrack) {
|
|
|
|
case TrackInfo::kAudioTrack:
|
|
|
|
return mData->mNumAudioTrack;
|
|
|
|
case TrackInfo::kVideoTrack:
|
|
|
|
return mData->mNumVideoTrack;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSeekable() const {
|
|
|
|
MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
|
|
|
|
|
|
|
|
return mData->mSeekable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSeekableOnlyInBufferedRanges() const {
|
|
|
|
MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
|
|
|
|
|
|
|
|
return mData->mSeekableOnlyInBufferedRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<EncryptionInfo> GetCrypto() const {
|
|
|
|
MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
|
|
|
|
|
|
|
|
if (!mData->mCrypto) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto crypto = MakeUnique<EncryptionInfo>();
|
|
|
|
*crypto = *mData->mCrypto;
|
|
|
|
return crypto;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<NotifyDataArrivedPromise> NotifyDataArrived();
|
|
|
|
|
|
|
|
bool ShouldComputeStartTime() const {
|
|
|
|
MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
|
|
|
|
|
|
|
|
return mData->mShouldComputeStartTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-07 15:50:10 +03:00
|
|
|
const RefPtr<TaskQueue> mTaskQueue;
|
2016-11-28 13:08:01 +03:00
|
|
|
struct Data {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Data)
|
|
|
|
|
|
|
|
explicit Data(MediaDataDemuxer* aDemuxer)
|
|
|
|
: mInitDone(false), mDemuxer(aDemuxer) {}
|
|
|
|
|
|
|
|
Atomic<bool> mInitDone;
|
|
|
|
// Only ever accessed over mTaskQueue once.
|
|
|
|
RefPtr<MediaDataDemuxer> mDemuxer;
|
|
|
|
// Only accessed once InitPromise has been resolved and immutable after.
|
|
|
|
// So we can safely access them without the use of the mutex.
|
|
|
|
uint32_t mNumAudioTrack = 0;
|
|
|
|
RefPtr<Wrapper> mAudioDemuxer;
|
|
|
|
uint32_t mNumVideoTrack = 0;
|
|
|
|
RefPtr<Wrapper> mVideoDemuxer;
|
|
|
|
bool mSeekable = false;
|
|
|
|
bool mSeekableOnlyInBufferedRange = false;
|
|
|
|
bool mShouldComputeStartTime = true;
|
|
|
|
UniquePtr<EncryptionInfo> mCrypto;
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
private:
|
|
|
|
~Data() {}
|
|
|
|
};
|
|
|
|
RefPtr<Data> mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MediaFormatReader::DemuxerProxy::Wrapper : public MediaTrackDemuxer {
|
|
|
|
public:
|
2018-06-07 15:50:10 +03:00
|
|
|
Wrapper(MediaTrackDemuxer* aTrackDemuxer, TaskQueue* aTaskQueue)
|
2016-11-28 13:08:01 +03:00
|
|
|
: mMutex("TrackDemuxer Mutex"),
|
|
|
|
mTaskQueue(aTaskQueue),
|
|
|
|
mGetSamplesMayBlock(aTrackDemuxer->GetSamplesMayBlock()),
|
|
|
|
mInfo(aTrackDemuxer->GetInfo()),
|
|
|
|
mTrackDemuxer(aTrackDemuxer) {
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LogConstructionAndBase(
|
|
|
|
"MediaFormatReader::DemuxerProxy::Wrapper", this,
|
|
|
|
static_cast<const MediaTrackDemuxer*>(this));
|
|
|
|
DecoderDoctorLogger::LinkParentAndChild(
|
|
|
|
"MediaFormatReader::DemuxerProxy::Wrapper", this, "track demuxer",
|
|
|
|
aTrackDemuxer);
|
2017-01-27 15:20:37 +03:00
|
|
|
}
|
2016-11-28 13:08:01 +03:00
|
|
|
|
|
|
|
UniquePtr<TrackInfo> GetInfo() const override {
|
|
|
|
if (!mInfo) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mInfo->Clone();
|
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
RefPtr<SeekPromise> Seek(const TimeUnit& aTime) override {
|
2016-11-28 13:08:01 +03:00
|
|
|
RefPtr<Wrapper> self = this;
|
|
|
|
return InvokeAsync(
|
|
|
|
mTaskQueue, __func__,
|
|
|
|
[self, aTime]() { return self->mTrackDemuxer->Seek(aTime); })
|
|
|
|
->Then(mTaskQueue, __func__,
|
2017-05-09 18:31:32 +03:00
|
|
|
[self](const TimeUnit& aTime) {
|
|
|
|
self->UpdateRandomAccessPoint();
|
|
|
|
return SeekPromise::CreateAndResolve(aTime, __func__);
|
|
|
|
},
|
|
|
|
[self](const MediaResult& aError) {
|
|
|
|
self->UpdateRandomAccessPoint();
|
|
|
|
return SeekPromise::CreateAndReject(aError, __func__);
|
|
|
|
});
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
RefPtr<SamplesPromise> GetSamples(int32_t aNumSamples) override {
|
|
|
|
RefPtr<Wrapper> self = this;
|
|
|
|
return InvokeAsync(mTaskQueue, __func__,
|
|
|
|
[self, aNumSamples]() {
|
|
|
|
return self->mTrackDemuxer->GetSamples(aNumSamples);
|
|
|
|
})
|
|
|
|
->Then(mTaskQueue, __func__,
|
2017-05-09 18:31:32 +03:00
|
|
|
[self](RefPtr<SamplesHolder> aSamples) {
|
|
|
|
self->UpdateRandomAccessPoint();
|
|
|
|
return SamplesPromise::CreateAndResolve(aSamples.forget(),
|
|
|
|
__func__);
|
|
|
|
},
|
|
|
|
[self](const MediaResult& aError) {
|
|
|
|
self->UpdateRandomAccessPoint();
|
|
|
|
return SamplesPromise::CreateAndReject(aError, __func__);
|
|
|
|
});
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GetSamplesMayBlock() const override { return mGetSamplesMayBlock; }
|
|
|
|
|
|
|
|
void Reset() override {
|
|
|
|
RefPtr<Wrapper> self = this;
|
2017-11-15 09:58:03 +03:00
|
|
|
nsresult rv = mTaskQueue->Dispatch(NS_NewRunnableFunction(
|
|
|
|
"MediaFormatReader::DemuxerProxy::Wrapper::Reset",
|
|
|
|
[self]() { self->mTrackDemuxer->Reset(); }));
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
2017-12-21 07:12:42 +03:00
|
|
|
Unused << rv;
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GetNextRandomAccessPoint(TimeUnit* aTime) override {
|
2017-04-13 10:16:08 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2016-11-28 13:08:01 +03:00
|
|
|
if (NS_SUCCEEDED(mNextRandomAccessPointResult)) {
|
|
|
|
*aTime = mNextRandomAccessPoint;
|
|
|
|
}
|
|
|
|
return mNextRandomAccessPointResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<SkipAccessPointPromise> SkipToNextRandomAccessPoint(
|
2017-04-17 11:35:04 +03:00
|
|
|
const TimeUnit& aTimeThreshold) override {
|
2016-11-28 13:08:01 +03:00
|
|
|
RefPtr<Wrapper> self = this;
|
|
|
|
return InvokeAsync(
|
|
|
|
mTaskQueue, __func__,
|
|
|
|
[self, aTimeThreshold]() {
|
|
|
|
return self->mTrackDemuxer->SkipToNextRandomAccessPoint(
|
|
|
|
aTimeThreshold);
|
|
|
|
})
|
|
|
|
->Then(
|
|
|
|
mTaskQueue, __func__,
|
2017-05-09 18:31:32 +03:00
|
|
|
[self](uint32_t aVal) {
|
|
|
|
self->UpdateRandomAccessPoint();
|
|
|
|
return SkipAccessPointPromise::CreateAndResolve(aVal, __func__);
|
|
|
|
},
|
|
|
|
[self](const SkipFailureHolder& aError) {
|
|
|
|
self->UpdateRandomAccessPoint();
|
|
|
|
return SkipAccessPointPromise::CreateAndReject(aError, __func__);
|
|
|
|
});
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
TimeIntervals GetBuffered() override {
|
2017-04-13 10:16:08 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2016-11-28 13:08:01 +03:00
|
|
|
return mBuffered;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakCycles() override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Mutex mMutex;
|
2018-06-07 15:50:10 +03:00
|
|
|
const RefPtr<TaskQueue> mTaskQueue;
|
2016-11-28 13:08:01 +03:00
|
|
|
const bool mGetSamplesMayBlock;
|
|
|
|
const UniquePtr<TrackInfo> mInfo;
|
|
|
|
// mTrackDemuxer is only ever accessed on demuxer's task queue.
|
|
|
|
RefPtr<MediaTrackDemuxer> mTrackDemuxer;
|
|
|
|
// All following members are protected by mMutex
|
|
|
|
nsresult mNextRandomAccessPointResult = NS_OK;
|
|
|
|
TimeUnit mNextRandomAccessPoint;
|
|
|
|
TimeIntervals mBuffered;
|
|
|
|
friend class DemuxerProxy;
|
|
|
|
|
|
|
|
~Wrapper() {
|
|
|
|
RefPtr<MediaTrackDemuxer> trackDemuxer = mTrackDemuxer.forget();
|
2017-11-15 09:58:03 +03:00
|
|
|
nsresult rv = mTaskQueue->Dispatch(NS_NewRunnableFunction(
|
|
|
|
"MediaFormatReader::DemuxerProxy::Wrapper::~Wrapper",
|
|
|
|
[trackDemuxer]() { trackDemuxer->BreakCycles(); }));
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
2017-12-21 07:12:42 +03:00
|
|
|
Unused << rv;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LogDestruction(
|
|
|
|
"MediaFormatReader::DemuxerProxy::Wrapper", this);
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateRandomAccessPoint() {
|
|
|
|
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
|
|
|
if (!mTrackDemuxer) {
|
|
|
|
// Detached.
|
|
|
|
return;
|
|
|
|
}
|
2017-04-13 10:16:08 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2016-11-28 13:08:01 +03:00
|
|
|
mNextRandomAccessPointResult =
|
|
|
|
mTrackDemuxer->GetNextRandomAccessPoint(&mNextRandomAccessPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateBuffered() {
|
|
|
|
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
|
|
|
if (!mTrackDemuxer) {
|
|
|
|
// Detached.
|
|
|
|
return;
|
|
|
|
}
|
2017-04-13 10:16:08 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2016-11-28 13:08:01 +03:00
|
|
|
mBuffered = mTrackDemuxer->GetBuffered();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RefPtr<MediaDataDemuxer::InitPromise> MediaFormatReader::DemuxerProxy::Init() {
|
2017-05-09 18:31:32 +03:00
|
|
|
using InitPromise = MediaDataDemuxer::InitPromise;
|
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
RefPtr<Data> data = mData;
|
2018-06-07 15:50:10 +03:00
|
|
|
RefPtr<TaskQueue> taskQueue = mTaskQueue;
|
2016-11-28 13:08:01 +03:00
|
|
|
return InvokeAsync(mTaskQueue, __func__,
|
|
|
|
[data, taskQueue]() {
|
|
|
|
if (!data->mDemuxer) {
|
2017-05-09 18:31:32 +03:00
|
|
|
return InitPromise::CreateAndReject(
|
2016-11-28 13:08:01 +03:00
|
|
|
NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
|
|
|
}
|
|
|
|
return data->mDemuxer->Init();
|
|
|
|
})
|
|
|
|
->Then(taskQueue, __func__,
|
|
|
|
[data, taskQueue]() {
|
|
|
|
if (!data->mDemuxer) { // Was shutdown.
|
2017-05-09 18:31:32 +03:00
|
|
|
return InitPromise::CreateAndReject(
|
|
|
|
NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
data->mNumAudioTrack =
|
|
|
|
data->mDemuxer->GetNumberTracks(TrackInfo::kAudioTrack);
|
|
|
|
if (data->mNumAudioTrack) {
|
|
|
|
RefPtr<MediaTrackDemuxer> d =
|
|
|
|
data->mDemuxer->GetTrackDemuxer(TrackInfo::kAudioTrack, 0);
|
|
|
|
if (d) {
|
|
|
|
RefPtr<Wrapper> wrapper =
|
|
|
|
new DemuxerProxy::Wrapper(d, taskQueue);
|
|
|
|
wrapper->UpdateBuffered();
|
|
|
|
data->mAudioDemuxer = wrapper;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LinkParentAndChild(
|
|
|
|
data->mDemuxer.get(), "decoder factory wrapper",
|
|
|
|
"MediaFormatReader::DecoderFactory::Wrapper",
|
|
|
|
wrapper.get());
|
2018-11-19 16:25:37 +03:00
|
|
|
}
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
data->mNumVideoTrack =
|
|
|
|
data->mDemuxer->GetNumberTracks(TrackInfo::kVideoTrack);
|
|
|
|
if (data->mNumVideoTrack) {
|
|
|
|
RefPtr<MediaTrackDemuxer> d =
|
|
|
|
data->mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0);
|
|
|
|
if (d) {
|
|
|
|
RefPtr<Wrapper> wrapper =
|
|
|
|
new DemuxerProxy::Wrapper(d, taskQueue);
|
|
|
|
wrapper->UpdateBuffered();
|
|
|
|
data->mVideoDemuxer = wrapper;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DecoderDoctorLogger::LinkParentAndChild(
|
|
|
|
data->mDemuxer.get(), "decoder factory wrapper",
|
|
|
|
"MediaFormatReader::DecoderFactory::Wrapper",
|
|
|
|
wrapper.get());
|
2018-11-19 16:25:37 +03:00
|
|
|
}
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
data->mCrypto = data->mDemuxer->GetCrypto();
|
|
|
|
data->mSeekable = data->mDemuxer->IsSeekable();
|
|
|
|
data->mSeekableOnlyInBufferedRange =
|
|
|
|
data->mDemuxer->IsSeekableOnlyInBufferedRanges();
|
|
|
|
data->mShouldComputeStartTime =
|
|
|
|
data->mDemuxer->ShouldComputeStartTime();
|
|
|
|
data->mInitDone = true;
|
2017-05-09 18:31:32 +03:00
|
|
|
return InitPromise::CreateAndResolve(NS_OK, __func__);
|
2016-11-28 13:08:01 +03:00
|
|
|
},
|
2017-05-09 18:31:32 +03:00
|
|
|
[](const MediaResult& aError) {
|
|
|
|
return InitPromise::CreateAndReject(aError, __func__);
|
|
|
|
});
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MediaFormatReader::NotifyDataArrivedPromise>
|
|
|
|
MediaFormatReader::DemuxerProxy::NotifyDataArrived() {
|
|
|
|
RefPtr<Data> data = mData;
|
|
|
|
return InvokeAsync(mTaskQueue, __func__, [data]() {
|
|
|
|
if (!data->mDemuxer) {
|
|
|
|
// Was shutdown.
|
|
|
|
return NotifyDataArrivedPromise::CreateAndReject(
|
|
|
|
NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
|
|
|
}
|
|
|
|
data->mDemuxer->NotifyDataArrived();
|
|
|
|
if (data->mAudioDemuxer) {
|
|
|
|
data->mAudioDemuxer->UpdateBuffered();
|
|
|
|
}
|
|
|
|
if (data->mVideoDemuxer) {
|
|
|
|
data->mVideoDemuxer->UpdateBuffered();
|
|
|
|
}
|
|
|
|
return NotifyDataArrivedPromise::CreateAndResolve(true, __func__);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-19 17:18:37 +03:00
|
|
|
MediaFormatReader::MediaFormatReader(MediaFormatReaderInit& aInit,
|
2017-07-06 11:59:22 +03:00
|
|
|
MediaDataDemuxer* aDemuxer)
|
2017-07-19 17:18:37 +03:00
|
|
|
: mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
|
2017-07-19 12:34:05 +03:00
|
|
|
"MediaFormatReader::mTaskQueue",
|
|
|
|
/* aSupportsTailDispatch = */ true)),
|
2019-02-22 12:18:18 +03:00
|
|
|
mAudio(this, MediaData::Type::AUDIO_DATA,
|
2018-03-20 01:48:56 +03:00
|
|
|
StaticPrefs::MediaAudioMaxDecodeError()),
|
2019-02-22 12:18:18 +03:00
|
|
|
mVideo(this, MediaData::Type::VIDEO_DATA,
|
2018-03-20 01:48:56 +03:00
|
|
|
StaticPrefs::MediaVideoMaxDecodeError()),
|
2017-03-01 08:02:29 +03:00
|
|
|
mDemuxer(new DemuxerProxy(aDemuxer)),
|
2015-10-07 04:00:52 +03:00
|
|
|
mDemuxerInitDone(false),
|
2017-03-15 10:20:45 +03:00
|
|
|
mPendingNotifyDataArrived(false),
|
2015-05-18 08:40:32 +03:00
|
|
|
mLastReportedNumDecodedFrames(0),
|
2016-07-26 02:36:55 +03:00
|
|
|
mPreviousDecodedKeyframeTime_us(sNoPreviousDecodedKeyframe),
|
2017-07-12 10:37:02 +03:00
|
|
|
mKnowsCompositor(aInit.mKnowsCompositor),
|
2015-05-18 08:40:32 +03:00
|
|
|
mInitDone(false),
|
2015-06-12 02:26:58 +03:00
|
|
|
mTrackDemuxersMayBlock(false),
|
2016-05-05 08:01:51 +03:00
|
|
|
mSeekScheduled(false),
|
2017-07-06 11:59:22 +03:00
|
|
|
mVideoFrameContainer(aInit.mVideoFrameContainer),
|
2017-07-13 05:19:36 +03:00
|
|
|
mCrashHelper(aInit.mCrashHelper),
|
2016-10-26 12:37:19 +03:00
|
|
|
mDecoderFactory(new DecoderFactory(this)),
|
2017-02-17 14:29:43 +03:00
|
|
|
mShutdownPromisePool(new ShutdownPromisePool()),
|
2017-07-19 12:34:05 +03:00
|
|
|
mBuffered(mTaskQueue, TimeIntervals(),
|
|
|
|
"MediaFormatReader::mBuffered (Canonical)"),
|
2017-07-07 06:05:03 +03:00
|
|
|
mFrameStats(aInit.mFrameStats),
|
2017-08-31 12:31:51 +03:00
|
|
|
mMediaDecoderOwnerID(aInit.mMediaDecoderOwnerID) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(aDemuxer);
|
|
|
|
MOZ_COUNT_CTOR(MediaFormatReader);
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLINKCHILD("audio decoder data", "MediaFormatReader::DecoderDataWithPromise",
|
|
|
|
&mAudio);
|
|
|
|
DDLINKCHILD("video decoder data", "MediaFormatReader::DecoderDataWithPromise",
|
|
|
|
&mVideo);
|
|
|
|
DDLINKCHILD("demuxer", aDemuxer);
|
2017-01-27 13:48:00 +03:00
|
|
|
mOnTrackWaitingForKeyListener = OnTrackWaitingForKey().Connect(
|
|
|
|
mTaskQueue, this, &MediaFormatReader::NotifyWaitingForKey);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaFormatReader::~MediaFormatReader() {
|
|
|
|
MOZ_COUNT_DTOR(MediaFormatReader);
|
2017-07-19 12:34:05 +03:00
|
|
|
MOZ_ASSERT(mShutdown);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ShutdownPromise> MediaFormatReader::Shutdown() {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2017-01-26 15:56:46 +03:00
|
|
|
LOG("");
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
mDemuxerInitRequest.DisconnectIfExists();
|
2016-11-28 13:08:01 +03:00
|
|
|
mNotifyDataArrivedPromise.DisconnectIfExists();
|
2016-09-10 12:56:50 +03:00
|
|
|
mMetadataPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2016-09-10 09:48:53 +03:00
|
|
|
mSeekPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
mSkipRequest.DisconnectIfExists();
|
2017-11-03 15:12:39 +03:00
|
|
|
mSetCDMPromise.RejectIfExists(
|
|
|
|
MediaResult(NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
"MediaFormatReader is shutting down"),
|
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-01-26 15:56:46 +03:00
|
|
|
if (mAudio.HasPromise()) {
|
|
|
|
mAudio.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
|
|
|
}
|
|
|
|
if (mVideo.HasPromise()) {
|
|
|
|
mVideo.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2017-01-26 15:56:46 +03:00
|
|
|
|
|
|
|
if (HasAudio()) {
|
2015-05-25 08:09:16 +03:00
|
|
|
mAudio.ResetDemuxer();
|
2015-05-18 08:40:32 +03:00
|
|
|
mAudio.mTrackDemuxer->BreakCycles();
|
2018-10-03 11:23:08 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mAudio.mMutex);
|
|
|
|
mAudio.mTrackDemuxer = nullptr;
|
|
|
|
}
|
2017-01-26 15:56:46 +03:00
|
|
|
mAudio.ResetState();
|
2017-02-25 02:59:53 +03:00
|
|
|
ShutdownDecoder(TrackInfo::kAudioTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 15:56:46 +03:00
|
|
|
if (HasVideo()) {
|
2015-05-25 08:09:16 +03:00
|
|
|
mVideo.ResetDemuxer();
|
2015-05-18 08:40:32 +03:00
|
|
|
mVideo.mTrackDemuxer->BreakCycles();
|
2018-10-03 11:23:08 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mVideo.mMutex);
|
|
|
|
mVideo.mTrackDemuxer = nullptr;
|
|
|
|
}
|
2017-01-26 15:56:46 +03:00
|
|
|
mVideo.ResetState();
|
2017-02-25 02:59:53 +03:00
|
|
|
ShutdownDecoder(TrackInfo::kVideoTrack);
|
2017-01-26 15:56:46 +03:00
|
|
|
}
|
|
|
|
|
2017-02-17 14:29:43 +03:00
|
|
|
mShutdownPromisePool->Track(mDemuxer->Shutdown());
|
2017-01-26 15:56:46 +03:00
|
|
|
mDemuxer = nullptr;
|
|
|
|
|
2017-01-27 13:48:00 +03:00
|
|
|
mOnTrackWaitingForKeyListener.Disconnect();
|
2017-01-26 15:56:46 +03:00
|
|
|
|
2017-02-17 14:34:03 +03:00
|
|
|
mShutdown = true;
|
|
|
|
return mShutdownPromisePool->Shutdown()->Then(
|
2017-01-26 15:56:46 +03:00
|
|
|
OwnerThread(), __func__, this, &MediaFormatReader::TearDownDecoders,
|
|
|
|
&MediaFormatReader::TearDownDecoders);
|
|
|
|
}
|
|
|
|
|
2017-02-25 02:59:53 +03:00
|
|
|
void MediaFormatReader::ShutdownDecoder(TrackType aTrack) {
|
2017-01-26 15:56:46 +03:00
|
|
|
LOGV("%s", TrackTypeToStr(aTrack));
|
|
|
|
|
2017-02-26 17:51:22 +03:00
|
|
|
// Shut down the pending decoder if any.
|
|
|
|
mDecoderFactory->ShutdownDecoder(aTrack);
|
2017-02-25 02:59:53 +03:00
|
|
|
|
2017-02-26 17:51:22 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
// Flush the decoder if necessary.
|
|
|
|
decoder.Flush();
|
|
|
|
// Shut down the decoder if any.
|
2017-01-26 15:56:46 +03:00
|
|
|
decoder.ShutdownDecoder();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ShutdownPromise> MediaFormatReader::TearDownDecoders() {
|
|
|
|
if (mAudio.mTaskQueue) {
|
|
|
|
mAudio.mTaskQueue->BeginShutdown();
|
|
|
|
mAudio.mTaskQueue->AwaitShutdownAndIdle();
|
|
|
|
mAudio.mTaskQueue = nullptr;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
if (mVideo.mTaskQueue) {
|
|
|
|
mVideo.mTaskQueue->BeginShutdown();
|
|
|
|
mVideo.mTaskQueue->AwaitShutdownAndIdle();
|
|
|
|
mVideo.mTaskQueue = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-26 15:56:46 +03:00
|
|
|
mDecoderFactory = nullptr;
|
2015-05-18 08:40:32 +03:00
|
|
|
mPlatform = nullptr;
|
2018-05-27 19:42:25 +03:00
|
|
|
mEncryptedPlatform = nullptr;
|
2016-05-22 16:39:55 +03:00
|
|
|
mVideoFrameContainer = nullptr;
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
ReleaseResources();
|
|
|
|
mBuffered.DisconnectAll();
|
|
|
|
return mTaskQueue->BeginShutdown();
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
nsresult MediaFormatReader::Init() {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
|
|
|
|
2017-04-25 09:57:55 +03:00
|
|
|
mAudio.mTaskQueue =
|
|
|
|
new TaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
|
|
|
|
"MFR::mAudio::mTaskQueue");
|
|
|
|
|
|
|
|
mVideo.mTaskQueue =
|
|
|
|
new TaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
|
|
|
|
"MFR::mVideo::mTaskQueue");
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-03 15:12:39 +03:00
|
|
|
bool MediaFormatReader::ResolveSetCDMPromiseIfDone(TrackType aTrack) {
|
|
|
|
// When a CDM proxy is set, MFR would shutdown the existing MediaDataDecoder
|
|
|
|
// and would create new one for specific track in the next Update.
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2017-11-03 15:14:49 +03:00
|
|
|
if (mSetCDMPromise.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-03 15:12:39 +03:00
|
|
|
|
2017-11-03 15:14:49 +03:00
|
|
|
MOZ_ASSERT(mCDMProxy);
|
|
|
|
if (mSetCDMForTracks.contains(aTrack)) {
|
2017-11-03 15:12:39 +03:00
|
|
|
mSetCDMForTracks -= aTrack;
|
|
|
|
}
|
2017-11-03 15:14:49 +03:00
|
|
|
|
|
|
|
if (mSetCDMForTracks.isEmpty()) {
|
|
|
|
LOGV("%s : Done ", __func__);
|
|
|
|
mSetCDMPromise.Resolve(/* aIgnored = */ true, __func__);
|
2018-08-09 19:24:33 +03:00
|
|
|
if (HasAudio()) {
|
|
|
|
ScheduleUpdate(TrackInfo::kAudioTrack);
|
|
|
|
}
|
|
|
|
if (HasVideo()) {
|
|
|
|
ScheduleUpdate(TrackInfo::kVideoTrack);
|
|
|
|
}
|
2017-11-03 15:14:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
LOGV("%s : %s track is ready.", __func__, TrackTypeToStr(aTrack));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::PrepareToSetCDMForTrack(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
LOGV("%s : %s", __func__, TrackTypeToStr(aTrack));
|
|
|
|
|
|
|
|
mSetCDMForTracks += aTrack;
|
|
|
|
if (mCDMProxy) {
|
|
|
|
// An old cdm proxy exists, so detaching old cdm proxy by shutting down
|
|
|
|
// MediaDataDecoder.
|
|
|
|
ShutdownDecoder(aTrack);
|
|
|
|
}
|
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFormatReader::IsDecoderWaitingForCDM(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2018-05-28 16:10:19 +03:00
|
|
|
return GetDecoderData(aTrack).IsEncrypted() &&
|
|
|
|
mSetCDMForTracks.contains(aTrack) && !mCDMProxy;
|
2017-11-03 15:12:39 +03:00
|
|
|
}
|
|
|
|
|
2015-09-27 13:40:03 +03:00
|
|
|
RefPtr<SetCDMPromise> MediaFormatReader::SetCDMProxy(CDMProxy* aProxy) {
|
2017-11-03 15:12:39 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
LOGV("SetCDMProxy (%p)", aProxy);
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
return SetCDMPromise::CreateAndReject(
|
|
|
|
MediaResult(NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
"MediaFormatReader is shutting down"),
|
|
|
|
__func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
mSetCDMPromise.RejectIfExists(
|
|
|
|
MediaResult(NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
|
|
"Another new CDM proxy is being set."),
|
|
|
|
__func__);
|
|
|
|
|
|
|
|
// Shutdown all decoders as switching CDM proxy indicates that it's
|
|
|
|
// inappropriate for the existing decoders to continue decoding via the old
|
|
|
|
// CDM proxy.
|
2017-11-03 15:14:49 +03:00
|
|
|
if (HasAudio()) {
|
|
|
|
PrepareToSetCDMForTrack(TrackInfo::kAudioTrack);
|
|
|
|
}
|
|
|
|
if (HasVideo()) {
|
|
|
|
PrepareToSetCDMForTrack(TrackInfo::kVideoTrack);
|
2017-11-03 15:12:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mCDMProxy = aProxy;
|
|
|
|
|
2018-05-28 15:46:35 +03:00
|
|
|
// Release old PDMFactory which contains an EMEDecoderModule.
|
|
|
|
mEncryptedPlatform = nullptr;
|
2017-11-03 15:14:49 +03:00
|
|
|
|
|
|
|
if (!mInitDone || mSetCDMForTracks.isEmpty() || !mCDMProxy) {
|
|
|
|
// 1) MFR is not initialized yet or
|
|
|
|
// 2) Demuxer is initialized without active audio and video or
|
|
|
|
// 3) A null cdm proxy is set
|
|
|
|
// the promise can be resolved directly.
|
|
|
|
mSetCDMForTracks.clear();
|
2017-11-03 15:12:39 +03:00
|
|
|
return SetCDMPromise::CreateAndResolve(/* aIgnored = */ true, __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<SetCDMPromise> p = mSetCDMPromise.Ensure(__func__);
|
|
|
|
return p;
|
2015-09-27 13:40:03 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-01-26 15:56:46 +03:00
|
|
|
bool MediaFormatReader::IsWaitingOnCDMResource() {
|
2015-09-27 13:59:52 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2015-09-27 13:40:03 +03:00
|
|
|
return IsEncrypted() && !mCDMProxy;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
RefPtr<MediaFormatReader::MetadataPromise>
|
2015-10-21 05:59:56 +03:00
|
|
|
MediaFormatReader::AsyncReadMetadata() {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2015-10-21 04:28:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mMetadataPromise.IsEmpty());
|
2015-08-11 06:50:07 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
if (mInitDone) {
|
|
|
|
// We are returning from dormant.
|
2017-05-18 05:20:44 +03:00
|
|
|
MetadataHolder metadata;
|
|
|
|
metadata.mInfo = MakeUnique<MediaInfo>(mInfo);
|
2018-05-30 22:15:35 +03:00
|
|
|
return MetadataPromise::CreateAndResolve(std::move(metadata), __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2015-10-21 04:28:04 +03:00
|
|
|
RefPtr<MetadataPromise> p = mMetadataPromise.Ensure(__func__);
|
|
|
|
|
2017-01-11 11:33:29 +03:00
|
|
|
mDemuxer->Init()
|
|
|
|
->Then(OwnerThread(), __func__, this,
|
|
|
|
&MediaFormatReader::OnDemuxerInitDone,
|
|
|
|
&MediaFormatReader::OnDemuxerInitFailed)
|
|
|
|
->Track(mDemuxerInitRequest);
|
2015-05-18 08:40:32 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-03-06 07:22:17 +03:00
|
|
|
void MediaFormatReader::OnDemuxerInitDone(const MediaResult& aResult) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
mDemuxerInitRequest.Complete();
|
|
|
|
|
2018-03-20 01:48:56 +03:00
|
|
|
if (NS_FAILED(aResult) && StaticPrefs::MediaPlaybackWarningsAsErrors()) {
|
2017-03-03 08:10:48 +03:00
|
|
|
mMetadataPromise.Reject(aResult, __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-07 04:00:52 +03:00
|
|
|
mDemuxerInitDone = true;
|
|
|
|
|
2016-01-08 03:22:53 +03:00
|
|
|
UniquePtr<MetadataTags> tags(MakeUnique<MetadataTags>());
|
|
|
|
|
2016-05-12 05:00:21 +03:00
|
|
|
RefPtr<PDMFactory> platform;
|
|
|
|
if (!IsWaitingOnCDMResource()) {
|
|
|
|
platform = new PDMFactory();
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
// To decode, we need valid video and a place to put it.
|
2017-01-27 15:20:37 +03:00
|
|
|
bool videoActive = !!mDemuxer->GetNumberTracks(TrackInfo::kVideoTrack) &&
|
|
|
|
GetImageContainer();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
if (videoActive) {
|
|
|
|
// We currently only handle the first video track.
|
2018-10-03 11:23:08 +03:00
|
|
|
MutexAutoLock lock(mVideo.mMutex);
|
2015-05-18 08:40:32 +03:00
|
|
|
mVideo.mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0);
|
2015-08-26 04:25:49 +03:00
|
|
|
if (!mVideo.mTrackDemuxer) {
|
2016-09-10 12:56:50 +03:00
|
|
|
mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
|
2015-08-26 04:25:49 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-12 05:00:21 +03:00
|
|
|
|
2016-05-12 04:42:20 +03:00
|
|
|
UniquePtr<TrackInfo> videoInfo = mVideo.mTrackDemuxer->GetInfo();
|
|
|
|
videoActive = videoInfo && videoInfo->IsValid();
|
|
|
|
if (videoActive) {
|
2017-09-04 12:27:43 +03:00
|
|
|
if (platform &&
|
|
|
|
!platform->SupportsMimeType(videoInfo->mMimeType, nullptr)) {
|
2016-05-12 05:00:21 +03:00
|
|
|
// We have no decoder for this track. Error.
|
2016-09-10 12:56:50 +03:00
|
|
|
mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
|
2016-05-12 05:00:21 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-10-03 11:23:08 +03:00
|
|
|
mInfo.mVideo = *videoInfo->GetAsVideoInfo();
|
|
|
|
mVideo.mWorkingInfo = MakeUnique<VideoInfo>(mInfo.mVideo);
|
2016-05-12 04:42:20 +03:00
|
|
|
for (const MetadataTag& tag : videoInfo->mTags) {
|
|
|
|
tags->Put(tag.mKey, tag.mValue);
|
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
mVideo.mOriginalInfo = std::move(videoInfo);
|
2016-05-12 04:42:20 +03:00
|
|
|
mTrackDemuxersMayBlock |= mVideo.mTrackDemuxer->GetSamplesMayBlock();
|
|
|
|
} else {
|
|
|
|
mVideo.mTrackDemuxer->BreakCycles();
|
|
|
|
mVideo.mTrackDemuxer = nullptr;
|
2016-01-08 03:22:53 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool audioActive = !!mDemuxer->GetNumberTracks(TrackInfo::kAudioTrack);
|
|
|
|
if (audioActive) {
|
2018-10-03 11:23:08 +03:00
|
|
|
MutexAutoLock lock(mAudio.mMutex);
|
2015-05-18 08:40:32 +03:00
|
|
|
mAudio.mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kAudioTrack, 0);
|
2015-08-26 04:25:49 +03:00
|
|
|
if (!mAudio.mTrackDemuxer) {
|
2016-09-10 12:56:50 +03:00
|
|
|
mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
|
2015-08-26 04:25:49 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-12 05:00:21 +03:00
|
|
|
|
2016-04-27 10:35:58 +03:00
|
|
|
UniquePtr<TrackInfo> audioInfo = mAudio.mTrackDemuxer->GetInfo();
|
|
|
|
// We actively ignore audio tracks that we know we can't play.
|
2017-09-04 12:27:43 +03:00
|
|
|
audioActive = audioInfo && audioInfo->IsValid() &&
|
|
|
|
(!platform ||
|
|
|
|
platform->SupportsMimeType(audioInfo->mMimeType, nullptr));
|
2016-05-12 05:00:21 +03:00
|
|
|
|
2016-04-27 10:35:58 +03:00
|
|
|
if (audioActive) {
|
2018-10-03 11:23:08 +03:00
|
|
|
mInfo.mAudio = *audioInfo->GetAsAudioInfo();
|
|
|
|
mAudio.mWorkingInfo = MakeUnique<AudioInfo>(mInfo.mAudio);
|
2016-04-27 10:35:58 +03:00
|
|
|
for (const MetadataTag& tag : audioInfo->mTags) {
|
|
|
|
tags->Put(tag.mKey, tag.mValue);
|
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
mAudio.mOriginalInfo = std::move(audioInfo);
|
2016-04-27 10:35:58 +03:00
|
|
|
mTrackDemuxersMayBlock |= mAudio.mTrackDemuxer->GetSamplesMayBlock();
|
|
|
|
} else {
|
|
|
|
mAudio.mTrackDemuxer->BreakCycles();
|
|
|
|
mAudio.mTrackDemuxer = nullptr;
|
2016-01-08 03:22:53 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<EncryptionInfo> crypto = mDemuxer->GetCrypto();
|
2017-07-13 06:18:07 +03:00
|
|
|
if (crypto && crypto->IsEncrypted()) {
|
2015-05-18 08:40:32 +03:00
|
|
|
// Try and dispatch 'encrypted'. Won't go if ready state still HAVE_NOTHING.
|
|
|
|
for (uint32_t i = 0; i < crypto->mInitDatas.Length(); i++) {
|
2017-07-13 06:18:07 +03:00
|
|
|
mOnEncrypted.Notify(crypto->mInitDatas[i].mInitData,
|
|
|
|
crypto->mInitDatas[i].mType);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
mInfo.mCrypto = *crypto;
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:41:36 +03:00
|
|
|
auto videoDuration = HasVideo() ? mInfo.mVideo.mDuration : TimeUnit::Zero();
|
|
|
|
auto audioDuration = HasAudio() ? mInfo.mAudio.mDuration : TimeUnit::Zero();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-04-12 11:41:36 +03:00
|
|
|
auto duration = std::max(videoDuration, audioDuration);
|
|
|
|
if (duration.IsPositive()) {
|
|
|
|
mInfo.mMetadataDuration = Some(duration);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2015-12-02 10:42:32 +03:00
|
|
|
mInfo.mMediaSeekable = mDemuxer->IsSeekable();
|
2016-02-04 07:31:21 +03:00
|
|
|
mInfo.mMediaSeekableOnlyInBufferedRanges =
|
|
|
|
mDemuxer->IsSeekableOnlyInBufferedRanges();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-07-14 17:25:44 +03:00
|
|
|
if (!videoActive && !audioActive) {
|
2016-09-10 12:56:50 +03:00
|
|
|
mMetadataPromise.Reject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__);
|
2015-07-14 17:25:44 +03:00
|
|
|
return;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mTags = std::move(tags);
|
2015-10-21 04:28:04 +03:00
|
|
|
mInitDone = true;
|
2016-10-27 10:21:05 +03:00
|
|
|
|
|
|
|
// Try to get the start time.
|
|
|
|
// For MSE case, the start time of each track is assumed to be 0.
|
|
|
|
// For others, we must demux the first sample to know the start time for each
|
|
|
|
// track.
|
2016-12-21 09:58:38 +03:00
|
|
|
if (!mDemuxer->ShouldComputeStartTime()) {
|
2017-04-17 11:35:04 +03:00
|
|
|
mAudio.mFirstDemuxedSampleTime.emplace(TimeUnit::Zero());
|
|
|
|
mVideo.mFirstDemuxedSampleTime.emplace(TimeUnit::Zero());
|
2016-10-27 10:21:05 +03:00
|
|
|
} else {
|
|
|
|
if (HasAudio()) {
|
|
|
|
RequestDemuxSamples(TrackInfo::kAudioTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasVideo()) {
|
|
|
|
RequestDemuxSamples(TrackInfo::kVideoTrack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 10:02:06 +03:00
|
|
|
if (aResult != NS_OK) {
|
|
|
|
mOnDecodeWarning.Notify(aResult);
|
2017-03-06 07:22:17 +03:00
|
|
|
}
|
|
|
|
|
2016-10-27 10:21:05 +03:00
|
|
|
MaybeResolveMetadataPromise();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::MaybeResolveMetadataPromise() {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2017-09-04 12:27:43 +03:00
|
|
|
if ((HasAudio() && mAudio.mFirstDemuxedSampleTime.isNothing()) ||
|
|
|
|
(HasVideo() && mVideo.mFirstDemuxedSampleTime.isNothing())) {
|
2016-10-27 10:21:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeUnit startTime =
|
|
|
|
std::min(mAudio.mFirstDemuxedSampleTime.refOr(TimeUnit::FromInfinity()),
|
|
|
|
mVideo.mFirstDemuxedSampleTime.refOr(TimeUnit::FromInfinity()));
|
|
|
|
|
|
|
|
if (!startTime.IsInfinite()) {
|
|
|
|
mInfo.mStartTime = startTime; // mInfo.mStartTime is initialized to 0.
|
|
|
|
}
|
|
|
|
|
2017-05-18 05:20:44 +03:00
|
|
|
MetadataHolder metadata;
|
|
|
|
metadata.mInfo = MakeUnique<MediaInfo>(mInfo);
|
2018-05-30 22:15:35 +03:00
|
|
|
metadata.mTags = mTags->Count() ? std::move(mTags) : nullptr;
|
2016-11-28 13:08:01 +03:00
|
|
|
|
|
|
|
// We now have all the informations required to calculate the initial buffered
|
|
|
|
// range.
|
|
|
|
mHasStartTime = true;
|
|
|
|
UpdateBuffered();
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mMetadataPromise.Resolve(std::move(metadata), __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-09-28 03:34:57 +03:00
|
|
|
bool MediaFormatReader::IsEncrypted() const {
|
2019-01-11 18:29:45 +03:00
|
|
|
return (HasAudio() && mAudio.GetCurrentInfo()->mCrypto.IsEncrypted()) ||
|
|
|
|
(HasVideo() && mVideo.GetCurrentInfo()->mCrypto.IsEncrypted());
|
2016-09-28 03:34:57 +03:00
|
|
|
}
|
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
void MediaFormatReader::OnDemuxerInitFailed(const MediaResult& aError) {
|
2015-05-18 08:40:32 +03:00
|
|
|
mDemuxerInitRequest.Complete();
|
2016-09-12 05:22:20 +03:00
|
|
|
mMetadataPromise.Reject(aError, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::ReadUpdatedMetadata(MediaInfo* aInfo) {
|
2018-10-03 11:23:08 +03:00
|
|
|
// Called on the MDSM's TaskQueue.
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mVideo.mMutex);
|
|
|
|
if (HasVideo()) {
|
|
|
|
aInfo->mVideo = *mVideo.GetWorkingInfo()->GetAsVideoInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mAudio.mMutex);
|
|
|
|
if (HasAudio()) {
|
|
|
|
aInfo->mAudio = *mAudio.GetWorkingInfo()->GetAsAudioInfo();
|
|
|
|
}
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaFormatReader::DecoderData& MediaFormatReader::GetDecoderData(
|
|
|
|
TrackType aTrack) {
|
2017-09-04 12:27:43 +03:00
|
|
|
MOZ_ASSERT(aTrack == TrackInfo::kAudioTrack ||
|
|
|
|
aTrack == TrackInfo::kVideoTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
if (aTrack == TrackInfo::kAudioTrack) {
|
|
|
|
return mAudio;
|
|
|
|
}
|
|
|
|
return mVideo;
|
|
|
|
}
|
|
|
|
|
2017-06-12 10:01:29 +03:00
|
|
|
bool MediaFormatReader::ShouldSkip(TimeUnit aTimeThreshold) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(HasVideo());
|
2017-06-12 11:36:42 +03:00
|
|
|
|
2018-03-20 01:48:56 +03:00
|
|
|
if (!StaticPrefs::MediaDecoderSkipToNextKeyFrameEnabled()) {
|
2017-06-12 11:36:42 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
TimeUnit nextKeyframe;
|
2015-05-18 08:40:32 +03:00
|
|
|
nsresult rv = mVideo.mTrackDemuxer->GetNextRandomAccessPoint(&nextKeyframe);
|
|
|
|
if (NS_FAILED(rv)) {
|
2017-06-12 10:01:29 +03:00
|
|
|
// Only OggTrackDemuxer with video type gets into here.
|
|
|
|
// We don't support skip-to-next-frame for this case.
|
|
|
|
return false;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2017-09-04 12:27:43 +03:00
|
|
|
return (nextKeyframe <= aTimeThreshold ||
|
|
|
|
(mVideo.mTimeThreshold &&
|
|
|
|
mVideo.mTimeThreshold.ref().EndTime() < aTimeThreshold)) &&
|
|
|
|
nextKeyframe.ToMicroseconds() >= 0 && !nextKeyframe.IsInfinite();
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
RefPtr<MediaFormatReader::VideoDataPromise> MediaFormatReader::RequestVideoData(
|
2017-06-12 11:06:11 +03:00
|
|
|
const TimeUnit& aTimeThreshold) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2017-01-27 15:20:37 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mSeekPromise.IsEmpty(),
|
|
|
|
"No sample requests allowed while seeking");
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mVideo.HasPromise(), "No duplicate sample requests");
|
2017-09-04 12:27:43 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mVideo.mSeekRequest.Exists() ||
|
|
|
|
mVideo.mTimeThreshold.isSome());
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!IsSeeking(), "called mid-seek");
|
2017-06-12 11:06:11 +03:00
|
|
|
LOGV("RequestVideoData(%" PRId64 ")", aTimeThreshold.ToMicroseconds());
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
if (!HasVideo()) {
|
|
|
|
LOG("called with no video track");
|
2017-03-22 06:28:33 +03:00
|
|
|
return VideoDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
|
2017-01-27 15:20:37 +03:00
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSeeking()) {
|
|
|
|
LOG("called mid-seek. Rejecting.");
|
2017-03-22 06:28:33 +03:00
|
|
|
return VideoDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_CANCELED,
|
2017-01-27 15:20:37 +03:00
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
NS_WARNING("RequestVideoData on shutdown MediaFormatReader!");
|
2017-03-22 06:28:33 +03:00
|
|
|
return VideoDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_CANCELED,
|
2017-01-27 15:20:37 +03:00
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-05-05 07:52:58 +03:00
|
|
|
// Ensure we have no pending seek going as ShouldSkip could return out of date
|
|
|
|
// information.
|
2017-06-12 10:01:29 +03:00
|
|
|
if (!mVideo.HasInternalSeekPending() && ShouldSkip(aTimeThreshold)) {
|
2017-03-22 06:28:33 +03:00
|
|
|
RefPtr<VideoDataPromise> p = mVideo.EnsurePromise(__func__);
|
2017-03-29 11:52:57 +03:00
|
|
|
SkipVideoDemuxToNextKeyFrame(aTimeThreshold);
|
2015-05-18 08:40:32 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
RefPtr<VideoDataPromise> p = mVideo.EnsurePromise(__func__);
|
2016-09-01 12:25:54 +03:00
|
|
|
ScheduleUpdate(TrackInfo::kVideoTrack);
|
2015-08-24 05:50:27 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
void MediaFormatReader::OnDemuxFailed(TrackType aTrack,
|
|
|
|
const MediaResult& aError) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2017-09-28 19:37:45 +03:00
|
|
|
LOG("Failed to demux %s, failure:%s",
|
2016-12-16 06:16:31 +03:00
|
|
|
aTrack == TrackType::kVideoTrack ? "video" : "audio",
|
2017-09-28 19:37:45 +03:00
|
|
|
aError.ErrorName().get());
|
2015-05-18 08:40:32 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
decoder.mDemuxRequest.Complete();
|
2016-09-12 05:22:20 +03:00
|
|
|
switch (aError.Code()) {
|
|
|
|
case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log,
|
|
|
|
aTrack == TrackType::kVideoTrack ? "video_demux_interruption"
|
|
|
|
: "audio_demux_interruption",
|
|
|
|
aError);
|
2016-05-23 09:09:12 +03:00
|
|
|
if (!decoder.mWaitingForData) {
|
2017-02-09 17:31:44 +03:00
|
|
|
decoder.RequestDrain();
|
2016-05-23 09:09:12 +03:00
|
|
|
}
|
2015-06-15 03:58:12 +03:00
|
|
|
NotifyEndOfStream(aTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
break;
|
2016-09-12 05:22:20 +03:00
|
|
|
case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log,
|
|
|
|
aTrack == TrackType::kVideoTrack ? "video_demux_interruption"
|
|
|
|
: "audio_demux_interruption",
|
|
|
|
aError);
|
2015-12-08 22:30:25 +03:00
|
|
|
if (!decoder.mWaitingForData) {
|
2017-02-09 17:31:44 +03:00
|
|
|
decoder.RequestDrain();
|
2015-12-08 22:30:25 +03:00
|
|
|
}
|
2015-05-18 08:42:01 +03:00
|
|
|
NotifyWaitingForData(aTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
break;
|
2016-09-12 05:22:20 +03:00
|
|
|
case NS_ERROR_DOM_MEDIA_CANCELED:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log,
|
|
|
|
aTrack == TrackType::kVideoTrack ? "video_demux_interruption"
|
|
|
|
: "audio_demux_interruption",
|
|
|
|
aError);
|
2015-05-18 08:40:32 +03:00
|
|
|
if (decoder.HasPromise()) {
|
2016-09-10 09:48:53 +03:00
|
|
|
decoder.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log,
|
|
|
|
aTrack == TrackType::kVideoTrack ? "video_demux_error"
|
|
|
|
: "audio_demux_error",
|
|
|
|
aError);
|
2016-09-12 05:22:20 +03:00
|
|
|
NotifyError(aTrack, aError);
|
2015-05-18 08:40:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::DoDemuxVideo() {
|
2017-05-09 18:31:32 +03:00
|
|
|
using SamplesPromise = MediaTrackDemuxer::SamplesPromise;
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "video_demuxing", DDNoValue{});
|
2016-10-27 10:21:05 +03:00
|
|
|
auto p = mVideo.mTrackDemuxer->GetSamples(1);
|
|
|
|
|
|
|
|
if (mVideo.mFirstDemuxedSampleTime.isNothing()) {
|
|
|
|
RefPtr<MediaFormatReader> self = this;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
p = p->Then(OwnerThread(), __func__,
|
|
|
|
[self](RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log, "video_first_demuxed",
|
|
|
|
DDNoValue{});
|
|
|
|
self->OnFirstDemuxCompleted(TrackInfo::kVideoTrack, aSamples);
|
|
|
|
return SamplesPromise::CreateAndResolve(aSamples.forget(),
|
|
|
|
__func__);
|
|
|
|
},
|
|
|
|
[self](const MediaResult& aError) {
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log,
|
|
|
|
"video_first_demuxing_error", aError);
|
|
|
|
self->OnFirstDemuxFailed(TrackInfo::kVideoTrack, aError);
|
|
|
|
return SamplesPromise::CreateAndReject(aError, __func__);
|
|
|
|
});
|
2016-10-27 10:21:05 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 11:33:29 +03:00
|
|
|
p->Then(OwnerThread(), __func__, this,
|
|
|
|
&MediaFormatReader::OnVideoDemuxCompleted,
|
|
|
|
&MediaFormatReader::OnVideoDemuxFailed)
|
|
|
|
->Track(mVideo.mDemuxRequest);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::OnVideoDemuxCompleted(
|
|
|
|
RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
|
2017-07-26 23:03:57 +03:00
|
|
|
LOGV("%zu video samples demuxed (sid:%d)", aSamples->mSamples.Length(),
|
2017-01-27 15:20:37 +03:00
|
|
|
aSamples->mSamples[0]->mTrackInfo
|
|
|
|
? aSamples->mSamples[0]->mTrackInfo->GetID()
|
|
|
|
: 0);
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "video_demuxed_samples",
|
|
|
|
uint64_t(aSamples->mSamples.Length()));
|
2015-05-18 08:40:32 +03:00
|
|
|
mVideo.mDemuxRequest.Complete();
|
|
|
|
mVideo.mQueuedSamples.AppendElements(aSamples->mSamples);
|
|
|
|
ScheduleUpdate(TrackInfo::kVideoTrack);
|
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
RefPtr<MediaFormatReader::AudioDataPromise>
|
2015-05-18 08:40:32 +03:00
|
|
|
MediaFormatReader::RequestAudioData() {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mAudio.HasPromise(), "No duplicate sample requests");
|
2016-05-16 11:15:45 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsVideoSeeking() || mSeekPromise.IsEmpty(),
|
|
|
|
"No sample requests allowed while seeking");
|
2017-09-04 12:27:43 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsVideoSeeking() || !mAudio.mSeekRequest.Exists() ||
|
|
|
|
mAudio.mTimeThreshold.isSome());
|
2016-05-16 11:15:45 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsVideoSeeking() || !IsSeeking(), "called mid-seek");
|
2015-05-18 08:40:32 +03:00
|
|
|
LOGV("");
|
|
|
|
|
|
|
|
if (!HasAudio()) {
|
|
|
|
LOG("called with no audio track");
|
2017-03-22 06:28:33 +03:00
|
|
|
return AudioDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR,
|
2017-01-27 15:20:37 +03:00
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSeeking()) {
|
|
|
|
LOG("called mid-seek. Rejecting.");
|
2017-03-22 06:28:33 +03:00
|
|
|
return AudioDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_CANCELED,
|
2017-01-27 15:20:37 +03:00
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
NS_WARNING("RequestAudioData on shutdown MediaFormatReader!");
|
2017-03-22 06:28:33 +03:00
|
|
|
return AudioDataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_CANCELED,
|
2017-01-27 15:20:37 +03:00
|
|
|
__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
RefPtr<AudioDataPromise> p = mAudio.EnsurePromise(__func__);
|
2016-09-01 12:25:54 +03:00
|
|
|
ScheduleUpdate(TrackInfo::kAudioTrack);
|
2015-08-11 06:50:07 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::DoDemuxAudio() {
|
2017-05-09 18:31:32 +03:00
|
|
|
using SamplesPromise = MediaTrackDemuxer::SamplesPromise;
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "audio_demuxing", DDNoValue{});
|
2016-10-27 10:21:05 +03:00
|
|
|
auto p = mAudio.mTrackDemuxer->GetSamples(1);
|
|
|
|
|
|
|
|
if (mAudio.mFirstDemuxedSampleTime.isNothing()) {
|
|
|
|
RefPtr<MediaFormatReader> self = this;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
p = p->Then(OwnerThread(), __func__,
|
|
|
|
[self](RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log, "audio_first_demuxed",
|
|
|
|
DDNoValue{});
|
|
|
|
self->OnFirstDemuxCompleted(TrackInfo::kAudioTrack, aSamples);
|
|
|
|
return SamplesPromise::CreateAndResolve(aSamples.forget(),
|
|
|
|
__func__);
|
|
|
|
},
|
|
|
|
[self](const MediaResult& aError) {
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log,
|
|
|
|
"audio_first_demuxing_error", aError);
|
|
|
|
self->OnFirstDemuxFailed(TrackInfo::kAudioTrack, aError);
|
|
|
|
return SamplesPromise::CreateAndReject(aError, __func__);
|
|
|
|
});
|
2016-10-27 10:21:05 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 11:33:29 +03:00
|
|
|
p->Then(OwnerThread(), __func__, this,
|
|
|
|
&MediaFormatReader::OnAudioDemuxCompleted,
|
|
|
|
&MediaFormatReader::OnAudioDemuxFailed)
|
|
|
|
->Track(mAudio.mDemuxRequest);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::OnAudioDemuxCompleted(
|
|
|
|
RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
|
2017-07-26 23:03:57 +03:00
|
|
|
LOGV("%zu audio samples demuxed (sid:%d)", aSamples->mSamples.Length(),
|
2017-01-27 15:20:37 +03:00
|
|
|
aSamples->mSamples[0]->mTrackInfo
|
|
|
|
? aSamples->mSamples[0]->mTrackInfo->GetID()
|
|
|
|
: 0);
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "audio_demuxed_samples",
|
|
|
|
uint64_t(aSamples->mSamples.Length()));
|
2015-05-18 08:40:32 +03:00
|
|
|
mAudio.mDemuxRequest.Complete();
|
|
|
|
mAudio.mQueuedSamples.AppendElements(aSamples->mSamples);
|
|
|
|
ScheduleUpdate(TrackInfo::kAudioTrack);
|
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::NotifyNewOutput(
|
2018-11-09 18:45:31 +03:00
|
|
|
TrackType aTrack, MediaDataDecoder::DecodedData&& aResults) {
|
2015-05-18 08:42:01 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
if (aResults.IsEmpty()) {
|
|
|
|
DDLOG(DDLogCategory::Log,
|
|
|
|
aTrack == TrackInfo::kAudioTrack ? "decoded_audio" : "decoded_video",
|
|
|
|
"no output samples");
|
|
|
|
} else
|
2018-11-09 18:45:31 +03:00
|
|
|
for (auto&& sample : aResults) {
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
if (DecoderDoctorLogger::IsDDLoggingEnabled()) {
|
|
|
|
switch (sample->mType) {
|
2019-02-22 12:18:18 +03:00
|
|
|
case MediaData::Type::AUDIO_DATA:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGPR(DDLogCategory::Log,
|
|
|
|
aTrack == TrackInfo::kAudioTrack ? "decoded_audio"
|
|
|
|
: "decoded_got_audio!?",
|
|
|
|
"{\"type\":\"AudioData\", \"offset\":%" PRIi64
|
|
|
|
", \"time_us\":%" PRIi64 ", \"timecode_us\":%" PRIi64
|
|
|
|
", \"duration_us\":%" PRIi64 ", \"frames\":%" PRIu32
|
2019-02-22 12:18:33 +03:00
|
|
|
", \"channels\":%" PRIu32 ", \"rate\":%" PRIu32
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
", \"bytes\":%zu}",
|
|
|
|
sample->mOffset, sample->mTime.ToMicroseconds(),
|
|
|
|
sample->mTimecode.ToMicroseconds(),
|
2019-02-22 12:18:33 +03:00
|
|
|
sample->mDuration.ToMicroseconds(),
|
2019-02-22 12:18:47 +03:00
|
|
|
static_cast<AudioData*>(sample.get())->Frames(),
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
sample->As<AudioData>()->mChannels,
|
|
|
|
sample->As<AudioData>()->mRate,
|
2019-02-22 12:18:04 +03:00
|
|
|
sample->As<AudioData>()->Data().Length());
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
break;
|
2019-02-22 12:18:18 +03:00
|
|
|
case MediaData::Type::VIDEO_DATA:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGPR(DDLogCategory::Log,
|
|
|
|
aTrack == TrackInfo::kVideoTrack ? "decoded_video"
|
|
|
|
: "decoded_got_video!?",
|
|
|
|
"{\"type\":\"VideoData\", \"offset\":%" PRIi64
|
|
|
|
", \"time_us\":%" PRIi64 ", \"timecode_us\":%" PRIi64
|
2019-02-22 12:18:33 +03:00
|
|
|
", \"duration_us\":%" PRIi64
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
", \"kf\":%s, \"size\":[%" PRIi32 ",%" PRIi32 "]}",
|
|
|
|
sample->mOffset, sample->mTime.ToMicroseconds(),
|
|
|
|
sample->mTimecode.ToMicroseconds(),
|
2019-02-22 12:18:33 +03:00
|
|
|
sample->mDuration.ToMicroseconds(),
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
sample->mKeyframe ? "true" : "false",
|
|
|
|
sample->As<VideoData>()->mDisplay.width,
|
|
|
|
sample->As<VideoData>()->mDisplay.height);
|
|
|
|
break;
|
2019-02-22 12:18:18 +03:00
|
|
|
case MediaData::Type::RAW_DATA:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGPR(DDLogCategory::Log,
|
|
|
|
aTrack == TrackInfo::kAudioTrack
|
|
|
|
? "decoded_audio"
|
|
|
|
: aTrack == TrackInfo::kVideoTrack ? "decoded_video"
|
|
|
|
: "decoded_?",
|
|
|
|
"{\"type\":\"RawData\", \"offset\":%" PRIi64
|
|
|
|
" \"time_us\":%" PRIi64 ", \"timecode_us\":%" PRIi64
|
2019-02-22 12:18:33 +03:00
|
|
|
", \"duration_us\":%" PRIi64 ", \"kf\":%s}",
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
sample->mOffset, sample->mTime.ToMicroseconds(),
|
|
|
|
sample->mTimecode.ToMicroseconds(),
|
2019-02-22 12:18:33 +03:00
|
|
|
sample->mDuration.ToMicroseconds(),
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
sample->mKeyframe ? "true" : "false");
|
|
|
|
break;
|
2019-02-22 12:18:18 +03:00
|
|
|
case MediaData::Type::NULL_DATA:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGPR(DDLogCategory::Log,
|
|
|
|
aTrack == TrackInfo::kAudioTrack
|
|
|
|
? "decoded_audio"
|
|
|
|
: aTrack == TrackInfo::kVideoTrack ? "decoded_video"
|
|
|
|
: "decoded_?",
|
|
|
|
"{\"type\":\"NullData\", \"offset\":%" PRIi64
|
|
|
|
" \"time_us\":%" PRIi64 ", \"timecode_us\":%" PRIi64
|
2019-02-22 12:18:33 +03:00
|
|
|
", \"duration_us\":%" PRIi64 ", \"kf\":%s}",
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
sample->mOffset, sample->mTime.ToMicroseconds(),
|
|
|
|
sample->mTimecode.ToMicroseconds(),
|
2019-02-22 12:18:33 +03:00
|
|
|
sample->mDuration.ToMicroseconds(),
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
sample->mKeyframe ? "true" : "false");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOGV("Received new %s sample time:%" PRId64 " duration:%" PRId64,
|
|
|
|
TrackTypeToStr(aTrack), sample->mTime.ToMicroseconds(),
|
|
|
|
sample->mDuration.ToMicroseconds());
|
|
|
|
decoder.mOutput.AppendElement(sample);
|
|
|
|
decoder.mNumSamplesOutput++;
|
|
|
|
decoder.mNumOfConsecutiveError = 0;
|
|
|
|
}
|
2017-01-26 15:56:46 +03:00
|
|
|
LOG("Done processing new %s samples", TrackTypeToStr(aTrack));
|
2017-05-11 11:29:57 +03:00
|
|
|
|
|
|
|
if (!aResults.IsEmpty()) {
|
|
|
|
// We have decoded our first frame, we can now starts to skip future errors.
|
|
|
|
decoder.mFirstFrameTime.reset();
|
|
|
|
}
|
2015-05-18 08:42:01 +03:00
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
}
|
|
|
|
|
2016-09-10 02:56:53 +03:00
|
|
|
void MediaFormatReader::NotifyError(TrackType aTrack,
|
|
|
|
const MediaResult& aError) {
|
2015-05-18 08:42:01 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-09-20 08:59:42 +03:00
|
|
|
NS_WARNING(aError.Description().get());
|
2015-05-25 08:09:16 +03:00
|
|
|
LOGV("%s Decoding error", TrackTypeToStr(aTrack));
|
2015-05-18 08:42:01 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2016-05-30 19:24:00 +03:00
|
|
|
decoder.mError = decoder.HasFatalError() ? decoder.mError : Some(aError);
|
2017-08-31 13:02:06 +03:00
|
|
|
|
|
|
|
// The GPU process had crashed and we receive a
|
|
|
|
// NS_ERROR_DOM_MEDIA_NEED_NEW_DECODER because we were doing HW decoding.
|
|
|
|
// Now, save the related data and we will report the recovery time when a new
|
|
|
|
// decoder is ready.
|
2017-09-03 22:28:52 +03:00
|
|
|
if (aTrack == TrackType::kVideoTrack &&
|
|
|
|
aError == NS_ERROR_DOM_MEDIA_NEED_NEW_DECODER &&
|
|
|
|
!aError.GPUCrashTimeStamp().IsNull()) {
|
|
|
|
GPUProcessCrashTelemetryLogger::RecordGPUCrashData(
|
2017-09-21 13:02:30 +03:00
|
|
|
mMediaDecoderOwnerID, decoder.mDecoder.get(),
|
2017-09-03 22:28:52 +03:00
|
|
|
aError.GPUCrashTimeStamp(), TimeStamp::Now());
|
2017-08-31 13:02:06 +03:00
|
|
|
}
|
|
|
|
|
2015-05-18 08:42:01 +03:00
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::NotifyWaitingForData(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
decoder.mWaitingForData = true;
|
2015-12-08 22:30:25 +03:00
|
|
|
if (decoder.mTimeThreshold) {
|
|
|
|
decoder.mTimeThreshold.ref().mWaiting = true;
|
|
|
|
}
|
2015-05-18 08:42:01 +03:00
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
}
|
|
|
|
|
2017-01-27 13:48:00 +03:00
|
|
|
void MediaFormatReader::NotifyWaitingForKey(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2017-07-13 09:49:23 +03:00
|
|
|
mOnWaitingForKey.Notify();
|
2017-01-27 13:48:00 +03:00
|
|
|
if (!decoder.mDecodeRequest.Exists()) {
|
|
|
|
LOGV("WaitingForKey received while no pending decode. Ignoring");
|
2017-02-24 17:00:39 +03:00
|
|
|
return;
|
2017-01-27 13:48:00 +03:00
|
|
|
}
|
|
|
|
decoder.mWaitingForKey = true;
|
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
}
|
|
|
|
|
2015-06-15 03:58:12 +03:00
|
|
|
void MediaFormatReader::NotifyEndOfStream(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
decoder.mDemuxEOS = true;
|
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
bool MediaFormatReader::NeedInput(DecoderData& aDecoder) {
|
2017-01-26 15:56:46 +03:00
|
|
|
// The decoder will not be fed a new raw sample until the current decoding
|
|
|
|
// requests has completed.
|
2017-09-04 12:27:43 +03:00
|
|
|
return (aDecoder.HasPromise() || aDecoder.mTimeThreshold.isSome()) &&
|
|
|
|
!aDecoder.HasPendingDrain() && !aDecoder.HasFatalError() &&
|
|
|
|
!aDecoder.mDemuxRequest.Exists() && !aDecoder.mOutput.Length() &&
|
|
|
|
!aDecoder.HasInternalSeekPending() &&
|
|
|
|
!aDecoder.mDecodeRequest.Exists();
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
void MediaFormatReader::ScheduleUpdate(TrackType aTrack) {
|
2015-05-18 08:42:01 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2018-08-09 19:24:33 +03:00
|
|
|
MOZ_RELEASE_ASSERT(decoder.GetCurrentInfo(),
|
|
|
|
"Can only schedule update when track exists");
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
if (decoder.mUpdateScheduled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOGV("SchedulingUpdate(%s)", TrackTypeToStr(aTrack));
|
|
|
|
decoder.mUpdateScheduled = true;
|
2017-06-12 22:34:10 +03:00
|
|
|
RefPtr<nsIRunnable> task(NewRunnableMethod<TrackType>(
|
|
|
|
"MediaFormatReader::Update", this, &MediaFormatReader::Update, aTrack));
|
2017-11-15 09:58:03 +03:00
|
|
|
nsresult rv = OwnerThread()->Dispatch(task.forget());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
2017-12-21 07:12:42 +03:00
|
|
|
Unused << rv;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFormatReader::UpdateReceivedNewData(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
|
|
|
|
if (!decoder.mReceivedNewData) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-08 22:30:25 +03:00
|
|
|
|
2016-05-05 07:52:58 +03:00
|
|
|
// We do not want to clear mWaitingForData while there are pending
|
|
|
|
// demuxing or seeking operations that could affect the value of this flag.
|
|
|
|
// This is in order to ensure that we will retry once they complete as we may
|
|
|
|
// now have new data that could potentially allow those operations to
|
|
|
|
// successfully complete if tried again.
|
|
|
|
if (decoder.mSeekRequest.Exists()) {
|
|
|
|
// Nothing more to do until this operation complete.
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-21 18:02:43 +03:00
|
|
|
|
|
|
|
if (aTrack == TrackType::kVideoTrack && mSkipRequest.Exists()) {
|
|
|
|
LOGV("Skipping in progress, nothing more to do");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-05 07:52:58 +03:00
|
|
|
if (decoder.mDemuxRequest.Exists()) {
|
|
|
|
// We may have pending operations to process, so we want to continue
|
|
|
|
// after UpdateReceivedNewData returns.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-02 14:08:05 +03:00
|
|
|
if (decoder.HasPendingDrain()) {
|
2015-12-08 22:30:25 +03:00
|
|
|
// We do not want to clear mWaitingForData or mDemuxEOS while
|
|
|
|
// a drain is in progress in order to properly complete the operation.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder.mReceivedNewData = false;
|
|
|
|
if (decoder.mTimeThreshold) {
|
|
|
|
decoder.mTimeThreshold.ref().mWaiting = false;
|
|
|
|
}
|
|
|
|
decoder.mWaitingForData = false;
|
|
|
|
|
2016-05-30 19:24:00 +03:00
|
|
|
if (decoder.HasFatalError()) {
|
2015-05-25 08:09:16 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-05 07:52:58 +03:00
|
|
|
|
2017-09-04 12:27:43 +03:00
|
|
|
if (!mSeekPromise.IsEmpty() &&
|
|
|
|
(!IsVideoSeeking() || aTrack == TrackInfo::kVideoTrack)) {
|
2016-05-05 08:01:51 +03:00
|
|
|
MOZ_ASSERT(!decoder.HasPromise());
|
2017-01-27 15:20:37 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
(IsVideoSeeking() || !mAudio.mTimeThreshold) && !mVideo.mTimeThreshold,
|
|
|
|
"InternalSeek must have been aborted when Seek was first called");
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
2017-09-04 12:27:43 +03:00
|
|
|
(IsVideoSeeking() || !mAudio.HasWaitingPromise()) &&
|
|
|
|
!mVideo.HasWaitingPromise(),
|
2017-01-27 15:20:37 +03:00
|
|
|
"Waiting promises must have been rejected when Seek was first called");
|
2017-09-04 12:27:43 +03:00
|
|
|
if (mVideo.mSeekRequest.Exists() ||
|
|
|
|
(!IsVideoSeeking() && mAudio.mSeekRequest.Exists())) {
|
2016-05-05 08:01:51 +03:00
|
|
|
// Already waiting for a seek to complete. Nothing more to do.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
LOG("Attempting Seek");
|
|
|
|
ScheduleSeek();
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-05 07:52:58 +03:00
|
|
|
if (decoder.HasInternalSeekPending() || decoder.HasWaitingPromise()) {
|
|
|
|
if (decoder.HasInternalSeekPending()) {
|
|
|
|
LOG("Attempting Internal Seek");
|
|
|
|
InternalSeek(aTrack, decoder.mTimeThreshold.ref());
|
|
|
|
}
|
2017-11-14 10:20:08 +03:00
|
|
|
if (decoder.HasWaitingPromise() && !decoder.IsWaitingForKey() &&
|
|
|
|
!decoder.IsWaitingForData()) {
|
2016-05-05 07:52:58 +03:00
|
|
|
MOZ_ASSERT(!decoder.HasPromise());
|
|
|
|
LOG("We have new data. Resolving WaitingPromise");
|
|
|
|
decoder.mWaitingPromise.Resolve(decoder.mType, __func__);
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::RequestDemuxSamples(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2015-05-25 08:09:16 +03:00
|
|
|
MOZ_ASSERT(!decoder.mDemuxRequest.Exists());
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
if (!decoder.mQueuedSamples.IsEmpty()) {
|
|
|
|
// No need to demux new samples.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decoder.mDemuxEOS) {
|
|
|
|
// Nothing left to demux.
|
2015-12-08 22:30:25 +03:00
|
|
|
// We do not want to attempt to demux while in waiting for data mode
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
// as it would retrigger an unnecessary drain.
|
2015-05-18 08:40:32 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-05-25 08:09:16 +03:00
|
|
|
|
|
|
|
LOGV("Requesting extra demux %s", TrackTypeToStr(aTrack));
|
2015-05-18 08:40:32 +03:00
|
|
|
if (aTrack == TrackInfo::kVideoTrack) {
|
|
|
|
DoDemuxVideo();
|
|
|
|
} else {
|
|
|
|
DoDemuxAudio();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::DecodeDemuxedSamples(TrackType aTrack,
|
2015-10-20 12:33:00 +03:00
|
|
|
MediaRawData* aSample) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2017-01-26 15:56:46 +03:00
|
|
|
RefPtr<MediaFormatReader> self = this;
|
|
|
|
decoder.mFlushed = false;
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGPR(DDLogCategory::Log,
|
|
|
|
aTrack == TrackInfo::kAudioTrack
|
|
|
|
? "decode_audio"
|
|
|
|
: aTrack == TrackInfo::kVideoTrack ? "decode_video" : "decode_?",
|
|
|
|
"{\"type\":\"MediaRawData\", \"offset\":%" PRIi64
|
|
|
|
", \"bytes\":%zu, \"time_us\":%" PRIi64 ", \"timecode_us\":%" PRIi64
|
2019-02-22 12:18:33 +03:00
|
|
|
", \"duration_us\":%" PRIi64 ",%s%s}",
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
aSample->mOffset, aSample->Size(), aSample->mTime.ToMicroseconds(),
|
|
|
|
aSample->mTimecode.ToMicroseconds(),
|
2019-02-22 12:18:33 +03:00
|
|
|
aSample->mDuration.ToMicroseconds(), aSample->mKeyframe ? " kf" : "",
|
|
|
|
aSample->mEOS ? " eos" : "");
|
2017-01-26 15:56:46 +03:00
|
|
|
decoder.mDecoder->Decode(aSample)
|
|
|
|
->Then(
|
|
|
|
mTaskQueue, __func__,
|
2018-11-09 18:45:31 +03:00
|
|
|
[self, aTrack, &decoder](MediaDataDecoder::DecodedData&& aResults) {
|
2017-01-26 15:56:46 +03:00
|
|
|
decoder.mDecodeRequest.Complete();
|
2018-11-09 18:45:31 +03:00
|
|
|
self->NotifyNewOutput(aTrack, std::move(aResults));
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2017-09-03 22:28:52 +03:00
|
|
|
// When we recovered from a GPU crash and get the first decoded
|
|
|
|
// frame, report the recovery time telemetry.
|
|
|
|
if (aTrack == TrackType::kVideoTrack) {
|
|
|
|
GPUProcessCrashTelemetryLogger::ReportTelemetry(
|
2017-10-26 11:59:40 +03:00
|
|
|
self->mMediaDecoderOwnerID, decoder.mDecoder.get());
|
2017-08-31 13:02:06 +03:00
|
|
|
}
|
2017-01-26 15:56:46 +03:00
|
|
|
},
|
2017-10-26 11:59:40 +03:00
|
|
|
[self, aTrack, &decoder](const MediaResult& aError) {
|
2017-01-26 15:56:46 +03:00
|
|
|
decoder.mDecodeRequest.Complete();
|
2017-10-26 11:59:40 +03:00
|
|
|
self->NotifyError(aTrack, aError);
|
2017-01-26 15:56:46 +03:00
|
|
|
})
|
|
|
|
->Track(decoder.mDecodeRequest);
|
2015-10-20 12:33:00 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::HandleDemuxedSamples(
|
2017-07-13 10:17:25 +03:00
|
|
|
TrackType aTrack, FrameStatistics::AutoNotifyDecoded& aA) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-06-08 15:28:24 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
|
2017-02-26 19:17:16 +03:00
|
|
|
if (decoder.mFlushing) {
|
2017-01-26 15:56:46 +03:00
|
|
|
LOGV("Decoder operation in progress, let it complete.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
if (decoder.mQueuedSamples.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-15 03:58:12 +03:00
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
RefPtr<MediaRawData> sample = decoder.mQueuedSamples[0];
|
|
|
|
const RefPtr<TrackInfoSharedPtr> info = sample->mTrackInfo;
|
|
|
|
|
|
|
|
if (info && decoder.mLastStreamSourceID != info->GetID()) {
|
|
|
|
nsTArray<RefPtr<MediaRawData>> samples;
|
|
|
|
if (decoder.mDecoder) {
|
2018-05-27 19:42:25 +03:00
|
|
|
bool recyclable =
|
|
|
|
StaticPrefs::MediaDecoderRecycleEnabled() &&
|
|
|
|
decoder.mDecoder->SupportDecoderRecycling() &&
|
2019-01-11 18:29:45 +03:00
|
|
|
(*info)->mCrypto.mCryptoScheme ==
|
|
|
|
decoder.GetCurrentInfo()->mCrypto.mCryptoScheme &&
|
2018-09-11 00:37:19 +03:00
|
|
|
(*info)->mMimeType == decoder.GetCurrentInfo()->mMimeType;
|
2017-09-14 15:45:10 +03:00
|
|
|
if (!recyclable && decoder.mTimeThreshold.isNothing() &&
|
|
|
|
(decoder.mNextStreamSourceID.isNothing() ||
|
2018-05-27 19:42:25 +03:00
|
|
|
decoder.mNextStreamSourceID.ref() != info->GetID())) {
|
2017-09-14 15:45:10 +03:00
|
|
|
LOG("%s stream id has changed from:%d to:%d, draining decoder.",
|
|
|
|
TrackTypeToStr(aTrack), decoder.mLastStreamSourceID, info->GetID());
|
|
|
|
decoder.RequestDrain();
|
|
|
|
decoder.mNextStreamSourceID = Some(info->GetID());
|
|
|
|
ScheduleUpdate(aTrack);
|
|
|
|
return;
|
2016-11-25 09:22:40 +03:00
|
|
|
}
|
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
// If flushing is required, it will clear our array of queued samples.
|
|
|
|
// So we may need to make a copy.
|
|
|
|
samples = decoder.mQueuedSamples;
|
|
|
|
if (!recyclable) {
|
|
|
|
LOG("Decoder does not support recycling, recreate decoder.");
|
|
|
|
ShutdownDecoder(aTrack);
|
2018-10-04 12:43:24 +03:00
|
|
|
// We're going to be using a new decoder following the change of content
|
|
|
|
// We can attempt to use hardware decoding again.
|
|
|
|
decoder.mHardwareDecodingDisabled = false;
|
2017-09-14 15:45:10 +03:00
|
|
|
} else if (decoder.HasWaitingPromise()) {
|
|
|
|
decoder.Flush();
|
2015-06-15 03:58:12 +03:00
|
|
|
}
|
2017-09-12 22:02:24 +03:00
|
|
|
}
|
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
LOG("%s stream id has changed from:%d to:%d.", TrackTypeToStr(aTrack),
|
|
|
|
decoder.mLastStreamSourceID, info->GetID());
|
|
|
|
|
|
|
|
decoder.mNextStreamSourceID.reset();
|
|
|
|
decoder.mLastStreamSourceID = info->GetID();
|
|
|
|
decoder.mInfo = info;
|
2018-10-03 11:23:08 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(decoder.mMutex);
|
|
|
|
if (aTrack == TrackInfo::kAudioTrack) {
|
|
|
|
decoder.mWorkingInfo = MakeUnique<AudioInfo>(*info->GetAsAudioInfo());
|
|
|
|
} else if (aTrack == TrackInfo::kVideoTrack) {
|
|
|
|
decoder.mWorkingInfo = MakeUnique<VideoInfo>(*info->GetAsVideoInfo());
|
|
|
|
}
|
|
|
|
}
|
2017-09-12 22:20:09 +03:00
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
decoder.mMeanRate.Reset();
|
|
|
|
|
|
|
|
if (sample->mKeyframe) {
|
|
|
|
if (samples.Length()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
decoder.mQueuedSamples = std::move(samples);
|
2017-09-14 15:45:10 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto time = TimeInterval(sample->mTime, sample->GetEndTime());
|
|
|
|
InternalSeekTarget seekTarget =
|
|
|
|
decoder.mTimeThreshold.refOr(InternalSeekTarget(time, false));
|
|
|
|
LOG("Stream change occurred on a non-keyframe. Seeking to:%" PRId64,
|
|
|
|
sample->mTime.ToMicroseconds());
|
|
|
|
InternalSeek(aTrack, seekTarget);
|
2015-08-11 06:50:07 +03:00
|
|
|
return;
|
2015-06-15 03:58:12 +03:00
|
|
|
}
|
2017-09-14 15:45:10 +03:00
|
|
|
}
|
2015-06-15 03:58:12 +03:00
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
// Calculate the average frame rate. The first frame will be accounted
|
|
|
|
// for twice.
|
|
|
|
decoder.mMeanRate.Update(sample->mDuration);
|
2015-10-20 12:33:00 +03:00
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
if (!decoder.mDecoder) {
|
|
|
|
mDecoderFactory->CreateDecoder(aTrack);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-20 12:33:00 +03:00
|
|
|
|
2017-09-14 15:45:10 +03:00
|
|
|
LOGV("Input:%" PRId64 " (dts:%" PRId64 " kf:%d)",
|
|
|
|
sample->mTime.ToMicroseconds(), sample->mTimecode.ToMicroseconds(),
|
|
|
|
sample->mKeyframe);
|
|
|
|
decoder.mNumSamplesInput++;
|
|
|
|
decoder.mSizeOfQueue++;
|
|
|
|
if (aTrack == TrackInfo::kVideoTrack) {
|
|
|
|
aA.mStats.mParsedFrames++;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2017-09-14 15:45:10 +03:00
|
|
|
|
|
|
|
DecodeDemuxedSamples(aTrack, sample);
|
|
|
|
|
|
|
|
decoder.mQueuedSamples.RemoveElementAt(0);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::InternalSeek(TrackType aTrack,
|
|
|
|
const InternalSeekTarget& aTarget) {
|
2015-12-08 22:30:25 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-05-05 07:52:58 +03:00
|
|
|
LOG("%s internal seek to %f", TrackTypeToStr(aTrack),
|
2016-05-18 06:48:05 +03:00
|
|
|
aTarget.Time().ToSeconds());
|
2016-05-05 07:52:58 +03:00
|
|
|
|
2015-12-08 22:30:25 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2016-05-05 08:06:40 +03:00
|
|
|
decoder.Flush();
|
2015-12-08 22:30:25 +03:00
|
|
|
decoder.ResetDemuxer();
|
2016-05-05 07:52:58 +03:00
|
|
|
decoder.mTimeThreshold = Some(aTarget);
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "seeking", DDNoValue{});
|
2016-05-05 07:52:58 +03:00
|
|
|
RefPtr<MediaFormatReader> self = this;
|
2017-01-11 11:33:29 +03:00
|
|
|
decoder.mTrackDemuxer->Seek(decoder.mTimeThreshold.ref().Time())
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
->Then(OwnerThread(), __func__,
|
|
|
|
[self, aTrack](TimeUnit aTime) {
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log, "seeked", DDNoValue{});
|
|
|
|
auto& decoder = self->GetDecoderData(aTrack);
|
|
|
|
decoder.mSeekRequest.Complete();
|
|
|
|
MOZ_ASSERT(decoder.mTimeThreshold,
|
|
|
|
"Seek promise must be disconnected when "
|
|
|
|
"timethreshold is reset");
|
|
|
|
decoder.mTimeThreshold.ref().mHasSeeked = true;
|
|
|
|
self->SetVideoDecodeThreshold();
|
|
|
|
self->ScheduleUpdate(aTrack);
|
|
|
|
},
|
|
|
|
[self, aTrack](const MediaResult& aError) {
|
|
|
|
auto& decoder = self->GetDecoderData(aTrack);
|
|
|
|
decoder.mSeekRequest.Complete();
|
|
|
|
switch (aError.Code()) {
|
|
|
|
case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log,
|
|
|
|
"seeking_interrupted", aError);
|
|
|
|
self->NotifyWaitingForData(aTrack);
|
|
|
|
break;
|
|
|
|
case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log,
|
|
|
|
"seeking_interrupted", aError);
|
|
|
|
decoder.mTimeThreshold.reset();
|
|
|
|
self->NotifyEndOfStream(aTrack);
|
|
|
|
break;
|
|
|
|
case NS_ERROR_DOM_MEDIA_CANCELED:
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log,
|
|
|
|
"seeking_interrupted", aError);
|
|
|
|
decoder.mTimeThreshold.reset();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log, "seeking_error",
|
|
|
|
aError);
|
|
|
|
decoder.mTimeThreshold.reset();
|
|
|
|
self->NotifyError(aTrack, aError);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
2017-01-11 11:33:29 +03:00
|
|
|
->Track(decoder.mSeekRequest);
|
2015-12-08 22:30:25 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 09:21:04 +03:00
|
|
|
void MediaFormatReader::DrainDecoder(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2017-02-09 17:31:44 +03:00
|
|
|
if (decoder.mDrainState == DrainState::Draining) {
|
2015-07-13 09:21:04 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-09-04 12:27:43 +03:00
|
|
|
if (!decoder.mDecoder ||
|
|
|
|
(decoder.mDrainState != DrainState::PartialDrainPending &&
|
|
|
|
decoder.mNumSamplesInput == decoder.mNumSamplesOutput)) {
|
2015-07-26 14:52:22 +03:00
|
|
|
// No frames to drain.
|
2017-01-26 15:56:46 +03:00
|
|
|
LOGV("Draining %s with nothing to drain", TrackTypeToStr(aTrack));
|
2017-02-09 17:31:44 +03:00
|
|
|
decoder.mDrainState = DrainState::DrainAborted;
|
|
|
|
ScheduleUpdate(aTrack);
|
2015-07-26 14:52:22 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-02-09 17:31:44 +03:00
|
|
|
|
|
|
|
decoder.mDrainState = DrainState::Draining;
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "draining", DDNoValue{});
|
2017-01-26 15:56:46 +03:00
|
|
|
RefPtr<MediaFormatReader> self = this;
|
|
|
|
decoder.mDecoder->Drain()
|
|
|
|
->Then(
|
|
|
|
mTaskQueue, __func__,
|
2018-11-09 18:45:31 +03:00
|
|
|
[self, aTrack, &decoder](MediaDataDecoder::DecodedData&& aResults) {
|
2017-01-26 15:56:46 +03:00
|
|
|
decoder.mDrainRequest.Complete();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log, "drained", DDNoValue{});
|
2017-02-07 17:36:20 +03:00
|
|
|
if (aResults.IsEmpty()) {
|
2017-02-09 17:31:44 +03:00
|
|
|
decoder.mDrainState = DrainState::DrainCompleted;
|
2017-02-07 17:36:20 +03:00
|
|
|
} else {
|
2018-11-09 18:45:31 +03:00
|
|
|
self->NotifyNewOutput(aTrack, std::move(aResults));
|
2017-02-07 17:36:20 +03:00
|
|
|
// Let's see if we have any more data available to drain.
|
2017-02-09 17:31:44 +03:00
|
|
|
decoder.mDrainState = DrainState::PartialDrainPending;
|
2017-02-07 17:36:20 +03:00
|
|
|
}
|
2017-10-26 11:59:40 +03:00
|
|
|
self->ScheduleUpdate(aTrack);
|
2017-01-26 15:56:46 +03:00
|
|
|
},
|
2017-10-26 11:59:40 +03:00
|
|
|
[self, aTrack, &decoder](const MediaResult& aError) {
|
2017-01-26 15:56:46 +03:00
|
|
|
decoder.mDrainRequest.Complete();
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOGEX(self.get(), DDLogCategory::Log, "draining_error", aError);
|
2017-10-26 11:59:40 +03:00
|
|
|
self->NotifyError(aTrack, aError);
|
2017-01-26 15:56:46 +03:00
|
|
|
})
|
|
|
|
->Track(decoder.mDrainRequest);
|
2015-07-13 09:21:04 +03:00
|
|
|
LOG("Requesting %s decoder to drain", TrackTypeToStr(aTrack));
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
void MediaFormatReader::Update(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2015-10-19 21:11:35 +03:00
|
|
|
if (mShutdown) {
|
2015-05-18 08:40:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-25 08:09:16 +03:00
|
|
|
LOGV("Processing update for %s", TrackTypeToStr(aTrack));
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
bool needOutput = false;
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2015-05-18 08:42:01 +03:00
|
|
|
decoder.mUpdateScheduled = false;
|
2017-11-03 15:12:39 +03:00
|
|
|
|
2015-10-19 21:11:35 +03:00
|
|
|
if (!mInitDone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-26 06:59:46 +03:00
|
|
|
if (aTrack == TrackType::kVideoTrack && mSkipRequest.Exists()) {
|
|
|
|
LOGV("Skipping in progress, nothing more to do");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:42:01 +03:00
|
|
|
if (UpdateReceivedNewData(aTrack)) {
|
2015-05-25 08:09:16 +03:00
|
|
|
LOGV("Nothing more to do");
|
2015-05-18 08:42:01 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-05-05 07:52:58 +03:00
|
|
|
if (decoder.mSeekRequest.Exists()) {
|
|
|
|
LOGV("Seeking hasn't completed, nothing more to do");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
2017-09-04 12:27:43 +03:00
|
|
|
!decoder.HasInternalSeekPending() ||
|
|
|
|
(!decoder.mOutput.Length() && !decoder.mQueuedSamples.Length()),
|
2017-01-27 15:20:37 +03:00
|
|
|
"No frames can be demuxed or decoded while an internal seek is pending");
|
2016-05-05 07:52:58 +03:00
|
|
|
|
2015-05-25 08:09:16 +03:00
|
|
|
// Record number of frames decoded and parsed. Automatically update the
|
|
|
|
// stats counters using the AutoNotifyDecoded stack-based class.
|
2017-07-13 10:17:25 +03:00
|
|
|
FrameStatistics::AutoNotifyDecoded a(mFrameStats);
|
2015-05-25 08:09:16 +03:00
|
|
|
|
2015-12-18 01:37:03 +03:00
|
|
|
// Drop any frames found prior our internal seek target.
|
|
|
|
while (decoder.mTimeThreshold && decoder.mOutput.Length()) {
|
|
|
|
RefPtr<MediaData>& output = decoder.mOutput[0];
|
2016-02-01 07:05:25 +03:00
|
|
|
InternalSeekTarget target = decoder.mTimeThreshold.ref();
|
2017-04-17 11:35:04 +03:00
|
|
|
auto time = output->mTime;
|
2016-05-18 06:48:05 +03:00
|
|
|
if (time >= target.Time()) {
|
2015-12-18 01:37:03 +03:00
|
|
|
// We have reached our internal seek target.
|
|
|
|
decoder.mTimeThreshold.reset();
|
2016-07-26 02:36:55 +03:00
|
|
|
// We might have dropped some keyframes.
|
|
|
|
mPreviousDecodedKeyframeTime_us = sNoPreviousDecodedKeyframe;
|
2015-12-18 01:37:03 +03:00
|
|
|
}
|
2016-05-18 06:48:05 +03:00
|
|
|
if (time < target.Time() || (target.mDropTarget && target.Contains(time))) {
|
2015-12-18 01:37:03 +03:00
|
|
|
LOGV("Internal Seeking: Dropping %s frame time:%f wanted:%f (kf:%d)",
|
2017-04-14 12:13:36 +03:00
|
|
|
TrackTypeToStr(aTrack), output->mTime.ToSeconds(),
|
2016-05-18 06:48:05 +03:00
|
|
|
target.Time().ToSeconds(), output->mKeyframe);
|
2015-12-18 01:37:03 +03:00
|
|
|
decoder.mOutput.RemoveElementAt(0);
|
2016-05-19 12:03:39 +03:00
|
|
|
decoder.mSizeOfQueue -= 1;
|
2015-12-18 01:37:03 +03:00
|
|
|
}
|
2015-05-18 08:42:01 +03:00
|
|
|
}
|
2015-07-13 09:21:04 +03:00
|
|
|
|
2017-09-04 12:27:43 +03:00
|
|
|
while (decoder.mOutput.Length() &&
|
2019-02-22 12:18:18 +03:00
|
|
|
decoder.mOutput[0]->mType == MediaData::Type::NULL_DATA) {
|
2017-04-14 12:13:36 +03:00
|
|
|
LOGV("Dropping null data. Time: %" PRId64,
|
|
|
|
decoder.mOutput[0]->mTime.ToMicroseconds());
|
2016-06-08 05:59:57 +03:00
|
|
|
decoder.mOutput.RemoveElementAt(0);
|
|
|
|
decoder.mSizeOfQueue -= 1;
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:42:01 +03:00
|
|
|
if (decoder.HasPromise()) {
|
|
|
|
needOutput = true;
|
2015-12-18 01:37:03 +03:00
|
|
|
if (decoder.mOutput.Length()) {
|
2016-05-19 12:03:39 +03:00
|
|
|
RefPtr<MediaData> output = decoder.mOutput[0];
|
|
|
|
decoder.mOutput.RemoveElementAt(0);
|
|
|
|
decoder.mSizeOfQueue -= 1;
|
2017-05-11 11:29:57 +03:00
|
|
|
decoder.mLastDecodedSampleTime =
|
2017-04-14 12:13:36 +03:00
|
|
|
Some(TimeInterval(output->mTime, output->GetEndTime()));
|
2016-05-19 12:03:39 +03:00
|
|
|
decoder.mNumSamplesOutputTotal++;
|
|
|
|
ReturnOutput(output, aTrack);
|
2015-05-18 08:42:01 +03:00
|
|
|
// We have a decoded sample ready to be returned.
|
2015-07-20 22:14:37 +03:00
|
|
|
if (aTrack == TrackType::kVideoTrack) {
|
2015-12-18 01:37:03 +03:00
|
|
|
uint64_t delta =
|
|
|
|
decoder.mNumSamplesOutputTotal - mLastReportedNumDecodedFrames;
|
2016-07-18 03:41:40 +03:00
|
|
|
a.mStats.mDecodedFrames = static_cast<uint32_t>(delta);
|
2015-12-18 01:37:03 +03:00
|
|
|
mLastReportedNumDecodedFrames = decoder.mNumSamplesOutputTotal;
|
2016-07-26 02:36:55 +03:00
|
|
|
if (output->mKeyframe) {
|
2017-04-14 12:13:36 +03:00
|
|
|
if (mPreviousDecodedKeyframeTime_us <
|
|
|
|
output->mTime.ToMicroseconds()) {
|
2016-07-26 02:36:55 +03:00
|
|
|
// There is a previous keyframe -> Record inter-keyframe stats.
|
2017-04-14 12:13:36 +03:00
|
|
|
uint64_t segment_us = output->mTime.ToMicroseconds() -
|
|
|
|
mPreviousDecodedKeyframeTime_us;
|
2016-07-26 02:36:55 +03:00
|
|
|
a.mStats.mInterKeyframeSum_us += segment_us;
|
|
|
|
a.mStats.mInterKeyframeCount += 1;
|
|
|
|
if (a.mStats.mInterKeyFrameMax_us < segment_us) {
|
|
|
|
a.mStats.mInterKeyFrameMax_us = segment_us;
|
|
|
|
}
|
|
|
|
}
|
2017-04-14 12:13:36 +03:00
|
|
|
mPreviousDecodedKeyframeTime_us = output->mTime.ToMicroseconds();
|
2016-07-26 02:36:55 +03:00
|
|
|
}
|
2015-07-13 23:12:23 +03:00
|
|
|
nsCString error;
|
2015-07-20 22:14:37 +03:00
|
|
|
mVideo.mIsHardwareAccelerated =
|
2015-07-13 23:12:23 +03:00
|
|
|
mVideo.mDecoder && mVideo.mDecoder->IsHardwareAccelerated(error);
|
2017-06-16 23:43:51 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// D3D11_YCBCR_IMAGE images are GPU based, we try to limit the amount
|
|
|
|
// of GPU RAM used.
|
|
|
|
VideoData* videoData = static_cast<VideoData*>(output.get());
|
|
|
|
mVideo.mIsHardwareAccelerated =
|
|
|
|
mVideo.mIsHardwareAccelerated ||
|
|
|
|
(videoData->mImage &&
|
|
|
|
videoData->mImage->GetFormat() == ImageFormat::D3D11_YCBCR_IMAGE);
|
|
|
|
#endif
|
2015-07-20 22:14:37 +03:00
|
|
|
}
|
2016-05-30 19:24:00 +03:00
|
|
|
} else if (decoder.HasFatalError()) {
|
2015-12-18 01:37:03 +03:00
|
|
|
LOG("Rejecting %s promise: DECODE_ERROR", TrackTypeToStr(aTrack));
|
2016-09-10 09:48:53 +03:00
|
|
|
decoder.RejectPromise(decoder.mError.ref(), __func__);
|
2015-12-08 22:30:25 +03:00
|
|
|
return;
|
2017-03-07 12:13:39 +03:00
|
|
|
} else if (decoder.HasCompletedDrain()) {
|
2015-12-08 22:30:25 +03:00
|
|
|
if (decoder.mDemuxEOS) {
|
2015-12-18 01:37:03 +03:00
|
|
|
LOG("Rejecting %s promise: EOS", TrackTypeToStr(aTrack));
|
2016-09-10 09:48:53 +03:00
|
|
|
decoder.RejectPromise(NS_ERROR_DOM_MEDIA_END_OF_STREAM, __func__);
|
2015-12-08 22:30:25 +03:00
|
|
|
} else if (decoder.mWaitingForData) {
|
2017-09-04 12:27:43 +03:00
|
|
|
if (decoder.mDrainState == DrainState::DrainCompleted &&
|
|
|
|
decoder.mLastDecodedSampleTime && !decoder.mNextStreamSourceID) {
|
2015-12-08 22:30:25 +03:00
|
|
|
// We have completed draining the decoder following WaitingForData.
|
|
|
|
// Set up the internal seek machinery to be able to resume from the
|
|
|
|
// last sample decoded.
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG("Seeking to last sample time: %" PRId64,
|
2017-05-11 11:29:57 +03:00
|
|
|
decoder.mLastDecodedSampleTime.ref().mStart.ToMicroseconds());
|
2017-01-27 15:20:37 +03:00
|
|
|
InternalSeek(aTrack, InternalSeekTarget(
|
2017-05-11 11:29:57 +03:00
|
|
|
decoder.mLastDecodedSampleTime.ref(), true));
|
2015-12-08 22:30:25 +03:00
|
|
|
}
|
2016-02-08 16:36:47 +03:00
|
|
|
if (!decoder.mReceivedNewData) {
|
|
|
|
LOG("Rejecting %s promise: WAITING_FOR_DATA", TrackTypeToStr(aTrack));
|
2016-09-10 09:48:53 +03:00
|
|
|
decoder.RejectPromise(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA, __func__);
|
2016-02-08 16:36:47 +03:00
|
|
|
}
|
2015-12-08 22:30:25 +03:00
|
|
|
}
|
2017-02-09 17:31:44 +03:00
|
|
|
|
|
|
|
decoder.mDrainState = DrainState::None;
|
|
|
|
|
2015-12-08 22:30:25 +03:00
|
|
|
// Now that draining has completed, we check if we have received
|
|
|
|
// new data again as the result may now be different from the earlier
|
|
|
|
// run.
|
2016-05-05 07:52:58 +03:00
|
|
|
if (UpdateReceivedNewData(aTrack) || decoder.mSeekRequest.Exists()) {
|
2015-12-08 22:30:25 +03:00
|
|
|
LOGV("Nothing more to do");
|
|
|
|
return;
|
2015-07-13 09:21:04 +03:00
|
|
|
}
|
2017-09-04 12:27:43 +03:00
|
|
|
} else if (decoder.mDemuxEOS && !decoder.HasPendingDrain() &&
|
|
|
|
decoder.mQueuedSamples.IsEmpty()) {
|
2016-05-24 12:58:36 +03:00
|
|
|
// It is possible to transition from WAITING_FOR_DATA directly to EOS
|
|
|
|
// state during the internal seek; in which case no draining would occur.
|
|
|
|
// There is no more samples left to be decoded and we are already in
|
|
|
|
// EOS state. We can immediately reject the data promise.
|
|
|
|
LOG("Rejecting %s promise: EOS", TrackTypeToStr(aTrack));
|
2016-09-10 09:48:53 +03:00
|
|
|
decoder.RejectPromise(NS_ERROR_DOM_MEDIA_END_OF_STREAM, __func__);
|
2017-01-27 13:48:00 +03:00
|
|
|
} else if (decoder.mWaitingForKey) {
|
|
|
|
LOG("Rejecting %s promise: WAITING_FOR_DATA due to waiting for key",
|
|
|
|
TrackTypeToStr(aTrack));
|
|
|
|
decoder.RejectPromise(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA, __func__);
|
2017-11-03 15:14:49 +03:00
|
|
|
} else if (IsDecoderWaitingForCDM(aTrack)) {
|
|
|
|
// Rejecting the promise could lead to entering buffering state for MDSM,
|
|
|
|
// once a qualified(with the same key system and sessions created by the
|
|
|
|
// same InitData) new cdm proxy is set, decoding can be resumed.
|
|
|
|
LOG("Rejecting %s promise: WAITING_FOR_DATA due to waiting for CDM",
|
|
|
|
TrackTypeToStr(aTrack));
|
|
|
|
decoder.RejectPromise(NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-04 12:27:43 +03:00
|
|
|
if (decoder.mDrainState == DrainState::DrainRequested ||
|
|
|
|
decoder.mDrainState == DrainState::PartialDrainPending) {
|
2017-02-11 01:46:58 +03:00
|
|
|
if (decoder.mOutput.IsEmpty()) {
|
|
|
|
DrainDecoder(aTrack);
|
|
|
|
}
|
2015-05-25 08:09:16 +03:00
|
|
|
return;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-09-10 03:49:54 +03:00
|
|
|
if (decoder.mError && !decoder.HasFatalError()) {
|
2017-05-12 15:16:33 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!decoder.HasInternalSeekPending(),
|
|
|
|
"No error can occur while an internal seek is pending");
|
2018-10-04 12:43:24 +03:00
|
|
|
|
|
|
|
nsCString error;
|
|
|
|
bool firstFrameDecodingFailedWithHardware =
|
|
|
|
decoder.mFirstFrameTime &&
|
|
|
|
decoder.mError.ref() == NS_ERROR_DOM_MEDIA_DECODE_ERR &&
|
|
|
|
decoder.mDecoder && decoder.mDecoder->IsHardwareAccelerated(error) &&
|
|
|
|
!decoder.mHardwareDecodingDisabled;
|
2017-01-27 15:20:37 +03:00
|
|
|
bool needsNewDecoder =
|
2018-10-04 12:43:24 +03:00
|
|
|
decoder.mError.ref() == NS_ERROR_DOM_MEDIA_NEED_NEW_DECODER ||
|
|
|
|
firstFrameDecodingFailedWithHardware;
|
2017-09-04 12:27:43 +03:00
|
|
|
if (!needsNewDecoder &&
|
|
|
|
++decoder.mNumOfConsecutiveError > decoder.mMaxConsecutiveError) {
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "too_many_decode_errors", decoder.mError.ref());
|
2016-09-13 06:03:21 +03:00
|
|
|
NotifyError(aTrack, decoder.mError.ref());
|
2016-05-30 19:24:00 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-10-04 12:43:24 +03:00
|
|
|
if (firstFrameDecodingFailedWithHardware) {
|
|
|
|
decoder.mHardwareDecodingDisabled = true;
|
|
|
|
}
|
2016-09-13 06:03:21 +03:00
|
|
|
decoder.mError.reset();
|
2017-05-11 11:29:57 +03:00
|
|
|
|
2016-05-30 19:24:00 +03:00
|
|
|
LOG("%s decoded error count %d", TrackTypeToStr(aTrack),
|
2017-05-11 11:31:23 +03:00
|
|
|
decoder.mNumOfConsecutiveError);
|
2017-05-11 11:29:57 +03:00
|
|
|
|
|
|
|
if (needsNewDecoder) {
|
|
|
|
LOG("Error: Need new decoder");
|
|
|
|
ShutdownDecoder(aTrack);
|
|
|
|
}
|
|
|
|
if (decoder.mFirstFrameTime) {
|
|
|
|
TimeInterval seekInterval = TimeInterval(decoder.mFirstFrameTime.ref(),
|
|
|
|
decoder.mFirstFrameTime.ref());
|
|
|
|
InternalSeek(aTrack, InternalSeekTarget(seekInterval, false));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
TimeUnit nextKeyframe;
|
2017-05-12 15:16:33 +03:00
|
|
|
if (aTrack == TrackType::kVideoTrack &&
|
|
|
|
NS_SUCCEEDED(
|
2017-05-12 15:18:26 +03:00
|
|
|
decoder.mTrackDemuxer->GetNextRandomAccessPoint(&nextKeyframe)) &&
|
|
|
|
!nextKeyframe.IsInfinite()) {
|
2017-01-27 15:20:37 +03:00
|
|
|
SkipVideoDemuxToNextKeyFrame(
|
2017-05-11 11:29:57 +03:00
|
|
|
decoder.mLastDecodedSampleTime.refOr(TimeInterval()).Length());
|
2016-10-26 00:48:47 +03:00
|
|
|
} else if (aTrack == TrackType::kAudioTrack) {
|
|
|
|
decoder.Flush();
|
2017-05-11 11:31:23 +03:00
|
|
|
} else {
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "no_keyframe", NS_ERROR_DOM_MEDIA_FATAL_ERR);
|
2017-05-11 11:31:23 +03:00
|
|
|
// We can't recover from this error.
|
|
|
|
NotifyError(aTrack, NS_ERROR_DOM_MEDIA_FATAL_ERR);
|
2016-05-30 19:24:00 +03:00
|
|
|
}
|
2017-01-26 15:56:46 +03:00
|
|
|
return;
|
2016-05-30 19:24:00 +03:00
|
|
|
}
|
|
|
|
|
2015-12-08 22:30:25 +03:00
|
|
|
bool needInput = NeedInput(decoder);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-05-29 11:41:36 +03:00
|
|
|
LOGV("Update(%s) ni=%d no=%d in:%" PRIu64 " out:%" PRIu64
|
|
|
|
" qs=%u decoding:%d flushing:%d desc:%s pending:%u waiting:%d eos:%d "
|
2017-11-03 15:14:49 +03:00
|
|
|
"ds:%d sid:%u waitcdm:%d",
|
2017-05-29 11:41:36 +03:00
|
|
|
TrackTypeToStr(aTrack), needInput, needOutput, decoder.mNumSamplesInput,
|
|
|
|
decoder.mNumSamplesOutput, uint32_t(size_t(decoder.mSizeOfQueue)),
|
|
|
|
decoder.mDecodeRequest.Exists(), decoder.mFlushing,
|
|
|
|
decoder.mDescription.get(), uint32_t(decoder.mOutput.Length()),
|
|
|
|
decoder.mWaitingForData, decoder.mDemuxEOS, int32_t(decoder.mDrainState),
|
2017-11-03 15:14:49 +03:00
|
|
|
decoder.mLastStreamSourceID, IsDecoderWaitingForCDM(aTrack));
|
2015-12-08 22:30:25 +03:00
|
|
|
|
2017-11-03 15:14:49 +03:00
|
|
|
if (IsWaitingOnCDMResource() || !ResolveSetCDMPromiseIfDone(aTrack)) {
|
2017-08-25 12:11:14 +03:00
|
|
|
// If the content is encrypted, MFR won't start to create decoder until
|
|
|
|
// CDMProxy is set.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-14 10:20:08 +03:00
|
|
|
if ((decoder.IsWaitingForData() &&
|
2017-09-04 12:27:43 +03:00
|
|
|
(!decoder.mTimeThreshold || decoder.mTimeThreshold.ref().mWaiting)) ||
|
2017-11-14 10:20:08 +03:00
|
|
|
(decoder.IsWaitingForKey())) {
|
2015-12-08 22:30:25 +03:00
|
|
|
// Nothing more we can do at present.
|
2017-11-03 15:14:49 +03:00
|
|
|
LOGV("Still waiting for data or key. data(%d)/key(%d)",
|
|
|
|
decoder.mWaitingForData, decoder.mWaitingForKey);
|
2015-12-08 22:30:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-23 16:10:12 +03:00
|
|
|
if (decoder.CancelWaitingForKey()) {
|
|
|
|
LOGV("No longer waiting for key. Resolving waiting promise");
|
|
|
|
return;
|
2017-01-27 13:48:00 +03:00
|
|
|
}
|
|
|
|
|
2015-12-08 22:30:25 +03:00
|
|
|
if (!needInput) {
|
|
|
|
LOGV("No need for additional input (pending:%u)",
|
|
|
|
uint32_t(decoder.mOutput.Length()));
|
|
|
|
return;
|
|
|
|
}
|
2015-05-25 08:09:16 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
// Demux samples if we don't have some.
|
|
|
|
RequestDemuxSamples(aTrack);
|
2015-10-20 12:33:00 +03:00
|
|
|
|
|
|
|
HandleDemuxedSamples(aTrack, a);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::ReturnOutput(MediaData* aData, TrackType aTrack) {
|
2016-08-25 13:18:22 +03:00
|
|
|
MOZ_ASSERT(GetDecoderData(aTrack).HasPromise());
|
2019-02-22 12:18:18 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aData->mType != MediaData::Type::NULL_DATA);
|
2017-09-04 12:27:43 +03:00
|
|
|
LOG("Resolved data promise for %s [%" PRId64 ", %" PRId64 "]",
|
|
|
|
TrackTypeToStr(aTrack), aData->mTime.ToMicroseconds(),
|
|
|
|
aData->GetEndTime().ToMicroseconds());
|
2016-05-06 08:56:47 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
if (aTrack == TrackInfo::kAudioTrack) {
|
2016-11-17 10:23:07 +03:00
|
|
|
AudioData* audioData = static_cast<AudioData*>(aData);
|
|
|
|
|
2017-09-04 12:27:43 +03:00
|
|
|
if (audioData->mChannels != mInfo.mAudio.mChannels ||
|
|
|
|
audioData->mRate != mInfo.mAudio.mRate) {
|
2016-11-17 10:23:07 +03:00
|
|
|
LOG("change of audio format (rate:%d->%d). "
|
|
|
|
"This is an unsupported configuration",
|
2017-09-04 12:27:43 +03:00
|
|
|
mInfo.mAudio.mRate, audioData->mRate);
|
2016-11-17 10:23:07 +03:00
|
|
|
mInfo.mAudio.mRate = audioData->mRate;
|
|
|
|
mInfo.mAudio.mChannels = audioData->mChannels;
|
2018-10-03 11:23:08 +03:00
|
|
|
MutexAutoLock lock(mAudio.mMutex);
|
|
|
|
mAudio.mWorkingInfo->GetAsAudioInfo()->mRate = audioData->mRate;
|
|
|
|
mAudio.mWorkingInfo->GetAsAudioInfo()->mChannels = audioData->mChannels;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2017-03-22 06:28:33 +03:00
|
|
|
mAudio.ResolvePromise(audioData, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
} else if (aTrack == TrackInfo::kVideoTrack) {
|
2016-11-17 10:23:07 +03:00
|
|
|
VideoData* videoData = static_cast<VideoData*>(aData);
|
|
|
|
|
|
|
|
if (videoData->mDisplay != mInfo.mVideo.mDisplay) {
|
|
|
|
LOG("change of video display size (%dx%d->%dx%d)",
|
|
|
|
mInfo.mVideo.mDisplay.width, mInfo.mVideo.mDisplay.height,
|
|
|
|
videoData->mDisplay.width, videoData->mDisplay.height);
|
|
|
|
mInfo.mVideo.mDisplay = videoData->mDisplay;
|
2018-10-03 11:23:08 +03:00
|
|
|
MutexAutoLock lock(mVideo.mMutex);
|
|
|
|
mVideo.mWorkingInfo->GetAsVideoInfo()->mDisplay = videoData->mDisplay;
|
2016-01-12 13:03:13 +03:00
|
|
|
}
|
2017-07-11 05:15:33 +03:00
|
|
|
|
|
|
|
TimeUnit nextKeyframe;
|
|
|
|
if (!mVideo.HasInternalSeekPending() &&
|
2017-09-04 12:27:43 +03:00
|
|
|
NS_SUCCEEDED(
|
|
|
|
mVideo.mTrackDemuxer->GetNextRandomAccessPoint(&nextKeyframe))) {
|
2017-07-11 05:15:33 +03:00
|
|
|
videoData->SetNextKeyFrameTime(nextKeyframe);
|
|
|
|
}
|
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
mVideo.ResolvePromise(videoData, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MediaFormatReader::SizeOfVideoQueueInFrames() {
|
|
|
|
return SizeOfQueue(TrackInfo::kVideoTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MediaFormatReader::SizeOfAudioQueueInFrames() {
|
|
|
|
return SizeOfQueue(TrackInfo::kAudioTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t MediaFormatReader::SizeOfQueue(TrackType aTrack) {
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2015-05-18 08:42:01 +03:00
|
|
|
return decoder.mSizeOfQueue;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
RefPtr<MediaFormatReader::WaitForDataPromise> MediaFormatReader::WaitForData(
|
2015-05-18 08:40:32 +03:00
|
|
|
MediaData::Type aType) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2019-02-22 12:18:18 +03:00
|
|
|
TrackType trackType = aType == MediaData::Type::VIDEO_DATA
|
|
|
|
? TrackType::kVideoTrack
|
|
|
|
: TrackType::kAudioTrack;
|
2015-05-18 08:40:32 +03:00
|
|
|
auto& decoder = GetDecoderData(trackType);
|
2017-11-14 10:20:08 +03:00
|
|
|
if (!decoder.IsWaitingForData() && !decoder.IsWaitingForKey()) {
|
2016-10-27 12:25:21 +03:00
|
|
|
// We aren't waiting for anything.
|
2015-07-20 09:05:16 +03:00
|
|
|
return WaitForDataPromise::CreateAndResolve(decoder.mType, __func__);
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WaitForDataPromise> p = decoder.mWaitingPromise.Ensure(__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
ScheduleUpdate(trackType);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-05-31 07:32:37 +03:00
|
|
|
nsresult MediaFormatReader::ResetDecode(TrackSet aTracks) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2015-05-25 08:09:16 +03:00
|
|
|
LOGV("");
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
mSeekPromise.RejectIfExists(NS_OK, __func__);
|
|
|
|
mSkipRequest.DisconnectIfExists();
|
|
|
|
|
|
|
|
// Do the same for any data wait promises.
|
2016-05-31 07:32:37 +03:00
|
|
|
if (aTracks.contains(TrackInfo::kAudioTrack)) {
|
|
|
|
mAudio.mWaitingPromise.RejectIfExists(
|
2019-02-22 12:18:18 +03:00
|
|
|
WaitForDataRejectValue(MediaData::Type::AUDIO_DATA,
|
2016-05-31 07:32:37 +03:00
|
|
|
WaitForDataRejectValue::CANCELED),
|
|
|
|
__func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTracks.contains(TrackInfo::kVideoTrack)) {
|
|
|
|
mVideo.mWaitingPromise.RejectIfExists(
|
2019-02-22 12:18:18 +03:00
|
|
|
WaitForDataRejectValue(MediaData::Type::VIDEO_DATA,
|
2016-05-31 07:32:37 +03:00
|
|
|
WaitForDataRejectValue::CANCELED),
|
|
|
|
__func__);
|
2016-05-16 09:50:04 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
// Reset miscellaneous seeking state.
|
|
|
|
mPendingSeekTime.reset();
|
|
|
|
|
2016-05-31 07:32:37 +03:00
|
|
|
if (HasVideo() && aTracks.contains(TrackInfo::kVideoTrack)) {
|
2016-05-13 04:14:12 +03:00
|
|
|
mVideo.ResetDemuxer();
|
2017-05-11 11:29:57 +03:00
|
|
|
mVideo.mFirstFrameTime = Some(media::TimeUnit::Zero());
|
2016-05-05 08:06:40 +03:00
|
|
|
Reset(TrackInfo::kVideoTrack);
|
2015-06-15 03:58:12 +03:00
|
|
|
if (mVideo.HasPromise()) {
|
2016-09-10 09:48:53 +03:00
|
|
|
mVideo.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2015-06-15 03:58:12 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2016-04-18 09:33:52 +03:00
|
|
|
|
2016-05-31 07:32:37 +03:00
|
|
|
if (HasAudio() && aTracks.contains(TrackInfo::kAudioTrack)) {
|
2016-05-13 04:14:12 +03:00
|
|
|
mAudio.ResetDemuxer();
|
2017-05-11 11:29:57 +03:00
|
|
|
mVideo.mFirstFrameTime = Some(media::TimeUnit::Zero());
|
2016-05-05 08:06:40 +03:00
|
|
|
Reset(TrackInfo::kAudioTrack);
|
2015-06-15 03:58:12 +03:00
|
|
|
if (mAudio.HasPromise()) {
|
2016-09-10 09:48:53 +03:00
|
|
|
mAudio.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
|
2015-06-15 03:58:12 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2016-05-31 07:32:37 +03:00
|
|
|
|
2017-07-19 10:15:14 +03:00
|
|
|
return NS_OK;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-05-05 08:06:40 +03:00
|
|
|
void MediaFormatReader::Reset(TrackType aTrack) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-05-05 08:06:40 +03:00
|
|
|
LOG("Reset(%s) BEGIN", TrackTypeToStr(aTrack));
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
|
|
|
|
decoder.ResetState();
|
2016-05-05 08:06:40 +03:00
|
|
|
decoder.Flush();
|
|
|
|
|
|
|
|
LOG("Reset(%s) END", TrackTypeToStr(aTrack));
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-05-26 07:58:48 +03:00
|
|
|
void MediaFormatReader::DropDecodedSamples(TrackType aTrack) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
|
|
|
size_t lengthDecodedQueue = decoder.mOutput.Length();
|
|
|
|
if (lengthDecodedQueue && decoder.mTimeThreshold.isSome()) {
|
2017-04-17 11:35:04 +03:00
|
|
|
auto time = decoder.mOutput.LastElement()->mTime;
|
2016-05-26 07:58:48 +03:00
|
|
|
if (time >= decoder.mTimeThreshold.ref().Time()) {
|
|
|
|
// We would have reached our internal seek target.
|
|
|
|
decoder.mTimeThreshold.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
decoder.mOutput.Clear();
|
|
|
|
decoder.mSizeOfQueue -= lengthDecodedQueue;
|
2017-07-13 09:12:25 +03:00
|
|
|
if (aTrack == TrackInfo::kVideoTrack && mFrameStats) {
|
2018-08-27 13:27:19 +03:00
|
|
|
mFrameStats->Accumulate({0, 0, lengthDecodedQueue, 0});
|
2016-05-26 07:58:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
void MediaFormatReader::SkipVideoDemuxToNextKeyFrame(TimeUnit aTimeThreshold) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG("Skipping up to %" PRId64, aTimeThreshold.ToMicroseconds());
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-05-26 07:58:48 +03:00
|
|
|
// We've reached SkipVideoDemuxToNextKeyFrame when our decoding is late.
|
|
|
|
// As such we can drop all already decoded samples and discard all pending
|
|
|
|
// samples.
|
|
|
|
DropDecodedSamples(TrackInfo::kVideoTrack);
|
|
|
|
|
2017-01-11 11:33:29 +03:00
|
|
|
mVideo.mTrackDemuxer->SkipToNextRandomAccessPoint(aTimeThreshold)
|
|
|
|
->Then(OwnerThread(), __func__, this,
|
|
|
|
&MediaFormatReader::OnVideoSkipCompleted,
|
|
|
|
&MediaFormatReader::OnVideoSkipFailed)
|
|
|
|
->Track(mSkipRequest);
|
2016-05-19 10:02:43 +03:00
|
|
|
}
|
2016-05-06 08:58:51 +03:00
|
|
|
|
2016-05-19 10:02:43 +03:00
|
|
|
void MediaFormatReader::VideoSkipReset(uint32_t aSkipped) {
|
2019-02-28 23:10:17 +03:00
|
|
|
PROFILER_ADD_MARKER("SkippedVideoDecode", GRAPHICS);
|
2016-05-19 10:02:43 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-05-26 07:58:48 +03:00
|
|
|
|
|
|
|
// Some frames may have been output by the decoder since we initiated the
|
|
|
|
// videoskip process and we know they would be late.
|
|
|
|
DropDecodedSamples(TrackInfo::kVideoTrack);
|
|
|
|
// Report the pending frames as dropped.
|
2017-07-13 09:12:25 +03:00
|
|
|
if (mFrameStats) {
|
2018-08-27 13:27:19 +03:00
|
|
|
mFrameStats->Accumulate({0, 0, SizeOfVideoQueueInFrames(), 0});
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-05-19 10:02:43 +03:00
|
|
|
// Cancel any pending demux request and pending demuxed samples.
|
|
|
|
mVideo.mDemuxRequest.DisconnectIfExists();
|
|
|
|
Reset(TrackType::kVideoTrack);
|
|
|
|
|
2017-07-13 09:12:25 +03:00
|
|
|
if (mFrameStats) {
|
2018-08-27 13:27:19 +03:00
|
|
|
mFrameStats->Accumulate({aSkipped, 0, aSkipped, 0});
|
2016-05-07 04:23:32 +03:00
|
|
|
}
|
|
|
|
|
2016-05-19 10:02:43 +03:00
|
|
|
mVideo.mNumSamplesSkippedTotal += aSkipped;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::OnVideoSkipCompleted(uint32_t aSkipped) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
LOG("Skipping succeeded, skipped %u frames", aSkipped);
|
|
|
|
mSkipRequest.Complete();
|
2016-05-19 10:02:43 +03:00
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "video_skipped", DDNoValue());
|
|
|
|
|
2016-05-19 10:02:43 +03:00
|
|
|
VideoSkipReset(aSkipped);
|
|
|
|
|
2016-09-01 12:25:54 +03:00
|
|
|
ScheduleUpdate(TrackInfo::kVideoTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::OnVideoSkipFailed(
|
|
|
|
MediaTrackDemuxer::SkipFailureHolder aFailure) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
LOG("Skipping failed, skipped %u frames", aFailure.mSkipped);
|
|
|
|
mSkipRequest.Complete();
|
2016-05-19 10:02:43 +03:00
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
switch (aFailure.mFailure.Code()) {
|
|
|
|
case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
|
|
|
|
case NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "video_skipping_interruption",
|
|
|
|
aFailure.mFailure);
|
2016-05-26 07:58:48 +03:00
|
|
|
// Some frames may have been output by the decoder since we initiated the
|
|
|
|
// videoskip process and we know they would be late.
|
|
|
|
DropDecodedSamples(TrackInfo::kVideoTrack);
|
2016-05-19 10:02:43 +03:00
|
|
|
// We can't complete the skip operation, will just service a video frame
|
|
|
|
// normally.
|
2016-09-01 12:25:54 +03:00
|
|
|
ScheduleUpdate(TrackInfo::kVideoTrack);
|
2015-06-15 03:58:12 +03:00
|
|
|
break;
|
2016-09-12 05:22:20 +03:00
|
|
|
case NS_ERROR_DOM_MEDIA_CANCELED:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "video_skipping_interruption",
|
|
|
|
aFailure.mFailure);
|
2015-08-25 14:35:15 +03:00
|
|
|
if (mVideo.HasPromise()) {
|
2016-09-12 05:22:20 +03:00
|
|
|
mVideo.RejectPromise(aFailure.mFailure, __func__);
|
2015-08-25 14:35:15 +03:00
|
|
|
}
|
2015-06-15 03:58:12 +03:00
|
|
|
break;
|
|
|
|
default:
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLOG(DDLogCategory::Log, "video_skipping_error", aFailure.mFailure);
|
2016-09-12 05:22:20 +03:00
|
|
|
NotifyError(TrackType::kVideoTrack, aFailure.mFailure);
|
2015-06-15 03:58:12 +03:00
|
|
|
break;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 12:34:05 +03:00
|
|
|
RefPtr<MediaFormatReader::SeekPromise> MediaFormatReader::Seek(
|
2016-11-29 17:42:50 +03:00
|
|
|
const SeekTarget& aTarget) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG("aTarget=(%" PRId64 ")", aTarget.GetTime().ToMicroseconds());
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mSeekPromise.IsEmpty());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mVideo.HasPromise());
|
2016-05-13 09:35:43 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aTarget.IsVideoOnly() || !mAudio.HasPromise());
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPendingSeekTime.isNothing());
|
2015-06-15 03:58:12 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mVideo.mTimeThreshold.isNothing());
|
2017-09-04 12:27:43 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aTarget.IsVideoOnly() ||
|
|
|
|
mAudio.mTimeThreshold.isNothing());
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-02-04 07:31:21 +03:00
|
|
|
if (!mInfo.mMediaSeekable && !mInfo.mMediaSeekableOnlyInBufferedRanges) {
|
2015-05-18 08:40:32 +03:00
|
|
|
LOG("Seek() END (Unseekable)");
|
|
|
|
return SeekPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
return SeekPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
|
|
|
|
}
|
|
|
|
|
2016-11-13 09:42:19 +03:00
|
|
|
SetSeekTarget(aTarget);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SeekPromise> p = mSeekPromise.Ensure(__func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2016-05-05 08:01:51 +03:00
|
|
|
ScheduleSeek();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-05-16 13:15:17 +03:00
|
|
|
void MediaFormatReader::SetSeekTarget(const SeekTarget& aTarget) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2016-10-16 17:15:29 +03:00
|
|
|
mOriginalSeekTarget = aTarget;
|
|
|
|
mFallbackSeekTime = mPendingSeekTime = Some(aTarget.GetTime());
|
2016-10-29 04:47:49 +03:00
|
|
|
}
|
|
|
|
|
2016-05-05 08:01:51 +03:00
|
|
|
void MediaFormatReader::ScheduleSeek() {
|
|
|
|
if (mSeekScheduled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mSeekScheduled = true;
|
2017-11-15 09:58:03 +03:00
|
|
|
nsresult rv = OwnerThread()->Dispatch(NewRunnableMethod(
|
|
|
|
"MediaFormatReader::AttemptSeek", this, &MediaFormatReader::AttemptSeek));
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
2017-12-21 07:12:42 +03:00
|
|
|
Unused << rv;
|
2016-05-05 08:01:51 +03:00
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
void MediaFormatReader::AttemptSeek() {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-05-05 08:01:51 +03:00
|
|
|
|
|
|
|
mSeekScheduled = false;
|
|
|
|
|
2015-09-28 08:23:28 +03:00
|
|
|
if (mPendingSeekTime.isNothing()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-13 04:14:12 +03:00
|
|
|
|
|
|
|
if (HasVideo()) {
|
|
|
|
mVideo.ResetDemuxer();
|
|
|
|
mVideo.ResetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't reset the audio demuxer not state when seeking video only
|
|
|
|
// as it will cause the audio to seek back to the beginning
|
|
|
|
// resulting in out-of-sync audio from video.
|
2016-05-16 09:47:57 +03:00
|
|
|
if (HasAudio() && !mOriginalSeekTarget.IsVideoOnly()) {
|
2016-05-13 04:14:12 +03:00
|
|
|
mAudio.ResetDemuxer();
|
|
|
|
mAudio.ResetState();
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
if (HasVideo()) {
|
|
|
|
DoVideoSeek();
|
|
|
|
} else if (HasAudio()) {
|
|
|
|
DoAudioSeek();
|
|
|
|
} else {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
void MediaFormatReader::OnSeekFailed(TrackType aTrack,
|
|
|
|
const MediaResult& aError) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2017-09-28 19:37:45 +03:00
|
|
|
LOGV("%s failure:%s", TrackTypeToStr(aTrack), aError.ErrorName().get());
|
2015-05-18 08:40:32 +03:00
|
|
|
if (aTrack == TrackType::kVideoTrack) {
|
2015-06-15 03:58:12 +03:00
|
|
|
mVideo.mSeekRequest.Complete();
|
2015-05-18 08:40:32 +03:00
|
|
|
} else {
|
2015-06-15 03:58:12 +03:00
|
|
|
mAudio.mSeekRequest.Complete();
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
|
2017-09-04 12:27:43 +03:00
|
|
|
if (HasVideo() && aTrack == TrackType::kAudioTrack &&
|
|
|
|
mFallbackSeekTime.isSome() &&
|
|
|
|
mPendingSeekTime.ref() != mFallbackSeekTime.ref()) {
|
2015-08-11 07:15:19 +03:00
|
|
|
// We have failed to seek audio where video seeked to earlier.
|
|
|
|
// Attempt to seek instead to the closest point that we know we have in
|
|
|
|
// order to limit A/V sync discrepency.
|
|
|
|
|
|
|
|
// Ensure we have the most up to date buffered ranges.
|
|
|
|
UpdateReceivedNewData(TrackType::kAudioTrack);
|
2017-04-17 11:35:04 +03:00
|
|
|
Maybe<TimeUnit> nextSeekTime;
|
2015-08-11 07:15:19 +03:00
|
|
|
// Find closest buffered time found after video seeked time.
|
|
|
|
for (const auto& timeRange : mAudio.mTimeRanges) {
|
|
|
|
if (timeRange.mStart >= mPendingSeekTime.ref()) {
|
|
|
|
nextSeekTime.emplace(timeRange.mStart);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 12:27:43 +03:00
|
|
|
if (nextSeekTime.isNothing() ||
|
|
|
|
nextSeekTime.ref() > mFallbackSeekTime.ref()) {
|
2016-05-16 09:47:57 +03:00
|
|
|
nextSeekTime = Some(mFallbackSeekTime.ref());
|
2015-08-11 07:15:19 +03:00
|
|
|
LOG("Unable to seek audio to video seek time. A/V sync may be broken");
|
|
|
|
} else {
|
2016-05-16 09:47:57 +03:00
|
|
|
mFallbackSeekTime.reset();
|
2015-08-11 07:15:19 +03:00
|
|
|
}
|
|
|
|
mPendingSeekTime = nextSeekTime;
|
|
|
|
DoAudioSeek();
|
|
|
|
return;
|
|
|
|
}
|
2015-05-18 08:42:01 +03:00
|
|
|
NotifyWaitingForData(aTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
2015-06-15 03:58:12 +03:00
|
|
|
MOZ_ASSERT(!mVideo.mSeekRequest.Exists() && !mAudio.mSeekRequest.Exists());
|
2015-05-18 08:40:32 +03:00
|
|
|
mPendingSeekTime.reset();
|
2016-12-16 11:57:27 +03:00
|
|
|
|
2019-02-22 12:18:18 +03:00
|
|
|
auto type = aTrack == TrackType::kAudioTrack ? MediaData::Type::AUDIO_DATA
|
|
|
|
: MediaData::Type::VIDEO_DATA;
|
2016-12-16 11:57:27 +03:00
|
|
|
mSeekPromise.Reject(SeekRejectValue(type, aError), __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::DoVideoSeek() {
|
|
|
|
MOZ_ASSERT(mPendingSeekTime.isSome());
|
2016-12-16 06:16:31 +03:00
|
|
|
LOGV("Seeking video to %" PRId64, mPendingSeekTime.ref().ToMicroseconds());
|
2017-04-17 11:35:04 +03:00
|
|
|
auto seekTime = mPendingSeekTime.ref();
|
2017-01-11 11:33:29 +03:00
|
|
|
mVideo.mTrackDemuxer->Seek(seekTime)
|
|
|
|
->Then(OwnerThread(), __func__, this,
|
|
|
|
&MediaFormatReader::OnVideoSeekCompleted,
|
|
|
|
&MediaFormatReader::OnVideoSeekFailed)
|
|
|
|
->Track(mVideo.mSeekRequest);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
void MediaFormatReader::OnVideoSeekCompleted(TimeUnit aTime) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-12-16 06:16:31 +03:00
|
|
|
LOGV("Video seeked to %" PRId64, aTime.ToMicroseconds());
|
2015-06-15 03:58:12 +03:00
|
|
|
mVideo.mSeekRequest.Complete();
|
2015-05-18 08:40:32 +03:00
|
|
|
|
2017-05-11 11:29:57 +03:00
|
|
|
mVideo.mFirstFrameTime = Some(aTime);
|
2016-07-26 02:36:55 +03:00
|
|
|
mPreviousDecodedKeyframeTime_us = sNoPreviousDecodedKeyframe;
|
|
|
|
|
2016-06-08 05:59:57 +03:00
|
|
|
SetVideoDecodeThreshold();
|
|
|
|
|
2016-05-16 09:47:57 +03:00
|
|
|
if (HasAudio() && !mOriginalSeekTarget.IsVideoOnly()) {
|
2016-04-18 09:33:52 +03:00
|
|
|
MOZ_ASSERT(mPendingSeekTime.isSome());
|
2016-05-16 09:47:57 +03:00
|
|
|
if (mOriginalSeekTarget.IsFast()) {
|
2016-01-28 15:25:15 +03:00
|
|
|
// We are performing a fast seek. We need to seek audio to where the
|
|
|
|
// video seeked to, to ensure proper A/V sync once playback resume.
|
|
|
|
mPendingSeekTime = Some(aTime);
|
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
DoAudioSeek();
|
|
|
|
} else {
|
|
|
|
mPendingSeekTime.reset();
|
2016-01-28 13:20:29 +03:00
|
|
|
mSeekPromise.Resolve(aTime, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
void MediaFormatReader::OnVideoSeekFailed(const MediaResult& aError) {
|
2016-07-26 02:36:55 +03:00
|
|
|
mPreviousDecodedKeyframeTime_us = sNoPreviousDecodedKeyframe;
|
2016-09-12 05:22:20 +03:00
|
|
|
OnSeekFailed(TrackType::kVideoTrack, aError);
|
2016-07-26 02:36:55 +03:00
|
|
|
}
|
|
|
|
|
2016-06-08 05:59:57 +03:00
|
|
|
void MediaFormatReader::SetVideoDecodeThreshold() {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
|
|
|
if (!HasVideo() || !mVideo.mDecoder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mVideo.mTimeThreshold && !IsSeeking()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeUnit threshold;
|
|
|
|
if (mVideo.mTimeThreshold) {
|
|
|
|
// For internalSeek.
|
|
|
|
threshold = mVideo.mTimeThreshold.ref().Time();
|
|
|
|
} else if (IsSeeking()) {
|
|
|
|
// If IsSeeking() is true, then video seek must have completed already.
|
|
|
|
TimeUnit keyframe;
|
|
|
|
if (NS_FAILED(mVideo.mTrackDemuxer->GetNextRandomAccessPoint(&keyframe))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the key frame is invalid/infinite, it means the target position is
|
|
|
|
// closing to end of stream. We don't want to skip any frame at this point.
|
2019-01-11 20:07:49 +03:00
|
|
|
threshold = keyframe.IsValid() && !keyframe.IsInfinite()
|
|
|
|
? mOriginalSeekTarget.GetTime()
|
|
|
|
: TimeUnit::Invalid();
|
2016-06-08 05:59:57 +03:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG("Set seek threshold to %" PRId64, threshold.ToMicroseconds());
|
2016-06-08 05:59:57 +03:00
|
|
|
mVideo.mDecoder->SetSeekThreshold(threshold);
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
void MediaFormatReader::DoAudioSeek() {
|
|
|
|
MOZ_ASSERT(mPendingSeekTime.isSome());
|
2016-12-16 06:16:31 +03:00
|
|
|
LOGV("Seeking audio to %" PRId64, mPendingSeekTime.ref().ToMicroseconds());
|
2017-04-17 11:35:04 +03:00
|
|
|
auto seekTime = mPendingSeekTime.ref();
|
2017-01-11 11:33:29 +03:00
|
|
|
mAudio.mTrackDemuxer->Seek(seekTime)
|
|
|
|
->Then(OwnerThread(), __func__, this,
|
|
|
|
&MediaFormatReader::OnAudioSeekCompleted,
|
|
|
|
&MediaFormatReader::OnAudioSeekFailed)
|
|
|
|
->Track(mAudio.mSeekRequest);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
void MediaFormatReader::OnAudioSeekCompleted(TimeUnit aTime) {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-12-16 06:16:31 +03:00
|
|
|
LOGV("Audio seeked to %" PRId64, aTime.ToMicroseconds());
|
2015-06-15 03:58:12 +03:00
|
|
|
mAudio.mSeekRequest.Complete();
|
2017-05-11 11:29:57 +03:00
|
|
|
mAudio.mFirstFrameTime = Some(aTime);
|
2015-05-18 08:40:32 +03:00
|
|
|
mPendingSeekTime.reset();
|
2016-01-28 13:20:29 +03:00
|
|
|
mSeekPromise.Resolve(aTime, __func__);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-09-12 05:22:20 +03:00
|
|
|
void MediaFormatReader::OnAudioSeekFailed(const MediaResult& aError) {
|
|
|
|
OnSeekFailed(TrackType::kAudioTrack, aError);
|
2016-07-26 02:36:55 +03:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:03:30 +03:00
|
|
|
void MediaFormatReader::ReleaseResources() {
|
2017-01-26 15:56:46 +03:00
|
|
|
LOGV("");
|
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ShutdownDecoder(TrackInfo::kAudioTrack);
|
|
|
|
ShutdownDecoder(TrackInfo::kVideoTrack);
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFormatReader::VideoIsHardwareAccelerated() const {
|
2015-07-20 22:14:37 +03:00
|
|
|
return mVideo.mIsHardwareAccelerated;
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
void MediaFormatReader::NotifyTrackDemuxers() {
|
2015-05-18 08:40:32 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2016-05-06 08:56:47 +03:00
|
|
|
LOGV("");
|
|
|
|
|
2015-09-15 06:03:48 +03:00
|
|
|
if (!mInitDone) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 13:08:01 +03:00
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
if (HasVideo()) {
|
|
|
|
mVideo.mReceivedNewData = true;
|
|
|
|
ScheduleUpdate(TrackType::kVideoTrack);
|
|
|
|
}
|
|
|
|
if (HasAudio()) {
|
|
|
|
mAudio.mReceivedNewData = true;
|
|
|
|
ScheduleUpdate(TrackType::kAudioTrack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
void MediaFormatReader::NotifyDataArrived() {
|
2015-06-17 01:37:48 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2016-11-28 13:08:01 +03:00
|
|
|
|
2017-04-25 16:28:31 +03:00
|
|
|
if (mShutdown || !mDemuxer || !mDemuxerInitDone) {
|
2016-11-28 13:08:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNotifyDataArrivedPromise.Exists()) {
|
2017-03-15 10:20:45 +03:00
|
|
|
// Already one in progress. Set the dirty flag so we can process it later.
|
|
|
|
mPendingNotifyDataArrived = true;
|
2016-11-28 13:08:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MediaFormatReader> self = this;
|
2017-01-11 11:33:29 +03:00
|
|
|
mDemuxer->NotifyDataArrived()
|
|
|
|
->Then(OwnerThread(), __func__,
|
|
|
|
[self]() {
|
|
|
|
self->mNotifyDataArrivedPromise.Complete();
|
|
|
|
self->UpdateBuffered();
|
|
|
|
self->NotifyTrackDemuxers();
|
2017-03-15 10:20:45 +03:00
|
|
|
if (self->mPendingNotifyDataArrived) {
|
|
|
|
self->mPendingNotifyDataArrived = false;
|
|
|
|
self->NotifyDataArrived();
|
|
|
|
}
|
2017-01-11 11:33:29 +03:00
|
|
|
},
|
|
|
|
[self]() { self->mNotifyDataArrivedPromise.Complete(); })
|
|
|
|
->Track(mNotifyDataArrivedPromise);
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2016-11-28 13:08:01 +03:00
|
|
|
void MediaFormatReader::UpdateBuffered() {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInitDone || !mHasStartTime) {
|
|
|
|
mBuffered = TimeIntervals();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasVideo()) {
|
|
|
|
mVideo.mTimeRanges = mVideo.mTrackDemuxer->GetBuffered();
|
|
|
|
bool hasLastEnd;
|
2017-04-17 11:35:04 +03:00
|
|
|
auto lastEnd = mVideo.mTimeRanges.GetEnd(&hasLastEnd);
|
2016-11-28 13:08:01 +03:00
|
|
|
if (hasLastEnd) {
|
2017-09-04 12:27:43 +03:00
|
|
|
if (mVideo.mLastTimeRangesEnd &&
|
|
|
|
mVideo.mLastTimeRangesEnd.ref() < lastEnd) {
|
2016-11-28 13:08:01 +03:00
|
|
|
// New data was added after our previous end, we can clear the EOS flag.
|
|
|
|
mVideo.mDemuxEOS = false;
|
|
|
|
ScheduleUpdate(TrackInfo::kVideoTrack);
|
|
|
|
}
|
|
|
|
mVideo.mLastTimeRangesEnd = Some(lastEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HasAudio()) {
|
|
|
|
mAudio.mTimeRanges = mAudio.mTrackDemuxer->GetBuffered();
|
|
|
|
bool hasLastEnd;
|
2017-04-17 11:35:04 +03:00
|
|
|
auto lastEnd = mAudio.mTimeRanges.GetEnd(&hasLastEnd);
|
2016-11-28 13:08:01 +03:00
|
|
|
if (hasLastEnd) {
|
2017-09-04 12:27:43 +03:00
|
|
|
if (mAudio.mLastTimeRangesEnd &&
|
|
|
|
mAudio.mLastTimeRangesEnd.ref() < lastEnd) {
|
2016-11-28 13:08:01 +03:00
|
|
|
// New data was added after our previous end, we can clear the EOS flag.
|
|
|
|
mAudio.mDemuxEOS = false;
|
|
|
|
ScheduleUpdate(TrackInfo::kAudioTrack);
|
|
|
|
}
|
|
|
|
mAudio.mLastTimeRangesEnd = Some(lastEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
media::TimeIntervals intervals;
|
|
|
|
if (HasAudio() && HasVideo()) {
|
|
|
|
intervals = media::Intersection(mVideo.mTimeRanges, mAudio.mTimeRanges);
|
|
|
|
} else if (HasAudio()) {
|
|
|
|
intervals = mAudio.mTimeRanges;
|
|
|
|
} else if (HasVideo()) {
|
|
|
|
intervals = mVideo.mTimeRanges;
|
|
|
|
}
|
|
|
|
|
2017-09-04 12:27:43 +03:00
|
|
|
if (!intervals.Length() || intervals.GetStart() == TimeUnit::Zero()) {
|
2016-11-28 13:08:01 +03:00
|
|
|
// IntervalSet already starts at 0 or is empty, nothing to shift.
|
|
|
|
mBuffered = intervals;
|
|
|
|
} else {
|
2017-04-17 11:35:04 +03:00
|
|
|
mBuffered = intervals.Shift(TimeUnit::Zero() - mInfo.mStartTime);
|
2016-11-28 13:08:01 +03:00
|
|
|
}
|
2015-05-18 08:40:32 +03:00
|
|
|
}
|
|
|
|
|
2015-10-15 03:04:00 +03:00
|
|
|
layers::ImageContainer* MediaFormatReader::GetImageContainer() {
|
2017-01-27 15:20:37 +03:00
|
|
|
return mVideoFrameContainer ? mVideoFrameContainer->GetImageContainer()
|
|
|
|
: nullptr;
|
2015-10-15 03:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-01-18 11:51:31 +03:00
|
|
|
void MediaFormatReader::GetMozDebugReaderData(nsACString& aString) {
|
2017-09-04 22:07:11 +03:00
|
|
|
nsCString result;
|
2017-09-01 15:58:19 +03:00
|
|
|
nsAutoCString audioDecoderName("unavailable");
|
|
|
|
nsAutoCString videoDecoderName = audioDecoderName;
|
|
|
|
nsAutoCString audioType("none");
|
|
|
|
nsAutoCString videoType("none");
|
2016-01-22 06:01:50 +03:00
|
|
|
|
2018-10-03 11:23:08 +03:00
|
|
|
AudioInfo audioInfo;
|
2018-05-26 22:21:45 +03:00
|
|
|
{
|
2016-11-29 17:50:08 +03:00
|
|
|
MutexAutoLock lock(mAudio.mMutex);
|
2018-10-03 11:23:08 +03:00
|
|
|
if (HasAudio()) {
|
|
|
|
audioInfo = *mAudio.GetWorkingInfo()->GetAsAudioInfo();
|
|
|
|
audioDecoderName = mAudio.mDecoder ? mAudio.mDecoder->GetDescriptionName()
|
|
|
|
: mAudio.mDescription;
|
|
|
|
audioType = audioInfo.mMimeType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoInfo videoInfo;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mVideo.mMutex);
|
|
|
|
if (HasVideo()) {
|
|
|
|
videoInfo = *mVideo.GetWorkingInfo()->GetAsVideoInfo();
|
|
|
|
videoDecoderName = mVideo.mDecoder ? mVideo.mDecoder->GetDescriptionName()
|
|
|
|
: mVideo.mDescription;
|
|
|
|
videoType = videoInfo.mMimeType;
|
|
|
|
}
|
2018-04-30 20:06:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
result += nsPrintfCString("Audio Decoder(%s, %u channels @ %0.1fkHz): %s\n",
|
2018-05-26 22:21:45 +03:00
|
|
|
audioType.get(), audioInfo.mChannels,
|
|
|
|
audioInfo.mRate / 1000.0f, audioDecoderName.get());
|
2017-03-01 06:03:01 +03:00
|
|
|
result += nsPrintfCString("Audio Frames Decoded: %" PRIu64 "\n",
|
2016-01-22 06:01:50 +03:00
|
|
|
mAudio.mNumSamplesOutputTotal);
|
2016-05-05 08:11:21 +03:00
|
|
|
if (HasAudio()) {
|
2017-01-27 15:20:37 +03:00
|
|
|
result += nsPrintfCString(
|
2017-03-01 06:03:01 +03:00
|
|
|
"Audio State: ni=%d no=%d wp=%d demuxr=%d demuxq=%u decoder=%d tt=%.1f "
|
|
|
|
"tths=%d in=%" PRIu64 " out=%" PRIu64
|
2017-05-29 11:41:36 +03:00
|
|
|
" qs=%u pending=%u wfd=%d eos=%d ds=%d wfk=%d sid=%u\n",
|
2017-02-23 16:43:01 +03:00
|
|
|
NeedInput(mAudio), mAudio.HasPromise(),
|
|
|
|
!mAudio.mWaitingPromise.IsEmpty(), mAudio.mDemuxRequest.Exists(),
|
|
|
|
uint32_t(mAudio.mQueuedSamples.Length()),
|
|
|
|
mAudio.mDecodeRequest.Exists(),
|
2017-01-27 15:20:37 +03:00
|
|
|
mAudio.mTimeThreshold ? mAudio.mTimeThreshold.ref().Time().ToSeconds()
|
|
|
|
: -1.0,
|
|
|
|
mAudio.mTimeThreshold ? mAudio.mTimeThreshold.ref().mHasSeeked : -1,
|
2017-02-23 16:43:01 +03:00
|
|
|
mAudio.mNumSamplesInput, mAudio.mNumSamplesOutput,
|
|
|
|
unsigned(size_t(mAudio.mSizeOfQueue)),
|
|
|
|
unsigned(mAudio.mOutput.Length()), mAudio.mWaitingForData,
|
2017-05-29 11:41:36 +03:00
|
|
|
mAudio.mDemuxEOS, int32_t(mAudio.mDrainState), mAudio.mWaitingForKey,
|
2017-02-23 16:43:01 +03:00
|
|
|
mAudio.mLastStreamSourceID);
|
2016-05-05 08:11:21 +03:00
|
|
|
}
|
2017-09-12 18:40:42 +03:00
|
|
|
|
2017-09-01 15:58:19 +03:00
|
|
|
result += nsPrintfCString(
|
2017-09-17 10:56:38 +03:00
|
|
|
"Video Decoder(%s, %dx%d @ %0.2f): %s\n", videoType.get(),
|
2017-09-12 18:40:42 +03:00
|
|
|
videoInfo.mDisplay.width < 0 ? 0 : videoInfo.mDisplay.width,
|
|
|
|
videoInfo.mDisplay.height < 0 ? 0 : videoInfo.mDisplay.height,
|
|
|
|
mVideo.mMeanRate.Mean(), videoDecoderName.get());
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
result +=
|
2017-03-01 06:03:01 +03:00
|
|
|
nsPrintfCString("Hardware Video Decoding: %s\n",
|
2017-01-27 15:20:37 +03:00
|
|
|
VideoIsHardwareAccelerated() ? "enabled" : "disabled");
|
2017-03-01 06:03:01 +03:00
|
|
|
result += nsPrintfCString(
|
|
|
|
"Video Frames Decoded: %" PRIu64 " (skipped=%" PRIu64 ")\n",
|
2017-02-23 16:43:01 +03:00
|
|
|
mVideo.mNumSamplesOutputTotal, mVideo.mNumSamplesSkippedTotal);
|
2016-05-05 08:11:21 +03:00
|
|
|
if (HasVideo()) {
|
2017-01-27 15:20:37 +03:00
|
|
|
result += nsPrintfCString(
|
2017-03-01 06:03:01 +03:00
|
|
|
"Video State: ni=%d no=%d wp=%d demuxr=%d demuxq=%u decoder=%d tt=%.1f "
|
|
|
|
"tths=%d in=%" PRIu64 " out=%" PRIu64
|
2017-05-29 11:41:36 +03:00
|
|
|
" qs=%u pending:%u wfd=%d eos=%d ds=%d wfk=%d sid=%u\n",
|
2017-02-23 16:43:01 +03:00
|
|
|
NeedInput(mVideo), mVideo.HasPromise(),
|
|
|
|
!mVideo.mWaitingPromise.IsEmpty(), mVideo.mDemuxRequest.Exists(),
|
|
|
|
uint32_t(mVideo.mQueuedSamples.Length()),
|
|
|
|
mVideo.mDecodeRequest.Exists(),
|
2017-01-27 15:20:37 +03:00
|
|
|
mVideo.mTimeThreshold ? mVideo.mTimeThreshold.ref().Time().ToSeconds()
|
|
|
|
: -1.0,
|
|
|
|
mVideo.mTimeThreshold ? mVideo.mTimeThreshold.ref().mHasSeeked : -1,
|
2017-02-23 16:43:01 +03:00
|
|
|
mVideo.mNumSamplesInput, mVideo.mNumSamplesOutput,
|
|
|
|
unsigned(size_t(mVideo.mSizeOfQueue)),
|
|
|
|
unsigned(mVideo.mOutput.Length()), mVideo.mWaitingForData,
|
2017-05-29 11:41:36 +03:00
|
|
|
mVideo.mDemuxEOS, int32_t(mVideo.mDrainState), mVideo.mWaitingForKey,
|
2017-02-23 16:43:01 +03:00
|
|
|
mVideo.mLastStreamSourceID);
|
2016-05-05 08:11:21 +03:00
|
|
|
}
|
2017-01-18 11:51:31 +03:00
|
|
|
aString += result;
|
2016-01-18 02:21:59 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 12:12:02 +03:00
|
|
|
void MediaFormatReader::SetVideoNullDecode(bool aIsNullDecode) {
|
2016-07-29 09:51:18 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2017-03-09 12:12:02 +03:00
|
|
|
return SetNullDecode(TrackType::kVideoTrack, aIsNullDecode);
|
2016-07-29 09:51:18 +03:00
|
|
|
}
|
|
|
|
|
2017-07-12 11:28:19 +03:00
|
|
|
void MediaFormatReader::UpdateCompositor(
|
|
|
|
already_AddRefed<layers::KnowsCompositor> aCompositor) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
mKnowsCompositor = aCompositor;
|
|
|
|
}
|
|
|
|
|
2017-03-09 12:12:02 +03:00
|
|
|
void MediaFormatReader::SetNullDecode(TrackType aTrack, bool aIsNullDecode) {
|
2016-07-29 09:51:18 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
2017-01-16 10:20:10 +03:00
|
|
|
auto& decoder = GetDecoderData(aTrack);
|
2017-03-09 12:12:02 +03:00
|
|
|
if (decoder.mIsNullDecode == aIsNullDecode) {
|
2016-07-29 09:51:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-09 12:12:02 +03:00
|
|
|
LOG("%s, decoder.mIsNullDecode = %d => aIsNullDecode = %d",
|
|
|
|
TrackTypeToStr(aTrack), decoder.mIsNullDecode, aIsNullDecode);
|
2017-01-16 10:20:10 +03:00
|
|
|
|
2017-03-09 12:12:02 +03:00
|
|
|
decoder.mIsNullDecode = aIsNullDecode;
|
2017-01-26 15:56:46 +03:00
|
|
|
ShutdownDecoder(aTrack);
|
2016-07-29 09:51:18 +03:00
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
void MediaFormatReader::OnFirstDemuxCompleted(
|
|
|
|
TrackInfo::TrackType aType,
|
|
|
|
RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
|
2016-10-27 10:21:05 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& decoder = GetDecoderData(aType);
|
|
|
|
MOZ_ASSERT(decoder.mFirstDemuxedSampleTime.isNothing());
|
2017-04-14 12:13:36 +03:00
|
|
|
decoder.mFirstDemuxedSampleTime.emplace(aSamples->mSamples[0]->mTime);
|
2016-10-27 10:21:05 +03:00
|
|
|
MaybeResolveMetadataPromise();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFormatReader::OnFirstDemuxFailed(TrackInfo::TrackType aType,
|
|
|
|
const MediaResult& aError) {
|
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& decoder = GetDecoderData(aType);
|
|
|
|
MOZ_ASSERT(decoder.mFirstDemuxedSampleTime.isNothing());
|
|
|
|
decoder.mFirstDemuxedSampleTime.emplace(TimeUnit::FromInfinity());
|
|
|
|
MaybeResolveMetadataPromise();
|
|
|
|
}
|
|
|
|
|
2015-05-18 08:40:32 +03:00
|
|
|
} // namespace mozilla
|
2017-03-01 06:58:39 +03:00
|
|
|
|
|
|
|
#undef NS_DispatchToMainThread
|