cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

1230
Views
0
Helpful
11
Replies
Beginner

Rtplib

Is there an sample code anywhere on how to use the Rtplib API to play an announcement?

Thanks,

Ben

1 ACCEPTED SOLUTION

Accepted Solutions
Beginner

Re: Rtplib

Here is the code sample that worked for me:

int rc;

    if (!EpApiInit ((PRTPLIBTRACE)rtpInitCallback, 21100, 500, AF_INET, NULL)) {

rc = EpApiGetLastError();
ERROR("TAPIWaveOut() - failed to initialize with error %d\n", rc);

    }

    m_media_handle = EpOpenById(p_dwWaveDeviceIDOut, Both, (PRTPENDPOINTCALLBACK)rtpEndpointCallback);

    if (m_media_handle == NULL) {

rc = EpApiGetLastError();
ERROR("TAPIWaveOut() - failed to open media handle with error %d\n", rc);

    }

m_stream_handle    = EpGetStreamHandle (m_media_handle, STREAM_TYPE_AUDIO, ToNwk);

    if (m_stream_handle == NULL) {

rc = EpApiGetLastError();
ERROR("MediaStreamStart() - failed to open stream handle with error %d\n", rc);
return -1;

    }

    rc = EpStreamStart (m_stream_handle, (PRTPENDPOINTCALLBACK)rtpDataCallback);

    if (rc == 0) {

rc = EpApiGetLastError();
ERROR("MediaStreamStart() - failed to start stream with error %d\n", rc);
return -1;

    }

FILE *fd = fopen(m_strFileName.c_str(), "r");

    fseek(fd, 0, SEEK_END);

    int fileSize = ftell(fd);

    fseek(fd, 0, SEEK_SET);

char *wav_buffer = (char *) malloc (sizeof(char)*fileSize);

    int rc = fread(wav_buffer, 1, fileSize, fd);  

    rc = EpStreamWrite (m_stream_handle, (PUCHAR)wav_buffer, fileSize, NULL, (PRTPENDPOINTCALLBACK)rtpWriteCallback);

    if (rc == 0) {

rc = EpApiGetLastError();
ERROR("Play() - failed to write stream with error %d\n", rc);
return -1;

    } else {

INFO("Play() - start stream succeeded\n");

    }

View solution in original post

11 REPLIES 11
Cisco Employee

Re: Rtplib

Hi Ben,

We covered this in the trouble ticket, and you've got it working.  Would you feel comfortable sharing your final code for this one operation? There's nothing confidential in the code snippet you sent me. 

Here's the sequence, for the benefit of others:

EpOpenById

EpGetStreamHandle

EpStreamStart

EpStreamWrite

Thanks,

Nick

Beginner

Re: Rtplib

Here is the code sample that worked for me:

int rc;

    if (!EpApiInit ((PRTPLIBTRACE)rtpInitCallback, 21100, 500, AF_INET, NULL)) {

rc = EpApiGetLastError();
ERROR("TAPIWaveOut() - failed to initialize with error %d\n", rc);

    }

    m_media_handle = EpOpenById(p_dwWaveDeviceIDOut, Both, (PRTPENDPOINTCALLBACK)rtpEndpointCallback);

    if (m_media_handle == NULL) {

rc = EpApiGetLastError();
ERROR("TAPIWaveOut() - failed to open media handle with error %d\n", rc);

    }

m_stream_handle    = EpGetStreamHandle (m_media_handle, STREAM_TYPE_AUDIO, ToNwk);

    if (m_stream_handle == NULL) {

rc = EpApiGetLastError();
ERROR("MediaStreamStart() - failed to open stream handle with error %d\n", rc);
return -1;

    }

    rc = EpStreamStart (m_stream_handle, (PRTPENDPOINTCALLBACK)rtpDataCallback);

    if (rc == 0) {

rc = EpApiGetLastError();
ERROR("MediaStreamStart() - failed to start stream with error %d\n", rc);
return -1;

    }

FILE *fd = fopen(m_strFileName.c_str(), "r");

    fseek(fd, 0, SEEK_END);

    int fileSize = ftell(fd);

    fseek(fd, 0, SEEK_SET);

char *wav_buffer = (char *) malloc (sizeof(char)*fileSize);

    int rc = fread(wav_buffer, 1, fileSize, fd);  

    rc = EpStreamWrite (m_stream_handle, (PUCHAR)wav_buffer, fileSize, NULL, (PRTPENDPOINTCALLBACK)rtpWriteCallback);

    if (rc == 0) {

rc = EpApiGetLastError();
ERROR("Play() - failed to write stream with error %d\n", rc);
return -1;

    } else {

INFO("Play() - start stream succeeded\n");

    }

View solution in original post

Cisco Employee

Re: Rtplib

Thanks so much!

Beginner

Re: Rtplib

I came back to this project after tabling it for a bit. Quite often, in response to my EpOpenById() calls I'm getting a EP_ERR_TOAPP_INVALID_STATE error. It doesn't happen every time, sometimes the call is successful. After I get the error I just wait some period of time and try again and it works. Any ideas? The documentation for TAPI media is sorely lacking.

Thanks,

Ben

Cisco Employee

Re: Rtplib

You'll get an EP_ERR_TOAPP_INVALID_STATE error if the stream is already started with EpStreamStart.  Maybe you're experiencing a timing issue or race condition?  Are you doing the epClose?  epApiClose before you exit the app?

Beginner

Re: Rtplib

I am doing an EpClose. I'm not calling EpApiClose because right now there is no graceful way to shut down the app. The sequence of function calls is this:

EpApiInit()

EpOpenById()

EpGetStreamHandle()

EpStreamStart()

EpStreamWrite()

EpStreamStop()

EpClose()

Strangely, I can't seem to get this to work at all now even after not running anything overnight. Does the rtplib output any logs anywhere? Is there a way to check if there are outstanding open streams and is there a way to force close them?

Beginner

Re: Rtplib

I managed to get things to a point where it is pretty reproducible and these are the steps and what I see:

EpApiInit()

EpOpenById()

EpGetStreamHandle()

EpStreamStart()

EpStreamWrite()

EpStreamStop()

EpClose()

This all succeeds. Then a second attempt (without restarting the app) fails on EpOpenById() with the EP_ERR_TOAPP_INVALID_STATE error.


If I stop my application and restart it I get the same exact behavior where the first attempt succeeds and the second one fails.

Cisco Employee

Re: Rtplib

What are your callbacks doing to make sure the data transfer is completed? 

As an aside, isn't there a way to capture whatever event closes the application so you can execute EpApiClose() in order to stop everything cleanly?  Even if that's not the cause of this problem, it's a good practice. 

Beginner

Re: Rtplib

That's another strange thing, even when everything works properly the only callback that gets called is the callback for EpStreamWrite(). In this case I'm just dumping the data out to the console so I can see when the transfer is done.

Beginner

Re: Rtplib

I just realized that at some point (probably after changing the code to properly shut things down) the error code changed to 17003 (EP_ERR_PARAM_INVALID) rather than 1301. I enabled highest level rtplib debugging and the exact error is:

EP_ERR_PARAM_INVALID: EpOpenAndSetId remote address not set for id: 34

Beginner

Re: Rtplib

Figured it out. Turns out you have to wait for a LINE_DEVSPECIFIC event before you can call EpOpenById(). The API documentation says that you need to wait for an event of type SLDSMT_START_TRANSMISION, however I was never seeing this type of event but I am getting an event of type SLDSMT_START_TRANSMISION_ADDRESSING_MODE (transmission is misspelled in the header file).

CreatePlease to create content
Content for Community-Ad
FusionCharts will render here