When both sides of the call are IP, the codec is selected from the list in the configuration file of both IP phones regardless of the codec’s set in the domain (IPGDC) or gateway (IPGKC), now for this scenario were both calls are IP, one of the phones will be determined as slave and the other as master, I think the master and slave selection process is when each phone generates a random number and the phone generating the highest number will be set as master, the master phone will check its codec list and pick the first codec see if its available in the slave phone list and that will be the call codec even if it was the last codec in the slave list, if the first codec that the master selected is not in the list of the slave phone, the master will pick the second codec in its list and so forth.
If one side of the call is a TDM phone, then the IP phone list will be filtered twice, first the IP phone list is compared to the domain list (IPGDC) and a new list is created which has the common codec’s in both the IP configuration file and the domain, any codec that is not found in both lists is thrown out, the new created list will be compared with the gatekeeper codec list (IPGKC) and the same process is applied, where the list that was produced through the comparison of IP phone list and Domain list, will now be compared and filtered through selecting only the common codec’s between the produced list and the gatekeeper list and the first codec in that list is then chosen.
Please post any correction about my comment that you might find here, this is to the best of my knowledge and I might be wrong, this seems to be a complicated process!