mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 23:25:33 +00:00
Enforce RTC_API in tests and examples in case stdcall is used
This commit is contained in:
@ -41,14 +41,14 @@ 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 *rtcGatheringState_print(rtcGatheringState state);
|
||||
@ -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 /"
|
||||
@ -122,14 +123,12 @@ int main(int argc, char **argv) {
|
||||
while ((read = getline(&line, &len, stdin)) != -1 && !all_space(line)) {
|
||||
sdp = (char *)realloc(sdp, (strlen(sdp) + 1) + strlen(line) + 1);
|
||||
strcat(sdp, line);
|
||||
|
||||
}
|
||||
printf("%s\n", sdp);
|
||||
rtcSetRemoteDescription(peer->pc, sdp, "offer");
|
||||
free(sdp);
|
||||
free(line);
|
||||
break;
|
||||
|
||||
}
|
||||
case 2: {
|
||||
// Parse Candidate
|
||||
@ -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) {
|
||||
|
@ -41,14 +41,14 @@ 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);
|
||||
@ -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,7 +120,6 @@ int main(int argc, char **argv){
|
||||
// Parse Description
|
||||
printf("[Description]: ");
|
||||
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
size_t read = 0;
|
||||
@ -127,14 +127,12 @@ int main(int argc, char **argv){
|
||||
while ((read = getline(&line, &len, stdin)) != -1 && !all_space(line)) {
|
||||
sdp = (char *)realloc(sdp, (strlen(sdp) + 1) + strlen(line) + 1);
|
||||
strcat(sdp, line);
|
||||
|
||||
}
|
||||
printf("%s\n", sdp);
|
||||
rtcSetRemoteDescription(peer->pc, sdp, "answer");
|
||||
free(sdp);
|
||||
free(line);
|
||||
break;
|
||||
|
||||
}
|
||||
case 2: {
|
||||
// Parse Candidate
|
||||
@ -150,7 +148,6 @@ int main(int argc, char **argv){
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
@ -199,30 +196,27 @@ 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];
|
||||
@ -230,13 +224,12 @@ static void openCallback(int id, void *ptr) {
|
||||
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 {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user