diff --git a/src/control_socket.cpp b/src/control_socket.cpp index 37269c326..d7d45d199 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -511,6 +511,10 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s struct msg_receiver *msg = (struct msg_receiver *) new_message(sizeof(struct msg_receiver)); msg->type = RECEIVER_MSG_MUTE; resp = send_message(s->root_module, path, (struct message *) msg); + } else if (prefix_matches(message, "av-delay ")) { + int val = atoi(suffix(message, "av-delay ")); + set_audio_delay(val); + resp = new_response(RESPONSE_OK, NULL); } else if (prefix_matches(message, "postprocess ")) { strncpy(path, "display", sizeof path); struct msg_universal *msg = (struct msg_universal *) new_message(sizeof(struct msg_universal)); diff --git a/src/host.cpp b/src/host.cpp index 98af6c690..71ffba72e 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -302,3 +302,14 @@ const char *get_commandline_param(const char *key) } } +int get_audio_delay(void) +{ + return audio_offset > 0 ? audio_offset : -video_offset; +} + +void set_audio_delay(int audio_delay) +{ + audio_offset = max(audio_delay, 0); + video_offset = audio_delay < 0 ? abs(audio_delay) : 0; +} + diff --git a/src/host.h b/src/host.h index 8f9c9d149..576fba639 100644 --- a/src/host.h +++ b/src/host.h @@ -118,9 +118,12 @@ extern char *export_dir; extern char *sage_network_device; // Both of following varables are non-negative. It indicates amount of milliseconds that -// audio or video should be delayed. This shall be used for AV sync control. +// audio or video should be delayed. This shall be used for AV sync control. For +// getting/setting you can use get_av_delay()/set_av_delay(). All is in milliseconds. extern volatile int audio_offset; extern volatile int video_offset; +int get_audio_delay(void); +void set_audio_delay(int val); #define RATE_UNLIMITED 0 #define RATE_AUTO -1 diff --git a/src/keyboard_control.cpp b/src/keyboard_control.cpp index 406a7b2e6..d5fe9f718 100644 --- a/src/keyboard_control.cpp +++ b/src/keyboard_control.cpp @@ -216,12 +216,10 @@ void keyboard_control::run() case '+': case '-': if (!m_locked_against_changes) { - int audio_delay = audio_offset > 0 ? audio_offset : - -video_offset; + int audio_delay = get_audio_delay(); audio_delay += c == '+' ? 10 : -10; log_msg(LOG_LEVEL_INFO, "New audio delay: %d ms.\n", audio_delay); - audio_offset = max(audio_delay, 0); - video_offset = audio_delay < 0 ? abs(audio_delay) : 0; + set_audio_delay(audio_delay); } else { LOCKED_MSG(); } @@ -268,8 +266,7 @@ void keyboard_control::usage() "\n"; cout << "Verbosity level: " << log_level << (log_level == LOG_LEVEL_INFO ? " (default)" : "") << "\n"; cout << "Locked against changes: " << (m_locked_against_changes ? "true" : "false") << "\n"; - int audio_delay = audio_offset > 0 ? audio_offset : -video_offset; - cout << "Audio playback delay: " << audio_delay << " ms\n"; + cout << "Audio playback delay: " << get_audio_delay() << " ms\n"; { char path[] = "audio.receiver";