From dc7608fb9ef7b4ae40403cc83a7aa8942466e614 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 27 Mar 2015 15:04:54 -0500 Subject: [PATCH] FS-7501: add mutex to vid buf and fix regression from last regression fix --- src/switch_core_media.c | 2 +- src/switch_vidderbuffer.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index a80472a81b..cda875ef77 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -4772,7 +4772,7 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi vloops++; - if (!buf && switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ)) { + if (!buf) { int buflen = SWITCH_RECOMMENDED_BUFFER_SIZE * 4; buf = switch_core_session_alloc(session, buflen); fr.packet = buf; diff --git a/src/switch_vidderbuffer.c b/src/switch_vidderbuffer.c index 6377b46c53..1cce952e4e 100644 --- a/src/switch_vidderbuffer.c +++ b/src/switch_vidderbuffer.c @@ -346,7 +346,9 @@ SWITCH_DECLARE(void) switch_vb_reset(switch_vb_t *vb) vb->next_seq = 0; vb->complete_frames = 0; + switch_mutex_lock(vb->mutex); hide_nodes(vb); + switch_mutex_unlock(vb->mutex); } SWITCH_DECLARE(switch_status_t) switch_vb_create(switch_vb_t **vbp, uint32_t min_frame_len, uint32_t max_frame_len, switch_memory_pool_t *pool) @@ -520,11 +522,12 @@ SWITCH_DECLARE(switch_status_t) switch_vb_get_packet(switch_vb_t *vb, switch_rtp switch_vb_node_t *node = NULL; switch_status_t status; + switch_mutex_lock(vb->mutex); vb_debug(vb, 2, "GET PACKET %u/%u n:%d\n", vb->complete_frames , vb->frame_len, vb->visible_nodes); if (vb->complete_frames < vb->frame_len) { vb_debug(vb, 2, "BUFFERING %u/%u\n", vb->complete_frames , vb->frame_len); - return SWITCH_STATUS_MORE_DATA; + switch_goto_status(SWITCH_STATUS_MORE_DATA, end); } if ((status = vb_next_packet(vb, &node)) == SWITCH_STATUS_SUCCESS) { @@ -552,11 +555,11 @@ SWITCH_DECLARE(switch_status_t) switch_vb_get_packet(switch_vb_t *vb, switch_rtp switch(status) { case SWITCH_STATUS_RESTART: vb_debug(vb, 2, "%s", "Error encountered ask for new keyframe\n"); - return SWITCH_STATUS_RESTART; + switch_goto_status(SWITCH_STATUS_RESTART, end); case SWITCH_STATUS_NOTFOUND: default: vb_debug(vb, 2, "%s", "No frames found wait for more\n"); - return SWITCH_STATUS_MORE_DATA; + switch_goto_status(SWITCH_STATUS_MORE_DATA, end); } } @@ -570,10 +573,15 @@ SWITCH_DECLARE(switch_status_t) switch_vb_get_packet(switch_vb_t *vb, switch_rtp vb_debug(vb, 1, "GET packet ts:%u seq:%u %s\n", ntohl(packet->header.ts), ntohs(packet->header.seq), packet->header.m ? " " : ""); - return status; + } else { + status = SWITCH_STATUS_MORE_DATA; } - return SWITCH_STATUS_MORE_DATA; + end: + + switch_mutex_unlock(vb->mutex); + + return status; }