Enforce RTC_API in tests and examples in case stdcall is used

This commit is contained in:
Paul-Louis Ageneau
2020-10-24 22:43:18 +02:00
parent 789ecd7977
commit 456365bc7c
5 changed files with 341 additions and 352 deletions

View File

@ -41,16 +41,16 @@ typedef struct {
bool connected;
} Peer;
static void dataChannelCallback(int pc, int dc, void *ptr);
static void descriptionCallback(int pc, const char *sdp, const char *type, void *ptr);
static void candidateCallback(int pc, const char *cand, const char *mid, void *ptr);
static void stateChangeCallback(int pc, rtcState state, void *ptr);
static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr);
static void closedCallback(int id, void *ptr);
static void messageCallback(int id, const char *message, int size, void *ptr);
static void deletePeer(Peer *peer);
static void RTC_API dataChannelCallback(int pc, int dc, void *ptr);
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr);
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr);
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr);
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr);
static void RTC_API closedCallback(int id, void *ptr);
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr);
static void RTC_API deletePeer(Peer *peer);
char* state_print(rtcState state);
char *state_print(rtcState state);
char *rtcGatheringState_print(rtcGatheringState state);
int all_space(const char *str);
@ -88,7 +88,8 @@ int main(int argc, char **argv) {
bool exit = false;
while (!exit) {
printf("\n");
printf("***************************************************************************************\n");
printf("***********************************************************************************"
"****\n");
printf("* 0: Exit /"
" 1: Enter remote description /"
" 2: Enter remote candidate /"
@ -118,26 +119,24 @@ int main(int argc, char **argv) {
char *line = NULL;
size_t len = 0;
size_t read = 0;
char *sdp = (char*) malloc(sizeof(char));
char *sdp = (char *)malloc(sizeof(char));
while ((read = getline(&line, &len, stdin)) != -1 && !all_space(line)) {
sdp = (char*) realloc (sdp,(strlen(sdp)+1) +strlen(line)+1);
sdp = (char *)realloc(sdp, (strlen(sdp) + 1) + strlen(line) + 1);
strcat(sdp, line);
}
printf("%s\n",sdp);
printf("%s\n", sdp);
rtcSetRemoteDescription(peer->pc, sdp, "offer");
free(sdp);
free(line);
break;
}
case 2: {
// Parse Candidate
printf("[Candidate]: ");
char* candidate = NULL;
char *candidate = NULL;
size_t candidate_size = 0;
if(getline(&candidate, &candidate_size, stdin)) {
if (getline(&candidate, &candidate_size, stdin)) {
rtcAddRemoteCandidate(peer->pc, candidate, "0");
free(candidate);
@ -150,15 +149,15 @@ int main(int argc, char **argv) {
}
case 3: {
// Send Message
if(!peer->connected) {
if (!peer->connected) {
printf("** Channel is not Open **");
break;
}
printf("[Message]: ");
char* message = NULL;
char *message = NULL;
size_t message_size = 0;
if(getline(&message, &message_size, stdin)) {
if (getline(&message, &message_size, stdin)) {
rtcSendMessage(peer->dc, message, -1);
free(message);
} else {
@ -169,7 +168,7 @@ int main(int argc, char **argv) {
}
case 4: {
// Connection Info
if(!peer->connected) {
if (!peer->connected) {
printf("** Channel is not Open **");
break;
}
@ -194,35 +193,32 @@ int main(int argc, char **argv) {
return 0;
}
static void descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
// Peer *peer = (Peer *)ptr;
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
printf("Description %s:\n%s\n", "answerer", sdp);
}
static void candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
// Peer *peer = (Peer *)ptr;
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
printf("Candidate %s: %s\n", "answerer", cand);
}
static void stateChangeCallback(int pc, rtcState state, void *ptr) {
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->state = state;
printf("State %s: %s\n", "answerer", state_print(state));
}
static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->gatheringState = state;
printf("Gathering state %s: %s\n", "answerer", rtcGatheringState_print(state));
}
static void closedCallback(int id, void *ptr) {
static void RTC_API closedCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = false;
}
static void messageCallback(int id, const char *message, int size, void *ptr) {
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr) {
if (size < 0) { // negative size indicates a null-terminated string
printf("Message %s: %s\n", "answerer", message);
} else {
@ -230,6 +226,17 @@ static void messageCallback(int id, const char *message, int size, void *ptr) {
}
}
static void RTC_API dataChannelCallback(int pc, int dc, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->dc = dc;
peer->connected = true;
rtcSetClosedCallback(dc, closedCallback);
rtcSetMessageCallback(dc, messageCallback);
char buffer[256];
if (rtcGetDataChannelLabel(dc, buffer, 256) >= 0)
printf("DataChannel %s: Received with label \"%s\"\n", "answerer", buffer);
}
static void deletePeer(Peer *peer) {
if (peer) {
if (peer->dc)
@ -240,17 +247,6 @@ static void deletePeer(Peer *peer) {
}
}
static void dataChannelCallback(int pc, int dc, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->dc = dc;
peer->connected = true;
rtcSetClosedCallback(dc, closedCallback);
rtcSetMessageCallback(dc, messageCallback);
char buffer[256];
if (rtcGetDataChannelLabel(dc, buffer, 256) >= 0)
printf("DataChannel %s: Received with label \"%s\"\n", "answerer", buffer);
}
char *state_print(rtcState state) {
char *str = NULL;
switch (state) {

View File

@ -41,21 +41,21 @@ typedef struct {
bool connected;
} Peer;
static void descriptionCallback(int pc, const char *sdp, const char *type, void *ptr);
static void candidateCallback(int pc, const char *cand, const char *mid, void *ptr);
static void stateChangeCallback(int pc, rtcState state, void *ptr);
static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr);
static void openCallback(int id, void *ptr);
static void closedCallback(int id, void *ptr);
static void messageCallback(int id, const char *message, int size, void *ptr);
static void deletePeer(Peer *peer);
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr);
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr);
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr);
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr);
static void RTC_API openCallback(int id, void *ptr);
static void RTC_API closedCallback(int id, void *ptr);
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr);
static void RTC_API deletePeer(Peer *peer);
char *state_print(rtcState state);
char *rtcGatheringState_print(rtcGatheringState state);
int all_space(const char *str);
int main(int argc, char **argv){
int main(int argc, char **argv) {
rtcInitLogger(RTC_LOG_DEBUG, NULL);
// Create peer
@ -79,7 +79,7 @@ int main(int argc, char **argv){
rtcSetStateChangeCallback(peer->pc, stateChangeCallback);
rtcSetGatheringStateChangeCallback(peer->pc, gatheringStateCallback);
// Since this is the offere, we will create a datachannel
// Since we are the offerer, we will create a datachannel
peer->dc = rtcCreateDataChannel(peer->pc, "test");
rtcSetOpenCallback(peer->dc, openCallback);
rtcSetClosedCallback(peer->dc, closedCallback);
@ -91,7 +91,8 @@ int main(int argc, char **argv){
while (!exit) {
printf("\n");
printf("***************************************************************************************\n");
printf("***********************************************************************************"
"****\n");
printf("* 0: Exit /"
" 1: Enter remote description /"
" 2: Enter remote candidate /"
@ -119,53 +120,49 @@ int main(int argc, char **argv){
// Parse Description
printf("[Description]: ");
char *line = NULL;
size_t len = 0;
size_t read = 0;
char *sdp = (char*) malloc(sizeof(char));
char *sdp = (char *)malloc(sizeof(char));
while ((read = getline(&line, &len, stdin)) != -1 && !all_space(line)) {
sdp = (char*) realloc (sdp,(strlen(sdp)+1) +strlen(line)+1);
sdp = (char *)realloc(sdp, (strlen(sdp) + 1) + strlen(line) + 1);
strcat(sdp, line);
}
printf("%s\n",sdp);
printf("%s\n", sdp);
rtcSetRemoteDescription(peer->pc, sdp, "answer");
free(sdp);
free(line);
break;
}
case 2: {
// Parse Candidate
printf("[Candidate]: ");
char* candidate = NULL;
char *candidate = NULL;
size_t candidate_size = 0;
if(getline(&candidate, &candidate_size, stdin)) {
if (getline(&candidate, &candidate_size, stdin)) {
rtcAddRemoteCandidate(peer->pc, candidate, "0");
free(candidate);
}else {
} else {
printf("Error reading line\n");
break;
}
break;
}
case 3: {
// Send Message
if(!peer->connected) {
if (!peer->connected) {
printf("** Channel is not Open **");
break;
}
printf("[Message]: ");
char* message = NULL;
char *message = NULL;
size_t message_size = 0;
if(getline(&message, &message_size, stdin)) {
if (getline(&message, &message_size, stdin)) {
rtcSendMessage(peer->dc, message, -1);
free(message);
}else {
} else {
printf("Error reading line\n");
break;
}
@ -174,7 +171,7 @@ int main(int argc, char **argv){
}
case 4: {
// Connection Info
if(!peer->connected) {
if (!peer->connected) {
printf("** Channel is not Open **");
break;
}
@ -199,44 +196,40 @@ int main(int argc, char **argv){
return 0;
}
static void descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
// Peer *peer = (Peer *)ptr;
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
printf("Description %s:\n%s\n", "offerer", sdp);
}
static void candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
// Peer *peer = (Peer *)ptr;
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
printf("Candidate %s: %s\n", "offerer", cand);
}
static void stateChangeCallback(int pc, rtcState state, void *ptr) {
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->state = state;
printf("State %s: %s\n", "offerer", state_print(state));
}
static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->gatheringState = state;
printf("Gathering state %s: %s\n", "offerer", rtcGatheringState_print(state));
}
static void openCallback(int id, void *ptr) {
static void RTC_API openCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = true;
char buffer[256];
if (rtcGetDataChannelLabel(peer->dc, buffer, 256) >= 0)
printf("DataChannel %s: Received with label \"%s\"\n","offerer", buffer);
printf("DataChannel %s: Received with label \"%s\"\n", "offerer", buffer);
}
static void closedCallback(int id, void *ptr) {
static void RTC_API closedCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = false;
}
static void messageCallback(int id, const char *message, int size, void *ptr) {
// Peer *peer = (Peer *)ptr;
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr) {
if (size < 0) { // negative size indicates a null-terminated string
printf("Message %s: %s\n", "offerer", message);
} else {

View File

@ -25,15 +25,15 @@ extern "C" {
#ifdef _WIN32
#define RTC_EXPORT __declspec(dllexport)
#else
#define RTC_EXPORT
#endif
#ifdef CAPI_STDCALL
#define RTC_API __stdcall
#else
#define RTC_API
#endif
#else // not WIN32
#define RTC_EXPORT
#define RTC_API
#endif
#ifndef RTC_ENABLE_WEBSOCKET
#define RTC_ENABLE_WEBSOCKET 1

View File

@ -42,33 +42,33 @@ typedef struct {
static Peer *peer1 = NULL;
static Peer *peer2 = NULL;
static void descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
Peer *peer = (Peer *)ptr;
printf("Description %d:\n%s\n", peer == peer1 ? 1 : 2, sdp);
Peer *other = peer == peer1 ? peer2 : peer1;
rtcSetRemoteDescription(other->pc, sdp, type);
}
static void candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
Peer *peer = (Peer *)ptr;
printf("Candidate %d: %s\n", peer == peer1 ? 1 : 2, cand);
Peer *other = peer == peer1 ? peer2 : peer1;
rtcAddRemoteCandidate(other->pc, cand, mid);
}
static void stateChangeCallback(int pc, rtcState state, void *ptr) {
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->state = state;
printf("State %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
}
static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->gatheringState = state;
printf("Gathering state %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
}
static void openCallback(int id, void *ptr) {
static void RTC_API openCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = true;
printf("DataChannel %d: Open\n", peer == peer1 ? 1 : 2);
@ -77,12 +77,12 @@ static void openCallback(int id, void *ptr) {
rtcSendMessage(peer->dc, message, -1); // negative size indicates a null-terminated string
}
static void closedCallback(int id, void *ptr) {
static void RTC_API closedCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = false;
}
static void messageCallback(int id, const char *message, int size, void *ptr) {
static void RTC_API messageCallback(int id, const char *message, int size, void *ptr) {
Peer *peer = (Peer *)ptr;
if (size < 0) { // negative size indicates a null-terminated string
printf("Message %d: %s\n", peer == peer1 ? 1 : 2, message);
@ -91,7 +91,7 @@ static void messageCallback(int id, const char *message, int size, void *ptr) {
}
}
static void dataChannelCallback(int pc, int dc, void *ptr) {
static void RTC_API dataChannelCallback(int pc, int dc, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->dc = dc;
peer->connected = true;

View File

@ -43,44 +43,44 @@ static Peer *peer2 = NULL;
static const char *mediaDescription = "video 9 UDP/TLS/RTP/SAVPF\r\n"
"a=mid:video\r\n";
static void descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
Peer *peer = (Peer *)ptr;
printf("Description %d:\n%s\n", peer == peer1 ? 1 : 2, sdp);
Peer *other = peer == peer1 ? peer2 : peer1;
rtcSetRemoteDescription(other->pc, sdp, type);
}
static void candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
static void RTC_API candidateCallback(int pc, const char *cand, const char *mid, void *ptr) {
Peer *peer = (Peer *)ptr;
printf("Candidate %d: %s\n", peer == peer1 ? 1 : 2, cand);
Peer *other = peer == peer1 ? peer2 : peer1;
rtcAddRemoteCandidate(other->pc, cand, mid);
}
static void stateChangeCallback(int pc, rtcState state, void *ptr) {
static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->state = state;
printf("State %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
}
static void gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->gatheringState = state;
printf("Gathering state %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
}
static void openCallback(int id, void *ptr) {
static void RTC_API openCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = true;
printf("Track %d: Open\n", peer == peer1 ? 1 : 2);
}
static void closedCallback(int id, void *ptr) {
static void RTC_API closedCallback(int id, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->connected = false;
}
static void trackCallback(int pc, int tr, void *ptr) {
static void RTC_API trackCallback(int pc, int tr, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->tr = tr;
peer->connected = true;