NuPlayerRenderer latency calculation bug?

170 views
Skip to first unread message

Sangyoun Lee

unread,
Apr 22, 2015, 5:40:52 PM4/22/15
to android-...@googlegroups.com
Hi all,

I am working with external speaker which has large buffer. The audio latency is over 3 secs.
By the way, AV was out of sync in NuPlayer and there is a suspicious code in NuPlayerRenderer.cpp.(With AwesomePlayer, AV is in sync.)

Test env. - aosp 5.0.2_r1, Nexus7(flo)

line 1341-1347
  1.     } else {                         // case 3: transitory at new track or audio fast tracks.
  2.         res = mAudioSink->getPosition(&numFramesPlayed);
  3.         CHECK_EQ(res, (status_t)OK);
  4.         numFramesPlayedAt = nowUs;
  5.         numFramesPlayedAt += 1000LL * mAudioSink->latency() / 2; /* XXX */
  6.         //ALOGD("getPosition: %d %lld", numFramesPlayed, numFramesPlayedAt);
  7.     }
I do not understand why this division is needed:"mAudioSink->latency() / 2".

I have tested after removing the division: "numFramesPlayedAt += 1000LL * mAudioSink->latency();"
AV is in sync now. 

This looks like a bug. Is there anyone who has any ideas about this code?

Thanks,
Sangyoun



Sangyoun Lee

unread,
Apr 24, 2015, 5:50:36 PM4/24/15
to android-...@googlegroups.com
I found that mAudioSink->latency(_) does not work properly.

frameworks/av/media/libmedia/AudioTrack.cpp
1244     // FIXME don't believe this lie
1245     mLatency = afLatency + (1000*frameCount) / mSampleRate;

I had better find another way to resolve this issue.

Thanks,
Sangyoun

Glenn Kasten

unread,
Apr 24, 2015, 6:25:21 PM4/24/15
to android-...@googlegroups.com
Yes, this is a difficult situation :-(
The problem is that afLatency does not take into account all the components of the latency,
and is not always up-to-date for the current path to the sink.

Sangyoun Lee

unread,
Apr 27, 2015, 6:28:20 PM4/27/15
to android-...@googlegroups.com
Thank you, I have one more question.

I did not implement 'audio_hw.c' for our device yet. It means that get_presentation_position( ) function is not implemented, so in NuPlayerRender, getTimestamp( ) fails and then the XXX code runs.
Could you give me the best way to fix this? Implementing 'audio_hw.c' for our device is the best way?

Thanks again,
Sangyoun

Glenn Kasten

unread,
May 2, 2015, 3:21:55 PM5/2/15
to android-...@googlegroups.com
Yes, you need to implement this API for the A/V sync to work.
Reply all
Reply to author
Forward
0 new messages