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);
}
}
}
- 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) {
}
- 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);
}
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);
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);
}
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;
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;
}
*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;
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 {
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;
return NULL;
}
+ switch_channel_set_flag(session->channel, CF_VIDEO_WRITING);
+
v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
}
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);
switch_core_session_rwunlock(session);
+ switch_channel_clear_flag(session->channel, CF_VIDEO_WRITING);
smh->video_write_thread_running = 0;
return NULL;
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;
}
} 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;
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;
if (!fh && smh->video_write_thread) {
switch_status_t st;
+
if (smh->video_write_thread_running > 0) {
smh->video_write_thread_running = -1;
}
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) {
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);
} 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);
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;
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 };
}
- 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);
}
}
- 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;
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")) ||
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 {
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);
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);
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 {
}
}
- 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);
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;
}
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);
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);
}
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_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);
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;
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) {
end:
if (abuf) {
+
switch_core_file_close(&fh);
free(abuf);
}