diff options
author | Chris Hiszpanski <chris.hiszpanski@verkada.com> | 2022-05-21 15:25:35 -0700 |
---|---|---|
committer | Chris Hiszpanski <chris.hiszpanski@verkada.com> | 2022-05-21 15:45:26 -0700 |
commit | 97261b79b20e4e53ef3a5b7a37d1ffb0b5665bcb (patch) | |
tree | 809099efc2ac9ccfb440776eda5c63b6a1970931 /tinyrtc.c | |
parent | 12df87e791ee6e468df31a6c468595b8c124a2b4 (diff) |
* Added trtc_ prefixes
* Split into tinyrtc.c/h
* Sending answer
* Answer validates
Diffstat (limited to 'tinyrtc.c')
-rw-r--r-- | tinyrtc.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/tinyrtc.c b/tinyrtc.c new file mode 100644 index 0000000..2092224 --- /dev/null +++ b/tinyrtc.c @@ -0,0 +1,126 @@ +/** + * WebRTC implementation for tiny devices + * + * Copyright (c) 2022 Chris Hiszpanski. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ + +#include <stdbool.h> +#include <stdio.h> // snprintf +#include <string.h> // memset + +#include "tinyrtc.h" + + +/// OPAQUE TYPE DEFINITIONS //////////////////////////////////////////////// + +struct trtc_peerconn_t { + bool active; + + char offer[TRTC_MAX_SDP_SIZE]; + char answer[TRTC_MAX_SDP_SIZE]; + + char l_ice_pwd[TRTC_MAX_ICE_PWD_SIZE]; + char l_ice_ufrag[TRTC_MAX_ICE_UFRAG_SIZE]; +}; + + +/// STATIC ALLOCATIONS ///////////////////////////////////////////////////// + +static struct trtc_peerconn_t peer_connection_pool[TRTC_MAX_PEER_CONNECTIONS]; + + +/// RTC PEER CONNECTION API //////////////////////////////////////////////// + +void rtc_init() { + memset(peer_connection_pool, 0, sizeof(peer_connection_pool)); +} + +struct trtc_peerconn_t* trtc_peer_connection(struct trtc_config_t cfg) { + for (int i = 0; i < TRTC_MAX_PEER_CONNECTIONS; i++) { + if (!peer_connection_pool[i].active) { + memset(&peer_connection_pool[i], 0, sizeof(struct trtc_peerconn_t)); + peer_connection_pool[i].active = true; + return &peer_connection_pool[i]; + } + } + + return NULL; +} + +int trtc_add_ice_candidate(struct trtc_peerconn_t *pc, const struct trtc_ice_candidate_t c) { + return -1; +}; + +const char * trtc_create_answer(struct trtc_peerconn_t *pc) { + unsigned char fp[32]; + + snprintf(pc->l_ice_ufrag, TRTC_MAX_ICE_UFRAG_SIZE, "xxxx"); // XXX + snprintf(pc->l_ice_pwd, TRTC_MAX_ICE_PWD_SIZE, "xxxxxxxxxxxxxxxxxxxxxx"); // XXX + + snprintf(pc->answer, TRTC_MAX_SDP_SIZE, + "v=0\\r\\n" + "o=- 2210401696197537454 2 IN IP4 127.0.0.1\\r\\n" // XXX + "s=-\\r\\n" + "t=0 0\\r\\n" + "a=group:BUNDLE 0\\r\\n" + "a=msid-semantic: WMS\\r\\n" + "m=video 9 UDP/TLS/RTP/SAVPF 98\\r\\n" // XXX + "c=IN IP4 0.0.0.0\\r\\n" + "a=rtcp:9 IN IP4 0.0.0.0\\r\\n" + "a=ice-ufrag:%s\\r\\n" + "a=ice-pwd:%s\\r\\n" + "a=ice-options:trickle\\r\\n" + "a=fingerprint:sha-256 " + "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:" + "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:" + "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:" + "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX\\r\\n" + "a=setup:passive\\r\\n" + "a=mid:0\\r\\n" + "a=sendonly\\r\\n" + "a=rtcp-mux\\r\\n" + "a=rtcp-rsize\\r\\n" + "a=rtpmap:98 H264/90000\\r\\n" + "a=rtcp-fb:98 nack\\r\\n" + "a=rtcp-fb:98 nack pli\\r\\n" + "a=fmtp:98 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\\r\\n", + pc->l_ice_ufrag, + pc->l_ice_pwd, + fp[ 0], fp[ 1], fp[ 2], fp[ 3], fp[ 4], fp[ 5], fp[ 6], fp[ 7], + fp[ 8], fp[ 9], fp[10], fp[11], fp[12], fp[13], fp[14], fp[15], + fp[16], fp[17], fp[18], fp[19], fp[20], fp[21], fp[22], fp[23], + fp[24], fp[25], fp[26], fp[27], fp[28], fp[29], fp[30], fp[31] + ); + + return pc->answer; +}; + +int trtc_set_local_description(struct trtc_peerconn_t *pc, const char *sdp) { + return -1; +}; + +int trtc_set_remote_description(struct trtc_peerconn_t *pc, const char *sdp) { + return -1; +}; |