srs中时间戳抖动处理
来源:互联网 发布:随州seo排名 编辑:程序博客网 时间:2024/05/29 15:15
/*** the time jitter algorithm:* 1. full, to ensure stream start at zero, and ensure stream monotonically increasing.* 2. zero, only ensure sttream start at zero, ignore timestamp jitter.* 3. off, disable the time jitter algorithm, like atc.*/enum SrsRtmpJitterAlgorithm{ SrsRtmpJitterAlgorithmFULL = 0x01, SrsRtmpJitterAlgorithmZERO, SrsRtmpJitterAlgorithmOFF};int _srs_time_jitter_string2int(std::string time_jitter);/*** time jitter detect and correct,* to ensure the rtmp stream is monotonically.*/class SrsRtmpJitter{private: int64_t last_pkt_time; int64_t last_pkt_correct_time;public: SrsRtmpJitter(); virtual ~SrsRtmpJitter();public: /** * detect the time jitter and correct it. * @param tba, the audio timebase, used to calc the "right" delta if jitter detected. * @param tbv, the video timebase, used to calc the "right" delta if jitter detected. * @param start_at_zero whether ensure stream start at zero. * @param mono_increasing whether ensure stream is monotonically inscreasing. */ virtual int correct(SrsSharedPtrMessage* msg, int tba, int tbv, SrsRtmpJitterAlgorithm ag); /** * get current client time, the last packet time. */ virtual int get_time();};超过抖动区域,置为默认值,都是相对时间
#define CONST_MAX_JITTER_MS 250#define CONST_MAX_JITTER_MS_NEG -250#define DEFAULT_FRAME_TIME_MS 10// for 26ms per audio packet,// 115 packets is 3s.#define SRS_PURE_AUDIO_GUESS_COUNT 115// when got these videos or audios, pure audio or video, mix ok.#define SRS_MIX_CORRECT_PURE_AV 10// the time to cleanup source in ms.#define SRS_SOURCE_CLEANUP 30000int _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; // for performance issue if (ag != SrsRtmpJitterAlgorithmFULL) { // all jitter correct features is disabled, ignore. if (ag == SrsRtmpJitterAlgorithmOFF) { return ret; } // start at zero, but donot ensure monotonically increasing. if (ag == SrsRtmpJitterAlgorithmZERO) { // for the first time, last_pkt_correct_time is -1. if (last_pkt_correct_time == -1) { last_pkt_correct_time = msg->timestamp; } msg->timestamp -= last_pkt_correct_time; return ret; } // other algorithm, ignore. return ret; } // full jitter algorithm, do jitter correct. // set to 0 for metadata. if (!msg->is_av()) { msg->timestamp = 0; return ret; } /** * we use a very simple time jitter detect/correct algorithm: * 1. delta: ensure the delta is positive and valid, * we set the delta to DEFAULT_FRAME_TIME_MS, * if the delta of time is nagative or greater than CONST_MAX_JITTER_MS. * 2. last_pkt_time: specifies the original packet time, * is used to detect next jitter. * 3. last_pkt_correct_time: simply add the positive delta, * and enforce the time monotonically. */ int64_t time = msg->timestamp; int64_t delta = time - last_pkt_time; // if jitter detected, reset the delta. if (delta < CONST_MAX_JITTER_MS_NEG || delta > CONST_MAX_JITTER_MS) { // use default 10ms to notice the problem of stream. // @see https://github.com/ossrs/srs/issues/425 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;}
0 0
- srs中时间戳抖动处理
- srs中时间戳抖动处理
- SRS中增加身份验证
- SRS中增加身份验证
- swift中关于表情键盘,抖动问题处理
- SRS
- 按键抖动与处理
- ffdemux_mpegts中时间戳的处理问题
- ffdemux_mpegts中时间戳的处理问题
- C++中时间处理
- C++中时间处理
- javascript中处理时间
- javascript中处理时间
- java中处理时间
- APP中时间处理
- datatables中参数的处理(处理时间戳)
- srs之时间戳矫正算法(混合单增算法,mix_correct to ensure timestamp monotonically increase)
- web应用中处理时间
- 创建型设计模式-原型模式
- 如何用Maven创建web项目(具体步骤)
- Android和UI那些事儿
- Spring Boot中使用Swagger2构建强大的RESTful API文档
- android : String.format
- srs中时间戳抖动处理
- swift 3.0
- 简述代码重构的重要性
- Android中基于TCP协议的网络通信
- codeforces 779C 排序加贪心
- 在Linux上搭建SVN服务器
- 开个博客
- JAVA中的反射机制
- SSL 1562_局域网_最小生成树