-
Notifications
You must be signed in to change notification settings - Fork 81
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
Video decoders on FTV3 (AFTN) have huge latency (~2 seconds) #42
Comments
The MediaCodec documentation states that Line 1251 in 3f2fa55
but it is ignored:
|
acknowledged. investigating |
Thanks @peddisri. Let me know if I can help in any way. |
The decoder has a max buffer that can hold upto 2 seconds of video frames. Hence Exo ends up spending lot of time in queuing up these buffers since the feeding data to input is a tight loop. Thereafter it goes into drainOutputBuffer mode. After you seeing any issue in the app playback due to this? |
I am playing a live stream from a network tuner device, so the 2s buffer introduces a large delay in playback. Does setting max-input-size make any difference? I thought exoplayer already calculates and sets it based on the stream: Lines 1096 to 1104 in 3f2fa55
Lines 1120 to 1121 in 3f2fa55
|
Well, this sets the max size of every frame. I tried to find if there is any API to configure number of input buffers, but Looks like there is none. |
I don't think it's per frame, but total for the decoder. That's why exoplayer uses
I tried something like this, but it doesn't work very well. If you don't feed in 2s of data into the decoder, it will stop returning frames. This seems like a bug in the hardware decoder. I don't see the same behavior on other devices using OMX.amlogic decoder, so perhaps the video driver on the AFTN needs to be updated in the next fireos release. |
No, this is per frame. They allocated for max possible input size. Its not 3 frames. |
The comment in the code says:
which I thought means "estimate input size assuming three [...] input frames" but I guess I misunderstood. The documentation for
So you are correct, it is the buffer size for one input frame. |
Can you share the code snippet where you put the hack? I think that should have worked. There is no reason for decoder to wait till 2 sec input buffers are available. of course what would happen is that you get into feedInputBuffer loop, break after say 6 frames, then immediately get into draingOutputBufferLoop. At this time, the decoder may not be ready with buffers immediately. So you get into feedInputBufferloop again, and this time again you feed 6 frames. Then hopefully drainOutputBuffers should have some output buffer. Can you enable verbose logging by doing this in PlayerActivity.java in onCreate and share the logs. Logger.setLogLevel(Logger.Module.Video, Log.DEBUG); |
Another question is that are you making sure that the first frame is I frame? I'm assuming since its a tuner, maybe you just start feeding the frames from P frame, which again means it is possible that decoder is waiting for the first I frame to start decoding. I'm checking this internally with my codec team and will let you know soon. |
@tmm1 any update on my last question? |
Sorry for the delay. I was traveling so I did not have access to my FTV3 for testing. I tried what you suggested, but it has no effect. I added the following patch to limit the input buffers: diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java
index fb4be054d..b7750b76c 100755
--- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java
@@ -602,8 +605,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
maybeInitCodec();
if (codec != null) {
TraceUtil.beginSection("drainAndFeed");
+ int n = 0;
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
- while (feedInputBuffer()) {}
+ while (feedInputBuffer() && n++ < 6) {}
TraceUtil.endSection();
} else {
decoderCounters.skippedInputBufferCount += skipSource(positionUs); But when I play any file, the DELAY reported by earlier patch is still ~2s:
The decoder refuses to produce any output buffers until 2 seconds of input data has been queued. This delay seems to be hard-coded somewhere in the driver. As I mentioned earlier, I only see this behavior on the FTV3 (and now the new FTV Cube also), but not any other Android TV devices which also use the same AMLogic chipset. The behavior is the same for all streams. For example if I use the "Apple 16x9 basic stream" test, it shows the same delay:
I already provided all the details necessary to reproduce this issue, and as I mentioned it happens with any video input. But since you asked, I am also attaching the verbose logs with the Module.Video=DEBUG enabled (also includes my DELAY patch above, using HLS > Apple 16x9 basic stream): https://paste.ubuntu.com/p/88h6zBy6sw/ |
Thank you for your response. I'll take a look. |
Were you able to reproduce this issue? |
yes |
I'm afraid, my earlier comment was invalid.My observation of the logs was incorrect. The reason for the delay is not video decoder. I think the Audio Track position does not move, and that's why the video rendering pipeline does not proceed. Need more investigation. |
I have been experiencing issues using MediaCodec directly on the new 3rd generation Fire TV, and have traced it back to an unexpected 2s decoding delay in both the mpeg2 and h264 MediaCodec decoders on that device.
To demonstrate, I wrote the following patch for exoplayer which logs the difference between the input and output timestamps. On most devices, this is under 200ms, but on the FTV3 it is 2000ms.
After applying the above, here is a sample log when playing back 720p-h264-60fps.ts. Notice there are no logs between
16:30:21.592
and16:30:23.073
, a two second gap where no video frames are received:If I try the same test on FTVStick2 (AFTT), you can see the calculated delay value is much more reasonable (~200ms):
The text was updated successfully, but these errors were encountered: