Bug 811381 - Move NextFrameStatus to MediaDecoderOwner, so that nsHTMLMediaElement doesn't need to include all of nsBuiltinDecoder. r=roc

This commit is contained in:
Chris Pearce 2012-11-14 11:45:31 -08:00
parent 9fe37d1328
commit 092eb0ac65
9 changed files with 52 additions and 40 deletions

View File

@ -49,6 +49,8 @@ public:
typedef mozilla::VideoFrameContainer VideoFrameContainer;
typedef mozilla::MediaStream MediaStream;
typedef mozilla::MediaResource MediaResource;
typedef mozilla::MediaDecoderOwner MediaDecoderOwner;
typedef mozilla::MetadataTags MetadataTags;
#ifdef MOZ_DASH
friend class nsDASHDecoder;
@ -191,11 +193,7 @@ public:
// Called by the media decoder and the video frame to get the
// ImageContainer containing the video data.
virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE;
ImageContainer* GetImageContainer()
{
VideoFrameContainer* container = GetVideoFrameContainer();
return container ? container->GetImageContainer() : nullptr;
}
ImageContainer* GetImageContainer();
// Called by the video frame to get the print surface, if this is
// a static document and we're not actually playing video
@ -217,7 +215,7 @@ public:
// the data for the next frame is available. This method will
// decide whether to set the ready state to HAVE_CURRENT_DATA,
// HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA.
virtual void UpdateReadyStateForData(nsBuiltinDecoder::NextFrameStatus aNextFrame) MOZ_FINAL MOZ_OVERRIDE;
virtual void UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatus aNextFrame) MOZ_FINAL MOZ_OVERRIDE;
// Use this method to change the mReadyState member, so required
// events can be fired.

View File

@ -2653,8 +2653,8 @@ public:
{
if (mElement && mHaveCurrentData) {
mElement->UpdateReadyStateForData(
mBlocked ? nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE_BUFFERING :
nsBuiltinDecoder::NEXT_FRAME_AVAILABLE);
mBlocked ? MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING :
MediaDecoderOwner::NEXT_FRAME_AVAILABLE);
}
}
void DoNotifyBlocked()
@ -3057,7 +3057,7 @@ bool nsHTMLMediaElement::ShouldCheckAllowOrigin()
return mCORSMode != CORS_NONE;
}
void nsHTMLMediaElement::UpdateReadyStateForData(nsBuiltinDecoder::NextFrameStatus aNextFrame)
void nsHTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatus aNextFrame)
{
if (mReadyState < nsIDOMHTMLMediaElement::HAVE_METADATA) {
// aNextFrame might have a next frame because the decoder can advance
@ -3082,9 +3082,9 @@ void nsHTMLMediaElement::UpdateReadyStateForData(nsBuiltinDecoder::NextFrameStat
return;
}
if (aNextFrame != nsBuiltinDecoder::NEXT_FRAME_AVAILABLE) {
if (aNextFrame != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
if (!mWaitingFired && aNextFrame == nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE_BUFFERING) {
if (!mWaitingFired && aNextFrame == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING) {
FireTimeUpdate(false);
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
mWaitingFired = true;
@ -3696,3 +3696,10 @@ void nsHTMLMediaElement::NotifyAudioAvailableListener()
mDecoder->NotifyAudioAvailableListener();
}
}
ImageContainer* nsHTMLMediaElement::GetImageContainer()
{
VideoFrameContainer* container = GetVideoFrameContainer();
return container ? container->GetImageContainer() : nullptr;
}

View File

@ -6,10 +6,14 @@
#ifndef MediaDecoderOwner_h_
#define MediaDecoderOwner_h_
#include "nsBuiltinDecoder.h"
class nsHTMLMediaElement;
namespace mozilla {
class VideoFrameContainer;
typedef nsDataHashtable<nsCStringHashKey, nsCString> MetadataTags;
class MediaDecoderOwner
{
public:
@ -115,16 +119,27 @@ public:
// called to notify that the principal of the decoder's media resource has changed.
virtual void NotifyDecoderPrincipalChanged() = 0;
// The status of the next frame which might be available from the decoder
enum NextFrameStatus {
// The next frame of audio/video is available
NEXT_FRAME_AVAILABLE,
// The next frame of audio/video is unavailable because the decoder
// is paused while it buffers up data
NEXT_FRAME_UNAVAILABLE_BUFFERING,
// The next frame of audio/video is unavailable for some other reasons
NEXT_FRAME_UNAVAILABLE
};
// Called by the decoder when some data has been downloaded or
// buffering/seeking has ended. aNextFrameAvailable is true when
// the data for the next frame is available. This method will
// decide whether to set the ready state to HAVE_CURRENT_DATA,
// HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA.
virtual void UpdateReadyStateForData(nsBuiltinDecoder::NextFrameStatus aNextFrame) = 0;
virtual void UpdateReadyStateForData(NextFrameStatus aNextFrame) = 0;
// Called by the media decoder and the video frame to get the
// ImageContainer containing the video data.
virtual mozilla::VideoFrameContainer* GetVideoFrameContainer() = 0;
virtual VideoFrameContainer* GetVideoFrameContainer() = 0;
};
}

View File

@ -967,7 +967,7 @@ void nsBuiltinDecoder::NextFrameUnavailableBuffering()
if (!mOwner || mShuttingDown || !mDecoderStateMachine)
return;
mOwner->UpdateReadyStateForData(nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE_BUFFERING);
mOwner->UpdateReadyStateForData(MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING);
}
void nsBuiltinDecoder::NextFrameAvailable()
@ -976,7 +976,7 @@ void nsBuiltinDecoder::NextFrameAvailable()
if (!mOwner || mShuttingDown || !mDecoderStateMachine)
return;
mOwner->UpdateReadyStateForData(nsBuiltinDecoder::NEXT_FRAME_AVAILABLE);
mOwner->UpdateReadyStateForData(MediaDecoderOwner::NEXT_FRAME_AVAILABLE);
}
void nsBuiltinDecoder::NextFrameUnavailable()
@ -984,7 +984,7 @@ void nsBuiltinDecoder::NextFrameUnavailable()
NS_ASSERTION(NS_IsMainThread(), "Should be called on main thread");
if (!mOwner || mShuttingDown || !mDecoderStateMachine)
return;
mOwner->UpdateReadyStateForData(nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE);
mOwner->UpdateReadyStateForData(MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE);
}
void nsBuiltinDecoder::UpdateReadyStateForData()
@ -992,7 +992,7 @@ void nsBuiltinDecoder::UpdateReadyStateForData()
NS_ASSERTION(NS_IsMainThread(), "Should be called on main thread");
if (!mOwner || mShuttingDown || !mDecoderStateMachine)
return;
NextFrameStatus frameStatus =
MediaDecoderOwner::NextFrameStatus frameStatus =
mDecoderStateMachine->GetNextFrameStatus();
mOwner->UpdateReadyStateForData(frameStatus);
}

View File

@ -191,6 +191,7 @@ destroying the nsBuiltinDecoder object.
#include "MediaResource.h"
#include "mozilla/ReentrantMonitor.h"
#include "MediaStreamGraph.h"
#include "MediaDecoderOwner.h"
namespace mozilla {
namespace layers {
@ -198,7 +199,6 @@ class Image;
} //namespace
class nsMediaByteRange;
class VideoFrameContainer;
class MediaDecoderOwner;
} //namespace
class nsAudioStream;
@ -223,8 +223,6 @@ static inline bool IsCurrentThread(nsIThread* aThread) {
return NS_GetCurrentThread() == aThread;
}
typedef nsDataHashtable<nsCStringHashKey, nsCString> MetadataTags;
class nsBuiltinDecoder : public nsIObserver
{
public:
@ -240,6 +238,8 @@ public:
typedef mozilla::TimeDuration TimeDuration;
typedef mozilla::VideoFrameContainer VideoFrameContainer;
typedef mozilla::layers::Image Image;
typedef mozilla::MetadataTags MetadataTags;
typedef mozilla::MediaDecoderOwner MediaDecoderOwner;
class DecodedStreamMainThreadListener;
@ -692,17 +692,6 @@ public:
// Notifies the element that decoding has failed.
virtual void DecodeError();
// The status of the next frame which might be available from the decoder
enum NextFrameStatus {
// The next frame of audio/video is available
NEXT_FRAME_AVAILABLE,
// The next frame of audio/video is unavailable because the decoder
// is paused while it buffers up data
NEXT_FRAME_UNAVAILABLE_BUFFERING,
// The next frame of audio/video is unavailable for some other reasons
NEXT_FRAME_UNAVAILABLE
};
#ifdef MOZ_RAW
static bool IsRawEnabled();
#endif

View File

@ -364,6 +364,7 @@ public:
typedef mozilla::VideoFrameContainer VideoFrameContainer;
typedef mozilla::MediaByteRange MediaByteRange;
typedef mozilla::AudioDataValue AudioDataValue;
typedef mozilla::MetadataTags MetadataTags;
nsBuiltinDecoderReader(nsBuiltinDecoder* aDecoder);
virtual ~nsBuiltinDecoderReader();

View File

@ -1308,15 +1308,15 @@ void nsBuiltinDecoderStateMachine::ClearPositionChangeFlag()
mPositionChangeQueued = false;
}
nsBuiltinDecoder::NextFrameStatus nsBuiltinDecoderStateMachine::GetNextFrameStatus()
MediaDecoderOwner::NextFrameStatus nsBuiltinDecoderStateMachine::GetNextFrameStatus()
{
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
if (IsBuffering() || IsSeeking()) {
return nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE_BUFFERING;
return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING;
} else if (HaveNextFrameData()) {
return nsBuiltinDecoder::NEXT_FRAME_AVAILABLE;
return MediaDecoderOwner::NEXT_FRAME_AVAILABLE;
}
return nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE;
return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
}
void nsBuiltinDecoderStateMachine::SetVolume(double volume)
@ -2389,13 +2389,13 @@ void nsBuiltinDecoderStateMachine::UpdateReadyState() {
nsCOMPtr<nsIRunnable> event;
switch (GetNextFrameStatus()) {
case nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE_BUFFERING:
case MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING:
event = NS_NewRunnableMethod(mDecoder, &nsBuiltinDecoder::NextFrameUnavailableBuffering);
break;
case nsBuiltinDecoder::NEXT_FRAME_AVAILABLE:
case MediaDecoderOwner::NEXT_FRAME_AVAILABLE:
event = NS_NewRunnableMethod(mDecoder, &nsBuiltinDecoder::NextFrameAvailable);
break;
case nsBuiltinDecoder::NEXT_FRAME_UNAVAILABLE:
case MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE:
event = NS_NewRunnableMethod(mDecoder, &nsBuiltinDecoder::NextFrameUnavailable);
break;
default:

View File

@ -110,6 +110,7 @@ public:
typedef mozilla::SourceMediaStream SourceMediaStream;
typedef mozilla::AudioSegment AudioSegment;
typedef mozilla::VideoSegment VideoSegment;
typedef mozilla::MediaDecoderOwner MediaDecoderOwner;
nsBuiltinDecoderStateMachine(nsBuiltinDecoder* aDecoder, nsBuiltinDecoderReader* aReader, bool aRealTime = false);
~nsBuiltinDecoderStateMachine();
@ -164,7 +165,7 @@ public:
return IsCurrentThread(mAudioThread);
}
nsBuiltinDecoder::NextFrameStatus GetNextFrameStatus();
MediaDecoderOwner::NextFrameStatus GetNextFrameStatus();
// Cause state transitions. These methods obtain the decoder monitor
// to synchronise the change of state, and to notify other threads

View File

@ -73,6 +73,7 @@ public:
// converting granulepos to timestamps.
class nsOggCodecState {
public:
typedef mozilla::MetadataTags MetadataTags;
// Ogg types we know about
enum CodecType {
TYPE_VORBIS=0,