Don't download Openh264 if not enabled on the project

This commit is contained in:
Erwan Croze 2016-09-21 11:15:02 +02:00
parent 186656c10d
commit 4ff7acf40c
8 changed files with 61 additions and 50 deletions

View file

@ -61,7 +61,7 @@
android:paddingLeft="30dp" android:paddingLeft="30dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1" android:layout_weight="1"
android:layout_height="wrap_content"> android:layout_height="match_parent">
<TextView <TextView
android:text="@string/password" android:text="@string/password"

View file

@ -58,12 +58,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:id="@+id/answerNo" android:id="@+id/answerNo"
android:layout_marginBottom="35dp"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/imageView" android:layout_toLeftOf="@+id/imageView"
android:layout_toStartOf="@+id/imageView" android:layout_toStartOf="@+id/imageView" />
android:layout_marginRight="26dp"
android:layout_marginEnd="26dp"/>
<Button <Button
style="@style/font7" style="@style/font7"
@ -85,8 +82,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:id="@+id/answerOk" android:id="@+id/answerOk"
android:layout_alignTop="@+id/answerYes" android:layout_centerHorizontal="true"
android:layout_centerHorizontal="true"/> android:layout_alignTop="@+id/answerYes" />
<TextView <TextView
style="@style/font7" style="@style/font7"

View file

@ -179,6 +179,7 @@
<string name="warning_wrong_destination_address">Cannot build destination address from %s</string> <string name="warning_wrong_destination_address">Cannot build destination address from %s</string>
<string name="error_unknown">Unknown error</string> <string name="error_unknown">Unknown error</string>
<string name="error_call_declined">Call declined</string> <string name="error_call_declined">Call declined</string>
<string name="error_user_busy">User busy</string>
<string name="error_user_not_found">User not found</string> <string name="error_user_not_found">User not found</string>
<string name="error_incompatible_media">Incompatible media parameters</string> <string name="error_incompatible_media">Incompatible media parameters</string>
<string name="error_low_bandwidth">Your correspondent has low bandwidth, video cannot be started</string> <string name="error_low_bandwidth">Your correspondent has low bandwidth, video cannot be started</string>

View file

@ -111,6 +111,8 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{
displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_SHORT); displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_SHORT);
} else if (message != null && call.getErrorInfo().getReason() == Reason.Media) { } else if (message != null && call.getErrorInfo().getReason() == Reason.Media) {
displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_SHORT); displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_SHORT);
} else if (message != null && call.getErrorInfo().getReason() == Reason.Busy) {
displayCustomToast(getString(R.string.error_user_busy), Toast.LENGTH_SHORT);
} else if (message != null) { } else if (message != null) {
displayCustomToast(getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_SHORT); displayCustomToast(getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_SHORT);
} }

View file

@ -215,11 +215,11 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
@Override @Override
public void OnProgress(final int current, final int max) { public void OnProgress(final int current, final int max) {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
OpenH264DownloadHelper ohcodec = LinphoneManager.getInstance().getOpenH264DownloadHelper(); OpenH264DownloadHelper ohcodec = LinphoneManager.getInstance().getOpenH264DownloadHelper();
if (progress == null) { if (progress == null) {
progress = new ProgressDialog((Context)ohcodec.getUserData(ctxt)); progress = new ProgressDialog((Context) ohcodec.getUserData(ctxt));
progress.setCanceledOnTouchOutside(false); progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false); progress.setCancelable(false);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
@ -238,22 +238,22 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
} }
} }
} }
}); });
} }
@Override @Override
public void OnError (final String error){ public void OnError(final String error) {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (progress != null) progress.dismiss(); if (progress != null) progress.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder((Context)LinphoneManager.getInstance().getOpenH264DownloadHelper().getUserData(ctxt)); AlertDialog.Builder builder = new AlertDialog.Builder((Context) LinphoneManager.getInstance().getOpenH264DownloadHelper().getUserData(ctxt));
builder.setMessage("Sorry an error has occurred."); builder.setMessage("Sorry an error has occurred.");
builder.setCancelable(false); builder.setCancelable(false);
builder.setNeutralButton("Ok", null); builder.setNeutralButton("Ok", null);
builder.show(); builder.show();
} }
}); });
} }
}; };
mCodecDownloader.setOpenH264HelperListener(mCodecListener); mCodecDownloader.setOpenH264HelperListener(mCodecListener);

View file

@ -685,7 +685,7 @@ public class SettingsFragment extends PreferencesListFragment {
PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key)); PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));
codecs.removeAll(); codecs.removeAll();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); final LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
final OpenH264DownloadHelper mCodecDownloader = LinphoneManager.getInstance().getOpenH264DownloadHelper(); final OpenH264DownloadHelper mCodecDownloader = LinphoneManager.getInstance().getOpenH264DownloadHelper();
@ -705,9 +705,11 @@ public class SettingsFragment extends PreferencesListFragment {
} }
} }
} }
if (pt.getMime().equals("H264") && mCodecDownloader.isCodecFound()) { if (lc.openH264Enabled()) {
codec.setSummary(mCodecDownloader.getLicenseMessage()); if (pt.getMime().equals("H264") && mCodecDownloader.isCodecFound()) {
codec.setTitle("OpenH264"); codec.setSummary(mCodecDownloader.getLicenseMessage());
codec.setTitle("OpenH264");
}
} }
codec.setChecked(lc.isPayloadTypeEnabled(pt)); codec.setChecked(lc.isPayloadTypeEnabled(pt));
@ -716,29 +718,31 @@ public class SettingsFragment extends PreferencesListFragment {
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue; boolean enable = (Boolean) newValue;
try { try {
if (enable && Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86") if (lc.openH264Enabled()) {
&& pt.getMime().equals("H264") && !mCodecDownloader.isCodecFound()) { if (enable && Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86")
mCodecDownloader.setOpenH264HelperListener(LinphoneManager.getInstance().getOpenH264HelperListener()); && pt.getMime().equals("H264") && !mCodecDownloader.isCodecFound()) {
mCodecDownloader.setUserData(0,LinphoneManager.getInstance().getContext()); mCodecDownloader.setOpenH264HelperListener(LinphoneManager.getInstance().getOpenH264HelperListener());
mCodecDownloader.setUserData(1,codec); mCodecDownloader.setUserData(0, LinphoneManager.getInstance().getContext());
mCodecDownloader.setUserData(1, codec);
AlertDialog.Builder builder = new AlertDialog.Builder(LinphoneManager.getInstance().getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(LinphoneManager.getInstance().getContext());
builder.setCancelable(false); builder.setCancelable(false);
builder.setMessage("Do you agree to download " + mCodecDownloader.getLicenseMessage()).setPositiveButton("Yes", new DialogInterface.OnClickListener() { builder.setMessage("Do you agree to download " + mCodecDownloader.getLicenseMessage()).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) if (which == DialogInterface.BUTTON_POSITIVE)
mCodecDownloader.downloadCodec(); mCodecDownloader.downloadCodec();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
// Disable H264
} }
} });
}).show(); builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
// Disable H264
}
}
}).show();
}
} }
LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable); LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
} catch (LinphoneCoreException e) { } catch (LinphoneCoreException e) {

View file

@ -479,8 +479,11 @@ public class StatusFragment extends Fragment {
PayloadType payloadVideo = params.getUsedVideoCodec(); PayloadType payloadVideo = params.getUsedVideoCodec();
if (payloadVideo != null && payloadAudio != null) { if (payloadVideo != null && payloadAudio != null) {
String videoMime = payloadVideo.getMime(); String videoMime = payloadVideo.getMime();
if (payloadVideo.getMime().equals("H264") && LinphoneManager.getInstance().getOpenH264DownloadHelper().isCodecFound()) if (LinphoneManager.getLc().openH264Enabled() &&
payloadVideo.getMime().equals("H264") &&
LinphoneManager.getInstance().getOpenH264DownloadHelper().isCodecFound()) {
videoMime = "OpenH264"; videoMime = "OpenH264";
}
codec.setText(videoMime + " / " + payloadAudio.getMime() + (payloadAudio.getRate() / 1000)); codec.setText(videoMime + " / " + payloadAudio.getMime() + (payloadAudio.getRate() / 1000));
} }
dl.setText(String.valueOf((int) videoStats.getDownloadBandwidth()) + " / " + (int) audioStats.getDownloadBandwidth() + " kbits/s"); dl.setText(String.valueOf((int) videoStats.getDownloadBandwidth()) + " / " + (int) audioStats.getDownloadBandwidth() + " kbits/s");

View file

@ -377,15 +377,19 @@ private static AssistantActivity instance;
} }
private void launchDownloadCodec() { private void launchDownloadCodec() {
OpenH264DownloadHelper downloadHelper = LinphoneCoreFactory.instance().createOpenH264DownloadHelper(); if (LinphoneManager.getLc().openH264Enabled()) {
if (Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86") && !downloadHelper.isCodecFound()) { OpenH264DownloadHelper downloadHelper = LinphoneCoreFactory.instance().createOpenH264DownloadHelper();
CodecDownloaderFragment codecFragment = new CodecDownloaderFragment(); if (Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86") && !downloadHelper.isCodecFound()) {
changeFragment(codecFragment); CodecDownloaderFragment codecFragment = new CodecDownloaderFragment();
currentFragment = AssistantFragmentsEnum.DOWNLOAD_CODEC; changeFragment(codecFragment);
back.setVisibility(View.VISIBLE); currentFragment = AssistantFragmentsEnum.DOWNLOAD_CODEC;
cancel.setEnabled(false); back.setVisibility(View.VISIBLE);
} else cancel.setEnabled(false);
} else
goToLinphoneActivity();
} else {
goToLinphoneActivity(); goToLinphoneActivity();
}
} }
public void endDownloadCodec() { public void endDownloadCodec() {