Add proper data structure for passing parameters between threads. Add some debug messages.
This commit is contained in:
@@ -893,12 +893,13 @@ typedef struct stats { // statistics for running averages
|
||||
} stats_t;
|
||||
|
||||
static void *player_thread_func(void *arg) {
|
||||
int threads_stop = 0;
|
||||
struct inter_threads_record itr;
|
||||
itr.please_stop = 0; // this will be used to signal to the subsidiary threads
|
||||
// create and start the timing, control and audio receiver threads
|
||||
pthread_t rtp_audio_thread, rtp_control_thread, rtp_timing_thread;
|
||||
pthread_create(&rtp_audio_thread, NULL, &rtp_audio_receiver, (void *)&threads_stop);
|
||||
pthread_create(&rtp_control_thread, NULL, &rtp_control_receiver, (void *)&threads_stop);
|
||||
pthread_create(&rtp_timing_thread, NULL, &rtp_timing_receiver, (void *)&threads_stop);
|
||||
pthread_create(&rtp_audio_thread, NULL, &rtp_audio_receiver, (void *)&itr);
|
||||
pthread_create(&rtp_control_thread, NULL, &rtp_control_receiver, (void *)&itr);
|
||||
pthread_create(&rtp_timing_thread, NULL, &rtp_timing_receiver, (void *)&itr);
|
||||
|
||||
session_corrections = 0;
|
||||
play_segment_reference_frame = 0; // zero signals that we are not in a play segment
|
||||
@@ -1232,6 +1233,7 @@ static void *player_thread_func(void *arg) {
|
||||
free(silence);
|
||||
debug(1,"Shut down audio, control and timing threads");
|
||||
// usleep(1000000);
|
||||
itr.please_stop = 1;
|
||||
pthread_kill(rtp_audio_thread, SIGUSR1);
|
||||
pthread_kill(rtp_control_thread, SIGUSR1);
|
||||
pthread_kill(rtp_timing_thread, SIGUSR1);
|
||||
|
||||
@@ -47,11 +47,6 @@
|
||||
#include <linux/in6.h>
|
||||
#endif
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t seconds;
|
||||
uint32_t fraction;
|
||||
} ntp_timestamp;
|
||||
|
||||
typedef struct time_ping_record {
|
||||
uint64_t local_to_remote_difference;
|
||||
uint64_t dispersion;
|
||||
@@ -96,15 +91,16 @@ static pthread_mutex_t reference_time_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
uint64_t static local_to_remote_time_difference; // used to switch between local and remote clocks
|
||||
|
||||
void *rtp_audio_receiver(void *arg) {
|
||||
// we inherit the signal mask (SIGUSR1)
|
||||
debug(2, "Audio receiver -- Server RTP thread starting.");
|
||||
|
||||
int *stop = arg; // when set to 1, we should stop
|
||||
// we inherit the signal mask (SIGUSR1)
|
||||
struct inter_threads_record *itr = arg;
|
||||
|
||||
int32_t last_seqno = -1;
|
||||
uint8_t packet[2048], *pktp;
|
||||
|
||||
ssize_t nread;
|
||||
while (*stop==0) {
|
||||
while (itr->please_stop==0) {
|
||||
nread = recv(audio_socket, packet, sizeof(packet), 0);
|
||||
if (nread < 0)
|
||||
break;
|
||||
@@ -160,7 +156,8 @@ void *rtp_audio_receiver(void *arg) {
|
||||
void *rtp_control_receiver(void *arg) {
|
||||
// we inherit the signal mask (SIGUSR1)
|
||||
|
||||
int *stop = arg; // when set to 1, we should stop
|
||||
debug(2, "Control receiver -- Server RTP thread starting.");
|
||||
struct inter_threads_record *itr = arg;
|
||||
|
||||
reference_timestamp = 0; // nothing valid received yet
|
||||
uint8_t packet[2048], *pktp;
|
||||
@@ -168,7 +165,7 @@ void *rtp_control_receiver(void *arg) {
|
||||
uint64_t remote_time_of_sync, local_time_now, remote_time_now;
|
||||
uint32_t sync_rtp_timestamp, rtp_timestamp_less_latency;
|
||||
ssize_t nread;
|
||||
while (*stop==0) {
|
||||
while (itr->please_stop==0) {
|
||||
nread = recv(control_socket, packet, sizeof(packet), 0);
|
||||
local_time_now = get_absolute_time_in_fp();
|
||||
// clock_gettime(CLOCK_MONOTONIC,&tn);
|
||||
@@ -260,6 +257,7 @@ void *rtp_control_receiver(void *arg) {
|
||||
}
|
||||
|
||||
void *rtp_timing_sender(void *arg) {
|
||||
debug(2, "Timing sender thread starting.");
|
||||
int *stop = arg; // the parameter points to this request to stop thing
|
||||
struct timing_request {
|
||||
char leader;
|
||||
@@ -315,9 +313,10 @@ void *rtp_timing_sender(void *arg) {
|
||||
}
|
||||
|
||||
void *rtp_timing_receiver(void *arg) {
|
||||
debug(2, "Timing receiver -- Server RTP thread starting.");
|
||||
// we inherit the signal mask (SIGUSR1)
|
||||
|
||||
int *stop = arg; // when set to 1, we should stop
|
||||
struct inter_threads_record *itr = arg;
|
||||
|
||||
uint8_t packet[2048], *pktp;
|
||||
ssize_t nread;
|
||||
@@ -335,7 +334,7 @@ void *rtp_timing_receiver(void *arg) {
|
||||
uint64_t first_local_to_remote_time_difference = 0;
|
||||
uint64_t first_local_to_remote_time_difference_time;
|
||||
uint64_t l2rtd = 0;
|
||||
while (*stop==0) {
|
||||
while (itr->please_stop==0) {
|
||||
nread = recv(timing_socket, packet, sizeof(packet), 0);
|
||||
arrival_time = get_absolute_time_in_fp();
|
||||
// clock_gettime(CLOCK_MONOTONIC,&att);
|
||||
|
||||
Reference in New Issue
Block a user