1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

support config and reload the pithy print.

This commit is contained in:
winlin 2013-11-10 11:52:19 +08:00
parent 6c3b5943e9
commit 3669419e4c
20 changed files with 235 additions and 97 deletions

View file

@ -21,4 +21,4 @@ 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 <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>

View file

@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CORE_AUTO_FREE_HPP
/*
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
*/
#include <srs_core.hpp>

View file

@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_log.hpp>
#include <srs_core_rtmp.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_source.hpp>
#include <srs_core_server.hpp>
#include <srs_core_pithy_print.hpp>

View file

@ -38,7 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_error.hpp>
#include <srs_core_log.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR)
@ -455,6 +455,18 @@ int SrsConfig::reload()
return ret;
}
}
srs_trace("reload listen success.");
}
// merge config: pithy_print
if (!srs_directive_equals(root->get("pithy_print"), old_root->get("pithy_print"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
SrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
srs_error("notify subscribes pithy_print listen failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload pithy_print success.");
}
return ret;
@ -593,6 +605,26 @@ SrsConfDirective* SrsConfig::get_chunk_size()
return root->get("chunk_size");
}
SrsConfDirective* SrsConfig::get_pithy_print_publish()
{
SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) {
return NULL;
}
return pithy->get("publish");
}
SrsConfDirective* SrsConfig::get_pithy_print_play()
{
SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) {
return NULL;
}
return pithy->get("play");
}
int SrsConfig::parse_file(const char* filename)
{
int ret = ERROR_SUCCESS;

View file

@ -114,6 +114,8 @@ public:
virtual SrsConfDirective* get_refer_publish(std::string vhost);
virtual SrsConfDirective* get_listen();
virtual SrsConfDirective* get_chunk_size();
virtual SrsConfDirective* get_pithy_print_publish();
virtual SrsConfDirective* get_pithy_print_play();
private:
virtual int parse_file(const char* filename);
virtual int parse_argv(int& i, char** argv);

View file

@ -21,14 +21,14 @@ 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 <srs_core_complex_handshake.hpp>
#include <srs_core_handshake.hpp>
#include <time.h>
#include <stdlib.h>
#include <srs_core_error.hpp>
#include <srs_core_log.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_socket.hpp>
// 68bytes FMS key which is used to sign the sever packet.
@ -1058,6 +1058,72 @@ void c1s1::destroy_blocks()
}
}
SrsSimpleHandshake::SrsSimpleHandshake()
{
}
SrsSimpleHandshake::~SrsSimpleHandshake()
{
}
int SrsSimpleHandshake::handshake(SrsSocket& skt)
{
int ret = ERROR_SUCCESS;
ssize_t nsize;
char* c0c1 = new char[1537];
SrsAutoFree(char, c0c1, true);
if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) {
srs_warn("read c0c1 failed. ret=%d", ret);
return ret;
}
srs_verbose("read c0c1 success.");
// plain text required.
if (c0c1[0] != 0x03) {
ret = ERROR_RTMP_PLAIN_REQUIRED;
srs_warn("only support rtmp plain text. ret=%d", ret);
return ret;
}
srs_verbose("check c0 success, required plain text.");
// try complex handshake
SrsComplexHandshake complex_handshake;
ret = complex_handshake.handshake(skt, c0c1 + 1);
if (ret == ERROR_SUCCESS) {
srs_trace("complex handshake success.");
return ret;
}
if (ret != ERROR_RTMP_TRY_SIMPLE_HS) {
srs_error("complex handshake failed. ret=%d", ret);
return ret;
}
srs_info("complex handhskae failed, try simple. ret=%d", ret);
char* s0s1s2 = new char[3073];
SrsAutoFree(char, s0s1s2, true);
// plain text required.
s0s1s2[0] = 0x03;
if ((ret = skt.write(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) {
srs_warn("simple handshake send s0s1s2 failed. ret=%d", ret);
return ret;
}
srs_verbose("simple handshake send s0s1s2 success.");
char* c2 = new char[1536];
SrsAutoFree(char, c2, true);
if ((ret = skt.read_fully(c2, 1536, &nsize)) != ERROR_SUCCESS) {
srs_warn("simple handshake read c2 failed. ret=%d", ret);
return ret;
}
srs_verbose("simple handshake read c2 success.");
srs_trace("simple handshake success.");
return ret;
}
SrsComplexHandshake::SrsComplexHandshake()
{
}

View file

@ -21,8 +21,8 @@ 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_CORE_COMPLEX_HANDSHKAE_HPP
#define SRS_CORE_COMPLEX_HANDSHKAE_HPP
#ifndef SRS_CORE_HANDSHKAE_HPP
#define SRS_CORE_HANDSHKAE_HPP
/*
#include <srs_core_complex_handshake.hpp>
@ -32,6 +32,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class SrsSocket;
/**
* try complex handshake, if failed, fallback to simple handshake.
*/
class SrsSimpleHandshake
{
public:
SrsSimpleHandshake();
virtual ~SrsSimpleHandshake();
public:
/**
* simple handshake.
*/
virtual int handshake(SrsSocket& skt);
};
/**
* rtmp complex handshake,
* @see also crtmp(crtmpserver) or librtmp,

View file

@ -23,15 +23,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_pithy_print.hpp>
#include <stdlib.h>
#include <map>
#include <srs_core_log.hpp>
#include <srs_core_config.hpp>
#include <srs_core_reload.hpp>
#include <srs_core_error.hpp>
#define SRS_STAGE_DEFAULT_INTERVAL_MS 1200
#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300
#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100
struct SrsStageInfo
struct SrsStageInfo : public SrsReloadHandler
{
int stage_id;
int pithy_print_time_ms;
@ -40,19 +44,46 @@ struct SrsStageInfo
SrsStageInfo(int _stage_id)
{
stage_id = _stage_id;
switch (_stage_id) {
case SRS_STAGE_PLAY_USER:
nb_clients = 0;
update_print_time();
config->subscribe(this);
}
virtual ~SrsStageInfo()
{
config->unsubscribe(this);
}
void update_print_time()
{
switch (stage_id) {
case SRS_STAGE_PLAY_USER: {
pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS;
case SRS_STAGE_PUBLISH_USER:
pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
SrsConfDirective* conf = config->get_pithy_print_play();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break;
default:
}
case SRS_STAGE_PUBLISH_USER: {
pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
SrsConfDirective* conf = config->get_pithy_print_publish();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break;
}
default: {
pithy_print_time_ms = SRS_STAGE_DEFAULT_INTERVAL_MS;
break;
}
}
nb_clients = 0;
}
public:
virtual int on_reload_pithy_print()
{
update_print_time();
return ERROR_SUCCESS;
}
};
static std::map<int, SrsStageInfo*> _srs_stages;

View file

@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_socket.hpp>
#include <srs_core_buffer.hpp>
#include <srs_core_stream.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
/****************************************************************************
*****************************************************************************

View file

@ -35,7 +35,11 @@ SrsReloadHandler::~SrsReloadHandler()
int SrsReloadHandler::on_reload_listen()
{
int ret = ERROR_SUCCESS;
return ret;
return ERROR_SUCCESS;
}
int SrsReloadHandler::on_reload_pithy_print()
{
return ERROR_SUCCESS;
}

View file

@ -39,6 +39,7 @@ public:
virtual ~SrsReloadHandler();
public:
virtual int on_reload_listen();
virtual int on_reload_pithy_print();
};
#endif

View file

@ -27,9 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_error.hpp>
#include <srs_core_socket.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_amf0.hpp>
#include <srs_core_complex_handshake.hpp>
#include <srs_core_handshake.hpp>
/**
* the signature for packets to client.
@ -167,13 +167,11 @@ SrsRtmp::SrsRtmp(st_netfd_t client_stfd)
{
protocol = new SrsProtocol(client_stfd);
stfd = client_stfd;
complex_handshake = new SrsComplexHandshake();
}
SrsRtmp::~SrsRtmp()
{
srs_freep(protocol);
srs_freep(complex_handshake);
}
void SrsRtmp::set_recv_timeout(int64_t timeout_us)
@ -225,58 +223,14 @@ int SrsRtmp::handshake()
{
int ret = ERROR_SUCCESS;
ssize_t nsize;
SrsSocket skt(stfd);
char* c0c1 = new char[1537];
SrsAutoFree(char, c0c1, true);
if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) {
srs_warn("read c0c1 failed. ret=%d", ret);
SrsSimpleHandshake hs;
if ((ret = hs.handshake(skt)) != ERROR_SUCCESS) {
return ret;
}
srs_verbose("read c0c1 success.");
// plain text required.
if (c0c1[0] != 0x03) {
ret = ERROR_RTMP_PLAIN_REQUIRED;
srs_warn("only support rtmp plain text. ret=%d", ret);
return ret;
}
srs_verbose("check c0 success, required plain text.");
// try complex handshake
ret = complex_handshake->handshake(skt, c0c1 + 1);
if (ret == ERROR_SUCCESS) {
srs_trace("complex handshake success.");
return ret;
}
if (ret != ERROR_RTMP_TRY_SIMPLE_HS) {
srs_error("complex handshake failed. ret=%d", ret);
return ret;
}
srs_info("complex handhskae failed, try simple. ret=%d", ret);
char* s0s1s2 = new char[3073];
SrsAutoFree(char, s0s1s2, true);
// plain text required.
s0s1s2[0] = 0x03;
if ((ret = skt.write(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) {
srs_warn("simple handshake send s0s1s2 failed. ret=%d", ret);
return ret;
}
srs_verbose("simple handshake send s0s1s2 success.");
char* c2 = new char[1536];
SrsAutoFree(char, c2, true);
if ((ret = skt.read_fully(c2, 1536, &nsize)) != ERROR_SUCCESS) {
srs_warn("simple handshake read c2 failed. ret=%d", ret);
return ret;
}
srs_verbose("simple handshake read c2 success.");
srs_trace("simple handshake success.");
return ret;
return ret;
}
int SrsRtmp::connect_app(SrsRequest* req)

View file

@ -39,7 +39,6 @@ class ISrsMessage;
class SrsCommonMessage;
class SrsCreateStreamPacket;
class SrsFMLEStartPacket;
class SrsComplexHandshake;
class SrsPublishPacket;
/**
@ -101,7 +100,6 @@ enum SrsClientType
class SrsRtmp
{
private:
SrsComplexHandshake* complex_handshake;
SrsProtocol* protocol;
st_netfd_t stfd;
public:

View file

@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_log.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_amf0.hpp>
#include <srs_core_codec.hpp>

View file

@ -6,8 +6,8 @@ file
..\core\srs_core.cpp,
..\core\srs_core_error.hpp,
..\core\srs_core_error.cpp,
..\core\srs_core_auto_free.hpp,
..\core\srs_core_auto_free.cpp,
..\core\srs_core_autofree.hpp,
..\core\srs_core_autofree.cpp,
..\core\srs_core_server.hpp,
..\core\srs_core_server.cpp,
..\core\srs_core_reload.hpp,
@ -26,8 +26,8 @@ file
..\core\srs_core_codec.cpp,
..\core\srs_core_rtmp.hpp,
..\core\srs_core_rtmp.cpp,
..\core\srs_core_complex_handshake.hpp,
..\core\srs_core_complex_handshake.cpp,
..\core\srs_core_handshake.hpp,
..\core\srs_core_handshake.cpp,
..\core\srs_core_protocol.hpp,
..\core\srs_core_protocol.cpp,
..\core\srs_core_amf0.hpp,