Simplified Bandwidth manager + default bandwidthes to 256/256 and video to qvga-portrait.
This commit is contained in:
parent
92d5914648
commit
ea9746b1d8
4 changed files with 81 additions and 50 deletions
|
@ -1,6 +1,6 @@
|
||||||
[net]
|
[net]
|
||||||
download_bw=384
|
download_bw=256
|
||||||
upload_bw=128
|
upload_bw=256
|
||||||
firewall_policy=0
|
firewall_policy=0
|
||||||
mtu=1300
|
mtu=1300
|
||||||
|
|
||||||
|
@ -32,4 +32,6 @@ remote_ring=/data/data/org.linphone/files/ringback.wav
|
||||||
local_ring=/data/data/org.linphone/files/oldphone_mono.wav
|
local_ring=/data/data/org.linphone/files/oldphone_mono.wav
|
||||||
ec_tail_len=100
|
ec_tail_len=100
|
||||||
|
|
||||||
|
[video]
|
||||||
|
size=qvga-portrait
|
||||||
|
|
||||||
|
|
|
@ -18,21 +18,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
import org.linphone.core.AndroidCameraRecordManager;
|
||||||
import org.linphone.core.LinphoneCall;
|
import org.linphone.core.LinphoneCall;
|
||||||
import org.linphone.core.LinphoneCallParams;
|
import org.linphone.core.LinphoneCallParams;
|
||||||
import org.linphone.core.LinphoneCore;
|
import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.VideoSize;
|
import org.linphone.core.VideoSize;
|
||||||
|
|
||||||
|
import android.hardware.Camera.Size;
|
||||||
|
|
||||||
public class BandwidthManager {
|
public class BandwidthManager {
|
||||||
|
|
||||||
public static final int HIGH_RESOLUTION = 0;
|
public static final int HIGH_RESOLUTION = 0;
|
||||||
public static final int LOW_RESOLUTION = 1;
|
public static final int LOW_RESOLUTION = 1;
|
||||||
public static final int LOW_BANDWIDTH = 2;
|
public static final int LOW_BANDWIDTH = 2;
|
||||||
|
|
||||||
private static final int[][] bandwidthes = {{512,512}, {128,128}, {80,80}};
|
private static final int[][] bandwidthes = {{256,256}, {128,128}, {80,80}};
|
||||||
private static BandwidthManager instance;
|
private static BandwidthManager instance;
|
||||||
|
|
||||||
private int currentProfile = LOW_RESOLUTION; // FIXME first profile never defined in C part
|
private int currentProfile = HIGH_RESOLUTION;
|
||||||
public int getCurrentProfile() {return currentProfile;}
|
public int getCurrentProfile() {return currentProfile;}
|
||||||
|
|
||||||
public static final synchronized BandwidthManager getInstance() {
|
public static final synchronized BandwidthManager getInstance() {
|
||||||
|
@ -40,29 +43,40 @@ public class BandwidthManager {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BandwidthManager() {}
|
|
||||||
|
|
||||||
public void changeTo(int profile) {
|
private BandwidthManager() {
|
||||||
|
// FIXME register a listener on NetworkManager to get notified of network state
|
||||||
|
// FIXME register a listener on Preference to get notified of change in video enable value
|
||||||
|
|
||||||
|
// FIXME initially get those values
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean userRestriction;
|
||||||
|
public boolean isUserRestriction() {return userRestriction;}
|
||||||
|
public void setUserRestriction(boolean limit) {
|
||||||
|
userRestriction = limit;
|
||||||
|
computeNewProfile();
|
||||||
|
}
|
||||||
|
private boolean videoEnabledInSettings = true;
|
||||||
|
|
||||||
|
|
||||||
|
private void computeNewProfile() {
|
||||||
|
int newProfile = userRestriction ? LOW_RESOLUTION : HIGH_RESOLUTION;
|
||||||
|
if (newProfile != currentProfile) {
|
||||||
|
currentProfile = newProfile;
|
||||||
|
onProfileChanged(currentProfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onProfileChanged(int newProfile) {
|
||||||
|
//
|
||||||
LinphoneCore lc = LinphoneService.instance().getLinphoneCore();
|
LinphoneCore lc = LinphoneService.instance().getLinphoneCore();
|
||||||
LinphoneCall lCall = lc.getCurrentCall();
|
lc.setUploadBandwidth(bandwidthes[newProfile][0]);
|
||||||
LinphoneCallParams params = lCall.getCurrentParamsReadOnly().copy();
|
lc.setDownloadBandwidth(bandwidthes[newProfile][1]);
|
||||||
|
|
||||||
if (profile == LOW_BANDWIDTH) { // OR video disabled by settings?
|
// Setting Linphone Core Preferred Video Size
|
||||||
// lc.enableVideo(false, false);
|
if (newProfile != LOW_BANDWIDTH) {
|
||||||
params.setVideoEnabled(false);
|
VideoSize targetVideoSize = getProfileVideoSize(newProfile);
|
||||||
} else {
|
|
||||||
params.setVideoEnabled(true);
|
|
||||||
VideoSize targetVideoSize;
|
|
||||||
switch (profile) {
|
|
||||||
case LOW_RESOLUTION:
|
|
||||||
targetVideoSize = VideoSize.createStandard(VideoSize.HVGA);
|
|
||||||
break;
|
|
||||||
case HIGH_RESOLUTION:
|
|
||||||
targetVideoSize = VideoSize.createStandard(VideoSize.CIF);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("profile not managed : " + profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
lc.setPreferredVideoSize(targetVideoSize);
|
lc.setPreferredVideoSize(targetVideoSize);
|
||||||
VideoSize actualVideoSize = lc.getPreferredVideoSize();
|
VideoSize actualVideoSize = lc.getPreferredVideoSize();
|
||||||
|
@ -71,11 +85,41 @@ public class BandwidthManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lc.isIncall()) {
|
||||||
|
LinphoneCall lCall = lc.getCurrentCall();
|
||||||
|
LinphoneCallParams params = lCall.getCurrentParamsReadOnly().copy();
|
||||||
|
|
||||||
lc.setUploadBandwidth(bandwidthes[profile][0]);
|
// Update video parm if
|
||||||
lc.setDownloadBandwidth(bandwidthes[profile][1]);
|
if (newProfile == LOW_BANDWIDTH) {
|
||||||
|
params.setVideoEnabled(false);
|
||||||
|
} else {
|
||||||
|
params.setVideoEnabled(true);
|
||||||
|
|
||||||
lc.updateCall(lCall, params);
|
}
|
||||||
currentProfile = profile;
|
|
||||||
|
lc.updateCall(lCall, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private VideoSize getProfileVideoSize(int profile) {
|
||||||
|
switch (profile) {
|
||||||
|
case LOW_RESOLUTION:
|
||||||
|
return closestVideoSize(VideoSize.createStandard(VideoSize.QCIF));
|
||||||
|
case HIGH_RESOLUTION:
|
||||||
|
return closestVideoSize(VideoSize.createStandard(VideoSize.QVGA));
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("profile not managed : " + profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VideoSize closestVideoSize(VideoSize vSize) {
|
||||||
|
for (Size s : AndroidCameraRecordManager.getInstance().supportedVideoSizes()) {
|
||||||
|
if (s.height == vSize.getHeight() && s.width == vSize.getWidth()) {
|
||||||
|
return vSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return VideoSize.createStandard(VideoSize.QCIF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -594,11 +594,11 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
if (prefVideoEnable && prefInitiateWithVideo && lParams.getVideoEnabled()) {
|
if (prefVideoEnable && prefInitiateWithVideo && lParams.getVideoEnabled()) {
|
||||||
getVideoManager().setMuted(false);
|
getVideoManager().setMuted(false);
|
||||||
lParams.setVideoEnabled(true);
|
lParams.setVideoEnabled(true);
|
||||||
lLinphoneCore.inviteAddressWithParams(lAddress, lParams);
|
|
||||||
} else {
|
} else {
|
||||||
lParams.setVideoEnabled(false);
|
lParams.setVideoEnabled(false);
|
||||||
lLinphoneCore.inviteAddressWithParams(lAddress, lParams);
|
|
||||||
}
|
}
|
||||||
|
lLinphoneCore.inviteAddressWithParams(lAddress, lParams);
|
||||||
|
|
||||||
} catch (LinphoneCoreException e) {
|
} catch (LinphoneCoreException e) {
|
||||||
Toast toast = Toast.makeText(DialerActivity.this
|
Toast toast = Toast.makeText(DialerActivity.this
|
||||||
,String.format(getString(R.string.error_cannot_get_call_parameters),mAddress.getText().toString())
|
,String.format(getString(R.string.error_cannot_get_call_parameters),mAddress.getText().toString())
|
||||||
|
|
|
@ -62,15 +62,10 @@ public class VideoCallActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rewriteChangeResolutionItem(MenuItem item) {
|
private void rewriteChangeResolutionItem(MenuItem item) {
|
||||||
switch (BandwidthManager.getInstance().getCurrentProfile()) {
|
if (BandwidthManager.getInstance().isUserRestriction()) {
|
||||||
case BandwidthManager.HIGH_RESOLUTION:
|
|
||||||
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_high_resolution));
|
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_high_resolution));
|
||||||
break;
|
} else {
|
||||||
case BandwidthManager.LOW_RESOLUTION:
|
|
||||||
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_low_resolution));
|
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_low_resolution));
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Current profile is unknown " + BandwidthManager.getInstance().getCurrentProfile());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,17 +91,7 @@ public class VideoCallActivity extends Activity {
|
||||||
break;
|
break;
|
||||||
case R.id.videocall_menu_change_resolution:
|
case R.id.videocall_menu_change_resolution:
|
||||||
BandwidthManager manager = BandwidthManager.getInstance();
|
BandwidthManager manager = BandwidthManager.getInstance();
|
||||||
switch (manager.getCurrentProfile()) {
|
manager.setUserRestriction(!manager.isUserRestriction());
|
||||||
case BandwidthManager.HIGH_RESOLUTION:
|
|
||||||
manager.changeTo(BandwidthManager.LOW_RESOLUTION);
|
|
||||||
break;
|
|
||||||
case BandwidthManager.LOW_RESOLUTION:
|
|
||||||
manager.changeTo(BandwidthManager.HIGH_RESOLUTION);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException("Current profile is unknown " + manager.getCurrentProfile());
|
|
||||||
}
|
|
||||||
|
|
||||||
rewriteChangeResolutionItem(item);
|
rewriteChangeResolutionItem(item);
|
||||||
break;
|
break;
|
||||||
case R.id.videocall_menu_terminate_call:
|
case R.id.videocall_menu_terminate_call:
|
||||||
|
|
Loading…
Reference in a new issue