Bug 1189602: [MSE] Always notify demuxer when data is added (or removed) to the resource. r=gerald

This commit is contained in:
Jean-Yves Avenard 2015-07-31 14:21:07 +10:00
Родитель 9fcb673926
Коммит 179ab5ffb6
2 изменённых файлов: 22 добавлений и 8 удалений

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

@ -370,6 +370,8 @@ TrackBuffersManager::CompleteResetParserState()
mInputBuffer = nullptr;
if (mCurrentInputBuffer) {
mCurrentInputBuffer->EvictAll();
// The demuxer will be recreated during the next run of SegmentParserLoop.
// As such we don't need to notify it that data has been removed.
mCurrentInputBuffer = new SourceBufferResource(mType);
}
@ -685,7 +687,7 @@ TrackBuffersManager::SegmentParserLoop()
}
// 2. If the input buffer does not contain a complete media segment header yet, then jump to the need more data step below.
if (mParser->MediaHeaderRange().IsNull()) {
mCurrentInputBuffer->AppendData(mInputBuffer);
AppendDataToCurrentInputBuffer(mInputBuffer);
mInputBuffer = nullptr;
NeedMoreData();
return;
@ -773,11 +775,24 @@ TrackBuffersManager::CreateDemuxerforMIMEType()
return;
}
void
TrackBuffersManager::AppendDataToCurrentInputBuffer(MediaByteBuffer* aData)
{
MOZ_ASSERT(mCurrentInputBuffer);
int64_t offset = mCurrentInputBuffer->GetLength();
mCurrentInputBuffer->AppendData(aData);
// A MediaByteBuffer has a maximum size of 2GiB.
mInputDemuxer->NotifyDataArrived(uint32_t(aData->Length()), offset);
}
void
TrackBuffersManager::InitializationSegmentReceived()
{
MOZ_ASSERT(mParser->HasCompleteInitData());
mCurrentInputBuffer = new SourceBufferResource(mType);
// The demuxer isn't initialized yet ; we don't want to notify it
// that data has been appended yet ; so we simply append the init segment
// to the resource.
mCurrentInputBuffer->AppendData(mParser->InitData());
uint32_t length =
mParser->InitSegmentRange().mEnd - (mProcessedInput - mInputBuffer->Length());
@ -990,6 +1005,7 @@ TrackBuffersManager::OnDemuxerInitDone(nsresult)
// This step has already been done in InitializationSegmentReceived when we
// transferred the content into mCurrentInputBuffer.
mCurrentInputBuffer->EvictAll();
mInputDemuxer->NotifyDataRemoved();
RecreateParser(true);
// 4. Set append state to WAITING_FOR_SEGMENT.
@ -1014,25 +1030,22 @@ TrackBuffersManager::CodedFrameProcessing()
MOZ_ASSERT(mProcessingPromise.IsEmpty());
nsRefPtr<CodedFrameProcessingPromise> p = mProcessingPromise.Ensure(__func__);
int64_t offset = mCurrentInputBuffer->GetLength();
MediaByteRange mediaRange = mParser->MediaSegmentRange();
uint32_t length;
if (mediaRange.IsNull()) {
length = mInputBuffer->Length();
mCurrentInputBuffer->AppendData(mInputBuffer);
AppendDataToCurrentInputBuffer(mInputBuffer);
mInputBuffer = nullptr;
} else {
// The mediaRange is offset by the init segment position previously added.
length = mediaRange.mEnd - (mProcessedInput - mInputBuffer->Length());
uint32_t length =
mediaRange.mEnd - (mProcessedInput - mInputBuffer->Length());
nsRefPtr<MediaByteBuffer> segment = new MediaByteBuffer;
MOZ_ASSERT(mInputBuffer->Length() >= length);
if (!segment->AppendElements(mInputBuffer->Elements(), length, fallible)) {
return CodedFrameProcessingPromise::CreateAndReject(NS_ERROR_OUT_OF_MEMORY, __func__);
}
mCurrentInputBuffer->AppendData(segment);
AppendDataToCurrentInputBuffer(segment);
mInputBuffer->RemoveElementsAt(0, length);
}
mInputDemuxer->NotifyDataArrived(length, offset);
DoDemuxVideo();

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

@ -160,6 +160,7 @@ private:
nsAutoPtr<ContainerParser> mParser;
// Demuxer objects and methods.
void AppendDataToCurrentInputBuffer(MediaByteBuffer* aData);
nsRefPtr<MediaByteBuffer> mInitData;
nsRefPtr<SourceBufferResource> mCurrentInputBuffer;
nsRefPtr<MediaDataDemuxer> mInputDemuxer;