1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-12 19:31:53 +00:00

refine code, move the kbps to protocol

This commit is contained in:
winlin 2015-05-23 09:58:00 +08:00
parent cfc0877ec9
commit 68d835021e
13 changed files with 89 additions and 89 deletions

4
trunk/configure vendored
View file

@ -159,7 +159,7 @@ MODULE_DEPENDS=("CORE" "KERNEL")
ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot})
MODULE_FILES=("srs_rtmp_amf0" "srs_rtmp_io" "srs_rtmp_stack" "srs_rtmp_sdk"
"srs_rtmp_handshake" "srs_rtmp_utility" "srs_rtmp_msg_array" "srs_rtmp_buffer"
"srs_raw_avc" "srs_rtsp_stack" "srs_http_stack")
"srs_raw_avc" "srs_rtsp_stack" "srs_http_stack" "srs_protocol_kbps")
RTMP_INCS="src/protocol"; MODULE_DIR=${RTMP_INCS} . auto/modules.sh
RTMP_OBJS="${MODULE_OBJS[@]}"
#
@ -173,7 +173,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
"srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
"srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic" "srs_app_hds"
"srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener" "srs_app_async_call"
"srs_app_caster_flv")

View file

@ -48,6 +48,8 @@ file
protocol readonly separator,
../../src/protocol/srs_http_stack.hpp,
../../src/protocol/srs_http_stack.cpp,
../../src/protocol/srs_protocol_kbps.hpp,
../../src/protocol/srs_protocol_kbps.cpp,
../../src/protocol/srs_raw_avc.hpp,
../../src/protocol/srs_raw_avc.cpp,
../../src/protocol/srs_rtmp_amf0.hpp,
@ -105,8 +107,6 @@ file
../../src/app/srs_app_ingest.cpp,
../../src/app/srs_app_json.hpp,
../../src/app/srs_app_json.cpp,
../../src/app/srs_app_kbps.hpp,
../../src/app/srs_app_kbps.cpp,
../../src/app/srs_app_listener.hpp,
../../src/app/srs_app_listener.cpp,
../../src/app/srs_app_log.hpp,

View file

@ -80,7 +80,6 @@
<ClInclude Include="..\..\src\app\srs_app_http_hooks.hpp" />
<ClInclude Include="..\..\src\app\srs_app_ingest.hpp" />
<ClInclude Include="..\..\src\app\srs_app_json.hpp" />
<ClInclude Include="..\..\src\app\srs_app_kbps.hpp" />
<ClInclude Include="..\..\src\app\srs_app_listener.hpp" />
<ClInclude Include="..\..\src\app\srs_app_log.hpp" />
<ClInclude Include="..\..\src\app\srs_app_mpegts_udp.hpp" />
@ -129,6 +128,7 @@
<ClInclude Include="..\..\src\protocol\srs_rtmp_stack.hpp" />
<ClInclude Include="..\..\src\protocol\srs_rtmp_utility.hpp" />
<ClInclude Include="..\..\src\protocol\srs_rtsp_stack.hpp" />
<ClInclude Include="..\..\src\protocol\srs_protocol_kbps.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\research\hls\ts_info.cc" />
@ -161,7 +161,6 @@
<ClCompile Include="..\..\src\app\srs_app_http_hooks.cpp" />
<ClCompile Include="..\..\src\app\srs_app_ingest.cpp" />
<ClCompile Include="..\..\src\app\srs_app_json.cpp" />
<ClCompile Include="..\..\src\app\srs_app_kbps.cpp" />
<ClCompile Include="..\..\src\app\srs_app_listener.cpp" />
<ClCompile Include="..\..\src\app\srs_app_log.cpp" />
<ClCompile Include="..\..\src\app\srs_app_mpegts_udp.cpp" />
@ -211,6 +210,7 @@
<ClCompile Include="..\..\src\protocol\srs_rtmp_stack.cpp" />
<ClCompile Include="..\..\src\protocol\srs_rtmp_utility.cpp" />
<ClCompile Include="..\..\src\protocol\srs_rtsp_stack.cpp" />
<ClCompile Include="..\..\src\protocol\srs_protocol_kbps.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
3C068D6A1B10149F00AA722C /* srs_protocol_kbps.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C068D681B10149F00AA722C /* srs_protocol_kbps.cpp */; };
3C0E1B8D1B0F5ADF003ADEF7 /* srs_http_stack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C0E1B8B1B0F5ADF003ADEF7 /* srs_http_stack.cpp */; };
3C1231F61AAE652D00CE8F6C /* srs_core_autofree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1231F01AAE652C00CE8F6C /* srs_core_autofree.cpp */; };
3C1231F71AAE652D00CE8F6C /* srs_core_performance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1231F21AAE652C00CE8F6C /* srs_core_performance.cpp */; };
@ -51,7 +52,6 @@
3C1232A21AAE81D900CE8F6C /* srs_app_http_hooks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232681AAE81D900CE8F6C /* srs_app_http_hooks.cpp */; };
3C1232A41AAE81D900CE8F6C /* srs_app_ingest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C12326C1AAE81D900CE8F6C /* srs_app_ingest.cpp */; };
3C1232A51AAE81D900CE8F6C /* srs_app_json.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C12326E1AAE81D900CE8F6C /* srs_app_json.cpp */; };
3C1232A61AAE81D900CE8F6C /* srs_app_kbps.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232701AAE81D900CE8F6C /* srs_app_kbps.cpp */; };
3C1232A71AAE81D900CE8F6C /* srs_app_listener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232721AAE81D900CE8F6C /* srs_app_listener.cpp */; };
3C1232A81AAE81D900CE8F6C /* srs_app_log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232741AAE81D900CE8F6C /* srs_app_log.cpp */; };
3C1232A91AAE81D900CE8F6C /* srs_app_mpegts_udp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C1232761AAE81D900CE8F6C /* srs_app_mpegts_udp.cpp */; };
@ -122,6 +122,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
3C068D681B10149F00AA722C /* srs_protocol_kbps.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_protocol_kbps.cpp; path = ../../../src/protocol/srs_protocol_kbps.cpp; sourceTree = "<group>"; };
3C068D691B10149F00AA722C /* srs_protocol_kbps.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_protocol_kbps.hpp; path = ../../../src/protocol/srs_protocol_kbps.hpp; sourceTree = "<group>"; };
3C0E1B8B1B0F5ADF003ADEF7 /* srs_http_stack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_http_stack.cpp; path = ../../../src/protocol/srs_http_stack.cpp; sourceTree = "<group>"; };
3C0E1B8C1B0F5ADF003ADEF7 /* srs_http_stack.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_http_stack.hpp; path = ../../../src/protocol/srs_http_stack.hpp; sourceTree = "<group>"; };
3C1231E51AAE64A400CE8F6C /* srs_xcode */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = srs_xcode; sourceTree = BUILT_PRODUCTS_DIR; };
@ -211,8 +213,6 @@
3C12326D1AAE81D900CE8F6C /* srs_app_ingest.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_ingest.hpp; path = ../../../src/app/srs_app_ingest.hpp; sourceTree = "<group>"; };
3C12326E1AAE81D900CE8F6C /* srs_app_json.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_json.cpp; path = ../../../src/app/srs_app_json.cpp; sourceTree = "<group>"; };
3C12326F1AAE81D900CE8F6C /* srs_app_json.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_json.hpp; path = ../../../src/app/srs_app_json.hpp; sourceTree = "<group>"; };
3C1232701AAE81D900CE8F6C /* srs_app_kbps.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_kbps.cpp; path = ../../../src/app/srs_app_kbps.cpp; sourceTree = "<group>"; };
3C1232711AAE81D900CE8F6C /* srs_app_kbps.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_kbps.hpp; path = ../../../src/app/srs_app_kbps.hpp; sourceTree = "<group>"; };
3C1232721AAE81D900CE8F6C /* srs_app_listener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_listener.cpp; path = ../../../src/app/srs_app_listener.cpp; sourceTree = "<group>"; };
3C1232731AAE81D900CE8F6C /* srs_app_listener.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_listener.hpp; path = ../../../src/app/srs_app_listener.hpp; sourceTree = "<group>"; };
3C1232741AAE81D900CE8F6C /* srs_app_log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_log.cpp; path = ../../../src/app/srs_app_log.cpp; sourceTree = "<group>"; };
@ -489,6 +489,8 @@
children = (
3C0E1B8B1B0F5ADF003ADEF7 /* srs_http_stack.cpp */,
3C0E1B8C1B0F5ADF003ADEF7 /* srs_http_stack.hpp */,
3C068D681B10149F00AA722C /* srs_protocol_kbps.cpp */,
3C068D691B10149F00AA722C /* srs_protocol_kbps.hpp */,
3C12322D1AAE81A400CE8F6C /* srs_raw_avc.cpp */,
3C12322E1AAE81A400CE8F6C /* srs_raw_avc.hpp */,
3C12322F1AAE81A400CE8F6C /* srs_rtmp_amf0.cpp */,
@ -556,8 +558,6 @@
3C12326D1AAE81D900CE8F6C /* srs_app_ingest.hpp */,
3C12326E1AAE81D900CE8F6C /* srs_app_json.cpp */,
3C12326F1AAE81D900CE8F6C /* srs_app_json.hpp */,
3C1232701AAE81D900CE8F6C /* srs_app_kbps.cpp */,
3C1232711AAE81D900CE8F6C /* srs_app_kbps.hpp */,
3C1232721AAE81D900CE8F6C /* srs_app_listener.cpp */,
3C1232731AAE81D900CE8F6C /* srs_app_listener.hpp */,
3C1232741AAE81D900CE8F6C /* srs_app_log.cpp */,
@ -931,12 +931,12 @@
3C1232211AAE814D00CE8F6C /* srs_kernel_buffer.cpp in Sources */,
3C1232471AAE81A400CE8F6C /* srs_rtmp_sdk.cpp in Sources */,
3C36DB5B1ABD1CB90066CCAF /* srs_lib_bandwidth.cpp in Sources */,
3C1232A61AAE81D900CE8F6C /* srs_app_kbps.cpp in Sources */,
3C12329D1AAE81D900CE8F6C /* srs_app_heartbeat.cpp in Sources */,
3C1232231AAE814D00CE8F6C /* srs_kernel_consts.cpp in Sources */,
3C1232AF1AAE81D900CE8F6C /* srs_app_rtsp.cpp in Sources */,
3CC52DDD1ACE4023006FEB01 /* srs_utest_reload.cpp in Sources */,
3C689FA11AB6AAC800C9CEEE /* sync.c in Sources */,
3C068D6A1B10149F00AA722C /* srs_protocol_kbps.cpp in Sources */,
3C12329A1AAE81D900CE8F6C /* srs_app_encoder.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View file

@ -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);
}
}

View file

@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_st.hpp>
class SrsKbps;
class SrsRequest;
class SrsRtmpServer;
class SrsKbpsLimit;
@ -199,4 +200,30 @@ private:
virtual int finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time);
};
/**
* the kbps limit, if exceed the kbps, slow down.
*/
class SrsKbpsLimit
{
private:
int _limit_kbps;
SrsKbps* _kbps;
public:
SrsKbpsLimit(SrsKbps* kbps, int limit_kbps);
virtual ~SrsKbpsLimit();
public:
/**
* get the system limit kbps.
*/
virtual int limit_kbps();
/**
* limit the recv bandwidth.
*/
virtual void recv_limit();
/**
* limit the send bandwidth.
*/
virtual void send_limit();
};
#endif

View file

@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_st.hpp>
#include <srs_app_thread.hpp>
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
class SrsConnection;

View file

@ -39,7 +39,7 @@ using namespace std;
#include <srs_app_source.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_core_autofree.hpp>
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_rtmp_msg_array.hpp>
#include <srs_app_utility.hpp>
#include <srs_rtmp_amf0.hpp>

View file

@ -38,7 +38,7 @@ using namespace std;
#include <srs_app_pithy_print.hpp>
#include <srs_rtmp_sdk.hpp>
#include <srs_rtmp_utility.hpp>
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_rtmp_msg_array.hpp>
#include <srs_app_utility.hpp>
#include <srs_rtmp_amf0.hpp>

View file

@ -29,7 +29,7 @@ using namespace std;
#include <srs_rtmp_sdk.hpp>
#include <srs_app_json.hpp>
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp>

View file

@ -39,7 +39,7 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_app_json.hpp>
#include <srs_kernel_stream.hpp>

View file

@ -21,12 +21,9 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_st.hpp>
#define _SRS_BANDWIDTH_LIMIT_INTERVAL_MS 100
SrsKbpsSample::SrsKbpsSample()
{
@ -253,41 +250,3 @@ void SrsKbps::sample()
os.sample();
}
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);
}
}

View file

@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_APP_KBPS_HPP
#define SRS_APP_KBPS_HPP
#ifndef SRS_PROTOCOL_KBPS_HPP
#define SRS_PROTOCOL_KBPS_HPP
/*
#include <srs_app_kbps.hpp>
#include <srs_protocol_kbps.hpp>
*/
#include <srs_core.hpp>
@ -234,30 +234,4 @@ public:
virtual void sample();
};
/**
* the kbps limit, if exceed the kbps, slow down.
*/
class SrsKbpsLimit
{
private:
int _limit_kbps;
SrsKbps* _kbps;
public:
SrsKbpsLimit(SrsKbps* kbps, int limit_kbps);
virtual ~SrsKbpsLimit();
public:
/**
* get the system limit kbps.
*/
virtual int limit_kbps();
/**
* limit the recv bandwidth.
*/
virtual void recv_limit();
/**
* limit the send bandwidth.
*/
virtual void send_limit();
};
#endif