summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/cell_pcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/esp32/components/eos/cell_pcm.c')
-rw-r--r--fw/esp32/components/eos/cell_pcm.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/fw/esp32/components/eos/cell_pcm.c b/fw/esp32/components/eos/cell_pcm.c
index 3f5089d..67a3a08 100644
--- a/fw/esp32/components/eos/cell_pcm.c
+++ b/fw/esp32/components/eos/cell_pcm.c
@@ -23,16 +23,20 @@ static i2s_chan_handle_t rx_chan;
static const char *TAG = "EOS CELL PCM";
static void pcm_rcvr_task(void *pvParameters) {
- unsigned char *buffer;
+ EOSMessage msg;
size_t size_r;
esp_err_t ret;
int done = 0;
int rv;
while (!done) {
- buffer = eos_net_alloc();
- buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM;
- ret = i2s_channel_read(rx_chan, buffer + 1, PCM_RX_WM, &size_r, 1000);
+ eos_net_alloc(&msg);
+ if (msg.size < PCM_RX_WM + 1) {
+ eos_net_free(&msg);
+ return;
+ }
+ msg.buffer[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM;
+ ret = i2s_channel_read(rx_chan, msg.buffer + 1, PCM_RX_WM, &size_r, 1000);
switch (ret) {
case ESP_OK: {
assert(size_r == PCM_RX_WM);
@@ -51,10 +55,10 @@ static void pcm_rcvr_task(void *pvParameters) {
}
}
if (ret == ESP_OK) {
- rv = eos_net_send(EOS_NET_MTYPE_CELL, buffer, size_r + 1);
+ rv = eos_net_send(EOS_NET_MTYPE_CELL, &msg, size_r + 1);
if (rv) ESP_LOGE(TAG, "NET SEND ERR:%d", rv);
} else {
- eos_net_free(buffer);
+ eos_net_free(&msg);
}
}
vTaskDelete(NULL);