mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-25 15:08:53 +00:00
Merge "Revert "Revert "channel: Use frame deferral API for safe sleep."""
This commit is contained in:
@@ -1544,19 +1544,18 @@ int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*c
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
int ms;
|
int ms;
|
||||||
AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
|
|
||||||
|
|
||||||
AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
|
|
||||||
|
|
||||||
/* If no other generator is present, start silencegen while waiting */
|
/* If no other generator is present, start silencegen while waiting */
|
||||||
if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
|
if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
|
||||||
silgen = ast_channel_start_silence_generator(chan);
|
silgen = ast_channel_start_silence_generator(chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ast_channel_lock(chan);
|
||||||
|
ast_channel_start_defer_frames(chan);
|
||||||
|
ast_channel_unlock(chan);
|
||||||
|
|
||||||
start = ast_tvnow();
|
start = ast_tvnow();
|
||||||
while ((ms = ast_remaining_ms(start, timeout_ms))) {
|
while ((ms = ast_remaining_ms(start, timeout_ms))) {
|
||||||
struct ast_frame *dup_f = NULL;
|
|
||||||
|
|
||||||
if (cond && ((*cond)(data) == 0)) {
|
if (cond && ((*cond)(data) == 0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1571,18 +1570,7 @@ int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*c
|
|||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
ast_frfree(f);
|
||||||
if (!ast_is_deferrable_frame(f)) {
|
|
||||||
ast_frfree(f);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((dup_f = ast_frisolate(f))) {
|
|
||||||
if (dup_f != f) {
|
|
||||||
ast_frfree(f);
|
|
||||||
}
|
|
||||||
AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1591,17 +1579,8 @@ int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*c
|
|||||||
ast_channel_stop_silence_generator(chan, silgen);
|
ast_channel_stop_silence_generator(chan, silgen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We need to free all the deferred frames, but we only need to
|
|
||||||
* queue the deferred frames if there was no error and no
|
|
||||||
* hangup was received
|
|
||||||
*/
|
|
||||||
ast_channel_lock(chan);
|
ast_channel_lock(chan);
|
||||||
while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
|
ast_channel_stop_defer_frames(chan);
|
||||||
if (!res) {
|
|
||||||
ast_queue_frame_head(chan, f);
|
|
||||||
}
|
|
||||||
ast_frfree(f);
|
|
||||||
}
|
|
||||||
ast_channel_unlock(chan);
|
ast_channel_unlock(chan);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Reference in New Issue
Block a user