提交 f19be2fd authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-7656 make chime work with video files

上级 c431ed1f
...@@ -1578,14 +1578,13 @@ static switch_status_t av_file_read(switch_file_handle_t *handle, void *data, si ...@@ -1578,14 +1578,13 @@ static switch_status_t av_file_read(switch_file_handle_t *handle, void *data, si
{ {
av_file_context_t *context = (av_file_context_t *)handle->private_info; av_file_context_t *context = (av_file_context_t *)handle->private_info;
int size; int size;
size_t need = *len * 2 * context->audio_st.channels;
if (!context->has_audio && context->has_video && switch_queue_size(context->eh.video_queue) > 0) { if (!context->has_audio && context->has_video && switch_queue_size(context->eh.video_queue) > 0) {
memset(data, 0, *len * handle->channels * 2); memset(data, 0, *len * handle->channels * 2);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
again:
if (!context->file_read_thread_running && switch_buffer_inuse(context->audio_buffer) == 0) { if (!context->file_read_thread_running && switch_buffer_inuse(context->audio_buffer) == 0) {
*len = 0; *len = 0;
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
...@@ -1598,12 +1597,17 @@ again: ...@@ -1598,12 +1597,17 @@ again:
switch_mutex_unlock(context->mutex); switch_mutex_unlock(context->mutex);
if (size == 0) { if (size == 0) {
switch_yield(20000); size_t blank = (handle->samplerate / 20) * 2 * handle->real_channels;
goto again;
if (need > blank) {
need = blank;
}
memset(data, 0, need);
*len = need / 2 / handle->real_channels;
} else {
*len = size / context->audio_st.channels / 2;
} }
*len = size / context->audio_st.channels / 2;
handle->pos += *len; handle->pos += *len;
handle->sample_count += *len; handle->sample_count += *len;
...@@ -1716,7 +1720,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f ...@@ -1716,7 +1720,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
int ticks = 0; int ticks = 0;
int max_delta = 1 * AV_TIME_BASE; // 1 second int max_delta = 1 * AV_TIME_BASE; // 1 second
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
if (!context->has_video) return SWITCH_STATUS_FALSE; if (!context->has_video) return SWITCH_STATUS_FALSE;
if ((flags & SVR_CHECK)) { if ((flags & SVR_CHECK)) {
...@@ -1752,7 +1756,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f ...@@ -1752,7 +1756,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
st->start_time, st->duration, st->nb_frames, av_q2d(st->time_base)); st->start_time, st->duration, st->nb_frames, av_q2d(st->time_base));
} }
again: if (0) goto again; again:
if (flags & SVR_BLOCK) { if (flags & SVR_BLOCK) {
status = switch_queue_pop(context->eh.video_queue, &pop); status = switch_queue_pop(context->eh.video_queue, &pop);
...@@ -1793,9 +1797,11 @@ again: if (0) goto again; ...@@ -1793,9 +1797,11 @@ again: if (0) goto again;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "picture is too late, off: %" SWITCH_INT64_T_FMT " queue size:%u\n", (int64_t)(switch_micro_time_now() - mst->next_pts), switch_queue_size(context->eh.video_queue)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "picture is too late, off: %" SWITCH_INT64_T_FMT " queue size:%u\n", (int64_t)(switch_micro_time_now() - mst->next_pts), switch_queue_size(context->eh.video_queue));
switch_img_free(&img); switch_img_free(&img);
if (switch_queue_size(context->eh.video_queue) > 0) { if (switch_queue_size(context->eh.video_queue) > 0) {
goto again; goto again;
} else { } else {
mst->next_pts = 0;
return SWITCH_STATUS_BREAK; return SWITCH_STATUS_BREAK;
} }
} }
......
...@@ -68,6 +68,7 @@ struct local_stream_context { ...@@ -68,6 +68,7 @@ struct local_stream_context {
int sent_png; int sent_png;
int last_w; int last_w;
int last_h; int last_h;
int serno;
switch_image_t *banner_img; switch_image_t *banner_img;
switch_time_t banner_timeout; switch_time_t banner_timeout;
struct local_stream_context *next; struct local_stream_context *next;
...@@ -110,6 +111,7 @@ struct local_stream_source { ...@@ -110,6 +111,7 @@ struct local_stream_source {
switch_image_t *blank_img; switch_image_t *blank_img;
switch_image_t *cover_art; switch_image_t *cover_art;
char *banner_txt; char *banner_txt;
int serno;
}; };
typedef struct local_stream_source local_stream_source_t; typedef struct local_stream_source local_stream_source_t;
...@@ -288,7 +290,8 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void ...@@ -288,7 +290,8 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
source->cover_art = switch_img_read_png(png_buf, SWITCH_IMG_FMT_I420); source->cover_art = switch_img_read_png(png_buf, SWITCH_IMG_FMT_I420);
} }
} }
source->serno++;
switch_safe_free(source->banner_txt); switch_safe_free(source->banner_txt);
title = artist = NULL; title = artist = NULL;
...@@ -311,7 +314,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void ...@@ -311,7 +314,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_core_timer_next(&timer); switch_core_timer_next(&timer);
olen = source->samples; olen = source->samples;
if (source->chime_total) { if (source->chime_total) {
if (source->chime_counter > 0) { if (source->chime_counter > 0) {
...@@ -340,7 +343,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void ...@@ -340,7 +343,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
} }
} }
retry: retry:
source->has_video = switch_core_file_has_video(use_fh) || source->cover_art || source->banner_txt; source->has_video = switch_core_file_has_video(use_fh) || source->cover_art || source->banner_txt;
...@@ -366,6 +369,12 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void ...@@ -366,6 +369,12 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
if (switch_core_has_video() && switch_core_file_has_video(use_fh)) { if (switch_core_has_video() && switch_core_file_has_video(use_fh)) {
switch_frame_t vid_frame = { 0 }; switch_frame_t vid_frame = { 0 };
if (use_fh == &source->chime_fh && switch_core_file_has_video(&fh)) {
if (switch_core_file_read_video(&fh, &vid_frame, SVR_FLUSH) == SWITCH_STATUS_SUCCESS) {
switch_img_free(&vid_frame.img);
}
}
if (switch_core_file_read_video(use_fh, &vid_frame, SVR_FLUSH) == SWITCH_STATUS_SUCCESS) { if (switch_core_file_read_video(use_fh, &vid_frame, SVR_FLUSH) == SWITCH_STATUS_SUCCESS) {
if (vid_frame.img) { if (vid_frame.img) {
source->has_video = 1; source->has_video = 1;
...@@ -382,14 +391,22 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void ...@@ -382,14 +391,22 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
source->has_video = 0; source->has_video = 0;
} }
if (use_fh == &source->chime_fh) {
olen = source->samples;
switch_core_file_read(&fh, abuf, &olen);
olen = source->samples;
}
if (switch_core_file_read(use_fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) { if (switch_core_file_read(use_fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
switch_core_file_close(use_fh); switch_core_file_close(use_fh);
flush_video_queue(source->video_q); flush_video_queue(source->video_q);
if (use_fh == &source->chime_fh) { if (use_fh == &source->chime_fh) {
source->chime_counter = source->rate * source->chime_freq; source->chime_counter = source->rate * source->chime_freq;
use_fh = &fh;
} else {
is_open = 0;
} }
is_open = 0;
} else { } else {
if (use_fh == &source->chime_fh && source->chime_max) { if (use_fh == &source->chime_fh && source->chime_max) {
source->chime_max_counter += (int32_t)source->samples; source->chime_max_counter += (int32_t)source->samples;
...@@ -805,6 +822,12 @@ static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle ...@@ -805,6 +822,12 @@ static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle
} }
} }
if (context->serno != context->source->serno) {
switch_img_free(&context->banner_img);
context->banner_timeout = 0;
context->serno = context->source->serno;
}
if (context->source->banner_txt) { if (context->source->banner_txt) {
if ((!context->banner_timeout || context->banner_timeout >= now)) { if ((!context->banner_timeout || context->banner_timeout >= now)) {
if (!context->banner_img) { if (!context->banner_img) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论