1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

Merge SRS3.0

This commit is contained in:
winlin 2020-10-31 19:25:56 +08:00
commit 8c1eca98b0
23 changed files with 82 additions and 76 deletions

View file

@ -201,6 +201,9 @@ For previous versions, please read:
## V3 changes
* v3.0, 2020-10-31, Remove some global elements for debugging. 3.0.152
* v3.0, 2020-10-31, Use global _srs_server for debugging. 3.0.151
* v3.0, 2020-10-31, Refine source cid, track previous one. 3.0.150
* v3.0, 2020-10-25, Add hls.realtime.conf for low-latency HLS. 3.0.149
* v3.0, 2020-10-24, Refine script and startup logs. 3.0.148
* v3.0, 2020-10-23, Allow FFmpeg if exists at /usr/local/bin/ffmpeg. 3.0.147

View file

@ -91,7 +91,7 @@ bool _bandwidth_is_stopped_publish(SrsBandwidthPacket* pkt)
{
return pkt->is_stopped_publish();
}
srs_error_t _srs_expect_bandwidth_packet(SrsRtmpServer* rtmp, _CheckPacketType pfn)
srs_error_t srs_expect_bandwidth_packet(SrsRtmpServer* rtmp, _CheckPacketType pfn)
{
srs_error_t err = srs_success;
@ -241,7 +241,7 @@ srs_error_t SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* l
}
}
if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != srs_success) {
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != srs_success) {
return srs_error_wrap(err, "expect bandwidth");
}
@ -304,7 +304,7 @@ srs_error_t SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*
}
}
if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != srs_success) {
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != srs_success) {
return srs_error_wrap(err, "expect bandwidth");
}
@ -328,7 +328,7 @@ srs_error_t SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit
}
}
if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != srs_success) {
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != srs_success) {
return srs_error_wrap(err, "expect packet");
}
@ -388,7 +388,7 @@ srs_error_t SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit*
// we just ignore the packet and send the bandwidth test data.
bool is_flash = (_req->swfUrl != "");
if (!is_flash) {
if ((err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != srs_success) {
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != srs_success) {
return srs_error_wrap(err, "expect bandwidth");
}
}
@ -422,7 +422,7 @@ srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidth
bool is_flash = (_req->swfUrl != "");
if (!is_flash) {
// ignore any error.
err = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final);
err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final);
srs_error_reset(err);
}

View file

@ -57,7 +57,7 @@ using namespace std;
#include <srs_kernel_utility.hpp>
#include <srs_rtmp_stack.hpp>
using namespace _srs_internal;
using namespace srs_internal;
// @global the version to identify the core.
const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER;
@ -92,7 +92,7 @@ bool is_common_space(char ch)
return (ch == ' ' || ch == '\t' || ch == SRS_CR || ch == SRS_LF);
}
namespace _srs_internal
namespace srs_internal
{
SrsConfigBuffer::SrsConfigBuffer()
{
@ -5272,20 +5272,20 @@ int SrsConfig::get_time_jitter(string vhost)
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return _srs_time_jitter_string2int(DEFAULT);
return srs_time_jitter_string2int(DEFAULT);
}
conf = conf->get("play");
if (!conf) {
return _srs_time_jitter_string2int(DEFAULT);
return srs_time_jitter_string2int(DEFAULT);
}
conf = conf->get("time_jitter");
if (!conf || conf->arg0().empty()) {
return _srs_time_jitter_string2int(DEFAULT);
return srs_time_jitter_string2int(DEFAULT);
}
return _srs_time_jitter_string2int(conf->arg0());
return srs_time_jitter_string2int(conf->arg0());
}
bool SrsConfig::get_mix_correct(string vhost)
@ -7505,15 +7505,15 @@ int SrsConfig::get_dvr_time_jitter(string vhost)
SrsConfDirective* conf = get_dvr(vhost);
if (!conf) {
return _srs_time_jitter_string2int(DEFAULT);
return srs_time_jitter_string2int(DEFAULT);
}
conf = conf->get("time_jitter");
if (!conf || conf->arg0().empty()) {
return _srs_time_jitter_string2int(DEFAULT);
return srs_time_jitter_string2int(DEFAULT);
}
return _srs_time_jitter_string2int(conf->arg0());
return srs_time_jitter_string2int(conf->arg0());
}
bool SrsConfig::get_http_api_enabled()

View file

@ -77,7 +77,7 @@ bool srs_vector_actual_equals(const std::vector<T>& a, const std::vector<T>& b)
return true;
}
namespace _srs_internal
namespace srs_internal
{
// The buffer of config content.
class SrsConfigBuffer
@ -229,7 +229,7 @@ public:
// Parse utilities
public:
// Parse config directive from file buffer.
virtual srs_error_t parse(_srs_internal::SrsConfigBuffer* buffer);
virtual srs_error_t parse(srs_internal::SrsConfigBuffer* buffer);
// Marshal the directive to writer.
// @param level, the root is level0, all its directives are level1, and so on.
virtual srs_error_t persistence(SrsFileWriter* writer, int level);
@ -253,13 +253,13 @@ private:
// 1. read a token(directive args and a ret flag),
// 2. initialize the directive by args, args[0] is name, args[1-N] is args of directive,
// 3. if ret flag indicates there are child-directives, read_conf(directive, block) recursively.
virtual srs_error_t parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type);
virtual srs_error_t parse_conf(srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type);
// Read a token from buffer.
// A token, is the directive args and a flag indicates whether has child-directives.
// @param args, the output directive args, the first is the directive name, left is the args.
// @param line_start, the actual start line of directive.
// @return, an error code indicates error or has child-directives.
virtual srs_error_t read_token(_srs_internal::SrsConfigBuffer* buffer, std::vector<std::string>& args, int& line_start);
virtual srs_error_t read_token(srs_internal::SrsConfigBuffer* buffer, std::vector<std::string>& args, int& line_start);
};
// The config service provider.
@ -425,7 +425,7 @@ protected:
// Parse config from the buffer.
// @param buffer, the config buffer, user must delete it.
// @remark, use protected for the utest to override with mock.
virtual srs_error_t parse_buffer(_srs_internal::SrsConfigBuffer* buffer);
virtual srs_error_t parse_buffer(srs_internal::SrsConfigBuffer* buffer);
// global env
public:
// Get the current work directory.

View file

@ -1141,9 +1141,9 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle
// trigger edge to fetch from origin.
bool vhost_is_edge = _srs_config->get_vhost_is_edge(r->vhost);
srs_trace("flv: source url=%s, is_edge=%d, source_id=[%d][%s]",
r->get_stream_url().c_str(), vhost_is_edge, ::getpid(), s->source_id().c_str());
srs_trace("flv: source url=%s, is_edge=%d, source_id=%s/%s",
r->get_stream_url().c_str(), vhost_is_edge, s->source_id().c_str(), s->pre_source_id().c_str());
return err;
}

View file

@ -524,8 +524,8 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
}
bool enabled_cache = _srs_config->get_gop_cache(req->vhost);
srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=[%d][%s]",
req->get_stream_url().c_str(), ip.c_str(), enabled_cache, info->edge, ::getpid(), source->source_id().c_str());
srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=%s/%s",
req->get_stream_url().c_str(), ip.c_str(), enabled_cache, info->edge, source->source_id().c_str(), source->pre_source_id().c_str());
source->set_cache(enabled_cache);
switch (info->type) {

View file

@ -66,7 +66,7 @@ using namespace std;
// the time to cleanup source.
#define SRS_SOURCE_CLEANUP (30 * SRS_UTIME_SECONDS)
int _srs_time_jitter_string2int(std::string time_jitter)
int srs_time_jitter_string2int(std::string time_jitter)
{
if (time_jitter == "full") {
return SrsRtmpJitterAlgorithmFULL;
@ -519,7 +519,7 @@ srs_error_t SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count)
count = 0;
if (should_update_source_id) {
srs_trace("update source_id=%s[%s]", source->source_id().c_str(), source->source_id().c_str());
srs_trace("update source_id=%s/%s", source->source_id().c_str(), source->pre_source_id().c_str());
should_update_source_id = false;
}
@ -2070,13 +2070,10 @@ srs_error_t SrsSource::on_source_id_changed(SrsContextId id)
if (!_source_id.compare(id)) {
return err;
}
if (_pre_source_id.empty()) {
_pre_source_id = id;
} else if (_pre_source_id.compare(_source_id)) {
_pre_source_id = _source_id;
}
_source_id = id;
// notice all consumer
@ -2559,7 +2556,10 @@ void SrsSource::on_unpublish()
_can_publish = true;
_source_id = SrsContextId();
if (!_source_id.empty()) {
_pre_source_id = _source_id;
}
// notify the handler.
srs_assert(handler);
SrsStatistic* stat = SrsStatistic::instance();

View file

@ -72,7 +72,7 @@ enum SrsRtmpJitterAlgorithm
SrsRtmpJitterAlgorithmZERO,
SrsRtmpJitterAlgorithmOFF
};
int _srs_time_jitter_string2int(std::string time_jitter);
int srs_time_jitter_string2int(std::string time_jitter);
// Time jitter detect and correct, to ensure the rtmp stream is monotonically.
class SrsRtmpJitter

View file

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP
#define SRS_VERSION3_REVISION 149
#define SRS_VERSION3_REVISION 152
#endif

View file

@ -37,11 +37,11 @@ using namespace std;
#include <srs_kernel_error.hpp>
// For utest to mock it.
_srs_open_t _srs_open_fn = ::open;
_srs_write_t _srs_write_fn = ::write;
_srs_read_t _srs_read_fn = ::read;
_srs_lseek_t _srs_lseek_fn = ::lseek;
_srs_close_t _srs_close_fn = ::close;
srs_open_t _srs_open_fn = ::open;
srs_write_t _srs_write_fn = ::write;
srs_read_t _srs_read_fn = ::read;
srs_lseek_t _srs_lseek_fn = ::lseek;
srs_close_t _srs_close_fn = ::close;
SrsFileWriter::SrsFileWriter()
{

View file

@ -121,11 +121,11 @@ public:
};
// For utest to mock it.
typedef int (*_srs_open_t)(const char* path, int oflag, ...);
typedef ssize_t (*_srs_write_t)(int fildes, const void* buf, size_t nbyte);
typedef ssize_t (*_srs_read_t)(int fildes, void* buf, size_t nbyte);
typedef off_t (*_srs_lseek_t)(int fildes, off_t offset, int whence);
typedef int (*_srs_close_t)(int fildes);
typedef int (*srs_open_t)(const char* path, int oflag, ...);
typedef ssize_t (*srs_write_t)(int fildes, const void* buf, size_t nbyte);
typedef ssize_t (*srs_read_t)(int fildes, void* buf, size_t nbyte);
typedef off_t (*srs_lseek_t)(int fildes, off_t offset, int whence);
typedef int (*srs_close_t)(int fildes);
#endif

View file

@ -125,7 +125,7 @@ srs_utime_t srs_get_system_startup_time()
// For utest to mock it.
#ifndef SRS_OSX
_srs_gettimeofday_t _srs_gettimeofday = (_srs_gettimeofday_t)::gettimeofday;
srs_gettimeofday_t _srs_gettimeofday = (srs_gettimeofday_t)::gettimeofday;
#endif
srs_utime_t srs_update_system_time()

View file

@ -174,7 +174,7 @@ extern int srs_chunk_header_c3(int perfer_cid, uint32_t timestamp, char* cache,
#ifdef SRS_OSX
#define _srs_gettimeofday gettimeofday
#else
typedef int (*_srs_gettimeofday_t) (struct timeval* tv, struct timezone* tz);
typedef int (*srs_gettimeofday_t) (struct timeval* tv, struct timezone* tz);
#endif
#endif

View file

@ -77,6 +77,9 @@ SrsConfig* _srs_config = new SrsConfig();
// @global version of srs, which can grep keyword "XCORE"
extern const char* _srs_version;
// @global main SRS server, for debugging
SrsServer* _srs_server = NULL;
/**
* main entrance.
*/

View file

@ -33,7 +33,7 @@ using namespace std;
#include <srs_kernel_buffer.hpp>
#include <srs_protocol_json.hpp>
using namespace _srs_internal;
using namespace srs_internal;
// AMF0 marker
#define RTMP_AMF0_Number 0x00
@ -1703,7 +1703,7 @@ srs_error_t srs_amf0_write_undefined(SrsBuffer* stream)
return err;
}
namespace _srs_internal
namespace srs_internal
{
srs_error_t srs_amf0_read_utf8(SrsBuffer* stream, string& value)
{

View file

@ -36,7 +36,7 @@ class SrsAmf0StrictArray;
class SrsJsonAny;
// internal objects, user should never use it.
namespace _srs_internal
namespace srs_internal
{
class SrsUnSortedHashtable;
class SrsAmf0ObjectEOF;
@ -335,8 +335,8 @@ public:
class SrsAmf0Object : public SrsAmf0Any
{
private:
_srs_internal::SrsUnSortedHashtable* properties;
_srs_internal::SrsAmf0ObjectEOF* eof;
srs_internal::SrsUnSortedHashtable* properties;
srs_internal::SrsAmf0ObjectEOF* eof;
private:
friend class SrsAmf0Any;
/**
@ -425,8 +425,8 @@ public:
class SrsAmf0EcmaArray : public SrsAmf0Any
{
private:
_srs_internal::SrsUnSortedHashtable* properties;
_srs_internal::SrsAmf0ObjectEOF* eof;
srs_internal::SrsUnSortedHashtable* properties;
srs_internal::SrsAmf0ObjectEOF* eof;
int32_t _count;
private:
friend class SrsAmf0Any;
@ -626,7 +626,7 @@ extern srs_error_t srs_amf0_read_undefined(SrsBuffer* stream);
extern srs_error_t srs_amf0_write_undefined(SrsBuffer* stream);
// internal objects, user should never use it.
namespace _srs_internal
namespace srs_internal
{
/**
* read amf0 string from stream.

View file

@ -34,7 +34,7 @@
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_utility.hpp>
using namespace _srs_internal;
using namespace srs_internal;
// for openssl_HMACsha256
#include <openssl/evp.h>
@ -112,7 +112,7 @@ static int DH_set_length(DH *dh, long length)
#endif
namespace _srs_internal
namespace srs_internal
{
// 68bytes FMS key which is used to sign the sever packet.
uint8_t SrsGenuineFMSKey[] = {

View file

@ -40,7 +40,7 @@ extern HMAC_CTX *HMAC_CTX_new(void);
extern void HMAC_CTX_free(HMAC_CTX *ctx);
#endif
namespace _srs_internal
namespace srs_internal
{
// The digest key generate size.
#define SRS_OpensslHashSize 512

View file

@ -32,7 +32,7 @@ using namespace std;
#include <srs_core_autofree.hpp>
#include <srs_protocol_json.hpp>
#include <srs_kernel_buffer.hpp>
using namespace _srs_internal;
using namespace srs_internal;
/**
* main scenario to use amf0.

View file

@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define _MIN_OK_CONF "listen 1935; "
class MockSrsConfigBuffer : public _srs_internal::SrsConfigBuffer
class MockSrsConfigBuffer : public srs_internal::SrsConfigBuffer
{
public:
MockSrsConfigBuffer(std::string buf);

View file

@ -3713,11 +3713,11 @@ VOID TEST(KernelFileTest, FileWriteReader)
}
// Mock the system call hooks.
extern _srs_open_t _srs_open_fn;
extern _srs_write_t _srs_write_fn;
extern _srs_read_t _srs_read_fn;
extern _srs_lseek_t _srs_lseek_fn;
extern _srs_close_t _srs_close_fn;
extern srs_open_t _srs_open_fn;
extern srs_write_t _srs_write_fn;
extern srs_read_t _srs_read_fn;
extern srs_lseek_t _srs_lseek_fn;
extern srs_close_t _srs_close_fn;
int mock_open(const char* /*path*/, int /*oflag*/, ...) {
return -1;
@ -3742,13 +3742,13 @@ int mock_close(int /*fildes*/) {
class MockSystemIO
{
private:
_srs_open_t oo;
_srs_write_t ow;
_srs_read_t _or;
_srs_lseek_t os;
_srs_close_t oc;
srs_open_t oo;
srs_write_t ow;
srs_read_t _or;
srs_lseek_t os;
srs_close_t oc;
public:
MockSystemIO(_srs_open_t o = NULL, _srs_write_t w = NULL, _srs_read_t r = NULL, _srs_lseek_t s = NULL, _srs_close_t c = NULL) {
MockSystemIO(srs_open_t o = NULL, srs_write_t w = NULL, srs_read_t r = NULL, srs_lseek_t s = NULL, srs_close_t c = NULL) {
oo = _srs_open_fn;
ow = _srs_write_fn;
os = _srs_lseek_fn;
@ -4191,7 +4191,7 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll)
}
#ifndef SRS_OSX
extern _srs_gettimeofday_t _srs_gettimeofday;
extern srs_gettimeofday_t _srs_gettimeofday;
int mock_gettimeofday(struct timeval* /*tp*/, struct timezone* /*tzp*/) {
return -1;
}
@ -4199,9 +4199,9 @@ int mock_gettimeofday(struct timeval* /*tp*/, struct timezone* /*tzp*/) {
class MockTime
{
private:
_srs_gettimeofday_t ot;
srs_gettimeofday_t ot;
public:
MockTime(_srs_gettimeofday_t t = NULL) {
MockTime(srs_gettimeofday_t t = NULL) {
ot = _srs_gettimeofday;
if (t) {
_srs_gettimeofday = t;

View file

@ -352,7 +352,7 @@ VOID TEST(ProtocolHandshakeTest, OpensslSha256)
// verify the dh key
VOID TEST(ProtocolHandshakeTest, DHKey)
{
_srs_internal::SrsDH dh;
srs_internal::SrsDH dh;
ASSERT_TRUE(ERROR_SUCCESS == dh.initialize(true));
@ -368,7 +368,7 @@ VOID TEST(ProtocolHandshakeTest, DHKey)
EXPECT_TRUE(srs_bytes_equals(pub_key1, pub_key2, 128));
// another dh
_srs_internal::SrsDH dh0;
srs_internal::SrsDH dh0;
ASSERT_TRUE(ERROR_SUCCESS == dh0.initialize(true));

View file

@ -37,7 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_stream.hpp>
#include <srs_protocol_kbps.hpp>
using namespace _srs_internal;
using namespace srs_internal;
#include <srs_protocol_io.hpp>