Bug 799344 - Un-templatify nsBuiltinDecoderReader::DecodeToFirstData() so that we don't need to know nsBuiltinDecoderStateMachine's interface in nsBuiltinDecoderReader.h. This means that nsBuiltinDecoderReader.h doesn't need to include nsBuiltinDecoderStateMachine.h when we move the state machine declaration from nsBuiltinDecoder.h to nsBuiltinDecoderStateMachine.h (in a later patch). nsBuiltinDecoderStateMachine.h needs to include nsBuiltinDecoderReader.h, so if nsBuiltinDecoderReader.h needed to include nsBuiltinDecoderStateMachine.h we'd have an include cycle, which is bad. r=roc

This commit is contained in:
Chris Pearce 2012-11-07 11:33:01 +13:00
parent 8ff522d0bb
commit c3a965dc66
4 changed files with 51 additions and 48 deletions

View File

@ -274,18 +274,14 @@ nsDASHReader::FindStartTime(int64_t& aOutStartTime)
mDecoder->GetReentrantMonitor());
if (HasVideo()) {
// Forward to video reader.
videoData
= mVideoReader->DecodeToFirstData(&nsBuiltinDecoderReader::DecodeVideoFrame,
VideoQueue());
videoData = mVideoReader->DecodeToFirstVideoData();
if (videoData) {
videoStartTime = videoData->mTime;
}
}
if (HasAudio()) {
// Forward to audio reader.
AudioData* audioData
= mAudioReader->DecodeToFirstData(&nsBuiltinDecoderReader::DecodeAudioData,
AudioQueue());
AudioData* audioData = mAudioReader->DecodeToFirstAudioData();
if (audioData) {
audioStartTime = audioData->mTime;
}

View File

@ -5,8 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GonkIOSurfaceImage.h"
#include "nsBuiltinDecoder.h"
#include "nsBuiltinDecoderReader.h"
#include "nsBuiltinDecoder.h"
#include "nsBuiltinDecoderStateMachine.h"
#include "VideoUtils.h"
#include "ImageContainer.h"
@ -342,6 +342,39 @@ nsresult nsBuiltinDecoderReader::ResetDecode()
return res;
}
VideoData* nsBuiltinDecoderReader::DecodeToFirstVideoData()
{
bool eof = false;
while (!eof && mVideoQueue.GetSize() == 0) {
{
ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
if (mDecoder->GetStateMachine()->IsShutdown()) {
return nullptr;
}
}
bool keyframeSkip = false;
eof = !DecodeVideoFrame(keyframeSkip, 0);
}
VideoData* d = nullptr;
return (d = mVideoQueue.PeekFront()) ? d : nullptr;
}
AudioData* nsBuiltinDecoderReader::DecodeToFirstAudioData()
{
bool eof = false;
while (!eof && mAudioQueue.GetSize() == 0) {
{
ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
if (mDecoder->GetStateMachine()->IsShutdown()) {
return nullptr;
}
}
eof = !DecodeAudioData();
}
AudioData* d = nullptr;
return (d = mAudioQueue.PeekFront()) ? d : nullptr;
}
VideoData* nsBuiltinDecoderReader::FindStartTime(int64_t& aOutStartTime)
{
NS_ASSERTION(mDecoder->OnStateMachineThread() || mDecoder->OnDecodeThread(),
@ -354,15 +387,13 @@ VideoData* nsBuiltinDecoderReader::FindStartTime(int64_t& aOutStartTime)
VideoData* videoData = nullptr;
if (HasVideo()) {
videoData = DecodeToFirstData(&nsBuiltinDecoderReader::DecodeVideoFrame,
mVideoQueue);
videoData = DecodeToFirstVideoData();
if (videoData) {
videoStartTime = videoData->mTime;
}
}
if (HasAudio()) {
AudioData* audioData = DecodeToFirstData(&nsBuiltinDecoderReader::DecodeAudioData,
mAudioQueue);
AudioData* audioData = DecodeToFirstAudioData();
if (audioData) {
audioStartTime = audioData->mTime;
}

View File

@ -13,6 +13,10 @@
#include "SharedBuffer.h"
#include "ImageLayers.h"
#include "AudioSampleFormat.h"
#include "MediaResource.h"
#include "nsHTMLMediaElement.h"
class nsBuiltinDecoder;
// Stores info relevant to presenting media frames.
class nsVideoInfo {
@ -31,8 +35,8 @@ public:
// at a size of aDisplay. You should validate the frame, picture, and
// display regions before using them to display video frames.
static bool ValidateVideoRegion(const nsIntSize& aFrame,
const nsIntRect& aPicture,
const nsIntSize& aDisplay);
const nsIntRect& aPicture,
const nsIntSize& aDisplay);
// Sample rate.
uint32_t mAudioRate;
@ -228,12 +232,12 @@ template <class T> class MediaQueue : private nsDeque {
mReentrantMonitor("mediaqueue"),
mEndOfStream(false)
{}
~MediaQueue() {
Reset();
}
inline int32_t GetSize() {
inline int32_t GetSize() {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
return nsDeque::GetSize();
}
@ -257,12 +261,12 @@ template <class T> class MediaQueue : private nsDeque {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
return static_cast<T*>(nsDeque::PopFront());
}
inline T* Peek() {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
return static_cast<T*>(nsDeque::Peek());
}
inline T* PeekFront() {
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
return static_cast<T*>(nsDeque::PeekFront());
@ -472,36 +476,8 @@ public:
return mDecoder;
}
// Reader decode function. Matches DecodeVideoFrame() and
// DecodeAudioData().
typedef bool (nsBuiltinDecoderReader::*DecodeFn)();
// Calls aDecodeFn on *this until aQueue has an item, whereupon
// we return the first item. Note: Inline defn. for external accessibility.
template<class Data>
Data* DecodeToFirstData(DecodeFn aDecodeFn,
MediaQueue<Data>& aQueue)
{
bool eof = false;
while (!eof && aQueue.GetSize() == 0) {
{
ReentrantMonitorAutoEnter decoderMon(mDecoder->GetReentrantMonitor());
if (mDecoder->GetStateMachine()->IsShutdown()) {
return nullptr;
}
}
eof = !(this->*aDecodeFn)();
}
Data* d = nullptr;
return (d = aQueue.PeekFront()) ? d : nullptr;
}
// Wrapper so that DecodeVideoFrame(bool&,int64_t) can be called from
// DecodeToFirstData().
bool DecodeVideoFrame() {
bool f = false;
return DecodeVideoFrame(f, 0);
}
AudioData* DecodeToFirstAudioData();
VideoData* DecodeToFirstVideoData();
// Sets range for initialization bytes; used by DASH.
virtual void SetInitByteRange(MediaByteRange &aByteRange) { }

View File

@ -3,12 +3,12 @@
* 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 "nsBuiltinDecoderStateMachine.h"
#include <limits>
#include "nsAudioStream.h"
#include "nsTArray.h"
#include "nsBuiltinDecoder.h"
#include "nsBuiltinDecoderReader.h"
#include "nsBuiltinDecoderStateMachine.h"
#include "mozilla/mozalloc.h"
#include "VideoUtils.h"
#include "nsTimeRanges.h"