diff options
-rw-r--r-- | apps/talk.c | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/apps/talk.c b/apps/talk.c index 827dd10c2a..9e92a11b51 100644 --- a/apps/talk.c +++ b/apps/talk.c | |||
@@ -550,7 +550,12 @@ alloc_err: | |||
550 | index_handle = core_free(index_handle); | 550 | index_handle = core_free(index_handle); |
551 | return false; | 551 | return false; |
552 | } | 552 | } |
553 | 553 | static inline int load_voicefile_failure(int fd) | |
554 | { | ||
555 | /*if (fd >= 0) probably redundant */ | ||
556 | close(fd); | ||
557 | return -1; | ||
558 | } | ||
554 | /* load the voice file into the mp3 buffer */ | 559 | /* load the voice file into the mp3 buffer */ |
555 | static bool load_voicefile_index(int fd) | 560 | static bool load_voicefile_index(int fd) |
556 | { | 561 | { |
@@ -909,7 +914,7 @@ int talk_id(int32_t id, bool enqueue) | |||
909 | { | 914 | { |
910 | int fd = open_voicefile(); | 915 | int fd = open_voicefile(); |
911 | if (fd < 0 || !load_voicefile_index(fd)) | 916 | if (fd < 0 || !load_voicefile_index(fd)) |
912 | return -1; | 917 | return load_voicefile_failure(fd); |
913 | isloaded = load_voicefile_data(fd); | 918 | isloaded = load_voicefile_data(fd); |
914 | close(fd); | 919 | close(fd); |
915 | } | 920 | } |
@@ -984,7 +989,7 @@ static int _talk_file(const char* filename, | |||
984 | { | 989 | { |
985 | int fd = open_voicefile(); | 990 | int fd = open_voicefile(); |
986 | if (fd < 0 || !load_voicefile_index(fd)) | 991 | if (fd < 0 || !load_voicefile_index(fd)) |
987 | return -1; | 992 | return load_voicefile_failure(fd); |
988 | load_voicefile_data(fd); | 993 | load_voicefile_data(fd); |
989 | close(fd); | 994 | close(fd); |
990 | } | 995 | } |
@@ -1158,6 +1163,11 @@ int talk_number(long n, bool enqueue) | |||
1158 | 1163 | ||
1159 | while (n) | 1164 | while (n) |
1160 | { | 1165 | { |
1166 | if (mil < 1) | ||
1167 | { | ||
1168 | talk_id(VOICE_CHAR_E, true); | ||
1169 | return 0; | ||
1170 | } | ||
1161 | int segment = n / mil; /* extract in groups of 3 digits */ | 1171 | int segment = n / mil; /* extract in groups of 3 digits */ |
1162 | n -= segment * mil; /* remove the used digits from number */ | 1172 | n -= segment * mil; /* remove the used digits from number */ |
1163 | mil /= 1000; /* digit place for next round */ | 1173 | mil /= 1000; /* digit place for next round */ |
@@ -1356,7 +1366,7 @@ int talk_time_intervals(long time, int unit_idx, bool enqueue) | |||
1356 | { | 1366 | { |
1357 | int fd = open_voicefile(); | 1367 | int fd = open_voicefile(); |
1358 | if (fd < 0 || !load_voicefile_index(fd)) | 1368 | if (fd < 0 || !load_voicefile_index(fd)) |
1359 | return -1; | 1369 | return load_voicefile_failure(fd); |
1360 | load_voicefile_data(fd); | 1370 | load_voicefile_data(fd); |
1361 | close(fd); | 1371 | close(fd); |
1362 | } | 1372 | } |
@@ -1526,21 +1536,21 @@ void talk_announce_voice_invalid(void) | |||
1526 | 1536 | ||
1527 | voice_fd = open(talkfile, O_RDONLY); | 1537 | voice_fd = open(talkfile, O_RDONLY); |
1528 | if (voice_fd < 0) | 1538 | if (voice_fd < 0) |
1529 | return; /* can't open */ | 1539 | goto out; /* can't open */ |
1530 | 1540 | ||
1531 | voice_sz= lseek(voice_fd, 0, SEEK_END); | 1541 | voice_sz= lseek(voice_fd, 0, SEEK_END); |
1532 | if (voice_sz == 0 || voice_sz > (64<<10)) | 1542 | if (voice_sz == 0 || voice_sz > (64<<10)) |
1533 | return; /* nothing here or too big */ | 1543 | goto out; /* nothing here or too big */ |
1534 | 1544 | ||
1535 | lseek(voice_fd, 0, SEEK_SET); | 1545 | lseek(voice_fd, 0, SEEK_SET); |
1536 | /* add a bit extra for buflib overhead (2K) */ | 1546 | /* add a bit extra for buflib overhead (2K) */ |
1537 | if (!create_clip_buffer(ALIGN_UP(voice_sz, sizeof(long)) + (2<<10))) | 1547 | if (!create_clip_buffer(ALIGN_UP(voice_sz, sizeof(long)) + (2<<10))) |
1538 | return; | 1548 | goto out; |
1539 | mutex_lock(&read_buffer_mutex); | 1549 | mutex_lock(&read_buffer_mutex); |
1540 | buf_handle = buflib_alloc(&clip_ctx, ALIGN_UP(voice_sz, sizeof(long))); | 1550 | buf_handle = buflib_alloc(&clip_ctx, ALIGN_UP(voice_sz, sizeof(long))); |
1541 | 1551 | ||
1542 | if (buf_handle < 0) | 1552 | if (buf_handle < 0) |
1543 | return; | 1553 | goto out; |
1544 | 1554 | ||
1545 | if (read_to_handle_ex(voice_fd, &clip_ctx, buf_handle, 0, voice_sz) > 0) | 1555 | if (read_to_handle_ex(voice_fd, &clip_ctx, buf_handle, 0, voice_sz) > 0) |
1546 | { | 1556 | { |
@@ -1553,10 +1563,12 @@ void talk_announce_voice_invalid(void) | |||
1553 | } | 1563 | } |
1554 | 1564 | ||
1555 | mutex_unlock(&read_buffer_mutex); | 1565 | mutex_unlock(&read_buffer_mutex); |
1556 | close(voice_fd); | ||
1557 | 1566 | ||
1558 | buf_handle = buflib_free(&clip_ctx, buf_handle); | 1567 | buf_handle = buflib_free(&clip_ctx, buf_handle); |
1559 | talk_handle = core_free(talk_handle); | 1568 | talk_handle = core_free(talk_handle); |
1569 | out: | ||
1570 | close(voice_fd); | ||
1571 | return; | ||
1560 | } | 1572 | } |
1561 | } | 1573 | } |
1562 | 1574 | ||
@@ -1600,6 +1612,14 @@ bool talk_get_debug_data(struct talk_debug_data *data) | |||
1600 | data->max_clipsize = size; | 1612 | data->max_clipsize = size; |
1601 | data->avg_clipsize += size; | 1613 | data->avg_clipsize += size; |
1602 | } | 1614 | } |
1615 | if (!(real_clips > 0)) | ||
1616 | { | ||
1617 | if (data->status == TALK_STATUS_OK) | ||
1618 | data->status = TALK_STATUS_ERR_NOFILE; | ||
1619 | |||
1620 | return false; | ||
1621 | } | ||
1622 | |||
1603 | cc = buflib_get_data(&clip_ctx, metadata_table_handle); | 1623 | cc = buflib_get_data(&clip_ctx, metadata_table_handle); |
1604 | for (int i = 0; i < (int) max_clips; i++) | 1624 | for (int i = 0; i < (int) max_clips; i++) |
1605 | { | 1625 | { |