From 0560c32375a5edd110d544f5762edb6f1fb0f005 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Fri, 24 Feb 2017 14:30:33 -0700 Subject: stream: Unit tests for stream read and tweaks framework * Removed the AST_CHAN_TP_MULTISTREAM tech property. We now rely on read_stream being set to indicate a multi stream channel. * Added ast_channel_is_multistream convenience function. * Fixed issue where stream and default_stream weren't being set on a frame retrieved from the queue. * Now testing for NULL being returned from the driver's read or read_stream callback. * Fixed issue where the dropnondefault code was crashing on a NULL f. * Now enforcing that if either read_stream or write_stream are set when ast_channel_tech_set is called that BOTH are set. * Added the unit tests. ASTERISK-26816 Change-Id: If7792b20d782e71e823dabd3124572cf0a4caab2 --- main/channel.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'main/channel.c') diff --git a/main/channel.c b/main/channel.c index e3e9561fe..12a30e048 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3944,13 +3944,17 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int default: break; } - } else if (!(ast_channel_tech(chan)->properties & AST_CHAN_TP_MULTISTREAM) && ( - f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) { - /* Since this channel driver does not support multistream determine the default stream this frame - * originated from and update the frame to include it. - */ - stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format)); - f->stream_num = ast_stream_get_position(stream); + } else if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) { + if (ast_channel_tech(chan) && ast_channel_tech(chan)->read_stream) { + stream = ast_stream_topology_get_stream(ast_channel_get_stream_topology(chan), f->stream_num); + default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format)); + } else { + /* Since this channel driver does not support multistream determine the default stream this frame + * originated from and update the frame to include it. + */ + stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format)); + f->stream_num = ast_stream_get_position(stream); + } } } else { ast_channel_blocker_set(chan, pthread_self()); @@ -3970,7 +3974,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int * thing different is that we need to find the default stream so we know whether to invoke the * default stream logic or not (such as transcoding). */ - if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) { + if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) { stream = ast_stream_topology_get_stream(ast_channel_get_stream_topology(chan), f->stream_num); default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format)); } @@ -3980,7 +3984,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int /* Since this channel driver does not support multistream determine the default stream this frame * originated from and update the frame to include it. */ - if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) { + if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO)) { stream = default_stream = ast_channel_get_default_stream(chan, ast_format_get_type(f->subclass.format)); f->stream_num = ast_stream_get_position(stream); } @@ -3989,13 +3993,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int ast_log(LOG_WARNING, "No read routine on channel %s\n", ast_channel_name(chan)); } - if (dropnondefault && stream != default_stream) { - /* If the frame originates from a non-default stream and the caller can not handle other streams - * absord the frame and replace it with a null one instead. - */ - ast_frfree(f); - f = &ast_null_frame; - } else if (stream == default_stream) { + if (stream == default_stream) { /* Perform the framehook read event here. After the frame enters the framehook list * there is no telling what will happen, !!! */ f = ast_framehook_list_read_event(ast_channel_framehooks(chan), f); @@ -4022,6 +4020,14 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio, int AST_LIST_NEXT(f, frame_list) = NULL; } + if (dropnondefault && stream != default_stream) { + /* If the frame originates from a non-default stream and the caller can not handle other streams + * absorb the frame and replace it with a null one instead. + */ + ast_frfree(f); + f = &ast_null_frame; + } + switch (f->frametype) { case AST_FRAME_CONTROL: if (f->subclass.integer == AST_CONTROL_ANSWER) { -- cgit v1.2.3