Merge branch 'development' of git.aillwee.com:base/shairport-sync into development

Memory leak fixes, move play lock to the first setup, hold the timing peer list until a full teardown.
This commit is contained in:
Mike Brady
2021-12-07 21:36:56 +00:00
4 changed files with 42 additions and 15 deletions
+1 -1
View File
@@ -112,7 +112,7 @@ static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIn
char portstring[20];
memset(portstring, 0, sizeof(portstring));
snprintf(portstring, sizeof(portstring), "%u", port);
send_ssnc_metadata('dapo', strdup(portstring), strlen(portstring), 0);
send_ssnc_metadata('dapo', portstring, strlen(portstring), 0);
#endif
}
} else {
-5
View File
@@ -1003,11 +1003,6 @@ void rtp_setup(SOCKADDR *local, SOCKADDR *remote, uint16_t cport, uint16_t tport
conn->request_sent = 0;
conn->rtp_running = 1;
#ifdef CONFIG_METADATA
send_ssnc_metadata('clip', conn->client_ip_string, strlen(conn->client_ip_string), 1);
send_ssnc_metadata('svip', conn->self_ip_string, strlen(conn->self_ip_string), 1);
#endif
}
}
+40 -8
View File
@@ -526,6 +526,7 @@ void release_hold_on_play_lock(__attribute__((unused)) rtsp_conn_info *conn) {
}
void release_play_lock(rtsp_conn_info *conn) {
debug(1, "Connection %d: release play lock.", conn->connection_number);
debug_mutex_lock(&playing_conn_lock, 1000000, 3);
if (playing_conn == conn) { // if we have the player
playing_conn = NULL; // let it go
@@ -535,6 +536,7 @@ void release_play_lock(rtsp_conn_info *conn) {
}
int get_play_lock(rtsp_conn_info *conn) {
debug(1, "Connection %d: request play lock.", conn->connection_number);
// returns -1 if it failed, 0 if it succeeded and 1 if it succeeded but
// interrupted an existing session
int response = 0;
@@ -590,7 +592,7 @@ int get_play_lock(rtsp_conn_info *conn) {
}
if ((have_the_player == 1) && (interrupting_current_session == 1)) {
debug(2, "Connection %d: Got player lock", conn->connection_number);
debug(1, "Connection %d: Got player lock", conn->connection_number);
response = 1;
} else {
debug(1, "Connection %d: failed to get player lock", conn->connection_number);
@@ -599,7 +601,7 @@ int get_play_lock(rtsp_conn_info *conn) {
}
if ((have_the_player) && (interrupting_current_session == 0)) {
debug(2, "Connection %d: got player lock.", conn->connection_number);
debug(1, "Connection %d: Got player lock.", conn->connection_number);
response = 0;
}
return response;
@@ -2282,7 +2284,7 @@ void handle_command(__attribute__((unused)) rtsp_conn_info *conn, rtsp_message *
if (item != NULL) {
char *typeValue = NULL;
plist_get_string_val(item, &typeValue);
if (strcmp(typeValue, "updateMRSupportedCommands") == 0) {
if ((typeValue != NULL) && (strcmp(typeValue, "updateMRSupportedCommands") == 0)) {
item = plist_dict_get_item(command_dict, "params");
if (item != NULL) {
// the item should be a dict
@@ -2298,7 +2300,7 @@ void handle_command(__attribute__((unused)) rtsp_conn_info *conn, rtsp_message *
uint64_t length = 0;
plist_get_data_val(the_item, &buff, &length);
// debug(1,"Item %d, length: %" PRId64 " bytes", item_number, length);
if ((length >= strlen("bplist00")) && (strstr(buff, "bplist00") == buff)) {
if ((buff != NULL) && (length >= strlen("bplist00")) && (strstr(buff, "bplist00") == buff)) {
// debug(1,"Contains a plist.");
plist_t subsidiary_plist = NULL;
plist_from_memory(buff, length, &subsidiary_plist);
@@ -2315,6 +2317,8 @@ void handle_command(__attribute__((unused)) rtsp_conn_info *conn, rtsp_message *
debug(1, "Can't access the plist!");
}
}
if (buff != NULL)
free(buff);
}
}
} else {
@@ -2329,6 +2333,8 @@ void handle_command(__attribute__((unused)) rtsp_conn_info *conn, rtsp_message *
"POST /command plist type is \"%s\", but \"updateMRSupportedCommands\" expected.",
typeValue);
}
if (typeValue != NULL)
free(typeValue);
} else {
debug(1, "Could not get the \"type\" item.");
}
@@ -2482,6 +2488,14 @@ void teardown_phase_two(rtsp_conn_info *conn) {
debug(2, "Connection %d: TEARDOWN mdns_update on %s.", conn->connection_number,
get_category_string(conn->airplay_stream_category));
mdns_update(NULL, secondary_txt_records);
if (conn->dacp_active_remote != NULL) {
free(conn->dacp_active_remote);
conn->dacp_active_remote = NULL;
}
if (conn->ap2_timing_peer_list_message) {
free(conn->ap2_timing_peer_list_message);
conn->ap2_timing_peer_list_message = NULL;
}
release_play_lock(conn);
}
}
@@ -2505,10 +2519,10 @@ void handle_teardown_2(rtsp_conn_info *conn, __attribute__((unused)) rtsp_messag
// we are being asked to close a stream
teardown_phase_one(conn);
plist_free(streams);
debug(2, "Connection %d: Stream TEARDOWN complete", conn->connection_number);
debug(1, "Connection %d: TEARDOWN phase one complete", conn->connection_number);
} else {
teardown_phase_two(conn);
debug(2, "Connection %d: non-stream TEARDOWN complete", conn->connection_number);
debug(1, "Connection %d: TEARDOWN phase two complete", conn->connection_number);
}
//} else {
// warn("Connection %d TEARDOWN received without having the player (no ANNOUNCE?)",
@@ -2521,6 +2535,8 @@ void handle_teardown_2(rtsp_conn_info *conn, __attribute__((unused)) rtsp_messag
debug(1, "Connection %d: missing plist!", conn->connection_number);
resp->respcode = 451; // don't know what to do here
}
// debug(1,"Bogus exit for valgrind -- remember to comment it out!.");
// exit(EXIT_SUCCESS); //
}
#endif
@@ -2545,6 +2561,12 @@ void handle_teardown(rtsp_conn_info *conn, __attribute__((unused)) rtsp_message
conn->connection_number);
resp->respcode = 451;
}
if (conn->dacp_active_remote != NULL) {
free(conn->dacp_active_remote);
conn->dacp_active_remote = NULL;
}
// debug(1,"Bogus exit for valgrind -- remember to comment it out!.");
// exit(EXIT_SUCCESS);
}
void handle_flush(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
@@ -2617,6 +2639,11 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
debug(2, "Connection %d: SETUP: PTP setup detected.", conn->connection_number);
conn->airplay_stream_category = ptp_stream;
conn->timing_type = ts_ptp;
get_play_lock(conn);
#ifdef CONFIG_METADATA
send_ssnc_metadata('clip', conn->client_ip_string, strlen(conn->client_ip_string), 1);
send_ssnc_metadata('svip', conn->self_ip_string, strlen(conn->self_ip_string), 1);
#endif
} else if (strcmp(timingProtocolString, "NTP") == 0) {
debug(1, "Connection %d: SETUP: NTP setup detected.", conn->connection_number);
conn->airplay_stream_category = ntp_stream;
@@ -2871,7 +2898,6 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
debug(2, "Connection %d: SETUP on %s. A \"streams\" array has been found",
conn->connection_number, get_category_string(conn->airplay_stream_category));
if (conn->airplay_stream_category == ptp_stream) {
get_play_lock(conn);
// get stream[0]
plist_t stream0 = plist_array_get_item(streams, 0);
@@ -3080,6 +3106,7 @@ void handle_setup_2(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp)
plist_free(setupResponsePlist);
msg_add_header(resp, "Content-Type", "application/x-apple-binary-plist");
}
plist_free(messagePlist);
debug_log_rtsp_message(2, " SETUP response", resp);
}
#endif
@@ -3193,7 +3220,12 @@ void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
} else {
debug(1, "Connection %d: SETUP doesn't contain a Transport header.", conn->connection_number);
}
if (resp->respcode != 200) {
if (resp->respcode == 200) {
#ifdef CONFIG_METADATA
send_ssnc_metadata('clip', conn->client_ip_string, strlen(conn->client_ip_string), 1);
send_ssnc_metadata('svip', conn->self_ip_string, strlen(conn->self_ip_string), 1);
#endif
} else {
debug(1, "Connection %d: SETUP error -- releasing the player lock.", conn->connection_number);
release_play_lock(conn);
}
+1 -1
View File
@@ -1843,7 +1843,7 @@ int main(int argc, char **argv) {
char *uuid = malloc(UUID_STR_LEN);
// Produces a UUID string at uuid consisting of lower-case letters
uuid_unparse_lower(binuuid, uuid);
config.airplay_pi = strdup(uuid);
config.airplay_pi = uuid;
debug(1, "Started in Airplay 2 mode on device \"%s\"!", config.airplay_device_id);
#else
debug(1, "Started in Airplay 1 mode!");