winlin

add librtmp demo srs_publish

@@ -2,3 +2,7 @@ @@ -2,3 +2,7 @@
2 # genereate the library header file. 2 # genereate the library header file.
3 3
4 objs=$1 4 objs=$1
  5 +
  6 +rm -f $objs/include/srs_librtmp.h &&
  7 +cp $objs/../src/libs/srs_librtmp.hpp $objs/include/srs_librtmp.h
  8 +echo "genereate srs-librtmp headers success"
@@ -7,22 +7,20 @@ @@ -7,22 +7,20 @@
7 # $BUILD_KEY a string indicates the build key for Makefile. ie. dump 7 # $BUILD_KEY a string indicates the build key for Makefile. ie. dump
8 # $LIB_NAME the app name to output. ie. smart_server 8 # $LIB_NAME the app name to output. ie. smart_server
9 # $MODULE_OBJS array, the objects to compile the app. 9 # $MODULE_OBJS array, the objects to compile the app.
10 -# $LINK_OPTIONS the linker options to generate the so(shared library).  
11 10
12 FILE=${SRS_OBJS}/${SRS_MAKEFILE} 11 FILE=${SRS_OBJS}/${SRS_MAKEFILE}
13 12
14 LIB_TARGET="${SRS_OBJS}/${LIB_NAME}" 13 LIB_TARGET="${SRS_OBJS}/${LIB_NAME}"
15 LIB_TAGET_STATIC="${LIB_TARGET}.a" 14 LIB_TAGET_STATIC="${LIB_TARGET}.a"
16 -LIB_TAGET_SHARED="${LIB_TARGET}.so"  
17 15
18 echo "generate lib ${LIB_NAME} depends..." 16 echo "generate lib ${LIB_NAME} depends..."
19 17
20 echo "" >> ${FILE} 18 echo "" >> ${FILE}
21 echo "# archive library ${LIB_TAGET_STATIC}" >> ${FILE} 19 echo "# archive library ${LIB_TAGET_STATIC}" >> ${FILE}
22 -echo "${BUILD_KEY}: ${LIB_TAGET_SHARED}" >> ${FILE} 20 +echo "${BUILD_KEY}: ${LIB_TAGET_STATIC}" >> ${FILE}
23 21
24 # build depends 22 # build depends
25 -echo -n "${LIB_TAGET_SHARED}: " >> ${FILE} 23 +echo -n "${LIB_TAGET_STATIC}: " >> ${FILE}
26 for item in ${MODULE_OBJS[*]}; do 24 for item in ${MODULE_OBJS[*]}; do
27 FILE_NAME=`basename $item` 25 FILE_NAME=`basename $item`
28 FILE_NAME=${FILE_NAME%.*} 26 FILE_NAME=${FILE_NAME%.*}
@@ -57,23 +55,4 @@ for item in ${MODULE_OBJS[*]}; do @@ -57,23 +55,4 @@ for item in ${MODULE_OBJS[*]}; do
57 done 55 done
58 echo "" >> ${FILE} 56 echo "" >> ${FILE}
59 57
60 -echo "generate lib ${LIB_NAME} link...";  
61 -  
62 -# archive librtmp.so  
63 -echo -n " \$(GCC) -shared -o ${LIB_TAGET_SHARED} " >> ${FILE}  
64 -for item in ${MODULE_OBJS[*]}; do  
65 - FILE_NAME=`basename $item`  
66 - FILE_NAME=${FILE_NAME%.*}  
67 -  
68 - if [ ! -f ${item} ]; then  
69 - continue;  
70 - fi  
71 -  
72 - OBJ_FILE=${SRS_OBJS}/$item  
73 - OBJ_FILE="${OBJ_FILE%.*}.o"  
74 - echo -n "${OBJ_FILE} " >> ${FILE}  
75 -done  
76 -echo -n "${LINK_OPTIONS} " >> ${FILE}  
77 -echo "" >> ${FILE}  
78 -  
79 echo -n "generate lib ${LIB_NAME} ok"; echo '!'; 58 echo -n "generate lib ${LIB_NAME} ok"; echo '!';
@@ -54,7 +54,7 @@ help: @@ -54,7 +54,7 @@ help:
54 @echo " librtmp build the client publish/play library." 54 @echo " librtmp build the client publish/play library."
55 55
56 clean: 56 clean:
57 - (rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp src st_*_load research) 57 + (rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp src st_*_load research include lib)
58 58
59 server: _prepare_dir 59 server: _prepare_dir
60 @echo "build the srs(simple rtmp server) over st(state-threads)" 60 @echo "build the srs(simple rtmp server) over st(state-threads)"
@@ -83,8 +83,10 @@ GDBDebug="-g -O0" @@ -83,8 +83,10 @@ GDBDebug="-g -O0"
83 WarnLevel="-Wall" 83 WarnLevel="-Wall"
84 # the compile standard. 84 # the compile standard.
85 CppStd="-ansi" 85 CppStd="-ansi"
  86 +# for library compile
  87 +LibraryCompile="-fPIC"
86 # the cxx flag generated. 88 # the cxx flag generated.
87 -CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug}" 89 +CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${LibraryCompile}"
88 #CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}" 90 #CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}"
89 cat << END > ${SRS_OBJS}/${SRS_MAKEFILE} 91 cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
90 CC ?= gcc 92 CC ?= gcc
@@ -166,7 +168,7 @@ APP_OBJS="${MODULE_OBJS[@]}" @@ -166,7 +168,7 @@ APP_OBJS="${MODULE_OBJS[@]}"
166 #LIBS Module, build libsrs.a for static link. 168 #LIBS Module, build libsrs.a for static link.
167 MODULE_ID="LIBS" 169 MODULE_ID="LIBS"
168 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") 170 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
169 -ModuleLibIncs=() 171 +ModuleLibIncs=(${SRS_OBJS})
170 MODULE_FILES=("srs_librtmp") 172 MODULE_FILES=("srs_librtmp")
171 MODULE_DIR="src/libs" . auto/modules.sh 173 MODULE_DIR="src/libs" . auto/modules.sh
172 LIBS_OBJS="${MODULE_OBJS[@]}" 174 LIBS_OBJS="${MODULE_OBJS[@]}"
@@ -202,7 +204,7 @@ BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/ @@ -202,7 +204,7 @@ BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/
202 # 204 #
203 # srs librtmp 205 # srs librtmp
204 MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}" 206 MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}"
205 -BUILD_KEY="librtmp" LIB_NAME="srs_librtmp" LINK_OPTIONS="" . auto/libs.sh 207 +BUILD_KEY="librtmp" LIB_NAME="lib/srs_librtmp" . auto/libs.sh
206 208
207 echo 'configure ok! ' 209 echo 'configure ok! '
208 210
@@ -211,6 +213,9 @@ echo 'configure ok! ' @@ -211,6 +213,9 @@ echo 'configure ok! '
211 ##################################################################################### 213 #####################################################################################
212 # create objs/logs for ffmpeg to write log. 214 # create objs/logs for ffmpeg to write log.
213 mkdir -p ${SRS_OBJS}/logs 215 mkdir -p ${SRS_OBJS}/logs
  216 +# lib and include for library
  217 +mkdir -p ${SRS_OBJS}/lib
  218 +mkdir -p ${SRS_OBJS}/include
214 219
215 ##################################################################################### 220 #####################################################################################
216 # configure summary 221 # configure summary
  1 +.PHONY: clean
  2 +
  3 +srs_publish: srs_publish.c Makefile ../../objs/include/srs_librtmp.h ../../objs/lib/srs_librtmp.a
  4 + gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
  5 +
  6 +clean:
  7 + @rm -f srs_publish
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +/**
  24 +gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
  25 +*/
  26 +
  27 +#include <stdio.h>
  28 +#include "../../objs/include/srs_librtmp.h"
  29 +
  30 +int main(int argc, char** argv)
  31 +{
  32 + printf("srs(simple-rtmp-server) client librtmp library.\n");
  33 + printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
  34 +
  35 + return 0;
  36 +}
@@ -77,8 +77,8 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) @@ -77,8 +77,8 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server)
77 77
78 stream_name = req->stream; 78 stream_name = req->stream;
79 server = forward_server; 79 server = forward_server;
80 - std::string s_port = RTMP_DEFAULT_PORTS;  
81 - port = RTMP_DEFAULT_PORT; 80 + std::string s_port = RTMP_DEFAULT_PORT;
  81 + port = ::atoi(RTMP_DEFAULT_PORT);
82 82
83 size_t pos = forward_server.find(":"); 83 size_t pos = forward_server.find(":");
84 if (pos != std::string::npos) { 84 if (pos != std::string::npos) {
@@ -29,7 +29,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,7 +29,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 30
31 // current release version 31 // current release version
32 -#define RTMP_SIG_SRS_VERSION "0.9.8" 32 +#define VERSION_MAJOR "0"
  33 +#define VERSION_MINOR "9"
  34 +#define VERSION_REVISION "8"
  35 +#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
33 // server info. 36 // server info.
34 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"
35 #define RTMP_SIG_SRS_ROLE "origin server" 38 #define RTMP_SIG_SRS_ROLE "origin server"
@@ -22,3 +22,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -22,3 +22,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 #include <srs_librtmp.hpp> 24 #include <srs_librtmp.hpp>
  25 +
  26 +#include <stdlib.h>
  27 +
  28 +#include <srs_protocol_rtmp.hpp>
  29 +
  30 +/**
  31 +* the stream over epoll: never wait for data coming, that is async mode.
  32 +*/
  33 +class SimpleSocketStream
  34 +{
  35 +private:
  36 + int sock;
  37 +public:
  38 + SimpleSocketStream(int fd){
  39 + sock = fd;
  40 + }
  41 + virtual ~SimpleSocketStream() {
  42 + ::close(sock);
  43 + }
  44 +public:
  45 +};
  46 +
  47 +/**
  48 +* export runtime context.
  49 +*/
  50 +struct Context
  51 +{
  52 + SrsRtmpClient* rtmp;
  53 + SimpleSocketStream* stream;
  54 + int stream_id;
  55 +
  56 + Context() {
  57 + rtmp = NULL;
  58 + stream = NULL;
  59 + stream_id = 0;
  60 + }
  61 + virtual ~Context() {
  62 + srs_freep(rtmp);
  63 + srs_freep(stream);
  64 + }
  65 +};
  66 +
  67 +#ifdef __cplusplus
  68 +extern "C"{
  69 +#endif
  70 +
  71 +srs_rtmp_t srs_rtmp_create(){
  72 + Context* context = new Context();
  73 + return context;
  74 +}
  75 +
  76 +void srs_rtmp_destroy(srs_rtmp_t rtmp){
  77 + srs_assert(rtmp != NULL);
  78 + Context* context = (Context*)rtmp;
  79 + srs_freep(context);
  80 +}
  81 +
  82 +int srs_version_major()
  83 +{
  84 + return ::atoi(VERSION_MAJOR);
  85 +}
  86 +
  87 +int srs_version_minor()
  88 +{
  89 + return ::atoi(VERSION_MINOR);
  90 +}
  91 +
  92 +int srs_version_revision()
  93 +{
  94 + return ::atoi(VERSION_REVISION);
  95 +}
  96 +
  97 +#ifdef __cplusplus
  98 +}
  99 +#endif
@@ -25,7 +25,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -25,7 +25,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #define SRS_LIB_RTMP_HPP 25 #define SRS_LIB_RTMP_HPP
26 26
27 /* 27 /*
28 -#include <srs_librtmp.hpp> 28 +#include <srs_librtmp.h>
29 */ 29 */
30 30
  31 +#ifdef __cplusplus
  32 +extern "C"{
  33 +#endif
  34 +
  35 +// the output handler.
  36 +typedef void* srs_rtmp_t;
  37 +
  38 +/**
  39 +* create a rtmp protocol stack.
  40 +* @return a rtmp handler, or NULL if error occured.
  41 +*/
  42 +srs_rtmp_t srs_rtmp_create();
  43 +
  44 +/**
  45 +* close a rtmp protocl stack.
  46 +*/
  47 +void srs_rtmp_destroy(srs_rtmp_t rtmp);
  48 +
  49 +/**
  50 +* get protocol stack version
  51 +*/
  52 +int srs_version_major();
  53 +int srs_version_minor();
  54 +int srs_version_revision();
  55 +
  56 +#ifdef __cplusplus
  57 +}
  58 +#endif
  59 +
31 #endif 60 #endif
@@ -116,7 +116,7 @@ int SrsRequest::discovery_app() @@ -116,7 +116,7 @@ int SrsRequest::discovery_app()
116 srs_verbose("discovery vhost=%s", vhost.c_str()); 116 srs_verbose("discovery vhost=%s", vhost.c_str());
117 } 117 }
118 118
119 - port = RTMP_DEFAULT_PORTS; 119 + port = RTMP_DEFAULT_PORT;
120 if ((pos = vhost.find(":")) != std::string::npos) { 120 if ((pos = vhost.find(":")) != std::string::npos) {
121 port = vhost.substr(pos + 1); 121 port = vhost.substr(pos + 1);
122 vhost = vhost.substr(0, pos); 122 vhost = vhost.substr(0, pos);
@@ -29,8 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,8 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
32 -#define RTMP_DEFAULT_PORT 1935  
33 -#define RTMP_DEFAULT_PORTS "1935" 32 +#define RTMP_DEFAULT_PORT "1935"
34 33
35 // the default chunk size for system. 34 // the default chunk size for system.
36 #define SRS_CONF_DEFAULT_CHUNK_SIZE 60000 35 #define SRS_CONF_DEFAULT_CHUNK_SIZE 60000
@@ -72,6 +72,7 @@ file @@ -72,6 +72,7 @@ file
72 ..\app\srs_core_source.hpp, 72 ..\app\srs_core_source.hpp,
73 ..\app\srs_core_source.cpp, 73 ..\app\srs_core_source.cpp,
74 research readonly separator, 74 research readonly separator,
  75 + ..\..\research\librtmp\srs_publish.c,
75 ..\..\research\hls\ts_info.cc; 76 ..\..\research\hls\ts_info.cc;
76 77
77 mainconfig 78 mainconfig