mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix bug #67: fix pithy print bug, stage must has a age
This commit is contained in:
parent
b175821b62
commit
cbbf53f8f9
3 changed files with 104 additions and 72 deletions
|
@ -34,27 +34,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#define SRS_STAGE_DEFAULT_INTERVAL_MS 1200
|
||||
|
||||
struct SrsStageInfo : public ISrsReloadHandler
|
||||
SrsStageInfo::SrsStageInfo(int _stage_id)
|
||||
{
|
||||
int stage_id;
|
||||
int pithy_print_time_ms;
|
||||
int nb_clients;
|
||||
|
||||
SrsStageInfo(int _stage_id)
|
||||
{
|
||||
stage_id = _stage_id;
|
||||
nb_clients = 0;
|
||||
_age = printed_age = 0;
|
||||
|
||||
update_print_time();
|
||||
|
||||
_srs_config->subscribe(this);
|
||||
}
|
||||
virtual ~SrsStageInfo()
|
||||
{
|
||||
}
|
||||
|
||||
SrsStageInfo::~SrsStageInfo()
|
||||
{
|
||||
_srs_config->unsubscribe(this);
|
||||
}
|
||||
void update_print_time()
|
||||
{
|
||||
}
|
||||
|
||||
void SrsStageInfo::update_print_time()
|
||||
{
|
||||
switch (stage_id) {
|
||||
case SRS_STAGE_PLAY_USER: {
|
||||
pithy_print_time_ms = _srs_config->get_pithy_print_play();
|
||||
|
@ -89,14 +86,31 @@ struct SrsStageInfo : public ISrsReloadHandler
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SrsStageInfo::elapse(int64_t diff)
|
||||
{
|
||||
_age += diff;
|
||||
}
|
||||
|
||||
bool SrsStageInfo::can_print()
|
||||
{
|
||||
int64_t can_print_age = nb_clients * pithy_print_time_ms;
|
||||
|
||||
bool can_print = _age >= can_print_age;
|
||||
if (can_print) {
|
||||
_age = 0;
|
||||
}
|
||||
public:
|
||||
virtual int on_reload_pithy_print()
|
||||
{
|
||||
|
||||
return can_print;
|
||||
}
|
||||
|
||||
int SrsStageInfo::on_reload_pithy_print()
|
||||
{
|
||||
update_print_time();
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static std::map<int, SrsStageInfo*> _srs_stages;
|
||||
|
||||
SrsPithyPrint::SrsPithyPrint(int _stage_id)
|
||||
|
@ -104,7 +118,7 @@ SrsPithyPrint::SrsPithyPrint(int _stage_id)
|
|||
stage_id = _stage_id;
|
||||
client_id = enter_stage();
|
||||
previous_tick = srs_get_system_time_ms();
|
||||
printed_age = _age = 0;
|
||||
_age = 0;
|
||||
}
|
||||
|
||||
SrsPithyPrint::~SrsPithyPrint()
|
||||
|
@ -146,9 +160,14 @@ void SrsPithyPrint::leave_stage()
|
|||
|
||||
void SrsPithyPrint::elapse()
|
||||
{
|
||||
int64_t diff = srs_get_system_time_ms() - previous_tick;
|
||||
SrsStageInfo* stage = _srs_stages[stage_id];
|
||||
srs_assert(stage != NULL);
|
||||
|
||||
_age += srs_max(0, diff);
|
||||
int64_t diff = srs_get_system_time_ms() - previous_tick;
|
||||
diff = srs_max(0, diff);
|
||||
|
||||
stage->elapse(diff);
|
||||
_age += diff;
|
||||
previous_tick = srs_get_system_time_ms();
|
||||
}
|
||||
|
||||
|
@ -157,15 +176,7 @@ bool SrsPithyPrint::can_print()
|
|||
SrsStageInfo* stage = _srs_stages[stage_id];
|
||||
srs_assert(stage != NULL);
|
||||
|
||||
int64_t alive_age = _age - printed_age;
|
||||
int64_t can_print_age = stage->nb_clients * stage->pithy_print_time_ms;
|
||||
|
||||
bool can_print = alive_age >= can_print_age;
|
||||
if (can_print) {
|
||||
printed_age = _age;
|
||||
}
|
||||
|
||||
return can_print;
|
||||
return stage->can_print();
|
||||
}
|
||||
|
||||
int64_t SrsPithyPrint::age()
|
||||
|
|
|
@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <srs_app_reload.hpp>
|
||||
|
||||
// the pithy stage for all play clients.
|
||||
#define SRS_STAGE_PLAY_USER 1
|
||||
// the pithy stage for all publish clients.
|
||||
|
@ -45,6 +47,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// the pithy stage for all edge.
|
||||
#define SRS_STAGE_EDGE 7
|
||||
|
||||
class SrsStageInfo : public ISrsReloadHandler
|
||||
{
|
||||
public:
|
||||
int stage_id;
|
||||
int pithy_print_time_ms;
|
||||
int nb_clients;
|
||||
public:
|
||||
int64_t _age;
|
||||
int64_t printed_age;
|
||||
public:
|
||||
SrsStageInfo(int _stage_id);
|
||||
virtual ~SrsStageInfo();
|
||||
virtual void update_print_time();
|
||||
public:
|
||||
virtual void elapse(int64_t diff);
|
||||
virtual bool can_print();
|
||||
public:
|
||||
virtual int on_reload_pithy_print();
|
||||
};
|
||||
|
||||
/**
|
||||
* the stage is used for a collection of object to do print,
|
||||
* the print time in a stage is constant and not changed.
|
||||
|
@ -58,7 +80,6 @@ private:
|
|||
int stage_id;
|
||||
// in ms.
|
||||
int64_t _age;
|
||||
int64_t printed_age;
|
||||
int64_t previous_tick;
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// current release version
|
||||
#define VERSION_MAJOR "0"
|
||||
#define VERSION_MINOR "9"
|
||||
#define VERSION_REVISION "97"
|
||||
#define VERSION_REVISION "98"
|
||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "srs"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue