completed -reset option using callback conn_reset

This commit is contained in:
fduncanh
2022-02-06 12:23:36 -05:00
parent 0a5af62fac
commit d5a9a2433b
11 changed files with 92 additions and 48 deletions

View File

@@ -50,6 +50,7 @@
#define DEFAULT_DEBUG_LOG false
#define LOWEST_ALLOWED_PORT 1024
#define HIGHEST_PORT 65535
#define NTP_TIMEOUT_LIMIT 10
static std::string server_name = DEFAULT_NAME;
static int start_raop_server (std::vector<char> hw_addr, std::string name, unsigned short display[5],
@@ -74,10 +75,11 @@ static bool use_video = true;
static unsigned char compression_type = 0;
static std::string audiosink = "autoaudiosink";
static bool use_audio = true;
static bool previous_no_close_behavior = false;
static bool new_window_closing_behavior = true;
static bool close_window;
static std::string decoder = "decodebin";
static bool show_client_FPS_data = false;
static unsigned int max_ntp_timeouts = NTP_TIMEOUT_LIMIT;
static gboolean connection_callback (gpointer loop){
if (!connections_stopped) {
@@ -231,6 +233,7 @@ static void print_info (char *name) {
printf("-as Choose the GStreamer audiosink; default \"autoaudiosink\"\n");
printf(" choices: pulsesink,alsasink,osssink,oss4sink,osxaudiosink,etc.\n");
printf("-as 0 (or -a) Turn audio off, streamed video only\n");
printf("-reset n Reset after 3n seconds client silence (default %d, 0 = never)\n", NTP_TIMEOUT_LIMIT);
printf("-nc do Not Close video window when client stops mirroring\n");
printf("-FPSdata Show video-streaming performance reports sent by client.\n");
printf("-d Enable debug logging\n");
@@ -271,11 +274,13 @@ static bool get_display_settings (std::string value, unsigned short *w, unsigned
}
static bool get_value (const char *str, unsigned int *n) {
// str must be a positive decimal <= input value *n
// if n > 0 str must be a positive decimal <= input value *n
// if n = 0, str must be a non-negative decimal
if (strlen(str) == 0 || strlen(str) > 10 || str[0] == '-') return false;
char *end;
unsigned long l = strtoul(str, &end, 10);
if (*end || l == 0 || (*n > 0 && l > *n)) return false;
if (*end) return false;
if (*n && (l == 0 || l > *n)) return false;
*n = (unsigned int) l;
return true;
}
@@ -448,14 +453,24 @@ int main (int argc, char *argv[]) {
} else if (arg == "-t") {
if (!option_has_value(i, argc, argv[i], argv[i+1])) exit(1);
server_timeout = 0;
get_value(argv[++i], &server_timeout);
bool valid = get_value(argv[++i], &server_timeout);
if (!valid || server_timeout == 0) {
fprintf(stderr,"invalid \"-t %s\", must have -t n with n > 0\n",argv[i]);
exit(1);
}
} else if (arg == "-nc") {
previous_no_close_behavior = true;
new_window_closing_behavior = false;
} else if (arg == "-avdec") {
decoder.erase();
decoder = "h264parse ! avdec_h264";
} else if (arg == "-FPSdata") {
show_client_FPS_data = true;
} else if (arg == "-reset") {
max_ntp_timeouts = 0;
if (!get_value(argv[++i], &max_ntp_timeouts)) {
fprintf(stderr, "invalid \"-reset %s\"; -reset n must have n >= 0, default n = %d\n", argv[i], NTP_TIMEOUT_LIMIT);
exit(1);
}
} else {
LOGE("unknown option %s, stopping\n",argv[i]);
exit(1);
@@ -469,7 +484,7 @@ int main (int argc, char *argv[]) {
#if __APPLE__
/* force use of -nc option on macOS */
LOGI("macOS detected: use -nc option as workaround for GStreamer problem");
previous_no_close_behavior = true;
new_window_closing_behavior = false;
server_timeout = 0;
#endif
@@ -521,6 +536,7 @@ int main (int argc, char *argv[]) {
reconnect:
counter = 0;
compression_type = 0;
close_window = new_window_closing_behavior;
main_loop();
if (relaunch_server || relaunch_video || reset_loop) {
if(reset_loop) {
@@ -529,7 +545,7 @@ int main (int argc, char *argv[]) {
raop_stop(raop);
}
if (use_audio) audio_renderer_stop();
if (use_video) {
if (use_video && close_window) {
video_renderer_destroy();
video_renderer_init(render_logger, server_name.c_str(), videoflip, decoder.c_str(), videosink.c_str());
video_renderer_start();
@@ -575,8 +591,15 @@ extern "C" void conn_destroy (void *cls) {
}
}
extern "C" void conn_reset (void *cls) {
LOGI("***ERROR lost connection with client");
close_window = false; /* leave "frozen" window open */
raop_stop(raop);
reset_loop = true;
}
extern "C" void conn_teardown(void *cls, bool *teardown_96, bool *teardown_110) {
if (*teardown_110 && !previous_no_close_behavior) {
if (*teardown_110 && close_window) {
reset_loop = true;
}
}
@@ -605,12 +628,6 @@ extern "C" void video_flush (void *cls) {
}
}
extern "C" void video_conn_reset (void *cls) {
if (use_video) {
LOGI("***ERROR Exited raop_rtp_mirror thread because ECONNRESET was received");
}
}
extern "C" void audio_set_volume (void *cls, float volume) {
if (use_audio) {
audio_renderer_set_volume(volume);
@@ -658,10 +675,10 @@ int start_raop_server (std::vector<char> hw_addr, std::string name, unsigned sho
memset(&raop_cbs, 0, sizeof(raop_cbs));
raop_cbs.conn_init = conn_init;
raop_cbs.conn_destroy = conn_destroy;
raop_cbs.conn_reset = conn_reset;
raop_cbs.conn_teardown = conn_teardown;
raop_cbs.audio_process = audio_process;
raop_cbs.video_process = video_process;
raop_cbs.video_conn_reset = video_conn_reset;
raop_cbs.audio_flush = audio_flush;
raop_cbs.video_flush = video_flush;
raop_cbs.audio_set_volume = audio_set_volume;
@@ -685,7 +702,8 @@ int start_raop_server (std::vector<char> hw_addr, std::string name, unsigned sho
if (display[4]) raop_set_plist(raop, "overscanned", (int) display[4]);
if (show_client_FPS_data) raop_set_plist(raop, "clientFPSdata", 1);
raop_set_plist(raop, "max_ntp_timeouts", max_ntp_timeouts);
/* network port selection (ports listed as "0" will be dynamically assigned) */
raop_set_tcp_ports(raop, tcp);
raop_set_udp_ports(raop, udp);