Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: support window #933

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,23 @@ ELSE()
ENDIF()
ENDIF()

SET(BUILTIN_CURL_DEFAULT "OFF")
SET(PULSEAUDIO_DEFAULT "OFF")
SET(PORTAUDIO_PLUGIN_DEFAULT "OFF")

IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
SET(BUILTIN_CURL_DEFAULT "OFF")
SET(PULSEAUDIO_DEFAULT "OFF")
SET(ASAN_DEFAULT "OFF")

ADD_DEFINITIONS(
-DNUGU_PLUGIN_FILE_EXTENSION=".dylib"
)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "MINGW")
ADD_DEFINITIONS(
# Run-time buffer overflow detection
-D_FORTIFY_SOURCE=2

-DNUGU_PLUGIN_FILE_EXTENSION=".dll"
)
ELSE()
SET(BUILTIN_CURL_DEFAULT "ON")
SET(PULSEAUDIO_DEFAULT "ON")
Expand Down Expand Up @@ -211,6 +220,12 @@ ELSE()
SET(LDFLAG_SOCKET "")
ENDIF()

IF(CMAKE_SYSTEM_NAME MATCHES "MINGW")
SET(LDFLAG_WINSOCK "-lws2_32")
ELSE()
SET(LDFLAG_WINSOCK "")
ENDIF()

SET(BUILD_LIBRARY ON)
SET(BUILD_PLUGINS ON)
SET(BUILD_EXAMPLES ON)
Expand Down Expand Up @@ -250,10 +265,16 @@ IF(VENDOR_PKGCONFIG)
pkg_check_modules(vendor_pkgs REQUIRED ${VENDOR_PKGCONFIG})
ENDIF()

IF(CMAKE_SYSTEM_NAME MATCHES "MINGW")
SET(GIO_PKGCONFIG gio-windows-2.0)
ELSE()
SET(GIO_PKGCONFIG gio-unix-2.0)
ENDIF()

IF(BUILD_LIBRARY)
# Set NUGU SDK library default dependency
SET(DEFAULT_LIB_DEPENDENCY
glib-2.0 gio-2.0 gio-unix-2.0 gthread-2.0
glib-2.0 gio-2.0 gthread-2.0 ${GIO_PKGCONFIG}
${CURL_PKGCONFIG} ${VENDOR_PKGCONFIG} ${RAPIDJSON_PKGCONFIG})

# Sets the option so that the built library has a higher link order than
Expand Down Expand Up @@ -343,27 +364,34 @@ IF (CMAKE_COMPILER_IS_GNUCC)

# Not warnings (GCC 10.3 issue)
STRING(APPEND CMAKE_C_FLAGS " -Wno-analyzer-malloc-leak")

IF(CMAKE_SYSTEM_NAME MATCHES "MINGW")
# Not warnings (false alarm in window)
STRING(APPEND CMAKE_C_FLAGS " -Wno-analyzer-fd-leak")
ENDIF()
ENDIF()

ADD_COMPILE_OPTIONS(
# Non-executable stack
-Wa,--execstack
IF(NOT CMAKE_SYSTEM_NAME MATCHES "MINGW")
ADD_COMPILE_OPTIONS(
# Non-executable stack
-Wa,--execstack

# Eliminate unused code and data (with --gc-sections link option)
-Wl,--gc-sections)
# Eliminate unused code and data (with --gc-sections link option)
-Wl,--gc-sections)

LINK_LIBRARIES(
# Link only needed libraries
-Wl,--as-needed
LINK_LIBRARIES(
# Link only needed libraries
-Wl,--as-needed

# Enforces symbol resolution at build time
-Wl,-z,defs
# Enforces symbol resolution at build time
-Wl,-z,defs

# Non-executable stack
-Wl,-z,noexecstack
# Non-executable stack
-Wl,-z,noexecstack

# Debian packaging default link flags
-Wl,-Bsymbolic-functions -Wl,-z,relro)
# Debian packaging default link flags
-Wl,-Bsymbolic-functions -Wl,-z,relro)
ENDIF()

# RPATH is useful only for testing without installation.
# Please use the '-DPACKAGING' option for debian packaging.
Expand Down Expand Up @@ -450,7 +478,11 @@ IF(BUILD_LIBRARY)
INSTALL(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nugu/)

# Install pkgconfig
CONFIGURE_FILE(nugu.pc.in ${PROJECT_BINARY_DIR}/nugu.pc @ONLY)
IF(ENABLE_VOICE_STREAMING)
CONFIGURE_FILE(nugu-no-epd.pc.in ${PROJECT_BINARY_DIR}/nugu.pc @ONLY)
ELSE()
CONFIGURE_FILE(nugu.pc.in ${PROJECT_BINARY_DIR}/nugu.pc @ONLY)
ENDIF()
INSTALL(FILES ${PROJECT_BINARY_DIR}/nugu.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/)

# Install asset files
Expand Down
2 changes: 1 addition & 1 deletion examples/capability_injection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FILE(GLOB_RECURSE SRC *.cc)
ADD_EXECUTABLE(nugu_capability_injection ${SRC})
TARGET_LINK_LIBRARIES(nugu_capability_injection ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_capability_injection ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_capability_injection libnugu)
INSTALL(TARGETS nugu_capability_injection RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion examples/profiling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADD_EXECUTABLE(nugu_prof main_prof.cc)
TARGET_LINK_LIBRARIES(nugu_prof ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_prof ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_prof libnugu)
INSTALL(TARGETS nugu_prof RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
INSTALL(DIRECTORY testcases DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/nugu)
2 changes: 1 addition & 1 deletion examples/response_filter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_EXECUTABLE(nugu_response_filter main.cc filter.cc)
TARGET_LINK_LIBRARIES(nugu_response_filter ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_response_filter ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_response_filter libnugu)
INSTALL(TARGETS nugu_response_filter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion examples/simple_asr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_EXECUTABLE(nugu_simple_asr main_asr.cc)
TARGET_LINK_LIBRARIES(nugu_simple_asr ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_simple_asr ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_simple_asr libnugu)
INSTALL(TARGETS nugu_simple_asr RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion examples/simple_play/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_EXECUTABLE(nugu_simple_play main_play.cc)
TARGET_LINK_LIBRARIES(nugu_simple_play ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_simple_play ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_simple_play libnugu)
INSTALL(TARGETS nugu_simple_play RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion examples/simple_text/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_EXECUTABLE(nugu_simple_text main_text.cc)
TARGET_LINK_LIBRARIES(nugu_simple_text ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_simple_text ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_simple_text libnugu)
INSTALL(TARGETS nugu_simple_text RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion examples/simple_tts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_EXECUTABLE(nugu_simple_tts main_tts.cc)
TARGET_LINK_LIBRARIES(nugu_simple_tts ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(nugu_simple_tts ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(nugu_simple_tts libnugu)
INSTALL(TARGETS nugu_simple_tts RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion examples/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_APP} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
capability
clientkit)
TARGET_LINK_LIBRARIES(${TARGET_APP} ${pkgs_LDFLAGS} -lnugu)
TARGET_LINK_LIBRARIES(${TARGET_APP} ${pkgs_LDFLAGS} -lnugu -lstdc++)
ADD_DEPENDENCIES(${TARGET_APP} libnugu)

# install
Expand Down
3 changes: 3 additions & 0 deletions externals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ include(ExternalProject)
FILE(GLOB_RECURSE njson_files njson/src/*.cpp)
ADD_LIBRARY(njson STATIC ${njson_files})
TARGET_INCLUDE_DIRECTORIES(njson PRIVATE njson/include)
IF(CMAKE_SYSTEM_NAME MATCHES "MINGW")
TARGET_COMPILE_OPTIONS(njson PRIVATE -Wno-class-memaccess)
ENDIF()
INSTALL(DIRECTORY njson/include/njson
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nugu/)

Expand Down
119 changes: 119 additions & 0 deletions include/base/nugu_winsock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2019 SK Telecom 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.
*/

#ifndef __NUGU_WINSOCKET_H__
#define __NUGU_WINSOCKET_H__

#ifdef __MSYS__

#ifdef __cplusplus
extern "C" {
#endif

/**
* @file nugu_winsock.h
* @defgroup NuguWinSock WindowSocket
* @ingroup SDKBase
* @brief Window tcp socket pair
*
* @{
*/

/**
* @brief window socket type
*/
typedef enum _nugu_winsock_type {
NUGU_WINSOCKET_SERVER, /**< Server socket type */
NUGU_WINSOCKET_CLIENT, /**< Client socket type */
} NuguWinSocketType;

/**
* @brief NuguWinSocket
*/
typedef struct _nugu_winsock_t NuguWinSocket;

/**
* @brief Initialize window socket
* @return result
* @retval 0 success
* @retval -1 failure
*/
int nugu_winsock_init(void);

/**
* @brief Deinitialize window socket
*/
void nugu_winsock_deinit(void);

/**
* @brief Create window socket
* @return window socket
* @see nugu_winsock_remove()
*/
NuguWinSocket *nugu_winsock_create(void);

/**
* @brief Remove window socket
* @param[in] wsock window socket
* @see nugu_winsock_create()
*/
void nugu_winsock_remove(NuguWinSocket *wsock);

/**
* @brief Get window socket handle for read/write
* @param[in] wsock window socket
* @param[in] type window socket type
* @return window socket handle
* @retval -1 failure
*/
int nugu_winsock_get_handle(NuguWinSocket *wsock, NuguWinSocketType type);

/**
* @brief Check for data in window socket
* @param[in] handle window socket handle
* @return result
* @retval -1 failure
* @retval 0 data is exist
*/
int nugu_winsock_check_for_data(int handle);

/**
* @brief Read data in window socket
* @param[in] handle window socket handle
* @param[out] buf data buffer
* @param[in] len data length
* @return read data size
* @retval -1 failure
*/
int nugu_winsock_read(int handle, char *buf, int len);

/**
* @brief Write data to window socket
* @param[in] handle window socket handle
* @param[in] buf data buffer
* @param[in] len data length
* @return written data size
* @retval -1 failure
*/
int nugu_winsock_write(int handle, const char *buf, int len);

#ifdef __cplusplus
}
#endif

#endif // __MSYS__

#endif // __NUGU_WINSOCKET_H__
10 changes: 10 additions & 0 deletions nugu-no-epd.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/nugu
version=@VERSION@

Name: nugu
Description: An AI platform
Version: ${version}
Requires: glib-2.0 @requires@
Libs: -L${libdir} -lnugu
Cflags: -I${includedir} -I${includedir}/base -I${includedir}/interface -I${includedir}/clientkit
3 changes: 3 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ MACRO(DEFINE_PLUGIN name)
ADD_LIBRARY(${name} SHARED ${name}.c)
TARGET_LINK_LIBRARIES(${name} ${pkgs_LDFLAGS} -lnugu)
SET_TARGET_PROPERTIES(${name} PROPERTIES PREFIX "" OUTPUT_NAME ${name})
IF(CMAKE_SYSTEM_NAME MATCHES "MINGW")
SET_TARGET_PROPERTIES(${name} PROPERTIES SUFFIX ".dll")
ENDIF()
INSTALL(TARGETS ${name} LIBRARY DESTINATION ${plugindir} COMPONENT libnugu_component)
ADD_DEPENDENCIES(${name} libnugu)
ENDIF()
Expand Down
9 changes: 9 additions & 0 deletions plugins/gstreamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ static int _create(NuguPlayerDriver *driver, NuguPlayer *player)
goto error_out;
}

#ifdef __MSYS__
gh->audio_sink =
gst_element_factory_make("directsoundsink", audio_sink);
if (!gh->audio_sink) {
nugu_error("create gst_element for 'directsoundsink' failed");
goto error_out;
}
#else
#ifdef ENABLE_PULSEAUDIO
gh->audio_sink = gst_element_factory_make("pulsesink", audio_sink);
if (!gh->audio_sink) {
Expand All @@ -443,6 +451,7 @@ static int _create(NuguPlayerDriver *driver, NuguPlayer *player)
goto error_out;
}
#endif
#endif

#ifdef ENABLE_GSTREAMER_PLUGIN_VOLUME
gh->volume = gst_element_factory_make("volume", volume);
Expand Down
9 changes: 9 additions & 0 deletions plugins/gstreamer_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ static int _create_gst_elements(struct pa_audio_param *pcm_param)
}
#endif

#ifdef __MSYS__
pcm_param->audio_sink =
gst_element_factory_make("directsoundsink", audio_sink);
if (!pcm_param->audio_sink) {
nugu_error("create gst_element for 'directsoundsink' failed");
goto error_out;
}
#else
#ifdef ENABLE_PULSEAUDIO
pcm_param->audio_sink =
gst_element_factory_make("pulsesink", audio_sink);
Expand All @@ -439,6 +447,7 @@ static int _create_gst_elements(struct pa_audio_param *pcm_param)
goto error_out;
}
#endif
#endif

#ifdef ENABLE_GSTREAMER_PLUGIN_VOLUME
gst_bin_add_many(GST_BIN(pcm_param->pipeline),
Expand Down
5 changes: 5 additions & 0 deletions plugins/gstreamer_recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,13 @@ static GstreamerHandle *_create(NuguRecorder *rec)
}

gh->pipeline = gst_pipeline_new(pipeline);
#ifdef __MSYS__
gh->audio_source =
gst_element_factory_make("directsoundsrc", audio_source);
#else
gh->audio_source =
gst_element_factory_make("autoaudiosrc", audio_source);
#endif
gh->caps_filter = gst_element_factory_make("capsfilter", caps_filter);
#ifdef __APPLE__
gh->audioconvert =
Expand Down
Loading