Bug 744896 - Part 3: Pass MediaInfo to functions MetadataLoaded and QueueMetadata. r=roc.

This commit is contained in:
Shelly Lin 2014-07-04 11:54:54 +08:00
parent bd62cf13ed
commit c7b36f2e75
14 changed files with 53 additions and 97 deletions

View File

@ -151,10 +151,7 @@ public:
// Called by the video decoder object, on the main thread,
// when it has read the metadata containing video dimensions,
// etc.
virtual void MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
virtual void MetadataLoaded(const MediaInfo* aInfo,
const MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE;
// Called by the video decoder object, on the main thread,

View File

@ -2876,13 +2876,10 @@ void HTMLMediaElement::ProcessMediaFragmentURI()
}
}
void HTMLMediaElement::MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
const MetadataTags* aTags)
{
mHasAudio = aHasAudio;
mHasAudio = aInfo->HasAudio();
mTags = aTags;
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
@ -2895,7 +2892,7 @@ void HTMLMediaElement::MetadataLoaded(int aChannels,
// If this element had a video track, but consists only of an audio track now,
// delete the VideoFrameContainer. This happens when the src is changed to an
// audio only file.
if (!aHasVideo && mVideoFrameContainer) {
if (!aInfo->HasVideo() && mVideoFrameContainer) {
// call ForgetElement() such that callbacks from |mVideoFrameContainer|
// won't reach us anymore.
mVideoFrameContainer->ForgetElement();

View File

@ -8,6 +8,7 @@
#define AbstractMediaDecoder_h_
#include "mozilla/Attributes.h"
#include "MediaInfo.h"
#include "nsISupports.h"
#include "nsDataHashtable.h"
#include "nsThreadUtils.h"
@ -89,8 +90,8 @@ public:
// Return true if the transport layer supports seeking.
virtual bool IsMediaSeekable() = 0;
virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) = 0;
virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) = 0;
virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) = 0;
virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) = 0;
// Set the media end time in microseconds
virtual void SetMediaEndTime(int64_t aTime) = 0;
@ -136,30 +137,27 @@ public:
};
};
class AudioMetadataEventRunner : public nsRunnable
class MetadataEventRunner : public nsRunnable
{
private:
nsRefPtr<AbstractMediaDecoder> mDecoder;
public:
AudioMetadataEventRunner(AbstractMediaDecoder* aDecoder, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
: mDecoder(aDecoder),
mChannels(aChannels),
mRate(aRate),
mHasAudio(aHasAudio),
mHasVideo(aHasVideo),
mTags(aTags)
MetadataEventRunner(AbstractMediaDecoder* aDecoder, MediaInfo* aInfo, MetadataTags* aTags)
: mDecoder(aDecoder),
mInfo(aInfo),
mTags(aTags)
{}
NS_IMETHOD Run() MOZ_OVERRIDE
{
mDecoder->MetadataLoaded(mChannels, mRate, mHasAudio, mHasVideo, mTags);
mDecoder->MetadataLoaded(mInfo, mTags);
return NS_OK;
}
int mChannels;
int mRate;
bool mHasAudio;
bool mHasVideo;
// The ownership is transferred to MediaDecoder.
MediaInfo* mInfo;
// The ownership is transferred to its owning element.
MetadataTags* mTags;
};

View File

@ -147,13 +147,13 @@ BufferDecoder::IsMediaSeekable()
}
void
BufferDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
BufferDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags)
{
// ignore
}
void
BufferDecoder::QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
BufferDecoder::QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags)
{
// ignore
}

View File

@ -60,8 +60,8 @@ public:
virtual bool IsMediaSeekable() MOZ_OVERRIDE;
virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_OVERRIDE;
virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_OVERRIDE;
virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) MOZ_OVERRIDE;
virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) MOZ_OVERRIDE;
virtual void SetMediaEndTime(int64_t aTime) MOZ_OVERRIDE;

View File

@ -653,15 +653,12 @@ already_AddRefed<nsIPrincipal> MediaDecoder::GetCurrentPrincipal()
}
void MediaDecoder::QueueMetadata(int64_t aPublishTime,
int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
MediaInfo* aInfo,
MetadataTags* aTags)
{
NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
GetReentrantMonitor().AssertCurrentThreadIn();
mDecoderStateMachine->QueueMetadata(aPublishTime, aChannels, aRate, aHasAudio, aHasVideo, aTags);
mDecoderStateMachine->QueueMetadata(aPublishTime, aInfo, aTags);
}
bool
@ -672,7 +669,7 @@ MediaDecoder::IsDataCachedToEndOfResource()
mResource->IsDataCachedToEndOfResource(mDecoderPosition));
}
void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags)
void MediaDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags)
{
MOZ_ASSERT(NS_IsMainThread());
if (mShuttingDown) {
@ -700,7 +697,7 @@ void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool
// Make sure the element and the frame (if any) are told about
// our new size.
Invalidate();
mOwner->MetadataLoaded(aChannels, aRate, aHasAudio, aHasVideo, aTags);
mOwner->MetadataLoaded(aInfo, aTags);
}
if (!mCalledResourceLoaded) {

View File

@ -751,10 +751,7 @@ public:
// main thread to be presented when the |currentTime| of the media is greater
// or equal to aPublishTime.
void QueueMetadata(int64_t aPublishTime,
int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
MediaInfo* aInfo,
MetadataTags* aTags);
/******
@ -777,10 +774,7 @@ public:
// Called when the metadata from the media file has been loaded by the
// state machine. Call on the main thread only.
virtual void MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
virtual void MetadataLoaded(MediaInfo* aInfo,
MetadataTags* aTags);
// Called when the first frame has been loaded.

View File

@ -49,10 +49,7 @@ public:
// Called by the video decoder object, on the main thread,
// when it has read the metadata containing video dimensions,
// etc.
virtual void MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
virtual void MetadataLoaded(const MediaInfo* aInfo,
const MetadataTags* aTags) = 0;
// Called by the video decoder object, on the main thread,

View File

@ -1983,13 +1983,10 @@ MediaDecoderStateMachine::FinishDecodeMetadata()
}
// Inform the element that we've loaded the metadata and the first frame.
nsAutoPtr<MediaInfo> info(new MediaInfo());
*info = mInfo;
nsCOMPtr<nsIRunnable> metadataLoadedEvent =
new AudioMetadataEventRunner(mDecoder,
mInfo.mAudio.mChannels,
mInfo.mAudio.mRate,
HasAudio(),
HasVideo(),
mMetadataTags.forget());
new MetadataEventRunner(mDecoder, info.forget(), mMetadataTags.forget());
NS_DispatchToMainThread(metadataLoadedEvent, NS_DISPATCH_NORMAL);
if (mState == DECODER_STATE_DECODING_METADATA) {
@ -3098,20 +3095,14 @@ bool MediaDecoderStateMachine::IsShutdown()
}
void MediaDecoderStateMachine::QueueMetadata(int64_t aPublishTime,
int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
MediaInfo* aInfo,
MetadataTags* aTags)
{
NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
AssertCurrentThreadInMonitor();
TimedMetadata* metadata = new TimedMetadata;
metadata->mPublishTime = aPublishTime;
metadata->mChannels = aChannels;
metadata->mRate = aRate;
metadata->mHasAudio = aHasAudio;
metadata->mHasVideo = aHasVideo;
metadata->mInfo = aInfo;
metadata->mTags = aTags;
mMetadataManager.QueueMetadata(metadata);
}

View File

@ -323,7 +323,7 @@ public:
// shutting down. The decoder monitor must be held while calling this.
bool IsShutdown();
void QueueMetadata(int64_t aPublishTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags);
void QueueMetadata(int64_t aPublishTime, MediaInfo* aInfo, MetadataTags* aTags);
// Returns true if we're currently playing. The decoder monitor must
// be held.

View File

@ -22,14 +22,10 @@ namespace mozilla {
// The metadata. The ownership is transfered to the element when dispatching to
// the main threads.
nsAutoPtr<MetadataTags> mTags;
// The sample rate of this media.
int mRate;
// The number of channel of this media.
int mChannels;
// True if this media has an audio track.
bool mHasAudio;
// True if this media has a video track.
bool mHasVideo;
// The media info, including the info of audio tracks and video tracks.
// The ownership is transfered to MediaDecoder when dispatching to the
// main thread.
nsAutoPtr<MediaInfo> mInfo;
};
// This class encapsulate the logic to give the metadata from the reader to
@ -51,12 +47,9 @@ namespace mozilla {
TimedMetadata* metadata = mMetadataQueue.getFirst();
while (metadata && aCurrentTime >= static_cast<double>(metadata->mPublishTime) / USECS_PER_S) {
nsCOMPtr<nsIRunnable> metadataUpdatedEvent =
new AudioMetadataEventRunner(aDecoder,
metadata->mChannels,
metadata->mRate,
metadata->mHasAudio,
metadata->mHasVideo,
metadata->mTags.forget());
new MetadataEventRunner(aDecoder,
metadata->mInfo.forget(),
metadata->mTags.forget());
NS_DispatchToMainThread(metadataUpdatedEvent);
delete mMetadataQueue.popFirst();
metadata = mMetadataQueue.getFirst();

View File

@ -627,8 +627,6 @@ bool OggReader::ReadOggChain()
OpusState* newOpusState = nullptr;
#endif /* MOZ_OPUS */
VorbisState* newVorbisState = nullptr;
int channels = 0;
long rate = 0;
MetadataTags* tags = nullptr;
if (HasVideo() || HasSkeleton() || !HasAudio()) {
@ -673,6 +671,7 @@ bool OggReader::ReadOggChain()
return false;
}
nsAutoPtr<MediaInfo> info(new MediaInfo());
if ((newVorbisState && ReadHeaders(newVorbisState)) &&
(mVorbisState->mInfo.rate == newVorbisState->mInfo.rate) &&
(mVorbisState->mInfo.channels == newVorbisState->mInfo.channels)) {
@ -681,8 +680,8 @@ bool OggReader::ReadOggChain()
mVorbisSerial = mVorbisState->mSerial;
LOG(PR_LOG_DEBUG, ("New vorbis ogg link, serial=%d\n", mVorbisSerial));
chained = true;
rate = mVorbisState->mInfo.rate;
channels = mVorbisState->mInfo.channels;
info->mAudio.mRate = mVorbisState->mInfo.rate;
info->mAudio.mChannels = mVorbisState->mInfo.channels;
tags = mVorbisState->GetTags();
}
@ -694,8 +693,8 @@ bool OggReader::ReadOggChain()
mOpusState = newOpusState;
mOpusSerial = mOpusState->mSerial;
chained = true;
rate = mOpusState->mRate;
channels = mOpusState->mChannels;
info->mAudio.mRate = mOpusState->mRate;
info->mAudio.mChannels = mOpusState->mChannels;
tags = mOpusState->GetTags();
}
#endif
@ -703,13 +702,12 @@ bool OggReader::ReadOggChain()
if (chained) {
SetChained(true);
{
info->mAudio.mHasAudio = HasAudio();
info->mVideo.mHasVideo = HasVideo();
int rate = info->mAudio.mRate;
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
mDecoder->QueueMetadata((mDecodedAudioFrames * USECS_PER_S) / rate,
channels,
rate,
HasAudio(),
HasVideo(),
tags);
info.forget(), tags);
}
return true;
}

View File

@ -55,14 +55,11 @@ void MediaOmxDecoder::SetCanOffloadAudio(bool aCanOffloadAudio)
mCanOffloadAudio = aCanOffloadAudio;
}
void MediaOmxDecoder::MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
void MediaOmxDecoder::MetadataLoaded(MediaInfo* aInfo,
MetadataTags* aTags)
{
MOZ_ASSERT(NS_IsMainThread());
MediaDecoder::MetadataLoaded(aChannels, aRate, aHasAudio, aHasVideo, aTags);
MediaDecoder::MetadataLoaded(aInfo, aTags);
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
if (!mCanOffloadAudio || mFallbackToStateMachine || mOutputStreams.Length() ||

View File

@ -21,10 +21,7 @@ public:
virtual MediaDecoder* Clone();
virtual MediaDecoderStateMachine* CreateStateMachine();
virtual void MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
virtual void MetadataLoaded(MediaInfo* aInfo,
MetadataTags* aTags);
virtual void ChangeState(PlayState aState);
virtual void ApplyStateToStateMachine(PlayState aState);