One way audio due to Opus falsely detecting codec ptime change (#2836)

remotes/origin/handle_multi_handshake_fail
Nanang Izzuddin 3 years ago committed by GitHub
parent 6b1821c0c7
commit 3cf3b04a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -861,25 +861,43 @@ static pj_status_t codec_parse( pjmedia_codec *codec,
opus_repacketizer_cat(opus_data->dec_packer, tmp_buf, pkt_size);
num_frames = opus_repacketizer_get_nb_frames(opus_data->dec_packer);
if (num_frames == 0) {
PJ_LOG(2, (THIS_FILE, "No frames retrieved (num_frames = 0)"));
pj_mutex_unlock(opus_data->mutex);
return PJMEDIA_CODEC_EFAILED;
}
out_pos = 0;
for (i = 0; i < num_frames; ++i) {
size = opus_repacketizer_out_range(opus_data->dec_packer, i, i+1,
((unsigned char*)pkt) + out_pos,
sizeof(tmp_buf));
if (size < 0) {
PJ_LOG(5, (THIS_FILE, "Parse failed! (%d)", pkt_size));
PJ_LOG(5, (THIS_FILE, "Parse failed! (pkt_size=%d, err=%d)",
pkt_size, size));
pj_mutex_unlock (opus_data->mutex);
return PJMEDIA_CODEC_EFAILED;
}
frames[i].type = PJMEDIA_FRAME_TYPE_AUDIO;
frames[i].buf = ((char*)pkt) + out_pos;
frames[i].size = size;
frames[i].bit_info = opus_packet_get_nb_samples(frames[i].buf,
frames[i].size, opus_data->cfg.sample_rate);
frames[i].bit_info = 0;
if (i == 0) {
unsigned ptime = frames[i].bit_info * 1000 /
opus_data->cfg.sample_rate;
int nsamples;
unsigned ptime;
nsamples = opus_packet_get_nb_samples(frames[i].buf,
frames[i].size,
opus_data->cfg.sample_rate);
if (nsamples <= 0) {
PJ_LOG(5, (THIS_FILE, "Parse failed to get samples number! "
"(err=%d)", nsamples));
pj_mutex_unlock (opus_data->mutex);
return PJMEDIA_CODEC_EFAILED;
}
ptime = nsamples * 1000 / opus_data->cfg.sample_rate;
if (ptime != opus_data->dec_ptime) {
PJ_LOG(4, (THIS_FILE, "Opus ptime change detected: %d ms "
"--> %d ms",
@ -888,9 +906,9 @@ static pj_status_t codec_parse( pjmedia_codec *codec,
opus_data->dec_frame_index = -1;
/* Signal to the stream about ptime change. */
frames[i].bit_info |= 0x10000;
frames[i].bit_info = 0x10000 | nsamples;
}
samples_per_frame = frames[i].bit_info;
samples_per_frame = nsamples;
}
frames[i].timestamp.u64 = ts->u64 + i * samples_per_frame;

@ -719,6 +719,8 @@ PJ_DEF(pj_status_t) pjmedia_jbuf_reset(pjmedia_jbuf *jb)
jb_framelist_reset(&jb->jb_framelist);
PJ_LOG(5, (jb->jb_name.ptr, "Jitter buffer reset"));
return PJ_SUCCESS;
}

@ -2038,6 +2038,7 @@ static void on_rx_rtp( pjmedia_tp_cb_param *param)
unsigned i, count = MAX;
unsigned ts_span;
pjmedia_frame frames[MAX];
pj_bzero(frames, sizeof(frames[0]) * MAX);
/* Get the timestamp of the first sample */
ts.u64 = pj_ntohl(hdr->ts);
@ -2049,13 +2050,15 @@ static void on_rx_rtp( pjmedia_tp_cb_param *param)
LOGERR_((stream->port.info.name.ptr, status,
"Codec parse() error"));
count = 0;
} else if (count == 0) {
PJ_LOG(2, (stream->port.info.name.ptr, "codec parsed 0 frames"));
} else if (stream->detect_ptime_change &&
frames[0].bit_info > 0xFFFF)
{
unsigned dec_ptime;
unsigned dec_ptime, old_ptime;
old_ptime = stream->dec_ptime;
PJ_LOG(4, (stream->port.info.name.ptr, "codec decode "
"ptime change detected"));
frames[0].bit_info &= 0xFFFF;
dec_ptime = frames[0].bit_info * 1000 /
stream->codec_param.info.clock_rate;
@ -2064,6 +2067,10 @@ static void on_rx_rtp( pjmedia_tp_cb_param *param)
stream->dec_ptime = (pj_uint16_t)dec_ptime;
pjmedia_jbuf_set_ptime(stream->jb, stream->dec_ptime);
PJ_LOG(4, (stream->port.info.name.ptr, "codec decode "
"ptime change detected: %d -> %d",
old_ptime, dec_ptime));
/* Reset jitter buffer after ptime changed */
pjmedia_jbuf_reset(stream->jb);
}

Loading…
Cancel
Save