srs中时间戳抖动处理
来源:互联网 发布:工业设计网站 知乎 编辑:程序博客网 时间:2024/05/22 16:55
http://blog.csdn.net/lcalqf/article/details/59543410
版权声明:本文为博主原创文章,未经博主允许不得转载。
-
-
-
-
-
-
- enum SrsRtmpJitterAlgorithm
- {
- SrsRtmpJitterAlgorithmFULL = 0x01,
- SrsRtmpJitterAlgorithmZERO,
- SrsRtmpJitterAlgorithmOFF
- };
- int _srs_time_jitter_string2int(std::string time_jitter);
-
-
-
-
-
- class SrsRtmpJitter
- {
- private:
- int64_t last_pkt_time;
- int64_t last_pkt_correct_time;
- public:
- SrsRtmpJitter();
- virtual ~SrsRtmpJitter();
- public:
-
-
-
-
-
-
-
- virtual int correct(SrsSharedPtrMessage* msg, int tba, int tbv, SrsRtmpJitterAlgorithm ag);
-
-
-
- virtual int get_time();
- };
超过抖动区域,置为默认值,都是相对时间
- #define CONST_MAX_JITTER_MS 250
- #define CONST_MAX_JITTER_MS_NEG -250
- #define DEFAULT_FRAME_TIME_MS 10
-
-
-
- #define SRS_PURE_AUDIO_GUESS_COUNT 115
-
-
- #define SRS_MIX_CORRECT_PURE_AV 10
-
-
- #define SRS_SOURCE_CLEANUP 30000
-
- int _srs_time_jitter_string2int(std::string time_jitter)
- {
- if (time_jitter == "full") {
- return SrsRtmpJitterAlgorithmFULL;
- } else if (time_jitter == "zero") {
- return SrsRtmpJitterAlgorithmZERO;
- } else {
- return SrsRtmpJitterAlgorithmOFF;
- }
- }
-
- SrsRtmpJitter::SrsRtmpJitter()
- {
- last_pkt_correct_time = -1;
- last_pkt_time = 0;
- }
-
- SrsRtmpJitter::~SrsRtmpJitter()
- {
- }
-
- int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, SrsRtmpJitterAlgorithm ag)
- {
- int ret = ERROR_SUCCESS;
-
-
- if (ag != SrsRtmpJitterAlgorithmFULL) {
-
- if (ag == SrsRtmpJitterAlgorithmOFF) {
- return ret;
- }
-
-
- if (ag == SrsRtmpJitterAlgorithmZERO) {
-
- if (last_pkt_correct_time == -1) {
- last_pkt_correct_time = msg->timestamp;
- }
- msg->timestamp -= last_pkt_correct_time;
- return ret;
- }
-
-
- return ret;
- }
-
-
-
- if (!msg->is_av()) {
- msg->timestamp = 0;
- return ret;
- }
-
-
-
-
-
-
-
-
-
-
-
- int64_t time = msg->timestamp;
- int64_t delta = time - last_pkt_time;
-
-
- if (delta < CONST_MAX_JITTER_MS_NEG || delta > CONST_MAX_JITTER_MS) {
-
-
- delta = DEFAULT_FRAME_TIME_MS;
-
- srs_info("jitter detected, last_pts=%"PRId64", pts=%"PRId64", diff=%"PRId64", last_time=%"PRId64", time=%"PRId64", diff=%"PRId64"",
- last_pkt_time, time, time - last_pkt_time, last_pkt_correct_time, last_pkt_correct_time + delta, delta);
- } else {
- srs_verbose("timestamp no jitter. time=%"PRId64", last_pkt=%"PRId64", correct_to=%"PRId64"",
- time, last_pkt_time, last_pkt_correct_time + delta);
- }
-
- last_pkt_correct_time = srs_max(0, last_pkt_correct_time + delta);
-
- msg->timestamp = last_pkt_correct_time;
- last_pkt_time = time;
-
- return ret;
- }
-
- int SrsRtmpJitter::get_time()
- {
- return (int)last_pkt_correct_time;
- }