-
Notifications
You must be signed in to change notification settings - Fork 565
Add new consecutiveDroppedFrames callback #1917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* Called to report the number of consecutive frames dropped by the video renderer. Consecutive | ||
* dropped frames are reported when a frame is renderered after a the previous consecutive frames | ||
* were not rendered optionally, whenever the consecutive dropped frame count is above a specified | ||
* threshold whilst the renderer is started. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The javadoc for this method is a bit confusing. Perhaps there were some copy-paste logic errors from the onDroppedFrames javadoc?
With your proposed changes, MediaCodecVideoRenderer
will call onConsecutiveDroppedFrames
when the renderer successfully renderers a frame after dropping previous frames. Perhaps some developers may subclass MediaCodecVideoRenderer and DefaultRenderersFactory in order to add a threshold for reporting this value as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment has been fixed and should be much clearer as to the behavior.
@@ -1945,6 +1947,17 @@ private void maybeNotifyDroppedFrames() { | |||
} | |||
} | |||
|
|||
private void maybeNotifyConsecutiveDroppedFrames() { | |||
// TODO: Figure out the notification threshold for consecutive dropped frames. | |||
if (consecutiveDroppedFrameCount > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a threshold value, maxConsecutiveDroppedFramesToNotify? This would include adding an addition constructor for MediaCodecVideoRenderer and a default value in DefaultRenderersFactory
.
Our team will discuss the best initial value but for now you can set it the same as MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY
which is 50.
Tying the callback to a threshold will require applications that care about this metric to set a reasonable threshold for themselves. If an application does not care about this metric then the event will not be dispatched as often.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new MIN_CONSECUTIVE_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY = 5
value in the Default Renderer. Only getting notified when 50 consecutive frames have been dropped seems very high. But I'll defer the final value to the team.
I've updated all the constructors to take in the value, but that seems like a breaking change.
handler.post( | ||
() -> | ||
castNonNull(listener) | ||
.onConsecutiveDroppedFrames(consecutiveDroppedFrameCount, elapsedMs)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test to MediaCodecVideoRendererTest
to make sure that provided a very late buffer that is dropped that this event is invoked? You can look at MediaCodecVideoRendererTest::render_withLateBuffer_dropsBuffer
. May also be helpful to have unit tests for the event testing the output for if dropped frames occur prior to any successful renders and between successful renders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests covering both the API being invoked and only being invoked when there are enough frame drops.
@@ -1244,6 +1248,18 @@ default void onVideoInputFormatChanged( | |||
@UnstableApi | |||
default void onDroppedVideoFrames(EventTime eventTime, int droppedFrames, long elapsedMs) {} | |||
|
|||
/** | |||
* Called after consecutive video frames have been dropped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this event is called after an 'end' to the run of consecutive dropped frames.
private void maybeNotifyConsecutiveDroppedFrames() { | ||
// TODO: Figure out the notification threshold for consecutive dropped frames. | ||
if (consecutiveDroppedFrameCount > 0) { | ||
long elapsed = getClock().elapsedRealtime() - consecutiveDroppedFrameAccumulationStartTimeMs ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Include unit in variable name, elapsedMs
.
4ff5889
to
a20a1d8
Compare
This is similar to the `droppedFrames` callback, but represents the number of consecutive frames that we dropped before rendering a frame or seeking or stopping the renderer. While we already have a `maxConsecutiveDroppedFrame` available in the `DecoderCounters`, this doesn't provide enough visibility into the actual statistics of dropped frames. If we get 200 dropped frames and a `maxConsecutive` of 20, we don't know if we dropped 20 frames in a row once and then dropped a single frame 180 times or if we dropped 20 frames 10 times. We could add some code on our `OnDroppedFrames` callback to estimate if two calls are for consecutive frames, but that seems very fragile. Specifying when to invoke the callback is controlled by `minConsecutiveDroppedFramesToNotify` similar to the `maxDroppedFramesToNotify` but that would only notify if more than X consecutive frames were dropped. Adding support for both `MediaCodecVideoRenderer` and `DecoderVideoRenderer`.
a20a1d8
to
b3a6365
Compare
Hi @microkatz @tonihei @icbaker , is this ready to be pushed upstream? I see Gilles has addressed most comments |
Apologies for the delay! I was holding off from additional comments and edits as we instituted a new Builder pattern into MediaCodecVideoRenderer rather than adding new constructors for all these new variables/thresholds etc. This PR then got lost in the weeds after that was completed here, decfb9b. There are a few requests for the PR. First, would you be able to rebase to the tip of main and transition to a Builder parameter for your consecutiveDroppedFrames threshold? Secondly, in discussions with the team, it was thought better if we could still have a single listener event for dropped frames rather than two. The idea would be to add an additional parameter to onDroppedFrames for maxConsecutive. Currently, onDroppedFrames may be invoked when the dropped frames threshold is reached. This would be changed so that the invocation would occur where you are currently checking for consecutive frame drops notification. At onStopped, onDisabled, and after a successful frame render. Would this suggestion still work to provide you the granularity of analytics you need? Please reach out if you have additional questions. |
Thanks for the feedback @microkatz, a single listener would also work, as long as we make sure to invoke it appropriately. We'll update the pull request with a rebase and the changes. |
This is similar to the
droppedFrames
callback, but represents the number of consecutive frames that we dropped before rendering a frame or seeking or stopping the renderer.While we already have a
maxConsecutiveDroppedFrame
available in theDecoderCounters
, this doesn't provide enough visibility into the actual statistics of dropped frames.If we get 200 dropped frames and a
maxConsecutive
of 20, we don't know if we dropped 20 frames in a row once and then dropped a single frame 180 times or if we dropped 20 frames 10 times.We could add some code on our
OnDroppedFrames
callback to estimate if two calls are for consecutive frames, but that seems very fragile.There is an open issue currently on how often to notify, and my preference would be to add a new
minConsecutiveDroppedFramesToNotify
similar to themaxDroppedFramesToNotify
but that would only notify if more than X consecutive frames were dropped.