Skip to content

Commit

Permalink
feat: support 3.3.0 for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Jan 27, 2021
1 parent de52ca6 commit 9c48594
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 64 deletions.
77 changes: 75 additions & 2 deletions Annotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.annotation.RetentionPolicy;

import io.agora.rtc.Constants;
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngineConfig;
import io.agora.rtc.video.BeautyOptions;
import io.agora.rtc.video.VideoCanvas;
Expand Down Expand Up @@ -265,12 +266,14 @@ public class Annotations {
AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_AUTO,
AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE,
AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_PREVIEW,
AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_MANUAL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraCameraCaptureOutputPreference {
int CAPTURER_OUTPUT_PREFERENCE_AUTO = 0;
int CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE = 1;
int CAPTURER_OUTPUT_PREFERENCE_PREVIEW = 2;
int CAPTURER_OUTPUT_PREFERENCE_MANUAL = 3;
}

@IntDef({
Expand Down Expand Up @@ -362,6 +365,7 @@ public class Annotations {
Constants.CONNECTION_CHANGED_RENEW_TOKEN,
Constants.CONNECTION_CHANGED_CLIENT_IP_ADDRESS_CHANGED,
Constants.CONNECTION_CHANGED_KEEP_ALIVE_TIMEOUT,
Constants.CONNECTION_CHANGED_PROXY_SERVER_INTERRUPTED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraConnectionChangedReason {
Expand Down Expand Up @@ -452,6 +456,7 @@ public class Annotations {
Constants.ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR,
Constants.ERR_PUBLISH_STREAM_NOT_FOUND,
Constants.ERR_PUBLISH_STREAM_FORMAT_NOT_SUPPORTED,
Constants.ERR_MODULE_NOT_FOUND,
Constants.ERR_LOAD_MEDIA_ENGINE,
Constants.ERR_START_CALL,
Constants.ERR_START_CAMERA,
Expand Down Expand Up @@ -765,8 +770,7 @@ public class Annotations {
Constants.WARN_ADM_RECORD_IS_OCCUPIED,
Constants.WARN_APM_HOWLING,
Constants.WARN_ADM_GLITCH_STATE,
// TODO(3.3.0) WARN_APM_RESIDUAL_ECHO
Constants.WARN_ADM_IMPROPER_SETTINGS,
Constants.WARN_APM_RESIDUAL_ECHO,
Constants.WARN_SUPER_RESOLUTION_STREAM_OVER_LIMITATION,
Constants.WARN_SUPER_RESOLUTION_USER_COUNT_OVER_LIMITATION,
Constants.WARN_SUPER_RESOLUTION_DEVICE_NOT_SUPPORTED,
Expand Down Expand Up @@ -845,6 +849,7 @@ public class Annotations {
Constants.CHAT_BEAUTIFIER_MAGNETIC,
Constants.CHAT_BEAUTIFIER_FRESH,
Constants.CHAT_BEAUTIFIER_VITALITY,
Constants.SINGING_BEAUTIFIER,
Constants.TIMBRE_TRANSFORMATION_VIGOROUS,
Constants.TIMBRE_TRANSFORMATION_DEEP,
Constants.TIMBRE_TRANSFORMATION_MELLOW,
Expand All @@ -865,4 +870,72 @@ public class Annotations {
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraAudienceLatencyLevelType {
}

@IntDef({
Constants.TRANSPORT_TYPE_NONE_PROXY,
Constants.TRANSPORT_TYPE_UDP_PROXY,
Constants.TRANSPORT_TYPE_TCP_PROXY,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraCloudProxyType {
}

@IntDef({
AgoraLogLevel.LOG_LEVEL_NONE,
AgoraLogLevel.LOG_LEVEL_INFO,
AgoraLogLevel.LOG_LEVEL_WARN,
AgoraLogLevel.LOG_LEVEL_ERROR,
AgoraLogLevel.LOG_LEVEL_FATAL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraLogLevel {
int LOG_LEVEL_NONE = 0;
int LOG_LEVEL_INFO = 1;
int LOG_LEVEL_WARN = 2;
int LOG_LEVEL_ERROR = 4;
int LOG_LEVEL_FATAL = 8;
}

@IntDef({
Constants.CAPTURE_BRIGHTNESS_LEVEL_INVALID,
Constants.CAPTURE_BRIGHTNESS_LEVEL_NORMAL,
Constants.CAPTURE_BRIGHTNESS_LEVEL_BRIGHT,
Constants.CAPTURE_BRIGHTNESS_LEVEL_DARK,
})
public @interface AgoraCaptureBrightnessLevelType {
}

@IntDef({
IRtcEngineEventHandler.UploadErrorReason.UPLOAD_SUCCESS,
IRtcEngineEventHandler.UploadErrorReason.UPLOAD_NET_ERROR,
IRtcEngineEventHandler.UploadErrorReason.UPLOAD_SERVER_ERROR,
})
public @interface AgoraUploadErrorReason {
}

@IntDef({
IRtcEngineEventHandler.ExperienceQuality.EXPERIENCE_GOOD,
IRtcEngineEventHandler.ExperienceQuality.EXPERIENCE_BAD,
})
public @interface AgoraExperienceQualityType {
}

@IntDef({
IRtcEngineEventHandler.ExperiencePoorReason.EXPERIENCE_REASON_NONE,
IRtcEngineEventHandler.ExperiencePoorReason.REMOTE_NETWORK_QUALITY_POOR,
IRtcEngineEventHandler.ExperiencePoorReason.LOCAL_NETWORK_QUALITY_POOR,
IRtcEngineEventHandler.ExperiencePoorReason.WIRELESS_SIGNAL_POOR,
IRtcEngineEventHandler.ExperiencePoorReason.WIFI_BLUETOOTH_COEXIST,
})
public @interface AgoraExperiencePoorReason {
}

@IntDef({
Constants.SR_STATE_REASON_SUCCESS,
Constants.SR_STATE_REASON_STREAM_OVER_LIMITATION,
Constants.SR_STATE_REASON_USER_COUNT_OVER_LIMITATION,
Constants.SR_STATE_REASON_DEVICE_NOT_SUPPORTED,
})
public @interface AgoraSuperResolutionStateReason {
}
}
31 changes: 30 additions & 1 deletion BeanCovertor.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.agora.rtc.base

import android.graphics.Color
import io.agora.rtc.RtcEngineConfig
import io.agora.rtc.internal.EncryptionConfig
import io.agora.rtc.internal.LastmileProbeConfig
import io.agora.rtc.live.LiveInjectStreamConfig
import io.agora.rtc.live.LiveTranscoding
import io.agora.rtc.live.LiveTranscoding.TranscodingUser
import io.agora.rtc.models.ChannelMediaOptions
import io.agora.rtc.models.ClientRoleOptions
import io.agora.rtc.models.DataStreamConfig
import io.agora.rtc.video.*

fun mapToVideoDimensions(map: Map<*, *>): VideoEncoderConfiguration.VideoDimensions {
Expand Down Expand Up @@ -162,7 +164,11 @@ fun mapToCameraCapturerConfiguration(map: Map<*, *>): CameraCapturerConfiguratio
return CameraCapturerConfiguration(
intToCapturerOutputPreference((map["preference"] as Number).toInt()),
intToCameraDirection((map["cameraDirection"] as Number).toInt())
)
).apply {
dimensions = CameraCapturerConfiguration.CaptureDimensions()
(map["captureWidth"] as? Number)?.toInt()?.let { dimensions.width = it }
(map["captureHeight"] as? Number)?.toInt()?.let { dimensions.height = it }
}
}

fun mapToChannelMediaOptions(map: Map<*, *>): ChannelMediaOptions {
Expand All @@ -172,6 +178,14 @@ fun mapToChannelMediaOptions(map: Map<*, *>): ChannelMediaOptions {
}
}

fun mapToRtcEngineConfig(map: Map<*, *>): RtcEngineConfig {
return RtcEngineConfig().apply {
mAppId = map["appId"] as String
(map["areaCode"] as? Number)?.toInt()?.let { mAreaCode = it }
(map["logConfig"] as? Map<*, *>)?.let { mLogConfig = mapToLogConfig(it) }
}
}

fun mapToEncryptionConfig(map: Map<*, *>): EncryptionConfig {
return EncryptionConfig().apply {
(map["encryptionMode"] as? Number)?.let { encryptionMode = intToEncryptionMode(it.toInt()) }
Expand All @@ -184,3 +198,18 @@ fun mapToClientRoleOptions(map: Map<*, *>): ClientRoleOptions {
(map["audienceLatencyLevel"] as? Number)?.let { audienceLatencyLevel = it.toInt() }
}
}

fun mapToLogConfig(map: Map<*, *>): RtcEngineConfig.LogConfig {
return RtcEngineConfig.LogConfig().apply {
(map["filePath"] as? String)?.let { filePath = it }
(map["fileSize"] as? Number)?.let { fileSize = it.toInt() }
(map["level"] as? Number)?.let { level = it.toInt() }
}
}

fun mapToDataStreamConfig(map: Map<*, *>): DataStreamConfig {
return DataStreamConfig().apply {
(map["syncWithAudio"] as? Boolean)?.let { syncWithAudio = it }
(map["ordered"] as? Boolean)?.let { ordered = it }
}
}
7 changes: 5 additions & 2 deletions Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ fun RemoteAudioStats.toMap(): Map<String, Any?> {
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime,
"publishDuration" to publishDuration
"publishDuration" to publishDuration,
"qoeQuality" to qoeQuality,
"qualityChangedReason" to qualityChangedReason
)
}

Expand All @@ -89,7 +91,8 @@ fun LocalVideoStats.toMap(): Map<String, Any?> {
"encodedFrameCount" to encodedFrameCount,
"codecType" to codecType,
"txPacketLossRate" to txPacketLossRate,
"captureFrameRate" to captureFrameRate
"captureFrameRate" to captureFrameRate,
"captureBrightnessLevel" to captureBrightnessLevel
)
}

Expand Down
2 changes: 1 addition & 1 deletion MediaObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger
class MediaObserver(
private val emit: (data: Map<String, Any?>?) -> Unit
) : IMetadataObserver {
private var maxMetadataSize = AtomicInteger(0)
private var maxMetadataSize = AtomicInteger(1024)
private var metadataList = Collections.synchronizedList<String>(mutableListOf())

fun addMetadata(metadata: String) {
Expand Down
56 changes: 28 additions & 28 deletions RtcChannel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.agora.rtc.base

import io.agora.rtc.Constants
import io.agora.rtc.IMetadataObserver
import io.agora.rtc.RtcChannel
import io.agora.rtc.RtcEngine
Expand Down Expand Up @@ -42,6 +41,7 @@ class IRtcChannel {

fun muteAllRemoteAudioStreams(params: Map<String, *>, callback: Callback)

@Deprecated("")
fun setDefaultMuteAllRemoteAudioStreams(params: Map<String, *>, callback: Callback)
}

Expand All @@ -50,7 +50,10 @@ class IRtcChannel {

fun muteAllRemoteVideoStreams(params: Map<String, *>, callback: Callback)

@Deprecated("")
fun setDefaultMuteAllRemoteVideoStreams(params: Map<String, *>, callback: Callback)

fun enableRemoteSuperResolution(params: Map<String, *>, callback: Callback)
}

interface RtcVoicePositionInterface {
Expand Down Expand Up @@ -94,8 +97,10 @@ class IRtcChannel {
}

interface RtcEncryptionInterface {
@Deprecated("")
fun setEncryptionSecret(params: Map<String, *>, callback: Callback)

@Deprecated("")
fun setEncryptionMode(params: Map<String, *>, callback: Callback)

fun enableEncryption(params: Map<String, *>, callback: Callback)
Expand Down Expand Up @@ -141,11 +146,7 @@ class RtcChannelManager(
}

override fun destroy(params: Map<String, *>, callback: Callback) {
var code: Int? = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = rtcChannelMap.remove(it.channelId())?.destroy()
}
callback.code(code)
callback.code(rtcChannelMap.remove(params["channelId"] as String)?.destroy())
}

override fun setClientRole(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -217,6 +218,10 @@ class RtcChannelManager(
callback.code(this[params["channelId"] as String]?.setDefaultMuteAllRemoteVideoStreams(params["muted"] as Boolean))
}

override fun enableRemoteSuperResolution(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.enableRemoteSuperResolution((params["uid"] as Number).toInt(), params["enable"] as Boolean))
}

override fun setRemoteVoicePosition(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.setRemoteVoicePosition((params["uid"] as Number).toInt(), (params["pan"] as Number).toDouble(), (params["gain"] as Number).toDouble()))
}
Expand Down Expand Up @@ -258,24 +263,22 @@ class RtcChannelManager(
}

override fun registerMediaMetadataObserver(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
val mediaObserver = MediaObserver { data ->
emit(RtcChannelEvents.MetadataReceived, data?.toMutableMap()?.apply { put("channelId", it.channelId()) })
}
code = it.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)
if (code == 0) mediaObserverMap[it.channelId()] = mediaObserver
val channelId = params["channelId"] as String
val mediaObserver = MediaObserver { data ->
emit(RtcChannelEvents.MetadataReceived, data?.toMutableMap()?.apply { put("channelId", channelId) })
}
callback.code(this[channelId]?.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)) {
mediaObserverMap[channelId] = mediaObserver
Unit
}
callback.code(code)
}

override fun unregisterMediaMetadataObserver(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)
if (code == 0) mediaObserverMap.remove(it.channelId())
val channelId = params["channelId"] as String
callback.code(this[channelId]?.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)) {
mediaObserverMap.remove(channelId)
Unit
}
callback.code(code)
}

override fun setMaxMetadataSize(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -318,18 +321,15 @@ class RtcChannelManager(
}

override fun createDataStream(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)
val channel = this[params["channelId"] as String]
(params["config"] as? Map<*, *>)?.let { config ->
callback.code(channel?.createDataStream(mapToDataStreamConfig(config))) { it }
return@createDataStream
}
callback.code(code) { it }
callback.code(channel?.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)) { it }
}

override fun sendStreamMessage(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray())
}
callback.code(code)
callback.code(this[params["channelId"] as String]?.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray()))
}
}
8 changes: 7 additions & 1 deletion RtcChannelEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class RtcChannelEvents {
const val AudioSubscribeStateChanged = "AudioSubscribeStateChanged"
const val VideoSubscribeStateChanged = "VideoSubscribeStateChanged"
const val RtmpStreamingEvent = "RtmpStreamingEvent"
const val UserSuperResolutionEnabled = "UserSuperResolutionEnabled"

fun toMap(): Map<String, String> {
return hashMapOf(
Expand Down Expand Up @@ -79,7 +80,8 @@ class RtcChannelEvents {
"VideoPublishStateChanged" to VideoPublishStateChanged,
"AudioSubscribeStateChanged" to AudioSubscribeStateChanged,
"VideoSubscribeStateChanged" to VideoSubscribeStateChanged,
"RtmpStreamingEvent" to RtmpStreamingEvent
"RtmpStreamingEvent" to RtmpStreamingEvent,
"UserSuperResolutionEnabled" to UserSuperResolutionEnabled
)
}
}
Expand Down Expand Up @@ -236,4 +238,8 @@ class RtcChannelEventHandler(
override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, @Annotations.AgoraRtmpStreamingEvent errCode: Int) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, errCode)
}

override fun onUserSuperResolutionEnabled(rtcChannel: RtcChannel?, uid: Int, enabled: Boolean, @Annotations.AgoraSuperResolutionStateReason reason: Int) {
callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid, enabled, reason)
}
}
Loading

0 comments on commit 9c48594

Please sign in to comment.