Browse Source

Make the event API use espeak_ng_STATUS.

master
Reece H. Dunn 9 years ago
parent
commit
3343bb45b6
4 changed files with 38 additions and 46 deletions
  1. 1
    0
      src/include/espeak-ng/espeak_ng.h
  2. 30
    31
      src/libespeak-ng/event.c
  3. 3
    11
      src/libespeak-ng/event.h
  4. 4
    4
      src/libespeak-ng/speech.c

+ 1
- 0
src/include/espeak-ng/espeak_ng.h View File

ENS_VOICE_NOT_FOUND = 0x100006FF, ENS_VOICE_NOT_FOUND = 0x100006FF,
ENS_MBROLA_NOT_FOUND = 0x100007FF, ENS_MBROLA_NOT_FOUND = 0x100007FF,
ENS_MBROLA_VOICE_NOT_FOUND = 0x100008FF, ENS_MBROLA_VOICE_NOT_FOUND = 0x100008FF,
ENS_EVENT_BUFFER_FULL = 0x100009FF,
} espeak_ng_STATUS; } espeak_ng_STATUS;


typedef enum { typedef enum {

+ 30
- 31
src/libespeak-ng/event.c View File

/* /*
* Copyright (C) 2007, Gilles Casse <[email protected]> * Copyright (C) 2007, Gilles Casse <[email protected]>
* Copyright (C) 2013-2015 Reece H. Dunn
* Copyright (C) 2013-2016 Reece H. Dunn
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
#include <stdbool.h> #include <stdbool.h>


#include "speech.h" #include "speech.h"
#include "espeak_ng.h"
#include "speak_lib.h" #include "speak_lib.h"
#include "event.h" #include "event.h"
#include "wave.h" #include "wave.h"
static node *head = NULL; static node *head = NULL;
static node *tail = NULL; static node *tail = NULL;
static int node_counter = 0; static int node_counter = 0;
static espeak_ERROR push(void *data);
static espeak_ng_STATUS push(void *data);
static void *pop(); static void *pop();
static void init(); static void init();
static void *polling_thread(void *); static void *polling_thread(void *);
return 1; return 1;
} }


espeak_ERROR event_declare(espeak_EVENT *event)
espeak_ng_STATUS event_declare(espeak_EVENT *event)
{ {
if (!event) if (!event)
return EE_INTERNAL_ERROR;
return EINVAL;


int a_status = pthread_mutex_lock(&my_mutex);
espeak_ERROR a_error = EE_OK;
espeak_ng_STATUS status;
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
return status;


if (!a_status) {
espeak_EVENT *a_event = event_copy(event);
a_error = push(a_event);
if (a_error != EE_OK)
event_delete(a_event);
a_status = pthread_mutex_unlock(&my_mutex);
espeak_EVENT *a_event = event_copy(event);
if ((status = push(a_event)) != ENS_OK) {
event_delete(a_event);
pthread_mutex_unlock(&my_mutex);
return status;
} }


sem_post(&my_sem_start_is_required);
status = pthread_mutex_lock(&my_mutex);


if (a_status != 0)
a_error = EE_INTERNAL_ERROR;
sem_post(&my_sem_start_is_required);


return a_error;
return status;
} }


espeak_ERROR event_clear_all()
espeak_ng_STATUS event_clear_all()
{ {
int a_status = pthread_mutex_lock(&my_mutex);
int a_event_is_running = 0;

if (a_status != 0)
return EE_INTERNAL_ERROR;
espeak_ng_STATUS status;
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
return status;


int a_event_is_running = 0;
if (my_event_is_running) { if (my_event_is_running) {
sem_post(&my_sem_stop_is_required); sem_post(&my_sem_stop_is_required);
a_event_is_running = 1; a_event_is_running = 1;
} else } else
init(); // clear pending events init(); // clear pending events
a_status = pthread_mutex_unlock(&my_mutex);
if (a_status != 0)
return EE_INTERNAL_ERROR;
if ((status = pthread_mutex_unlock(&my_mutex)) != ENS_OK)
return status;


if (a_event_is_running) { if (a_event_is_running) {
while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR)
continue; // Restart when interrupted by handler continue; // Restart when interrupted by handler
} }


return EE_OK;
return ENS_OK;
} }


static int sleep_until_timeout_or_stop_request(uint32_t time_in_ms) static int sleep_until_timeout_or_stop_request(uint32_t time_in_ms)


enum { MAX_NODE_COUNTER = 1000 }; enum { MAX_NODE_COUNTER = 1000 };


static espeak_ERROR push(void *the_data)
static espeak_ng_STATUS push(void *the_data)
{ {
assert((!head && !tail) || (head && tail)); assert((!head && !tail) || (head && tail));


if (the_data == NULL) if (the_data == NULL)
return EE_INTERNAL_ERROR;
return EINVAL;


if (node_counter >= MAX_NODE_COUNTER) if (node_counter >= MAX_NODE_COUNTER)
return EE_BUFFER_FULL;
return ENS_EVENT_BUFFER_FULL;


node *n = (node *)malloc(sizeof(node)); node *n = (node *)malloc(sizeof(node));
if (n == NULL) if (n == NULL)
return EE_INTERNAL_ERROR;
return ENOMEM;


if (head == NULL) { if (head == NULL) {
head = n; head = n;


node_counter++; node_counter++;


return EE_OK;
return ENS_OK;
} }


static void *pop() static void *pop()

+ 3
- 11
src/libespeak-ng/event.h View File

/* /*
* Copyright (C) 2007, Gilles Casse <[email protected]> * Copyright (C) 2007, Gilles Casse <[email protected]>
* Copyright (C) 2015 Reece H. Dunn
* Copyright (C) 2015-2016 Reece H. Dunn
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
void event_set_callback(t_espeak_callback *cb); void event_set_callback(t_espeak_callback *cb);


// Clear any pending event. // Clear any pending event.
//
// Return: EE_OK: operation achieved
// EE_INTERNAL_ERROR.
espeak_ERROR event_clear_all();
espeak_ng_STATUS event_clear_all();


// Declare a future event // Declare a future event
//
// Return: EE_OK: operation achieved
// EE_BUFFER_FULL: the event can not be buffered;
// you may try after a while to call the function again.
// EE_INTERNAL_ERROR.
espeak_ERROR event_declare(espeak_EVENT *event);
espeak_ng_STATUS event_declare(espeak_EVENT *event);


// Terminate the event component. // Terminate the event component.
// Last function to be called. // Last function to be called.

+ 4
- 4
src/libespeak-ng/speech.c View File

// TBD: the last one has its size=0. // TBD: the last one has its size=0.
if (event && (event->type == espeakEVENT_WORD) && (event->length == 0)) if (event && (event->type == espeakEVENT_WORD) && (event->length == 0))
break; break;
espeak_ERROR a_error = event_declare(event);
if (a_error != EE_BUFFER_FULL)
err = event_declare(event);
if (err != ENS_EVENT_BUFFER_FULL)
break; break;
usleep(10000); usleep(10000);
a_wave_can_be_played = fifo_is_command_enabled(); a_wave_can_be_played = fifo_is_command_enabled();


if (my_mode == ENOUTPUT_MODE_SPEAK_AUDIO) { if (my_mode == ENOUTPUT_MODE_SPEAK_AUDIO) {
while (1) { while (1) {
espeak_ERROR a_error = event_declare(event_list);
if (a_error != EE_BUFFER_FULL)
err = event_declare(event_list);
if (err != ENS_EVENT_BUFFER_FULL)
break; break;
usleep(10000); usleep(10000);
} }

Loading…
Cancel
Save