Skip to content

Commit

Permalink
Merge pull request #3 from Mingyiz/master
Browse files Browse the repository at this point in the history
.
  • Loading branch information
kedacomresearch authored Jan 26, 2018
2 parents 249a7bc + f6f2f3b commit 7f38cd3
Show file tree
Hide file tree
Showing 9 changed files with 613 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CMakelists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 2.8)
project(libwebstreamer)

if(__AUTOCMAKE__)
include( AutoCMake )
else()
include(cmake/AutoCMake.cmake)
endif()
autocmake_pkgconfig_init()

include_directories(lib)

#add_library( libwebstreamer SHARED lib/source/example.cpp)
file(GLOB_RECURSE LWS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lib/*.[ch]pp")

autocmake_add_library(libwebstreamer SHARED
SOURCES ${LWS_SOURCES}
MODULES gstreamer-1.0 glib-2.0 json-glib-1.0 openwebrtc-lite-0.3
)
if(MSVC)

else()
set_target_properties(libwebstreamer PROPERTIES PREFIX "lib")
set_target_properties(libwebstreamer PROPERTIES OUTPUT_NAME "webstreamer")
set_target_properties(libwebstreamer PROPERTIES EXPORT_NAME "libwebstreamer")
endif()
#set_target_properties(libwebstreamer PROPERTIES VERSION 1.1 SOVERSION 1)

install(TARGETS libwebstreamer
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/libwebstreamer.h DESTINATION include )
10 changes: 10 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if not exist %~dp0\build mkdir %~dp0\build
pushd %~dp0\build
set PKG_CONFIG=C:\cerbero\build-tools\bin\pkg-config

set PKG_CONFIG_LIBDIR=C:\cerbero\x86_64\lib\pkgconfig
%PKG_CONFIG% --version
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX="C:/cerbero/x86_64" ..
cmake --build . --target ALL_BUILD --config Debug -- /p:Platform=x64
cmake --build . --target INSTALL --config Debug -- /p:Platform=x64
popd
221 changes: 221 additions & 0 deletions cmake/AutoCMake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@

set( AUTOCMAKE_ROOT ${CMAKE_CURRENT_LIST_DIR})
enable_testing()

include (CMakeParseArguments)

macro( TRACE msg )
if ( $ENV{AUTOCMAKE_TRACE} MATCHES "ON" )
MESSAGE( ${msg} )
endif()
endmacro()

IF(MSVC)
ADD_DEFINITIONS( -D_CRT_SECURE_NO_DEPRECATE )
ADD_DEFINITIONS( -D_CRT_NONSTDC_NO_DEPRECATE )
ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS )

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

ENDIF()


if(MSVC)
option(MSVC_STATIC_RUNTIME
"Link all libraries and executables with the C run-time DLL (msvcr*.dll)
instead of the static C run-time library (libcmt*.lib.)
The default is to use the C run-time DLL only with the
libraries and executables that need it."
OFF)
if(MSVC_STATIC_RUNTIME)
# Use the static C library for all build types
foreach(var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
endif()
endforeach()
endif()
endif()


macro( autocmake_msvc_project_group source_files sgbd_cur_dir)
if(MSVC)
foreach(sgbd_file ${${source_files}})

string(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${sgbd_file})
string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath})
string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)
string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name})

if(sgbd_nogroup)
set(sgbd_group_name "\\")
endif(sgbd_nogroup)

source_group(${sgbd_group_name} FILES ${sgbd_file})

endforeach(sgbd_file)
endif()
endmacro()

macro( autocmake_default_set _variable _defalut _value)
SET( M "dset variable:${_variable} _defalut:${_defalut} value:${_value}<${${_value}}>" )

if( ${_value} )
SET(M "+${M}")
set( ${_variable} ${${_value}} )
else()
set( ${_variable} ${_defalut} )
SET(M "-[${_variable}:${${_variable}}@${_defalut}]${M}")
endif()
#MESSAGE("${M} => ${${_variable}}")
endmacro()

macro( autocmake_install_pc )


CMAKE_PARSE_ARGUMENTS( _this ""
"VERSION;NAME;DESCRIPTION;PREFIX;DESTINATION;INCLUDEDIR;SHAREDLIBDIR;EXECDIR;LIBDIR;BINDIR"
"LIBS;CFLAGS;REQUIRES"
${ARGN} )
#MESSAGE( "+_this_EXECDIR : ${_this_EXECDIR}" )
autocmake_default_set( _this_NAME "${PROJECT_NAME}" _this_NAME )
autocmake_default_set( _this_VERSION "${VERSION}" _this_VERSION )
autocmake_default_set( _this_PREFIX "${CMAKE_INSTALL_PREFIX}" _this_PREFIX )
autocmake_default_set( _this_DESTINATION "lib/pkgconfig" _this_DESTINATION )
autocmake_default_set( _this_DESCRIPTION "" _this_DESCRIPTION )
autocmake_default_set( _this_LIBS ${_this_NAME} _this_LIBS )
autocmake_default_set( _this_CFLAGS "" _this_CFLAGS )
autocmake_default_set( _this_INCLUDEDIR "include" _this_INCLUDEDIR )
autocmake_default_set( _this_LIBDIR "lib" _this_LIBDIR )
autocmake_default_set( _this_EXECDIR "bin" _this_EXECDIR )
autocmake_default_set( _this_SHAREDLIBDIR "lib" _this_SHAREDLIBDIR)
#MESSAGE( "-_this_EXECDIR : ${_this_EXECDIR}" )

set(_libs "")
foreach( _lib ${_this_LIBS} )
set( _libs "-l${_lib} ${_libs}")
endforeach()
set(_requires)
foreach( _req ${_this_REQUIRES} )
if ( _requires )
set( _requires "${_requires}, ${_req}")
else()
set( _requires "${_req}")
endif()
endforeach()

#MESSAGE("******${_this_NAME} : @${CMAKE_CURRENT_BINARY_DIR}/${_this_NAME}.pc ")
FILE( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_this_NAME}.pc
"prefix=${_this_PREFIX}\n"
"exec_prefix=\${prefix}/${_this_EXECDIR}\n"
"libdir=\${prefix}/${_this_LIBDIR}\n"
"sharedlibdir=\${prefix}/${_this_SHAREDLIBDIR}\n"
"includedir=\${prefix}/${_this_INCLUDEDIR}\n"
"\n"
"Name: ${_this_NAME}\n"
"Description: ${_this_DESCRIPTION}\n"
"Version: ${_this_VERSION}\n"
"Requires: ${_requires}\n"
"\n"
"Requires:\n"
"Libs: -L\${libdir} -L\${sharedlibdir} ${_libs}\n"
"Cflags: -I\${includedir} ${_this_CFLAGS}\n" )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_this_NAME}.pc DESTINATION "${_this_DESTINATION}")
endmacro()

macro( autocmake_pkgconfig_init )


find_package(PkgConfig 0.29.1 REQUIRED)
if( "$ENV{MSYSTEM}" STREQUAL "msys" )
foreach ( _var $ENV{PKG_CONFIG_LIBDIR} $ENV{PKG_CONFIG_PATH} )

execute_process(COMMAND cygpath --unix ${_var}
OUTPUT_VARIABLE _upath
OUTPUT_STRIP_TRAILING_WHITESPACE)
if( NOT _PKG_CONFIG_PATH )
SET( _PKG_CONFIG_PATH ${_upath})
else()
SET( _PKG_CONFIG_PATH ${_upath}:${_PKG_CONFIG_PATH} )
endif()
endforeach()
SET(ENV{PKG_CONFIG_PATH} ${_PKG_CONFIG_PATH})
endif()

endmacro()

macro( autocmake_check_modules _prefix )
TRACE("+autocmake_check_modules ${_prefix}")
set( ${_prefix}_LIBS)
set( ${_prefix}_LINK_DIRECTORIES)
set( ${_prefix}_INCLUDE_DIRECTORIES)

foreach( _pkg ${ARGN} )
pkg_check_modules( ${_pkg} ${_pkg} REQUIRED)
TRACE(" ${_pkg}_CFLAGS : ${${_pkg}_CFLAGS}")
TRACE(" ${_pkg}_INCLUDEDIR : ${${_pkg}_INCLUDEDIR}")
TRACE(" ${_pkg}_INCLUDE_DIRS : ${${_pkg}_INCLUDE_DIRS}")
TRACE(" ${_pkg}_LIBRARY_DIRS : ${${_pkg}_LIBRARY_DIRS}")
list(APPEND ${_prefix}_LINK_DIRECTORIES ${${_pkg}_LIBRARY_DIRS} )
list(APPEND ${_prefix}_INCLUDE_DIRECTORIES ${${_pkg}_INCLUDE_DIRS} )
list(APPEND ${_prefix}_INCLUDE_DIRECTORIES ${${_pkg}_INCLUDEDIR} )
list(APPEND ${_prefix}_LIBS ${${_pkg}_LIBRARIES})

endforeach()
list(REMOVE_DUPLICATES ${_prefix}_LINK_DIRECTORIES)
list(REMOVE_DUPLICATES ${_prefix}_INCLUDE_DIRECTORIES)
list(REMOVE_DUPLICATES ${_prefix}_LIBS)
foreach(cat LINK_DIRECTORIES;INCLUDE_DIRECTORIES;LIBS)
TRACE("<${cat}>")
foreach(item ${${_prefix}_${cat}})
TRACE(" ${item}")
endforeach()

endforeach(cat )
TRACE("-autocmake_check_modules ${_prefix}")



endmacro()

macro( autocmake_add_library _name )
CMAKE_PARSE_ARGUMENTS( _this "STATIC;SHARED"
""
"MODULES;SOURCES"
${ARGN} )
autocmake_check_modules( _module ${_this_MODULES})
include_directories( ${_module_INCLUDE_DIRECTORIES} )
link_directories( ${_module_LINK_DIRECTORIES} )

# MESSAGE(" ${_this_STATIC} | ${_this_SHARED}")

if( ${_this_STATIC} )
add_library( ${_name} STATIC ${_this_SOURCES})
endif()

if( ${_this_SHARED} )
add_library( ${_name} SHARED ${_this_SOURCES})
target_link_libraries( ${_name} ${_module_LIBS})
endif()


endmacro()

macro( autocmake_add_add_executable _name )
CMAKE_PARSE_ARGUMENTS( _this "" ""
"MODULES;SOURCES"
${ARGN} )
autocmake_check_modules( _module ${_this_MODULES})
include_directories( ${_module_INCLUDE_DIRECTORIES} )
link_directories( ${_module_LINK_DIRECTORIES} )
add_executable( ${_name} ${_this_SOURCES})
target_link_libraries( ${_name} ${_module_LIBS})
endmacro()
38 changes: 38 additions & 0 deletions lib/dispatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//#include "webstreamer.hpp"
//#include "dispatcher.hpp"
//#include <memory>
//#include <glib.h>

//namespace libwebstreamer
//{
// namespace dispatcher
// {
// static std::unique_ptr<GAsyncQueue, decltype(&g_async_queue_unref)> _data_queue(g_async_queue_new(), &g_async_queue_unref);
// static std::unique_ptr<GAsyncQueue, decltype(&g_async_queue_unref)> _size_queue(g_async_queue_new(), &g_async_queue_unref);
// static std::unique_ptr<GAsyncQueue, decltype(&g_async_queue_unref)> _context_queue(g_async_queue_new(), &g_async_queue_unref);
//
// static gboolean on_call_pipeline_manager(gpointer manager);
//
// void on_call(const void* data, size_t size, void* context)
// {
// g_print("@on_call:=--data:%d,size:%d,context:%d---------\n", data, size, context);
//
// g_async_queue_push(_context_queue.get(), context);
// g_async_queue_push(_data_queue.get(), (gpointer)data);
// g_async_queue_push(_size_queue.get(), (gpointer)size);
//
// schedule_with_user_data(on_call_pipeline_manager, NULL);
// }
//
// gboolean on_call_pipeline_manager(gpointer manager)
// {
// const void* data = g_async_queue_pop(_data_queue.get());
// size_t size = (size_t)g_async_queue_pop(_size_queue.get());
// void* context = g_async_queue_pop(_context_queue.get());
// g_print("@on_call_pipeline_manager:=--data:%d,size:%d,context:%d---------\n", data, size, context);
// on_callback(data, size, context);
//
// return G_SOURCE_REMOVE;
// }
// }
//}
13 changes: 13 additions & 0 deletions lib/dispatcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef LIBWEBSTREAMER_DISPATCHER_DISPATCHER_HPP
#define LIBWEBSTREAMER_DISPATCHER_DISPATCHER_HPP

namespace libwebstreamer
{
namespace dispatcher
{
void on_call(const void* data, size_t size, void* context);
void on_callback(const void* data, size_t size, void* context);
}
}

#endif
Loading

0 comments on commit 7f38cd3

Please sign in to comment.