Allow the player thread variable to be a null to indicate presence or absence of player thread

This commit is contained in:
Mike Brady
2017-08-25 21:59:52 +01:00
parent fe6ae61d09
commit 06fa348504
3 changed files with 27 additions and 24 deletions
+15 -10
View File
@@ -2433,11 +2433,10 @@ void player_flush(int64_t timestamp, rtsp_conn_info *conn) {
#endif
}
int player_play(pthread_t *player_thread, rtsp_conn_info *conn) {
int player_play(rtsp_conn_info *conn) {
// need to use conn in place of streram below. Need to put the stream as a parameter to he
// if (*player_thread!=NULL)
// die("Trying to create a second player thread for this RTSP session");
if (conn->player_thread!=NULL)
die("Trying to create a second player thread for this RTSP session");
if (config.buffer_start_fill > BUFFER_FRAMES)
die("specified buffer starting fill %d > buffer size %d", config.buffer_start_fill,
BUFFER_FRAMES);
@@ -2445,28 +2444,34 @@ int player_play(pthread_t *player_thread, rtsp_conn_info *conn) {
#ifdef CONFIG_METADATA
send_ssnc_metadata('pbeg', NULL, 0, 1);
#endif
pthread_t *pt = malloc(sizeof(pthread_t));
if (pt==NULL)
die("Couldn't allocate space for pthread_t");
conn->player_thread = pt;
size_t size = (PTHREAD_STACK_MIN + 256 * 1024);
pthread_attr_t tattr;
pthread_attr_init(&tattr);
int rc = pthread_attr_setstacksize(&tattr, size);
if (rc)
debug(1, "Error setting stack size for player_thread: %s", strerror(errno));
pthread_create(player_thread, &tattr, player_thread_func, (void *)conn);
pthread_create(pt, &tattr, player_thread_func, (void *)conn);
pthread_attr_destroy(&tattr);
return 0;
}
void player_stop(pthread_t *player_thread, rtsp_conn_info *conn) {
if (player_thread) {
void player_stop(rtsp_conn_info *conn) {
if (conn->player_thread) {
conn->player_thread_please_stop = 1;
pthread_cond_signal(&conn->flowcontrol); // tell it to give up
pthread_join(*player_thread, NULL);
pthread_kill(*conn->player_thread, SIGUSR1);
pthread_join(*conn->player_thread, NULL);
#ifdef CONFIG_METADATA
send_ssnc_metadata('pend', NULL, 0, 1);
#endif
command_stop();
player_thread = NULL;
free(conn->player_thread);
conn->player_thread = NULL;
} else {
debug(1,"Attempting to kill the non-existent player thread of RTSP conversation %d.",conn->connection_number);
debug(1,"player thread of RTSP conversation %d is already deleted.",conn->connection_number);
}
}
+5 -3
View File
@@ -60,7 +60,9 @@ typedef struct {
int stop;
int running;
pthread_t thread;
pthread_t player_thread;
// pthread_t *ptp;
pthread_t *player_thread;
abuf_t audio_buffer[BUFFER_FRAMES];
int max_frames_per_packet, input_num_channels, input_bit_depth, input_rate;
@@ -160,8 +162,8 @@ typedef struct {
} rtsp_conn_info;
int player_play(pthread_t *thread, rtsp_conn_info *conn);
void player_stop(pthread_t *thread, rtsp_conn_info *conn);
int player_play(rtsp_conn_info *conn);
void player_stop(rtsp_conn_info *conn);
void player_volume(double f, rtsp_conn_info *conn);
void player_flush(int64_t timestamp, rtsp_conn_info *conn);
+7 -11
View File
@@ -672,14 +672,10 @@ static void handle_teardown(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag
resp->respcode = 200;
msg_add_header(resp, "Connection", "close");
debug(1, "TEARDOWN: synchronous closing the player thread of RTSP conversation thread %d (2).",conn->connection_number);
debug(1, "TEARDOWN: synchronously terminating the player thread of RTSP conversation thread %d (2).",conn->connection_number);
if (rtsp_playing()) {
player_stop(&conn->player_thread, conn); // might be less noisy doing this first
player_stop(conn); // might be less noisy doing this first
}
debug(1,"TEARDOWN leaving the conversation thread open...");
//debug(1, "RTSP conversation thread %d synchronously closed (2).",conn->connection_number);
//conn->stop = 1;
// usleep(1000000);
}
static void handle_flush(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) {
@@ -833,7 +829,7 @@ static void handle_setup(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *
strcat(hdr, q); // should unsplice the timing port entry
}
player_play(&conn->player_thread, conn); // the thread better be 0
player_play(conn); // the thread better be 0
char *resphdr = alloca(200);
*resphdr = 0;
@@ -1828,11 +1824,11 @@ static void *rtsp_conversation_thread_func(void *pconn) {
if ((reply==rtsp_read_request_response_immediate_shutdown_requested) ||
(reply==rtsp_read_request_response_channel_closed)) {
debug(1, "Synchronous closing down of RTSP conversation thread %d (1).",conn->connection_number);
if (rtsp_playing()) {
player_stop(&conn->player_thread, conn); // might be less noisy doing this first
if ((rtsp_playing()) && (conn->player_thread)) {
debug(1, "Synchronously terminate playing thread of RTSP conversation thread %d.",conn->connection_number);
player_stop(conn); // might be less noisy doing this first
}
debug(1, "RTSP conversation thread %d synchronously closed (1).",conn->connection_number);
debug(1, "Synchronously terminate RTSP conversation thread %d.",conn->connection_number);
conn->stop = 1;
} else {
debug(1, "rtsp_read_request error %d, packet ignored.", (int)reply);