mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-30 02:10:39 +00:00
FS-8318 #resolve [mod_av can record out of sync when video from chrome has packet loss]
This commit is contained in:
parent
0a987a2502
commit
1bf8fe2de0
@ -491,12 +491,30 @@ static switch_status_t open_audio(AVFormatContext *fc, AVCodec *codec, MediaStre
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int flush_video_queue(switch_queue_t *q, int min)
|
||||||
|
{
|
||||||
|
void *pop;
|
||||||
|
|
||||||
|
if (switch_queue_size(q) > min) {
|
||||||
|
while (switch_queue_trypop(q, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_image_t *img = (switch_image_t *) pop;
|
||||||
|
switch_img_free(&img);
|
||||||
|
if (min && switch_queue_size(q) <= min) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch_queue_size(q);
|
||||||
|
}
|
||||||
|
|
||||||
static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *obj)
|
static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *obj)
|
||||||
{
|
{
|
||||||
record_helper_t *eh = (record_helper_t *) obj;
|
record_helper_t *eh = (record_helper_t *) obj;
|
||||||
void *pop = NULL;
|
void *pop = NULL;
|
||||||
switch_image_t *img = NULL, *tmp_img = NULL;
|
switch_image_t *img = NULL, *tmp_img = NULL;
|
||||||
int d_w = 0, d_h = 0;
|
int d_w = 0, d_h = 0;
|
||||||
|
int size = 0, skip = 0, skip_freq = 0, skip_count = 0, skip_total = 0, skip_total_count = 0;
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "video thread start\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "video thread start\n");
|
||||||
|
|
||||||
@ -505,6 +523,8 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
|
|||||||
int got_packet;
|
int got_packet;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
top:
|
||||||
|
|
||||||
if (switch_queue_pop(eh->video_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
if (switch_queue_pop(eh->video_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_img_free(&img);
|
switch_img_free(&img);
|
||||||
|
|
||||||
@ -526,6 +546,30 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (skip) {
|
||||||
|
if ((skip_total_count > 0 && !--skip_total_count) || ++skip_count >= skip_freq) {
|
||||||
|
skip_total_count = skip_total;
|
||||||
|
skip_count = 0;
|
||||||
|
skip--;
|
||||||
|
goto top;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
size = switch_queue_size(eh->video_queue);
|
||||||
|
|
||||||
|
if (size > 5) {
|
||||||
|
skip = size;
|
||||||
|
|
||||||
|
if (size > 10) {
|
||||||
|
skip_freq = 3;
|
||||||
|
skip_total = 1;
|
||||||
|
} else {
|
||||||
|
skip_freq = 2;
|
||||||
|
skip_total = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//switch_mutex_lock(eh->mutex);
|
//switch_mutex_lock(eh->mutex);
|
||||||
|
|
||||||
@ -1578,23 +1622,6 @@ static switch_status_t av_file_truncate(switch_file_handle_t *handle, int64_t of
|
|||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_video_queue(switch_queue_t *q, int min)
|
|
||||||
{
|
|
||||||
void *pop;
|
|
||||||
|
|
||||||
if (switch_queue_size(q) <= min) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (switch_queue_trypop(q, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_image_t *img = (switch_image_t *) pop;
|
|
||||||
switch_img_free(&img);
|
|
||||||
if (min && switch_queue_size(q) <= min) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static switch_status_t av_file_write(switch_file_handle_t *handle, void *data, size_t *len)
|
static switch_status_t av_file_write(switch_file_handle_t *handle, void *data, size_t *len)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user