Skip to content

Commit

Permalink
Merge branch 'dev/4.3.0' of github.com:AgoraIO/API-Examples into dev/…
Browse files Browse the repository at this point in the history
…4.3.0

* 'dev/4.3.0' of github.com:AgoraIO/API-Examples:
  adapter video extension for v430 (#370)
  [Android][Audio]fix NMS-19192.
  [Android]fix NMS-19192/NMS-19194.
  • Loading branch information
zhaoyongqiang committed Feb 22, 2024
2 parents 11c4166 + 7aabfbb commit 5fdb1f0
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -52,6 +53,9 @@
import io.agora.spatialaudio.RemoteVoicePositionInfo;
import io.agora.spatialaudio.SpatialAudioZone;

/**
* The type Spatial sound.
*/
@Example(
index = 22,
group = ADVANCED,
Expand Down Expand Up @@ -94,7 +98,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
return;
}
try {
/**Creates an RtcEngine instance.
/*Creates an RtcEngine instance.
* @param context The context of Android Activity
* @param appId The App ID issued to you by Agora. See <a href="https://docs.agora.io/en/Agora%20Platform/token#get-an-app-id">
* How to get the App ID</a>
Expand All @@ -107,7 +111,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
config.mEventHandler = iRtcEngineEventHandler;
config.mAreaCode = ((MainApplication) getActivity().getApplication()).getGlobalSettings().getAreaCode();
engine = (RtcEngineEx) RtcEngine.create(config);
/**
/*
* This parameter is for reporting the usages of APIExample to agora background.
* Generally, it is not necessary for you to set this parameter.
*/
Expand Down Expand Up @@ -177,6 +181,7 @@ protected void onPositionChanged() {
float[] forward = new float[]{1.0F, 0.0F, 0.0F};
float[] right = new float[]{0.0F, 1.0F, 0.0F};
float[] up = new float[]{0.0F, 0.0F, 1.0F};
Log.d(TAG, "updateSelfPosition >> pos=" + Arrays.toString(pos));
localSpatial.updateSelfPosition(pos, forward, right, up);
}
});
Expand All @@ -202,11 +207,7 @@ protected void onPositionChanged() {
localSpatial.setZones(new SpatialAudioZone[]{mediaPlayerLeftZone});
} else {
zoneTv.setVisibility(View.INVISIBLE);
SpatialAudioZone worldZone = new SpatialAudioZone();
worldZone.upLength = AXIS_MAX_DISTANCE * 2;
worldZone.forwardLength = AXIS_MAX_DISTANCE * 2;
worldZone.rightLength = AXIS_MAX_DISTANCE * 2;
localSpatial.setZones(new SpatialAudioZone[]{worldZone});
localSpatial.setZones(null);
}
});
}
Expand All @@ -218,7 +219,7 @@ private void joinChannel() {

engine.setClientRole(io.agora.rtc2.Constants.CLIENT_ROLE_BROADCASTER);

/**Please configure accessToken in the string_config file.
/*Please configure accessToken in the string_config file.
* A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
* https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
* A token generated at the server. This applies to scenarios with high-security requirements. For details, see
Expand All @@ -228,7 +229,7 @@ private void joinChannel() {
ChannelMediaOptions option = new ChannelMediaOptions();
option.autoSubscribeAudio = true;

/** Allows a user to join a channel.
/* Allows a user to join a channel.
if you do not specify the uid, we will generate the uid for you*/
int res = engine.joinChannel(ret, channelId, 0, option);
if (res != 0) {
Expand Down Expand Up @@ -298,7 +299,7 @@ private void initMediaPlayers() {
private void showMediaPlayerSettingDialog(IMediaPlayer mediaPlayer) {
String key = "MediaPlayer_" + mediaPlayer.getMediaPlayerId();
BottomSheetDialog dialog = cacheDialogs.get(key);
if(dialog != null){
if (dialog != null) {
dialog.show();
return;
}
Expand Down Expand Up @@ -345,7 +346,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
private void showRemoteUserSettingDialog(int uid) {
String key = "RemoteUser_" + uid;
BottomSheetDialog dialog = cacheDialogs.get(key);
if(dialog != null){
if (dialog != null) {
dialog.show();
return;
}
Expand Down Expand Up @@ -396,7 +397,6 @@ private void unInitMediaPlayers() {
private IMediaPlayer createLoopMediaPlayer() {
IMediaPlayer mediaPlayer = engine.createMediaPlayer();
mediaPlayer.registerPlayerObserver(new IMediaPlayerObserver() {

@Override
public void onPlayerStateChanged(Constants.MediaPlayerState state, Constants.MediaPlayerReason reason) {
if (state.equals(PLAYER_STATE_OPEN_COMPLETED)) {
Expand Down Expand Up @@ -475,22 +475,22 @@ private float[] getVoicePosition(View view) {
float transY = view.getTranslationY();
double posForward = -1 * AXIS_MAX_DISTANCE * transY / ((rootView.getHeight()) / 2.0f);
double posRight = AXIS_MAX_DISTANCE * transX / ((rootView.getWidth()) / 2.0f);
Log.d(TAG, "VoicePosition posForward=" + posForward + ", posRight=" + posRight);
//Log.d(TAG, "VoicePosition posForward=" + posForward + ", posRight=" + posRight);
return new float[]{(float) posForward, (float) posRight, 0.0F};
}

private float[] getViewRelativeSizeInAxis(View view) {
return new float[]{
AXIS_MAX_DISTANCE * view.getWidth() * 1.0f / (rootView.getWidth() / 2.0f),
AXIS_MAX_DISTANCE * view.getHeight() * 1.0f / (rootView.getHeight() / 2.0f) ,
AXIS_MAX_DISTANCE * view.getHeight() * 1.0f / (rootView.getHeight() / 2.0f),
};
}

private BottomSheetDialog showCommonSettingDialog(boolean isMute, SpatialAudioParams params,
CompoundButton.OnCheckedChangeListener muteCheckListener,
CompoundButton.OnCheckedChangeListener blurCheckListener,
CompoundButton.OnCheckedChangeListener airborneCheckListener,
SeekBar.OnSeekBarChangeListener attenuationSeekChangeListener
CompoundButton.OnCheckedChangeListener muteCheckListener,
CompoundButton.OnCheckedChangeListener blurCheckListener,
CompoundButton.OnCheckedChangeListener airborneCheckListener,
SeekBar.OnSeekBarChangeListener attenuationSeekChangeListener
) {
BottomSheetDialog dialog = new BottomSheetDialog(requireContext());
View dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_spatial_sound, null);
Expand Down Expand Up @@ -581,20 +581,23 @@ public boolean onTouch(View v, MotionEvent event) {
v.setTranslationY(newTranY);
onPositionChanged();
break;
case MotionEvent.ACTION_UP:
default:
break;
}
return true;
}

/**
* On position changed.
*/
protected abstract void onPositionChanged();
}

/**
* IRtcEngineEventHandler is an abstract class providing default implementation.
* The SDK uses this class to report to the app on SDK runtime events.
*/
private class InnerRtcEngineEventHandler extends IRtcEngineEventHandler {
private final class InnerRtcEngineEventHandler extends IRtcEngineEventHandler {
@Override
public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
super.onJoinChannelSuccess(channel, uid, elapsed);
Expand All @@ -617,8 +620,8 @@ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {

/**
* Error code description can be found at:
* en: https://api-ref.agora.io/en/voice-sdk/android/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onerror
* cn: https://docs.agora.io/cn/voice-call-4.x/API%20Reference/java_ng/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onerror
* en: https://api-ref.agora.io/en/video-sdk/android/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onerror
* cn: https://docs.agora.io/cn/video-call-4.x/API%20Reference/java_ng/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onerror
*/
@Override
public void onError(int err) {
Expand All @@ -643,7 +646,9 @@ public void onUserJoined(int uid, int elapsed) {
remoteLeftTv.setTag(uid);
remoteLeftTv.setVisibility(View.VISIBLE);
remoteLeftTv.setText(uid + "");
localSpatial.updateRemotePosition(uid, getVoicePositionInfo(remoteLeftTv));
RemoteVoicePositionInfo info = getVoicePositionInfo(remoteLeftTv);
Log.d(TAG, "left remote user >> pos=" + Arrays.toString(info.position));
localSpatial.updateRemotePosition(uid, info);

remoteLeftTv.setOnClickListener(v -> showRemoteUserSettingDialog(uid));
} else if (remoteRightTv.getTag() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@

<TextView
android:id="@+id/tv_zone"
android:layout_width="100dp"
android:layout_height="200dp"
android:layout_width="130dp"
android:layout_height="230dp"
android:layout_gravity="center"
android:background="#88ff8800"
android:gravity="bottom"
Expand Down
4 changes: 2 additions & 2 deletions Android/APIExample/agora-simple-filter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ dependencies {
api fileTree(dir: "libs", include: ["*.jar", "*.aar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ project(agora-simple-filter)
set(agora-lib-so ${PROJECT_SOURCE_DIR}/../agoraLibs/${CMAKE_ANDROID_ARCH_ABI}/libagora-rtc-sdk.so)
link_libraries(${agora-lib-so})

set(agora-ffmpeg-so ${PROJECT_SOURCE_DIR}/../agoraLibs/${CMAKE_ANDROID_ARCH_ABI}/libagora-ffmpeg.so)
link_libraries(${agora-ffmpeg-so})

set(agora-soundtouch-so ${PROJECT_SOURCE_DIR}/../agoraLibs/${CMAKE_ANDROID_ARCH_ABI}/libagora-soundtouch.so)
link_libraries(${agora-soundtouch-so})

set(agora-fdkaac-so ${PROJECT_SOURCE_DIR}/../agoraLibs/${CMAKE_ANDROID_ARCH_ABI}/libagora-fdkaac.so)
link_libraries(${agora-fdkaac-so})

#link opencv so
set(opencv-lib-so ${PROJECT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libopencv_java4.so)
link_libraries(${opencv-lib-so})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ namespace agora {
if (!eglCore_) {
eglCore_ = new EglCore();
offscreenSurface_ = eglCore_->createOffscreenSurface(640, 320);

}
if (!eglCore_->isCurrent(offscreenSurface_)) {
eglCore_->makeCurrent(offscreenSurface_);
}
#endif
return true;
Expand All @@ -57,10 +53,36 @@ namespace agora {
return true;
}

bool WatermarkProcessor::makeCurrent() {
const std::lock_guard<std::mutex> lock(mutex_);
#if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
if (eglCore_ && offscreenSurface_) {
if (!eglCore_->isCurrent(offscreenSurface_)) {
eglCore_->makeCurrent(offscreenSurface_);
}
return true;
}
#endif
return false;
}

bool WatermarkProcessor::detachCurrent() {
const std::lock_guard<std::mutex> lock(mutex_);
#if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
if (eglCore_) {
eglCore_->makeNothingCurrent();
return true;
}
#endif
return false;
}

int WatermarkProcessor::processFrame(agora::rtc::VideoFrameData &capturedFrame) {
// PRINTF_INFO("processFrame: w: %d, h: %d, r: %d, enable: %d", capturedFrame.width, capturedFrame.height, capturedFrame.rotation, wmEffectEnabled_);
if (wmEffectEnabled_) {
makeCurrent();
addWatermark(capturedFrame);
detachCurrent();
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ namespace agora {

bool releaseOpenGL();

bool makeCurrent();

bool detachCurrent();

int processFrame(agora::rtc::VideoFrameData &capturedFrame);

int setParameters(std::string parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ private void stopPublish() {
* This method removes only one stream RTMP URL address each time it is called.*/
unpublishing = true;
retryTask.cancel(true);
retryTask = null;
engine.stopRtmpStream(et_url.getText().toString());
transcoding.removeUser(myUid);
}
Expand Down Expand Up @@ -564,28 +563,25 @@ public void onRtmpStreamingStateChanged(String url, int state, int errCode) {
} else if (state == Constants.RTMP_STREAM_PUBLISH_STATE_IDLE) {
if (unpublishing) {
unpublishing = false;
publishing = false;
/*Push stream not started or ended, make changes to the UI.*/
handler.post(() -> {
publish.setEnabled(true);
publish.setText(getString(R.string.publish));
transCodeSwitch.setEnabled(true);
});
}
// Retry logic
if (retryTask != null) {
if (retried >= MAX_RETRY_TIMES) {
retryTask.cancel(true);
retried = 0;
/*Push stream not started or ended, make changes to the UI.*/
handler.post(() -> {
publish.setEnabled(true);
publish.setText(getString(R.string.publish));
transCodeSwitch.setEnabled(true);
});
} else {
retried++;
startRtmpStreaming();
}
} else if (retried >= MAX_RETRY_TIMES) {
retryTask.cancel(true);
retried = 0;
/*Push stream not started or ended, make changes to the UI.*/
handler.post(() -> {
publish.setEnabled(true);
publish.setText(getString(R.string.publish));
transCodeSwitch.setEnabled(true);
});
} else {
retried++;
startRtmpStreaming();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -180,6 +181,7 @@ protected void onPositionChanged() {
float[] forward = new float[]{1.0F, 0.0F, 0.0F};
float[] right = new float[]{0.0F, 1.0F, 0.0F};
float[] up = new float[]{0.0F, 0.0F, 1.0F};
Log.d(TAG, "updateSelfPosition >> pos=" + Arrays.toString(pos));
localSpatial.updateSelfPosition(pos, forward, right, up);
}
});
Expand All @@ -205,11 +207,7 @@ protected void onPositionChanged() {
localSpatial.setZones(new SpatialAudioZone[]{mediaPlayerLeftZone});
} else {
zoneTv.setVisibility(View.INVISIBLE);
SpatialAudioZone worldZone = new SpatialAudioZone();
worldZone.upLength = AXIS_MAX_DISTANCE * 2;
worldZone.forwardLength = AXIS_MAX_DISTANCE * 2;
worldZone.rightLength = AXIS_MAX_DISTANCE * 2;
localSpatial.setZones(new SpatialAudioZone[]{worldZone});
localSpatial.setZones(null);
}
});
}
Expand Down Expand Up @@ -477,7 +475,7 @@ private float[] getVoicePosition(View view) {
float transY = view.getTranslationY();
double posForward = -1 * AXIS_MAX_DISTANCE * transY / ((rootView.getHeight()) / 2.0f);
double posRight = AXIS_MAX_DISTANCE * transX / ((rootView.getWidth()) / 2.0f);
Log.d(TAG, "VoicePosition posForward=" + posForward + ", posRight=" + posRight);
//Log.d(TAG, "VoicePosition posForward=" + posForward + ", posRight=" + posRight);
return new float[]{(float) posForward, (float) posRight, 0.0F};
}

Expand Down Expand Up @@ -648,7 +646,9 @@ public void onUserJoined(int uid, int elapsed) {
remoteLeftTv.setTag(uid);
remoteLeftTv.setVisibility(View.VISIBLE);
remoteLeftTv.setText(uid + "");
localSpatial.updateRemotePosition(uid, getVoicePositionInfo(remoteLeftTv));
RemoteVoicePositionInfo info = getVoicePositionInfo(remoteLeftTv);
Log.d(TAG, "left remote user >> pos=" + Arrays.toString(info.position));
localSpatial.updateRemotePosition(uid, info);

remoteLeftTv.setOnClickListener(v -> showRemoteUserSettingDialog(uid));
} else if (remoteRightTv.getTag() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@

<TextView
android:id="@+id/tv_zone"
android:layout_width="100dp"
android:layout_height="200dp"
android:layout_width="130dp"
android:layout_height="230dp"
android:layout_gravity="center"
android:background="#88ff8800"
android:gravity="bottom"
Expand Down

0 comments on commit 5fdb1f0

Please sign in to comment.