Hello,

I am trying to understand the logic for AV sync in Stagefright in Android
2.2, while playing youtube videos.

As per my understanding the main logic for AV Synchronization is in function
"onVideoEvent" in AwesomePlayer.cpp. Here basically we try to
compute the lateness of arrival of a decoded video frame, and based on the
amount of lateness(with respect to the AudioPlayer) decide whether to
render the video frame(which came in time) immediately or whether to render
it(which came before time) after some time or whether to drop
the particular frame(which came quite late).

While calculating the lateness, there is a call to
"AudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)". After seeing
the definition for
the function getMediaTimeMapping() and looking through the file
AudioPlayer.cpp, I concluded that

- The variable "realTimeUs" is the real-time position of Audio playback,
where was the audio track on the timeline, when this call was made?

1. Please let me know if this understanding of mine is correct?

- The variable "mediaTimeUs is the timestamp on the last AudioBuffer
read(decoded).

2. Please let me know if this understanding of mine is correct?

3. Hows the call to getMediaTimeMapping different from calling getRealTimeUs
and getMediaTimeUs  separately?

- In AudioPlayer.cpp this is how the mPositionTimeRealUs is calculated
    mPositionTimeRealUs=
                ((mNumFramesPlayed + size_done / mFrameSize) * 1000000)
                    / mSampleRate;
  and this is how mNumFramesPlayed is calculated

    mNumFramesPlayed += size_done / mFrameSize;
  This means mNumFramesPlayed is actual number of frames played. While this
would be logically true, if we started the media playback and
  continue without doing any seek operation. But when we do seek, It seems
that this logic of mPositionRealTimeUs does not hold good. This is
  what is my conclusion from printing continuous values of
mPositionRealTimeUs.

4. Please let me know, if this understanding of mine is correct?

5. When we call postEventWithDelay(10000), will it really post the event
after 10000uSecs. Looking at code I felt that it just
   inserts the event at a appropriate position in Queue. The event with max
realtime_us in last.
   Where does it ensure that a 10000 uSecs are calculated before the event
is posted?

Thanks in advance. I think that the answers to these questions would help me
understand the AV sync logic correctly.

regards
-Nitin

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: http://groups.google.com/group/android-porting

Reply via email to