]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
WIP not shabby auto vid settings
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 3 Oct 2015 18:34:09 +0000 (13:34 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 6 Nov 2015 20:01:54 +0000 (14:01 -0600)
html5/verto/js/src/jquery.jsonrpcclient.js
html5/verto/video_demo/js/verto-min.js
html5/verto/video_demo/verto.js
src/include/switch_core_media.h
src/mod/applications/mod_conference/conference_member.c
src/mod/applications/mod_conference/mod_conference.h
src/mod/endpoints/mod_verto/mod_verto.c
src/switch_core_media.c

index 58d9986aec50e29bf2013047f7d1a22a1b9365d8..6f4f07c72b6398f679ee82ff71a7367eb173e7c1 100644 (file)
        if (socket !== null) {
            this.speedCB = cb;
            this.speedBytes = bytes;
-           socket.send("#SPU");
-           socket.send("#SPB\n" + new Array(bytes).join("."));
+           socket.send("#SPU " + bytes);
+
+           var loops = bytes / 1024;
+           var rem = bytes % 1024;
+           var i;
+           var data = new Array(1024).join(".");
+           for (i = 0; i < loops; i++) {
+               socket.send("#SPB " + data);
+           }
+           
+           if (rem) {
+               socket.send("#SPB " + data);
+           }
+
+           socket.send("#SPE");
        }
     };
 
index c3bdff18541eaf68490fa731f9c60a2c013883ee..fd9430ce4e96fec0a8cbee7ce6f6469ff1937df3 100644 (file)
@@ -95,7 +95,9 @@ $.FSRTC.getValidRes=function(cam,func){var used=[];var cached=localStorage.getIt
 return func?func(cache):null;}
 $.FSRTC.validRes=[];resI=0;checkRes(cam,func);}
 $.FSRTC.checkPerms=function(runtime,check_audio,check_video){getUserMedia({constraints:{audio:check_audio,video:check_video,},onsuccess:function(e){e.getTracks().forEach(function(track){track.stop();});console.info("media perm init complete");if(runtime){setTimeout(runtime,100,true);}},onerror:function(e){if(check_video&&check_audio){console.error("error, retesting with audio params only");return $.FSRTC.checkPerms(runtime,check_audio,false);}
-console.error("media perm init error");if(runtime){runtime(false)}}});}})(jQuery);(function($){$.JsonRpcClient=function(options){var self=this;this.options=$.extend({ajaxUrl:null,socketUrl:null,onmessage:null,login:null,passwd:null,sessid:null,loginParams:null,userVariables:null,getSocket:function(onmessage_cb){return self._getSocket(onmessage_cb);}},options);self.ws_cnt=0;this.wsOnMessage=function(event){self._wsOnMessage(event);};};$.JsonRpcClient.prototype._ws_socket=null;$.JsonRpcClient.prototype._ws_callbacks={};$.JsonRpcClient.prototype._current_id=1;$.JsonRpcClient.prototype.speedTest=function(bytes,cb){var socket=this.options.getSocket(this.wsOnMessage);if(socket!==null){this.speedCB=cb;this.speedBytes=bytes;socket.send("#SPU");socket.send("#SPB\n"+new Array(bytes).join("."));}};$.JsonRpcClient.prototype.call=function(method,params,success_cb,error_cb){if(!params){params={};}
+console.error("media perm init error");if(runtime){runtime(false)}}});}})(jQuery);(function($){$.JsonRpcClient=function(options){var self=this;this.options=$.extend({ajaxUrl:null,socketUrl:null,onmessage:null,login:null,passwd:null,sessid:null,loginParams:null,userVariables:null,getSocket:function(onmessage_cb){return self._getSocket(onmessage_cb);}},options);self.ws_cnt=0;this.wsOnMessage=function(event){self._wsOnMessage(event);};};$.JsonRpcClient.prototype._ws_socket=null;$.JsonRpcClient.prototype._ws_callbacks={};$.JsonRpcClient.prototype._current_id=1;$.JsonRpcClient.prototype.speedTest=function(bytes,cb){var socket=this.options.getSocket(this.wsOnMessage);if(socket!==null){this.speedCB=cb;this.speedBytes=bytes;socket.send("#SPU "+bytes);var loops=bytes/512;var rem=bytes%512;var i;var data=new Array(512).join(".");for(i=0;i<loops;i++){socket.send("#SPB "+data);}
+if(rem){socket.send("#SPB "+data);}
+socket.send("#SPE");}};$.JsonRpcClient.prototype.call=function(method,params,success_cb,error_cb){if(!params){params={};}
 if(this.options.sessid){params.sessid=this.options.sessid;}
 var request={jsonrpc:'2.0',method:method,params:params,id:this._current_id++};if(!success_cb){success_cb=function(e){console.log("Success: ",e);};}
 if(!error_cb){error_cb=function(e){console.log("Error: ",e);};}
index ea23bbff7509ff0493686024af55952e27828028..1c935dcb3ef6b13a68ddb45dd88521bc9d241a49 100644 (file)
@@ -561,17 +561,30 @@ var callbacks = {
         if (success) {
            vertoHandle.rpcClient.speedTest(1024 * 256, function(e, obj) {
                //console.error("Up: " + obj.upKPS, "Down: ", obj.downKPS);
-               
+               var vid = "default";
                if (outgoingBandwidth === "default") {
-                   outgoingBandwidth = obj.upKPS * .75;
+                   outgoingBandwidth = Math.ceil(obj.upKPS * .75).toString();
+                   
+                   $("#vqual_hd").prop("checked", true);
+                   vid = "1280x720";
+
+                   if (outgoingBandwidth < 1024) {
+                       $("#vqual_vga").prop("checked", true);
+                       vid = "640x480";
+                   }
+                   if (outgoingBandwidth < 512) {
+                       $("#vqual_qvga").prop("checked", true);
+                       vid = "320x240";
+                   }
                }
+
                if (incomingBandwidth === "default") {
-                   incomingBandwidth = obj.downKPS * .75;
+                   incomingBandwidth = Math.ceil(obj.downKPS * .75).toString();
                }
 
-               //console.error(outgoingBandwidth, incomingBandwidth);
+               console.info(outgoingBandwidth, incomingBandwidth);
 
-               $("#bwinfo").html("<b>Bandwidth: " + "Up: " + obj.upKPS + " Down: " + obj.downKPS + "</b>");
+               $("#bwinfo").html("<b>Bandwidth: " + "Up: " + obj.upKPS + " Down: " + obj.downKPS + " Vid: " + vid + "</b>");
                online(true);
                goto_page("main");
                $("input[type='radio']").checkboxradio("refresh");
@@ -782,7 +795,7 @@ function docall() {
     $("#main_info").html("Trying");
 
     check_vid_res();
-
+    console.error(outgoingBandwidth, incomingBandwidth);
     cur_call = vertoHandle.newCall({
         destination_number: $("#ext").val(),
         caller_id_name: $("#cidname").val(),
index 9a60b7a5d108aa23587ce8cd8ccafecea4a14b9b..c8ddcf2c621018d9177ff7614ca773fd3fca7d8c 100644 (file)
@@ -341,6 +341,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses
 SWITCH_DECLARE(switch_file_handle_t *) switch_core_media_get_video_file(switch_core_session_t *session, switch_rw_t rw);
 SWITCH_DECLARE(switch_bool_t) switch_core_session_in_video_thread(switch_core_session_t *session);
 SWITCH_DECLARE(switch_bool_t) switch_core_media_check_dtls(switch_core_session_t *session, switch_media_type_t type);
+SWITCH_DECLARE(switch_status_t) switch_core_media_set_outgoing_bitrate(switch_core_session_t *session, switch_media_type_t type, uint32_t bitrate);
 
 SWITCH_END_EXTERN_C
 #endif
index 2114b9b0fd99bb594c0258c35478a1acb02dab83..a0adb1779502895c45510ec1651577486a927273 100644 (file)
@@ -767,6 +767,28 @@ switch_status_t conference_member_add(conference_obj_t *conference, conference_m
                        conference_utils_member_set_flag_locked(member, MFLAG_NO_MINIMIZE_ENCODING);
                }
 
+               if ((var = switch_channel_get_variable(member->channel, "rtp_video_max_bandwidth_in"))) {
+                       int tmp = atoi(var);
+                       if (tmp > 0) {
+                               member->max_bw_in = tmp;
+                       }
+                       printf("FORCE MAX %d\n", member->max_bw_in);
+               }
+               
+               if ((var = switch_channel_get_variable(member->channel, "rtp_video_max_bandwidth_out"))) {
+                       int tmp = atoi(var);
+                       if (tmp > 0) {
+                               member->max_bw_out = tmp;
+                               
+                               if (member->max_bw_out < conference->video_codec_settings.video.bandwidth) {
+                                       printf("DED ENCODER for %d\n", member->max_bw_out);
+                                       conference_utils_member_set_flag_locked(member, MFLAG_NO_MINIMIZE_ENCODING);
+                                       switch_core_media_set_outgoing_bitrate(member->session, SWITCH_MEDIA_TYPE_VIDEO, member->max_bw_out);
+                               }
+                       }
+               }
+
+
                switch_channel_set_variable_printf(channel, "conference_member_id", "%d", member->id);
                switch_channel_set_variable_printf(channel, "conference_moderator", "%s", conference_utils_member_test_flag(member, MFLAG_MOD) ? "true" : "false");
                switch_channel_set_variable_printf(channel, "conference_ghost", "%s", conference_utils_member_test_flag(member, MFLAG_GHOST) ? "true" : "false");
index 482d7c14d3c7b427a992b6fa981c48550f90c2b7..842674a271bfe26cf011f5f3ffbcd481d2b4c0af 100644 (file)
@@ -761,6 +761,7 @@ struct conference_member {
        switch_image_t *pcanvas_img;
        int max_bw_in;
        int force_bw_in;
+       int max_bw_out;
 };
 
 typedef enum {
index 8f67776e3170938c5bc384f7325250e4065f7197..02f1f0ebb8e41ec0fd53e922477b3ce8782927bc 100644 (file)
@@ -1856,30 +1856,49 @@ static void client_run(jsock_t *jsock)
                                char *s = (char *) data;
 
                                if (*s == '#') {
-                                       char repl[80] = "", *s = (char *) data;
+                                       char repl[2048] = "";
                                        switch_time_t a, b;
-
+                                       
                                        if (s[1] == 'S' && s[2] == 'P') {
 
                                                if (s[3] == 'U') {
+                                                       int i, size = 0;
+                                                       char *p = s+4;
+                                                       int loops = 0;
+                                                       int rem = 0;
 
+                                                       if (!(size = atoi(p))) {
+                                                               continue;
+                                                       }
+                                                       
                                                        a = switch_time_now();
-                                                       bytes = ws_read_frame(&jsock->ws, &oc, &data);
+                                                       do {
+                                                               bytes = ws_read_frame(&jsock->ws, &oc, &data);
+                                                               s = (char *) data;
+                                                       } while (bytes && data && s[0] == '#' && s[3] == 'B');
                                                        b = switch_time_now();
 
                                                        if (!bytes || !data) continue;
                                        
+                                                       if (s[0] != '#') goto nm;
+
                                                        switch_snprintf(repl, sizeof(repl), "#SPU %ld", (b - a) / 1000);
                                                        ws_write_frame(&jsock->ws, WSOC_TEXT, repl, strlen(repl));
 
-
-                                                       s = (char *) data;
-                                                       s[3] = 'B';
+                                                       loops = size / 1024;
+                                                       rem = size % 1024;
+                                                       switch_snprintf(repl, sizeof(repl), "#SPB ");
+                                                       memset(repl+4, '.', 1024);
                                                        a = switch_time_now();
-                                                       ws_write_frame(&jsock->ws, WSOC_TEXT, data, bytes);
+                                                       for (i = 0; i < loops; i++) {
+                                                               ws_write_frame(&jsock->ws, WSOC_TEXT, repl, 1024);
+                                                       }
+                                                       if (rem) {
+                                                               ws_write_frame(&jsock->ws, WSOC_TEXT, repl, rem);
+                                                       }
                                                        b = switch_time_now();
 
-                                                       switch_snprintf(repl, sizeof(repl), "#SPD %ld", (b - a) / 1000);
+                                                       switch_snprintf(repl, sizeof(repl), "#SPD %ld", ((b - a) / 1000) - 200);
                                                        ws_write_frame(&jsock->ws, WSOC_TEXT, repl, strlen(repl));
                                                }
                                        }
@@ -1887,6 +1906,7 @@ static void client_run(jsock_t *jsock)
                                        continue;
                                }
 
+                       nm:
 
                                if (process_input(jsock, data, bytes) != SWITCH_STATUS_SUCCESS) {
                                        die("Input Error\n");
index 5d6e9ae7c5dadfcfa8c3ee6cbfb24f2748e35bdc..904da2e9e9bbda5125d018078da78024a8136392 100644 (file)
@@ -8890,6 +8890,30 @@ SWITCH_DECLARE(switch_bool_t) switch_core_media_check_dtls(switch_core_session_t
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_core_media_set_outgoing_bitrate(switch_core_session_t *session, switch_media_type_t type, uint32_t bitrate)
+{
+       switch_media_handle_t *smh;
+       switch_rtp_engine_t *engine;
+       switch_status_t status = SWITCH_STATUS_FALSE;
+
+       if (!(smh = session->media_handle)) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       if (switch_channel_down(session->channel)) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       engine = &smh->engines[type];
+
+       if (switch_core_codec_ready(&engine->write_codec)) {
+               status = switch_core_codec_control(&engine->write_codec, SCC_VIDEO_BANDWIDTH, 
+                                                                                  SCCT_INT, &bitrate, SCCT_NONE, NULL, NULL, NULL);
+       }
+       
+       return status;
+}
+
 //?
 SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
 {