Skip to content

Commit

Permalink
Fix incorrect buffer size in NuPlayer
Browse files Browse the repository at this point in the history
This was discovered from running GTS tests that were failing because the
DRM implementation was receiving media packets of incorrect sizes for
decryption. The problem is that it was copying content using the size of
the underlying MediaBuffer object rather than the range that was set in
it. That was leading to lots of trailing garbage in media packets.
Generally this was fine and decoders would ignore them, but recent
changes in decryption handling for AMD platforms exposed this problem.

The fix is very straightforward in that we should be using the
range_length rather than the size when copying them. This doesn't impact
non-DRM content as those buffer sizes appear to be correct already based
on testing.

Bug: b:268158584
Test: gts.MediaPlayerTest#testLLAMA_H264_BASELINE_240P_800_DOWNLOADED_V1_ASYNC
      no longer shows corruption on guybrush and packet sizes now match
      up as expected
Change-Id: I14eda495fa76621436b212f2bd3ae9f7093137fe
  • Loading branch information
Narflex authored and thestinger committed Sep 18, 2023
1 parent c8117d1 commit f06d23d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,14 +1104,14 @@ bool NuPlayer::Decoder::onInputBufferFetched(const sp<AMessage> &msg) {
static_cast<MediaBufferHolder*>(holder.get())->mediaBuffer() : nullptr;
}
if (mediaBuf != NULL) {
if (mediaBuf->size() > codecBuffer->capacity()) {
if (mediaBuf->range_length() > codecBuffer->capacity()) {
handleError(ERROR_BUFFER_TOO_SMALL);
mDequeuedInputBuffers.push_back(bufferIx);
return false;
}

codecBuffer->setRange(0, mediaBuf->size());
memcpy(codecBuffer->data(), mediaBuf->data(), mediaBuf->size());
codecBuffer->setRange(0, mediaBuf->range_length());
memcpy(codecBuffer->data(), mediaBuf->data(), mediaBuf->range_length());

MetaDataBase &meta_data = mediaBuf->meta_data();
cryptInfo = NuPlayerDrm::getSampleCryptoInfo(meta_data);
Expand Down

0 comments on commit f06d23d

Please sign in to comment.