audiohook: add directional awareness

Add enum to allow setting optional direction. If set to only one
direction, only feed matching-direction frames to the associated
slin factory.

This prevents mangling the transcoder on non-mixed frames when the
READ and WRITE frames would have otherwise required it.  Also
removes the need to mute or discard the un-wanted frames as they
are no longer added in the first place.

res_stasis_snoop is changed to use this addition to set direction
on audiohook based on spy direction.

If no direction is set, the ast_audiohook_init will init this enum
to BOTH which maintains existing functionality.

ASTERISK-30252

Change-Id: If8716bad334562a5d812be4eeb2a92e4f3be28eb
This commit is contained in:
Mike Bradeen
2022-09-29 14:55:20 -06:00
committed by Friendly Automation
parent a587258733
commit 14e1ba19ee
3 changed files with 40 additions and 13 deletions

View File

@@ -188,21 +188,9 @@ static struct ast_frame *snoop_read(struct ast_channel *chan)
}
ast_audiohook_lock(&snoop->spy);
if (snoop->spy_direction != AST_AUDIOHOOK_DIRECTION_BOTH) {
/*
* When a singular direction is chosen frames are still written to the
* opposing direction's queue. Those frames must be read so the queue
* does not continue to grow, however since they are not needed for the
* selected direction they can be dropped.
*/
enum ast_audiohook_direction opposing_direction =
snoop->spy_direction == AST_AUDIOHOOK_DIRECTION_READ ?
AST_AUDIOHOOK_DIRECTION_WRITE : AST_AUDIOHOOK_DIRECTION_READ;
ast_frame_dtor(ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples,
opposing_direction, snoop->spy_format));
}
frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples, snoop->spy_direction, snoop->spy_format);
ast_audiohook_unlock(&snoop->spy);
return frame ? frame : &snoop->silence;
@@ -287,6 +275,14 @@ static int snoop_setup_audiohook(struct ast_channel *chan, enum ast_audiohook_ty
return -1;
}
/* Set the audiohook direction so we don't write unnecessary frames */
if (ast_audiohook_set_frame_feed_direction(audiohook, *direction)) {
/* If we are unable to set direction, the audiohook either failed to init
or someone else started using it already. If we don't bail here, we risk
feeding frames that will never be read */
return -1;
}
return ast_audiohook_attach(chan, audiohook);
}