const char *func;
int line;
switch_file_handle_t *handle;
+ switch_queue_t *video_q;
struct local_stream_context *next;
};
int32_t chime_counter;
int32_t chime_max_counter;
switch_file_handle_t chime_fh;
+ switch_queue_t *video_q;
};
typedef struct local_stream_source local_stream_source_t;
source->prebuf = DEFAULT_PREBUFFER_SIZE;
}
+ switch_queue_create(&source->video_q, 500, source->pool);
switch_buffer_create_dynamic(&audio_buffer, 1024, source->prebuf + 10, 0);
dist_buf = switch_core_alloc(source->pool, source->prebuf + 10);
if (switch_core_file_open(&fh,
(char *) fname,
- source->channels, source->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ source->channels, source->rate, SWITCH_FILE_FLAG_VIDEO | SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", fname);
switch_yield(1000000);
continue;
while (RUNNING && !source->stopped) {
int is_open;
switch_file_handle_t *use_fh = &fh;
+ int has_video = 0;
switch_core_timer_next(&timer);
olen = source->samples;
if (switch_core_file_open(&source->chime_fh,
(char *) val,
source->channels,
- source->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ source->rate, SWITCH_FILE_FLAG_VIDEO | SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", val);
}
}
}
}
-
+ has_video = 0;
if (is_open) {
+
+ if (switch_core_file_has_video(use_fh)) {
+ switch_frame_t vid_frame = { 0 };
+
+ has_video = 1;
+
+ if (switch_core_file_read_video(use_fh, &vid_frame, SVR_FLUSH) == SWITCH_STATUS_SUCCESS) {
+ if (vid_frame.img) {
+ switch_queue_push(source->video_q, vid_frame.img);
+ }
+ }
+ }
+
if (switch_core_file_read(use_fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
switch_core_file_close(use_fh);
if (use_fh == &source->chime_fh) {
goto retry;
}
}
-
+
switch_buffer_write(audio_buffer, abuf, olen * 2 * source->channels);
}
}
}
if (!is_open || used >= source->prebuf || (source->total && used > source->samples * 2 * source->channels)) {
+ void *pop;
+
used = switch_buffer_read(audio_buffer, dist_buf, source->samples * 2 * source->channels);
- if (source->total) {
+
+ if (!source->total) {
+ switch_mutex_lock(source->mutex);
+
+ while (switch_queue_trypop(source->video_q, &pop) == SWITCH_STATUS_SUCCESS) {
+ switch_image_t *img = (switch_image_t *) pop;
+ switch_img_free(&img);
+ }
+
+ switch_mutex_unlock(source->mutex);
+
+ } else {
uint32_t bused = 0;
+
switch_mutex_lock(source->mutex);
for (cp = source->context_list; cp && RUNNING; cp = cp->next) {
+ if (has_video) {
+ switch_set_flag(cp->handle, SWITCH_FILE_FLAG_VIDEO);
+ } else {
+ switch_clear_flag(cp->handle, SWITCH_FILE_FLAG_VIDEO);
+ }
+
if (switch_test_flag(cp->handle, SWITCH_FILE_CALLBACK)) {
continue;
}
+
switch_mutex_lock(cp->audio_mutex);
bused = (uint32_t)switch_buffer_inuse(cp->audio_buffer);
if (bused > source->samples * 768) {
switch_mutex_unlock(cp->audio_mutex);
}
switch_mutex_unlock(source->mutex);
+
+ switch_mutex_lock(source->mutex);
+ while (switch_queue_trypop(source->video_q, &pop) == SWITCH_STATUS_SUCCESS) {
+ switch_image_t *img = (switch_image_t *) pop;
+ switch_image_t *imgcp = NULL;
+
+ if (source->total == 1) {
+ switch_queue_push(source->context_list->video_q, img);
+ } else if (source->context_list) {
+ for (cp = source->context_list; cp && RUNNING; cp = cp->next) {
+ if (cp->video_q) {
+ imgcp = NULL;
+ switch_img_copy(img, &imgcp);
+ if (imgcp) {
+ switch_queue_push(cp->video_q, imgcp);
+ }
+ }
+ }
+ } else {
+ switch_img_free(&img);
+ }
+ }
+ switch_mutex_unlock(source->mutex);
+
}
}
}
switch_buffer_destroy(&audio_buffer);
+ if (source->video_q) {
+ void *pop;
+
+ while (switch_queue_trypop(source->video_q, &pop) == SWITCH_STATUS_SUCCESS) {
+ switch_image_t *img = (switch_image_t *) pop;
+ switch_img_free(&img);
+ }
+ }
+
if (fd > -1) {
close(fd);
}
goto end;
}
+ switch_queue_create(&context->video_q, 500, handle->memory_pool);
+
handle->samples = 0;
handle->samplerate = source->rate;
handle->channels = source->channels;
}
last = cp;
}
+
+ if (context->video_q) {
+ void *pop;
+
+ while (switch_queue_trypop(context->video_q, &pop) == SWITCH_STATUS_SUCCESS) {
+ switch_image_t *img = (switch_image_t *) pop;
+ switch_img_free(&img);
+ }
+ }
+
context->source->total--;
switch_mutex_unlock(context->source->mutex);
switch_buffer_destroy(&context->audio_buffer);
return SWITCH_STATUS_SUCCESS;
}
+static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle, switch_frame_t *frame, switch_video_read_flag_t flags)
+{
+ void *pop;
+ local_stream_context_t *context = handle->private_info;
+ switch_status_t status;
+
+ if (!context->source->ready) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ while((flags & SVR_FLUSH) && switch_queue_size(context->video_q) > 1) {
+ if (switch_queue_trypop(context->video_q, &pop) == SWITCH_STATUS_SUCCESS) {
+ switch_image_t *img = (switch_image_t *) pop;
+ switch_img_free(&img);
+ }
+ }
+
+ if (!context->source->ready) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if ((flags && SVR_BLOCK)) {
+ status = switch_queue_pop(context->video_q, &pop);
+ } else {
+ status = switch_queue_trypop(context->video_q, &pop);
+ }
+
+ if (status == SWITCH_STATUS_SUCCESS) {
+ if (!pop) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ frame->img = (switch_image_t *) pop;
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ return (flags & SVR_FLUSH) ? SWITCH_STATUS_BREAK : status;
+}
+
static switch_status_t local_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
{
local_stream_context_t *context = handle->private_info;
file_interface->file_open = local_stream_file_open;
file_interface->file_close = local_stream_file_close;
file_interface->file_read = local_stream_file_read;
+ file_interface->file_read_video = local_stream_file_read_video;
if (switch_event_bind(modname, SWITCH_EVENT_SHUTDOWN, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event handler!\n");