Bug 1388604 - move SetReadMode() from MediaResource to BaseMediaResource. r=gerald

It would be less accurate to call SetReadMode(MediaCacheStream::MODE_PLAYBACK)
in ChannelMediaDecoder::MetadataLoaded() instead of DecodeMetadataState::OnMetadataRead()
because MDSM might have started decoding by the time 'metadata loaded' event arrives
in the main thread. However this little inaccuracy should be fine since it only
affects a small amount of data concerning the eviction algorithm.

MozReview-Commit-ID: JoQMGr5Fvge

--HG--
extra : rebase_source : 3663a028522cc8b973964f62e59d7568a5eba10a
extra : source : 359b4454633432d3334a106aedb267a2451afb45
This commit is contained in:
JW Wang 2017-08-09 11:06:29 +08:00
Родитель 71f3e232a7
Коммит 32951f4824
10 изменённых файлов: 27 добавлений и 23 удалений

Просмотреть файл

@ -43,8 +43,6 @@ private:
return principal.forget();
}
// These methods are called off the main thread.
// The mode is initially MODE_PLAYBACK.
void SetReadMode(MediaCacheStream::ReadMode aMode) override {}
nsresult ReadAt(int64_t aOffset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes) override
{

Просмотреть файл

@ -254,6 +254,9 @@ ChannelMediaDecoder::Load(nsIChannel* aChannel,
rv = OpenResource(aStreamListener);
NS_ENSURE_SUCCESS(rv, rv);
// Set mode to METADATA since we are about to read metadata.
mResource->SetReadMode(MediaCacheStream::MODE_METADATA);
SetStateMachine(CreateStateMachine());
NS_ENSURE_TRUE(GetStateMachine(), NS_ERROR_FAILURE);
@ -501,6 +504,17 @@ ChannelMediaDecoder::Resume()
}
}
void
ChannelMediaDecoder::MetadataLoaded(
UniquePtr<MediaInfo> aInfo,
UniquePtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility)
{
MediaDecoder::MetadataLoaded(Move(aInfo), Move(aTags), aEventVisibility);
// Set mode to PLAYBACK after reading metadata.
mResource->SetReadMode(MediaCacheStream::MODE_PLAYBACK);
}
} // namespace mozilla
// avoid redefined macro in unified build

Просмотреть файл

@ -57,6 +57,10 @@ protected:
void OnPlaybackEvent(MediaEventType aEvent) override;
void DurationChanged() override;
void DownloadProgressed() override;
void MetadataLoaded(UniquePtr<MediaInfo> aInfo,
UniquePtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility) override;
RefPtr<ResourceCallback> mResourceCallback;
RefPtr<BaseMediaResource> mResource;

Просмотреть файл

@ -456,6 +456,12 @@ protected:
virtual void OnPlaybackEvent(MediaEventType aEvent);
// Called when the metadata from the media file has been loaded by the
// state machine. Call on the main thread only.
virtual void MetadataLoaded(UniquePtr<MediaInfo> aInfo,
UniquePtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility);
/******
* The following members should be accessed with the decoder lock held.
******/
@ -496,12 +502,6 @@ protected:
private:
nsCString GetDebugInfo();
// Called when the metadata from the media file has been loaded by the
// state machine. Call on the main thread only.
void MetadataLoaded(UniquePtr<MediaInfo> aInfo,
UniquePtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility);
// Called when the owner's activity changed.
void NotifyCompositor();

Просмотреть файл

@ -341,9 +341,6 @@ public:
MOZ_ASSERT(!mMetadataRequest.Exists());
SLOG("Dispatching AsyncReadMetadata");
// Set mode to METADATA since we are about to read metadata.
Resource()->SetReadMode(MediaCacheStream::MODE_METADATA);
// We disconnect mMetadataRequest in Exit() so it is fine to capture
// a raw pointer here.
Reader()->ReadMetadata()
@ -2224,9 +2221,6 @@ DecodeMetadataState::OnMetadataRead(MetadataHolder&& aMetadata)
{
mMetadataRequest.Complete();
// Set mode to PLAYBACK after reading metadata.
Resource()->SetReadMode(MediaCacheStream::MODE_PLAYBACK);
mMaster->mInfo.emplace(*aMetadata.mInfo);
mMaster->mMediaSeekable = Info().mMediaSeekable;
mMaster->mMediaSeekableOnlyInBufferedRanges =

Просмотреть файл

@ -164,8 +164,6 @@ public:
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() = 0;
// These methods are called off the main thread.
// The mode is initially MODE_PLAYBACK.
virtual void SetReadMode(MediaCacheStream::ReadMode aMode) = 0;
// Read up to aCount bytes from the stream. The read starts at
// aOffset in the stream, seeking to that location initially if
// it is not the current stream offset. The remaining arguments,
@ -325,6 +323,9 @@ public:
// Resume any downloads that have been suspended.
virtual void Resume() = 0;
// The mode is initially MODE_PLAYBACK.
virtual void SetReadMode(MediaCacheStream::ReadMode aMode) = 0;
/**
* Open the stream. This creates a stream listener and returns it in
* aStreamListener; this listener needs to be notified of incoming data.

Просмотреть файл

@ -20,7 +20,6 @@ public:
{
return nullptr;
}
void SetReadMode(MediaCacheStream::ReadMode aMode) override {}
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
uint32_t* aBytes) override;
// Data stored in file, caching recommended.

Просмотреть файл

@ -48,7 +48,6 @@ public:
~HLSResource();
void Suspend();
void Resume();
void SetReadMode(MediaCacheStream::ReadMode aMode) override { UNIMPLEMENTED(); }
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
bool ShouldCacheReads() override { UNIMPLEMENTED(); return false; }
int64_t Tell() override { UNIMPLEMENTED(); return -1; }

Просмотреть файл

@ -32,7 +32,6 @@ public:
, mEnded(false)
{}
void SetReadMode(MediaCacheStream::ReadMode aMode) override { UNIMPLEMENTED(); }
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
bool ShouldCacheReads() override { UNIMPLEMENTED(); return false; }
int64_t Tell() override { UNIMPLEMENTED(); return -1; }

Просмотреть файл

@ -45,10 +45,6 @@ public:
UNIMPLEMENTED();
return nullptr;
}
void SetReadMode(MediaCacheStream::ReadMode aMode) override
{
UNIMPLEMENTED();
}
nsresult ReadAt(int64_t aOffset,
char* aBuffer,
uint32_t aCount,