mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1834275 - Allow passing in a track type to TrackBuffersManager::EvictionThreshold. r=alwu
This helps when the HasVideo() and HasAudio() both return false because the demuxer hasn't initialized yet. Differential Revision: https://phabricator.services.mozilla.com/D179064
This commit is contained in:
parent
d40c706f2c
commit
90e783dbb0
@ -699,7 +699,10 @@ already_AddRefed<MediaByteBuffer> SourceBuffer::PrepareAppend(
|
||||
// Give a chance to the TrackBuffersManager to evict some data if needed.
|
||||
Result evicted = mTrackBuffersManager->EvictData(
|
||||
TimeUnit::FromSeconds(mMediaSource->GetDecoder()->GetCurrentTime()),
|
||||
aLength);
|
||||
aLength,
|
||||
mType.ExtendedType().Type().HasAudioMajorType()
|
||||
? TrackInfo::TrackType::kAudioTrack
|
||||
: TrackInfo::TrackType::kVideoTrack);
|
||||
|
||||
// See if we have enough free space to append our new data.
|
||||
if (evicted == Result::BUFFER_FULL) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "TrackBuffersManager.h"
|
||||
#include "ContainerParser.h"
|
||||
#include "MediaInfo.h"
|
||||
#include "MediaSourceDemuxer.h"
|
||||
#include "MediaSourceUtils.h"
|
||||
#include "SourceBuffer.h"
|
||||
@ -344,14 +345,14 @@ TrackBuffersManager::RangeRemoval(TimeUnit aStart, TimeUnit aEnd) {
|
||||
}
|
||||
|
||||
TrackBuffersManager::EvictDataResult TrackBuffersManager::EvictData(
|
||||
const TimeUnit& aPlaybackTime, int64_t aSize) {
|
||||
const TimeUnit& aPlaybackTime, int64_t aSize, TrackType aType) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (aSize > EvictionThreshold()) {
|
||||
if (aSize > EvictionThreshold(aType)) {
|
||||
// We're adding more data than we can hold.
|
||||
return EvictDataResult::BUFFER_FULL;
|
||||
}
|
||||
const int64_t toEvict = GetSize() + aSize - EvictionThreshold();
|
||||
const int64_t toEvict = GetSize() + aSize - EvictionThreshold(aType);
|
||||
|
||||
const uint32_t canEvict =
|
||||
Evictable(HasVideo() ? TrackInfo::kVideoTrack : TrackInfo::kAudioTrack);
|
||||
@ -361,7 +362,7 @@ TrackBuffersManager::EvictDataResult TrackBuffersManager::EvictData(
|
||||
"kB, "
|
||||
"evict=%" PRId64 "kB canevict=%" PRIu32 "kB",
|
||||
aPlaybackTime.ToMicroseconds(), GetSize() / 1024,
|
||||
EvictionThreshold() / 1024, toEvict / 1024, canEvict / 1024);
|
||||
EvictionThreshold(aType) / 1024, toEvict / 1024, canEvict / 1024);
|
||||
|
||||
if (toEvict <= 0) {
|
||||
mEvictionState = EvictionState::NO_EVICTION_NEEDED;
|
||||
@ -503,8 +504,11 @@ void TrackBuffersManager::CompleteResetParserState() {
|
||||
}
|
||||
}
|
||||
|
||||
int64_t TrackBuffersManager::EvictionThreshold() const {
|
||||
if (HasVideo()) {
|
||||
int64_t TrackBuffersManager::EvictionThreshold(
|
||||
TrackInfo::TrackType aType) const {
|
||||
MOZ_ASSERT(aType != TrackInfo::kTextTrack);
|
||||
if (aType == TrackInfo::kVideoTrack ||
|
||||
(aType == TrackInfo::kUndefinedTrack && HasVideo())) {
|
||||
return mVideoEvictionThreshold;
|
||||
}
|
||||
return mAudioEvictionThreshold;
|
||||
|
@ -108,8 +108,8 @@ class TrackBuffersManager final
|
||||
// add aSize bytes.
|
||||
// Eviction is done in two steps, first remove data up to aPlaybackTime
|
||||
// and if still more space is needed remove from the end.
|
||||
EvictDataResult EvictData(const media::TimeUnit& aPlaybackTime,
|
||||
int64_t aSize);
|
||||
EvictDataResult EvictData(const media::TimeUnit& aPlaybackTime, int64_t aSize,
|
||||
TrackType aType);
|
||||
|
||||
// Queue a task to run ChangeType
|
||||
void ChangeType(const MediaContainerType& aType);
|
||||
@ -131,7 +131,13 @@ class TrackBuffersManager final
|
||||
// The parent SourceBuffer is about to be destroyed.
|
||||
void Detach();
|
||||
|
||||
int64_t EvictionThreshold() const;
|
||||
// Return the eviction threshold, in bytes, for a track type (audio or video).
|
||||
// When the track type isn't passed in (kUndefinedTrack), this returns the
|
||||
// value for video if a video track is present. Specifying the track type
|
||||
// explicitely is useful when initialization hasn't finished, but the track
|
||||
// type is known already.
|
||||
int64_t EvictionThreshold(
|
||||
TrackInfo::TrackType aType = TrackInfo::TrackType::kUndefinedTrack) const;
|
||||
|
||||
// Interface for MediaSourceDemuxer
|
||||
MediaInfo GetMetadata() const;
|
||||
|
Loading…
Reference in New Issue
Block a user