#endif
#include <iniparser.h>
#include <mm_display_interface.h>
+#include <tbm_bufmgr.h>
#ifdef __cplusplus
extern "C" {
} \
} while (0)
+#define RET_WITH_UNLOCK_IF(expr, mutex, fmt, arg...) \
+do { \
+ if ((expr)) { \
+ LOG_ERROR(""fmt"", ##arg); \
+ g_mutex_unlock(mutex); \
+ return; \
+ } \
+} while (0)
+
#define RET_VAL_WITH_UNLOCK_IF(expr, val, mutex, fmt, arg...) \
do { \
if ((expr)) { \
void *user_data;
} webrtc_callbacks_s;
+typedef struct _webrtc_tbm_bo_s {
+ bool used;
+ void *bo;
+} webrtc_tbm_bo_s;
+
+typedef struct _webrtc_tbm_s {
+ tbm_bufmgr bufmgr;
+
+ GCond cond;
+ GMutex mutex;
+ GList *bo_list; /* for decoded video data by sw codec */
+} webrtc_tbm_s;
+
typedef struct _webrtc_display {
void *object;
int type;
void _deinit_display(webrtc_s *webrtc);
int _apply_display(webrtc_s *webrtc, webrtc_display_s *display);
+webrtc_tbm_s *_alloc_tbm(void);
+void _release_tbm(webrtc_tbm_s *tbm);
+void _create_tbm_bo_list(webrtc_tbm_s *tbm, int bo_size, int list_length);
+void _destroy_tbm_bo_list(webrtc_tbm_s *tbm);
+void *_get_unused_tbm_bo(webrtc_tbm_s *tbm, unsigned int timeout_sec);
+void _release_tbm_bo(webrtc_tbm_s *tbm, void *bo);
+
int _webrtcbin_create_offer(webrtc_s *webrtc, char **offer);
int _webrtcbin_create_answer(webrtc_s *webrtc, char **answer);
int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description, bool is_remote);
--- /dev/null
+/*
+ * Copyright (c) 2020 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"
+
+static void __tbm_bo_destroy_cb(webrtc_tbm_bo_s *tbm_bo)
+{
+ if (tbm_bo == NULL)
+ return;
+
+ if (tbm_bo->bo && tbm_bo->used) {
+ tbm_bo->used = false;
+ LOG_DEBUG("unref bo[%p]", tbm_bo->bo);
+ tbm_bo_unref(tbm_bo->bo);
+ tbm_bo->bo = NULL;
+ }
+
+ g_free(tbm_bo);
+}
+
+void _destroy_tbm_bo_list(webrtc_tbm_s *tbm)
+{
+ RET_IF(tbm == NULL, "tbm is NULL");
+
+ g_mutex_lock(&tbm->mutex);
+
+ if (tbm->bo_list) {
+ LOG_DEBUG("destroy tbm->bo_list[%p, length:%d]", tbm->bo_list, g_list_length(tbm->bo_list));
+ g_list_free_full(tbm->bo_list, (GDestroyNotify)__tbm_bo_destroy_cb);
+ tbm->bo_list = NULL;
+ }
+
+ g_mutex_unlock(&tbm->mutex);
+}
+
+void _create_tbm_bo_list(webrtc_tbm_s *tbm, int bo_size, int list_length)
+{
+ RET_IF(tbm == NULL, "tbm is NULL");
+ RET_IF(bo_size <= 0, "invalid bo_size(%d)", bo_size);
+ RET_IF(list_length <= 0, "invalid list_length(%d)", list_length);
+
+ g_mutex_lock(&tbm->mutex);
+
+ RET_WITH_UNLOCK_IF(tbm->bo_list != NULL, &tbm->mutex, "bo_list is not NULL");
+
+ while (list_length--) {
+ webrtc_tbm_bo_s *tbm_bo = g_new0(webrtc_tbm_bo_s, 1);
+
+ tbm_bo->bo = tbm_bo_alloc(tbm->bufmgr, bo_size, TBM_BO_DEFAULT);
+ if (tbm_bo->bo == NULL) {
+ LOG_ERROR("failed to tbm_bo_alloc()");
+ g_free(tbm_bo);
+ break;
+ }
+ LOG_DEBUG("bo[%p] is created", tbm_bo->bo);
+ tbm->bo_list = g_list_append(tbm->bo_list, tbm_bo);
+ }
+ LOG_DEBUG("tbm->bo_list[%p, length:%d] is created", tbm->bo_list, g_list_length(tbm->bo_list));
+
+ g_mutex_unlock(&tbm->mutex);
+}
+
+void *_get_unused_tbm_bo(webrtc_tbm_s *tbm, unsigned int timeout_sec)
+{
+ GList *l;
+ gboolean ret = TRUE;
+ gint64 end_time = g_get_monotonic_time() + timeout_sec * G_TIME_SPAN_SECOND;
+
+ RET_VAL_IF(tbm == NULL, NULL, "tbm is NULL");
+
+ g_mutex_lock(&tbm->mutex);
+
+ while (true) {
+ for (l = g_list_first(tbm->bo_list); l; l = g_list_next(l)) {
+ webrtc_tbm_bo_s *tbm_bo = (webrtc_tbm_bo_s *)l->data;
+ if (tbm_bo && (!tbm_bo->used)) {
+ LOG_DEBUG("found unused bo[%p]", tbm_bo->bo);
+ tbm_bo->used = true;
+ g_mutex_unlock(&tbm->mutex);
+ return tbm_bo_ref(tbm_bo->bo);
+ }
+ }
+
+ ret = g_cond_wait_until(&tbm->cond, &tbm->mutex, end_time);
+ if (!ret) {
+ LOGE("failed to get unused bo within %d sec. of timeout", timeout_sec);
+ break;
+ }
+ }
+
+ g_mutex_unlock(&tbm->mutex);
+
+ return NULL;
+}
+
+void _release_tbm_bo(webrtc_tbm_s *tbm, void *bo)
+{
+ GList *l;
+
+ RET_IF(tbm == NULL, "tbm is NUL");
+ RET_IF(bo == NULL, "bo is NUL");
+
+ g_mutex_lock(&tbm->mutex);
+
+ for (l = g_list_first(tbm->bo_list); l; l = g_list_next(l)) {
+ webrtc_tbm_bo_s *tbm_bo = (webrtc_tbm_bo_s *)l->data;
+ if (tbm_bo && (tbm_bo->bo == bo)) {
+ tbm_bo->used = false;
+ LOG_DEBUG("unref bo[%p]", tbm_bo->bo);
+ tbm_bo_unref(tbm_bo->bo);
+ g_cond_signal(&tbm->cond);
+ g_mutex_unlock(&tbm->mutex);
+ return;
+ }
+ }
+
+ g_mutex_unlock(&tbm->mutex);
+}
+
+webrtc_tbm_s *_alloc_tbm(void)
+{
+ webrtc_tbm_s *tbm = g_new0(webrtc_tbm_s, 1);
+
+ tbm->bufmgr = tbm_bufmgr_init(-1);
+ if (tbm->bufmgr == NULL) {
+ LOG_ERROR("tbm->bufmgr is NULL");
+ g_free(tbm);
+ return NULL;
+ }
+
+ g_mutex_init(&tbm->mutex);
+ g_cond_init(&tbm->cond);
+
+ LOG_DEBUG("tbm[%p] bufmgr[%p]", tbm, tbm->bufmgr);
+
+ return tbm;
+}
+
+void _release_tbm(webrtc_tbm_s *tbm)
+{
+ RET_IF(tbm == NULL, "tbm is NULL");
+
+ _destroy_tbm_bo_list(tbm);
+
+ g_mutex_lock(&tbm->mutex);
+
+ if (tbm->bufmgr) {
+ LOG_DEBUG("deinit tbm->bufmgr[%p]", tbm->bufmgr);
+ tbm_bufmgr_deinit(tbm->bufmgr);
+ tbm->bufmgr = NULL;
+ }
+
+ g_mutex_unlock(&tbm->mutex);
+ g_mutex_clear(&tbm->mutex);
+ g_cond_clear(&tbm->cond);
+
+ LOG_DEBUG("free tbm[%p]", tbm);
+
+ g_free(tbm);
+}