The speech recognition version of chantest provides a good example for showing the behavior of implicit resource allocation for the following reasons:
To make chantest support delayed resource allocation, IRP_RESOURCE_RETURNMODE must be set. After the channel is successfully initialized, from within the IRE_EXEC case of the main while loop, the parameter is set as follows:
if (irSetParam(cid, IRP_RESOURCE_RETURNMODE,
DELAYED_GRANT_TIMEOUT) == IRR_FAIL) {
cleanup ("Error on irSetParam", cid);
break;
}
DELAYED_GRANT_TIMEOUT is defined elsewhere as 10000 milliseconds:
#define DELAYED_GRANT_TIMEOUT 10000
If speech recognition cannot be started due to insufficient resource (return code of IRR_PENDING), the play is not started, chantest waits for the IRE_GRANT event before play is started. Recognition is started in the functions playInstr() and reprompt(). Both functions are updated as follows.
void playInstr(channel_id cid)
{
.
.
.
int ret;
.
.
.
ret = irStartRecog(cid,0);
if (ret == IRR_FAIL) {
cleanup("irStartRecog Error", cid);
return;
} else if (ret == IRR_PENDING) {
return;
}
.
.
.
}
Finally, event handling code must be added for IRE_GRANT and IRE_DENY, and IRE_ECHO_START must deal with the IREM_DENY modifier.
while (irWCheck(&ev) != IRR_FAIL) {
.
.
.
switch (ev.event_id) {
.
.
.
case IRE_ECHO_START:
if (ev.event_mod1 == IREM_ERROR || ev.event_mod1 == IREM_DENY) {
cleanup("IRE_ECHO_START reports IREM_ERROR/IREM_DENY", cid);
break;
}
.
.
.
case IRE_GRANT:
if (irLibState(cid) == IRS_PLAY_QUEUED) {
/* Recognition resources were delayed, start play now */
if (irEnd(cid, 0, 0) == IRR_FAIL) {
cleanup("Error on irEnd", cid);
}
}
break;
case IRE_DENY:
/* Recognition resources denied. Note: echo cancellation and
* play resource allocation is indicated through an
* an IRE_ECHO_START and IRE_PLAY_DONE event with an IREM_DENY
* event respectively. */
cleanup("Resources for recognition denied.",cid);
break;
.
.
.
}
}
If the IRE_GRANT is due to play or echo cancellation, it is ignored and the program continues as normal. If echo cancellation resources are denied, the program drops the call. The program ignores play failures for any reason and continues, most likely attempting to reprompt.