2016-04-14 07:01:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef SEEK_TASK_H
|
|
|
|
#define SEEK_TASK_H
|
|
|
|
|
|
|
|
#include "mozilla/MozPromise.h"
|
2016-04-27 09:50:39 +03:00
|
|
|
#include "MediaCallbackID.h"
|
2016-04-14 07:01:55 +03:00
|
|
|
#include "MediaDecoderReader.h"
|
|
|
|
#include "SeekJob.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class AbstractThread;
|
|
|
|
class MediaData;
|
|
|
|
class MediaDecoderReaderWrapper;
|
|
|
|
|
|
|
|
struct SeekTaskResolveValue
|
|
|
|
{
|
|
|
|
RefPtr<MediaData> mSeekedAudioData;
|
|
|
|
RefPtr<MediaData> mSeekedVideoData;
|
|
|
|
bool mIsAudioQueueFinished;
|
|
|
|
bool mIsVideoQueueFinished;
|
|
|
|
bool mNeedToStopPrerollingAudio;
|
|
|
|
bool mNeedToStopPrerollingVideo;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SeekTaskRejectValue
|
|
|
|
{
|
|
|
|
bool mIsAudioQueueFinished;
|
|
|
|
bool mIsVideoQueueFinished;
|
|
|
|
bool mNeedToStopPrerollingAudio;
|
|
|
|
bool mNeedToStopPrerollingVideo;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SeekTask {
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SeekTask)
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const bool IsExclusive = true;
|
|
|
|
|
|
|
|
using SeekTaskPromise =
|
|
|
|
MozPromise<SeekTaskResolveValue, SeekTaskRejectValue, IsExclusive>;
|
|
|
|
|
|
|
|
static already_AddRefed<SeekTask>
|
|
|
|
CreateSeekTask(const void* aDecoderID,
|
|
|
|
AbstractThread* aThread,
|
2016-04-19 11:14:46 +03:00
|
|
|
MediaDecoderReaderWrapper* aReader,
|
2016-04-14 07:01:55 +03:00
|
|
|
SeekJob&& aSeekJob,
|
|
|
|
const MediaInfo& aInfo,
|
|
|
|
const media::TimeUnit& aDuration,
|
|
|
|
int64_t aCurrentMediaTime);
|
|
|
|
|
|
|
|
virtual void Discard();
|
|
|
|
|
|
|
|
virtual RefPtr<SeekTaskPromise> Seek(const media::TimeUnit& aDuration);
|
|
|
|
|
|
|
|
virtual bool NeedToResetMDSM() const;
|
|
|
|
|
|
|
|
SeekJob& GetSeekJob();
|
|
|
|
|
2016-04-18 09:33:52 +03:00
|
|
|
bool Exists() const;
|
2016-04-14 07:01:55 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SeekTask(const void* aDecoderID,
|
|
|
|
AbstractThread* aThread,
|
2016-04-19 11:14:46 +03:00
|
|
|
MediaDecoderReaderWrapper* aReader,
|
2016-04-14 07:01:55 +03:00
|
|
|
SeekJob&& aSeekJob,
|
|
|
|
const MediaInfo& aInfo,
|
|
|
|
const media::TimeUnit& aDuration,
|
|
|
|
int64_t aCurrentMediaTime);
|
|
|
|
|
|
|
|
virtual ~SeekTask();
|
|
|
|
|
|
|
|
void Resolve(const char* aCallSite);
|
|
|
|
|
|
|
|
void RejectIfExist(const char* aCallSite);
|
|
|
|
|
|
|
|
void AssertOwnerThread() const;
|
|
|
|
|
|
|
|
bool HasAudio() const;
|
|
|
|
|
|
|
|
bool HasVideo() const;
|
|
|
|
|
|
|
|
TaskQueue* DecodeTaskQueue() const;
|
|
|
|
|
|
|
|
AbstractThread* OwnerThread() const;
|
|
|
|
|
|
|
|
bool IsVideoDecoding() const;
|
|
|
|
|
|
|
|
bool IsAudioDecoding() const;
|
|
|
|
|
|
|
|
nsresult EnsureVideoDecodeTaskQueued();
|
|
|
|
|
|
|
|
nsresult EnsureAudioDecodeTaskQueued();
|
|
|
|
|
|
|
|
const char* AudioRequestStatus();
|
|
|
|
|
|
|
|
const char* VideoRequestStatus();
|
|
|
|
|
|
|
|
void RequestVideoData();
|
|
|
|
|
|
|
|
void RequestAudioData();
|
|
|
|
|
|
|
|
nsresult DropAudioUpToSeekTarget(MediaData* aSample);
|
|
|
|
|
|
|
|
nsresult DropVideoUpToSeekTarget(MediaData* aSample);
|
|
|
|
|
|
|
|
bool IsAudioSeekComplete();
|
|
|
|
|
|
|
|
bool IsVideoSeekComplete();
|
|
|
|
|
|
|
|
void CheckIfSeekComplete();
|
|
|
|
|
|
|
|
virtual void OnSeekResolved(media::TimeUnit);
|
|
|
|
|
|
|
|
virtual void OnSeekRejected(nsresult aResult);
|
|
|
|
|
|
|
|
virtual void OnAudioDecoded(MediaData* aAudioSample);
|
|
|
|
|
|
|
|
virtual void OnAudioNotDecoded(MediaDecoderReader::NotDecodedReason aReason);
|
|
|
|
|
|
|
|
virtual void OnVideoDecoded(MediaData* aVideoSample);
|
|
|
|
|
|
|
|
virtual void OnVideoNotDecoded(MediaDecoderReader::NotDecodedReason aReason);
|
|
|
|
|
2016-04-27 09:50:39 +03:00
|
|
|
void SetMediaDecoderReaderWrapperCallback();
|
|
|
|
|
|
|
|
void CancelMediaDecoderReaderWrapperCallback();
|
|
|
|
|
2016-04-14 07:01:55 +03:00
|
|
|
/*
|
|
|
|
* Data shared with MDSM.
|
|
|
|
*/
|
|
|
|
const void* mDecoderID; // For logging.
|
|
|
|
const RefPtr<AbstractThread> mOwnerThread;
|
2016-04-19 11:14:46 +03:00
|
|
|
const RefPtr<MediaDecoderReaderWrapper> mReader;
|
2016-04-14 07:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal state.
|
|
|
|
*/
|
|
|
|
SeekJob mSeekJob;
|
|
|
|
MozPromiseHolder<SeekTaskPromise> mSeekTaskPromise;
|
|
|
|
int64_t mCurrentTimeBeforeSeek;
|
|
|
|
const uint32_t mAudioRate; // Audio sample rate.
|
|
|
|
const bool mHasAudio;
|
|
|
|
const bool mHasVideo;
|
|
|
|
bool mDropAudioUntilNextDiscontinuity;
|
|
|
|
bool mDropVideoUntilNextDiscontinuity;
|
|
|
|
bool mIsDiscarded;
|
|
|
|
|
|
|
|
// This temporarily stores the first frame we decode after we seek.
|
|
|
|
// This is so that if we hit end of stream while we're decoding to reach
|
|
|
|
// the seek target, we will still have a frame that we can display as the
|
|
|
|
// last frame in the media.
|
|
|
|
RefPtr<MediaData> mFirstVideoFrameAfterSeek;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Track the current seek promise made by the reader.
|
|
|
|
*/
|
|
|
|
MozPromiseRequestHolder<MediaDecoderReader::SeekPromise> mSeekRequest;
|
2016-04-27 09:50:39 +03:00
|
|
|
CallbackID mAudioCallbackID;
|
|
|
|
CallbackID mVideoCallbackID;
|
2016-05-19 14:02:20 +03:00
|
|
|
CallbackID mWaitAudioCallbackID;
|
|
|
|
CallbackID mWaitVideoCallbackID;
|
2016-04-14 07:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Information which are going to be returned to MDSM.
|
|
|
|
*/
|
|
|
|
RefPtr<MediaData> mSeekedAudioData;
|
|
|
|
RefPtr<MediaData> mSeekedVideoData;
|
|
|
|
bool mIsAudioQueueFinished;
|
|
|
|
bool mIsVideoQueueFinished;
|
|
|
|
bool mNeedToStopPrerollingAudio;
|
|
|
|
bool mNeedToStopPrerollingVideo;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* SEEK_TASK_H */
|