Skip to content

Commit 04a7141

Browse files
DavidLesnjakRobertRostohar
authored andcommitted
SDS PLAY: Update driver
- Improve performance - Update configuration file
1 parent 52a0c6b commit 04a7141

File tree

3 files changed

+56
-87
lines changed

3 files changed

+56
-87
lines changed

ARM.SDS.pdsc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<releases>
1111
<release version="0.0.0">
1212
Active Development ...
13+
SDS Player:
14+
- Improve performance
15+
- Update configuration file
1316
SDSIO-Server:
1417
- Correct response handling for open and read commands
1518
- Remove automatic file open after .sds file index is reset in read mode
@@ -169,15 +172,15 @@
169172
</component>
170173

171174
<!-- SDS Player -->
172-
<component Cclass="SDS" Cgroup="Player" Cvariant="CMSIS-RTOS2" Cversion="1.0.0" condition="SDS Player with CMSIS-RTOS2">
175+
<component Cclass="SDS" Cgroup="Player" Cvariant="CMSIS-RTOS2" Cversion="2.0.0" condition="SDS Player with CMSIS-RTOS2">
173176
<description>Play from Input device</description>
174177
<RTE_Components_h>
175178
#define RTE_SDS_PLAYER /* Synchronous Data Stream Player */
176179
</RTE_Components_h>
177180
<files>
178181
<file category="header" name="sds/include/sds_play.h"/>
179182
<file category="source" name="sds/source/sds_play.c"/>
180-
<file category="header" name="sds/config/sds_play_config.h" attr="config" version="1.0.0"/>
183+
<file category="header" name="sds/config/sds_play_config.h" attr="config" version="2.0.0"/>
181184
</files>
182185
</component>
183186
</components>

sds/config/sds_play_config.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Arm Limited. All rights reserved.
2+
* Copyright (c) 2023-2024 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -17,7 +17,7 @@
1717
*
1818
* Name: sds_play_config.h
1919
* Purpose: SDS Player configuration options
20-
* Rev.: V1.0.0
20+
* Rev.: V2.0.0
2121
*/
2222

2323
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
@@ -26,11 +26,11 @@
2626

2727
// <o>Maximum number of player streams <1-31>
2828
// <i>Default: 16
29-
#define SDS_PLAY_MAX_STREAMS 16U
29+
#define SDS_PLAY_MAX_STREAMS 16U
3030

31-
// <o>Maximum size of a record
31+
// <o>Size of a temporary player buffer
3232
// <i>Default: 8192
33-
#define SDS_PLAY_MAX_RECORD_SIZE 8192U
33+
#define SDS_PLAY_BUF_SIZE 8192U
3434

3535
// </h>
3636

sds/source/sds_play.c

Lines changed: 46 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Arm Limited. All rights reserved.
2+
* Copyright (c) 2023-2024 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -48,17 +48,15 @@ typedef struct {
4848
uint32_t buf_size;
4949
sdsId_t stream;
5050
sdsioId_t sdsio;
51-
PlayHead_t head_in;
5251
PlayHead_t head_out;
53-
volatile uint32_t cnt_in;
54-
volatile uint32_t cnt_out;
52+
uint32_t record_data_cnt;
5553
} sdsPlay_t;
5654

5755
static sdsPlay_t PlayStreams[SDS_PLAY_MAX_STREAMS] = {0};
5856
static sdsPlay_t *pPlayStreams[SDS_PLAY_MAX_STREAMS] = {NULL};
5957

6058
// Player buffer
61-
static uint8_t PlayBuf[SDS_PLAY_MAX_RECORD_SIZE];
59+
static uint8_t PlayBuf[SDS_PLAY_BUF_SIZE];
6260

6361
// Event callback
6462
static sdsPlayEvent_t sdsPlayEvent = NULL;
@@ -153,7 +151,7 @@ static void sdsPlayEventCallback (sdsId_t id, uint32_t event, void *arg) {
153151
// Player thread
154152
static __NO_RETURN void sdsPlayThread (void *arg) {
155153
sdsPlay_t *play;
156-
uint32_t size, num, flags, n;
154+
uint32_t flags, cnt, num, n;
157155
(void)arg;
158156

159157
while (1) {
@@ -175,55 +173,30 @@ static __NO_RETURN void sdsPlayThread (void *arg) {
175173
osEventFlagsSet(sdsPlayCloseEventFlags, 1U << play->index);
176174
continue;
177175
}
178-
do {
179-
if (play->head_in.data_size == 0U) {
180-
// Read new header
181-
num = sdsioRead(play->sdsio, &play->head_in, HEAD_SIZE);
182-
if (num == 0U) {
183-
if (sdsioEndOfStream(play->sdsio) == 0) {
184-
if (sdsPlayEvent != NULL) {
185-
sdsPlayEvent(play, SDS_PLAY_EVENT_IO_ERROR);
186-
}
187-
} else {
188-
play->flags |= SDS_PLAY_FLAG_EOS;
189-
}
190-
break;
191-
}
192176

193-
if (num == HEAD_SIZE) {
194-
if (play->head_in.data_size == 0U) {
195-
break;
196-
}
197-
} else {
198-
if (sdsPlayEvent != NULL) {
199-
sdsPlayEvent(play, SDS_PLAY_EVENT_IO_ERROR);
200-
}
201-
break;
202-
}
203-
}
204-
205-
size = play->head_in.data_size + HEAD_SIZE;
206-
if (size > SDS_PLAY_MAX_RECORD_SIZE) {
207-
if (sdsPlayEvent != NULL) {
208-
sdsPlayEvent(play, SDS_PLAY_EVENT_IO_ERROR);
209-
}
177+
while (1) {
178+
cnt = play->buf_size - sdsGetCount(play->stream);
179+
if (cnt == 0U) {
210180
break;
211181
}
212-
if (size <= (play->buf_size - sdsGetCount(play->stream))) {
213-
memcpy(PlayBuf, &play->head_in, HEAD_SIZE);
214-
if (sdsioRead(play->sdsio, PlayBuf + HEAD_SIZE, play->head_in.data_size) == play->head_in.data_size) {
215-
if (sdsWrite(play->stream, PlayBuf, size) == size) {
216-
play->head_in.data_size = 0U;
217-
play->cnt_in++;
218-
}
182+
if (cnt > sizeof(PlayBuf)) {
183+
cnt = sizeof(PlayBuf);
184+
}
185+
num = sdsioRead(play->sdsio, PlayBuf, cnt);
186+
if (num != 0U) {
187+
sdsWrite(play->stream, PlayBuf, num);
188+
}
189+
if (num != cnt) {
190+
if (sdsioEndOfStream(play->sdsio) != 0) {
191+
play->flags |= SDS_PLAY_FLAG_EOS;
219192
} else {
220193
if (sdsPlayEvent != NULL) {
221194
sdsPlayEvent(play, SDS_PLAY_EVENT_IO_ERROR);
222195
}
223-
break;
224196
}
197+
break;
225198
}
226-
} while (play->head_in.data_size == 0U);
199+
}
227200
}
228201
}
229202
}
@@ -270,7 +243,7 @@ sdsPlayId_t sdsPlayOpen (const char *name, void *buf, uint32_t buf_size, uint32_
270243
uint32_t index;
271244

272245
if ((name != NULL) && (buf != NULL) && (buf_size != 0U) &&
273-
(buf_size <= SDS_PLAY_MAX_RECORD_SIZE) && (io_threshold <= buf_size)) {
246+
(buf_size <= SDS_PLAY_BUF_SIZE) && (io_threshold <= buf_size)) {
274247

275248
play = sdsPlayAlloc(&index);
276249
if (play != NULL) {
@@ -279,12 +252,9 @@ sdsPlayId_t sdsPlayOpen (const char *name, void *buf, uint32_t buf_size, uint32_
279252
play->event_close = 0U;
280253
play->flags = 0U;
281254
play->buf_size = buf_size;
282-
play->head_in.timestamp = 0U;
283-
play->head_in.data_size = 0U;
284255
play->head_out.timestamp = 0U;
285256
play->head_out.data_size = 0U;
286-
play->cnt_in = 0U;
287-
play->cnt_out = 0U;
257+
play->record_data_cnt = 0U;
288258
play->stream = sdsOpen(buf, buf_size, io_threshold, 0U);
289259
play->sdsio = sdsioOpen(name, sdsioModeRead);
290260

@@ -335,28 +305,25 @@ int32_t sdsPlayClose (sdsPlayId_t id) {
335305
uint32_t sdsPlayRead (sdsPlayId_t id, uint32_t *timestamp, void *buf, uint32_t buf_size) {
336306
sdsPlay_t *play = id;
337307
uint32_t num = 0U;
308+
uint32_t size;
338309

339310
if ((play != NULL) && (buf != NULL) && (buf_size != 0U)) {
340-
if (play->cnt_out < play->cnt_in) {
341-
if (play->head_out.data_size == 0U) {
342-
if (sdsRead(play->stream, &play->head_out, HEAD_SIZE) != HEAD_SIZE) {
343-
play->head_out.data_size = 0U;
311+
size = sdsGetCount(play->stream);
312+
if ((play->head_out.data_size == 0U) && (size >= HEAD_SIZE)) {
313+
sdsRead(play->stream, &play->head_out, HEAD_SIZE);
314+
size -= HEAD_SIZE;
315+
}
316+
317+
if ((play->head_out.data_size != 0U) && (play->head_out.data_size <= size)) {
318+
if (play->head_out.data_size <= buf_size) {
319+
num = sdsRead(play->stream, buf, play->head_out.data_size);
320+
if (timestamp != NULL) {
321+
*timestamp = play->head_out.timestamp;
344322
}
345-
}
346-
if (play->head_out.data_size != 0U) {
347-
if (play->head_out.data_size <= buf_size) {
348-
if (sdsRead(play->stream, buf, play->head_out.data_size) == play->head_out.data_size) {
349-
if (timestamp != NULL) {
350-
*timestamp = play->head_out.timestamp;
351-
}
352-
num = play->head_out.data_size;
353-
play->head_out.data_size = 0U;
354-
play->cnt_out++;
355-
if (play->event_threshold != 0U) {
356-
play->event_threshold = 0U;
357-
osThreadFlagsSet(sdsPlayThreadId, 1U << play->index);
358-
}
359-
}
323+
play->head_out.data_size = 0U;
324+
if (play->event_threshold != 0U) {
325+
play->event_threshold = 0U;
326+
osThreadFlagsSet(sdsPlayThreadId, 1U << play->index);
360327
}
361328
}
362329
}
@@ -367,20 +334,19 @@ uint32_t sdsPlayRead (sdsPlayId_t id, uint32_t *timestamp, void *buf, uint32_t b
367334
// Get record data size from Player stream
368335
uint32_t sdsPlayGetSize (sdsPlayId_t id) {
369336
sdsPlay_t *play = id;
370-
uint32_t num = 0U;
337+
uint32_t size = 0U;
338+
uint32_t cnt;
371339

372340
if (play != NULL) {
373-
if (play->cnt_out < play->cnt_in) {
374-
if (play->head_out.data_size == 0U) {
375-
if (sdsRead(play->stream, &play->head_out, HEAD_SIZE) == HEAD_SIZE) {
376-
num = play->head_out.data_size;
377-
} else {
378-
play->head_out.data_size = 0U;
379-
}
341+
if (play->head_out.data_size == 0U) {
342+
cnt = sdsGetCount(play->stream);
343+
if (cnt >= HEAD_SIZE) {
344+
sdsRead(play->stream, &play->head_out, HEAD_SIZE);
380345
}
381346
}
347+
size = play->head_out.data_size;
382348
}
383-
return num;
349+
return size;
384350
}
385351

386352
// Check if end of stream has been reached
@@ -389,7 +355,7 @@ int32_t sdsPlayEndOfStream (sdsPlayId_t id) {
389355
int32_t eos = 0;
390356

391357
if (play != NULL) {
392-
if ((play->cnt_out == play->cnt_in) && ((play->flags & SDS_PLAY_FLAG_EOS) != 0U)) {
358+
if ((sdsGetCount(play->stream) == 0U) && ((play->flags & SDS_PLAY_FLAG_EOS) != 0U)) {
393359
eos = 1;
394360
}
395361
}

0 commit comments

Comments
 (0)