Bug 1610375 - Never use the ContainerParser for media segments unless we have first received an init segment. r=bryce

An error will be returned should it occur, we keep the code flow as-is in order to closely follow the MSE spec steps (https://w3c.github.io/media-source/#sourcebuffer-segment-parser-loop)

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2020-03-10 06:02:02 +00:00
parent 0af61b98f5
commit 90a12ad8b8
2 changed files with 25 additions and 8 deletions

View File

@ -193,7 +193,8 @@ class WebMContainerParser
// We should be more precise.
if (initSegment || !HasCompleteInitData()) {
if (mParser.mInitEndOffset > 0) {
MOZ_ASSERT(mParser.mInitEndOffset <= mResource->GetLength());
MOZ_DIAGNOSTIC_ASSERT(mInitData && mResource &&
mParser.mInitEndOffset <= mResource->GetLength());
if (!mInitData->SetLength(mParser.mInitEndOffset, fallible)) {
// Super unlikely OOM
return NS_ERROR_OUT_OF_MEMORY;
@ -539,6 +540,9 @@ class MP4ContainerParser : public ContainerParser,
return NS_ERROR_NOT_AVAILABLE;
}
MOZ_DIAGNOSTIC_ASSERT(mResource && mParser && mInitData,
"Should have received an init segment first");
mResource->AppendData(aData);
MediaByteRangeSet byteRanges;
byteRanges +=

View File

@ -826,14 +826,27 @@ void TrackBuffersManager::SegmentParserLoop() {
return;
}
int64_t start, end;
MediaResult newData =
mParser->ParseStartAndEndTimestamps(*mInputBuffer, start, end);
if (!NS_SUCCEEDED(newData) && newData.Code() != NS_ERROR_NOT_AVAILABLE) {
RejectAppend(newData, __func__);
return;
MOZ_ASSERT(mSourceBufferAttributes->GetAppendState() ==
AppendState::PARSING_INIT_SEGMENT ||
mSourceBufferAttributes->GetAppendState() ==
AppendState::PARSING_MEDIA_SEGMENT);
int64_t start = 0;
int64_t end = 0;
MediaResult newData = NS_ERROR_NOT_AVAILABLE;
if (mSourceBufferAttributes->GetAppendState() ==
AppendState::PARSING_INIT_SEGMENT ||
(mSourceBufferAttributes->GetAppendState() ==
AppendState::PARSING_MEDIA_SEGMENT &&
mFirstInitializationSegmentReceived && !mChangeTypeReceived)) {
newData = mParser->ParseStartAndEndTimestamps(*mInputBuffer, start, end);
if (NS_FAILED(newData) && newData.Code() != NS_ERROR_NOT_AVAILABLE) {
RejectAppend(newData, __func__);
return;
}
mProcessedInput += mInputBuffer->Length();
}
mProcessedInput += mInputBuffer->Length();
// 5. If the append state equals PARSING_INIT_SEGMENT, then run the
// following steps: