#include <iniparser.h>
#include <mm_display_interface.h>
#include <tbm_bufmgr.h>
+#include <libwebsockets.h>
#ifdef __cplusplus
extern "C" {
gulong signal_id;
} webrtc_signal_s;
+typedef struct _webrtc_websocket_s {
+ GMutex mutex;
+ struct lws_context *context;
+} webrtc_websocket_s;
+
int _load_ini(webrtc_s *webrtc);
void _unload_ini(webrtc_s *webrtc);
ini_item_media_source_s* _ini_get_source_by_type(webrtc_ini_s *ini, webrtc_media_source_type_e type);
int _data_channel_send_string(webrtc_data_channel_s *channel, const char *string);
int _data_channel_send_bytes(webrtc_data_channel_s *channel, const char *data, unsigned int size);
+typedef int (*_websocket_cb)(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
+webrtc_websocket_s *_alloc_websocket(const int port, const char *ssl_cert_path, const char *ssl_private_key_path, const char *ssl_ca_path, _websocket_cb callback, void *user_data);
+void _release_websocket(webrtc_websocket_s *ws);
+int _start_websocket(webrtc_websocket_s *ws, int timeout_ms);
+int _stop_websocket(webrtc_websocket_s *ws);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "webrtc.h"
+#include "webrtc_private.h"
+
+webrtc_websocket_s *_alloc_websocket(const int port, const char *ssl_cert_path, const char *ssl_private_key_path, const char *ssl_ca_path, _websocket_cb callback, void *user_data)
+{
+ struct lws_protocols protocols[] = {
+ {
+ "signaling-protocol",
+ callback,
+ 0,
+ 0,
+ 0,
+ },
+ {
+ NULL, NULL, 0, 0 /* end of list */
+ }
+ };
+
+ struct lws_context_creation_info info = {
+ .port = port,
+ .iface = NULL,
+ .protocols = protocols,
+ .extensions = NULL,
+ .ssl_cert_filepath = ssl_cert_path,
+ .ssl_private_key_filepath = ssl_private_key_path,
+ .ssl_ca_filepath = ssl_ca_path,
+ .gid = -1,
+ .uid = -1,
+ .user = user_data
+ };
+
+ webrtc_websocket_s *ws = g_new0(webrtc_websocket_s, 1);
+
+ ws->context = lws_create_context(&info);
+ if (!ws->context) {
+ LOG_ERROR("failed to lws_create_context()");
+ g_free(ws);
+ return NULL;
+ }
+
+ g_mutex_init(&ws->mutex);
+
+ LOG_DEBUG("ws[%p, context:%p]", ws, ws->context);
+
+ return ws;
+}
+
+void _release_websocket(webrtc_websocket_s *ws)
+{
+ RET_IF(ws == NULL, "ws is NULL");
+
+ g_mutex_lock(&ws->mutex);
+
+ LOG_DEBUG("ws[%p, context:%p]", ws, ws->context);
+
+ lws_context_destroy(ws->context);
+
+ g_mutex_unlock(&ws->mutex);
+ g_mutex_clear(&ws->mutex);
+
+ g_free(ws);
+
+ return;
+}
+
+int _start_websocket(webrtc_websocket_s *ws, int timeout_ms)
+{
+ int ret;
+
+ RET_VAL_IF(ws == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ws is NULL");
+ RET_VAL_IF(timeout_ms < 0, WEBRTC_ERROR_INVALID_PARAMETER, "invalid timeout_ms(%d)", timeout_ms);
+
+ g_mutex_lock(&ws->mutex);
+
+ ret = lws_service(ws->context, timeout_ms);
+ if (ret != 0) {
+ LOG_ERROR("failed to lws_service(), ret[%d]", ret);
+ g_mutex_unlock(&ws->mutex);
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ }
+
+ LOG_DEBUG("ws[%p, context:%p], timeout_ms[%d]", ws, ws->context, timeout_ms);
+
+ g_mutex_unlock(&ws->mutex);
+
+ return WEBRTC_ERROR_NONE;
+}
+
+int _stop_websocket(webrtc_websocket_s *ws)
+{
+ RET_VAL_IF(ws == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ws is NULL");
+
+ g_mutex_lock(&ws->mutex);
+
+ lws_cancel_service(ws->context);
+
+ LOG_DEBUG("ws[%p, context:%p]", ws, ws->context);
+
+ g_mutex_unlock(&ws->mutex);
+
+ return WEBRTC_ERROR_NONE;
+}