# Native play

To implement native play functionality, the application performs the following tasks:

- Opens the ADI API on the context and starts the NOCC protocol.

- Opens the MSPP API on the context and creates an RTP endpoint.

- Retrieves the filter ID of the RTP endpoint.

- Supplies the ADI API with information about the RTP audio streams and specifies the desired behavior for native play operations.

- Starts and stops playing audio data from a native audio stream.

The following illustration shows an overview of the native play mechanism:

## Sample procedure

When implementing native play functionality, applications use functions from the following resources:

- NaturalAccess functions to set up event queues and contexts, and to open services on the contexts.

- ADI API functions to start a protocol, to set native play settings, and to play audio data.

- MSPP API functions to create an RTP endpoint and retrieve the unique filter ID for the endpoint.

The following procedure shows the function sequence used to implement a typical native play operation:

Step | Action
1 | ctaCreateQueue creates a NaturalAccess event queue. ctaCreateQueue (&queuehd)
2 | ctaCreateContext creates a NaturalAccess context for the audio channel. ctaCreateContext (queuehd, &ctahd)
3 | ctaOpenServices opens the ADI and MSPP APIs on the context. ctaOpenServices (ctahd, svclist, nsvcs)
4 | adiStartProtocol starts the nocc protocol on the ADI port. adiStartProtocol (ctahd, "nocc", NULL, startparms)
5 | mspCreateEndpoint creates an audio MSPP API RTP endpoint and returns an MSPP API endpoint handle (ephd). mspCreateEndpoint (ctahd, msp addrstruct, msp parmstruct, &rtpephd)
6 | mspGetFilterHandle retrieves the runtime filter ID (fltID) associated with the RTP endpoint handle (ephd). The application uses the returned fltID as the destination for the audio stream played out from the ADI port. mspGetFilterHandle (rtpephd, MSP_ENDPOINT_RTPFDX, &fltID)
7 | adiSetNativeInfo specifies both the context handle of the ADI port and the RTP endpoint fltID returned by mspGetFilterHandle, sets NMS native play parameters. adiSetNativeInfo (ctahd, NULL, fltID, fltID_parms)
8 | adiPlayFromMemory starts playing a message. adiPlayFromMemory (ctahd, encoding, buffer, bufsize, parms)
9 | adiStopPlaying stops playing the message. adiStopPlaying (ctahd)

## Example

The following example shows how to perform a native play operation:

ret = ctaCreateQueue( NULL, 0, &hCtaQueueHd );
ret = ctaCreateContext( hCtaQueueHd, 0, "Play", &ctahd );
ServiceCount = 2;
ServDesc[0].name.svcname = "ADI";
ServDesc[0].name.svcmgrname = "ADIMGR";
ServDesc[0].mvipaddr.board = board;
ServDesc[0].mvipaddr.mode = 0;
ServDesc[1].name.svcname = "MSP";
ServDesc[1].name.svcmgrname = "MSPMGR";
ret = ctaOpenServices( ctahd, ServDesc, ServiceCount );
ret = WaitForSpecificEvent( CTAEVN_OPEN_SERVICES_DONE, &event );
ret = adiStartProtocol( ctahd, "nocc", NULL, NULL );
ret = WaitForSpecificEvent( ADIEVN_STARTPROTOCOL_DONE, &event );
// create mspp RTP endpoint
ret = mspCreateEndpoint( ctahd, &mspAddr, &mspParm, &ephd );
ret = WaitForSpecificEvent( MSPEVN_CREATE_ENDPOINT_DONE, &event );
// get cg6xxx board handle
ret = mspGetFilterHandle( msphd, MSP_FILTER_RTPFDX_EPH, rtp_play_filter_handle );
ret = adiSetNativeInfo( ctahd, NULL, /* no ingress handle, as this is a play only */
rtp_play_filter_handle, &natpr_ctl ); /* RTP endpoint filter ID
specified as a destination for audio */
ret = adiPlayFromMemory( ctahd, ADI_ENCODE_EDTX_AMRNB, /* audio play */
MemoryBuffer, RecordedBytes, NULL );