CjConnectivity
Typedefs | Enumerations | Functions
cj_connectivity.h File Reference
#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...
 

Enumerations

enum  CjCoConnectionEvent {
  CJ_CO_CONNECTION_EVENT_DATA_RECEIVED = 101,
  CJ_CO_CONNECTION_EVENT_MSG_RECEIVED = 100,
  CJ_CO_CONNECTION_EVENT_INCREASE_VIDEO_BITRATE = 8,
  CJ_CO_CONNECTION_EVENT_REDUCE_VIDEO_BITRATE = 7,
  CJ_CO_CONNECTION_EVENT_MESSAGING_READY = 6,
  CJ_CO_CONNECTION_EVENT_DISCONNECT_NETWORK_CHANGE = 5,
  CJ_CO_CONNECTION_EVENT_DISCONNECT_PEER_STOPPED_RESPONDING = 4,
  CJ_CO_CONNECTION_EVENT_DISCONNECT_SIGNAL_RECEIVED_FROM_PEER = 3,
  CJ_CO_CONNECTION_EVENT_CONNECTING = 2,
  CJ_CO_CONNECTION_EVENT_CONNECT_SUCCESS_OTHER_CONNECTION_TYPE = 1,
  CJ_CO_CONNECTION_EVENT_CONNECT_SUCCESS = 0,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_TOKEN_ERROR = -1,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_TOKEN_EXPIRED = -2,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_TIMEOUT = -3,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_MAX_CONNECTIONS_EXCEEDED = -4,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_VERSION_TOO_OLD = -5,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_OTHER_DEVICE_VERSION_TOO_OLD = -6,
  CJ_CO_CONNECTION_EVENT_CONNECT_FAIL_SESSION_MAX_TIME_REACHED = -7
}
 CjCoConnectionEvent gives information about events occurring with a specific connection, as well as receives data and messages. More...
 
enum  CjCoConnectionType {
  CJ_CO_CONNECTION_TYPE_NONE,
  CJ_CO_CONNECTION_TYPE_LOCAL,
  CJ_CO_CONNECTION_TYPE_P2P,
  CJ_CO_CONNECTION_TYPE_SERVER,
  CJ_CO_CONNECTION_TYPE_ALL
}
 CjOpConnectionType indicates what kind of connection we are dealing with (direct local connection, peer-to-peer via public internet, or via server relay). More...
 
enum  CjCoDataType {
  CJ_CO_DATA_TYPE_NONE,
  CJ_CO_DATA_TYPE_VIDEO,
  CJ_CO_DATA_TYPE_AUDIO,
  CJ_CO_DATA_TYPE_OTHER
}
 CjCoDataType indicates whether the type of data being sent or received is video, audio, or other. More...
 
enum  CjCoError {
  CJ_CO_SUCCESS = 0,
  CJ_CO_FAILURE = -1,
  CJ_CO_BAD_PARAMETER = -2,
  CJ_CO_INTERNAL_ERROR = -3,
  CJ_CO_UNINITIALIZED = -4,
  CJ_CO_ALREADY_INITIALIZED = -5,
  CJ_CO_TOKEN_ERROR = -6,
  CJ_CO_TOKEN_EXPIRED = -7,
  CJ_CO_OFFLINE = -8,
  CJ_CO_DISCONNECTED = -9,
  CJ_CO_MAX_CONNECTIONS_EXCEEDED = -10,
  CJ_CO_TOKEN_MIN_RECONNECT_INTERVAL = -11
}
 Most methods will return a CjOpError code. The code indicates success or what type of failure happened. 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 Documentation

◆ cj_co_connection_event_handler

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.

Parameters
connectionEventType of event received.
otherDeviceIdThe unique ID of the other device for which the event was received.
connectionTypeThe type of connection the event was received through.
dataTypeThe type of data that was received.
bufThe buffer that was received. Will be NULL if not applicable.
bufLenLength of the buffer. Will be 0 if not applicable.
dataA pointer to the data given when specifying connection_handler
Note
This callback will be called each time with successful connectionEvent when one of the connection types gets established. For example, if the first data connection to get established is via server, then this callback will be called with CJ_CO_CONNECTION_TYPE_SERVER as connectionType. If a little bit later a peer-to-peer data connection is successfully established, then this callback will be called again with the CJ_CO_CONNECTION_TYPE_P2P connectionType.

Enumeration Type Documentation

◆ 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.nosp@m.rt@s.nosp@m.eajei.nosp@m..com to get a token with no limit.

◆ CjCoConnectionType

CjOpConnectionType indicates what kind of connection we are dealing with (direct local connection, peer-to-peer via public internet, or via server relay).

Enumerator
CJ_CO_CONNECTION_TYPE_NONE 

No associated connection type.

CJ_CO_CONNECTION_TYPE_LOCAL 

Connection over same local network.

CJ_CO_CONNECTION_TYPE_P2P 

Peer-to-peer connection over the public internet.

CJ_CO_CONNECTION_TYPE_SERVER 

Connection via relay server.

CJ_CO_CONNECTION_TYPE_ALL 

Encompasses all connection types (such as for example when receiving and overall timeout event).

◆ CjCoDataType

CjCoDataType indicates whether the type of data being sent or received is video, audio, or other.

Enumerator
CJ_CO_DATA_TYPE_NONE 

No associated data type.

CJ_CO_DATA_TYPE_VIDEO 

Data is video.

CJ_CO_DATA_TYPE_AUDIO 

Data is audio.

CJ_CO_DATA_TYPE_OTHER 

Data is neither audio nor video.

◆ CjCoError

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.nosp@m.rt@s.nosp@m.eajei.nosp@m..com to get your own token to remove this limitation.

Function Documentation

◆ cj_co_connect()

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.

Parameters
otherDeviceIdThe unique ID of the destination device.
Returns
Error code.

◆ cj_co_init()

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.

Parameters
tokenA unique token (please contact suppo.nosp@m.rt@s.nosp@m.eajei.nosp@m..com to obtain yours).
myDeviceIdUnique device ID for this device. Maximum length is 32.
videoReceivingBufferSizeSize 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.
videoResendBufferSizeSize 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.
nbrReceivingAudioFramesToBufferNumber 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.
audioResendBufferSizeSize 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.
connectionEventHandlerCallback to receive any events and data.
dataPointer which will be passed to callback.
Returns
Error code.

◆ cj_co_is_connected()

bool cj_co_is_connected ( void  )

Check if we have a data connection with other device.

Returns
true if connected, false otherwise.

◆ cj_co_is_connected_via_connection_type()

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.

Parameters
connectionTypeThe type of connection we want to check.
Returns
true if connected, false otherwise.

◆ cj_co_network_changed_hint()

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).

◆ cj_co_process_main_loop()

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.

◆ cj_co_send_audio_frames()

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.

Parameters
audioFramesThe audio frames.
audioFramesSizeSize of the audio frames in bytes. Maximum is 916. If longer, separate the audioFrames into smaller pieces and send those.
Returns
Error code.

◆ cj_co_send_msg()

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.

Parameters
msgThe message to send.
msgLenThe length of the message.
otherDeviceIdThe unique ID of the destination device.
Returns
Error code.

◆ cj_co_send_other_data()

CjCoError cj_co_send_other_data ( const uint8_t *  buf,
size_t  bufSize 
)

Send data that is neither H.264 video nor audio.

Parameters
bufThe data buffer.
bufSizeSize of the data buffer in bytes.
Returns
Error code.
Note
This data is getting sent over UDP as is, with no resending.

◆ cj_co_send_push_notification()

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.

Parameters
msgText that gets displayed in push notification.
actionThe action string gets embedded into push notification and can be retrieved on app side when user taps notification.
Returns
Error code.
Note
Enabling push notifications to work for your own app requires Seajei to enable it. Please contact Seajei at suppo.nosp@m.rt@s.nosp@m.eajei.nosp@m..com to enable your push notifications.

◆ cj_co_send_video_h264_data_chunk()

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.

Parameters
h264DataThe partial frame data.
h264DataSizeSize of the partial frame data in bytes.
Returns
Error code.

◆ cj_co_send_video_h264_frame()

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.

Parameters
h264FrameThe frame.
h264FrameSizeSize of the frame in bytes.
Returns
Error code.