Skip to content

Support dynamically allocated signaling payload #2140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions samples/Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,9 @@ STATUS submitPendingIceCandidate(PPendingMessageQueue pPendingMessageQueue, PSam
if (pReceivedSignalingMessage->signalingMessage.messageType == SIGNALING_MESSAGE_TYPE_ICE_CANDIDATE) {
CHK_STATUS(handleRemoteCandidate(pSampleStreamingSession, &pReceivedSignalingMessage->signalingMessage));
}
#ifdef DYNAMIC_SIGNALING_PAYLOAD
SAFE_MEMFREE(pReceivedSignalingMessage->signalingMessage.payload);
#endif
SAFE_MEMFREE(pReceivedSignalingMessage);
}
} while (!noPendingSignalingMessageForClient);
Expand All @@ -1418,6 +1421,11 @@ STATUS submitPendingIceCandidate(PPendingMessageQueue pPendingMessageQueue, PSam

CleanUp:

#ifdef DYNAMIC_SIGNALING_PAYLOAD
if (pReceivedSignalingMessage) {
SAFE_MEMFREE(pReceivedSignalingMessage->signalingMessage.payload);
}
#endif
SAFE_MEMFREE(pReceivedSignalingMessage);
CHK_LOG_ERR(retStatus);
return retStatus;
Expand Down Expand Up @@ -1539,6 +1547,12 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe

*pReceivedSignalingMessageCopy = *pReceivedSignalingMessage;

#ifdef DYNAMIC_SIGNALING_PAYLOAD
pReceivedSignalingMessageCopy->signalingMessage.payload = (PCHAR) MEMALLOC(pReceivedSignalingMessage->signalingMessage.payloadLen);
CHK(pReceivedSignalingMessageCopy->signalingMessage.payload != NULL, STATUS_NOT_ENOUGH_MEMORY);
MEMCPY(pReceivedSignalingMessageCopy->signalingMessage.payload, pReceivedSignalingMessage->signalingMessage.payload, pReceivedSignalingMessage->signalingMessage.payloadLen);
#endif

CHK_STATUS(stackQueueEnqueue(pPendingMessageQueue->messageQueue, (UINT64) pReceivedSignalingMessageCopy));

// NULL the pointers to not free any longer
Expand Down Expand Up @@ -1571,6 +1585,11 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe

CleanUp:

#ifdef DYNAMIC_SIGNALING_PAYLOAD
if (pReceivedSignalingMessageCopy) {
SAFE_MEMFREE(pReceivedSignalingMessageCopy->signalingMessage.payload);
}
#endif
SAFE_MEMFREE(pReceivedSignalingMessageCopy);
if (pPendingMessageQueue != NULL) {
freeMessageQueue(pPendingMessageQueue);
Expand Down
13 changes: 13 additions & 0 deletions src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,15 @@ typedef struct {
//!<
} RtcIceCandidateInit, *PRtcIceCandidateInit;

/**
* @brief Define this macro to use dynamically allocated payload in SignalingMessage
* This can be useful for platforms with limited memory as it avoids allocating
* MAX_SIGNALING_MESSAGE_LEN for each message when only a small payload is needed
*/
#ifndef DYNAMIC_SIGNALING_PAYLOAD
#define DYNAMIC_SIGNALING_PAYLOAD 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a CMake option? (for out of the box builds)

For backwards compatibility, we should have 0/OFF as the default since it requires an application change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

option(ENABLE_STATS_CALCULATION_CONTROL "Enable support for runtime control of ice agent stat calculations." OFF)

if (ENABLE_STATS_CALCULATION_CONTROL)
add_definitions(-DENABLE_STATS_CALCULATION_CONTROL)
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL: #2146

#endif

/**
* @brief Structure defining the basic signaling message
*/
Expand All @@ -1276,7 +1285,11 @@ typedef struct {

UINT32 payloadLen; //!< Optional payload length. If 0, the length will be calculated

#ifdef DYNAMIC_SIGNALING_PAYLOAD
PCHAR payload; //!< Actual signaling message payload - dynamically allocated
#else
CHAR payload[MAX_SIGNALING_MESSAGE_LEN + 1]; //!< Actual signaling message payload
#endif
} SignalingMessage, *PSignalingMessage;

/**
Expand Down
13 changes: 12 additions & 1 deletion src/source/Signaling/LwsApiCalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,10 @@ STATUS receiveLwsMessage(PSignalingClient pSignalingClient, PCHAR pMessage, UINT

CHK(NULL != (pSignalingMessageWrapper = (PSignalingMessageWrapper) MEMCALLOC(1, SIZEOF(SignalingMessageWrapper))), STATUS_NOT_ENOUGH_MEMORY);

#ifdef DYNAMIC_SIGNALING_PAYLOAD
CHK(NULL != (pSignalingMessageWrapper->receivedSignalingMessage.signalingMessage.payload = (PBYTE) MEMCALLOC(1, MAX_SIGNALING_MESSAGE_LEN + 1)), STATUS_NOT_ENOUGH_MEMORY);
#endif

pSignalingMessageWrapper->receivedSignalingMessage.signalingMessage.version = SIGNALING_MESSAGE_CURRENT_VERSION;

// Loop through the tokens and extract the stream description
Expand Down Expand Up @@ -2235,7 +2239,11 @@ STATUS receiveLwsMessage(PSignalingClient pSignalingClient, PCHAR pMessage, UINT
if (IS_VALID_TID_VALUE(receivedTid)) {
THREAD_CANCEL(receivedTid);
}

#ifdef DYNAMIC_SIGNALING_PAYLOAD
if (pSignalingMessageWrapper) {
SAFE_MEMFREE(pSignalingMessageWrapper->receivedSignalingMessage.signalingMessage.payload);
}
#endif
SAFE_MEMFREE(pSignalingMessageWrapper);
}

Expand Down Expand Up @@ -2402,6 +2410,9 @@ PVOID receiveLwsMessageWrapper(PVOID args)
CleanUp:
CHK_LOG_ERR(retStatus);

#ifdef DYNAMIC_SIGNALING_PAYLOAD
SAFE_MEMFREE(pSignalingMessageWrapper->receivedSignalingMessage.signalingMessage.payload);
#endif
SAFE_MEMFREE(pSignalingMessageWrapper);

return (PVOID) (ULONG_PTR) retStatus;
Expand Down
Loading