Repository navigation
media: Support In-Place WebMStreamParser - #13017
Conversation
🤖 Gemini Suggested Commit Message💡 Pro Tips for a Better Commit Message:
|
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for zero-copy parsing of WebM media segments when BUILDFLAG(USE_STARBOARD_MEDIA) is enabled. It adds the WebMSegmentedBuffer interface and its implementation WebMSegmentedBufferImpl to allow parsing directly from non-contiguous stream segments, avoiding redundant copies of frame data. Feedback is provided to replace a DCHECK with a runtime parameter validation check in webm_crypto_helpers.cc to prevent a potential integer underflow vulnerability. Additionally, the newly added classes WebMSegmentedBuffer and WebMSegmentedBufferImpl should be updated with class comments documenting their purpose, lifetime, ownership, and threading model to comply with the repository style guide.
c4b216f to
2e05712
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces SegmentedByteQueue (with borrowed and owned implementations) and integrates it into the WebM stream and cluster parsers under the USE_STARBOARD_MEDIA build flag. This allows parsing of WebM media streams without redundant copying of appended data when borrow mode is enabled. Unit tests for the new queue are also added. The review feedback suggests enhancing the class comment for SegmentedByteQueue to explicitly document its expected lifetime and ownership, ensuring full compliance with the repository's style guide on class documentation.
2e05712 to
7c15129
Compare
7c15129 to
8872340
Compare
Add SegmentedByteQueue, the parse buffer interface for the in-place MSE stream parsers, with two implementations that SegmentedByteQueue::Create(borrow_mode) chooses between: - BorrowedSegmentedByteQueue holds appended byte ranges by reference instead of copying them. Each Push() becomes its own segment pointing directly at the caller's memory, kept alive by a release closure that is destroyed once the segment has been entirely popped, or on Reset() or destruction. - OwnedSegmentedByteQueue copies every append into one ByteQueue and destroys the release closure before Push() returns. Reads come in three forms, each taking an optional offset from the front of the queue: - PeekContiguousData() returns the run of bytes that is contiguous at an offset, without copying. - PeekSegmentedData() describes a range as an ordered list of runs, so that data straddling a segment boundary is returned in full, also without copying. - PeekLinearizedData() returns a range contiguously. The borrowed queue reads in place when the range lies within one segment, and otherwise gathers it into a scratch ByteQueue that is reused across calls and freed only on Reset(). The owned queue always reads in place. The queue lives in media/formats/common, next to OffsetByteQueue, since only the stream parsers use it, and is only built with use_starboard_media. ByteQueue gains a const Data() so that the owned queue's const reads can return spans. This is the storage behind the zero-copy MSE parsers enabled by kCobaltInPlaceMediaSourceParser. The MP4 and WebM parser changes build on top of this and land separately. Also add a "borrow_mode" bool param to kCobaltInPlaceMediaSourceParser, false by default, for the stream parsers to pass to SegmentedByteQueue::Create(). It chooses between borrowing appends, which deviates from the MSE specification, and copying each append into memory that the parser owns while still parsing it in place. Nothing reads it yet, so until the parsers do, the ArrayBuffer is retained and borrowed whenever the feature is enabled. Bug: 558350763 TAG=agy CONV=1df2b103-4f30-4fb5-9a48-dba07254227f
8872340 to
eee700a
Compare
xiaomings
left a comment
There was a problem hiding this comment.
Approve so we can merge it into the upcoming release.
eee700a to
6dc2ca7
Compare
When kCobaltInPlaceMediaSourceParser is enabled, Blink retains the buffer of every append and passes a release runner along with it. WebMStreamParser then holds the stream in a SegmentedByteQueue instead of `byte_queue_`, and parses it in place. The first append with a release runner creates the queue with SegmentedByteQueue::Create(), passing the feature's "borrow_mode" param, so each append is either borrowed or copied into memory the queue owns. The release runner must not be empty, and the two AppendToParseBuffer() overloads must not be mixed. Both are CHECKed. Give the WebM parsers overloads that take a SegmentedByteQueue and an offset instead of a pointer: - WebMParseElementHeader(), WebMListParser::Parse() and WebMClusterParser::Parse() read element headers in place, linearizing them only when they straddle a segment boundary. - WebMClusterParser hands contiguous elements to the pointer-based code. For a SimpleBlock that straddles a boundary, it linearizes only the block header, the Opus TOC and, when encrypted, the encryption header, and hands the frame data to the scatter-gather StreamParserBuffer::CopyFrom() as segments. A straddling Block or BlockAdditional is gathered straight from the segments. - WebMCreateDecryptConfig() gains an overload that takes the frame size separately, so it can work from just the encryption header. - Info and Tracks are small and are linearized before parsing. Add a scatter-gather StreamParserBuffer::CopyFrom() overload that takes the frame data as a span of segments and forwards them to ExternalMemoryAllocator::CopyFrom(parts, type), so a block that straddles an append boundary is copied once, straight into the decoder buffer. Bug: 558350763 TAG=agy CONV=f7ab1644-7417-41cb-a782-c47dc051b09f
6dc2ca7 to
a3f21e8
Compare
Refer to original PR: #13017 When kCobaltInPlaceMediaSourceParser is enabled, Blink retains the buffer of every append and passes a release runner along with it. WebMStreamParser then holds the stream in a SegmentedByteQueue instead of `byte_queue_`, and parses it in place. The first append with a release runner creates the queue with SegmentedByteQueue::Create(), passing the feature's "borrow_mode" param, so each append is either borrowed or copied into memory the queue owns. The release runner must not be empty, and the two AppendToParseBuffer() overloads must not be mixed. Both are CHECKed. Give the WebM parsers overloads that take a SegmentedByteQueue and an offset instead of a pointer: - WebMParseElementHeader(), WebMListParser::Parse() and WebMClusterParser::Parse() read element headers in place, linearizing them only when they straddle a segment boundary. - WebMClusterParser hands contiguous elements to the pointer-based code. For a SimpleBlock that straddles a boundary, it linearizes only the block header, the Opus TOC and, when encrypted, the encryption header, and hands the frame data to the scatter-gather StreamParserBuffer::CopyFrom() as segments. A straddling Block or BlockAdditional is gathered straight from the segments. - WebMCreateDecryptConfig() gains an overload that takes the frame size separately, so it can work from just the encryption header. - Info and Tracks are small and are linearized before parsing. Add a scatter-gather StreamParserBuffer::CopyFrom() overload that takes the frame data as a span of segments and forwards them to ExternalMemoryAllocator::CopyFrom(parts, type), so a block that straddles an append boundary is copied once, straight into the decoder buffer. Bug: 558350763 TAG=agy CONV=f7ab1644-7417-41cb-a782-c47dc051b09f (cherry picked from commit 10c5e9d)
…arser (#13319) Automated cherry-pick roll to staging. Original pull requests: - #13017 CONFLICTED files: ``` media/base/byte_queue.h ```⚠️ This PR has conflicts that must be resolved manually (don't forget to update the `.github/AUTOROLL` file). Use the following commands to checkout the branch locally and resolve the conflicts in a separate commit: ```bash gh pr checkout <pull_request_number> -R youtube/cobalt # Resolve conflicts and update .github/AUTOROLL then git add <resolved_files> # Copy CONFLICTED commit's message and metadata # Replace CONFLICTED in title with RESOLVED git commit -c <conflicted_sha> git push origin autoroll-main-to-staging ``` --------- Co-authored-by: Jason <jasonzh@google.com>
…arser Refer to original PR: #13017 When kCobaltInPlaceMediaSourceParser is enabled, Blink retains the buffer of every append and passes a release runner along with it. WebMStreamParser then holds the stream in a SegmentedByteQueue instead of `byte_queue_`, and parses it in place. The first append with a release runner creates the queue with SegmentedByteQueue::Create(), passing the feature's "borrow_mode" param, so each append is either borrowed or copied into memory the queue owns. The release runner must not be empty, and the two AppendToParseBuffer() overloads must not be mixed. Both are CHECKed. Give the WebM parsers overloads that take a SegmentedByteQueue and an offset instead of a pointer: - WebMParseElementHeader(), WebMListParser::Parse() and WebMClusterParser::Parse() read element headers in place, linearizing them only when they straddle a segment boundary. - WebMClusterParser hands contiguous elements to the pointer-based code. For a SimpleBlock that straddles a boundary, it linearizes only the block header, the Opus TOC and, when encrypted, the encryption header, and hands the frame data to the scatter-gather StreamParserBuffer::CopyFrom() as segments. A straddling Block or BlockAdditional is gathered straight from the segments. - WebMCreateDecryptConfig() gains an overload that takes the frame size separately, so it can work from just the encryption header. - Info and Tracks are small and are linearized before parsing. Add a scatter-gather StreamParserBuffer::CopyFrom() overload that takes the frame data as a span of segments and forwards them to ExternalMemoryAllocator::CopyFrom(parts, type), so a block that straddles an append boundary is copied once, straight into the decoder buffer. Bug: 558350763 TAG=agy CONV=f7ab1644-7417-41cb-a782-c47dc051b09f (cherry picked from commit 10c5e9d)
Refer to original PR: #13017 When kCobaltInPlaceMediaSourceParser is enabled, Blink retains the buffer of every append and passes a release runner along with it. WebMStreamParser then holds the stream in a SegmentedByteQueue instead of `byte_queue_`, and parses it in place. The first append with a release runner creates the queue with SegmentedByteQueue::Create(), passing the feature's "borrow_mode" param, so each append is either borrowed or copied into memory the queue owns. The release runner must not be empty, and the two AppendToParseBuffer() overloads must not be mixed. Both are CHECKed. Give the WebM parsers overloads that take a SegmentedByteQueue and an offset instead of a pointer: - WebMParseElementHeader(), WebMListParser::Parse() and WebMClusterParser::Parse() read element headers in place, linearizing them only when they straddle a segment boundary. - WebMClusterParser hands contiguous elements to the pointer-based code. For a SimpleBlock that straddles a boundary, it linearizes only the block header, the Opus TOC and, when encrypted, the encryption header, and hands the frame data to the scatter-gather StreamParserBuffer::CopyFrom() as segments. A straddling Block or BlockAdditional is gathered straight from the segments. - WebMCreateDecryptConfig() gains an overload that takes the frame size separately, so it can work from just the encryption header. - Info and Tracks are small and are linearized before parsing. Add a scatter-gather StreamParserBuffer::CopyFrom() overload that takes the frame data as a span of segments and forwards them to ExternalMemoryAllocator::CopyFrom(parts, type), so a block that straddles an append boundary is copied once, straight into the decoder buffer. Bug: 558350763 TAG=agy CONV=f7ab1644-7417-41cb-a782-c47dc051b09f (cherry picked from commit 10c5e9d)
When kCobaltInPlaceMediaSourceParser is enabled, Blink retains the buffer of every append and passes a release runner along with it. WebMStreamParser then holds the stream in a SegmentedByteQueue instead of
byte_queue_, and parses it in place. The first append with a release runner creates the queue with SegmentedByteQueue::Create(), passing the feature's "borrow_mode" param, so each append is either borrowed or copied into memory the queue owns.The release runner must not be empty, and the two AppendToParseBuffer() overloads must not be mixed. Both are CHECKed.
Give the WebM parsers overloads that take a SegmentedByteQueue and an offset instead of a pointer:
Add a scatter-gather StreamParserBuffer::CopyFrom() overload that takes the frame data as a span of segments and forwards them to ExternalMemoryAllocator::CopyFrom(parts, type), so a block that straddles an append boundary is copied once, straight into the decoder buffer.
Bug: 558350763
TAG=agy
CONV=f7ab1644-7417-41cb-a782-c47dc051b09f