问题
I am trying to analyze flow of messages exchanged while playing a video in Android. I came across this image while doing so.
http://img521.imageshack.us/img521/3585/capturehb.png
Then I went through the source files for AwesomePlayer and TimedEventQueue. I am unable to get what is meant by event in those files.
Any help regarding this is appreciated.
Thank you.
Link for TimedEventQueue source files is attached below.
https://github.com/cozybit/aosp-frameworks-base/blob/master/media/libstagefright/TimedEventQueue.cpp
回答1:
In general, TimedEventQueue
is a mechanism by which an event
is pushed into a queue
with a specific timeout
. At the end of the timeout
, a function associated with the event
is invoked which will perform some functionality. Coming to the relation of AwesomePlayer
and TimedEventQueue
, please find an overview of this relationship as below.
In Android, AwesomePlayer
is the core implementation of the player engine which spawns of the video
and audio
track related paths and helps in the overall functioning of the player
engine.
In addition to this, AwesomePlayer
serves as a SINK for the video
track i.e. a bridge between OMXCodec
i.e. video decoder
implementation and display pipeline i.e. SurfaceTexture
. Before going into the TimedEventQueue
, a brief summary of operation is as below.
The player
engine works in a pull
model and AwesomePlayer
pulls the video frame from the decoder through the read
call. Once a video frame is available, AV Synchronization
logic comes into picture which will decide when to render
the frame. Once the frame is ready to be rendered, it is passed to the SurfaceTexture
module through the mVideoRenderer->render
call.
Coming to TimedEventQueue
, AwesomePlayer
uses this concept to achieve the aforementioned functionality. When a start
is called, a postVideoEvent_l()
is invoked. By default, there is a time delay implemented in the android tree after which this event is triggered. When this event is triggered, a corresponding function is invoked. In this case, onVideoEvent
is invoked which will then proceed with the blocking read
call.
After a video buffer is received, if the video frame is earlier than the audio track timestamp by 10 ms, then another postVideoEvent_l(10000)
is triggered which will force this thread to sleep for 10 ms more, after which onVideoEvent
is again triggered.
Similarly, after a video frame is rendered
, then AwesomePlayer
will trigger another postVideoEvent_l()
which will sleep for default period of time and come back and block in read
call again.
来源:https://stackoverflow.com/questions/15664963/what-is-meant-by-event-in-android-media-player