Bug 1558364 - Convert TrackBuffersManager::mPendingInput into a MediaSpan. r=jya

This allows us to avoid a (probably small) copy when we stash the pending input.

Differential Revision: https://phabricator.services.mozilla.com/D34662

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris Pearce 2019-06-14 00:31:06 +00:00
Родитель d5f83d4740
Коммит 8f2dd4a937
3 изменённых файлов: 12 добавлений и 17 удалений

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

@ -64,6 +64,8 @@ class MediaSpan {
return (*mBuffer)[mStart + aIndex];
}
bool Append(const MediaSpan& aBuffer) { return Append(aBuffer.Buffer()); }
bool Append(MediaByteBuffer* aBuffer) {
if (!aBuffer) {
return true;

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

@ -447,7 +447,7 @@ void TrackBuffersManager::CompleteResetParserState() {
}
// 7. Remove all bytes from the input buffer.
mPendingInputBuffer = nullptr;
mPendingInputBuffer.reset();
mInputBuffer.reset();
if (mCurrentInputBuffer) {
mCurrentInputBuffer->EvictAll();
@ -787,8 +787,8 @@ void TrackBuffersManager::SegmentParserLoop() {
if (mPendingInputBuffer) {
// We now have a complete media segment header. We can resume
// parsing the data.
AppendDataToCurrentInputBuffer(mPendingInputBuffer);
mPendingInputBuffer = nullptr;
AppendDataToCurrentInputBuffer(*mPendingInputBuffer);
mPendingInputBuffer.reset();
}
mNewMediaSegmentStarted = false;
} else {
@ -797,10 +797,12 @@ void 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 (!mPendingInputBuffer) {
mPendingInputBuffer = new MediaByteBuffer();
mPendingInputBuffer = Some(MediaSpan(*mInputBuffer));
} else {
// Note we reset mInputBuffer below, so this won't end up appending
// the contents of mInputBuffer to itself.
mPendingInputBuffer->Append(*mInputBuffer);
}
mPendingInputBuffer->AppendElements(mInputBuffer->Elements(),
mInputBuffer->Length());
mInputBuffer.reset();
NeedMoreData();
@ -974,8 +976,7 @@ void TrackBuffersManager::OnDemuxerResetDone(const MediaResult& aResult) {
// We had a partial media segment header stashed aside.
// Reparse its content so we can continue parsing the current input buffer.
int64_t start, end;
mParser->ParseStartAndEndTimestamps(MediaSpan(mPendingInputBuffer), start,
end);
mParser->ParseStartAndEndTimestamps(*mPendingInputBuffer, start, end);
mProcessedInput += mPendingInputBuffer->Length();
}
@ -989,13 +990,6 @@ void TrackBuffersManager::AppendDataToCurrentInputBuffer(
mInputDemuxer->NotifyDataArrived();
}
void TrackBuffersManager::AppendDataToCurrentInputBuffer(
MediaByteBuffer* aData) {
MOZ_ASSERT(mCurrentInputBuffer);
mCurrentInputBuffer->AppendData(MediaSpan(aData));
mInputDemuxer->NotifyDataArrived();
}
void TrackBuffersManager::InitializationSegmentReceived() {
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(mParser->HasCompleteInitData());

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

@ -223,14 +223,13 @@ class TrackBuffersManager final
// Demuxer objects and methods.
void AppendDataToCurrentInputBuffer(const MediaSpan& aData);
void AppendDataToCurrentInputBuffer(MediaByteBuffer* aData);
RefPtr<MediaByteBuffer> mInitData;
// Temporary input buffer to handle partial media segment header.
// We store the current input buffer content into it should we need to
// reinitialize the demuxer once we have some samples and a discontinuity is
// detected.
RefPtr<MediaByteBuffer> mPendingInputBuffer;
Maybe<MediaSpan> mPendingInputBuffer;
RefPtr<SourceBufferResource> mCurrentInputBuffer;
RefPtr<MediaDataDemuxer> mInputDemuxer;
// Length already processed in current media segment.