Simplify SetLoudSpeaker calls and add a function to receive plug intent

Remove reduntant calls and add a function to receive plug intent.

BUG=None
TEST=local

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2806 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
leozwang@webrtc.org 2012-09-24 07:06:40 +00:00
parent 31b61b5fb6
commit 60c741281d
3 changed files with 37 additions and 16 deletions

View File

@ -16,6 +16,13 @@
</intent-filter>
</activity>
</application>
<receiver android:name="com.juno.brheadset.HeadsetStateReceiver">
<intent-filter>
<action android:name="android.intent.action.HEADSET_PLUG"/>
</intent-filter>
</receiver>
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-feature android:name="android.hardware.camera" />

View File

@ -1402,14 +1402,13 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1Set
JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1SetLoudspeakerStatus(
JNIEnv *,
jobject,
jboolean enable)
{
jboolean enable) {
VALIDATE_HARDWARE_POINTER;
if (voeData.hardware->SetLoudspeakerStatus(enable) != 0) {
__android_log_print(ANDROID_LOG_ERROR, WEBRTC_LOG_TAG,
"SetLoudspeakerStatus(%d) failed", enable);
return -1;
}
return 0;
}

View File

@ -21,8 +21,11 @@ import org.webrtc.videoengine.ViERenderer;
import android.app.TabActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
@ -184,6 +187,8 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
private StatsView statsView = null;
private BroadcastReceiver receiver;
public int GetCameraOrientation(int cameraOrientation) {
Display display = this.getWindowManager().getDefaultDisplay();
int displatyRotation = display.getRotation();
@ -230,6 +235,24 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);
setContentView(R.layout.tabhost);
IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
if (am.isWiredHeadsetOn()) {
enableSpeaker = false;
}
else {
enableSpeaker = true;
}
RouteAudio(enableSpeaker);
}
};
registerReceiver(receiver, receiverFilter );
mTabHost = getTabHost();
// Main tab
@ -597,10 +620,10 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
if (enableVideoSend) {
currentCameraOrientation =
ViEAndroidAPI.GetCameraOrientation(usingFrontCamera?1:0);
ViEAndroidAPI.GetCameraOrientation(usingFrontCamera ? 1 : 0);
ret = ViEAndroidAPI.SetSendCodec(channel, codecType, INIT_BITRATE,
codecSizeWidth, codecSizeHeight, SEND_CODEC_FRAMERATE);
int camId = ViEAndroidAPI.StartCamera(channel, usingFrontCamera?1:0);
int camId = ViEAndroidAPI.StartCamera(channel, usingFrontCamera ? 1 : 0);
if(camId > 0) {
cameraId = camId;
@ -746,16 +769,8 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
}
private void RouteAudio(boolean enableSpeaker) {
int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);
if (sdkVersion >= 5) {
AudioManager am =
(AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
am.setSpeakerphoneOn(enableSpeaker);
}
else {
if (0 != ViEAndroidAPI.VoE_SetLoudspeakerStatus(enableSpeaker)) {
Log.d(TAG, "VoE set louspeaker status failed");
}
if (0 != ViEAndroidAPI.VoE_SetLoudspeakerStatus(enableSpeaker)) {
Log.d(TAG, "VoE set louspeaker status failed");
}
}