Skip to content

Commit cb4db80

Browse files
Fix g711 rtp encoder timestamp calculate bug (ZLMediaKit#4085)
1 parent 3f59233 commit cb4db80

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

ext-codec/G711Rtp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ void G711RtpEncoder::setOpt(int opt, const toolkit::Any &param) {
2626
bool G711RtpEncoder::inputFrame(const Frame::Ptr &frame) {
2727
auto ptr = frame->data() + frame->prefixSize();
2828
auto size = frame->size() - frame->prefixSize();
29-
29+
uint64_t in_pts;
3030
if (!_pkt_bytes) {
31-
_in_pts = frame->pts();
31+
in_pts = frame->pts();
3232
// G711压缩率固定是2倍
3333
_pkt_bytes = _pkt_dur_ms * _channels * (_sample_bit / 8) * _sample_rate / 1000 / 2;
3434
} else {
35-
_in_pts = frame->pts() - (float)_buffer.size() / (float)_pkt_bytes * _pkt_dur_ms;
35+
in_pts = frame->pts() - _buffer.size() * _pkt_dur_ms / _pkt_bytes;
3636
}
3737

3838
_buffer.append(ptr, size);
3939

4040
while (_buffer.size() >= _pkt_bytes) {
41-
_in_pts += _pkt_dur_ms;
42-
RtpCodec::inputRtp(getRtpInfo().makeRtp(TrackAudio, _buffer.data(), _pkt_bytes, false, _in_pts), false);
41+
RtpCodec::inputRtp(getRtpInfo().makeRtp(TrackAudio, _buffer.data(), _pkt_bytes, false, in_pts), false);
42+
in_pts += _pkt_dur_ms;
4343
_buffer.erase(0, _pkt_bytes);
4444
}
4545
return true;

ext-codec/G711Rtp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class G711RtpEncoder : public RtpCodec {
5959

6060
uint32_t _pkt_dur_ms = 20;
6161
uint32_t _pkt_bytes = 0;
62-
int64_t _in_pts = 0;
6362
toolkit::BufferLikeString _buffer;
6463
};
6564

0 commit comments

Comments
 (0)