Skip to content

Commit

Permalink
Merge pull request #71 from OurEra/v4x
Browse files Browse the repository at this point in the history
Release for v5.0.0
  • Loading branch information
OurEra authored Apr 15, 2022
2 parents 9c0d49e + 1f60ad9 commit 2cb6922
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 61 deletions.
8 changes: 5 additions & 3 deletions QNDroidRTCDemo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.qiniu.droid.rtc.demo"
minSdkVersion 18
targetSdkVersion 30
versionCode 33
versionName "4.0.1"
versionCode 34
versionName "5.0.0"
buildConfigField "long", "BUILD_TIMESTAMP", System.currentTimeMillis() + "L"
}

Expand Down Expand Up @@ -41,11 +41,13 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'com.qiniu:happy-dns:0.2.18'
// xCrash
implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.0.0'

// QNDroidRTCLibrary
if (buildWithQNDroidRTCLibrary) {
implementation project(':library')
implementation files('libs/pldroid-player-2.1.4.jar')
implementation files('libs/pldroid-player-2.4.0.jar')
} else {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
Expand Down
Binary file removed QNDroidRTCDemo/app/libs/pldroid-player-2.1.4.jar
Binary file not shown.
Binary file added QNDroidRTCDemo/app/libs/pldroid-player-2.4.0.jar
Binary file not shown.
Binary file removed QNDroidRTCDemo/app/libs/qndroid-rtc-4.0.1.jar
Binary file not shown.
Binary file added QNDroidRTCDemo/app/libs/qndroid-rtc-5.0.0.jar
Binary file not shown.
1 change: 1 addition & 0 deletions QNDroidRTCDemo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".RTCApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.qiniu.droid.rtc.demo;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.qiniu.droid.rtc.QNFileLogHelper;
import com.qiniu.droid.rtc.demo.utils.ToastUtils;
import com.qiniu.droid.rtc.demo.utils.Utils;

import java.io.File;

import xcrash.TombstoneManager;
import xcrash.XCrash;

public class RTCApplication extends Application {
private static final String TAG = "RTCApplication";

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);

Log.i(TAG, "external file path = " + getExternalFilesDir(null));
xcrash.XCrash.init(this, new XCrash.InitParameters()
.setLogDir(getExternalFilesDir(null).getAbsolutePath())
.setJavaDumpNetworkInfo(false)
.setNativeDumpNetwork(false)
.setNativeDumpAllThreads(false)
.setAppVersion(Utils.getVersion(this)));
checkToUploadCrashFiles();
}

private void checkToUploadCrashFiles() {
File crashFolder = new File(getExternalFilesDir(null).getAbsolutePath());
File[] crashFiles = crashFolder.listFiles();
if (crashFiles == null) {
return;
}
for (File crashFile : crashFiles) {
if (crashFile.isFile()) {
QNFileLogHelper.getInstance().reportLogFileByPath(crashFile.getPath(), new QNFileLogHelper.LogReportCallback() {
@Override
public void onReportSuccess(String name) {
ToastUtils.showShortToast(RTCApplication.this, "崩溃日志已上传!");
TombstoneManager.deleteTombstone(crashFile.getPath());
}

@Override
public void onReportError(String name, String errorMsg) {
ToastUtils.showShortToast(RTCApplication.this, "崩溃日志上传失败 : " + errorMsg);
}
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {

//播放器相关
mVideoView.setVideoPath(mRtmpUrl);
mVideoView.setOnErrorListener(errorCode -> {
mVideoView.setOnErrorListener((errorCode, extraData) -> {
switch (errorCode) {
case PLOnErrorListener.ERROR_CODE_OPEN_FAILED:
logAndToast("播放器打开失败,请确认是否在推流!");
Expand All @@ -91,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
return false;
});
mVideoView.setOnInfoListener((what, extra) -> {
mVideoView.setOnInfoListener((what, extra, extraData) -> {
switch (what) {
case PLOnInfoListener.MEDIA_INFO_VIDEO_RENDERING_START:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.qiniu.droid.rtc.demo.activity;

import static com.qiniu.droid.rtc.demo.utils.Config.DEFAULT_FPS;
import static com.qiniu.droid.rtc.demo.utils.Config.DEFAULT_RESOLUTION;
import static com.qiniu.droid.rtc.demo.utils.Utils.getSystemUiVisibility;

import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
Expand All @@ -16,8 +12,8 @@
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
Expand Down Expand Up @@ -102,6 +98,10 @@
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

import static com.qiniu.droid.rtc.demo.utils.Config.DEFAULT_FPS;
import static com.qiniu.droid.rtc.demo.utils.Config.DEFAULT_RESOLUTION;
import static com.qiniu.droid.rtc.demo.utils.Utils.getSystemUiVisibility;

public class RoomActivity extends FragmentActivity implements ControlFragment.OnCallEvents {
private static final String TAG = "RoomActivity";

Expand Down Expand Up @@ -135,7 +135,6 @@ public class RoomActivity extends FragmentActivity implements ControlFragment.On
private boolean mBeautyEnabled = false;
private boolean mVideoEnabled = true;
private boolean mSpeakerEnabled = true;
private boolean mIsError = false;
private boolean mIsAdmin = false;
private boolean mIsJoinedRoom = false;
private ControlFragment mControlFragment;
Expand Down Expand Up @@ -198,6 +197,12 @@ public class RoomActivity extends FragmentActivity implements ControlFragment.On
*/
private int mSerialNum = 0;

/**
* {@link QNRTC#init} 和 {@link QNRTC#deinit()} 为静态方法,需要对称调用;
* 为了避免在页面退出进入时存在顺序问题,建议保存是否初始化状态
*/
private static boolean mInitRTC;

private final Semaphore mCaptureStoppedSem = new Semaphore(1);

@Override
Expand Down Expand Up @@ -267,28 +272,34 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}
}
// 初始化 Client 和本地 Track 列表
initClient();
// 初始化本地音视频 track
initLocalTracks();
// 初始化合流相关配置
initMergeLayoutConfig();

// 多人显示窗口管理类
mTrackWindowManager = new TrackWindowManager(mUserId, screenWidth, screenHeight, outMetrics.density, mClient, mTrackWindowFullScreen, mTrackWindowsList);

List<QNTrack> localTrackListExcludeScreenTrack = new ArrayList<>(mLocalTrackList);
localTrackListExcludeScreenTrack.remove(mLocalScreenTrack);
mTrackWindowManager.addTrack(mUserId, localTrackListExcludeScreenTrack);
new Timer().schedule(mUpdateNetWorkQualityInfoTask, 5000, 10000);
if (mInitRTC) {
ToastUtils.showShortToast(RoomActivity.this, "RTC 未释放完成,当前页面不可用,请退出后重试!");
} else {
// 初始化 Client 和本地 Track 列表
initClient();
// 初始化本地音视频 track
initLocalTracks();
// 初始化合流相关配置
initMergeLayoutConfig();

// 多人显示窗口管理类
mTrackWindowManager = new TrackWindowManager(mUserId, screenWidth, screenHeight, outMetrics.density, mClient, mTrackWindowFullScreen, mTrackWindowsList);

List<QNTrack> localTrackListExcludeScreenTrack = new ArrayList<>(mLocalTrackList);
localTrackListExcludeScreenTrack.remove(mLocalScreenTrack);
mTrackWindowManager.addTrack(mUserId, localTrackListExcludeScreenTrack);
new Timer().schedule(mUpdateNetWorkQualityInfoTask, 5000, 10000);
mInitRTC = true;
}
}

@Override
protected void onResume() {
super.onResume();
// 开始视频采集
startCaptureAfterAcquire();
if (!mIsJoinedRoom) {
if (!mIsJoinedRoom && mClient != null) {
// 加入房间
mClient.join(mRoomToken);
}
Expand Down Expand Up @@ -321,6 +332,24 @@ protected void onPause() {
@Override
protected void onDestroy() {
super.onDestroy();
releaseClient();
if (mInitRTC) {
// 反初始化
QNRTC.deinit();
mInitRTC = false;
}
if (mTrackWindowFullScreen != null) {
mTrackWindowFullScreen.dispose();
}
for (UserTrackView item : mTrackWindowsList) {
item.dispose();
}
mTrackWindowsList.clear();
mPopWindow = null;
}

private void releaseClient() {
mUpdateNetWorkQualityInfoTask.cancel();
if (mClient != null) {
if (mIsAdmin && mIsMergeStreaming) {
// 如果当前正在合流,则停止
Expand All @@ -336,18 +365,6 @@ protected void onDestroy() {
mClient.leave();
mClient = null;
}
// 反初始化
QNRTC.deinit();

mUpdateNetWorkQualityInfoTask.cancel();
if (mTrackWindowFullScreen != null) {
mTrackWindowFullScreen.dispose();
}
for (UserTrackView item : mTrackWindowsList) {
item.dispose();
}
mTrackWindowsList.clear();
mPopWindow = null;
}

/**
Expand Down Expand Up @@ -522,6 +539,7 @@ private void initMergeLayoutConfig() {
}
} else {
// 更新合流布局到默认合流配置
mCurrentMergeConfig = new QNTranscodingLiveStreamingConfig();
setMergeStreamLayouts();
}
if (mPopWindow != null) {
Expand Down Expand Up @@ -552,14 +570,6 @@ private void disconnectWithErrorMessage(final String errorMessage) {
.show();
}

private void reportError(final String description) {
// TODO: handle error.
if (!mIsError) {
mIsError = true;
disconnectWithErrorMessage(description);
}
}

private void showKickoutDialog(final String userId) {
if (mKickOutDialog == null) {
mKickOutDialog = new AlertDialog.Builder(this)
Expand All @@ -586,13 +596,14 @@ private void resetMergeStream() {

// video tracks merge layout options.
List<RTCTrackMergeOption> roomVideoTrackList = mRoomMergeOption.getVideoMergeOptions();
boolean isDefaultStreaming = (mCurrentMergeConfig == null || TextUtils.isEmpty(mCurrentMergeConfig.getStreamID()));
if (!roomVideoTrackList.isEmpty()) {
List<QNTranscodingLiveStreamingTrack> mergeTrackOptions = SplitUtils.split(
roomVideoTrackList.size(),
mCurrentMergeConfig == null ?
isDefaultStreaming ?
QNAppServer.STREAMING_WIDTH
: mCurrentMergeConfig.getWidth(),
mCurrentMergeConfig == null ?
isDefaultStreaming ?
QNAppServer.STREAMING_HEIGHT
: mCurrentMergeConfig.getHeight()
);
Expand Down Expand Up @@ -690,9 +701,7 @@ private void updateMergeTrack() {

@Override
public void onCallHangUp() {
if (mClient != null) {
mClient.leave();
}
releaseClient();
finish();
}

Expand Down Expand Up @@ -822,9 +831,11 @@ public void onToggleDirectLiving() {
private final TimerTask mUpdateNetWorkQualityInfoTask = new TimerTask() {
@Override
public void run() {
Map<String, QNNetworkQuality> qualityMap = mClient.getUserNetworkQuality();
for (Map.Entry<String, QNNetworkQuality> entry : qualityMap.entrySet()) {
Log.i(TAG, "remote user " + entry.getKey() + " " + entry.getValue().toString());
if (mClient != null) {
Map<String, QNNetworkQuality> qualityMap = mClient.getUserNetworkQuality();
for (Map.Entry<String, QNNetworkQuality> entry : qualityMap.entrySet()) {
Log.i(TAG, "remote user " + entry.getKey() + " " + entry.getValue().toString());
}
}
}
};
Expand Down Expand Up @@ -1088,8 +1099,8 @@ public void onSubscribed(String remoteUserID, List<QNRemoteAudioTrack> remoteAud
tracks.addAll(remoteAudioTracks);
tracks.addAll(remoteVideoTracks);
mTrackWindowManager.addTrack(remoteUserID, tracks);
for (QNRemoteAudioTrack audioTrack : remoteAudioTracks) {
audioTrack.setTrackInfoChangedListener(new QNTrackInfoChangedListener() {
for (QNTrack track : tracks) {
((QNRemoteTrack)track).setTrackInfoChangedListener(new QNTrackInfoChangedListener() {
@Override
public void onMuteStateChanged(boolean isMuted) {
updateRemoteLogText("onRemoteUserMuted:remoteUserId = " + remoteUserID);
Expand Down Expand Up @@ -1200,7 +1211,7 @@ public void onError(int errorCode, String errorMessage) {

private final QNLiveStreamingListener mLiveStreamingListener = new QNLiveStreamingListener() {
/**
* 当转推成功的时候会回调此方法
* 当自定义合流任务和直接转推任务开启成功的时候会回调此方法
*
* @param streamID 转推成功的 streamID
*/
Expand Down Expand Up @@ -1237,7 +1248,6 @@ public void onStarted(String streamID) {

@Override
public void onStopped(String streamID) {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public class Config {
};

public static int[] DEFAULT_BITRATE = {
600 * 1000, // (500 - 600kbps)
1000 * 1000, // (900 - 1200kbps)
1500 * 1000, // (1400 - 1500kbps)
2000 * 1000 // (1800 - 2000kbps)
600, // (500 - 600kbps)
1000, // (900 - 1200kbps)
1500, // (1400 - 1500kbps)
2000 // (1800 - 2000kbps)
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ public static DnsManager getDefaultDnsManager(Context context) {
IResolver r2 = AndroidDnsServer.defaultResolver(context);
return new DnsManager(NetworkInfo.normal, new IResolver[]{r0, r1, r2});
}

public static String getVersion(Context context) {
PackageManager packageManager = context.getPackageManager();
try {
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
return packageInfo.versionName;

} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
}
Binary file modified QNDroidRTCDemo/app/src/main/jniLibs/arm64-v8a/libQPlayer.so
Binary file not shown.
Binary file modified QNDroidRTCDemo/app/src/main/jniLibs/arm64-v8a/libqcOpenSSL.so
Binary file not shown.
Binary file modified QNDroidRTCDemo/app/src/main/jniLibs/arm64-v8a/libqndroid_rtc.so
Binary file not shown.
Binary file modified QNDroidRTCDemo/app/src/main/jniLibs/armeabi-v7a/libQPlayer.so
Binary file not shown.
Binary file modified QNDroidRTCDemo/app/src/main/jniLibs/armeabi-v7a/libqcOpenSSL.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified QNDroidRTCDemo/app/src/main/jniLibs/x86/libqndroid_rtc.so
Binary file not shown.
Loading

0 comments on commit 2cb6922

Please sign in to comment.