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; mInputBuffer = nullptr;
if (mCurrentInputBuffer) { if (mCurrentInputBuffer) {
mCurrentInputBuffer->EvictAll(); 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); 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. // 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()) { if (mParser->MediaHeaderRange().IsNull()) {
mCurrentInputBuffer->AppendData(mInputBuffer); AppendDataToCurrentInputBuffer(mInputBuffer);
mInputBuffer = nullptr; mInputBuffer = nullptr;
NeedMoreData(); NeedMoreData();
return; return;
@ -773,11 +775,24 @@ TrackBuffersManager::CreateDemuxerforMIMEType()
return; 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 void
TrackBuffersManager::InitializationSegmentReceived() TrackBuffersManager::InitializationSegmentReceived()
{ {
MOZ_ASSERT(mParser->HasCompleteInitData()); MOZ_ASSERT(mParser->HasCompleteInitData());
mCurrentInputBuffer = new SourceBufferResource(mType); 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()); mCurrentInputBuffer->AppendData(mParser->InitData());
uint32_t length = uint32_t length =
mParser->InitSegmentRange().mEnd - (mProcessedInput - mInputBuffer->Length()); mParser->InitSegmentRange().mEnd - (mProcessedInput - mInputBuffer->Length());
@ -990,6 +1005,7 @@ TrackBuffersManager::OnDemuxerInitDone(nsresult)
// This step has already been done in InitializationSegmentReceived when we // This step has already been done in InitializationSegmentReceived when we
// transferred the content into mCurrentInputBuffer. // transferred the content into mCurrentInputBuffer.
mCurrentInputBuffer->EvictAll(); mCurrentInputBuffer->EvictAll();
mInputDemuxer->NotifyDataRemoved();
RecreateParser(true); RecreateParser(true);
// 4. Set append state to WAITING_FOR_SEGMENT. // 4. Set append state to WAITING_FOR_SEGMENT.
@ -1014,25 +1030,22 @@ TrackBuffersManager::CodedFrameProcessing()
MOZ_ASSERT(mProcessingPromise.IsEmpty()); MOZ_ASSERT(mProcessingPromise.IsEmpty());
nsRefPtr<CodedFrameProcessingPromise> p = mProcessingPromise.Ensure(__func__); nsRefPtr<CodedFrameProcessingPromise> p = mProcessingPromise.Ensure(__func__);
int64_t offset = mCurrentInputBuffer->GetLength();
MediaByteRange mediaRange = mParser->MediaSegmentRange(); MediaByteRange mediaRange = mParser->MediaSegmentRange();
uint32_t length;
if (mediaRange.IsNull()) { if (mediaRange.IsNull()) {
length = mInputBuffer->Length(); AppendDataToCurrentInputBuffer(mInputBuffer);
mCurrentInputBuffer->AppendData(mInputBuffer);
mInputBuffer = nullptr; mInputBuffer = nullptr;
} else { } else {
// The mediaRange is offset by the init segment position previously added. // 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; nsRefPtr<MediaByteBuffer> segment = new MediaByteBuffer;
MOZ_ASSERT(mInputBuffer->Length() >= length); MOZ_ASSERT(mInputBuffer->Length() >= length);
if (!segment->AppendElements(mInputBuffer->Elements(), length, fallible)) { if (!segment->AppendElements(mInputBuffer->Elements(), length, fallible)) {
return CodedFrameProcessingPromise::CreateAndReject(NS_ERROR_OUT_OF_MEMORY, __func__); return CodedFrameProcessingPromise::CreateAndReject(NS_ERROR_OUT_OF_MEMORY, __func__);
} }
mCurrentInputBuffer->AppendData(segment); AppendDataToCurrentInputBuffer(segment);
mInputBuffer->RemoveElementsAt(0, length); mInputBuffer->RemoveElementsAt(0, length);
} }
mInputDemuxer->NotifyDataArrived(length, offset);
DoDemuxVideo(); DoDemuxVideo();

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

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