Allow for different output rates in the new calculations
This commit is contained in:
@@ -973,10 +973,10 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
|
||||
frame_to_local_time(conn->first_packet_timestamp +conn->latency * conn->output_sample_ratio + (int64_t)(config.audio_backend_latency_offset * config.output_rate),&should_be_time,conn);
|
||||
|
||||
if(should_be_time>=conn->first_packet_time_to_play) {
|
||||
if ((((should_be_time-conn->first_packet_time_to_play)*1000000)>>32)>10)
|
||||
if ((((should_be_time-conn->first_packet_time_to_play)*1000000)>>32)>10*conn->output_sample_ratio)
|
||||
debug(1,"New time for first packet timestamp %" PRId64 " is later than calculated time by %" PRId64 " microseconds.",curframe->timestamp,((should_be_time-conn->first_packet_time_to_play)*1000000)>>32);
|
||||
} else {
|
||||
if ((((conn->first_packet_time_to_play-should_be_time)*1000000)>>32)>10)
|
||||
if ((((conn->first_packet_time_to_play-should_be_time)*1000000)>>32)>10*conn->output_sample_ratio)
|
||||
debug(1,"New time for first packet timestamp %" PRId64 " is earlier than calculated time by %" PRId64 " microseconds.",curframe->timestamp,((conn->first_packet_time_to_play-should_be_time)*1000000)>>32);
|
||||
}
|
||||
|
||||
@@ -1014,10 +1014,10 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
|
||||
frame_to_local_time(conn->first_packet_timestamp +conn->latency * conn->output_sample_ratio + (int64_t)(config.audio_backend_latency_offset * config.output_rate),&should_be_time,conn);
|
||||
|
||||
if(should_be_time>=conn->first_packet_time_to_play) {
|
||||
if ((((should_be_time-conn->first_packet_time_to_play)*1000000)>>32)>50)
|
||||
if ((((should_be_time-conn->first_packet_time_to_play)*1000000)>>32)>50*conn->output_sample_ratio)
|
||||
debug(1,"New time for recalculated first packet timestamp %" PRId64 " is later than calculated time by %" PRId64 " microseconds.",curframe->timestamp,((should_be_time-conn->first_packet_time_to_play)*1000000)>>32);
|
||||
} else {
|
||||
if ((((conn->first_packet_time_to_play-should_be_time)*1000000)>>32)>50)
|
||||
if ((((conn->first_packet_time_to_play-should_be_time)*1000000)>>32)>50*conn->output_sample_ratio)
|
||||
debug(1,"New time for recalculated first packet timestamp %" PRId64 " is earlier than calculated time by %" PRId64 " microseconds.",curframe->timestamp,((conn->first_packet_time_to_play-should_be_time)*1000000)>>32);
|
||||
}
|
||||
|
||||
@@ -2065,7 +2065,7 @@ void *player_thread_func(void *arg) {
|
||||
int64_t should_be_frame;
|
||||
local_time_to_frame(local_time_now,&should_be_frame,conn);
|
||||
|
||||
if (abs(td_in_frames + rt-should_be_frame)>10)
|
||||
if (abs(td_in_frames + rt-should_be_frame)>10*conn->output_sample_ratio)
|
||||
debug(1,"Difference between old and new frame number is %" PRId64 " frames.",td_in_frames + rt - should_be_frame);
|
||||
// this is the actual delay, including the latency we actually want, which will
|
||||
// fluctuate a good bit about a potentially rising or falling trend.
|
||||
|
||||
@@ -999,6 +999,9 @@ int sanitised_source_rate_information(int64_t *frames, uint64_t *time, rtsp_conn
|
||||
return result;
|
||||
}
|
||||
|
||||
// we assume here that the timestamp is a timestamp calculated at the output rate, which could be an integer multiple of the input rate
|
||||
// the reference timestamps are denominated in terms of the input rate
|
||||
|
||||
int frame_to_local_time(int64_t timestamp, uint64_t *time, rtsp_conn_info *conn) {
|
||||
debug_mutex_lock(&conn->reference_time_mutex, 1000, 1);
|
||||
int result = 0;
|
||||
@@ -1006,15 +1009,15 @@ int frame_to_local_time(int64_t timestamp, uint64_t *time, rtsp_conn_info *conn)
|
||||
int64_t frame_difference;
|
||||
result = sanitised_source_rate_information(&frame_difference,&time_difference,conn);
|
||||
|
||||
int64_t timestamp_interval = timestamp - conn->reference_timestamp; // we could be dealing with multiples of 44100 (nominally)
|
||||
int64_t timestamp_interval = timestamp - conn->reference_timestamp*conn->output_sample_ratio; // we could be dealing with multiples of 44100 (nominally)
|
||||
// debug(1, "Timestamp interval: %" PRId64 " frames with reference timestamp %" PRId64 ".",timestamp_interval,conn->reference_timestamp);
|
||||
uint64_t timestamp_interval_time;
|
||||
uint64_t remote_time_of_timestamp;
|
||||
if (timestamp_interval>=0) {
|
||||
timestamp_interval_time = (timestamp_interval * time_difference)/frame_difference; // this is the nominal time, based on the fps specified between current and previous sync frame.
|
||||
timestamp_interval_time = (timestamp_interval * time_difference)/(frame_difference*conn->output_sample_ratio); // this is the nominal time, based on the fps specified between current and previous sync frame.
|
||||
remote_time_of_timestamp = conn->remote_reference_timestamp_time + timestamp_interval_time; // based on the reference timestamp time plus the time interval calculated based on the specified fps.
|
||||
} else {
|
||||
timestamp_interval_time = ((-timestamp_interval) * time_difference)/frame_difference; // this is the nominal time, based on the fps specified between current and previous sync frame.
|
||||
timestamp_interval_time = ((-timestamp_interval) * time_difference)/(frame_difference*conn->output_sample_ratio); // this is the nominal time, based on the fps specified between current and previous sync frame.
|
||||
remote_time_of_timestamp = conn->remote_reference_timestamp_time - timestamp_interval_time; // based on the reference timestamp time plus the time interval calculated based on the specified fps.
|
||||
}
|
||||
*time = remote_time_of_timestamp - local_to_remote_time_difference_now(conn);
|
||||
@@ -1035,19 +1038,20 @@ int local_time_to_frame(uint64_t time, int64_t *frame, rtsp_conn_info *conn) {
|
||||
// next, get the remote time interval from the remote_time to the reference time
|
||||
uint64_t time_interval;
|
||||
|
||||
// here, we calculate the time interval, in terms of remote time
|
||||
if (remote_time >= conn->remote_reference_timestamp_time)
|
||||
time_interval = remote_time - conn->remote_reference_timestamp_time;
|
||||
else
|
||||
time_interval = conn->remote_reference_timestamp_time - remote_time;
|
||||
|
||||
// now, convert the remote time interval into frames
|
||||
// now, convert the remote time interval into frames using the frame rate we have observed or which has been nominated
|
||||
int64_t frame_interval = (time_interval * frame_difference)/time_difference;
|
||||
if (remote_time >= conn->remote_reference_timestamp_time) {
|
||||
// debug(1,"Frame interval is %" PRId64 " frames.",frame_interval);
|
||||
*frame = conn->reference_timestamp+frame_interval;
|
||||
*frame = (conn->reference_timestamp+frame_interval)*conn->output_sample_ratio;
|
||||
} else {
|
||||
// debug(1,"Frame interval is %" PRId64 " frames.",-frame_interval);
|
||||
*frame = conn->reference_timestamp-frame_interval;
|
||||
*frame = (conn->reference_timestamp-frame_interval)*conn->output_sample_ratio;
|
||||
}
|
||||
debug_mutex_unlock(&conn->reference_time_mutex, 3);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user