mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine code, move the kbps to protocol
This commit is contained in:
parent
cfc0877ec9
commit
68d835021e
13 changed files with 89 additions and 89 deletions
|
@ -35,7 +35,10 @@ using namespace std;
|
|||
#include <srs_core_autofree.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
#include <srs_app_kbps.hpp>
|
||||
#include <srs_protocol_kbps.hpp>
|
||||
#include <srs_app_st.hpp>
|
||||
|
||||
#define _SRS_BANDWIDTH_LIMIT_INTERVAL_MS 100
|
||||
|
||||
// default sample duration, in ms
|
||||
#define _SRS_BANDWIDTH_SAMPLE_DURATION_MS 3000
|
||||
|
@ -475,3 +478,40 @@ int SrsBandwidth::finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& pu
|
|||
return ret;
|
||||
}
|
||||
|
||||
SrsKbpsLimit::SrsKbpsLimit(SrsKbps* kbps, int limit_kbps)
|
||||
{
|
||||
_kbps = kbps;
|
||||
_limit_kbps = limit_kbps;
|
||||
}
|
||||
|
||||
SrsKbpsLimit::~SrsKbpsLimit()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsKbpsLimit::limit_kbps()
|
||||
{
|
||||
return _limit_kbps;
|
||||
}
|
||||
|
||||
void SrsKbpsLimit::recv_limit()
|
||||
{
|
||||
_kbps->sample();
|
||||
|
||||
while (_kbps->get_recv_kbps() > _limit_kbps) {
|
||||
_kbps->sample();
|
||||
|
||||
st_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL_MS * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void SrsKbpsLimit::send_limit()
|
||||
{
|
||||
_kbps->sample();
|
||||
|
||||
while (_kbps->get_send_kbps() > _limit_kbps) {
|
||||
_kbps->sample();
|
||||
|
||||
st_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL_MS * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue