Bug 1002994 - Remove array of old decoders from SourceBuffer, just keep a reference to the current decoder. r=cajbir

This commit is contained in:
Matthew Gregan 2014-04-28 23:12:00 +12:00
Родитель 5d37b4d754
Коммит bf1587c898
2 изменённых файлов: 31 добавлений и 42 удалений

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

@ -198,12 +198,8 @@ SourceBuffer::GetBuffered(ErrorResult& aRv)
return nullptr;
}
nsRefPtr<TimeRanges> ranges = new TimeRanges();
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
nsRefPtr<TimeRanges> r = new TimeRanges();
mDecoders[i]->GetBuffered(r);
if (r->Length() > 0) {
ranges->Add(r->GetStartTime(), r->GetEndTime());
}
if (mDecoder) {
mDecoder->GetBuffered(ranges);
}
ranges->Normalize();
return ranges.forget();
@ -270,10 +266,10 @@ SourceBuffer::Abort(ErrorResult& aRv)
mAppendWindowStart = 0;
mAppendWindowEnd = PositiveInfinity<double>();
MSE_DEBUG("%p Abort: Discarding decoders.", this);
if (mCurrentDecoder) {
mCurrentDecoder->GetResource()->Ended();
mCurrentDecoder = nullptr;
MSE_DEBUG("%p Abort: Discarding decoder.", this);
if (mDecoder) {
mDecoder->GetResource()->Ended();
mDecoder = nullptr;
}
}
@ -300,16 +296,15 @@ void
SourceBuffer::Detach()
{
Ended();
mDecoders.Clear();
mCurrentDecoder = nullptr;
mDecoder = nullptr;
mMediaSource = nullptr;
}
void
SourceBuffer::Ended()
{
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
mDecoders[i]->GetResource()->Ended();
if (mDecoder) {
mDecoder->GetResource()->Ended();
}
}
@ -341,8 +336,8 @@ SourceBuffer::Create(MediaSource* aMediaSource, const nsACString& aType)
SourceBuffer::~SourceBuffer()
{
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
mDecoders[i]->GetResource()->Ended();
if (mDecoder) {
mDecoder->GetResource()->Ended();
}
}
@ -381,11 +376,7 @@ SourceBuffer::InitNewDecoder()
if (!decoder) {
return false;
}
mDecoders.AppendElement(decoder);
// XXX: At this point, we really want to push through any remaining
// processing for the old decoder and discard it, rather than hanging on
// to all of them in mDecoders.
mCurrentDecoder = decoder;
mDecoder = decoder;
return true;
}
@ -430,10 +421,10 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR
// TODO: Test buffer full flag.
StartUpdating();
// TODO: Run buffer append algorithm asynchronously (would call StopUpdating()).
if (mParser->IsInitSegmentPresent(aData, aLength) || !mCurrentDecoder) {
MSE_DEBUG("%p AppendBuffer: New initialization segment, switching decoders.", this);
if (mCurrentDecoder) {
mCurrentDecoder->GetResource()->Ended();
if (!mDecoder || mParser->IsInitSegmentPresent(aData, aLength)) {
MSE_DEBUG("%p AppendBuffer: New initialization segment, creating decoder.", this);
if (mDecoder) {
mDecoder->GetResource()->Ended();
}
if (!InitNewDecoder()) {
aRv.Throw(NS_ERROR_FAILURE); // XXX: Review error handling.
@ -441,10 +432,10 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR
}
}
// XXX: For future reference: NDA call must run on the main thread.
mCurrentDecoder->NotifyDataArrived(reinterpret_cast<const char*>(aData),
aLength,
mCurrentDecoder->GetResource()->GetLength());
mCurrentDecoder->GetResource()->AppendData(aData, aLength);
mDecoder->NotifyDataArrived(reinterpret_cast<const char*>(aData),
aLength,
mDecoder->GetResource()->GetLength());
mDecoder->GetResource()->AppendData(aData, aLength);
// Eviction uses a byte threshold. If the buffer is greater than the
// number of bytes then data is evicted. The time range for this
@ -452,7 +443,7 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR
// evict data before that range across all SourceBuffer's it knows
// about.
const int evict_threshold = 1000000;
bool evicted = mCurrentDecoder->GetResource()->EvictData(evict_threshold);
bool evicted = mDecoder->GetResource()->EvictData(evict_threshold);
if (evicted) {
double start = 0.0;
double end = 0.0;
@ -485,14 +476,15 @@ SourceBuffer::GetBufferedStartEndTime(double* aStart, double* aEnd)
void
SourceBuffer::Evict(double aStart, double aEnd)
{
for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
// Need to map time to byte offset then evict
int64_t end = mDecoders[i]->ConvertToByteOffset(aEnd);
if (end <= 0) {
NS_WARNING("SourceBuffer::Evict failed");
continue;
}
mDecoders[i]->GetResource()->EvictBefore(end);
if (!mDecoder) {
return;
}
// Need to map time to byte offset then evict
int64_t end = mDecoder->ConvertToByteOffset(aEnd);
if (end > 0) {
mDecoder->GetResource()->EvictBefore(end);
} else {
NS_WARNING("SourceBuffer::Evict failed");
}
}

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

@ -140,10 +140,7 @@ private:
nsAutoPtr<ContainerParser> mParser;
// XXX: We only want to keep the current decoder alive, but need a way to
// query @buffered for everything this SourceBuffer is responsible for.
nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders;
nsRefPtr<SubBufferDecoder> mCurrentDecoder;
nsRefPtr<SubBufferDecoder> mDecoder;
double mAppendWindowStart;
double mAppendWindowEnd;