diff --git a/daemon/audio_player.c b/daemon/audio_player.c index b485f5d60..472ad720d 100644 --- a/daemon/audio_player.c +++ b/daemon/audio_player.c @@ -35,8 +35,8 @@ static bool audio_player_run(struct media_player *mp) { if (!buf) { if (!size) { // error or not active: just reschedule - mp->next_run = timeval_add_usec(mp->next_run, ap->ptime_us); - timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run); + mp->next_run += ap->ptime_us; + timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run)); return false; } buf = g_alloca(size); @@ -162,16 +162,16 @@ void audio_player_start(struct call_media *m) { media_player_set_media(mp, m); - if (mp->next_run.tv_sec) // already running? + if (mp->next_run) // already running? return; ilogs(transcoding, LOG_DEBUG, "Starting audio player"); ap->last_run = timeval_from_us(rtpe_now); - mp->next_run = timeval_from_us(rtpe_now); - mp->next_run = timeval_add_usec(mp->next_run, ap->ptime_us); - timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run); + mp->next_run = rtpe_now; + mp->next_run += ap->ptime_us; + timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run)); } @@ -199,7 +199,7 @@ bool audio_player_is_active(struct call_media *m) { return false; if (!m->audio_player->mp) return false; - if (!m->audio_player->mp->next_run.tv_sec) + if (!m->audio_player->mp->next_run) return false; return true; } diff --git a/daemon/media_player.c b/daemon/media_player.c index e7932521b..27f4424c2 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -174,7 +174,7 @@ static void media_player_shutdown(struct media_player *mp) { //ilog(LOG_DEBUG, "shutting down media_player"); timerthread_obj_deschedule(&mp->tt_obj); - mp->next_run.tv_sec = 0; + mp->next_run = 0; if (mp->sink) { unsigned int num = send_timer_flush(mp->sink->send_timer, mp->coder.handler); @@ -541,7 +541,7 @@ retry:; // got a packet struct media_player_cache_packet *pkt = entry->packets->pdata[read_idx]; - long long us_dur = pkt->duration; + int64_t us_dur = pkt->duration; mp->cache_read_idx++; @@ -568,7 +568,7 @@ retry:; read_idx == 0, mp->seq++, 0, -1, 0); mp->buffer_ts += pkt->duration_ts; - mp->sync_ts_tv = timeval_from_us(rtpe_now); + mp->sync_ts_tv = rtpe_now; media_packet_encrypt(mp->crypt_handler->out->rtp_crypt, mp->sink, &packet); @@ -578,8 +578,8 @@ retry:; mutex_unlock(&mp->sink->out_lock); // schedule our next run - mp->next_run = timeval_add_usec(mp->next_run, us_dur); - timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run); + mp->next_run += us_dur; + timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run)); return false; } @@ -655,17 +655,17 @@ static void media_player_cached_reader_start(struct media_player *mp, str_case_v mp->coder.handler = codec_handler_make_dummy(&entry->coder.handler->dest_pt, mp->media, codec_set); mp->run_func = media_player_read_decoded_packet; - mp->next_run = timeval_from_us(rtpe_now); + mp->next_run = rtpe_now; mp->coder.duration = entry->coder.duration; // if we played anything before, scale our sync TS according to the time // that has passed - if (mp->sync_ts_tv.tv_sec) { - int64_t ts_diff_us = timeval_diff(timeval_from_us(rtpe_now), mp->sync_ts_tv); + if (mp->sync_ts_tv) { + int64_t ts_diff_us = rtpe_now - mp->sync_ts_tv; mp->buffer_ts += fraction_divl(ts_diff_us * dst_pt->clock_rate / 1000000, &dst_pt->codec_def->default_clockrate_fact); } - mp->sync_ts_tv = timeval_from_us(rtpe_now); + mp->sync_ts_tv = rtpe_now; media_player_read_decoded_packet(mp); } @@ -938,8 +938,8 @@ static int media_player_setup_common(struct media_player *mp, const rtp_payload_ // if we played anything before, scale our sync TS according to the time // that has passed - if (mp->sync_ts_tv.tv_sec) { - int64_t ts_diff_us = timeval_diff(timeval_from_us(rtpe_now), mp->sync_ts_tv); + if (mp->sync_ts_tv) { + int64_t ts_diff_us = rtpe_now - mp->sync_ts_tv; mp->sync_ts += fraction_divl(ts_diff_us * (*dst_pt)->clock_rate / 1000000, &(*dst_pt)->codec_def->default_clockrate_fact); } @@ -1047,7 +1047,7 @@ void media_player_add_packet(struct media_player *mp, char *buf, size_t len, struct codec_packet *p = packet.packets_out.head->data; if (p->rtp) { mp->sync_ts = ntohl(p->rtp->timestamp); - mp->sync_ts_tv = p->ttq_entry.when; + mp->sync_ts_tv = timeval_us(p->ttq_entry.when); } } @@ -1058,8 +1058,8 @@ void media_player_add_packet(struct media_player *mp, char *buf, size_t len, ilog(LOG_ERR, "Error sending playback media to RTP sink"); mutex_unlock(&mp->sink->out_lock); - mp->next_run = timeval_add_usec(mp->next_run, us_dur); - timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run); + mp->next_run += us_dur; + timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run)); } static int media_player_find_file_begin(struct media_player *mp) { @@ -1207,9 +1207,9 @@ static bool media_player_play_start(struct media_player *mp, const rtp_payload_t if (media_player_cache_entry_init(mp, dst_pt, codec_set)) return true; - mp->next_run = timeval_from_us(rtpe_now); + mp->next_run = rtpe_now; // give ourselves a bit of a head start with decoding - mp->next_run = timeval_add_usec(mp->next_run, -50000); + mp->next_run -= 50000; // if start_pos is positive, try to seek to that position if (mp->opts.start_pos > 0) { @@ -2002,7 +2002,7 @@ static void media_player_run(void *ptr) { mutex_lock(&mp->lock); bool finished = false; - if (mp->next_run.tv_sec) + if (mp->next_run) finished = mp->run_func(mp); mutex_unlock(&mp->lock); @@ -2011,7 +2011,7 @@ static void media_player_run(void *ptr) { if (finished) { rwlock_lock_w(&call->master_lock); - mp->next_run.tv_sec = 0; + mp->next_run = 0; if (mp->opts.block_egress) MEDIA_CLEAR(mp->media, BLOCK_EGRESS); @@ -2031,7 +2031,7 @@ bool media_player_is_active(struct call_monologue *ml) { return false; if (!ml->player) return false; - if (!ml->player->next_run.tv_sec) + if (!ml->player->next_run) return false; return true; } diff --git a/daemon/t38.c b/daemon/t38.c index c901e1f23..628b6643b 100644 --- a/daemon/t38.c +++ b/daemon/t38.c @@ -273,8 +273,8 @@ static bool t38_pcm_player(struct media_player *mp) { if (num <= 0) { ilog(LOG_DEBUG, "No T.38 PCM samples generated"); // use a fixed interval of 10 ms - mp->next_run = timeval_add_usec(mp->next_run, 10000); - timerthread_obj_schedule_abs(&mp->tt_obj, mp->next_run); + mp->next_run += 10000; + timerthread_obj_schedule_abs(&mp->tt_obj, timeval_from_us(mp->next_run)); mutex_unlock(&tg->lock); return false; } @@ -482,7 +482,7 @@ void t38_gateway_start(struct t38_gateway *tg, str_case_value_ht codec_set) { // now start our player if we can or should // already running? - if (tg->pcm_player->next_run.tv_sec) + if (tg->pcm_player->next_run) return; // only start our player only if we can send both ways @@ -504,8 +504,8 @@ void t38_gateway_start(struct t38_gateway *tg, str_case_value_ht codec_set) { ilog(LOG_DEBUG, "Starting T.38 PCM player"); // start off PCM player - tg->pcm_player->next_run = timeval_from_us(rtpe_now); - timerthread_obj_schedule_abs(&tg->pcm_player->tt_obj, tg->pcm_player->next_run); + tg->pcm_player->next_run = rtpe_now; + timerthread_obj_schedule_abs(&tg->pcm_player->tt_obj, timeval_from_us(tg->pcm_player->next_run)); } diff --git a/include/media_player.h b/include/media_player.h index a164a4fc2..75f162a00 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -70,7 +70,7 @@ struct media_player { struct packet_stream *sink; const struct streamhandler *crypt_handler; - struct timeval next_run; + int64_t next_run; media_player_opts_t opts; @@ -86,7 +86,7 @@ struct media_player { unsigned long seq; unsigned long buffer_ts; unsigned long sync_ts; - struct timeval sync_ts_tv; + int64_t sync_ts_tv; long long last_frame_ts; };