Skip to content

Commit

Permalink
Bug 1362440 - part2 : parsing entire content to decide whether it's m…
Browse files Browse the repository at this point in the history
…edia segment. r=kinetik

The spec [1] defines what's the media segment, and the parser would return error
if the format is not correct.

[1] https://w3c.github.io/media-source/webm-byte-stream-format.html

MozReview-Commit-ID: 4hq59Pywz2t
  • Loading branch information
alastor0325 committed Oct 30, 2017
1 parent d94b550 commit e31a334
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
31 changes: 10 additions & 21 deletions dom/media/mediasource/ContainerParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,20 @@ class WebMContainerParser : public ContainerParser
MediaResult IsMediaSegmentPresent(MediaByteBuffer* aData) override
{
ContainerParser::IsMediaSegmentPresent(aData);
// XXX: This is overly primitive, needs to collect data as it's appended
// to the SB and handle, rather than assuming everything is present in a
// single aData segment.
// 0x1a45dfa3 // EBML
// ...
// DocType == "webm"
// ...
// 0x18538067 // Segment (must be "unknown" size)
// 0x1549a966 // -> Segment Info
// 0x1654ae6b // -> One or more Tracks

// 0x1f43b675 // Cluster
if (aData->Length() < 4) {
return NS_ERROR_NOT_AVAILABLE;
}
if ((*aData)[0] == 0x1f && (*aData)[1] == 0x43 && (*aData)[2] == 0xb6 &&
(*aData)[3] == 0x75) {
return NS_OK;
}
// 0x1c53bb6b // Cues
if ((*aData)[0] == 0x1c && (*aData)[1] == 0x53 && (*aData)[2] == 0xbb &&
(*aData)[3] == 0x6b) {
return NS_OK;

WebMBufferedParser parser(0);
nsTArray<WebMTimeDataOffset> mapping;
ReentrantMonitor dummy("dummy");
parser.AppendMediaSegmentOnly();
bool result = parser.Append(aData->Elements(), aData->Length(), mapping,
dummy);
if (!result) {
return MediaResult(NS_ERROR_FAILURE, RESULT_DETAIL("Invalid webm content"));
}
return MediaResult(NS_ERROR_FAILURE, RESULT_DETAIL("Invalid webm content"));
return parser.GetClusterOffset() >= 0 ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}

MediaResult ParseStartAndEndTimestamps(MediaByteBuffer* aData,
Expand Down
6 changes: 6 additions & 0 deletions dom/media/webm/WebMBufferedParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ WebMBufferedParser::EndSegmentOffset(int64_t aOffset)
return mBlockEndOffset;
}

int64_t
WebMBufferedParser::GetClusterOffset() const
{
return mClusterOffset;
}

// SyncOffsetComparator and TimeComparator are slightly confusing, in that
// the nsTArray they're used with (mTimeMapping) is sorted by mEndOffset and
// these comparators are used on the other fields of WebMTimeDataOffset.
Expand Down
13 changes: 11 additions & 2 deletions dom/media/webm/WebMBufferedParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct WebMBufferedParser
, mVIntLeft(0)
, mBlockSize(0)
, mClusterTimecode(0)
, mClusterOffset(0)
, mClusterOffset(-1)
, mClusterEndOffset(-1)
, mBlockOffset(0)
, mBlockTimecode(0)
Expand All @@ -87,6 +87,12 @@ struct WebMBufferedParser
return mTimecodeScale;
}

// Use this function when we would only feed media segment for the parser.
void AppendMediaSegmentOnly()
{
mGotTimecodeScale = true;
}

// If this parser is not expected to parse a segment info, it must be told
// the appropriate timecode scale to use from elsewhere.
void SetTimecodeScale(uint32_t aTimecodeScale) {
Expand Down Expand Up @@ -115,6 +121,9 @@ struct WebMBufferedParser
// This allows to determine the end of the interval containg aOffset.
int64_t EndSegmentOffset(int64_t aOffset);

// Return the Cluster offset, return -1 if we can't find the Cluster.
int64_t GetClusterOffset() const;

// The offset at which this parser started parsing. Used to merge
// adjacent parsers, in which case the later parser adopts the earlier
// parser's mStartOffset.
Expand Down Expand Up @@ -232,7 +241,7 @@ struct WebMBufferedParser

// Start offset of the cluster currently being parsed. Used as the sync
// point offset for the offset-to-time mapping as each block timecode is
// been parsed.
// been parsed. -1 if unknown.
int64_t mClusterOffset;

// End offset of the cluster currently being parsed. -1 if unknown.
Expand Down

0 comments on commit e31a334

Please sign in to comment.