Fix delay used when polling for rendered buffers

If a desired render time earlier than the current system clock time is
provided to MediaCodec::releaseOutputBuffer, it is likely that the
onFrameRendered callback will be dropped. This is because the code that
sets the delay for polling for rendered buffers always assumes the
desired render time is in the future. This is not necessarily true if
apps choose to still specify a desired render time as soon as possible
to render a buffer that has been delayed due to decoding or network
problems, rather than using MediaCodec::releaseOutputBuffer that
has no desired render time parameter.

Bug: 288044725
Test: atest DecoderRenderTest
Change-Id: I40bb693405d2338cf1b43d9a0d8545386595e8ed
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index e0ebc11..1a8597f 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -6060,7 +6060,9 @@
             // presentation timestamp is used instead, which almost certainly occurs in the past,
             // since it's almost always a zero-based offset from the start of the stream. In these
             // scenarios, we expect the frame to be rendered with no delay.
-            int64_t delayUs = noRenderTime ? 0 : renderTimeNs / 1000 - ALooper::GetNowUs();
+            int64_t nowUs = ALooper::GetNowUs();
+            int64_t renderTimeUs = renderTimeNs / 1000;
+            int64_t delayUs = renderTimeUs < nowUs ? 0 : renderTimeUs - nowUs;
             delayUs += 100 * 1000; /* 100ms in microseconds */
             status_t err =
                     mMsgPollForRenderedBuffers->postUnique(/* token= */ mMsgPollForRenderedBuffers,