CjConnectivity
|
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
Typedefs | |
typedef void(* | cj_co_connection_event_handler) (CjCoConnectionEvent connectionEvent, const char *otherDeviceId, CjCoConnectionType connectionType, CjCoDataType dataType, const uint8_t *buf, size_t bufLen, void *data) |
Callback gets called when any type of event is received, including receiving messages or data. More... | |
Functions | |
CjCoError | cj_co_init (const char *token, const char *myDeviceId, size_t videoReceivingBufferSize, size_t videoResendBufferSize, size_t nbrReceivingAudioFramesToBuffer, size_t audioResendBufferSize, cj_co_connection_event_handler connectionEventHandler, void *data) |
Initializes library, sets local device unique ID, and defines how big buffers for resending lost video and audio packets should be. More... | |
void | cj_co_deinit (void) |
Disconnects from other device if needed and deinitializes library. | |
void | cj_co_process_main_loop (void) |
This function needs to be called regularly for the library to function. More... | |
void | cj_co_network_changed_hint (void) |
Deals with network changes. More... | |
CjCoError | cj_co_send_msg (const char *msg, size_t msgLen, const char *otherDeviceId) |
Send message to other device via signaling. More... | |
CjCoError | cj_co_send_push_notification (const char *msg, const char *action) |
Send push notification to other device. More... | |
CjCoError | cj_co_connect (const char *otherDeviceId) |
Establish a data connection to another device. More... | |
bool | cj_co_is_connected (void) |
Check if we have a data connection with other device. More... | |
bool | cj_co_is_connected_via_connection_type (CjCoConnectionType connectionType) |
Check if we have a data connection with other device via a specific data connection type. More... | |
void | cj_co_disconnect (void) |
Disconnects from other device. | |
CjCoError | cj_co_send_video_h264_frame (const uint8_t *h264Frame, size_t h264FrameSize) |
Send H.264 video frame (NALU). More... | |
CjCoError | cj_co_send_video_h264_data_chunk (const uint8_t *h264Data, size_t h264DataSize) |
Send H.264 video data chunks. More... | |
CjCoError | cj_co_send_audio_frames (const uint8_t *audioFrames, size_t audioFramesSize) |
Send audio frames. More... | |
CjCoError | cj_co_send_other_data (const uint8_t *buf, size_t bufSize) |
Send data that is neither H.264 video nor audio. More... | |
typedef void(* cj_co_connection_event_handler) (CjCoConnectionEvent connectionEvent, const char *otherDeviceId, CjCoConnectionType connectionType, CjCoDataType dataType, const uint8_t *buf, size_t bufLen, void *data) |
Callback gets called when any type of event is received, including receiving messages or data.
connectionEvent | Type of event received. |
otherDeviceId | The unique ID of the other device for which the event was received. |
connectionType | The type of connection the event was received through. |
dataType | The type of data that was received. |
buf | The buffer that was received. Will be NULL if not applicable. |
bufLen | Length of the buffer. Will be 0 if not applicable. |
data | A pointer to the data given when specifying connection_handler |
enum CjCoConnectionEvent |
CjCoConnectionEvent gives information about events occurring with a specific connection, as well as receives data and messages.
Enumerator | |
---|---|
CJ_CO_CONNECTION_EVENT_DATA_RECEIVED | Data was received (could be any type of data such as audio, video, or other). |
CJ_CO_CONNECTION_EVENT_MSG_RECEIVED | Message received via signaling. |
CJ_CO_CONNECTION_EVENT_INCREASE_VIDEO_BITRATE | Network conditions are good enough for a higher bitrate than the one currently used. Increase the video resolution/bitrate when receiving this event. |
CJ_CO_CONNECTION_EVENT_REDUCE_VIDEO_BITRATE | Network conditions are not good enough for current bitrate. Reduce the video resolution/bitrate when receiving this event. |
CJ_CO_CONNECTION_EVENT_MESSAGING_READY | Device is ready to receive messages to its ID. |
CJ_CO_CONNECTION_EVENT_DISCONNECT_NETWORK_CHANGE | Got disconnected because of a network change (such as network lost for example). |
CJ_CO_CONNECTION_EVENT_DISCONNECT_PEER_STOPPED_RESPONDING | Peer stopped responding, indicating that peer either crashed or lost its network connection. |
CJ_CO_CONNECTION_EVENT_DISCONNECT_SIGNAL_RECEIVED_FROM_PEER | Peer sent disconnection request. |
CJ_CO_CONNECTION_EVENT_CONNECTING | Received a connection request and started initiating connection. |
CJ_CO_CONNECTION_EVENT_CONNECT_SUCCESS_OTHER_CONNECTION_TYPE | Connection was successful on one of the other two of three connection types (CjCoConnectionType). Gets received on second and third successful connection type. |
CJ_CO_CONNECTION_EVENT_CONNECT_SUCCESS | Connection was successful. Gets received when first of 3 possible connection types gets established. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_TOKEN_ERROR | Something is wrong with the token provided. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_TOKEN_EXPIRED | The token provided is expired. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_TIMEOUT | It took too long to attempt the connection. One of the 2 devices is not connected to the network or has very poor connectivity. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_MAX_CONNECTIONS_EXCEEDED | Already attempted the maximum number of connections allowed. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_VERSION_TOO_OLD | This device's version is too old and not compatible with other device. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_OTHER_DEVICE_VERSION_TOO_OLD | Other device's version is too old and not compatible with this device. |
CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_SESSION_MAX_TIME_REACHED | The token used has a session maximum time limit and that limit has been reached. Contact suppo to get a token with no limit. rt@s eajei .com |
enum CjCoConnectionType |
CjOpConnectionType indicates what kind of connection we are dealing with (direct local connection, peer-to-peer via public internet, or via server relay).
enum CjCoDataType |
enum CjCoError |
Most methods will return a CjOpError code. The code indicates success or what type of failure happened.
Enumerator | |
---|---|
CJ_CO_SUCCESS | Success return value. No error occurred. |
CJ_CO_FAILURE | A generic error. Not enough information for a specific error code. |
CJ_CO_BAD_PARAMETER | An input parameter is bad. |
CJ_CO_INTERNAL_ERROR | An internal error has occurred. |
CJ_CO_UNINITIALIZED | Trying to call functions that need initialization first. |
CJ_CO_ALREADY_INITIALIZED | Trying to initialize but we are already initialized. |
CJ_CO_TOKEN_ERROR | There was an error with the token. |
CJ_CO_TOKEN_EXPIRED | Token status is expired. |
CJ_CO_OFFLINE | The network connection is offline. |
CJ_CO_DISCONNECTED | The data connection is disconnected. |
CJ_CO_MAX_CONNECTIONS_EXCEEDED | Already attempted the maximum number of connections allowed. |
CJ_CO_TOKEN_MIN_RECONNECT_INTERVAL | Attempted to reconnect more quickly than minimum interval tied to this token. Contact suppo to get your own token to remove this limitation. rt@s eajei .com |
CjCoError cj_co_connect | ( | const char * | otherDeviceId | ) |
Establish a data connection to another device.
Data connection will be used to stream video, audio or other type of data.
otherDeviceId | The unique ID of the destination device. |
CjCoError cj_co_init | ( | const char * | token, |
const char * | myDeviceId, | ||
size_t | videoReceivingBufferSize, | ||
size_t | videoResendBufferSize, | ||
size_t | nbrReceivingAudioFramesToBuffer, | ||
size_t | audioResendBufferSize, | ||
cj_co_connection_event_handler | connectionEventHandler, | ||
void * | data | ||
) |
Initializes library, sets local device unique ID, and defines how big buffers for resending lost video and audio packets should be.
token | A unique token (please contact suppo to obtain yours). rt@s eajei .com |
myDeviceId | Unique device ID for this device. Maximum length is 32. |
videoReceivingBufferSize | Size in bytes of buffer for receiving incoming video packets for video frames to be rebuilt and re-ordered. It is recommended to have a big enough buffer to hold 1 second of video. For example for a 2 Mbps 1080p video stream, this would mean 250000 bytes. If device does not receive and display video, set to 0. |
videoResendBufferSize | Size of buffer for keeping a copy of last video frames sent in case some sent video packets get lost and need to be re-sent. It is recommended to have a big enough buffer to hold 1 second of video. For example for a 2 Mbps 1080p video stream, this would mean 250000 bytes. If device does not capture and send video, set to 0. |
nbrReceivingAudioFramesToBuffer | Number of receiving audio frames to buffer. Smaller numbers reduces lag, but increases risk of having to drop frames due to jitter. Larger numbers enable better jitter management, but introduce extra lag. Recommended values are 8 for 20 ms audio frames, 5 for 40 ms frames. If device does not receive and play audio, set to 0. |
audioResendBufferSize | Size of buffer for keeping a copy of last audio frames sent in case some sent audio packets get lost and need to be re-sent. It is recommended to have a big enough buffer to hold 1 second of audio. For example for a 50 kbps audio stream, this would mean 6250 bytes. If device does not capture and send audio, set to 0. |
connectionEventHandler | Callback to receive any events and data. |
data | Pointer which will be passed to callback. |
bool cj_co_is_connected | ( | void | ) |
Check if we have a data connection with other device.
bool cj_co_is_connected_via_connection_type | ( | CjCoConnectionType | connectionType | ) |
Check if we have a data connection with other device via a specific data connection type.
connectionType | The type of connection we want to check. |
void cj_co_network_changed_hint | ( | void | ) |
Deals with network changes.
Call this function anytime there is a network change, such as any connection or disconnection. If that info is not available, it can also be called regularly (such as every few seconds).
void cj_co_process_main_loop | ( | void | ) |
This function needs to be called regularly for the library to function.
Suggested interval is every 4 milliseconds.
CjCoError cj_co_send_audio_frames | ( | const uint8_t * | audioFrames, |
size_t | audioFramesSize | ||
) |
Send audio frames.
After a number of audio frames are captured from the microphone (and typically encoded with an audio codec), use this function to send them.
audioFrames | The audio frames. |
audioFramesSize | Size of the audio frames in bytes. Maximum is 916. If longer, separate the audioFrames into smaller pieces and send those. |
CjCoError cj_co_send_msg | ( | const char * | msg, |
size_t | msgLen, | ||
const char * | otherDeviceId | ||
) |
Send message to other device via signaling.
There is no need to establish a connection first. Message is guaranteed to be received if both devices are connected to the internet and both devices have been initialized and received the CJ_CO_CONNECTION_EVENT_MESSAGING_READY connection event. Use for small messages only (up to 5 KB), not for streaming audio or video.
msg | The message to send. |
msgLen | The length of the message. |
otherDeviceId | The unique ID of the destination device. |
CjCoError cj_co_send_other_data | ( | const uint8_t * | buf, |
size_t | bufSize | ||
) |
Send data that is neither H.264 video nor audio.
buf | The data buffer. |
bufSize | Size of the data buffer in bytes. |
CjCoError cj_co_send_push_notification | ( | const char * | msg, |
const char * | action | ||
) |
Send push notification to other device.
The push notification will be sent to the mobile phone that previously called registerPushNotificationsFromDevice with this device's ID. The registerPushNotificationsFromDevice function is only available in Seajei's mobile phone SDKs.
msg | Text that gets displayed in push notification. |
action | The action string gets embedded into push notification and can be retrieved on app side when user taps notification. |
CjCoError cj_co_send_video_h264_data_chunk | ( | const uint8_t * | h264Data, |
size_t | h264DataSize | ||
) |
Send H.264 video data chunks.
Some embedded systems don't capture complete frames, but instead capture random lengths of partial frame data (ordered). This function will figure out the beginnings and ends of frames and send them out.
h264Data | The partial frame data. |
h264DataSize | Size of the partial frame data in bytes. |
CjCoError cj_co_send_video_h264_frame | ( | const uint8_t * | h264Frame, |
size_t | h264FrameSize | ||
) |
Send H.264 video frame (NALU).
Send iFrame, pFrame, SPS, or PPS. SPS/PPS, or SPS/PPS/iFrame may be combined into a single frame.
h264Frame | The frame. |
h264FrameSize | Size of the frame in bytes. |