11-07-2014 12:46 PM
Is there an sample code anywhere on how to use the Rtplib API to play an announcement?
Thanks,
Ben
Solved! Go to Solution.
11-17-2014 06:52 AM
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"); |
}
11-13-2014 11:37 AM
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
11-17-2014 06:52 AM
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"); |
}
11-17-2014 07:02 AM
Thanks so much!
03-31-2015 01:54 PM
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
03-31-2015 02:22 PM
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?
04-01-2015 06:22 AM
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?
04-02-2015 11:23 AM
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.
04-02-2015 01:00 PM
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.
04-02-2015 01:12 PM
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.
04-02-2015 01:27 PM
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
04-03-2015 08:23 AM
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).
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide