Преглед изворни кода

Merge pull request #2228 from devsaurus/pcm_fix_leak

Fix leak in pcm for subsequent object creation
Terry Ellison пре 6 година
родитељ
комит
73c9700b00
4 измењених фајлова са 22 додато и 16 уклоњено
  1. 10 6
      app/modules/pcm.c
  2. 3 3
      app/pcm/drv_sigma_delta.c
  3. 6 4
      app/pcm/pcm.h
  4. 3 3
      app/pcm/pcm_core.c

+ 10 - 6
app/modules/pcm.c

@@ -19,6 +19,9 @@
 #define COND_REF(_cond) _cond ? luaL_ref( L, LUA_REGISTRYINDEX ) : LUA_NOREF
 
 
+// task handles
+task_handle_t pcm_data_vu_task, pcm_data_play_task, pcm_start_play_task;
+
 static void dispatch_callback( lua_State *L, int self_ref, int cb_ref, int returns )
 {
   if (cb_ref != LUA_NOREF) {
@@ -94,7 +97,7 @@ static int pcm_drv_pause( lua_State *L )
   return 0;
 }
 
-static void pcm_start_play_task( task_param_t param, uint8 prio )
+static void pcm_start_play( task_param_t param, uint8 prio )
 {
   lua_State *L = lua_getstate();
   pud_t *pud = (pud_t *)param;
@@ -126,8 +129,8 @@ static int pcm_drv_play( lua_State *L )
   }
 
   // schedule actions for play in separate task since drv:play() might have been called
-  // in the callback fn of pcm_data_play_task() which in turn gets called when starting play...
-  task_post_low( cfg->start_play_task, (os_param_t)pud );
+  // in the callback fn of pcm_data_play() which in turn gets called when starting play...
+  task_post_low( pcm_start_play_task, (os_param_t)pud );
 
   return 0;
 }
@@ -203,10 +206,7 @@ static int pcm_new( lua_State *L )
   cfg->bufs[0].rpos     = cfg->bufs[1].rpos     = 0;
   cfg->bufs[0].empty    = cfg->bufs[1].empty    = TRUE;
 
-  cfg->data_vu_task    = task_get_id( pcm_data_vu_task );
   cfg->vu_freq         = 10;
-  cfg->data_play_task  = task_get_id( pcm_data_play_task );
-  cfg->start_play_task = task_get_id( pcm_start_play_task );
 
   if (driver == PCM_DRIVER_SD) {
     cfg->pin = luaL_checkinteger( L, 2 );
@@ -257,6 +257,10 @@ static const LUA_REG_TYPE pcm_map[] = {
 
 int luaopen_pcm( lua_State *L ) {
   luaL_rometatable( L, "pcm.driver", (void *)pcm_driver_map );  // create metatable
+
+  pcm_data_vu_task    = task_get_id( pcm_data_vu );
+  pcm_data_play_task  = task_get_id( pcm_data_play );
+  pcm_start_play_task = task_get_id( pcm_start_play );
   return 0;
 }
 

+ 3 - 3
app/pcm/drv_sigma_delta.c

@@ -33,7 +33,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
     if (cfg->vu_samples_tmp >= cfg->vu_req_samples) {
       cfg->vu_peak = cfg->vu_peak_tmp;
 
-      task_post_low( cfg->data_vu_task, (os_param_t)cfg );
+      task_post_low( pcm_data_vu_task, (os_param_t)cfg );
 
       cfg->vu_samples_tmp = 0;
       cfg->vu_peak_tmp    = 0;
@@ -44,7 +44,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
       // buffer data consumed, request to re-fill it
       buf->empty = TRUE;
       cfg->fbuf_idx = cfg->rbuf_idx;
-      task_post_high( cfg->data_play_task, (os_param_t)cfg );
+      task_post_high( pcm_data_play_task, (os_param_t)cfg );
       // switch to next buffer
       cfg->rbuf_idx ^= 1;
       dbg_platform_gpio_write( PLATFORM_GPIO_LOW );
@@ -54,7 +54,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
     cfg->isr_throttled = 1;
     dbg_platform_gpio_write( PLATFORM_GPIO_LOW );
     cfg->fbuf_idx = cfg->rbuf_idx;
-    task_post_high( cfg->data_play_task, (os_param_t)cfg );
+    task_post_high( pcm_data_play_task, (os_param_t)cfg );
   }
 
 }

+ 6 - 4
app/pcm/pcm.h

@@ -4,6 +4,7 @@
 #define _PCM_H
 
 
+#include "task/task.h"
 #include "platform.h"
 
 
@@ -63,8 +64,6 @@ typedef struct {
   // buffer selectors
   uint8_t rbuf_idx;   // read by ISR
   uint8_t fbuf_idx;   // fill by data task
-  // task handles
-  task_handle_t data_vu_task, data_play_task, start_play_task;
   // callback fn refs
   int self_ref;
     int cb_data_ref, cb_drained_ref, cb_paused_ref, cb_stopped_ref, cb_vu_ref;
@@ -95,7 +94,10 @@ typedef struct {
 } pud_t;
 
 
-void pcm_data_vu_task( task_param_t param, uint8 prio );
-void pcm_data_play_task( task_param_t param, uint8 prio );
+void pcm_data_vu( task_param_t param, uint8 prio );
+void pcm_data_play( task_param_t param, uint8 prio );
+
+// task handles
+extern task_handle_t pcm_data_vu_task, pcm_data_play_task, pcm_start_play_task;
 
 #endif /* _PCM_H */

+ 3 - 3
app/pcm/pcm_core.c

@@ -27,7 +27,7 @@ static void dispatch_callback( lua_State *L, int self_ref, int cb_ref, int retur
   }
 }
 
-void pcm_data_vu_task( task_param_t param, uint8 prio )
+void pcm_data_vu( task_param_t param, uint8 prio )
 {
   cfg_t *cfg = (cfg_t *)param;
   lua_State *L = lua_getstate();
@@ -40,7 +40,7 @@ void pcm_data_vu_task( task_param_t param, uint8 prio )
   }
 }
 
-void pcm_data_play_task( task_param_t param, uint8 prio )
+void pcm_data_play( task_param_t param, uint8 prio )
 {
   cfg_t *cfg = (cfg_t *)param;
   pcm_buf_t *buf = &(cfg->bufs[cfg->fbuf_idx]);
@@ -85,7 +85,7 @@ void pcm_data_play_task( task_param_t param, uint8 prio )
         // rerun data callback to get next buffer chunk
         dbg_platform_gpio_write( PLATFORM_GPIO_LOW );
         cfg->fbuf_idx = other_buf;
-        pcm_data_play_task( param, 0 );
+        pcm_data_play( param, 0 );
       }
       // unthrottle ISR
       cfg->isr_throttled = 0;