@@ -46,7 +46,8 @@ static bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8
4646
4747
4848ACSession * ac_new (Mono_Time * mono_time , const Logger * log , ToxAV * av , Tox * tox , uint32_t friend_number ,
49- toxav_audio_receive_frame_cb * cb , void * cb_data )
49+ toxav_audio_receive_frame_cb * cb , void * cb_data ,
50+ toxav_audio_receive_frame_pts_cb * cb_pts , void * cb_pts_data )
5051{
5152 ACSession * ac = (ACSession * )calloc (sizeof (ACSession ), 1 );
5253
@@ -111,9 +112,15 @@ ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, Tox *tox,
111112 ac -> av = av ;
112113 ac -> tox = tox ;
113114 ac -> friend_number = friend_number ;
115+
116+ // set callback
114117 ac -> acb = cb ;
115118 ac -> acb_user_data = cb_data ;
116119
120+ // set pts callback
121+ ac -> acb_pts = cb_pts ;
122+ ac -> acb_pts_user_data = cb_pts_data ;
123+
117124 return ac ;
118125
119126DECODER_CLEANUP :
@@ -330,6 +337,7 @@ uint8_t ac_iterate(ACSession *ac, uint64_t *a_r_timestamp, uint64_t *a_l_timesta
330337 }
331338
332339 uint8_t ret_value = 1 ;
340+ uint64_t header_pts_saved = 0 ;
333341
334342 pthread_mutex_lock (ac -> queue_mutex );
335343
@@ -432,13 +440,14 @@ uint8_t ac_iterate(ACSession *ac, uint64_t *a_r_timestamp, uint64_t *a_l_timesta
432440
433441 // LOGGER_ERROR(ac->log, "AUDIO:TTx: %llu %lld now=%llu", header_v3->frame_record_timestamp, (long long)*a_r_timestamp, current_time_monotonic(ac->mono_time));
434442 if (header_v3 -> frame_record_timestamp > 0 ) {
443+ header_pts_saved = header_v3 -> frame_record_timestamp ;
435444 if (* a_r_timestamp < header_v3 -> frame_record_timestamp ) {
436445 // LOGGER_ERROR(ac->log, "AUDIO:TTx:2: %llu", header_v3->frame_record_timestamp);
437446 * a_r_timestamp = header_v3 -> frame_record_timestamp ;
438447 * a_l_timestamp = current_time_monotonic (ac -> mono_time );
439448 } else {
440449 // TODO: this should not happen here!
441- LOGGER_DEBUG (ac -> log , "AUDIO: remote timestamp older" );
450+ LOGGER_API_DEBUG (ac -> tox , "AUDIO: remote timestamp older" );
442451 }
443452 }
444453
@@ -455,11 +464,19 @@ uint8_t ac_iterate(ACSession *ac, uint64_t *a_r_timestamp, uint64_t *a_l_timesta
455464 }
456465
457466 if (rc < 0 ) {
458- LOGGER_WARNING (ac -> log , "Decoding error: %s" , opus_strerror (rc ));
459- } else if (ac -> acb ) {
460- ac -> lp_frame_duration = (rc * 1000 ) / ac -> lp_sampling_rate ;
461- ac -> acb (ac -> av , ac -> friend_number , ac -> temp_audio_buffer , rc , ac -> lp_channel_count ,
462- ac -> lp_sampling_rate , ac -> acb_user_data );
467+ LOGGER_API_WARNING (ac -> tox , "Decoding error: %s" , opus_strerror (rc ));
468+ } else {
469+ if (ac -> acb_pts ) {
470+ ac -> lp_frame_duration = (rc * 1000 ) / ac -> lp_sampling_rate ;
471+ ac -> acb_pts (ac -> av , ac -> friend_number , ac -> temp_audio_buffer , rc , ac -> lp_channel_count ,
472+ ac -> lp_sampling_rate , ac -> acb_pts_user_data , header_pts_saved );
473+ return ret_value ;
474+ } else if (ac -> acb ) {
475+ ac -> lp_frame_duration = (rc * 1000 ) / ac -> lp_sampling_rate ;
476+ ac -> acb (ac -> av , ac -> friend_number , ac -> temp_audio_buffer , rc , ac -> lp_channel_count ,
477+ ac -> lp_sampling_rate , ac -> acb_user_data );
478+ return ret_value ;
479+ }
463480 }
464481
465482 return ret_value ;
0 commit comments