Skip to content

Commit

Permalink
Merge branch v5.0.115 into develop
Browse files Browse the repository at this point in the history
1. Asan: Support parse asan symbol backtrace log. v5.0.113 (#3324)
2. GB: Refine lazy object GC. v5.0.114 (#3321)
3. Fix #3328: Docker: Avoiding duplicated copy files. v5.0.115
  • Loading branch information
winlinvip committed Dec 24, 2022
2 parents 2daf637 + 5dcd663 commit e45563e
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 235 deletions.
7 changes: 7 additions & 0 deletions .run/gb28181.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="gb28181" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-c conf/gb28181.conf" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$CMakeCurrentBuildDir$/../../../" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>
10 changes: 1 addition & 9 deletions trunk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ WORKDIR /srs/trunk

# Build and install SRS.
# Note that SRT is enabled by default, so we configure without --srt=on.
# Note that we have copied all files by make install.
RUN ./configure --gb28181=on --h265=on --sanitizer-static=on && make && make install

# All config files for SRS.
RUN cp -R conf /usr/local/srs/conf && \
cp research/api-server/static-dir/index.html /usr/local/srs/objs/nginx/html/ && \
cp research/api-server/static-dir/favicon.ico /usr/local/srs/objs/nginx/html/ && \
cp research/players/crossdomain.xml /usr/local/srs/objs/nginx/html/ && \
cp -R research/console /usr/local/srs/objs/nginx/html/ && \
cp -R research/players /usr/local/srs/objs/nginx/html/ && \
cp -R 3rdparty/signaling/www/demos /usr/local/srs/objs/nginx/html/

############################################################
# dist
############################################################
Expand Down
3 changes: 3 additions & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The changelog for SRS.

## SRS 5.0 Changelog

* v5.0, 2022-12-24, Fix [#3328](https://github.com/ossrs/srs/issues/3328): Docker: Avoiding duplicated copy files. v5.0.115
* v5.0, 2022-12-20, Merge [#3321](https://github.com/ossrs/srs/pull/3321): GB: Refine lazy object GC. v5.0.114
* v5.0, 2022-12-18, Merge [#3324](https://github.com/ossrs/srs/pull/3324): Asan: Support parse asan symbol backtrace log. v5.0.113
* v5.0, 2022-12-17, Merge [#3323](https://github.com/ossrs/srs/pull/3323): SRT: Fix srt to rtmp crash when sps or pps empty. v5.0.112
* v5.0, 2022-12-15, For [#3300](https://github.com/ossrs/srs/issues/3300): GB28181: Fix memory overlap for small packets. v5.0.111
* v5.0, 2022-12-14, For [#939](https://github.com/ossrs/srs/issues/939): FLV: Support set default has_av and disable guessing. v5.0.110
Expand Down
89 changes: 50 additions & 39 deletions trunk/src/app/srs_app_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,69 @@ extern ISrsLazyGc* _srs_gc;

// A wrapper template for lazy-sweep resource.
// See https://github.com/ossrs/srs/issues/3176#lazy-sweep
//
// Usage for resource which manages itself in coroutine cycle, see SrsLazyGbSession:
// class Resource {
// private:
// SrsLazyObjectWrapper<Resource>* wrapper_;
// private:
// friend class SrsLazyObjectWrapper<Resource>;
// Resource(SrsLazyObjectWrapper<Resource>* wrapper) { wrapper_ = wrapper; }
// public:
// srs_error_t Resource::cycle() {
// srs_error_t err = do_cycle();
// _srs_gb_manager->remove(wrapper_);
// return err;
// }
// };
// SrsLazyObjectWrapper<Resource>* obj = new SrsLazyObjectWrapper<Resource>*();
// _srs_gb_manager->add(obj); // Add wrapper to resource manager.
// Start a coroutine to do obj->resource()->cycle().
//
// Usage for resource managed by other object:
// class Resource {
// private:
// friend class SrsLazyObjectWrapper<Resource>;
// Resource(SrsLazyObjectWrapper<Resource>* /*wrapper*/) {
// }
// };
// class Manager {
// private:
// SrsLazyObjectWrapper<Resource>* wrapper_;
// public:
// Manager() { wrapper_ = new SrsLazyObjectWrapper<Resource>(); }
// ~Manager() { srs_freep(wrapper_); }
// };
// Manager* manager = new Manager();
// srs_freep(manager);
//
// Note that under-layer resource are destroyed by _srs_gc, which is literally equal to srs_freep. However, the root
// wrapper might be managed by other resource manager, such as _srs_gb_manager for SrsLazyGbSession. Furthermore, other
// copied out wrappers might be freed by srs_freep. All are ok, because all wrapper and resources are simply normal
// object, so if you added to manager then you should use manager to remove it, and you can also directly delete it.
template<typename T>
class SrsLazyObjectWrapper : public ISrsResource
{
private:
T* resource_;
bool is_root_;
public:
SrsLazyObjectWrapper(T* resource = NULL, ISrsResource* wrapper = NULL) {
resource_ = resource ? resource : new T();
resource_->gc_use();

is_root_ = !resource;
if (!resource) {
resource_->gc_set_creator_wrapper(wrapper ? wrapper : this);
}
SrsLazyObjectWrapper() {
init(new T(this));
}
virtual ~SrsLazyObjectWrapper() {
resource_->gc_dispose();

if (is_root_) {
resource_->gc_set_creator_wrapper(NULL);
}

if (resource_->gc_ref() == 0) {
_srs_gc->remove(resource_);
}
}
private:
SrsLazyObjectWrapper(T* resource) {
init(resource);
}
void init(T* resource) {
resource_ = resource;
resource_->gc_use();
}
public:
SrsLazyObjectWrapper<T>* copy() {
return new SrsLazyObjectWrapper<T>(resource_);
Expand All @@ -183,31 +219,6 @@ class SrsLazyObjectWrapper : public ISrsResource
}
};

// Use macro to generate a wrapper class, because typedef will cause IDE incorrect tips.
// See https://github.com/ossrs/srs/issues/3176#lazy-sweep
#define SRS_LAZY_WRAPPER_GENERATOR(Resource, IWrapper, IResource) \
private: \
SrsLazyObjectWrapper<Resource> impl_; \
public: \
Resource##Wrapper(Resource* resource = NULL) : impl_(resource, this) { \
} \
virtual ~Resource##Wrapper() { \
} \
public: \
IWrapper* copy() { \
return new Resource##Wrapper(impl_.resource()); \
} \
IResource* resource() { \
return impl_.resource(); \
} \
public: \
virtual const SrsContextId& get_id() { \
return impl_.get_id(); \
} \
virtual std::string desc() { \
return impl_.desc(); \
} \

// If a connection is able be expired, user can use HTTP-API to kick-off it.
class ISrsExpire
{
Expand Down
77 changes: 24 additions & 53 deletions trunk/src/app/srs_app_gb28181.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,11 @@ std::string srs_sip_state(SrsGbSipState ostate, SrsGbSipState state)
return srs_fmt("%s->%s", srs_gb_sip_state(ostate).c_str(), srs_gb_sip_state(state).c_str());
}

ISrsGbSipConn::ISrsGbSipConn()
SrsLazyGbSession::SrsLazyGbSession(SrsLazyObjectWrapper<SrsLazyGbSession>* wrapper_root)
{
}

ISrsGbSipConn::~ISrsGbSipConn()
{
}

ISrsGbSipConnWrapper::ISrsGbSipConnWrapper()
{
}

ISrsGbSipConnWrapper::~ISrsGbSipConnWrapper()
{
}

ISrsGbMediaConn::ISrsGbMediaConn()
{
}

ISrsGbMediaConn::~ISrsGbMediaConn()
{
}

ISrsGbMediaConnWrapper::ISrsGbMediaConnWrapper()
{
}

ISrsGbMediaConnWrapper::~ISrsGbMediaConnWrapper()
{
}

SrsLazyGbSession::SrsLazyGbSession()
{
sip_ = new ISrsGbSipConnWrapper();
media_ = new ISrsGbMediaConnWrapper();
wrapper_root_ = wrapper_root;
sip_ = new SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>();
media_ = new SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>();
muxer_ = new SrsGbMuxer(this);
state_ = SrsGbSessionStateInit;

Expand Down Expand Up @@ -225,7 +194,7 @@ void SrsLazyGbSession::on_ps_pack(SrsPackContext* ctx, SrsPsPacket* ps, const st
}
}

void SrsLazyGbSession::on_sip_transport(ISrsGbSipConnWrapper* sip)
void SrsLazyGbSession::on_sip_transport(SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>* sip)
{
srs_freep(sip_);
sip_ = sip->copy();
Expand All @@ -234,12 +203,12 @@ void SrsLazyGbSession::on_sip_transport(ISrsGbSipConnWrapper* sip)
sip_->resource()->set_cid(cid_);
}

ISrsGbSipConnWrapper* SrsLazyGbSession::sip_transport()
SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>* SrsLazyGbSession::sip_transport()
{
return sip_;
}

void SrsLazyGbSession::on_media_transport(ISrsGbMediaConnWrapper* media)
void SrsLazyGbSession::on_media_transport(SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>* media)
{
srs_freep(media_);
media_ = media->copy();
Expand Down Expand Up @@ -273,7 +242,7 @@ srs_error_t SrsLazyGbSession::cycle()
media_->resource()->interrupt();

// Note that we added wrapper to manager, so we must free the wrapper, not this connection.
SrsLazyGbSessionWrapper* wrapper = dynamic_cast<SrsLazyGbSessionWrapper*>(gc_creator_wrapper());
SrsLazyObjectWrapper<SrsLazyGbSession>* wrapper = wrapper_root_;
srs_assert(wrapper); // The creator wrapper MUST never be null, because we created it.
_srs_gb_manager->remove(wrapper);

Expand Down Expand Up @@ -366,7 +335,7 @@ srs_error_t SrsLazyGbSession::drive_state()
}

// Now, we're able to query session by ssrc, for media packets.
SrsLazyGbSessionWrapper* wrapper = dynamic_cast<SrsLazyGbSessionWrapper*>(gc_creator_wrapper());
SrsLazyObjectWrapper<SrsLazyGbSession>* wrapper = wrapper_root_;
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine.
_srs_gb_manager->add_with_fast_id(ssrc, wrapper);
}
Expand Down Expand Up @@ -493,7 +462,7 @@ srs_error_t SrsGbListener::on_tcp_client(ISrsListener* listener, srs_netfd_t stf

// Handle TCP connections.
if (listener == sip_listener_) {
SrsLazyGbSipTcpConnWrapper* conn = new SrsLazyGbSipTcpConnWrapper();
SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>* conn = new SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>();
SrsLazyGbSipTcpConn* resource = dynamic_cast<SrsLazyGbSipTcpConn*>(conn->resource());
resource->setup(conf_, sip_listener_, media_listener_, stfd);

Expand All @@ -504,7 +473,7 @@ srs_error_t SrsGbListener::on_tcp_client(ISrsListener* listener, srs_netfd_t stf

_srs_gb_manager->add(conn, NULL);
} else if (listener == media_listener_) {
SrsLazyGbMediaTcpConnWrapper* conn = new SrsLazyGbMediaTcpConnWrapper();
SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>* conn = new SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>();
SrsLazyGbMediaTcpConn* resource = dynamic_cast<SrsLazyGbMediaTcpConn*>(conn->resource());
resource->setup(stfd);

Expand All @@ -522,8 +491,9 @@ srs_error_t SrsGbListener::on_tcp_client(ISrsListener* listener, srs_netfd_t stf
return err;
}

SrsLazyGbSipTcpConn::SrsLazyGbSipTcpConn()
SrsLazyGbSipTcpConn::SrsLazyGbSipTcpConn(SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>* wrapper_root)
{
wrapper_root_ = wrapper_root;
session_ = NULL;
state_ = SrsGbSipStateInit;
register_ = new SrsSipMessage();
Expand Down Expand Up @@ -940,7 +910,7 @@ srs_error_t SrsLazyGbSipTcpConn::cycle()
sender_->interrupt();

// Note that we added wrapper to manager, so we must free the wrapper, not this connection.
SrsLazyGbSipTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbSipTcpConnWrapper*>(gc_creator_wrapper());
SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>* wrapper = wrapper_root_;
srs_assert(wrapper); // The creator wrapper MUST never be null, because we created it.
_srs_gb_manager->remove(wrapper);

Expand Down Expand Up @@ -987,7 +957,7 @@ srs_error_t SrsLazyGbSipTcpConn::do_cycle()
return err;
}

srs_error_t SrsLazyGbSipTcpConn::bind_session(SrsSipMessage* msg, SrsLazyGbSessionWrapper** psession)
srs_error_t SrsLazyGbSipTcpConn::bind_session(SrsSipMessage* msg, SrsLazyObjectWrapper<SrsLazyGbSession>** psession)
{
srs_error_t err = srs_success;

Expand All @@ -998,14 +968,14 @@ srs_error_t SrsLazyGbSipTcpConn::bind_session(SrsSipMessage* msg, SrsLazyGbSessi
if (msg->type_ != HTTP_REQUEST || msg->method_ != HTTP_REGISTER) return err;

// The lazy-sweep wrapper for this resource.
SrsLazyGbSipTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbSipTcpConnWrapper*>(gc_creator_wrapper());
SrsLazyObjectWrapper<SrsLazyGbSipTcpConn>* wrapper = wrapper_root_;
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine of receiver.

// Find exists session for register, might be created by another object and still alive.
SrsLazyGbSessionWrapper* session = dynamic_cast<SrsLazyGbSessionWrapper*>(_srs_gb_manager->find_by_id(device));
SrsLazyObjectWrapper<SrsLazyGbSession>* session = dynamic_cast<SrsLazyObjectWrapper<SrsLazyGbSession>*>(_srs_gb_manager->find_by_id(device));
if (!session) {
// Create new GB session.
session = new SrsLazyGbSessionWrapper();
session = new SrsLazyObjectWrapper<SrsLazyGbSession>();

if ((err = session->resource()->initialize(conf_)) != srs_success) {
srs_freep(session);
Expand Down Expand Up @@ -1248,8 +1218,9 @@ ISrsPsPackHandler::~ISrsPsPackHandler()
{
}

SrsLazyGbMediaTcpConn::SrsLazyGbMediaTcpConn()
SrsLazyGbMediaTcpConn::SrsLazyGbMediaTcpConn(SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>* wrapper_root)
{
wrapper_root_ = wrapper_root;
pack_ = new SrsPackContext(this);
trd_ = new SrsSTCoroutine("media", this);
buffer_ = new uint8_t[65535];
Expand Down Expand Up @@ -1324,7 +1295,7 @@ srs_error_t SrsLazyGbMediaTcpConn::cycle()
srs_trace("PS: Media disconnect, code=%d", srs_error_code(err));

// Note that we added wrapper to manager, so we must free the wrapper, not this connection.
SrsLazyGbMediaTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbMediaTcpConnWrapper*>(gc_creator_wrapper());
SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>* wrapper = wrapper_root_;
srs_assert(wrapper); // The creator wrapper MUST never be null, because we created it.
_srs_gb_manager->remove(wrapper);

Expand Down Expand Up @@ -1478,18 +1449,18 @@ srs_error_t SrsLazyGbMediaTcpConn::on_ps_pack(SrsPsPacket* ps, const std::vector
return err;
}

srs_error_t SrsLazyGbMediaTcpConn::bind_session(uint32_t ssrc, SrsLazyGbSessionWrapper** psession)
srs_error_t SrsLazyGbMediaTcpConn::bind_session(uint32_t ssrc, SrsLazyObjectWrapper<SrsLazyGbSession>** psession)
{
srs_error_t err = srs_success;

if (!ssrc) return err;

// The lazy-sweep wrapper for this resource.
SrsLazyGbMediaTcpConnWrapper* wrapper = dynamic_cast<SrsLazyGbMediaTcpConnWrapper*>(gc_creator_wrapper());
SrsLazyObjectWrapper<SrsLazyGbMediaTcpConn>* wrapper = wrapper_root_;
srs_assert(wrapper); // It MUST never be NULL, because this method is in the cycle of coroutine.

// Find exists session for register, might be created by another object and still alive.
SrsLazyGbSessionWrapper* session = dynamic_cast<SrsLazyGbSessionWrapper*>(_srs_gb_manager->find_by_fast_id(ssrc));
SrsLazyObjectWrapper<SrsLazyGbSession>* session = dynamic_cast<SrsLazyObjectWrapper<SrsLazyGbSession>*>(_srs_gb_manager->find_by_fast_id(ssrc));
if (!session) return err;

_srs_gb_manager->add_with_fast_id(ssrc, session);
Expand Down
Loading

0 comments on commit e45563e

Please sign in to comment.