Add preferences to choose the video preset and the preferred video FPS + update linphone submodule.

This commit is contained in:
Ghislain MARY 2015-06-11 15:23:09 +02:00
parent f777f9f421
commit e79d0cb747
6 changed files with 154 additions and 16 deletions

View file

@ -67,7 +67,10 @@
<string name="pref_video_automatically_accept_video_key">pref_video_automatically_accept_video_key</string>
<string name="pref_video_initiate_call_with_video_key">pref_video_initiate_call_with_video_key</string>
<string name="pref_video_enable_key">pref_video_enable_key</string>
<string name="pref_video_preset_key">pref_video_preset_key</string>
<string name="pref_preferred_video_size_key">pref_preferred_video_size_key</string>
<string name="pref_preferred_video_fps_key">pref_preferred_video_fps_key</string>
<string name="pref_bandwidth_limit_key">pref_bandwidth_limit_key</string>
<string name="pref_animation_enable_key">pref_animation_enable_key</string>
<string name="pref_escape_plus_key">pref_escape_plus_key</string>
<string name="pref_echo_cancellation_key">pref_echo_cancellation_key</string>

View file

@ -112,6 +112,7 @@
<string name="pref_video_initiate_call_with_video_title">Initiate video calls</string>
<string name="pref_video_initiate_call_with_video">Always send video requests</string>
<string name="pref_video_enable_title">Enable Video</string>
<string name="pref_bandwidth_limit">Bandwidth limit in kbits/s</string>
<string name="pref_animation_enable_title">Enable Animations</string>
<string name="pref_escape_plus">Replace + by 00</string>
<string name="pref_ilbc_summary">iLBC might be unavailable depending on ARM processor and Android OS version.</string>

View file

@ -110,10 +110,23 @@
android:summary="@string/pref_video_automatically_accept_video"
android:dependency="@string/pref_video_enable_key"/>
<ListPreference
android:title="Video preset"
android:key="@string/pref_video_preset_key"/>
<ListPreference
android:title="@string/pref_preferred_video_size"
android:key="@string/pref_preferred_video_size_key"/>
<ListPreference
android:title="Preferred FPS"
android:key="@string/pref_preferred_video_fps_key"/>
<EditTextPreference
android:title="@string/pref_bandwidth_limit"
android:key="@string/pref_bandwidth_limit_key"
android:numeric="integer" />
<PreferenceCategory
android:title="@string/pref_video_codecs_title"
android:key="@string/pref_video_codecs_key"

View file

@ -760,22 +760,56 @@ public class LinphonePreferences {
getLc().setVideoPolicy(shouldInitiateVideoCall(), accept);
}
public String getVideoPreset() {
String preset = getLc().getVideoPreset();
if (preset == null) preset = "default";
return preset;
}
public void setVideoPreset(String preset) {
if (preset.equals("default")) preset = null;
getLc().setVideoPreset(preset);
preset = getVideoPreset();
if (!preset.equals("custom")) {
getLc().setPreferredFramerate(0);
}
setPreferredVideoSize(getPreferredVideoSize()); // Apply the bandwidth limit
}
public String getPreferredVideoSize() {
//LinphoneCore can only return video size (width and height), not the name
return getConfig().getString("video", "size", "qvga");
}
public void setPreferredVideoSize(String preferredVideoSize) {
int bandwidth = 512;
if (preferredVideoSize.equals("720p")) {
bandwidth = 1024 + 128;
} else if (preferredVideoSize.equals("qvga")) {
bandwidth = 380;
} else if (preferredVideoSize.equals("qcif")) {
bandwidth = 256;
}
getLc().setPreferredVideoSizeByName(preferredVideoSize);
String preset = getVideoPreset();
if (!preset.equals("custom")) {
int bandwidth = 512;
if (preferredVideoSize.equals("720p")) {
bandwidth = 1024 + 128;
} else if (preferredVideoSize.equals("qvga")) {
bandwidth = 380;
} else if (preferredVideoSize.equals("qcif")) {
bandwidth = 256;
}
setBandwidthLimit(bandwidth);
}
}
public int getPreferredVideoFps() {
return (int)getLc().getPreferredFramerate();
}
public void setPreferredVideoFps(int fps) {
getLc().setPreferredFramerate(fps);
}
public int getBandwidthLimit() {
return getLc().getDownloadBandwidth();
}
public void setBandwidthLimit(int bandwidth) {
getLc().setUploadBandwidth(bandwidth);
getLc().setDownloadBandwidth(bandwidth);
}

View file

@ -50,6 +50,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.widget.EditText;
/**
* @author Sylvain Berfini
@ -125,8 +126,8 @@ public class SettingsFragment extends PreferencesListFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(LinphoneService.instance(), SetupActivity.class);
startActivityForResult(intent, WIZARD_INTENT);
return true;
startActivityForResult(intent, WIZARD_INTENT);
return true;
}
});
findPreference(getString(R.string.pref_add_account_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@ -134,7 +135,7 @@ public class SettingsFragment extends PreferencesListFragment {
public boolean onPreferenceClick(Preference preference) {
int nbAccounts = mPrefs.getAccountCount();
LinphoneActivity.instance().displayAccountSettings(nbAccounts);
return true;
return true;
}
});
}
@ -427,6 +428,21 @@ public class SettingsFragment extends PreferencesListFragment {
pref.setValue(key);
}
private void initializeVideoPresetPreferences(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
entries.add("default");
values.add("default");
entries.add("high-fps");
values.add("high-fps");
entries.add("custom");
values.add("custom");
setListPreferenceValues(pref, entries, values);
String value = mPrefs.getVideoPreset();
pref.setSummary(value);
pref.setValue(value);
}
private void initializePreferredVideoSizePreferences(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
@ -442,6 +458,25 @@ public class SettingsFragment extends PreferencesListFragment {
pref.setValue(value);
}
private void initializePreferredVideoFpsPreferences(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
entries.add("none");
values.add("0");
for (int i = 5; i <= 30; i += 5) {
String str = Integer.toString(i);
entries.add(str);
values.add(str);
}
setListPreferenceValues(pref, entries, values);
String value = Integer.toString(mPrefs.getPreferredVideoFps());
if (value.equals("0")) {
value = "none";
}
pref.setSummary(value);
pref.setValue(value);
}
private static void setListPreferenceValues(ListPreference pref, List<CharSequence> entries, List<CharSequence> values) {
CharSequence[] contents = new CharSequence[entries.size()];
entries.toArray(contents);
@ -535,7 +570,7 @@ public class SettingsFragment extends PreferencesListFragment {
findPreference(getString(R.string.pref_adaptive_rate_algorithm_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAdaptiveRateAlgorithm(AdaptiveRateAlgorithm.fromString((String)newValue));
mPrefs.setAdaptiveRateAlgorithm(AdaptiveRateAlgorithm.fromString((String) newValue));
preference.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));
return true;
}
@ -547,10 +582,10 @@ public class SettingsFragment extends PreferencesListFragment {
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setCodecBitrateLimit(Integer.parseInt(newValue.toString()));
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
int bitrate=Integer.parseInt(newValue.toString());
int bitrate = Integer.parseInt(newValue.toString());
for (final PayloadType pt : lc.getAudioCodecs()) {
if(lc.payloadTypeIsVbr(pt)){
if (lc.payloadTypeIsVbr(pt)) {
lc.setPayloadTypeBitrate(pt, bitrate);
}
}
@ -577,7 +612,13 @@ public class SettingsFragment extends PreferencesListFragment {
}
private void initVideoSettings() {
initializeVideoPresetPreferences((ListPreference) findPreference(getString(R.string.pref_video_preset_key)));
initializePreferredVideoSizePreferences((ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));
initializePreferredVideoFpsPreferences((ListPreference) findPreference(getString(R.string.pref_preferred_video_fps_key)));
EditTextPreference bandwidth = (EditTextPreference) findPreference(getString(R.string.pref_bandwidth_limit_key));
bandwidth.setText(Integer.toString(mPrefs.getBandwidthLimit()));
bandwidth.setSummary(bandwidth.getText());
updateVideoPreferencesAccordingToPreset();
PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));
codecs.removeAll();
@ -624,6 +665,24 @@ public class SettingsFragment extends PreferencesListFragment {
((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_accept_video_key))).setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
}
private void updateVideoPreferencesAccordingToPreset() {
if (mPrefs.getVideoPreset().equals("custom")) {
findPreference(getString(R.string.pref_preferred_video_fps_key)).setEnabled(true);
findPreference(getString(R.string.pref_bandwidth_limit_key)).setEnabled(true);
} else {
findPreference(getString(R.string.pref_preferred_video_fps_key)).setEnabled(false);
findPreference(getString(R.string.pref_bandwidth_limit_key)).setEnabled(false);
}
((ListPreference) findPreference(getString(R.string.pref_video_preset_key))).setSummary(mPrefs.getVideoPreset());
int fps = mPrefs.getPreferredVideoFps();
String fpsStr = Integer.toString(fps);
if (fpsStr.equals("0")) {
fpsStr = "none";
}
((ListPreference) findPreference(getString(R.string.pref_preferred_video_fps_key))).setSummary(fpsStr);
((EditTextPreference) findPreference(getString(R.string.pref_bandwidth_limit_key))).setSummary(Integer.toString(mPrefs.getBandwidthLimit()));
}
private void setVideoPreferencesListener() {
findPreference(getString(R.string.pref_video_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
@ -672,11 +731,39 @@ public class SettingsFragment extends PreferencesListFragment {
}
});
findPreference(getString(R.string.pref_video_preset_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setVideoPreset(newValue.toString());
preference.setSummary(mPrefs.getVideoPreset());
updateVideoPreferencesAccordingToPreset();
return true;
}
});
findPreference(getString(R.string.pref_preferred_video_size_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setPreferredVideoSize(newValue.toString());
preference.setSummary(mPrefs.getPreferredVideoSize());
updateVideoPreferencesAccordingToPreset();
return true;
}
});
findPreference(getString(R.string.pref_preferred_video_fps_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setPreferredVideoFps(Integer.parseInt(newValue.toString()));
updateVideoPreferencesAccordingToPreset();
return true;
}
});
findPreference(getString(R.string.pref_bandwidth_limit_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setBandwidthLimit(Integer.parseInt(newValue.toString()));
preference.setSummary(newValue.toString());
return true;
}
});

@ -1 +1 @@
Subproject commit ad1d7c12c9b459660b34d63408b144bf5890f3b6
Subproject commit 7ac6a838d4fb2f0e16850a265ad5392923f71488