Bug 1138253 - Clean up AutoNotifyDecoded; r=cpearce

This commit is contained in:
Anthony Jones 2015-03-03 17:46:46 +13:00
parent c88a00a5d4
commit 1610a3a893
9 changed files with 32 additions and 40 deletions

View File

@ -137,17 +137,18 @@ public:
// to ensure all parsed and decoded frames are reported on all return paths.
class AutoNotifyDecoded {
public:
AutoNotifyDecoded(AbstractMediaDecoder* aDecoder, uint32_t& aParsed, uint32_t& aDecoded)
: mDecoder(aDecoder), mParsed(aParsed), mDecoded(aDecoded) {}
explicit AutoNotifyDecoded(AbstractMediaDecoder* aDecoder)
: mParsed(0), mDecoded(0), mDecoder(aDecoder) {}
~AutoNotifyDecoded() {
if (mDecoder) {
mDecoder->NotifyDecodedFrames(mParsed, mDecoded);
}
}
uint32_t mParsed;
uint32_t mDecoded;
private:
AbstractMediaDecoder* mDecoder;
uint32_t& mParsed;
uint32_t& mDecoded;
};
#ifdef MOZ_EME

View File

@ -125,8 +125,7 @@ bool AndroidMediaReader::DecodeVideoFrame(bool &aKeyframeSkip,
{
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
// Throw away the currently buffered frame if we are seeking.
if (mLastVideoFrame && mVideoSeekTimeUs != -1) {
@ -162,7 +161,7 @@ bool AndroidMediaReader::DecodeVideoFrame(bool &aKeyframeSkip,
// when a frame is a keyframe.
#if 0
if (!frame.mKeyFrame) {
++parsed;
++a.mParsed;
continue;
}
#endif
@ -250,8 +249,8 @@ bool AndroidMediaReader::DecodeVideoFrame(bool &aKeyframeSkip,
if (!v) {
return false;
}
parsed++;
decoded++;
a.mParsed++;
a.mDecoded++;
NS_ASSERTION(decoded <= parsed, "Expect to decode fewer frames than parsed in AndroidMedia...");
// Since MPAPI doesn't give us the end time of frames, we keep one frame

View File

@ -672,8 +672,7 @@ MP4Reader::Update(TrackType aTrack)
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
bool needInput = false;
bool needOutput = false;
@ -688,7 +687,7 @@ MP4Reader::Update(TrackType aTrack)
}
if (aTrack == kVideo) {
uint64_t delta = decoder.mNumSamplesOutput - mLastReportedNumDecodedFrames;
decoded = static_cast<uint32_t>(delta);
a.mDecoded = static_cast<uint32_t>(delta);
mLastReportedNumDecodedFrames = decoder.mNumSamplesOutput;
}
if (decoder.HasPromise()) {
@ -722,7 +721,7 @@ MP4Reader::Update(TrackType aTrack)
if (sample) {
decoder.mDecoder->Input(sample);
if (aTrack == kVideo) {
parsed++;
a.mParsed++;
}
} else {
{

View File

@ -899,8 +899,7 @@ bool OggReader::DecodeVideoFrame(bool &aKeyframeSkip,
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
// Read the next data packet. Skip any non-data packets we encounter.
ogg_packet* packet = 0;
@ -915,7 +914,7 @@ bool OggReader::DecodeVideoFrame(bool &aKeyframeSkip,
}
nsAutoRef<ogg_packet> autoRelease(packet);
parsed++;
a.mParsed++;
NS_ASSERTION(packet && packet->granulepos != -1,
"Must know first packet's granulepos");
bool eos = packet->e_o_s;
@ -925,7 +924,7 @@ bool OggReader::DecodeVideoFrame(bool &aKeyframeSkip,
{
aKeyframeSkip = false;
nsresult res = DecodeTheora(packet, aTimeThreshold);
decoded++;
a.mDecoded++;
if (NS_FAILED(res)) {
return false;
}

View File

@ -370,8 +370,7 @@ bool MediaOmxReader::DecodeVideoFrame(bool &aKeyframeSkip,
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
bool doSeek = mVideoSeekTimeUs != -1;
if (doSeek) {
@ -473,7 +472,7 @@ bool MediaOmxReader::DecodeVideoFrame(bool &aKeyframeSkip,
return false;
}
decoded++;
a.mDecoded++;
NS_ASSERTION(decoded <= parsed, "Expect to decode fewer frames than parsed in OMX decoder...");
mVideoQueue.Push(v);

View File

@ -157,8 +157,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip,
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
if (!mFrameSize)
return false; // Metadata read failed. We should refuse to play.
@ -185,7 +184,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip,
return false;
}
parsed++;
a.mParsed++;
if (currentFrameTime >= aTimeThreshold)
break;
@ -229,7 +228,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip,
mVideoQueue.Push(v);
mCurrentFrame++;
decoded++;
a.mDecoded++;
currentFrameTime += USECS_PER_S / mFrameRate;
return true;

View File

@ -337,13 +337,12 @@ bool
IntelWebMVideoDecoder::DecodeVideoFrame(bool& aKeyframeSkip,
int64_t aTimeThreshold)
{
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mReader->GetDecoder(), parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mReader->GetDecoder());
MOZ_ASSERT(mPlatform && mReader->GetDecoder());
if (aKeyframeSkip) {
bool ok = SkipVideoDemuxToNextKeyFrame(aTimeThreshold, parsed);
bool ok = SkipVideoDemuxToNextKeyFrame(aTimeThreshold, a.mParsed);
if (!ok) {
NS_WARNING("Failed to skip demux up to next keyframe");
return false;
@ -360,7 +359,7 @@ IntelWebMVideoDecoder::DecodeVideoFrame(bool& aKeyframeSkip,
// mNumSamplesOutput field since the last time we were called.
MonitorAutoLock mon(mMonitor);
uint64_t delta = mNumSamplesOutput - mLastReportedNumDecodedFrames;
decoded = static_cast<uint32_t>(delta);
a.mDecoded = static_cast<uint32_t>(delta);
mLastReportedNumDecodedFrames = mNumSamplesOutput;
}
return rv;

View File

@ -79,9 +79,7 @@ SoftwareWebMVideoDecoder::DecodeVideoFrame(bool &aKeyframeSkip,
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mReader->GetDecoder(),
parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mReader->GetDecoder());
nsAutoRef<NesteggPacketHolder> holder(mReader->NextPacket(WebMReader::VIDEO));
if (!holder) {
@ -144,7 +142,7 @@ SoftwareWebMVideoDecoder::DecodeVideoFrame(bool &aKeyframeSkip,
}
if (aKeyframeSkip && (!si.is_kf || tstamp_usecs < aTimeThreshold)) {
// Skipping to next keyframe...
parsed++; // Assume 1 frame per chunk.
a.mParsed++; // Assume 1 frame per chunk.
continue;
}
@ -160,7 +158,7 @@ SoftwareWebMVideoDecoder::DecodeVideoFrame(bool &aKeyframeSkip,
// the time threshold required then it is not added
// to the video queue and won't be displayed.
if (tstamp_usecs < aTimeThreshold) {
parsed++; // Assume 1 frame per chunk.
a.mParsed++; // Assume 1 frame per chunk.
continue;
}
@ -218,9 +216,9 @@ SoftwareWebMVideoDecoder::DecodeVideoFrame(bool &aKeyframeSkip,
if (!v) {
return false;
}
parsed++;
decoded++;
NS_ASSERTION(decoded <= parsed,
a.mParsed++;
a.mDecoded++;
NS_ASSERTION(a.mDecoded <= a.mParsed,
"Expect only 1 frame per chunk per packet in WebM...");
mReader->VideoQueue().Push(v);
}

View File

@ -808,8 +808,7 @@ WMFReader::DecodeVideoFrame(bool &aKeyframeSkip,
// Record number of frames decoded and parsed. Automatically update the
// stats counters using the AutoNotifyDecoded stack-based class.
uint32_t parsed = 0, decoded = 0;
AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded);
AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
HRESULT hr;
@ -876,8 +875,8 @@ WMFReader::DecodeVideoFrame(bool &aKeyframeSkip,
}
NS_ENSURE_TRUE(SUCCEEDED(hr) && v, false);
parsed++;
decoded++;
a.mParsed++;
a.mDecoded++;
mVideoQueue.Push(v);
#ifdef LOG_SAMPLE_DECODE