revert use of TIME_MONOTONIC back to TIME_REALTIME

This commit is contained in:
F. Duncanh
2023-02-03 11:45:43 -05:00
parent 2eab11f88a
commit ba1dd3ccbd
5 changed files with 13 additions and 35 deletions

View File

@@ -29,11 +29,11 @@ extern "C" {
#include <stdbool.h>
#include "../lib/logger.h"
bool gstreamer_init(uint64_t * unix_start_time, uint64_t *monotonic_start_time);
bool gstreamer_init();
void audio_renderer_init(logger_t *logger, const char* audiosink, const char* audiodelay);
void audio_renderer_start(unsigned char* compression_type);
void audio_renderer_stop();
void audio_renderer_render_buffer(unsigned char* data, int *data_len, unsigned short *seqnum, uint64_t *pts);
void audio_renderer_render_buffer(unsigned char* data, int *data_len, unsigned short *seqnum, uint64_t *ntp_time);
void audio_renderer_set_volume(float volume);
void audio_renderer_flush();
void audio_renderer_destroy();

View File

@@ -69,27 +69,8 @@ static gboolean check_plugins (void)
return ret;
}
bool gstreamer_init(uint64_t *unix_start_time, uint64_t *monotonic_start_time){
struct timespec tp;
GstClock *clock = NULL;
GstClockTime time;
bool gstreamer_init(){
gst_init(NULL,NULL);
clock = gst_system_clock_obtain();
if (!clock) {
g_print("gstreamer_init: error: failed to obtain gst_system_clock\n");
return false;
}
g_object_set(clock, "clock-type", GST_CLOCK_TYPE_MONOTONIC, NULL);
time = GST_TIME_AS_NSECONDS(gst_clock_get_time(clock));
if (clock_gettime(CLOCK_REALTIME, &tp)){
g_print("gstreamer_init: error failed to get unix time\n");
return false;
}
time += GST_TIME_AS_NSECONDS(gst_clock_get_time(clock));
*monotonic_start_time = time/2;
*unix_start_time = (1000000000 * tp.tv_sec) + tp.tv_nsec;
g_object_unref (clock);
return (bool) check_plugins ();
}
@@ -104,7 +85,7 @@ void audio_renderer_init(logger_t *render_logger, const char* audiosink, const c
GError *error = NULL;
GstCaps *caps = NULL;
GstClock *clock = gst_system_clock_obtain();
g_object_set(clock, "clock-type", GST_CLOCK_TYPE_MONOTONIC, NULL);
g_object_set(clock, "clock-type", GST_CLOCK_TYPE_REALTIME, NULL);
logger = render_logger;
@@ -217,10 +198,10 @@ void audio_renderer_start(unsigned char *ct) {
}
void audio_renderer_render_buffer(unsigned char* data, int *data_len, unsigned short *seqnum, uint64_t *pts_raw) {
void audio_renderer_render_buffer(unsigned char* data, int *data_len, unsigned short *seqnum, uint64_t *ntp_time) {
GstBuffer *buffer;
bool valid;
GstClockTime pts = (GstClockTime) *pts_raw;
GstClockTime pts = (GstClockTime) (*ntp_time * 1000); /* convert from usec to nsec */
if (pts >= gst_audio_pipeline_base_time) {
pts -= gst_audio_pipeline_base_time;
} else {

View File

@@ -48,7 +48,7 @@ void video_renderer_init (logger_t *logger, const char *server_name, videoflip_t
const char *decoder, const char *converter, const char *videosink, const bool *fullscreen);
void video_renderer_start ();
void video_renderer_stop ();
void video_renderer_render_buffer (unsigned char* data, int *data_len, int *nal_count, uint64_t *pts);
void video_renderer_render_buffer (unsigned char* data, int *data_len, int *nal_count, uint64_t *ntp_time);
void video_renderer_flush ();
unsigned int video_renderer_listen(void *loop);
void video_renderer_destroy ();

View File

@@ -127,7 +127,7 @@ void video_renderer_init(logger_t *render_logger, const char *server_name, vide
GError *error = NULL;
GstCaps *caps = NULL;
GstClock *clock = gst_system_clock_obtain();
g_object_set(clock, "clock-type", GST_CLOCK_TYPE_MONOTONIC, NULL);
g_object_set(clock, "clock-type", GST_CLOCK_TYPE_REALTIME, NULL);
logger = render_logger;
@@ -218,9 +218,9 @@ void video_renderer_start() {
#endif
}
void video_renderer_render_buffer(unsigned char* data, int *data_len, int *nal_count, uint64_t *pts_raw) {
void video_renderer_render_buffer(unsigned char* data, int *data_len, int *nal_count, uint64_t *ntp_time) {
GstBuffer *buffer;
GstClockTime pts = (GstClockTime) *pts_raw;
GstClockTime pts = (GstClockTime) (*ntp_time * 1000); /*convert from usec to nsec */
if (pts >= gst_video_pipeline_base_time) {
pts -= gst_video_pipeline_base_time;
} else {

View File

@@ -107,7 +107,6 @@ static bool bt709_fix = false;
static int max_connections = 2;
static unsigned short raop_port;
static unsigned short airplay_port;
static uint64_t ntp_start_time, gst_start_time;
/* 95 byte png file with a 1x1 white square (single pixel): placeholder for coverart*/
static const unsigned char empty_image[] = {
@@ -991,8 +990,7 @@ extern "C" void audio_process (void *cls, raop_ntp_t *ntp, audio_decode_struct *
dump_audio_to_file(data->data, data->data_len, (data->data)[0] & 0xf0);
}
if (use_audio) {
uint64_t pts = ((data->ntp_time * 1000) + gst_start_time) - ntp_start_time;
audio_renderer_render_buffer(data->data, &(data->data_len), &(data->seqnum), &pts);
audio_renderer_render_buffer(data->data, &(data->data_len), &(data->seqnum), &(data->ntp_time));
}
}
@@ -1001,8 +999,7 @@ extern "C" void video_process (void *cls, raop_ntp_t *ntp, h264_decode_struct *d
dump_video_to_file(data->data, data->data_len);
}
if (use_video) {
uint64_t pts = ((data->ntp_time * 1000) + gst_start_time) - ntp_start_time;
video_renderer_render_buffer(data->data, &(data->data_len), &(data->nal_count), &pts);
video_renderer_render_buffer(data->data, &(data->data_len), &(data->nal_count), &(data->ntp_time));
}
}
@@ -1277,7 +1274,7 @@ int main (int argc, char *argv[]) {
append_hostname(server_name);
}
if (!gstreamer_init(&ntp_start_time, &gst_start_time)) {
if (!gstreamer_init()) {
LOGE ("stopping");
exit (1);
}