本月还有3篇微博需要更新,否则就持之以恒的徽章就没啦,前一段时间都在忙各种事情没有时间更新博客,现在阶段性的不太忙了,补上这月个剩下的3篇,关于Linphone的内容,各位有想了解的,想好题目,在留言你提问,如果我能解答我就出个博客专门说一下,解答不了的也没辙了。
本博客的大部分内容是为了记录项目中的一些和业务不太相关,但是和对应技术比较相关的东西,一方面为了以后能回顾一下,另一方面也能帮其它同学解决点实际问题。
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=G722,PCMU,PCMA,GSM"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=PCMU,PCMA,GSM"/>
改为
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=G722,PCMU,PCMA,GSM,H263,H264,VP8"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=PCMU,PCMA,GSM,H263,H264,VP8"/>
/*获得LinphonePreferences的实体类,这个包含了Linphone的所有参数配置*/
LinphonePreferences mPrefs = LinphonePreferences.instance();
/*设置自动接听视频通话的请求,也就是说只要是视频通话来了,直接就接通,不用按键确定,这是我们的业务流,不用理会*/
mPrefs.setAutomaticallyAcceptVideoRequests(true);
/*设置初始话视频电话,设置了这个你拨号的时候就默认为使用视频发起通话了*/
mPrefs.setInitiateVideoCall(true);
/*这是允许视频通话,这个选了false就彻底不能接听或者拨打视频电话了*/
mPrefs.enableVideo(true);
setCodecMime();
/*
设置音频的codec,这里我只选择了打开VP8的codec。H264因为硬件平台的原因,无法正常使用decode所以放弃了
*/
private void setCodecMime()
{
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
for (final PayloadType pt : lc.getVideoCodecs())
{
debug.i("setCodecMime = " + pt.getMime());
if (!pt.getMime().equals("VP8"))
{
try
{
debug.i("disable codec " + pt.getMime());
LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, false);
}
catch (LinphoneCoreException e)
{
Log.e(e);
}
}
}
}
public static void dialNumber(String number)
{
if (LinphoneManager.getLc().getCallsNb() == 0)
{
debug.i("dialNumber(" + number + ");");
LinphoneManager.getInstance().newOutgoingCall("电话号码", "显示姓名");
}
}
public static void answer(Context mContext)
{
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null)
{
List calls = LinphoneUtils.getLinphoneCalls(LinphoneManager.getLc());
for (LinphoneCall call : calls)
{
if (State.IncomingReceived == call.getState())
{
mCall = call;
break;
}
}
}
if (State.IncomingReceived != mCall.getState()) return;
if (mContext.getPackageManager().checkPermission(Manifest.permission.RECORD_AUDIO, mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED || LinphonePreferences.instance()
.audioPermAsked())
{
// startActivity(new Intent(LinphoneActivity.instance(),
// CallIncomingActivity.class));
debug.i("CallIncomingActivity.class");
}
else
{
debug.i("checkAndRequestAudioPermission(true);");
checkAndRequestAudioPermission(mContext, true);
}
LinphoneCallParams params = LinphoneManager.getLc().createCallParams(mCall);
boolean isLowBandwidthConnection = !LinphoneUtils.isHighBandwidthConnection(LinphoneService.instance().getApplicationContext());
if (params != null)
{
params.enableLowBandwidth(isLowBandwidthConnection);
}
else
{
Log.e("Could not create call params for call");
}
if (params == null || !LinphoneManager.getInstance().acceptCallWithParams(mCall, params))
{
// the above method takes care of Samsung Galaxy S
// Toast.makeText(this, R.string.couldnt_accept_call,
// Toast.LENGTH_LONG).show();
}
else
{
// if (!LinphoneActivity.isInstanciated()) {
// return;
// }
final LinphoneCallParams remoteParams = mCall.getRemoteParams();
if (remoteParams != null && remoteParams.getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests())
{
// LinphoneActivity.instance().startVideoActivity(mCall);
debug.i("LinphoneActivity.instance().startVideoActivity(mCall)");
switchVideo(true);
}
else
{
debug.i("LinphoneActivity.instance().startIncallActivity(mCall);");
// LinphoneActivity.instance().startIncallActivity(mCall);
switchVideo(false);
}
}
}
private static void switchVideo(final boolean displayVideo)
{
debug.i("switchVideo");
final LinphoneCall call = LinphoneManager.getLc().getCurrentCall();
if (call == null)
{
return;
}
// Check if the call is not terminated
if (call.getState() == State.CallEnd || call.getState() == State.CallReleased) return;
if (!displayVideo)
{
// showAudioView();
}
else
{
if (!call.getRemoteParams().isLowBandwidthEnabled())
{
LinphoneManager.getInstance().addVideo();
debug.i("addVideo");
// if (videoCallFragment == null ||
// !videoCallFragment.isVisible())
// {
// showVideoView();
// }
}
else
{
// displayCustomToast(getString(R.string.error_low_bandwidth),
// Toast.LENGTH_LONG);
}
}
}
if (!call.getRemoteParams().isLowBandwidthEnabled())
{
LinphoneManager.getInstance().addVideo();
debug.i("addVideo");
// if (videoCallFragment == null ||
// !videoCallFragment.isVisible())
// {
// showVideoView();
// }
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@+drawable/background"
android:gravity="center_horizontal"
tools:context="com.sxkeda.launcher.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="@+id/fragmentContainer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/titleBar"
android:layout_toRightOf="@+id/left_icon_panel"
android:orientation="vertical" >
LinearLayout>
RelativeLayout>
if (state == LinphoneCall.State.Connected)
{
LinphoneCall mCall = LinphoneManager.getLc().getCurrentCall();
/*在接通状态下,必须查看来电的远程参数,确定其带有视频通话的参数才打开视频通话,否则只进行语音通话*/
final LinphoneCallParams remoteParams = mCall.getRemoteParams();
debug.i("remoteParams.getVideoEnabled() = "+remoteParams.getVideoEnabled());
if (remoteParams != null && remoteParams.getVideoEnabled())
{
changeFragmentToVideoCall();
}
else
{
changeFragmentToAudioCall();
}
}
if (state == LinphoneCall.State.OutgoingProgress)
{
debug.i("to CallVideoFragment");
if (Business.getInstance().isCurrentCallVideo())
{
changeFragmentToVideoCall();
}
else
{
changeFragmentToAudioCall();
}
}
private void changeFragmentToVideoCall()
{
CallVideoFragment videoCallFragment = new CallVideoFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragmentContainer2, videoCallFragment);
transaction.commit();
}