From aa5d28ed85ec899df548bb16342d4962c0501bab Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 1 Mar 2014 19:15:36 +0800 Subject: [PATCH] add library --- trunk/auto/generate_header.sh | 4 ++ trunk/auto/libs.sh | 79 ++++++++++++++++++++++++++++++++++ trunk/configure | 23 ++++++++-- trunk/src/libs/srs_librtmp.cpp | 24 +++++++++++ trunk/src/libs/srs_librtmp.hpp | 31 +++++++++++++ trunk/src/srs/srs.upp | 3 ++ 6 files changed, 161 insertions(+), 3 deletions(-) create mode 100755 trunk/auto/generate_header.sh create mode 100755 trunk/auto/libs.sh create mode 100644 trunk/src/libs/srs_librtmp.cpp create mode 100644 trunk/src/libs/srs_librtmp.hpp diff --git a/trunk/auto/generate_header.sh b/trunk/auto/generate_header.sh new file mode 100755 index 000000000..0fa4f4b0c --- /dev/null +++ b/trunk/auto/generate_header.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# genereate the library header file. + +objs=$1 diff --git a/trunk/auto/libs.sh b/trunk/auto/libs.sh new file mode 100755 index 000000000..41766633d --- /dev/null +++ b/trunk/auto/libs.sh @@ -0,0 +1,79 @@ +# generate the library for static link. +# +# params: +# $SRS_OBJS the objs directory. ie. objs +# $SRS_MAKEFILE the makefile name. ie. Makefile +# +# $BUILD_KEY a string indicates the build key for Makefile. ie. dump +# $LIB_NAME the app name to output. ie. smart_server +# $MODULE_OBJS array, the objects to compile the app. +# $LINK_OPTIONS the linker options to generate the so(shared library). + +FILE=${SRS_OBJS}/${SRS_MAKEFILE} + +LIB_TARGET="${SRS_OBJS}/${LIB_NAME}" +LIB_TAGET_STATIC="${LIB_TARGET}.a" +LIB_TAGET_SHARED="${LIB_TARGET}.so" + +echo "generate lib ${LIB_NAME} depends..." + +echo "" >> ${FILE} +echo "# archive library ${LIB_TAGET_STATIC}" >> ${FILE} +echo "${BUILD_KEY}: ${LIB_TAGET_SHARED}" >> ${FILE} + +# build depends +echo -n "${LIB_TAGET_SHARED}: " >> ${FILE} +for item in ${MODULE_OBJS[*]}; do + FILE_NAME=`basename $item` + FILE_NAME=${FILE_NAME%.*} + + if [ ! -f ${item} ]; then + continue; + fi + + OBJ_FILE=${SRS_OBJS}/$item + OBJ_FILE="${OBJ_FILE%.*}.o" + echo -n "${OBJ_FILE} " >> ${FILE} +done +echo "" >> ${FILE} + +# build header file +echo -n " @bash auto/generate_header.sh ${SRS_OBJS}" >> ${FILE} +echo "" >> ${FILE} + +# archive librtmp.a +echo -n " \$(AR) -rs ${LIB_TAGET_STATIC} " >> ${FILE} +for item in ${MODULE_OBJS[*]}; do + FILE_NAME=`basename $item` + FILE_NAME=${FILE_NAME%.*} + + if [ ! -f ${item} ]; then + continue; + fi + + OBJ_FILE=${SRS_OBJS}/$item + OBJ_FILE="${OBJ_FILE%.*}.o" + echo -n "${OBJ_FILE} " >> ${FILE} +done +echo "" >> ${FILE} + +echo "generate lib ${LIB_NAME} link..."; + +# archive librtmp.so +echo -n " \$(GCC) -shared -o ${LIB_TAGET_SHARED} " >> ${FILE} +for item in ${MODULE_OBJS[*]}; do + FILE_NAME=`basename $item` + FILE_NAME=${FILE_NAME%.*} + + if [ ! -f ${item} ]; then + continue; + fi + + OBJ_FILE=${SRS_OBJS}/$item + OBJ_FILE="${OBJ_FILE%.*}.o" + echo -n "${OBJ_FILE} " >> ${FILE} +done +echo -n "${LINK_OPTIONS} " >> ${FILE} +echo "" >> ${FILE} + +echo -n "generate lib ${LIB_NAME} ok"; echo '!'; diff --git a/trunk/configure b/trunk/configure index 6f70f83fa..1062b75de 100755 --- a/trunk/configure +++ b/trunk/configure @@ -42,15 +42,16 @@ echo "" >> $SRS_AUTO_HEADERS_H echo "generate Makefile" SRS_MAKEFILE="Makefile" cat << END > ${SRS_MAKEFILE} -.PHONY: default help clean server bandwidth _prepare_dir -default: server bandwidth +.PHONY: default help clean server bandwidth librtmp _prepare_dir +default: server bandwidth librtmp help: - @echo "Usage: make |||" + @echo "Usage: make ||||" @echo " help display this help menu" @echo " clean cleanup project" @echo " server build the srs(simple rtmp server) over st(state-threads)" @echo " bandwidth build the bandwidth test client tool." + @echo " librtmp build the client publish/play library." clean: (rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp src st_*_load research) @@ -63,6 +64,10 @@ bandwidth: _prepare_dir @echo "build the bandwidth test client tool" \$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE} bandwidth +librtmp: _prepare_dir + @echo "build the client publish/play library." + \$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE} librtmp + # the ./configure will generate it. _prepare_dir: @mkdir -p ${SRS_OBJS} @@ -158,6 +163,14 @@ MODULE_FILES=("srs_core_server" "srs_core_conn" "srs_core_client" "srs_core_sock MODULE_DIR="src/app" . auto/modules.sh APP_OBJS="${MODULE_OBJS[@]}" # +#LIBS Module, build libsrs.a for static link. +MODULE_ID="LIBS" +MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") +ModuleLibIncs=() +MODULE_FILES=("srs_librtmp") +MODULE_DIR="src/libs" . auto/modules.sh +LIBS_OBJS="${MODULE_OBJS[@]}" +# #Main Module MODULE_ID="MAIN" MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") @@ -186,6 +199,10 @@ BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh # bandwidth # bandwidth test tool, to test the bandwidth to server BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/apps.sh +# +# srs librtmp +MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}" +BUILD_KEY="librtmp" LIB_NAME="srs_librtmp" LINK_OPTIONS="" . auto/libs.sh echo 'configure ok! ' diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp new file mode 100644 index 000000000..e6dac2ee6 --- /dev/null +++ b/trunk/src/libs/srs_librtmp.cpp @@ -0,0 +1,24 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp new file mode 100644 index 000000000..f845ce268 --- /dev/null +++ b/trunk/src/libs/srs_librtmp.hpp @@ -0,0 +1,31 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef SRS_LIB_RTMP_HPP +#define SRS_LIB_RTMP_HPP + +/* +#include +*/ + +#endif diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 2c5623728..e4f7868a6 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -4,6 +4,9 @@ file ..\main\srs_main_bandcheck.cpp, auto readonly separator, ..\..\objs\srs_auto_headers.hpp, + libs readonly separator, + ..\libs\srs_librtmp.hpp, + ..\libs\srs_librtmp.cpp, core readonly separator, ..\core\srs_core.hpp, ..\core\srs_core.cpp,