]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Begin to add support for monotonic 64-bit timestamps and frame sequence numbers
authorMike Brady <mikebrady@eircom.net>
Fri, 2 Sep 2016 11:22:38 +0000 (12:22 +0100)
committerMike Brady <mikebrady@eircom.net>
Fri, 2 Sep 2016 11:22:38 +0000 (12:22 +0100)
player.c
player.h

index 933ee1bcb605fcfe75ac7e46577eeec3da12ec52..f570ca5a89787abb2cbffe2a4b6ed82be5f411d6 100644 (file)
--- a/player.c
+++ b/player.c
@@ -76,6 +76,9 @@ static AES_KEY aes;
 #endif
 static int input_sample_rate, input_bit_depth, input_num_channels, max_frames_per_packet;
 
+static uint32_t timestamp_epoch; // zero means not initialised, could start at 2 or 1.
+
+
 static int input_bytes_per_frame = 4;
 static int output_bytes_per_frame;
 
@@ -147,6 +150,19 @@ static audio_parameters audio_information;
 // stats
 static uint64_t missing_packets, late_packets, too_late_packets, resend_requests;
 
+// make timestamps and seqnos definitely monotonic
+
+// add an epoch to the timestamp. The monotonic timestamp guaranteed to start between 2^32 and 2^33 frames and continue up to 2^64 frames
+// which is about 4*10^8 * 1,000 seconds at 384,000 frames per second -- about 4 trillion seconds or over 100,000 years.
+// also, it won't reach zero until then, if ever, so we can safely say that a null monotonic timestamp can mean something special
+uint64_t monotonic_timestamp(uint32_t timestamp) {
+
+}
+
+// add an epoch to the seq_no. Uses the accompanying timstamp to detemine the correct epoch
+uint64_t monotonic_seqno(uint16_t seq_no) { 
+}
+
 static void ab_resync(void) {
   int i;
   for (i = 0; i < BUFFER_FRAMES; i++) {
@@ -1086,6 +1102,7 @@ typedef struct stats { // statistics for running averages
 static void *player_thread_func(void *arg) {
        struct inter_threads_record itr;
        itr.please_stop = 0;
+       timestamp_epoch = 0; // indicate that the next timestamp will be the first one.
        // 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 *)&itr);
@@ -1816,7 +1833,7 @@ int player_play(stream_cfg *stream, pthread_t *player_thread) {
 #endif
     aesiv = stream->aesiv;
   }
-  init_decoder(stream->fmtp);
+  init_decoder(stream->fmtp); // this sets up incoming rate, bit depth, channels
   // must be after decoder init
   init_buffer();
   please_stop = 0;
@@ -1844,6 +1861,7 @@ int player_play(stream_cfg *stream, pthread_t *player_thread) {
   rc = pthread_attr_setstacksize(&tattr, size);
   if (rc)
     debug(1, "Error setting stack size for player_thread: %s", strerror(errno));
+  timestamp_epoch = 0;
   pthread_create(player_thread, &tattr, player_thread_func, NULL);
   pthread_attr_destroy(&tattr);
   return 0;
index 9012b0cb81cfabca8bfed3fb8562c974a624626e..d6a16e5add7120232eb595f5984e3de1f7622b0a 100644 (file)
--- a/player.h
+++ b/player.h
@@ -22,4 +22,10 @@ void player_flush(uint32_t timestamp);
 
 void player_put_packet(seq_t seqno, uint32_t timestamp, uint8_t *data, int len);
 
+uint64_t monotonic_timestamp(uint32_t timestamp); // add an epoch to the timestamp. The monotonic timestamp guaranteed to start between 2^32 2^33 frames and continue up to 2^64 frames
+// which is about 4*10^8 * 1,000 seconds at 384,000 frames per second -- about 4 trillion seconds.
+// assumes, without checking, that successive timestamps in a series always span an interval of less than one minute.
+
+uint64_t monotonic_seqno(uint16_t seq_no); // add an epoch to the seq_no. Uses the accompanying timstamp to detemine the correct epoch
+
 #endif //_PLAYER_H