]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8876 #resolve [Bind video threads to CPU alternating]
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 25 Feb 2016 22:11:28 +0000 (16:11 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 25 Feb 2016 22:11:37 +0000 (16:11 -0600)
src/switch_core_media.c
src/switch_vpx.c

index 0cb2bb6872ffa2650e322d6c614822f8e3367813..086ec3b9fd03ad5a397269cbe860b2e57e992b0e 100644 (file)
@@ -66,7 +66,14 @@ typedef struct secure_settings_s {
        char *remote_crypto_key;
 } switch_secure_settings_t;
 
+typedef struct core_video_globals_s {
+       int cpu_count;
+       int cur_cpu;
+       switch_memory_pool_t *pool;
+       switch_mutex_t *mutex;
+} core_video_globals_t;
 
+static core_video_globals_t video_globals = { 0 };
 
 struct media_helper {
        switch_core_session_t *session;
@@ -5008,6 +5015,27 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses
        return SWITCH_STATUS_SUCCESS;
 }
 
+int next_cpu(void)
+{
+       int x = 0;
+
+       switch_mutex_lock(video_globals.mutex);
+       x = video_globals.cur_cpu++;
+       if (video_globals.cur_cpu == video_globals.cpu_count) {
+               video_globals.cur_cpu = 0;
+       }
+       switch_mutex_unlock(video_globals.mutex);
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Binding to CPU %d\n", x);
+
+       return x;
+}
+
+static void bind_cpu(void)
+{
+       switch_core_thread_set_cpu_affinity(next_cpu());
+}
+
+
 static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, void *obj)
 {
        struct media_helper *mh = obj;
@@ -5029,6 +5057,8 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi
                return NULL;
        }
 
+       bind_cpu();
+
        if ((var = switch_channel_get_variable(session->channel, "core_video_blank_image"))) {
                blank_img = switch_img_read_png(var, SWITCH_IMG_FMT_I420);
        }
@@ -10283,11 +10313,18 @@ SWITCH_DECLARE (void) switch_core_media_recover_session(switch_core_session_t *s
 SWITCH_DECLARE(void) switch_core_media_init(void)
 {
        switch_core_gen_certs(DTLS_SRTP_FNAME ".pem");  
+
+       video_globals.cpu_count = switch_core_cpu_count();
+       video_globals.cur_cpu = 0;
+
+       switch_core_new_memory_pool(&video_globals.pool);
+       switch_mutex_init(&video_globals.mutex, SWITCH_MUTEX_NESTED, video_globals.pool);
+
 }
 
 SWITCH_DECLARE(void) switch_core_media_deinit(void)
 {
-       
+       switch_core_destroy_memory_pool(&video_globals.pool);
 }
 
 static int payload_number(const char *name)
index 58b7e2e147524c586f0c3daa801c655a4d7a3378..e49fa4c7979a479e15070c49efb35916e9986493 100644 (file)
@@ -304,7 +304,7 @@ static switch_status_t init_decoder(switch_codec_t *codec)
                //      context->decoder_init = 0;
                //}
 
-               cfg.threads = switch_core_cpu_count();
+               cfg.threads = 1;//(switch_core_cpu_count() > 1) ? 2 : 1;
 
                if (!context->is_vp9) { // vp8 only
                        // dec_flags = VPX_CODEC_USE_POSTPROC;
@@ -391,7 +391,7 @@ static switch_status_t init_encoder(switch_codec_t *codec)
        config->rc_target_bitrate = context->bandwidth;
        config->g_lag_in_frames = 0;
        config->kf_max_dist = 2000;
-       config->g_threads = (cpus > 1) ? 2 : 1;
+       config->g_threads = 1;//(cpus > 1) ? 2 : 1;
        
        if (context->is_vp9) {
                //config->rc_dropframe_thresh = 2;