Bug 860760 - Pause OMX media sources when playback is paused. r=sotaro, r=cdouble

OMXCodec needs to now when the stream is paused. Otherwise it will
prevent the device from lowering its power state when idle.
This commit is contained in:
Diego Wilson 2013-04-10 17:58:25 -07:00
parent 03f093b739
commit 4b30b46d1f
4 changed files with 57 additions and 0 deletions

View File

@ -331,5 +331,18 @@ nsresult MediaOmxReader::GetBuffered(mozilla::dom::TimeRanges* aBuffered, int64_
return NS_OK;
}
void MediaOmxReader::OnDecodeThreadFinish() {
if (mOmxDecoder.get()) {
mOmxDecoder->Pause();
}
}
void MediaOmxReader::OnDecodeThreadStart() {
if (mOmxDecoder.get()) {
nsresult result = mOmxDecoder->Play();
NS_ASSERTION(result == NS_OK, "OmxDecoder should be in play state to continue decoding");
}
}
} // namespace mozilla

View File

@ -57,6 +57,10 @@ public:
MetadataTags** aTags);
virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
virtual nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered, int64_t aStartTime);
virtual void OnDecodeThreadStart() MOZ_OVERRIDE;
virtual void OnDecodeThreadFinish() MOZ_OVERRIDE;
};
} // namespace mozilla

View File

@ -141,6 +141,7 @@ OmxDecoder::OmxDecoder(MediaResource *aResource,
mVideoBuffer(nullptr),
mAudioBuffer(nullptr),
mIsVideoSeeking(false),
mPaused(false),
mAudioMetadataRead(false)
{
}
@ -666,3 +667,32 @@ void OmxDecoder::ReleaseAllPendingVideoBuffersLocked()
}
mPendingVideoBuffers.clear();
}
nsresult OmxDecoder::Play() {
if (!mPaused) {
return NS_OK;
}
if (mVideoSource.get() && mVideoSource->start() != OK) {
return NS_ERROR_UNEXPECTED;
}
if (mAudioSource.get()&& mAudioSource->start() != OK) {
return NS_ERROR_UNEXPECTED;
}
mPaused = false;
return NS_OK;
}
void OmxDecoder::Pause() {
if (mPaused) {
return;
}
if (mVideoSource.get()) {
mVideoSource->pause();
}
if (mAudioSource.get()) {
mAudioSource->pause();
}
mPaused = true;
}

View File

@ -132,6 +132,10 @@ class OmxDecoder : public RefBase {
bool ToVideoFrame(VideoFrame *aFrame, int64_t aTimeUs, void *aData, size_t aSize, bool aKeyFrame);
bool ToAudioFrame(AudioFrame *aFrame, int64_t aTimeUs, void *aData, size_t aDataOffset, size_t aSize,
int32_t aAudioChannels, int32_t aAudioSampleRate);
//True if decoder is in a paused state
bool mPaused;
public:
OmxDecoder(MediaResource *aResource, AbstractMediaDecoder *aDecoder);
~OmxDecoder();
@ -172,6 +176,12 @@ public:
}
bool ReleaseVideoBuffer(MediaBuffer *aBuffer);
//Change decoder into a playing state
nsresult Play();
//Change decoder into a paused state
void Pause();
};
}