]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7656 make chime work with video files
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 20 Jun 2015 01:37:28 +0000 (20:37 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 20 Jun 2015 01:37:36 +0000 (20:37 -0500)
src/mod/applications/mod_av/avformat.c
src/mod/formats/mod_local_stream/mod_local_stream.c

index 6b36dd4edde1dae2d7625f52767554238ad2148a..f3eadd4cdd6f3573fa141107d1a19e8ee054333a 100644 (file)
@@ -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;
        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) {
                memset(data, 0, *len * handle->channels * 2);
                return SWITCH_STATUS_SUCCESS;
        }
 
-again:
-
        if (!context->file_read_thread_running && switch_buffer_inuse(context->audio_buffer) == 0) {
                *len = 0;
                return SWITCH_STATUS_FALSE;
@@ -1598,12 +1597,17 @@ again:
        switch_mutex_unlock(context->mutex);
 
        if (size == 0) {
-               switch_yield(20000);
-               goto again;
+               size_t blank = (handle->samplerate / 20) * 2 * handle->real_channels;
+               
+               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->sample_count += *len;
 
@@ -1716,7 +1720,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
        int ticks = 0;
        int max_delta = 1 * AV_TIME_BASE; // 1 second
        switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+       
        if (!context->has_video) return SWITCH_STATUS_FALSE;
 
        if ((flags & SVR_CHECK)) {
@@ -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));
        }
 
-again: if (0) goto again;
+ again:
 
        if (flags & SVR_BLOCK) {
                status = switch_queue_pop(context->eh.video_queue, &pop);
@@ -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_img_free(&img);
 
+
                        if (switch_queue_size(context->eh.video_queue) > 0) {
                                goto again;
                        } else {
+                               mst->next_pts = 0;
                                return SWITCH_STATUS_BREAK;
                        }
                }
index f835972ab493d5a0f448aa4fb4388c790098747f..169e38216230500b4cdb8864237b58bd68f2e746 100644 (file)
@@ -68,6 +68,7 @@ struct local_stream_context {
        int sent_png;
        int last_w;
        int last_h;
+       int serno;
        switch_image_t *banner_img;
        switch_time_t banner_timeout;
        struct local_stream_context *next;
@@ -110,6 +111,7 @@ struct local_stream_source {
        switch_image_t *blank_img;
        switch_image_t *cover_art;
        char *banner_txt;
+       int serno;
 };
 
 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
                                        source->cover_art = switch_img_read_png(png_buf, SWITCH_IMG_FMT_I420);
                                }
                        }
-                       
+
+                       source->serno++;
                        switch_safe_free(source->banner_txt);
                        title = artist = NULL;
                        
@@ -311,7 +314,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
 
                                switch_core_timer_next(&timer);
                                olen = source->samples;
-
+                               
                                if (source->chime_total) {
 
                                        if (source->chime_counter > 0) {
@@ -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;
 
@@ -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)) {
                                                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 (vid_frame.img) {
                                                                source->has_video = 1;
@@ -382,14 +391,22 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
                                                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) {
                                                switch_core_file_close(use_fh);
                                                flush_video_queue(source->video_q);
 
                                                if (use_fh == &source->chime_fh) {
                                                        source->chime_counter = source->rate * source->chime_freq;
+                                                       use_fh = &fh;
+                                               } else {
+                                                       is_open = 0;
                                                }
-                                               is_open = 0;
                                        } else {
                                                if (use_fh == &source->chime_fh && source->chime_max) {
                                                        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
                }
        }
 
+       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->banner_timeout || context->banner_timeout >= now)) {
                        if (!context->banner_img) {