FS-8914
This commit is contained in:
parent
86e6480af8
commit
2cf9962f61
|
@ -628,6 +628,26 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
|
|||
|
||||
endfor:
|
||||
|
||||
for(;;) {
|
||||
AVPacket pkt = { 0 };
|
||||
int got_packet = 0;
|
||||
int ret = 0;
|
||||
|
||||
av_init_packet(&pkt);
|
||||
|
||||
ret = avcodec_encode_video2(eh->video_st->st->codec, &pkt, eh->video_st->frame, &got_packet);
|
||||
|
||||
if (ret < 0) {
|
||||
break;
|
||||
} else if (got_packet) {
|
||||
switch_mutex_lock(eh->mutex);
|
||||
ret = write_frame(eh->fc, &eh->video_st->st->codec->time_base, eh->video_st->st, &pkt);
|
||||
switch_mutex_unlock(eh->mutex);
|
||||
av_free_packet(&pkt);
|
||||
if (ret < 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
while(switch_queue_trypop(eh->video_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||
if (!pop) break;
|
||||
img = (switch_image_t *) pop;
|
||||
|
@ -1296,7 +1316,7 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo
|
|||
pkt.data = NULL;
|
||||
pkt.size = 0;
|
||||
|
||||
if ((error = av_read_frame(context->fc, &pkt)) < 0) {
|
||||
if (context->video_st.st && (error = av_read_frame(context->fc, &pkt)) < 0) {
|
||||
if (error == AVERROR_EOF) {
|
||||
eof = 1;
|
||||
/* just make sure*/
|
||||
|
@ -1725,6 +1745,14 @@ static switch_status_t av_file_write(switch_file_handle_t *handle, void *data, s
|
|||
//inuse = switch_buffer_inuse(context->audio_buffer);
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "inuse: %d samples: %d bytes: %d\n", inuse, context->audio_st.frame->nb_samples, bytes);
|
||||
|
||||
if (context->closed) {
|
||||
inuse = switch_buffer_inuse(context->audio_buffer);
|
||||
if (inuse < bytes) {
|
||||
char buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0};
|
||||
switch_buffer_write(context->audio_buffer, buf, bytes - inuse);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while ((inuse = switch_buffer_inuse(context->audio_buffer)) >= bytes) {
|
||||
AVPacket pkt = { 0 };
|
||||
|
@ -1810,37 +1838,17 @@ static switch_status_t av_file_close(switch_file_handle_t *handle)
|
|||
context->eh.finalize = 1;
|
||||
|
||||
if (context->eh.video_queue) {
|
||||
|
||||
|
||||
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||
switch_rgb_color_t bgcolor;
|
||||
int x;
|
||||
|
||||
switch_color_set_rgb(&bgcolor, "#000000");
|
||||
x = (int)handle->mm.fps * 1;
|
||||
|
||||
if (x <= 0) x = 100;
|
||||
|
||||
while(handle->mm.vw && x-- > 0) {
|
||||
switch_image_t *blank_img = NULL;
|
||||
if ((blank_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, handle->mm.vw, handle->mm.vh, 1))) {
|
||||
switch_img_fill(blank_img, 0, 0, blank_img->d_w, blank_img->d_h, &bgcolor);
|
||||
switch_queue_push(context->eh.video_queue, blank_img);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
switch_queue_push(context->eh.video_queue, NULL);
|
||||
}
|
||||
|
||||
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||
av_file_write(handle, NULL, NULL);
|
||||
}
|
||||
|
||||
if (context->eh.video_thread) {
|
||||
switch_thread_join(&status, context->eh.video_thread);
|
||||
}
|
||||
|
||||
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
||||
av_file_write(handle, NULL, NULL);
|
||||
}
|
||||
|
||||
if (context->file_read_thread_running && context->file_read_thread) {
|
||||
context->file_read_thread_running = 0;
|
||||
switch_thread_join(&status, context->file_read_thread);
|
||||
|
|
|
@ -1356,6 +1356,27 @@ SWITCH_STANDARD_APP(redirect_function)
|
|||
switch_core_session_receive_message(session, &msg);
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(video_set_decode_function)
|
||||
{
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
char *txt = (char *) data;
|
||||
int on = 0, wait = 0;
|
||||
|
||||
if (txt) {
|
||||
on = !strcasecmp(txt, "on");
|
||||
wait = !strcasecmp(txt, "wait");
|
||||
}
|
||||
|
||||
if (data && (on || wait)) {
|
||||
switch_channel_set_flag_recursive(channel, CF_VIDEO_DECODED_READ);
|
||||
if (wait) {
|
||||
switch_core_session_wait_for_video_input_params(session, 10000);
|
||||
}
|
||||
} else {
|
||||
switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ);
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(video_refresh_function)
|
||||
{
|
||||
switch_core_session_message_t msg = { 0 };
|
||||
|
@ -6149,6 +6170,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
|
|||
SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "video_refresh", "Send video refresh.", "Send video refresh.", video_refresh_function, "",
|
||||
SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "video_decode", "Set video decode.", "Set video decode.", video_set_decode_function, "[[on|wait]|off]",
|
||||
SAF_NONE);
|
||||
SWITCH_ADD_APP(app_interface, "send_info", "Send info", "Send info", send_info_function, "<info>", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "jitterbuffer", "Send session jitterbuffer", "Send a jitterbuffer message to a session.",
|
||||
jitterbuffer_function, "<jitterbuffer_data>", SAF_SUPPORT_NOMEDIA);
|
||||
|
|
|
@ -3246,6 +3246,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
|
|||
switch_event_t *event;
|
||||
const char *var;
|
||||
|
||||
|
||||
switch_mutex_lock(channel->profile_mutex);
|
||||
if (channel->hold_record && !channel->hold_record->off) {
|
||||
channel->hold_record->off = switch_time_now();
|
||||
|
|
|
@ -11193,14 +11193,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_wait_for_video_input_params(
|
|||
switch_frame_t *read_frame;
|
||||
switch_status_t status;
|
||||
|
||||
if (switch_channel_test_flag(session->channel, CF_VIDEO_READY) && smh->vid_params.width && smh->vid_params.height) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
|
||||
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (switch_channel_test_flag(session->channel, CF_VIDEO_READY) && smh->vid_params.width && smh->vid_params.height && smh->vid_params.fps) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
timeout_ms -= (read_impl.microseconds_per_packet / 1000);
|
||||
|
|
|
@ -536,6 +536,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||
|
||||
file_flags |= SWITCH_FILE_FLAG_VIDEO;
|
||||
switch_channel_set_flag_recursive(channel, CF_VIDEO_DECODED_READ);
|
||||
switch_core_session_request_video_refresh(session);
|
||||
switch_core_session_wait_for_video_input_params(session, 10000);
|
||||
switch_core_media_get_vid_params(session, &vid_params);
|
||||
fh->mm.vw = vid_params.width;
|
||||
|
|
Loading…
Reference in New Issue