- improve latency measurement and make sync almost perfect
Signed-off-by: Karl Osterseher <karli_o@gmx.at>
This commit is contained in:
@@ -54,9 +54,9 @@ int64_t MEDIANFILTER_Insert(sMedianFilter_t *medianFilter, int64_t sample) {
|
||||
unsigned int i;
|
||||
sMedianNode_t *newNode, *it;
|
||||
|
||||
if (medianFilter->ageHead ==
|
||||
medianFilter->valueHead) { // if oldest node is also the smallest node,
|
||||
// increment value head
|
||||
// if oldest node is also the smallest node,
|
||||
// increment value head
|
||||
if (medianFilter->ageHead == medianFilter->valueHead) {
|
||||
medianFilter->valueHead = medianFilter->valueHead->nextValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
#define CHNK_CTRL_CNT 2
|
||||
|
||||
#define LATENCY_MEDIAN_FILTER_LEN 199 // 299 //499 // 199 // 29 // 99
|
||||
#define LATENCY_MEDIAN_AVG_DIVISOR \
|
||||
0 // set to 0 if you do not wish to be the median an average around actual
|
||||
// median average will be (LATENCY_MEDIAN_FILTER_LEN /
|
||||
// LATENCY_MEDIAN_AVG_DIVISOR) + 1 samples around median. e.g. if n=4 then
|
||||
// 2 samples above and below will be added plus the actual median. So in
|
||||
// reality n+1 samples will be averaged
|
||||
|
||||
// set to 0 if you do not wish to be the median an average around actual
|
||||
// median average will be (LATENCY_MEDIAN_FILTER_LEN /
|
||||
// LATENCY_MEDIAN_AVG_DIVISOR) + 1 samples around median. e.g. if n=4 then
|
||||
// 2 samples above and below will be added plus the actual median. So in
|
||||
// reality n+1 samples will be averaged
|
||||
#define LATENCY_MEDIAN_AVG_DIVISOR 0
|
||||
|
||||
#define SHORT_BUFFER_LEN 199 // 99
|
||||
#define MINI_BUFFER_LEN 39 // 19
|
||||
|
||||
@@ -1386,8 +1386,9 @@ static void player_task(void *pvParameters) {
|
||||
usec = usec % 1000;
|
||||
// ESP_LOGI (TAG, "%d, %lldus, %lldus %llds, %lld.%lldms", dir, age,
|
||||
// avg, sec, msec, usec);
|
||||
ESP_LOGI(TAG, "%d, %lldus, %lldus, %lldus", dir, avg, shortMedian,
|
||||
miniMedian);
|
||||
// ESP_LOGI(TAG, "%d, %lldus, %lldus, %lldus", dir, avg,
|
||||
// shortMedian,
|
||||
// miniMedian);
|
||||
}
|
||||
|
||||
dir = 0;
|
||||
|
||||
28
main/main.c
28
main/main.c
@@ -75,8 +75,8 @@ SemaphoreHandle_t decoderWriteSemaphore = NULL;
|
||||
|
||||
const char *VERSION_STRING = "0.0.2";
|
||||
|
||||
#define HTTP_TASK_PRIORITY 9
|
||||
#define HTTP_TASK_CORE_ID tskNO_AFFINITY // 1 // tskNO_AFFINITY
|
||||
#define HTTP_TASK_PRIORITY (configMAX_PRIORITIES - 2) // 9
|
||||
#define HTTP_TASK_CORE_ID 1 // 1 // tskNO_AFFINITY
|
||||
|
||||
#define OTA_TASK_PRIORITY 6
|
||||
#define OTA_TASK_CORE_ID tskNO_AFFINITY // 1 // tskNO_AFFINITY
|
||||
@@ -138,8 +138,10 @@ void time_sync_msg_cb(void *args);
|
||||
|
||||
static char base_message_serialized[BASE_MESSAGE_SIZE];
|
||||
static char time_message_serialized[TIME_MESSAGE_SIZE];
|
||||
static const esp_timer_create_args_t tSyncArgs = {.callback = &time_sync_msg_cb,
|
||||
.name = "tSyncMsg"};
|
||||
static const esp_timer_create_args_t tSyncArgs = {
|
||||
.callback = &time_sync_msg_cb,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
.name = "tSyncMsg"};
|
||||
|
||||
struct netconn *lwipNetconn;
|
||||
|
||||
@@ -198,6 +200,7 @@ void time_sync_msg_cb(void *args) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
rc1 = netconn_write(lwipNetconn, base_message_serialized, BASE_MESSAGE_SIZE,
|
||||
NETCONN_NOCOPY);
|
||||
if (rc1 != ERR_OK) {
|
||||
@@ -213,6 +216,20 @@ void time_sync_msg_cb(void *args) {
|
||||
|
||||
return;
|
||||
}
|
||||
#else
|
||||
uint8_t *p_pkt = (uint8_t *)malloc(BASE_MESSAGE_SIZE + TIME_MESSAGE_SIZE);
|
||||
memcpy(&p_pkt[0], base_message_serialized, BASE_MESSAGE_SIZE);
|
||||
memcpy(&p_pkt[BASE_MESSAGE_SIZE], time_message_serialized, TIME_MESSAGE_SIZE);
|
||||
|
||||
rc1 = netconn_write(lwipNetconn, p_pkt, BASE_MESSAGE_SIZE + TIME_MESSAGE_SIZE,
|
||||
NETCONN_NOCOPY);
|
||||
if (rc1 != ERR_OK) {
|
||||
ESP_LOGW(TAG, "error writing timesync msg");
|
||||
|
||||
return;
|
||||
}
|
||||
free(p_pkt);
|
||||
#endif
|
||||
|
||||
// ESP_LOGI(TAG, "%s: sent time sync message", __func__);
|
||||
|
||||
@@ -2332,8 +2349,7 @@ static void http_get_task(void *pvParameters) {
|
||||
|
||||
player_latency_insert(tmpDiffToServer);
|
||||
|
||||
// ESP_LOGI(TAG, "Current latency: %lld",
|
||||
// tmpDiffToServer);
|
||||
ESP_LOGI(TAG, "Current latency: %lld", tmpDiffToServer);
|
||||
|
||||
// store current time
|
||||
lastTimeSync = now;
|
||||
|
||||
Reference in New Issue
Block a user