diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 552ea1c621..7a0a0e49ad 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1932,7 +1932,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_close(_In_ switch_file_handle_t SWITCH_DECLARE(switch_status_t) switch_core_file_command(switch_file_handle_t *fh, switch_file_command_t command); SWITCH_DECLARE(switch_status_t) switch_core_file_truncate(switch_file_handle_t *fh, int64_t offset); -SWITCH_DECLARE(switch_bool_t) switch_core_file_has_video(switch_file_handle_t *fh); +SWITCH_DECLARE(switch_bool_t) switch_core_file_has_video(switch_file_handle_t *fh, switch_bool_t CHECK_OPEN); ///\} diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 0883285587..f740b94932 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1491,6 +1491,7 @@ typedef enum { CF_VIDEO_BITRATE_UNMANAGABLE, CF_VIDEO_ECHO, CF_VIDEO_BLANK, + CF_VIDEO_WRITING, CF_SLA_INTERCEPT, CF_VIDEO_BREAK, CF_AUDIO_PAUSE, diff --git a/src/mod/applications/mod_conference/conference_file.c b/src/mod/applications/mod_conference/conference_file.c index 8ca5b0d754..6cf27559a3 100644 --- a/src/mod/applications/mod_conference/conference_file.c +++ b/src/mod/applications/mod_conference/conference_file.c @@ -91,7 +91,7 @@ switch_status_t conference_file_close(conference_obj_t *conference, conference_f conference_al_close(node->al); } #endif - if (conference->playing_video_file && switch_core_file_has_video(&node->fh) && conference->canvases[0] && node->canvas_id > -1) { + if (conference->playing_video_file && switch_core_file_has_video(&node->fh, SWITCH_FALSE) && conference->canvases[0] && node->canvas_id > -1) { if (conference->canvases[node->canvas_id]->timer.timer_interface) { conference->canvases[node->canvas_id]->timer.interval = conference->video_fps.ms; conference->canvases[node->canvas_id]->timer.samples = conference->video_fps.samples; diff --git a/src/mod/applications/mod_conference/conference_video.c b/src/mod/applications/mod_conference/conference_video.c index 2c7d7f7ef2..f471017609 100644 --- a/src/mod/applications/mod_conference/conference_video.c +++ b/src/mod/applications/mod_conference/conference_video.c @@ -1586,7 +1586,7 @@ void conference_video_check_recording(conference_obj_t *conference, mcu_canvas_t continue; } - if (switch_test_flag((&imember->rec->fh), SWITCH_FILE_OPEN) && switch_core_file_has_video(&imember->rec->fh)) { + if (switch_test_flag((&imember->rec->fh), SWITCH_FILE_OPEN) && switch_core_file_has_video(&imember->rec->fh, SWITCH_TRUE)) { switch_core_file_write_video(&imember->rec->fh, frame); } } @@ -1696,7 +1696,7 @@ void conference_video_patch_fnode(mcu_canvas_t *canvas, conference_file_node_t * void conference_video_fnode_check(conference_file_node_t *fnode, int canvas_id) { mcu_canvas_t *canvas = NULL; - if (switch_core_file_has_video(&fnode->fh) && switch_core_file_read_video(&fnode->fh, NULL, SVR_CHECK) == SWITCH_STATUS_BREAK) { + if (switch_core_file_has_video(&fnode->fh, SWITCH_TRUE) && switch_core_file_read_video(&fnode->fh, NULL, SVR_CHECK) == SWITCH_STATUS_BREAK) { int full_screen = 0; char *res_id = NULL; @@ -2220,13 +2220,13 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread_t *thr do_refresh = 100; } - if (conference->async_fnode && switch_core_file_has_video(&conference->async_fnode->fh)) { + if (conference->async_fnode && switch_core_file_has_video(&conference->async_fnode->fh, SWITCH_TRUE)) { check_async_file = 1; file_count++; files_playing = 1; } - if (conference->fnode && switch_core_file_has_video(&conference->fnode->fh)) { + if (conference->fnode && switch_core_file_has_video(&conference->fnode->fh, SWITCH_TRUE)) { check_file = 1; file_count++; files_playing = 1; diff --git a/src/mod/formats/mod_local_stream/mod_local_stream.c b/src/mod/formats/mod_local_stream/mod_local_stream.c index df25128372..b314132f95 100644 --- a/src/mod/formats/mod_local_stream/mod_local_stream.c +++ b/src/mod/formats/mod_local_stream/mod_local_stream.c @@ -358,7 +358,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void switch_buffer_zero(audio_buffer); - if (switch_core_file_has_video(&fh)) { + if (switch_core_file_has_video(&fh, SWITCH_FALSE)) { flush_video_queue(source->video_q); } @@ -425,7 +425,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void } } - if (title && (source->cover_art || switch_core_file_has_video(&fh))) { + if (title && (source->cover_art || switch_core_file_has_video(&fh, SWITCH_TRUE))) { const char *format = "#cccccc:#333333:FreeSans.ttf:3%:"; if (artist) { @@ -466,7 +466,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void } - if (switch_core_file_has_video(&source->chime_fh)) { + if (switch_core_file_has_video(&source->chime_fh, SWITCH_FALSE)) { flush_video_queue(source->video_q); } @@ -479,7 +479,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void 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, SWITCH_TRUE) || source->cover_art || source->banner_txt; is_open = switch_test_flag(use_fh, SWITCH_FILE_OPEN); @@ -503,10 +503,10 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void if (is_open) { int svr = 0; - 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_TRUE)) { switch_frame_t vid_frame = { 0 }; - if (use_fh == &source->chime_fh && switch_core_file_has_video(&fh)) { + if (use_fh == &source->chime_fh && switch_core_file_has_video(&fh, SWITCH_TRUE)) { if (switch_core_file_read_video(&fh, &vid_frame, svr) == SWITCH_STATUS_SUCCESS) { switch_img_free(&vid_frame.img); } @@ -599,14 +599,6 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void switch_mutex_lock(cp->audio_mutex); if (switch_test_flag(cp->handle, SWITCH_FILE_OPEN)) { - if (source->has_video && !switch_test_flag(cp->handle, SWITCH_FILE_FLAG_VIDEO)) { - switch_set_flag_locked(cp->handle, SWITCH_FILE_FLAG_VIDEO); - } else { - if (switch_test_flag(cp->handle, SWITCH_FILE_FLAG_VIDEO)) { - switch_clear_flag_locked(cp->handle, SWITCH_FILE_FLAG_VIDEO); - } - } - if (switch_test_flag(cp->handle, SWITCH_FILE_CALLBACK)) { switch_mutex_unlock(cp->audio_mutex); continue; @@ -992,7 +984,7 @@ static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle return SWITCH_STATUS_FALSE; } - while (switch_queue_size(context->video_q) < 5) { + while (!(flags & SVR_BLOCK) && switch_queue_size(context->video_q) < 5) { return SWITCH_STATUS_BREAK; } @@ -1094,6 +1086,16 @@ static switch_status_t local_stream_file_read(switch_file_handle_t *handle, void *len = 0; return SWITCH_STATUS_FALSE; } + + if (context->source->has_video) { + if (!switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) { + switch_set_flag_locked(handle, SWITCH_FILE_FLAG_VIDEO); + } + } else { + if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) { + switch_clear_flag_locked(handle, SWITCH_FILE_FLAG_VIDEO); + } + } switch_mutex_lock(context->audio_mutex); need = *len * 2 * context->source->channels; diff --git a/src/switch_core_file.c b/src/switch_core_file.c index fcc21e4491..8632e8482f 100644 --- a/src/switch_core_file.c +++ b/src/switch_core_file.c @@ -495,9 +495,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh, return status; } -SWITCH_DECLARE(switch_bool_t) switch_core_file_has_video(switch_file_handle_t *fh) +SWITCH_DECLARE(switch_bool_t) switch_core_file_has_video(switch_file_handle_t *fh, switch_bool_t check_open) { - return (switch_test_flag(fh, SWITCH_FILE_OPEN) && switch_test_flag(fh, SWITCH_FILE_FLAG_VIDEO)) ? SWITCH_TRUE : SWITCH_FALSE; + return ((!check_open || switch_test_flag(fh, SWITCH_FILE_OPEN)) && switch_test_flag(fh, SWITCH_FILE_FLAG_VIDEO)) ? SWITCH_TRUE : SWITCH_FALSE; } SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh, void *data, switch_size_t *len) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index d43f9b9287..6c79d8d39e 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -2667,8 +2667,6 @@ static void switch_core_session_parse_codec_settings(switch_core_session_t *sess system_bw = switch_parse_bandwidth_string(bwv); - printf("%d %d\n", engine->sdp_bw, system_bw); - if (engine->sdp_bw && engine->sdp_bw <= system_bw) { engine->codec_settings.video.bandwidth = engine->sdp_bw; } else { @@ -5008,6 +5006,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void int buflen = SWITCH_RTP_MAX_BUF_LEN; switch_timer_t timer = { 0 }; int fps; + switch_video_read_flag_t read_flags = SVR_FLUSH|SVR_BLOCK; if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) { return NULL; @@ -5017,6 +5016,8 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void return NULL; } + switch_channel_set_flag(session->channel, CF_VIDEO_WRITING); + v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO]; @@ -5054,7 +5055,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void } if (smh->video_write_fh && !switch_test_flag(smh->video_write_fh, SWITCH_FILE_FLAG_VIDEO_EOF)) { - wstatus = switch_core_file_read_video(smh->video_write_fh, &fr, SVR_BLOCK); + wstatus = switch_core_file_read_video(smh->video_write_fh, &fr, read_flags); if (wstatus == SWITCH_STATUS_SUCCESS) { switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_NONE, SVR_FLUSH); @@ -5070,6 +5071,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void switch_core_session_rwunlock(session); + switch_channel_clear_flag(session->channel, CF_VIDEO_WRITING); smh->video_write_thread_running = 0; return NULL; @@ -5135,11 +5137,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses switch_assert(session); - if (!switch_channel_test_flag(session->channel, CF_VIDEO)) { + if (!(smh = session->media_handle)) { return SWITCH_STATUS_FALSE; } - if (!(smh = session->media_handle)) { + if (!smh->video_read_fh && !smh->video_read_fh && !switch_channel_test_flag(session->channel, CF_VIDEO)) { + return SWITCH_STATUS_FALSE; + } + + if (fh && !switch_core_file_has_video(fh, SWITCH_TRUE)) { return SWITCH_STATUS_FALSE; } @@ -5181,9 +5187,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses } else { switch_mutex_lock(v_engine->mh.file_write_mutex); - if (fh && smh->video_write_fh) { - //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "File is already open\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "File is already open\n"); smh->video_write_fh = fh; switch_mutex_unlock(v_engine->mh.file_write_mutex); return SWITCH_STATUS_SUCCESS; @@ -5199,7 +5204,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses if (fh) { switch_threadattr_t *thd_attr = NULL; - + switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session)); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); smh->video_write_thread_running = 1; @@ -5208,6 +5213,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses if (!fh && smh->video_write_thread) { switch_status_t st; + if (smh->video_write_thread_running > 0) { smh->video_write_thread_running = -1; } @@ -5385,7 +5391,8 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi switch_core_media_gen_key_frame(session); } - + send_blank = 1; + if (switch_channel_test_flag(channel, CF_VIDEO_READY)) { switch_mutex_lock(mh->file_read_mutex); if (smh->video_read_fh && switch_test_flag(smh->video_read_fh, SWITCH_FILE_OPEN) && read_frame->img) { @@ -5393,10 +5400,24 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi send_blank = 0; } switch_mutex_unlock(mh->file_read_mutex); - } else if (switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ) || v_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) { - send_blank = 1; + //} else if (switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ) || v_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) { + //send_blank = 1; } + if (switch_channel_test_flag(channel, CF_VIDEO_WRITING) || session->video_read_callback) { + send_blank = 0; + } + + if (send_blank) { + if (read_frame && (switch_channel_test_flag(channel, CF_VIDEO_ECHO))) { + switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0); + } else if (blank_img) { + fr.img = blank_img; + switch_yield(10000); + switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_FORCE, 0); + } + } +#if 0 if (blank_img && (send_blank || switch_channel_test_flag(channel, CF_VIDEO_BLANK)) && !session->video_read_callback) { fr.img = blank_img; switch_yield(10000); @@ -5404,6 +5425,8 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi } else if (read_frame && (switch_channel_test_flag(channel, CF_VIDEO_ECHO))) { switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0); } +#endif + } switch_img_free(&blank_img); diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index d599fd5dfd..00837038aa 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1139,7 +1139,7 @@ static void *SWITCH_THREAD_FUNC recording_thread(switch_thread_t *thread, void * data = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE); while(switch_test_flag(rh->fh, SWITCH_FILE_OPEN)) { - if (switch_core_file_has_video(rh->fh)) { + if (switch_core_file_has_video(rh->fh, SWITCH_TRUE)) { switch_core_session_get_read_impl(session, &read_impl); if (read_impl.decoded_bytes_per_packet > 0 && read_impl.decoded_bytes_per_packet <= SWITCH_RECOMMENDED_BUFFER_SIZE) { bsize = read_impl.decoded_bytes_per_packet; @@ -1352,7 +1352,7 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s } - //if (switch_core_file_has_video(rh->fh)) { + //if (switch_core_file_has_video(rh->fh, SWITCH_TRUE)) { //switch_core_media_set_video_file(session, NULL, SWITCH_RW_READ); //switch_channel_clear_flag_recursive(session->channel, CF_VIDEO_DECODED_READ); //} @@ -2551,7 +2551,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t return SWITCH_STATUS_GENERR; } - if (switch_core_file_has_video(fh)) { + if (switch_core_file_has_video(fh, SWITCH_TRUE)) { //switch_core_media_set_video_file(session, fh, SWITCH_RW_READ); //switch_channel_set_flag_recursive(session->channel, CF_VIDEO_DECODED_READ); diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index a4e56982eb..e6f7f9256b 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -360,6 +360,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se switch_dtmf_t dtmf = { 0 }; switch_file_handle_t lfh = { 0 }; switch_file_handle_t vfh = { 0 }; + switch_file_handle_t ind_fh = { 0 }; switch_frame_t *read_frame; switch_codec_t codec, write_codec = { 0 }; char *codec_name; @@ -370,7 +371,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se uint32_t org_silence_hits = 0; int asis = 0; int32_t sample_start = 0; - int waste_resources = 0, fill_cng = 0; + int waste_resources = 1400, fill_cng = 0; switch_codec_implementation_t read_impl = { 0 }; switch_frame_t write_frame = { 0 }; unsigned char write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 }; @@ -417,7 +418,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se } - if ((p = switch_channel_get_variable(channel, "record_sample_rate")) || (fh->params && (p = switch_event_get_header(fh->params, "record_sample_rate")))) { + if ((p = switch_channel_get_variable(channel, "record_sample_rate"))) { int tmp = 0; tmp = atoi(p); @@ -427,51 +428,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se } } - if ((p = switch_channel_get_variable(channel, "record_fill_cng")) || (fh->params && (p = switch_event_get_header(fh->params, "record_fill_cng")))) { - if (!strcasecmp(p, "true")) { - fill_cng = 1400; - } else { - if ((fill_cng = atoi(p)) < 0) { - fill_cng = 0; - } - } - } - - if ((p = switch_channel_get_variable(channel, "record_waste_resources")) || - (fh->params && (p = switch_event_get_header(fh->params, "record_waste_resources")))) { - - if (!strcasecmp(p, "true")) { - waste_resources = 1400; - } else { - if ((waste_resources = atoi(p)) < 0) { - waste_resources = 0; - } - } - } - - - if (fill_cng || waste_resources) { - if (switch_core_codec_init(&write_codec, - "L16", - NULL, - NULL, - read_impl.actual_samples_per_second, - read_impl.microseconds_per_packet / 1000, - read_impl.number_of_channels, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, - switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activated, ready to waste resources!\n"); - write_frame.data = write_buf; - write_frame.buflen = sizeof(write_buf); - write_frame.datalen = read_impl.decoded_bytes_per_packet; - write_frame.samples = write_frame.datalen / 2; - write_frame.codec = &write_codec; - } else { - arg_recursion_check_stop(args); - return SWITCH_STATUS_FALSE; - } - } - if (!strstr(file, SWITCH_URL_SEPARATOR)) { char *ext; @@ -550,7 +506,66 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se return SWITCH_STATUS_GENERR; } - if (switch_core_file_has_video(fh)) { + + if ((p = switch_channel_get_variable(channel, "record_fill_cng")) || (fh->params && (p = switch_event_get_header(fh->params, "record_fill_cng")))) { + if (!strcasecmp(p, "true")) { + fill_cng = 1400; + } else { + if ((fill_cng = atoi(p)) < 0) { + fill_cng = 0; + } + } + } + + if ((p = switch_channel_get_variable(channel, "record_indication")) || (fh->params && (p = switch_event_get_header(fh->params, "record_indication")))) { + int flags = SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT; + waste_resources = 1400; + + if (switch_core_file_open(&ind_fh, + p, + read_impl.number_of_channels, + read_impl.actual_samples_per_second, flags, NULL) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Indication file invalid\n"); + } + } + + if ((p = switch_channel_get_variable(channel, "record_waste_resources")) || + (fh->params && (p = switch_event_get_header(fh->params, "record_waste_resources")))) { + + if (!strcasecmp(p, "true")) { + waste_resources = 1400; + } else { + if ((waste_resources = atoi(p)) < 0) { + waste_resources = 0; + } + } + } + + if (fill_cng || waste_resources) { + if (switch_core_codec_init(&write_codec, + "L16", + NULL, + NULL, + read_impl.actual_samples_per_second, + read_impl.microseconds_per_packet / 1000, + read_impl.number_of_channels, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, + switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activated, ready to waste resources!\n"); + write_frame.data = write_buf; + write_frame.buflen = sizeof(write_buf); + write_frame.datalen = read_impl.decoded_bytes_per_packet; + write_frame.samples = write_frame.datalen / 2; + write_frame.codec = &write_codec; + } else { + arg_recursion_check_stop(args); + return SWITCH_STATUS_FALSE; + } + } + + + + if (switch_core_file_has_video(fh, SWITCH_TRUE)) { switch_core_session_request_video_refresh(session); if ((p = switch_channel_get_variable(channel, "record_play_video")) || @@ -565,7 +580,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Failure opening video playback file.\n"); } - if (switch_core_file_has_video(fh)) { + if (switch_core_file_has_video(&vfh, SWITCH_TRUE)) { switch_core_media_set_video_file(session, &vfh, SWITCH_RW_WRITE); switch_core_media_gen_key_frame(session); } else { @@ -586,11 +601,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se switch_channel_set_flag(channel, CF_VIDEO_BLANK); } - - if ((p = switch_channel_get_variable(channel, "record_indication")) || (fh->params && (p = switch_event_get_header(fh->params, "record_indication")))) { - switch_ivr_play_file(session, NULL, p, NULL); - } - if (sample_start > 0) { uint32_t pos = 0; switch_core_file_seek(fh, &pos, sample_start, SEEK_SET); @@ -661,16 +671,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, read_impl.microseconds_per_packet / 1000); - if (switch_core_file_has_video(fh)) { + if (switch_core_file_has_video(fh, SWITCH_FALSE)) { if (echo_on) { switch_channel_clear_flag(channel, CF_VIDEO_ECHO); switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); echo_on = 0; } switch_core_media_set_video_file(session, NULL, SWITCH_RW_READ); - if (switch_test_flag(&vfh, SWITCH_FILE_OPEN)) { - switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); - } + switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); } switch_channel_clear_flag(channel, CF_VIDEO_BLANK); switch_core_file_close(fh); @@ -810,7 +818,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Failure opening video playback file.\n"); } - if (switch_core_file_has_video(fh)) { + if (switch_core_file_has_video(&vfh, SWITCH_TRUE)) { //switch_core_media_set_video_file(session, &vfh, SWITCH_RW_WRITE); switch_core_media_gen_key_frame(session); } else { @@ -848,7 +856,20 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se } } - if (fill_cng) { + write_frame.datalen = read_impl.decoded_bytes_per_packet; + write_frame.samples = write_frame.datalen / 2; + + if (switch_test_flag(&ind_fh, SWITCH_FILE_OPEN)) { + switch_size_t olen = write_frame.codec->implementation->samples_per_packet; + + if (switch_core_file_read(&ind_fh, write_frame.data, &olen) == SWITCH_STATUS_SUCCESS) { + write_frame.samples = olen; + write_frame.datalen = olen * 2 * ind_fh.channels;; + } else { + switch_core_file_close(&ind_fh); + } + + } else if (fill_cng) { switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, read_impl.number_of_channels, fill_cng); } else if (waste_resources) { switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, read_impl.number_of_channels, waste_resources); @@ -867,8 +888,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se break; } } + - if (waste_resources) { + if (waste_resources || switch_test_flag(&ind_fh, SWITCH_FILE_OPEN)) { if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { break; } @@ -879,16 +901,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se switch_core_codec_destroy(&write_codec); } - if (switch_core_file_has_video(fh)) { + if (switch_core_file_has_video(fh, SWITCH_FALSE)) { if (echo_on) { switch_channel_clear_flag(channel, CF_VIDEO_ECHO); switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); echo_on = 0; } switch_core_media_set_video_file(session, NULL, SWITCH_RW_READ); - if (switch_test_flag(&vfh, SWITCH_FILE_OPEN)) { - switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); - } + switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); } switch_channel_clear_flag(channel, CF_VIDEO_BLANK); switch_core_file_close(fh); @@ -1375,7 +1395,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_channel_set_private(channel, "__fh", fh); switch_core_session_io_rwunlock(session); - if (switch_core_file_has_video(fh)) { + if (switch_core_file_has_video(fh, SWITCH_TRUE)) { switch_core_media_set_video_file(session, fh, SWITCH_RW_WRITE); } @@ -1452,10 +1472,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_channel_set_private(channel, "__fh", NULL); switch_core_session_io_rwunlock(session); - if (switch_core_file_has_video(fh)) { - //switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); - switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); - } + switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); switch_core_file_close(fh); @@ -1479,10 +1496,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_channel_set_private(channel, "__fh", NULL); switch_core_session_io_rwunlock(session); - if (switch_core_file_has_video(fh)) { - //switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); - switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); - } + switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); switch_core_file_close(fh); switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); @@ -1509,10 +1523,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_core_session_io_write_lock(session); switch_channel_set_private(channel, "__fh", NULL); switch_core_session_io_rwunlock(session); - if (switch_core_file_has_video(fh)) { - //switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); - switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); - } + + switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); + switch_core_file_close(fh); switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); status = SWITCH_STATUS_GENERR; @@ -1921,11 +1934,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_core_session_io_write_lock(session); switch_channel_set_private(channel, "__fh", NULL); switch_core_session_io_rwunlock(session); - - if (switch_core_file_has_video(fh)) { - //switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ); - switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); - } + + switch_core_media_set_video_file(session, NULL, SWITCH_RW_WRITE); switch_core_file_close(fh); if (fh->audio_buffer) { @@ -2088,6 +2098,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_ end: if (abuf) { + switch_core_file_close(&fh); free(abuf); }