0

I am going through the NuPlayer implementations in Android Stagefright. As per my understanding NuPlayerFactory is creating NuPlayerDriver in turn it creates ALooper and NuPlayer. I Couldn't understand ALooper and what does it do. I can see all the implementations in NuPlayer are invoking AMessage calls e.g as below:

NuPlyercpp: new AMessage(kWhatSourceNotify, id());

I am not sure how does it trigger NuPlayer::onMessageReceived(). Could readers please explain?

Ganesh
  • 5,880
  • 2
  • 36
  • 54
stackuser
  • 629
  • 8
  • 19

1 Answers1

2

In NuPlayerDriver constructor, you see

mPlayer = new NuPlayer;
mLooper->registerHandler(mPlayer);

This ALooper::registerHandler() uses a global ALooperRoster to remember the relation between a handler (mPlayer) and a looper (mLooper).

In NuPlyer.cpp, the general pattern is:

sp<AMessage> msg = new AMessage(..., id());
....
msg->post();

AMessage::post() calls the global ALooperRoster to post the message with 0 delay, using the relation that was established in NuPlayerDriver constructor.

Ganesh
  • 5,880
  • 2
  • 36
  • 54
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307