2016-05-24 03:02:57 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AccurateSeekTask.h"
|
|
|
|
#include "MediaDecoderReaderWrapper.h"
|
|
|
|
#include "mozilla/AbstractThread.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
extern LazyLogModule gMediaDecoderLog;
|
|
|
|
extern LazyLogModule gMediaSampleLog;
|
|
|
|
|
|
|
|
// avoid redefined macro in unified build
|
|
|
|
#undef LOG
|
|
|
|
#undef DECODER_LOG
|
|
|
|
#undef VERBOSE_LOG
|
|
|
|
|
|
|
|
#define LOG(m, l, x, ...) \
|
|
|
|
MOZ_LOG(m, l, ("[AccurateSeekTask] Decoder=%p " x, mDecoderID, ##__VA_ARGS__))
|
|
|
|
#define DECODER_LOG(x, ...) \
|
|
|
|
LOG(gMediaDecoderLog, LogLevel::Debug, x, ##__VA_ARGS__)
|
|
|
|
#define VERBOSE_LOG(x, ...) \
|
|
|
|
LOG(gMediaDecoderLog, LogLevel::Verbose, x, ##__VA_ARGS__)
|
|
|
|
#define SAMPLE_LOG(x, ...) \
|
|
|
|
LOG(gMediaSampleLog, LogLevel::Debug, x, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
// Somehow MSVC doesn't correctly delete the comma before ##__VA_ARGS__
|
|
|
|
// when __VA_ARGS__ expands to nothing. This is a workaround for it.
|
|
|
|
#define DECODER_WARN_HELPER(a, b) NS_WARNING b
|
|
|
|
#define DECODER_WARN(x, ...) \
|
|
|
|
DECODER_WARN_HELPER(0, (nsPrintfCString("Decoder=%p " x, mDecoderID, ##__VA_ARGS__).get()))
|
|
|
|
|
|
|
|
AccurateSeekTask::AccurateSeekTask(const void* aDecoderID,
|
|
|
|
AbstractThread* aThread,
|
|
|
|
MediaDecoderReaderWrapper* aReader,
|
2016-07-05 06:12:42 +00:00
|
|
|
const SeekTarget& aTarget,
|
2016-05-24 03:02:57 +00:00
|
|
|
const MediaInfo& aInfo,
|
2016-06-28 09:16:31 +00:00
|
|
|
const media::TimeUnit& aEnd,
|
2016-05-24 03:02:57 +00:00
|
|
|
int64_t aCurrentMediaTime)
|
2016-07-05 06:12:42 +00:00
|
|
|
: SeekTask(aDecoderID, aThread, aReader, aTarget)
|
2016-06-28 09:16:31 +00:00
|
|
|
, mCurrentTimeBeforeSeek(media::TimeUnit::FromMicroseconds(aCurrentMediaTime))
|
2016-05-24 03:02:57 +00:00
|
|
|
, mAudioRate(aInfo.mAudio.mRate)
|
2016-07-05 06:12:42 +00:00
|
|
|
, mDoneAudioSeeking(!aInfo.HasAudio() || aTarget.IsVideoOnly())
|
2016-06-28 05:16:52 +00:00
|
|
|
, mDoneVideoSeeking(!aInfo.HasVideo())
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
// Bound the seek time to be inside the media range.
|
2016-06-28 09:16:31 +00:00
|
|
|
NS_ASSERTION(aEnd.ToMicroseconds() != -1, "Should know end time by now");
|
2016-06-30 05:37:20 +00:00
|
|
|
mTarget.SetTime(std::max(media::TimeUnit(), std::min(mTarget.GetTime(), aEnd)));
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
// Configure MediaDecoderReaderWrapper.
|
2016-06-28 03:59:43 +00:00
|
|
|
SetCallbacks();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AccurateSeekTask::~AccurateSeekTask()
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
MOZ_ASSERT(mIsDiscarded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccurateSeekTask::Discard()
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
// Disconnect MDSM.
|
|
|
|
RejectIfExist(__func__);
|
|
|
|
|
|
|
|
// Disconnect MediaDecoderReaderWrapper.
|
|
|
|
mSeekRequest.DisconnectIfExists();
|
2016-06-28 03:59:43 +00:00
|
|
|
CancelCallbacks();
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
mIsDiscarded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AccurateSeekTask::NeedToResetMDSM() const
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<AccurateSeekTask::SeekTaskPromise>
|
|
|
|
AccurateSeekTask::Seek(const media::TimeUnit& aDuration)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
// Do the seek.
|
2016-06-30 05:37:20 +00:00
|
|
|
mSeekRequest.Begin(mReader->Seek(mTarget, aDuration)
|
2016-05-24 03:02:57 +00:00
|
|
|
->Then(OwnerThread(), __func__, this,
|
|
|
|
&AccurateSeekTask::OnSeekResolved, &AccurateSeekTask::OnSeekRejected));
|
|
|
|
|
|
|
|
return mSeekTaskPromise.Ensure(__func__);
|
|
|
|
}
|
|
|
|
|
2016-06-28 07:39:42 +00:00
|
|
|
void
|
2016-07-05 09:00:28 +00:00
|
|
|
AccurateSeekTask::RequestAudioData()
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-28 05:16:52 +00:00
|
|
|
MOZ_ASSERT(!mDoneAudioSeeking);
|
2016-06-29 09:06:00 +00:00
|
|
|
MOZ_ASSERT(!mReader->IsRequestingAudioData());
|
2016-06-29 09:26:13 +00:00
|
|
|
MOZ_ASSERT(!mReader->IsWaitingAudioData());
|
2016-06-28 08:13:09 +00:00
|
|
|
mReader->RequestAudioData();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 07:39:42 +00:00
|
|
|
void
|
2016-07-05 09:00:28 +00:00
|
|
|
AccurateSeekTask::RequestVideoData()
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-28 05:16:52 +00:00
|
|
|
MOZ_ASSERT(!mDoneVideoSeeking);
|
2016-06-29 09:06:00 +00:00
|
|
|
MOZ_ASSERT(!mReader->IsRequestingVideoData());
|
2016-06-29 09:26:13 +00:00
|
|
|
MOZ_ASSERT(!mReader->IsWaitingVideoData());
|
2016-06-28 08:13:09 +00:00
|
|
|
mReader->RequestVideoData(false, media::TimeUnit());
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
AccurateSeekTask::DropAudioUpToSeekTarget(MediaData* aSample)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
RefPtr<AudioData> audio(aSample->As<AudioData>());
|
2016-07-05 05:58:51 +00:00
|
|
|
MOZ_ASSERT(audio && mTarget.IsAccurate());
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
CheckedInt64 sampleDuration = FramesToUsecs(audio->mFrames, mAudioRate);
|
|
|
|
if (!sampleDuration.isValid()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-06-30 05:37:20 +00:00
|
|
|
if (audio->mTime + sampleDuration.value() <= mTarget.GetTime().ToMicroseconds()) {
|
2016-05-24 03:02:57 +00:00
|
|
|
// Our seek target lies after the frames in this AudioData. Don't
|
|
|
|
// push it onto the audio queue, and keep decoding forwards.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-30 05:37:20 +00:00
|
|
|
if (audio->mTime > mTarget.GetTime().ToMicroseconds()) {
|
2016-05-24 03:02:57 +00:00
|
|
|
// The seek target doesn't lie in the audio block just after the last
|
|
|
|
// audio frames we've seen which were before the seek target. This
|
|
|
|
// could have been the first audio data we've seen after seek, i.e. the
|
|
|
|
// seek terminated after the seek target in the audio stream. Just
|
|
|
|
// abort the audio decode-to-target, the state machine will play
|
|
|
|
// silence to cover the gap. Typically this happens in poorly muxed
|
|
|
|
// files.
|
|
|
|
DECODER_WARN("Audio not synced after seek, maybe a poorly muxed file?");
|
|
|
|
mSeekedAudioData = audio;
|
2016-06-28 05:16:52 +00:00
|
|
|
mDoneAudioSeeking = true;
|
2016-05-24 03:02:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The seek target lies somewhere in this AudioData's frames, strip off
|
|
|
|
// any frames which lie before the seek target, so we'll begin playback
|
|
|
|
// exactly at the seek target.
|
2016-06-30 05:37:20 +00:00
|
|
|
NS_ASSERTION(mTarget.GetTime().ToMicroseconds() >= audio->mTime,
|
2016-05-24 03:02:57 +00:00
|
|
|
"Target must at or be after data start.");
|
2016-06-30 05:37:20 +00:00
|
|
|
NS_ASSERTION(mTarget.GetTime().ToMicroseconds() < audio->mTime + sampleDuration.value(),
|
2016-05-24 03:02:57 +00:00
|
|
|
"Data must end after target.");
|
|
|
|
|
|
|
|
CheckedInt64 framesToPrune =
|
2016-06-30 05:37:20 +00:00
|
|
|
UsecsToFrames(mTarget.GetTime().ToMicroseconds() - audio->mTime, mAudioRate);
|
2016-05-24 03:02:57 +00:00
|
|
|
if (!framesToPrune.isValid()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (framesToPrune.value() > audio->mFrames) {
|
|
|
|
// We've messed up somehow. Don't try to trim frames, the |frames|
|
|
|
|
// variable below will overflow.
|
|
|
|
DECODER_WARN("Can't prune more frames that we have!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
uint32_t frames = audio->mFrames - static_cast<uint32_t>(framesToPrune.value());
|
|
|
|
uint32_t channels = audio->mChannels;
|
|
|
|
AlignedAudioBuffer audioData(frames * channels);
|
|
|
|
if (!audioData) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(audioData.get(),
|
|
|
|
audio->mAudioData.get() + (framesToPrune.value() * channels),
|
|
|
|
frames * channels * sizeof(AudioDataValue));
|
|
|
|
CheckedInt64 duration = FramesToUsecs(frames, mAudioRate);
|
|
|
|
if (!duration.isValid()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
RefPtr<AudioData> data(new AudioData(audio->mOffset,
|
2016-06-30 05:37:20 +00:00
|
|
|
mTarget.GetTime().ToMicroseconds(),
|
2016-05-24 03:02:57 +00:00
|
|
|
duration.value(),
|
|
|
|
frames,
|
|
|
|
Move(audioData),
|
|
|
|
channels,
|
|
|
|
audio->mRate));
|
|
|
|
MOZ_ASSERT(!mSeekedAudioData, "Should be the 1st sample after seeking");
|
|
|
|
mSeekedAudioData = data;
|
2016-06-28 05:16:52 +00:00
|
|
|
mDoneAudioSeeking = true;
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
AccurateSeekTask::DropVideoUpToSeekTarget(MediaData* aSample)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
RefPtr<VideoData> video(aSample->As<VideoData>());
|
|
|
|
MOZ_ASSERT(video);
|
|
|
|
DECODER_LOG("DropVideoUpToSeekTarget() frame [%lld, %lld]",
|
|
|
|
video->mTime, video->GetEndTime());
|
2016-06-30 05:37:20 +00:00
|
|
|
const int64_t target = mTarget.GetTime().ToMicroseconds();
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
// If the frame end time is less than the seek target, we won't want
|
|
|
|
// to display this frame after the seek, so discard it.
|
|
|
|
if (target >= video->GetEndTime()) {
|
|
|
|
DECODER_LOG("DropVideoUpToSeekTarget() pop video frame [%lld, %lld] target=%lld",
|
|
|
|
video->mTime, video->GetEndTime(), target);
|
|
|
|
mFirstVideoFrameAfterSeek = video;
|
|
|
|
} else {
|
|
|
|
if (target >= video->mTime && video->GetEndTime() >= target) {
|
|
|
|
// The seek target lies inside this frame's time slice. Adjust the frame's
|
|
|
|
// start time to match the seek target. We do this by replacing the
|
|
|
|
// first frame with a shallow copy which has the new timestamp.
|
|
|
|
RefPtr<VideoData> temp = VideoData::ShallowCopyUpdateTimestamp(video.get(), target);
|
|
|
|
video = temp;
|
|
|
|
}
|
|
|
|
mFirstVideoFrameAfterSeek = nullptr;
|
|
|
|
|
|
|
|
DECODER_LOG("DropVideoUpToSeekTarget() found video frame [%lld, %lld] containing target=%lld",
|
|
|
|
video->mTime, video->GetEndTime(), target);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mSeekedVideoData, "Should be the 1st sample after seeking");
|
|
|
|
mSeekedVideoData = video;
|
2016-06-28 05:16:52 +00:00
|
|
|
mDoneVideoSeeking = true;
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-29 09:06:00 +00:00
|
|
|
AccurateSeekTask::MaybeFinishSeek()
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-28 05:16:52 +00:00
|
|
|
if (mDoneAudioSeeking && mDoneVideoSeeking) {
|
2016-05-24 03:02:57 +00:00
|
|
|
Resolve(__func__); // Call to MDSM::SeekCompleted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccurateSeekTask::OnSeekResolved(media::TimeUnit)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
mSeekRequest.Complete();
|
|
|
|
// We must decode the first samples of active streams, so we can determine
|
|
|
|
// the new stream time. So dispatch tasks to do that.
|
2016-06-28 05:16:52 +00:00
|
|
|
if (!mDoneVideoSeeking) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestVideoData();
|
2016-06-28 05:16:52 +00:00
|
|
|
}
|
|
|
|
if (!mDoneAudioSeeking) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestAudioData();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccurateSeekTask::OnSeekRejected(nsresult aResult)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
|
|
|
mSeekRequest.Complete();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResult), "Cancels should also disconnect mSeekRequest");
|
|
|
|
RejectIfExist(__func__);
|
|
|
|
}
|
|
|
|
|
2016-06-28 09:07:34 +00:00
|
|
|
void
|
|
|
|
AccurateSeekTask::AdjustFastSeekIfNeeded(MediaData* aSample)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-30 05:37:20 +00:00
|
|
|
if (mTarget.IsFast() &&
|
|
|
|
mTarget.GetTime() > mCurrentTimeBeforeSeek &&
|
2016-06-28 09:16:31 +00:00
|
|
|
aSample->mTime < mCurrentTimeBeforeSeek.ToMicroseconds()) {
|
2016-06-28 09:07:34 +00:00
|
|
|
// We are doing a fastSeek, but we ended up *before* the previous
|
|
|
|
// playback position. This is surprising UX, so switch to an accurate
|
|
|
|
// seek and decode to the seek target. This is not conformant to the
|
|
|
|
// spec, fastSeek should always be fast, but until we get the time to
|
|
|
|
// change all Readers to seek to the keyframe after the currentTime
|
|
|
|
// in this case, we'll just decode forward. Bug 1026330.
|
2016-06-30 05:37:20 +00:00
|
|
|
mTarget.SetType(SeekTarget::Accurate);
|
2016-06-28 09:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-24 03:02:57 +00:00
|
|
|
void
|
|
|
|
AccurateSeekTask::OnAudioDecoded(MediaData* aAudioSample)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-28 03:46:37 +00:00
|
|
|
MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
RefPtr<MediaData> audio(aAudioSample);
|
|
|
|
MOZ_ASSERT(audio);
|
|
|
|
|
|
|
|
// The MDSM::mDecodedAudioEndTime will be updated once the whole SeekTask is
|
|
|
|
// resolved.
|
|
|
|
|
|
|
|
SAMPLE_LOG("OnAudioDecoded [%lld,%lld] disc=%d",
|
2016-06-28 03:26:22 +00:00
|
|
|
audio->mTime, audio->GetEndTime(), audio->mDiscontinuity);
|
2016-05-24 03:02:57 +00:00
|
|
|
|
2016-07-08 03:52:40 +00:00
|
|
|
// Video-only seek doesn't reset audio decoder. There might be pending audio
|
|
|
|
// requests when AccurateSeekTask::Seek() begins. We will just store the data
|
|
|
|
// without checking |mDiscontinuity| or calling DropAudioUpToSeekTarget().
|
2016-07-05 05:58:51 +00:00
|
|
|
if (mTarget.IsVideoOnly()) {
|
2016-07-08 03:52:40 +00:00
|
|
|
mSeekedAudioData = audio.forget();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-29 08:52:09 +00:00
|
|
|
if (mFirstAudioSample) {
|
|
|
|
mFirstAudioSample = false;
|
|
|
|
MOZ_ASSERT(audio->mDiscontinuity);
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 08:52:09 +00:00
|
|
|
AdjustFastSeekIfNeeded(audio);
|
2016-06-28 09:07:34 +00:00
|
|
|
|
2016-06-30 05:37:20 +00:00
|
|
|
if (mTarget.IsFast()) {
|
2016-06-29 08:52:09 +00:00
|
|
|
// Non-precise seek; we can stop the seek at the first sample.
|
|
|
|
mSeekedAudioData = audio;
|
|
|
|
mDoneAudioSeeking = true;
|
|
|
|
} else if (NS_FAILED(DropAudioUpToSeekTarget(audio))) {
|
2016-07-07 06:30:54 +00:00
|
|
|
CancelCallbacks();
|
2016-06-29 08:52:09 +00:00
|
|
|
RejectIfExist(__func__);
|
|
|
|
return;
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
2016-06-29 08:52:09 +00:00
|
|
|
|
2016-06-29 09:06:00 +00:00
|
|
|
if (!mDoneAudioSeeking) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestAudioData();
|
2016-06-29 09:06:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
MaybeFinishSeek();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-28 08:54:38 +00:00
|
|
|
AccurateSeekTask::OnNotDecoded(MediaData::Type aType,
|
|
|
|
MediaDecoderReader::NotDecodedReason aReason)
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-28 03:46:37 +00:00
|
|
|
MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
|
|
|
|
|
2016-06-28 08:54:38 +00:00
|
|
|
SAMPLE_LOG("OnNotDecoded type=%d reason=%u", aType, aReason);
|
2016-05-24 03:02:57 +00:00
|
|
|
|
2016-07-08 03:52:40 +00:00
|
|
|
// Ignore pending requests from video-only seek.
|
2016-07-05 05:58:51 +00:00
|
|
|
if (aType == MediaData::AUDIO_DATA && mTarget.IsVideoOnly()) {
|
2016-07-08 03:52:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-24 03:02:57 +00:00
|
|
|
if (aReason == MediaDecoderReader::DECODE_ERROR) {
|
|
|
|
// If this is a decode error, delegate to the generic error path.
|
2016-07-07 06:30:54 +00:00
|
|
|
CancelCallbacks();
|
2016-05-24 03:02:57 +00:00
|
|
|
RejectIfExist(__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the decoder is waiting for data, we tell it to call us back when the
|
|
|
|
// data arrives.
|
|
|
|
if (aReason == MediaDecoderReader::WAITING_FOR_DATA) {
|
2016-06-28 08:54:38 +00:00
|
|
|
mReader->WaitForData(aType);
|
2016-05-24 03:02:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aReason == MediaDecoderReader::CANCELED) {
|
2016-06-28 08:54:38 +00:00
|
|
|
if (aType == MediaData::AUDIO_DATA) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestAudioData();
|
2016-06-28 08:54:38 +00:00
|
|
|
} else {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestVideoData();
|
2016-06-28 08:54:38 +00:00
|
|
|
}
|
2016-05-24 03:02:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aReason == MediaDecoderReader::END_OF_STREAM) {
|
2016-06-28 08:54:38 +00:00
|
|
|
if (aType == MediaData::AUDIO_DATA) {
|
|
|
|
mIsAudioQueueFinished = true;
|
|
|
|
mDoneAudioSeeking = true;
|
|
|
|
} else {
|
|
|
|
mIsVideoQueueFinished = true;
|
|
|
|
mDoneVideoSeeking = true;
|
|
|
|
if (mFirstVideoFrameAfterSeek) {
|
|
|
|
// Hit the end of stream. Move mFirstVideoFrameAfterSeek into
|
|
|
|
// mSeekedVideoData so we have something to display after seeking.
|
|
|
|
mSeekedVideoData = mFirstVideoFrameAfterSeek.forget();
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 09:06:00 +00:00
|
|
|
MaybeFinishSeek();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccurateSeekTask::OnVideoDecoded(MediaData* aVideoSample)
|
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-06-28 03:46:37 +00:00
|
|
|
MOZ_ASSERT(!mSeekTaskPromise.IsEmpty(), "Seek shouldn't be finished");
|
2016-05-24 03:02:57 +00:00
|
|
|
|
|
|
|
RefPtr<MediaData> video(aVideoSample);
|
|
|
|
MOZ_ASSERT(video);
|
|
|
|
|
|
|
|
// The MDSM::mDecodedVideoEndTime will be updated once the whole SeekTask is
|
|
|
|
// resolved.
|
|
|
|
|
|
|
|
SAMPLE_LOG("OnVideoDecoded [%lld,%lld] disc=%d",
|
2016-06-28 03:26:22 +00:00
|
|
|
video->mTime, video->GetEndTime(), video->mDiscontinuity);
|
2016-05-24 03:02:57 +00:00
|
|
|
|
2016-06-29 08:52:09 +00:00
|
|
|
if (mFirstVideoSample) {
|
|
|
|
mFirstVideoSample = false;
|
|
|
|
MOZ_ASSERT(video->mDiscontinuity);
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 08:52:09 +00:00
|
|
|
AdjustFastSeekIfNeeded(video);
|
2016-06-28 09:07:34 +00:00
|
|
|
|
2016-06-30 05:37:20 +00:00
|
|
|
if (mTarget.IsFast()) {
|
2016-06-29 08:52:09 +00:00
|
|
|
// Non-precise seek. We can stop the seek at the first sample.
|
|
|
|
mSeekedVideoData = video;
|
|
|
|
mDoneVideoSeeking = true;
|
|
|
|
} else if (NS_FAILED(DropVideoUpToSeekTarget(video.get()))) {
|
2016-07-07 06:30:54 +00:00
|
|
|
CancelCallbacks();
|
2016-06-29 08:52:09 +00:00
|
|
|
RejectIfExist(__func__);
|
|
|
|
return;
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
2016-06-29 08:52:09 +00:00
|
|
|
|
2016-06-29 09:06:00 +00:00
|
|
|
if (!mDoneVideoSeeking) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestVideoData();
|
2016-06-29 09:06:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
MaybeFinishSeek();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-28 03:59:43 +00:00
|
|
|
AccurateSeekTask::SetCallbacks()
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
|
|
|
|
2016-06-14 03:22:45 +00:00
|
|
|
mAudioCallback = mReader->AudioCallback().Connect(
|
|
|
|
OwnerThread(), [this] (AudioCallbackData aData) {
|
|
|
|
if (aData.is<MediaData*>()) {
|
|
|
|
OnAudioDecoded(aData.as<MediaData*>());
|
|
|
|
} else {
|
2016-06-28 08:54:38 +00:00
|
|
|
OnNotDecoded(MediaData::AUDIO_DATA,
|
|
|
|
aData.as<MediaDecoderReader::NotDecodedReason>());
|
2016-06-14 03:22:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mVideoCallback = mReader->VideoCallback().Connect(
|
|
|
|
OwnerThread(), [this] (VideoCallbackData aData) {
|
|
|
|
typedef Tuple<MediaData*, TimeStamp> Type;
|
|
|
|
if (aData.is<Type>()) {
|
|
|
|
OnVideoDecoded(Get<0>(aData.as<Type>()));
|
|
|
|
} else {
|
2016-06-28 08:54:38 +00:00
|
|
|
OnNotDecoded(MediaData::VIDEO_DATA,
|
|
|
|
aData.as<MediaDecoderReader::NotDecodedReason>());
|
2016-06-14 03:22:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mAudioWaitCallback = mReader->AudioWaitCallback().Connect(
|
|
|
|
OwnerThread(), [this] (WaitCallbackData aData) {
|
2016-07-08 03:52:40 +00:00
|
|
|
// Ignore pending requests from video-only seek.
|
2016-07-05 05:58:51 +00:00
|
|
|
if (mTarget.IsVideoOnly()) {
|
2016-07-08 03:52:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-14 03:22:45 +00:00
|
|
|
if (aData.is<MediaData::Type>()) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestAudioData();
|
2016-06-14 03:22:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mVideoWaitCallback = mReader->VideoWaitCallback().Connect(
|
|
|
|
OwnerThread(), [this] (WaitCallbackData aData) {
|
|
|
|
if (aData.is<MediaData::Type>()) {
|
2016-07-05 09:00:28 +00:00
|
|
|
RequestVideoData();
|
2016-06-14 03:22:45 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-28 03:59:43 +00:00
|
|
|
AccurateSeekTask::CancelCallbacks()
|
2016-05-24 03:02:57 +00:00
|
|
|
{
|
|
|
|
AssertOwnerThread();
|
2016-07-07 06:30:54 +00:00
|
|
|
mAudioCallback.DisconnectIfExists();
|
|
|
|
mVideoCallback.DisconnectIfExists();
|
|
|
|
mAudioWaitCallback.DisconnectIfExists();
|
|
|
|
mVideoWaitCallback.DisconnectIfExists();
|
2016-05-24 03:02:57 +00:00
|
|
|
}
|
|
|
|
} // namespace mozilla
|