Repository: ossrs/srs
File: trunk/src/app/srs_app_source.hpp (C++)

Code before:
    virtual srs_error_t update_ash(SrsSharedPtrMessage* msg);
    // Update the cached video sequence header.
    virtual srs_error_t update_vsh(SrsSharedPtrMessage* msg);
};

// The source manager to create and refresh all stream sources.
class SrsLiveSourceManager : public ISrsHourGlass
{
private:
    srs_mutex_t lock;
    std::map<std::string, SrsLiveSource*> pool;
    SrsHourGlass* timer_;
public:
    SrsLiveSourceManager();
    virtual ~SrsLiveSourceManager();
public:
    virtual srs_error_t initialize();
    //  create source when fetch from cache failed.
    // @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);
public:
    // Get the exists source, NULL when not exists.
    // update the request and return the exists source.
    virtual SrsLiveSource* fetch(SrsRequest* r, bool update = true);
public:
    // dispose and cycle all sources.
    virtual void dispose();
// interface ISrsHourGlass
private:
    virtual srs_error_t setup_ticks();
    virtual srs_error_t notify(int event, srs_utime_t interval, srs_utime_t tick);
public:
    // when system exit, destroy th`e sources,
    // For gmc to analysis mem leaks.
    virtual void destroy();
};

// Global singleton instance.
extern SrsLiveSourceManager* _srs_sources;

// For RTMP2RTC, bridge SrsLiveSource to SrsRtcSource
class ISrsLiveSourceBridger
{
public:
    ISrsLiveSourceBridger();
    virtual ~ISrsLiveSourceBridger();
public:
    virtual srs_error_t on_publish() = 0;
    virtual srs_error_t on_audio(SrsSharedPtrMessage* audio) = 0;

Review comment (suggestion):
This modification is the simplest, but it lacks maintainability and does not solve the fundamental problem.

```
Functions like fetch, which are similar to get, can never update.
```

Adding a parameter cannot solve this problem. Therefore, the fetch function should be separated into an API.

`TRANS_BY_GPT3`

Code after:
    virtual srs_error_t update_ash(SrsSharedPtrMessage* msg);
    // Update the cached video sequence header.
    virtual srs_error_t update_vsh(SrsSharedPtrMessage* msg);
};

// The source manager to create and refresh all stream sources.
class SrsLiveSourceManager : public ISrsHourGlass
{
private:
    srs_mutex_t lock;
    std::map<std::string, SrsLiveSource*> pool;
    SrsHourGlass* timer_;
public:
    SrsLiveSourceManager();
    virtual ~SrsLiveSourceManager();
public:
    virtual srs_error_t initialize();
    //  create source when fetch from cache failed.
    // @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);
public:
    // Get the exists source, NULL when not exists.
    virtual SrsLiveSource* fetch(SrsRequest* r);
public:
    // dispose and cycle all sources.
    virtual void dispose();
// interface ISrsHourGlass
private:
    virtual srs_error_t setup_ticks();
    virtual srs_error_t notify(int event, srs_utime_t interval, srs_utime_t tick);
public:
    // when system exit, destroy th`e sources,
    // For gmc to analysis mem leaks.
    virtual void destroy();
};

// Global singleton instance.
extern SrsLiveSourceManager* _srs_sources;

// For RTMP2RTC, bridge SrsLiveSource to SrsRtcSource
class ISrsLiveSourceBridger
{
public:
    ISrsLiveSourceBridger();
    virtual ~ISrsLiveSourceBridger();
public:
    virtual srs_error_t on_publish() = 0;
    virtual srs_error_t on_audio(SrsSharedPtrMessage* audio) = 0;
    virtual srs_error_t on_video(SrsSharedPtrMessage* video) = 0;