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

SmartPtr: Support shared ptr for live source. v6.0.129 (#4089)

Detail change log:

1. [Simple,Refactor] Remove member fields of http entry, etc.
e34b3d3aa4
2. [Ignore] Rename source to live_source.
846f95ec96
3. [Ignore] Use directly ptr in consumer.
d38af021ad
4. [Complex, Important] Use shared ptr for live source.
88f922413a

The object relationship:

![live-source](1adb59af-6e7a-40f3-9a4a-1cc849d7dae1)

---

Co-authored-by: Jacob Su <suzp1984@gmail.com>
This commit is contained in:
Winlin 2024-06-15 07:54:56 +08:00 committed by GitHub
parent 908c2f2a30
commit e7069788e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 256 additions and 235 deletions

View file

@ -19,6 +19,7 @@
#include <srs_protocol_st.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_stream_bridge.hpp>
#include <srs_core_autofree.hpp>
class SrsFormat;
class SrsRtmpFormat;
@ -168,9 +169,11 @@ public:
// The consumer for SrsLiveSource, that is a play client.
class SrsLiveConsumer : public ISrsWakable
{
private:
// Because source references to this object, so we should directly use the source ptr.
SrsLiveSource* source_;
private:
SrsRtmpJitter* jitter;
SrsLiveSource* source;
SrsMessageQueue* queue;
bool paused;
// when source id changed, notice all consumers
@ -288,9 +291,9 @@ public:
virtual ~ISrsLiveSourceHandler();
public:
// when stream start publish, mount stream.
virtual srs_error_t on_publish(SrsLiveSource* s, SrsRequest* r) = 0;
virtual srs_error_t on_publish(SrsRequest* r) = 0;
// when stream stop publish, unmount stream.
virtual void on_unpublish(SrsLiveSource* s, SrsRequest* r) = 0;
virtual void on_unpublish(SrsRequest* r) = 0;
};
// The mix queue to correct the timestamp for mix_correct algorithm.
@ -315,7 +318,9 @@ public:
class SrsOriginHub : public ISrsReloadHandler
{
private:
SrsLiveSource* source;
// Because source references to this object, so we should directly use the source ptr.
SrsLiveSource* source_;
private:
SrsRequest* req_;
bool is_active;
private:
@ -341,7 +346,7 @@ public:
public:
// Initialize the hub with source and request.
// @param r The request object, managed by source.
virtual srs_error_t initialize(SrsLiveSource* s, SrsRequest* r);
virtual srs_error_t initialize(SrsSharedPtr<SrsLiveSource> s, SrsRequest* r);
// Dispose the hub, release utilities resource,
// For example, delete all HLS pieces.
virtual void dispose();
@ -443,7 +448,7 @@ class SrsLiveSourceManager : public ISrsHourGlass
{
private:
srs_mutex_t lock;
std::map<std::string, SrsLiveSource*> pool;
std::map< std::string, SrsSharedPtr<SrsLiveSource> > pool;
SrsHourGlass* timer_;
public:
SrsLiveSourceManager();
@ -454,10 +459,10 @@ public:
// @param r the client request.
// @param h the event handler for source.
// @param pps the matched source, if success never be NULL.
virtual srs_error_t fetch_or_create(SrsRequest* r, ISrsLiveSourceHandler* h, SrsLiveSource** pps);
virtual srs_error_t fetch_or_create(SrsRequest* r, ISrsLiveSourceHandler* h, SrsSharedPtr<SrsLiveSource>& pps);
public:
// Get the exists source, NULL when not exists.
virtual SrsLiveSource* fetch(SrsRequest* r);
virtual SrsSharedPtr<SrsLiveSource> fetch(SrsRequest* r);
public:
// dispose and cycle all sources.
virtual void dispose();
@ -539,7 +544,7 @@ public:
bool publisher_is_idle_for(srs_utime_t timeout);
public:
// Initialize the hls with handlers.
virtual srs_error_t initialize(SrsRequest* r, ISrsLiveSourceHandler* h);
virtual srs_error_t initialize(SrsSharedPtr<SrsLiveSource> wrapper, SrsRequest* r, ISrsLiveSourceHandler* h);
// Bridge to other source, forward packets to it.
void set_bridge(ISrsStreamBridge* v);
// Interface ISrsReloadHandler