Skip to content

Commit

Permalink
Reset read/write translator while setting read/write format
Browse files Browse the repository at this point in the history
This change helps resolve an issue in input audio format when an application invoked before MRCPRecog (and possibly MRCPSynth and SynthAndrecog) creates a translator but does not reset it on exit.
  • Loading branch information
achaloyan committed Apr 15, 2021
1 parent 8031d32 commit 828380a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions app-unimrcp/app_mrcprecog.c
Expand Up @@ -1184,6 +1184,7 @@ static int app_recog_exec(struct ast_channel *chan, ast_app_data data)
ast_format_compat *orawreadformat = ast_channel_get_rawreadformat(chan, app_session->pool);

/* Set read format. */
ast_channel_readtrans_set(chan, NULL);
ast_channel_set_readformat(chan, app_session->nreadformat);
ast_channel_set_rawreadformat(chan, app_session->nreadformat);

Expand Down
1 change: 1 addition & 0 deletions app-unimrcp/app_mrcpsynth.c
Expand Up @@ -640,6 +640,7 @@ static int app_synth_exec(struct ast_channel *chan, ast_app_data data)
ast_format_compat *orawwriteformat = ast_channel_get_rawwriteformat(chan, app_session->pool);

/* Set write format. */
ast_channel_writetrans_set(chan, NULL);
ast_channel_set_writeformat(chan, app_session->nwriteformat);
ast_channel_set_rawwriteformat(chan, app_session->nwriteformat);

Expand Down
2 changes: 2 additions & 0 deletions app-unimrcp/app_synthandrecog.c
Expand Up @@ -1468,13 +1468,15 @@ static int app_synthandrecog_exec(struct ast_channel *chan, ast_app_data data)
ast_format_compat *orawwriteformat = ast_channel_get_rawwriteformat(chan, app_session->pool);

/* Set read format. */
ast_channel_readtrans_set(chan, NULL);
ast_channel_set_readformat(chan, app_session->nreadformat);
ast_channel_set_rawreadformat(chan, app_session->nreadformat);
/* Store old read format. */
app_session->readformat = oreadformat;
app_session->rawreadformat = orawreadformat;

/* Set write format. */
ast_channel_writetrans_set(chan, NULL);
ast_channel_set_writeformat(chan, app_session->nwriteformat);
ast_channel_set_rawwriteformat(chan, app_session->nwriteformat);
/* Store old write format. */
Expand Down
8 changes: 8 additions & 0 deletions include/ast_compat_defs.h
Expand Up @@ -220,6 +220,14 @@ static APR_INLINE void ast_channel_set_rawwriteformat(struct ast_channel *chan,
{
// Do nothing, defined for >= 13 only
}
static APR_INLINE void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
{
// Do nothing, defined for >= 11 only
}
static APR_INLINE void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
{
// Do nothing, defined for >= 11 only
}
#endif

#if AST_VERSION_AT_LEAST(11,0,0)
Expand Down

0 comments on commit 828380a

Please sign in to comment.