Skip to content

Commit d3b9c3b

Browse files
author
CarlosDerSeher
committed
add ESP_PM_NO_LIGHT_SLEEP lock during active playback
Signed-off-by: CarlosDerSeher <[email protected]>
1 parent bb56710 commit d3b9c3b

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

components/lightsnapcast/player.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sys/time.h>
88

99
#include "driver/i2s_common.h"
10+
#include "esp_pm.h"
1011
#include "freertos/FreeRTOS.h"
1112
#include "freertos/portmacro.h"
1213
#include "freertos/semphr.h"
@@ -23,6 +24,10 @@
2324
#include "clk_ctrl_os.h"
2425
#endif
2526

27+
#if CONFIG_PM_ENABLE
28+
#include "esp_pm.h"
29+
#endif
30+
2631
#include <math.h>
2732

2833
#include "MedianFilter.h"
@@ -41,6 +46,10 @@ static const char *TAG = "PLAYER";
4146

4247
#if USE_SAMPLE_INSERTION
4348

49+
#if CONFIG_PM_ENABLE
50+
esp_pm_lock_handle_t player_pm_lock_handle = NULL;
51+
#endif
52+
4453
#define INSERT_SAMPLES \
4554
1 //!< currently only allowed to be 1 or sync algorithm will break
4655

@@ -413,6 +422,13 @@ int deinit_player(void) {
413422

414423

415424
tg0_timer_deinit();
425+
426+
#if CONFIG_PM_ENABLE
427+
if (player_pm_lock_handle) {
428+
esp_pm_lock_delete(player_pm_lock_handle);
429+
player_pm_lock_handle = NULL;
430+
}
431+
#endif
416432

417433
ESP_LOGI(TAG, "deinit player done");
418434

@@ -472,6 +488,10 @@ int init_player(i2s_std_gpio_config_t pin_config0_, i2s_port_t i2sNum_) {
472488
miniMedianFilter.numNodes = MINI_BUFFER_LEN;
473489
miniMedianFilter.medianBuffer = miniMedianBuffer;
474490
MEDIANFILTER_Init(&miniMedianFilter);
491+
492+
#if CONFIG_PM_ENABLE
493+
esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "player", &player_pm_lock_handle);
494+
#endif
475495

476496
ESP_LOGI(TAG, "init player done");
477497

@@ -503,6 +523,8 @@ int start_player(snapcastSetting_t *setting) {
503523
while(reset_latency_buffer()<0) {
504524
vTaskDelay(pdMS_TO_TICKS(10));
505525
}
526+
527+
esp_pm_lock_acquire(player_pm_lock_handle);
506528
#endif
507529

508530
// create message queue to inform task of changed settings
@@ -1978,7 +2000,9 @@ static void player_task(void *pvParameters) {
19782000
snapcastSettingQueueHandle = NULL;
19792001
xSemaphoreGive(snapcastSettingsMux);
19802002

1981-
2003+
#if CONFIG_PM_ENABLE
2004+
esp_pm_lock_release(player_pm_lock_handle);
2005+
#endif
19822006

19832007
ret = destroy_pcm_queue(&pcmChkQHdl);
19842008

0 commit comments

Comments
 (0)