How a codec is invoked after receiving an incoming call

Hi all,

Can anyone please tell me how a codec is invoked after asterisk receives an incoming call? What is the sequence of events? Is there any web link where i could find info about it?

I have tried to find it out by looking at the source code but i am stuck.