Skip to content

Commit

Permalink
support RTMP and FLV.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed May 28, 2015
1 parent 6688161 commit 7b509c7
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 63 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ cd ~ && git clone https://github.com/simple-rtmp-server/srs-dolphin.git

```
cd ~/srs-dolphin/trunk && make &&
./objs/srs_dolphin -p 19350 -w 4 -s 1936,1937,1938,1939 \
-b ../../srs/trunk/objs/srs -c conf/dolphin.conf
./objs/srs_dolphin -w 4 -p 19350 \
-b ~/srs/trunk/objs/srs -c conf/dolphin.conf \
-s 1936,1937,1938,1939
```

Remark: User can specifies the SRS in other valid path.<br/>
Expand All @@ -59,8 +60,9 @@ done
**Step 5:** Play stream

```
Origin SRS stream: rtmp://127.0.0.1:1935/live/livestream
Edge Dolphin stream: rtmp://127.0.0.1:19350/live/livestream
Origin SRS RTMP stream: rtmp://127.0.0.1:1935/live/livestream
Edge Dolphin RTMP stream: rtmp://127.0.0.1:19350/live/livestream
Edge Dolphin HTTP-FLV stream: http://127.0.0.1:8088/live/livestream.flv
```

Remark: User can use [SB][SB] to do the benchmark.
Expand All @@ -69,10 +71,11 @@ Remark: User can use [SB][SB] to do the benchmark.

1. Multiple Processes for SRS edge.
1. Delivery stream in RTMP.
1. [dev] Delivery stream in HTTP FLV.
1. Delivery stream in HTTP FLV.
1. [dev] Support HTTP API for Multiple Processes.
1. [dev] Muktiple Processes for SRS origin.
1. [dev] Auto fork new process when worker or SRS exit.
1. [dev] Load balance proxy for RTMP and HTTP-FLV.

Winlin 2015.5

Expand Down
10 changes: 10 additions & 0 deletions trunk/conf/dolphin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
# 1. listen, the port to listen is managed by dolphin.
# 2. daemon, set to off, for dolphin will fork process.
# 3. srs_log_tank, set to console, for dolphin will mange it.
# 4. http_server.listen, the port to listen is manged by dolphin.

max_connections 1000;
http_server {
enabled on;
dir ./objs/nginx/html;
}
vhost __defaultVhost__ {
mode remote;
origin 127.0.0.1:1935;
http_remux {
enabled on;
mount /[app]/[stream].flv;
hstrs on;
}
}
36 changes: 29 additions & 7 deletions trunk/src/core/dlp_core_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ void* dlp_context_fpn(void* arg)
return NULL;
}

int dlp_run_proxyer(vector<int> ports, std::vector<int> fds, std::vector<int> sports)
{
int dlp_run_proxyer(vector<int> rports, vector<int> rfds,
vector<int> hports, vector<int> hfds, vector<int> srports, vector<int> shports
) {
int ret = ERROR_SUCCESS;

// set the title to worker
Expand All @@ -375,13 +376,34 @@ int dlp_run_proxyer(vector<int> ports, std::vector<int> fds, std::vector<int> sp

DlpProxyServer server;

dlp_assert(ports.size() == fds.size());
for (int i = 0; i < (int)ports.size(); i++) {
int port = ports.at(i);
int fd = fds.at(i);
dlp_assert(rports.size() == rfds.size());
for (int i = 0; i < (int)rports.size(); i++) {
int port = rports.at(i);
int fd = rfds.at(i);

DlpProxyContext* context = new DlpProxyContext(&server);
if ((ret = context->initialize(port, fd, srports)) != ERROR_SUCCESS) {
dlp_freep(context);
return ret;
}

st_thread_t trd = NULL;
if ((trd = st_thread_create(dlp_context_fpn, context, 0, 0)) == NULL) {
dlp_freep(context);

ret = ERROR_ST_TRHEAD;
dlp_warn("worker thread create error. ret=%d", ret);
return ret;
}
}

dlp_assert(hports.size() == hfds.size());
for (int i = 0; i < (int)hports.size(); i++) {
int port = hports.at(i);
int fd = hfds.at(i);

DlpProxyContext* context = new DlpProxyContext(&server);
if ((ret = context->initialize(port, fd, sports)) != ERROR_SUCCESS) {
if ((ret = context->initialize(port, fd, shports)) != ERROR_SUCCESS) {
dlp_freep(context);
return ret;
}
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/core/dlp_core_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class DlpProxyConnection
virtual int proxy_recv(DlpProxyRecvContext* rc);
};

extern int dlp_run_proxyer(std::vector<int> ports, std::vector<int> fds, std::vector<int> sports);
extern int dlp_run_proxyer(
std::vector<int> rports, std::vector<int> rfds, std::vector<int> hports, std::vector<int> hfds,
std::vector<int> sports, std::vector<int> shports
);

#endif
23 changes: 14 additions & 9 deletions trunk/src/core/dlp_core_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace std;

#include <st.h>

int dlp_fork_srs(int rtmp_port, string binary, string conf)
int dlp_fork_srs_process(int rtmp_port, int http_port, string binary, string conf)
{
int ret = ERROR_SUCCESS;

Expand All @@ -48,32 +48,37 @@ int dlp_fork_srs(int rtmp_port, string binary, string conf)
std::string argv3 = "-p";
char argv4[10];
snprintf(argv4, sizeof(argv4), "%d", rtmp_port);
std::string argv5 = "-x";
char argv6[10];
snprintf(argv6, sizeof(argv6), "%d", http_port);
// TODO: FIXME: should specifies the log file and tank.

char** argv = new char*[5 + 1];
char** argv = new char*[7 + 1];
argv[0] = (char*)argv0.data();
argv[1] = (char*)argv1.data();
argv[2] = (char*)argv2.data();
argv[3] = (char*)argv3.data();
argv[4] = (char*)argv4;
argv[5] = NULL;
argv[5] = (char*)argv5.data();
argv[6] = (char*)argv6;
argv[7] = NULL;

dlp_trace("exec srs: %s %s %s %s %s", argv[0], argv[1], argv[2], argv[3], argv[4]);
dlp_trace("exec srs: %s %s %s %s %s %s %s", argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);

// TODO: execv or execvp
ret = execv(binary.data(), argv);

return ret;
}

int dlp_run_srs(int rtmp_port, string binary, string conf)
int dlp_run_srs(int rtmp_port, int http_port, string binary, string conf)
{
int ret = ERROR_SUCCESS;

// set the title to srs
dlp_process_title->set_title(DLP_SRS);

dlp_trace("dolphin srs serve port %d", rtmp_port);
dlp_trace("dolphin srs serve port rtmp=%d, http=%d", rtmp_port, http_port);

pid_t pid = -1;
if ((pid = fork()) < 0) {
Expand All @@ -84,13 +89,13 @@ int dlp_run_srs(int rtmp_port, string binary, string conf)

// child process: ffmpeg encoder engine.
if (pid == 0) {
ret = dlp_fork_srs(rtmp_port, binary, conf);
ret = dlp_fork_srs_process(rtmp_port, http_port, binary, conf);
exit(ret);
}

// parent.
// TODO: FIXME: we must manage these srs processes.
dlp_trace("fork srs pid=%d, port=%d, binary=%s, conf=%s", pid, rtmp_port, binary.c_str(), conf.c_str());
dlp_trace("fork srs pid=%d, rtmp=%d, http=%d, binary=%s, conf=%s", pid, rtmp_port, http_port, binary.c_str(), conf.c_str());

for (;;) {
int status = 0;
Expand All @@ -100,7 +105,7 @@ int dlp_run_srs(int rtmp_port, string binary, string conf)

// update the title with dynamic data.
char ptitle[256];
snprintf(ptitle, sizeof(ptitle), "%s(%dr)", DLP_SRS, rtmp_port);
snprintf(ptitle, sizeof(ptitle), "%s(%dr+%dh)", DLP_SRS, rtmp_port, http_port);
dlp_process_title->set_title(ptitle);

// use system sleep.
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/dlp_core_srs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

#include <dlp_core.hpp>

extern int dlp_run_srs(int rtmp_port, std::string binary, std::string conf);
extern int dlp_run_srs(int rtmp_port, int http_port, std::string binary, std::string conf);

#endif
Loading

0 comments on commit 7b509c7

Please sign in to comment.