Skip to content

Add events generation #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ To build this module, all you need to do is type `make`, but because it relies
on `pkg-config` and FreeSWITCH, you need to point `pkg-config` to where
FreeSWITCH is installed before building:

```
```shell
host$ export PKG_CONFIG_PATH=/usr/local/freeswitch/lib/pkgconfig/
host$ make
```

Sample Configuration
--------------------

Just put a file like this in your freeswitch installation, in **conf/autoload_configs/amd.conf.xml**

```xml
<configuration name="amd.conf" description="mod_amd Configuration">
<settings>
Expand All @@ -41,3 +43,9 @@ Just put a file like this in your freeswitch installation, in **conf/autoload_co
</settings>
</configuration>
```

Events
------

The module fires the custom FreeSWITCH event `amd` with the significant fields `AMD-Result` and `AMD-Cause`.
`Unique-ID` to recognize FreeSWITCH instance.
26 changes: 25 additions & 1 deletion mod_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef enum {
} amd_vad_state_t;

typedef struct {
const switch_core_session_t *session;
switch_core_session_t *session;
switch_channel_t *channel;
amd_vad_state_t state;
uint32_t frame_ms;
Expand All @@ -158,6 +158,24 @@ typedef struct {
uint32_t in_greeting:1;
} amd_vad_t;

static void amd_fire_event(const char *result, const char *cause, switch_core_session_t *fs_s)
{
switch_event_t *event;
switch_event_t *event_copy;

if ((switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "amd")) != SWITCH_STATUS_SUCCESS)
return;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "AMD-Result", result);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "AMD-Cause", cause);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(fs_s));
if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS)
return;
switch_core_session_queue_event(fs_s, &event);
switch_event_fire(&event_copy);

return;
}

static amd_frame_classifier classify_frame(const switch_frame_t *f, const switch_codec_implementation_t *codec)
{
int16_t *audio = f->data;
Expand Down Expand Up @@ -207,6 +225,7 @@ static switch_bool_t amd_handle_silence_frame(amd_vad_t *vad, const switch_frame

switch_channel_set_variable(vad->channel, "amd_result", "MACHINE");
switch_channel_set_variable(vad->channel, "amd_cause", "INITIALSILENCE");
amd_fire_event("MACHINE", "INITIALSILENCE", vad->session);
return SWITCH_TRUE;
}

Expand All @@ -220,6 +239,7 @@ static switch_bool_t amd_handle_silence_frame(amd_vad_t *vad, const switch_frame

switch_channel_set_variable(vad->channel, "amd_result", "HUMAN");
switch_channel_set_variable(vad->channel, "amd_cause", "HUMAN");
amd_fire_event("HUMAN", "HUMAN", vad->session);
return SWITCH_TRUE;
}

Expand Down Expand Up @@ -252,6 +272,7 @@ static switch_bool_t amd_handle_voiced_frame(amd_vad_t *vad, const switch_frame_

switch_channel_set_variable(vad->channel, "amd_result", "MACHINE");
switch_channel_set_variable(vad->channel, "amd_cause", "MAXWORDLENGTH");
amd_fire_event("MACHINE", "MAXWORDLENGTH", vad->session);
return SWITCH_TRUE;
}

Expand All @@ -265,6 +286,7 @@ static switch_bool_t amd_handle_voiced_frame(amd_vad_t *vad, const switch_frame_

switch_channel_set_variable(vad->channel, "amd_result", "MACHINE");
switch_channel_set_variable(vad->channel, "amd_cause", "MAXWORDS");
amd_fire_event("MACHINE", "MAXWORDS", vad->session);
return SWITCH_TRUE;
}

Expand All @@ -278,6 +300,7 @@ static switch_bool_t amd_handle_voiced_frame(amd_vad_t *vad, const switch_frame_

switch_channel_set_variable(vad->channel, "amd_result", "MACHINE");
switch_channel_set_variable(vad->channel, "amd_cause", "LONGGREETING");
amd_fire_event("MACHINE", "LONGGREETING", vad->session);
return SWITCH_TRUE;
}

Expand Down Expand Up @@ -390,6 +413,7 @@ SWITCH_STANDARD_APP(amd_start_function)

switch_channel_set_variable(channel, "amd_result", "NOTSURE");
switch_channel_set_variable(channel, "amd_cause", "TOOLONG");
amd_fire_event("NOTSURE", "TOOLONG", vad.session);
break;
}
}
Expand Down