Simplified Bandwidth manager + default bandwidthes to 256/256 and video to qvga-portrait.

This commit is contained in:
Guillaume Beraudo 2010-11-30 10:12:21 +01:00
parent 92d5914648
commit ea9746b1d8
4 changed files with 81 additions and 50 deletions

View file

@ -1,6 +1,6 @@
[net]
download_bw=384
upload_bw=128
download_bw=256
upload_bw=256
firewall_policy=0
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
ec_tail_len=100
[video]
size=qvga-portrait

View file

@ -18,21 +18,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone;
import org.linphone.core.AndroidCameraRecordManager;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCallParams;
import org.linphone.core.LinphoneCore;
import org.linphone.core.VideoSize;
import android.hardware.Camera.Size;
public class BandwidthManager {
public static final int HIGH_RESOLUTION = 0;
public static final int LOW_RESOLUTION = 1;
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 int currentProfile = LOW_RESOLUTION; // FIXME first profile never defined in C part
private int currentProfile = HIGH_RESOLUTION;
public int getCurrentProfile() {return currentProfile;}
public static final synchronized BandwidthManager getInstance() {
@ -40,29 +43,40 @@ public class BandwidthManager {
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();
LinphoneCall lCall = lc.getCurrentCall();
LinphoneCallParams params = lCall.getCurrentParamsReadOnly().copy();
lc.setUploadBandwidth(bandwidthes[newProfile][0]);
lc.setDownloadBandwidth(bandwidthes[newProfile][1]);
if (profile == LOW_BANDWIDTH) { // OR video disabled by settings?
// lc.enableVideo(false, false);
params.setVideoEnabled(false);
} 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);
}
// Setting Linphone Core Preferred Video Size
if (newProfile != LOW_BANDWIDTH) {
VideoSize targetVideoSize = getProfileVideoSize(newProfile);
lc.setPreferredVideoSize(targetVideoSize);
VideoSize actualVideoSize = lc.getPreferredVideoSize();
@ -71,11 +85,41 @@ public class BandwidthManager {
}
}
lc.setUploadBandwidth(bandwidthes[profile][0]);
lc.setDownloadBandwidth(bandwidthes[profile][1]);
lc.updateCall(lCall, params);
currentProfile = profile;
if (lc.isIncall()) {
LinphoneCall lCall = lc.getCurrentCall();
LinphoneCallParams params = lCall.getCurrentParamsReadOnly().copy();
// Update video parm if
if (newProfile == LOW_BANDWIDTH) {
params.setVideoEnabled(false);
} else {
params.setVideoEnabled(true);
}
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);
}
}

View file

@ -594,11 +594,11 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
if (prefVideoEnable && prefInitiateWithVideo && lParams.getVideoEnabled()) {
getVideoManager().setMuted(false);
lParams.setVideoEnabled(true);
lLinphoneCore.inviteAddressWithParams(lAddress, lParams);
} else {
lParams.setVideoEnabled(false);
lLinphoneCore.inviteAddressWithParams(lAddress, lParams);
}
lLinphoneCore.inviteAddressWithParams(lAddress, lParams);
} catch (LinphoneCoreException e) {
Toast toast = Toast.makeText(DialerActivity.this
,String.format(getString(R.string.error_cannot_get_call_parameters),mAddress.getText().toString())

View file

@ -62,15 +62,10 @@ public class VideoCallActivity extends Activity {
}
private void rewriteChangeResolutionItem(MenuItem item) {
switch (BandwidthManager.getInstance().getCurrentProfile()) {
case BandwidthManager.HIGH_RESOLUTION:
if (BandwidthManager.getInstance().isUserRestriction()) {
item.setTitle(getString(R.string.menu_videocall_change_resolution_when_high_resolution));
break;
case BandwidthManager.LOW_RESOLUTION:
} else {
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;
case R.id.videocall_menu_change_resolution:
BandwidthManager manager = BandwidthManager.getInstance();
switch (manager.getCurrentProfile()) {
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());
}
manager.setUserRestriction(!manager.isUserRestriction());
rewriteChangeResolutionItem(item);
break;
case R.id.videocall_menu_terminate_call: