mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add librtmp demo srs_publish
This commit is contained in:
parent
aa5d28ed85
commit
713b05541b
12 changed files with 172 additions and 34 deletions
|
@ -2,3 +2,7 @@
|
|||
# genereate the library header file.
|
||||
|
||||
objs=$1
|
||||
|
||||
rm -f $objs/include/srs_librtmp.h &&
|
||||
cp $objs/../src/libs/srs_librtmp.hpp $objs/include/srs_librtmp.h
|
||||
echo "genereate srs-librtmp headers success"
|
||||
|
|
|
@ -7,22 +7,20 @@
|
|||
# $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}
|
||||
echo "${BUILD_KEY}: ${LIB_TAGET_STATIC}" >> ${FILE}
|
||||
|
||||
# build depends
|
||||
echo -n "${LIB_TAGET_SHARED}: " >> ${FILE}
|
||||
echo -n "${LIB_TAGET_STATIC}: " >> ${FILE}
|
||||
for item in ${MODULE_OBJS[*]}; do
|
||||
FILE_NAME=`basename $item`
|
||||
FILE_NAME=${FILE_NAME%.*}
|
||||
|
@ -57,23 +55,4 @@ for item in ${MODULE_OBJS[*]}; do
|
|||
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 '!';
|
||||
|
|
13
trunk/configure
vendored
13
trunk/configure
vendored
|
@ -54,7 +54,7 @@ help:
|
|||
@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)
|
||||
(rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp src st_*_load research include lib)
|
||||
|
||||
server: _prepare_dir
|
||||
@echo "build the srs(simple rtmp server) over st(state-threads)"
|
||||
|
@ -83,8 +83,10 @@ GDBDebug="-g -O0"
|
|||
WarnLevel="-Wall"
|
||||
# the compile standard.
|
||||
CppStd="-ansi"
|
||||
# for library compile
|
||||
LibraryCompile="-fPIC"
|
||||
# the cxx flag generated.
|
||||
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug}"
|
||||
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${LibraryCompile}"
|
||||
#CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}"
|
||||
cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
|
||||
CC ?= gcc
|
||||
|
@ -166,7 +168,7 @@ APP_OBJS="${MODULE_OBJS[@]}"
|
|||
#LIBS Module, build libsrs.a for static link.
|
||||
MODULE_ID="LIBS"
|
||||
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
|
||||
ModuleLibIncs=()
|
||||
ModuleLibIncs=(${SRS_OBJS})
|
||||
MODULE_FILES=("srs_librtmp")
|
||||
MODULE_DIR="src/libs" . auto/modules.sh
|
||||
LIBS_OBJS="${MODULE_OBJS[@]}"
|
||||
|
@ -202,7 +204,7 @@ BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/
|
|||
#
|
||||
# srs librtmp
|
||||
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}"
|
||||
BUILD_KEY="librtmp" LIB_NAME="srs_librtmp" LINK_OPTIONS="" . auto/libs.sh
|
||||
BUILD_KEY="librtmp" LIB_NAME="lib/srs_librtmp" . auto/libs.sh
|
||||
|
||||
echo 'configure ok! '
|
||||
|
||||
|
@ -211,6 +213,9 @@ echo 'configure ok! '
|
|||
#####################################################################################
|
||||
# create objs/logs for ffmpeg to write log.
|
||||
mkdir -p ${SRS_OBJS}/logs
|
||||
# lib and include for library
|
||||
mkdir -p ${SRS_OBJS}/lib
|
||||
mkdir -p ${SRS_OBJS}/include
|
||||
|
||||
#####################################################################################
|
||||
# configure summary
|
||||
|
|
7
trunk/research/librtmp/Makefile
Executable file
7
trunk/research/librtmp/Makefile
Executable file
|
@ -0,0 +1,7 @@
|
|||
.PHONY: clean
|
||||
|
||||
srs_publish: srs_publish.c Makefile ../../objs/include/srs_librtmp.h ../../objs/lib/srs_librtmp.a
|
||||
gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
|
||||
|
||||
clean:
|
||||
@rm -f srs_publish
|
36
trunk/research/librtmp/srs_publish.c
Executable file
36
trunk/research/librtmp/srs_publish.c
Executable file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
/**
|
||||
gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../../objs/include/srs_librtmp.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("srs(simple-rtmp-server) client librtmp library.\n");
|
||||
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -77,8 +77,8 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server)
|
|||
|
||||
stream_name = req->stream;
|
||||
server = forward_server;
|
||||
std::string s_port = RTMP_DEFAULT_PORTS;
|
||||
port = RTMP_DEFAULT_PORT;
|
||||
std::string s_port = RTMP_DEFAULT_PORT;
|
||||
port = ::atoi(RTMP_DEFAULT_PORT);
|
||||
|
||||
size_t pos = forward_server.find(":");
|
||||
if (pos != std::string::npos) {
|
||||
|
|
|
@ -29,7 +29,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
*/
|
||||
|
||||
// current release version
|
||||
#define RTMP_SIG_SRS_VERSION "0.9.8"
|
||||
#define VERSION_MAJOR "0"
|
||||
#define VERSION_MINOR "9"
|
||||
#define VERSION_REVISION "8"
|
||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "srs"
|
||||
#define RTMP_SIG_SRS_ROLE "origin server"
|
||||
|
|
|
@ -22,3 +22,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
*/
|
||||
|
||||
#include <srs_librtmp.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <srs_protocol_rtmp.hpp>
|
||||
|
||||
/**
|
||||
* the stream over epoll: never wait for data coming, that is async mode.
|
||||
*/
|
||||
class SimpleSocketStream
|
||||
{
|
||||
private:
|
||||
int sock;
|
||||
public:
|
||||
SimpleSocketStream(int fd){
|
||||
sock = fd;
|
||||
}
|
||||
virtual ~SimpleSocketStream() {
|
||||
::close(sock);
|
||||
}
|
||||
public:
|
||||
};
|
||||
|
||||
/**
|
||||
* export runtime context.
|
||||
*/
|
||||
struct Context
|
||||
{
|
||||
SrsRtmpClient* rtmp;
|
||||
SimpleSocketStream* stream;
|
||||
int stream_id;
|
||||
|
||||
Context() {
|
||||
rtmp = NULL;
|
||||
stream = NULL;
|
||||
stream_id = 0;
|
||||
}
|
||||
virtual ~Context() {
|
||||
srs_freep(rtmp);
|
||||
srs_freep(stream);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
srs_rtmp_t srs_rtmp_create(){
|
||||
Context* context = new Context();
|
||||
return context;
|
||||
}
|
||||
|
||||
void srs_rtmp_destroy(srs_rtmp_t rtmp){
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
srs_freep(context);
|
||||
}
|
||||
|
||||
int srs_version_major()
|
||||
{
|
||||
return ::atoi(VERSION_MAJOR);
|
||||
}
|
||||
|
||||
int srs_version_minor()
|
||||
{
|
||||
return ::atoi(VERSION_MINOR);
|
||||
}
|
||||
|
||||
int srs_version_revision()
|
||||
{
|
||||
return ::atoi(VERSION_REVISION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -25,7 +25,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define SRS_LIB_RTMP_HPP
|
||||
|
||||
/*
|
||||
#include <srs_librtmp.hpp>
|
||||
#include <srs_librtmp.h>
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
// the output handler.
|
||||
typedef void* srs_rtmp_t;
|
||||
|
||||
/**
|
||||
* create a rtmp protocol stack.
|
||||
* @return a rtmp handler, or NULL if error occured.
|
||||
*/
|
||||
srs_rtmp_t srs_rtmp_create();
|
||||
|
||||
/**
|
||||
* close a rtmp protocl stack.
|
||||
*/
|
||||
void srs_rtmp_destroy(srs_rtmp_t rtmp);
|
||||
|
||||
/**
|
||||
* get protocol stack version
|
||||
*/
|
||||
int srs_version_major();
|
||||
int srs_version_minor();
|
||||
int srs_version_revision();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -116,7 +116,7 @@ int SrsRequest::discovery_app()
|
|||
srs_verbose("discovery vhost=%s", vhost.c_str());
|
||||
}
|
||||
|
||||
port = RTMP_DEFAULT_PORTS;
|
||||
port = RTMP_DEFAULT_PORT;
|
||||
if ((pos = vhost.find(":")) != std::string::npos) {
|
||||
port = vhost.substr(pos + 1);
|
||||
vhost = vhost.substr(0, pos);
|
||||
|
|
|
@ -29,8 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
*/
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#define RTMP_DEFAULT_PORT 1935
|
||||
#define RTMP_DEFAULT_PORTS "1935"
|
||||
#define RTMP_DEFAULT_PORT "1935"
|
||||
|
||||
// the default chunk size for system.
|
||||
#define SRS_CONF_DEFAULT_CHUNK_SIZE 60000
|
||||
|
|
|
@ -72,6 +72,7 @@ file
|
|||
..\app\srs_core_source.hpp,
|
||||
..\app\srs_core_source.cpp,
|
||||
research readonly separator,
|
||||
..\..\research\librtmp\srs_publish.c,
|
||||
..\..\research\hls\ts_info.cc;
|
||||
|
||||
mainconfig
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue