mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 10:33:13 +00:00
cel: Add STREAM_BEGIN, STREAM_END and DTMF event types.
Fixes: #1280
UserNote: Enabling the tracking of the
STREAM_BEGIN and the STREAM_END event
types in cel.conf will log media files and
music on hold played to each channel.
The STREAM_BEGIN event's extra field will
contain a JSON with the file details (path,
format and language), or the class name, in
case of music on hold is played. The DTMF
event's extra field will contain a JSON with
the digit and the duration in milliseconds.
(cherry picked from commit f516f07fd2
)
This commit is contained in:
committed by
George Joseph
parent
eb1ede4612
commit
fcb35f97b9
26
main/file.c
26
main/file.c
@@ -39,6 +39,7 @@
|
||||
#include "asterisk/mod_format.h"
|
||||
#include "asterisk/cli.h"
|
||||
#include "asterisk/channel.h"
|
||||
#include "asterisk/cel.h"
|
||||
#include "asterisk/sched.h"
|
||||
#include "asterisk/translate.h"
|
||||
#include "asterisk/utils.h"
|
||||
@@ -221,15 +222,25 @@ int ast_file_fdtemp(const char *path, char **filename, const char *template_name
|
||||
|
||||
int ast_stopstream(struct ast_channel *tmp)
|
||||
{
|
||||
struct ast_json * cel_event = NULL;
|
||||
|
||||
ast_channel_lock(tmp);
|
||||
|
||||
/* Stop a running stream if there is one */
|
||||
if (ast_channel_stream(tmp)) {
|
||||
ast_closestream(ast_channel_stream(tmp));
|
||||
ast_channel_stream_set(tmp, NULL);
|
||||
|
||||
cel_event = ast_json_pack("{ s: s }", "event", "FILE_STREAM_END");
|
||||
if (cel_event) {
|
||||
ast_cel_publish_event(tmp, AST_CEL_STREAM_END, cel_event);
|
||||
}
|
||||
|
||||
if (ast_channel_oldwriteformat(tmp) && ast_set_write_format(tmp, ast_channel_oldwriteformat(tmp)))
|
||||
ast_log(LOG_WARNING, "Unable to restore format back to %s\n", ast_format_get_name(ast_channel_oldwriteformat(tmp)));
|
||||
}
|
||||
ast_json_unref(cel_event);
|
||||
|
||||
/* Stop the video stream too */
|
||||
if (ast_channel_vstream(tmp) != NULL) {
|
||||
ast_closestream(ast_channel_vstream(tmp));
|
||||
@@ -1301,6 +1312,7 @@ int ast_file_read_dirs(const char *dir_name, ast_file_on_file on_file, void *obj
|
||||
int ast_streamfile(struct ast_channel *chan, const char *filename,
|
||||
const char *preflang)
|
||||
{
|
||||
struct ast_json * cel_event = NULL;
|
||||
struct ast_filestream *fs = NULL;
|
||||
struct ast_filestream *vfs = NULL;
|
||||
off_t pos;
|
||||
@@ -1367,6 +1379,20 @@ int ast_streamfile(struct ast_channel *chan, const char *filename,
|
||||
if (!res && vfs)
|
||||
res = ast_playstream(vfs);
|
||||
|
||||
cel_event = ast_json_pack("{ s: s, s: {s: s, s: s, s: s}}",
|
||||
"event", "FILE_STREAM_BEGIN",
|
||||
"extra",
|
||||
"sound", tmp_filename,
|
||||
"format", ast_format_get_name(ast_channel_writeformat(chan)),
|
||||
"language", preflang ? preflang : "default"
|
||||
);
|
||||
if (cel_event) {
|
||||
ast_cel_publish_event(chan, AST_CEL_STREAM_BEGIN, cel_event);
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Unable to build extradata for sound file STREAM_BEGIN event on channel %s", ast_channel_name(chan));
|
||||
}
|
||||
ast_json_unref(cel_event);
|
||||
|
||||
if (VERBOSITY_ATLEAST(3)) {
|
||||
ast_channel_lock(chan);
|
||||
ast_verb(3, "<%s> Playing '%s.%s' (language '%s')\n", ast_channel_name(chan), tmp_filename, ast_format_get_name(ast_channel_writeformat(chan)), preflang ? preflang : "default");
|
||||
|
Reference in New Issue
Block a user