Bug 1097823 - Move NotDecodedReason from RequestSampleCallback to MediaDecoderReader. r=cpearce

This commit is contained in:
Bobby Holley 2014-12-08 14:45:36 -08:00
Родитель 1eb5757054
Коммит 8c9d29f7fe
10 изменённых файлов: 43 добавлений и 48 удалений

Просмотреть файл

@ -20,8 +20,6 @@ class MediaData;
template<class Target>
class MediaDataDecodedListener : public RequestSampleCallback {
public:
using RequestSampleCallback::NotDecodedReason;
MediaDataDecodedListener(Target* aTarget,
MediaTaskQueue* aTaskQueue)
: mMonitor("MediaDataDecodedListener")
@ -52,7 +50,8 @@ public:
mTaskQueue->Dispatch(task);
}
virtual void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) MOZ_OVERRIDE {
virtual void OnNotDecoded(MediaData::Type aType,
MediaDecoderReader::NotDecodedReason aReason) MOZ_OVERRIDE {
MonitorAutoLock lock(mMonitor);
if (!mTarget || !mTaskQueue) {
// We've been shutdown, abort.
@ -133,7 +132,7 @@ private:
class DeliverNotDecodedTask : public nsRunnable {
public:
DeliverNotDecodedTask(MediaData::Type aType,
RequestSampleCallback::NotDecodedReason aReason,
MediaDecoderReader::NotDecodedReason aReason,
Target* aTarget)
: mType(aType)
, mReason(aReason)
@ -153,7 +152,7 @@ private:
}
private:
MediaData::Type mType;
RequestSampleCallback::NotDecodedReason mReason;
MediaDecoderReader::NotDecodedReason mReason;
RefPtr<Target> mTarget;
};

Просмотреть файл

@ -204,7 +204,7 @@ MediaDecoderReader::RequestVideoData(bool aSkipToNextKeyframe,
}
GetCallback()->OnVideoDecoded(v);
} else if (VideoQueue().IsFinished()) {
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, END_OF_STREAM);
}
}
@ -237,7 +237,7 @@ MediaDecoderReader::RequestAudioData()
GetCallback()->OnAudioDecoded(a);
return;
} else if (AudioQueue().IsFinished()) {
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, END_OF_STREAM);
return;
}
}
@ -307,12 +307,13 @@ AudioDecodeRendezvous::OnAudioDecoded(AudioData* aSample)
}
void
AudioDecodeRendezvous::OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason)
AudioDecodeRendezvous::OnNotDecoded(MediaData::Type aType,
MediaDecoderReader::NotDecodedReason aReason)
{
MOZ_ASSERT(aType == MediaData::AUDIO_DATA);
MonitorAutoLock mon(mMonitor);
mSample = nullptr;
mStatus = aReason == DECODE_ERROR ? NS_ERROR_FAILURE : NS_OK;
mStatus = aReason == MediaDecoderReader::DECODE_ERROR ? NS_ERROR_FAILURE : NS_OK;
mHaveResult = true;
mon.NotifyAll();
}

Просмотреть файл

@ -30,6 +30,13 @@ class SharedDecoderManager;
// be accessed on the decode task queue.
class MediaDecoderReader {
public:
enum NotDecodedReason {
END_OF_STREAM,
DECODE_ERROR,
WAITING_FOR_DATA,
CANCELED
};
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderReader)
explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder);
@ -290,13 +297,6 @@ class RequestSampleCallback {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RequestSampleCallback)
enum NotDecodedReason {
END_OF_STREAM,
DECODE_ERROR,
WAITING_FOR_DATA,
CANCELED
};
// Receives the result of a RequestAudioData() call.
virtual void OnAudioDecoded(AudioData* aSample) = 0;
@ -305,7 +305,8 @@ public:
// Called when a RequestAudioData() or RequestVideoData() call can't be
// fulfiled. The reason is passed as aReason.
virtual void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) = 0;
virtual void OnNotDecoded(MediaData::Type aType,
MediaDecoderReader::NotDecodedReason aReason) = 0;
virtual void OnSeekCompleted(nsresult aResult) = 0;
@ -322,8 +323,6 @@ protected:
// model of the MediaDecoderReader to a synchronous model.
class AudioDecodeRendezvous : public RequestSampleCallback {
public:
using RequestSampleCallback::NotDecodedReason;
AudioDecodeRendezvous();
~AudioDecodeRendezvous();
@ -331,7 +330,8 @@ public:
// Note: aSample is null at end of stream.
virtual void OnAudioDecoded(AudioData* aSample) MOZ_OVERRIDE;
virtual void OnVideoDecoded(VideoData* aSample) MOZ_OVERRIDE {}
virtual void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) MOZ_OVERRIDE;
virtual void OnNotDecoded(MediaData::Type aType,
MediaDecoderReader::NotDecodedReason aReason) MOZ_OVERRIDE;
virtual void OnSeekCompleted(nsresult aResult) MOZ_OVERRIDE {};
virtual void BreakCycles() MOZ_OVERRIDE {};
void Reset();

Просмотреть файл

@ -805,7 +805,7 @@ MediaDecoderStateMachine::Push(VideoData* aSample)
void
MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType,
RequestSampleCallback::NotDecodedReason aReason)
MediaDecoderReader::NotDecodedReason aReason)
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
SAMPLE_LOG("OnNotDecoded (aType=%u, aReason=%u)", aType, aReason);
@ -820,7 +820,7 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType,
}
// If this is a decode error, delegate to the generic error path.
if (aReason == RequestSampleCallback::DECODE_ERROR) {
if (aReason == MediaDecoderReader::DECODE_ERROR) {
DecodeError();
return;
}
@ -828,7 +828,7 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType,
// If the decoder is waiting for data, we need to make sure that the requests
// are cleared, which happened above. Additionally, if we're out of decoded
// samples, we need to switch to buffering mode.
if (aReason == RequestSampleCallback::WAITING_FOR_DATA) {
if (aReason == MediaDecoderReader::WAITING_FOR_DATA) {
bool outOfSamples = isAudio ? !AudioQueue().GetSize() : !VideoQueue().GetSize();
if (outOfSamples) {
StartBuffering();
@ -837,14 +837,14 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType,
return;
}
if (aReason == RequestSampleCallback::CANCELED) {
if (aReason == MediaDecoderReader::CANCELED) {
DispatchDecodeTasksIfNeeded();
return;
}
// This is an EOS. Finish off the queue, and then handle things based on our
// state.
MOZ_ASSERT(aReason == RequestSampleCallback::END_OF_STREAM);
MOZ_ASSERT(aReason == MediaDecoderReader::END_OF_STREAM);
if (!isAudio && mState == DECODER_STATE_SEEKING &&
mCurrentSeekTarget.IsValid() && mFirstVideoFrameAfterSeek) {
// Null sample. Hit end of stream. If we have decoded a frame,

Просмотреть файл

@ -373,7 +373,7 @@ public:
void OnAudioDecoded(AudioData* aSample);
void OnVideoDecoded(VideoData* aSample);
void OnNotDecoded(MediaData::Type aType, RequestSampleCallback::NotDecodedReason aReason);
void OnNotDecoded(MediaData::Type aType, MediaDecoderReader::NotDecodedReason aReason);
void OnSeekCompleted(nsresult aResult);
private:

Просмотреть файл

@ -666,8 +666,7 @@ MP4Reader::ReturnOutput(MediaData* aData, TrackType aTrack)
void
MP4Reader::ReturnEOS(TrackType aTrack)
{
GetCallback()->OnNotDecoded(aTrack == kAudio ? MediaData::AUDIO_DATA : MediaData::VIDEO_DATA,
RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(aTrack == kAudio ? MediaData::AUDIO_DATA : MediaData::VIDEO_DATA, END_OF_STREAM);
}
MP4Sample*
@ -753,8 +752,7 @@ MP4Reader::Error(TrackType aTrack)
MonitorAutoLock mon(data.mMonitor);
data.mError = true;
}
GetCallback()->OnNotDecoded(aTrack == kVideo ? MediaData::VIDEO_DATA : MediaData::AUDIO_DATA,
RequestSampleCallback::DECODE_ERROR);
GetCallback()->OnNotDecoded(aTrack == kVideo ? MediaData::VIDEO_DATA : MediaData::AUDIO_DATA, DECODE_ERROR);
}
void
@ -784,8 +782,7 @@ MP4Reader::Flush(TrackType aTrack)
data.mNumSamplesOutput = 0;
data.mInputExhausted = false;
if (data.mOutputRequested) {
GetCallback()->OnNotDecoded(aTrack == kVideo ? MediaData::VIDEO_DATA : MediaData::AUDIO_DATA,
RequestSampleCallback::CANCELED);
GetCallback()->OnNotDecoded(aTrack == kVideo ? MediaData::VIDEO_DATA : MediaData::AUDIO_DATA, CANCELED);
}
data.mOutputRequested = false;
data.mDiscontinuity = true;
@ -810,8 +807,7 @@ MP4Reader::SkipVideoDemuxToNextKeyFrame(int64_t aTimeThreshold, uint32_t& parsed
nsAutoPtr<MP4Sample> compressed(PopSample(kVideo));
if (!compressed) {
// EOS, or error. Let the state machine know.
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA,
RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, END_OF_STREAM);
{
MonitorAutoLock mon(mVideo.mMonitor);
mVideo.mDemuxEOS = true;

Просмотреть файл

@ -100,7 +100,7 @@ MediaSourceReader::RequestAudioData()
MSE_DEBUGV("MediaSourceReader(%p)::RequestAudioData", this);
if (!mAudioReader) {
MSE_DEBUG("MediaSourceReader(%p)::RequestAudioData called with no audio reader", this);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR);
return;
}
mAudioIsSeeking = false;
@ -139,7 +139,7 @@ MediaSourceReader::RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThres
this, aSkipToNextKeyframe, aTimeThreshold);
if (!mVideoReader) {
MSE_DEBUG("MediaSourceReader(%p)::RequestVideoData called with no video reader", this);
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, RequestSampleCallback::DECODE_ERROR);
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, DECODE_ERROR);
return;
}
if (aSkipToNextKeyframe) {
@ -177,17 +177,16 @@ MediaSourceReader::OnVideoDecoded(VideoData* aSample)
}
void
MediaSourceReader::OnNotDecoded(MediaData::Type aType, RequestSampleCallback::NotDecodedReason aReason)
MediaSourceReader::OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason)
{
MSE_DEBUG("MediaSourceReader(%p)::OnNotDecoded aType=%u aReason=%u IsEnded: %d", this, aType, aReason, IsEnded());
if (aReason == RequestSampleCallback::DECODE_ERROR ||
aReason == RequestSampleCallback::CANCELED) {
if (aReason == DECODE_ERROR || aReason == CANCELED) {
GetCallback()->OnNotDecoded(aType, aReason);
return;
}
// End of stream. Force switching past this stream to another reader by
// switching to the end of the buffered range.
MOZ_ASSERT(aReason == RequestSampleCallback::END_OF_STREAM);
MOZ_ASSERT(aReason == END_OF_STREAM);
nsRefPtr<MediaDecoderReader> reader = aType == MediaData::AUDIO_DATA ?
mAudioReader : mVideoReader;
@ -228,13 +227,13 @@ MediaSourceReader::OnNotDecoded(MediaData::Type aType, RequestSampleCallback::No
// If the entire MediaSource is done, generate an EndOfStream.
if (IsEnded()) {
GetCallback()->OnNotDecoded(aType, RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(aType, END_OF_STREAM);
return;
}
// We don't have the data the caller wants. Tell that we're waiting for JS to
// give us more data.
GetCallback()->OnNotDecoded(aType, RequestSampleCallback::WAITING_FOR_DATA);
GetCallback()->OnNotDecoded(aType, WAITING_FOR_DATA);
}
void

Просмотреть файл

@ -54,7 +54,7 @@ public:
void OnVideoDecoded(VideoData* aSample);
void OnNotDecoded(MediaData::Type aType, RequestSampleCallback::NotDecodedReason aReason);
void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason);
void OnSeekCompleted(nsresult aResult);

Просмотреть файл

@ -488,7 +488,7 @@ MediaCodecReader::DecodeAudioDataTask()
}
}
if (AudioQueue().AtEndOfStream()) {
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, END_OF_STREAM);
}
return result;
}
@ -508,7 +508,7 @@ MediaCodecReader::DecodeVideoFrameTask(int64_t aTimeThreshold)
}
}
if (VideoQueue().AtEndOfStream()) {
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, RequestSampleCallback::END_OF_STREAM);
GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, END_OF_STREAM);
}
return result;
}

Просмотреть файл

@ -743,7 +743,7 @@ bool WebMReader::DecodeOpus(const unsigned char* aData, size_t aLength,
// Discard padding should be used only on the final packet, so
// decoding after a padding discard is invalid.
LOG(PR_LOG_DEBUG, ("Opus error, discard padding on interstitial packet"));
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR);
return false;
}
@ -797,7 +797,7 @@ bool WebMReader::DecodeOpus(const unsigned char* aData, size_t aLength,
if (discardPadding < 0) {
// Negative discard padding is invalid.
LOG(PR_LOG_DEBUG, ("Opus error, negative discard padding"));
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR);
return false;
}
if (discardPadding > 0) {
@ -810,7 +810,7 @@ bool WebMReader::DecodeOpus(const unsigned char* aData, size_t aLength,
if (discardFrames.value() > frames) {
// Discarding more than the entire packet is invalid.
LOG(PR_LOG_DEBUG, ("Opus error, discard padding larger than packet"));
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR);
GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR);
return false;
}
LOG(PR_LOG_DEBUG, ("Opus decoder discarding %d of %d frames",