Skip to content

Commit

Permalink
feat: support 3.0.+
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Mar 26, 2021
1 parent ad03101 commit 21c7655
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 227 deletions.
59 changes: 12 additions & 47 deletions Annotations.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.agora.rtc.base;

import androidx.annotation.IntDef;
import androidx.annotation.StringDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -388,20 +389,16 @@ public class Annotations {
int MAINTAIN_BALANCED = 2;
}

@IntDef({
AgoraEncryptionMode.NONE,
@StringDef({
AgoraEncryptionMode.AES128XTS,
AgoraEncryptionMode.AES128ECB,
AgoraEncryptionMode.AES256XTS,
AgoraEncryptionMode.SM4128ECB,
AgoraEncryptionMode.AES128ECB,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraEncryptionMode {
int NONE = 0;
int AES128XTS = 1;
int AES128ECB = 2;
int AES256XTS = 3;
int SM4128ECB = 4;
String AES128XTS = "aes-128-xts";
String AES256XTS = "aes-256-xts";
String AES128ECB = "aes-128-ecb";
}

@IntDef({
Expand All @@ -425,7 +422,6 @@ public class Annotations {
Constants.ERR_ALREADY_IN_USE,
Constants.ERR_INVALID_APP_ID,
Constants.ERR_INVALID_CHANNEL_NAME,
Constants.ERR_NO_SERVER_RESOURCES,
Constants.ERR_TOKEN_EXPIRED,
Constants.ERR_INVALID_TOKEN,
Constants.ERR_CONNECTION_INTERRUPTED,
Expand Down Expand Up @@ -755,57 +751,26 @@ public class Annotations {
Constants.WARN_ADM_RUNTIME_PLAYOUT_WARNING,
Constants.WARN_ADM_RUNTIME_RECORDING_WARNING,
Constants.WARN_ADM_RECORD_AUDIO_SILENCE,
Constants.WARN_ADM_PLAYOUT_ABNORMAL_FREQUENCY,
Constants.WARN_ADM_RECORD_ABNORMAL_FREQUENCY,
Constants.WARN_ADM_CALL_INTERRUPTION,
Constants.WARN_ADM_RECORD_AUDIO_LOWLEVEL,
Constants.WARN_ADM_PLAYOUT_AUDIO_LOWLEVEL,
Constants.WARN_ADM_RECORD_IS_OCCUPIED,
Constants.WARN_APM_HOWLING,
Constants.WARN_ADM_GLITCH_STATE,
Constants.WARN_APM_RESIDUAL_ECHO,
Constants.WARN_ADM_IMPROPER_SETTINGS,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraWarningCode {
}

@IntDef({
RtcEngineConfig.AreaCode.AREA_CODE_CN,
RtcEngineConfig.AreaCode.AREA_CODE_NA,
RtcEngineConfig.AreaCode.AREA_CODE_EU,
RtcEngineConfig.AreaCode.AREA_CODE_AS,
RtcEngineConfig.AreaCode.AREA_CODE_JP,
RtcEngineConfig.AreaCode.AREA_CODE_IN,
RtcEngineConfig.AreaCode.AREA_CODE_GLOB,
RtcEngineConfig.IPAreaCode.AREA_CN,
RtcEngineConfig.IPAreaCode.AREA_NA,
RtcEngineConfig.IPAreaCode.AREA_EUR,
RtcEngineConfig.IPAreaCode.AREA_AS,
RtcEngineConfig.IPAreaCode.AREA_GLOBAL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraAreaCode {
}

@IntDef({
Constants.SUB_STATE_IDLE,
Constants.SUB_STATE_NO_SUBSCRIBED,
Constants.SUB_STATE_SUBSCRIBING,
Constants.SUB_STATE_SUBSCRIBED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraStreamSubscribeState {
}

@IntDef({
Constants.PUB_STATE_IDLE,
Constants.PUB_STATE_NO_PUBLISHED,
Constants.PUB_STATE_PUBLISHING,
Constants.PUB_STATE_PUBLISHED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraStreamPublishState {
}

@IntDef({
Constants.RTMP_STREAMING_EVENT_FAILED_LOAD_IMAGE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraRtmpStreamingEvent {
}
}
8 changes: 0 additions & 8 deletions BeanCovertor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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
Expand Down Expand Up @@ -178,10 +177,3 @@ fun mapToRtcEngineConfig(map: Map<*, *>): RtcEngineConfig {
(map["areaCode"] as? Number)?.toInt()?.let { mAreaCode = it }
}
}

fun mapToEncryptionConfig(map: Map<*, *>): EncryptionConfig {
return EncryptionConfig().apply {
(map["encryptionMode"] as? Number)?.let { encryptionMode = intToEncryptionMode(it.toInt()) }
(map["encryptionKey"] as? String)?.let { encryptionKey = it }
}
}
10 changes: 0 additions & 10 deletions EnumCovertor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.agora.rtc.base

import io.agora.rtc.internal.EncryptionConfig
import io.agora.rtc.live.LiveInjectStreamConfig
import io.agora.rtc.live.LiveTranscoding
import io.agora.rtc.video.CameraCapturerConfiguration
Expand Down Expand Up @@ -86,12 +85,3 @@ fun intToCameraDirection(@Annotations.AgoraCameraDirection intValue: Int): Camer
}
throw RuntimeException("CameraCapturerConfiguration.CAMERA_DIRECTION not contains $intValue")
}

fun intToEncryptionMode(@Annotations.AgoraEncryptionMode intValue: Int): EncryptionConfig.EncryptionMode {
for (value in EncryptionConfig.EncryptionMode.values()) {
if (value.value == intValue) {
return value
}
}
throw RuntimeException("EncryptionConfig.EncryptionMode not contains $intValue")
}
13 changes: 4 additions & 9 deletions Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ fun LocalAudioStats.toMap(): Map<String, Any?> {
return hashMapOf(
"numChannels" to numChannels,
"sentSampleRate" to sentSampleRate,
"sentBitrate" to sentBitrate,
"txPacketLossRate" to txPacketLossRate
"sentBitrate" to sentBitrate
)
}

Expand Down Expand Up @@ -69,8 +68,7 @@ fun RemoteAudioStats.toMap(): Map<String, Any?> {
"receivedBitrate" to receivedBitrate,
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime,
"publishDuration" to publishDuration
"totalActiveTime" to totalActiveTime
)
}

Expand All @@ -87,9 +85,7 @@ fun LocalVideoStats.toMap(): Map<String, Any?> {
"encodedFrameWidth" to encodedFrameWidth,
"encodedFrameHeight" to encodedFrameHeight,
"encodedFrameCount" to encodedFrameCount,
"codecType" to codecType,
"txPacketLossRate" to txPacketLossRate,
"captureFrameRate" to captureFrameRate
"codecType" to codecType
)
}

Expand All @@ -106,8 +102,7 @@ fun RemoteVideoStats.toMap(): Map<String, Any?> {
"rxStreamType" to rxStreamType,
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime,
"publishDuration" to publishDuration
"totalActiveTime" to totalActiveTime
)
}

Expand Down
15 changes: 1 addition & 14 deletions RtcChannel.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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
import io.agora.rtc.internal.EncryptionConfig
import java.util.*

class IRtcChannel {
Expand Down Expand Up @@ -97,8 +95,6 @@ class IRtcChannel {
fun setEncryptionSecret(params: Map<String, *>, callback: Callback)

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

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

interface RtcInjectStreamInterface {
Expand Down Expand Up @@ -287,16 +283,7 @@ class RtcChannelManager(
}

override fun setEncryptionMode(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.setEncryptionMode(when ((params["encryptionMode"] as Number).toInt()) {
EncryptionConfig.EncryptionMode.AES_128_XTS.value -> "aes-128-xts"
EncryptionConfig.EncryptionMode.AES_128_ECB.value -> "aes-128-ecb"
EncryptionConfig.EncryptionMode.AES_256_XTS.value -> "aes-256-xts"
else -> ""
}))
}

override fun enableEncryption(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.enableEncryption(params["enabled"] as Boolean, mapToEncryptionConfig(params["config"] as Map<*, *>)))
callback.code(this[params["channelId"] as String]?.setEncryptionMode(params["encryptionMode"] as String))
}

override fun addInjectStreamUrl(params: Map<String, *>, callback: Callback) {
Expand Down
32 changes: 1 addition & 31 deletions RtcChannelEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class RtcChannelEvents {
const val ChannelMediaRelayStateChanged = "ChannelMediaRelayStateChanged"
const val ChannelMediaRelayEvent = "ChannelMediaRelayEvent"
const val MetadataReceived = "MetadataReceived"
const val AudioPublishStateChanged = "AudioPublishStateChanged"
const val VideoPublishStateChanged = "VideoPublishStateChanged"
const val AudioSubscribeStateChanged = "AudioSubscribeStateChanged"
const val VideoSubscribeStateChanged = "VideoSubscribeStateChanged"
const val RtmpStreamingEvent = "RtmpStreamingEvent"

fun toMap(): Map<String, String> {
return hashMapOf(
Expand Down Expand Up @@ -74,12 +69,7 @@ class RtcChannelEvents {
"StreamMessageError" to StreamMessageError,
"ChannelMediaRelayStateChanged" to ChannelMediaRelayStateChanged,
"ChannelMediaRelayEvent" to ChannelMediaRelayEvent,
"MetadataReceived" to MetadataReceived,
"AudioPublishStateChanged" to AudioPublishStateChanged,
"VideoPublishStateChanged" to VideoPublishStateChanged,
"AudioSubscribeStateChanged" to AudioSubscribeStateChanged,
"VideoSubscribeStateChanged" to VideoSubscribeStateChanged,
"RtmpStreamingEvent" to RtmpStreamingEvent
"MetadataReceived" to MetadataReceived
)
}
}
Expand Down Expand Up @@ -216,24 +206,4 @@ class RtcChannelEventHandler(
override fun onChannelMediaRelayEvent(rtcChannel: RtcChannel?, @Annotations.AgoraChannelMediaRelayEvent code: Int) {
callback(RtcChannelEvents.ChannelMediaRelayEvent, rtcChannel, code)
}

override fun onAudioPublishStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioPublishStateChanged, rtcChannel, rtcChannel?.channelId(), oldState, newState, elapseSinceLastState)
}

override fun onVideoPublishStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoPublishStateChanged, rtcChannel, rtcChannel?.channelId(), oldState, newState, elapseSinceLastState)
}

override fun onAudioSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid, oldState, newState, elapseSinceLastState)
}

override fun onVideoSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid, oldState, newState, elapseSinceLastState)
}

override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, @Annotations.AgoraRtmpStreamingEvent errCode: Int) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, errCode)
}
}
25 changes: 5 additions & 20 deletions RtcEngine.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.agora.rtc.base

import android.content.Context
import io.agora.rtc.*
import io.agora.rtc.internal.EncryptionConfig
import io.agora.rtc.Constants
import io.agora.rtc.IMetadataObserver
import io.agora.rtc.RtcEngine
import io.agora.rtc.RtcEngineEx
import io.agora.rtc.models.UserInfo

class IRtcEngine {
Expand Down Expand Up @@ -34,8 +36,6 @@ class IRtcEngine {

fun getConnectionState(callback: Callback)

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

fun getCallId(callback: Callback)

fun rate(params: Map<String, *>, callback: Callback)
Expand Down Expand Up @@ -267,8 +267,6 @@ class IRtcEngine {
fun setEncryptionSecret(params: Map<String, *>, callback: Callback)

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

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

interface RtcAudioRecorderInterface {
Expand Down Expand Up @@ -386,10 +384,6 @@ class RtcEngineManager(
callback.resolve(engine) { it.connectionState }
}

override fun sendCustomReportMessage(params: Map<String, *>, callback: Callback) {
callback.code(engine?.sendCustomReportMessage(params["id"] as String, params["category"] as String, params["event"] as String, params["label"] as String, (params["value"] as Number).toInt()))
}

override fun getCallId(callback: Callback) {
callback.resolve(engine) { it.callId }
}
Expand Down Expand Up @@ -808,16 +802,7 @@ class RtcEngineManager(
}

override fun setEncryptionMode(params: Map<String, *>, callback: Callback) {
callback.code(engine?.setEncryptionMode(when ((params["encryptionMode"] as Number).toInt()) {
EncryptionConfig.EncryptionMode.AES_128_XTS.value -> "aes-128-xts"
EncryptionConfig.EncryptionMode.AES_128_ECB.value -> "aes-128-ecb"
EncryptionConfig.EncryptionMode.AES_256_XTS.value -> "aes-256-xts"
else -> ""
}))
}

override fun enableEncryption(params: Map<String, *>, callback: Callback) {
callback.code(engine?.enableEncryption(params["enabled"] as Boolean, mapToEncryptionConfig(params["config"] as Map<*, *>)))
callback.code(engine?.setEncryptionMode(params["encryptionMode"] as String))
}

override fun startAudioRecording(params: Map<String, *>, callback: Callback) {
Expand Down
44 changes: 1 addition & 43 deletions RtcEngineEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ class RtcEngineEvents {
const val CameraReady = "CameraReady"
const val VideoStopped = "VideoStopped"
const val MetadataReceived = "MetadataReceived"
const val FirstLocalAudioFramePublished = "FirstLocalAudioFramePublished"
const val FirstLocalVideoFramePublished = "FirstLocalVideoFramePublished"
const val AudioPublishStateChanged = "AudioPublishStateChanged"
const val VideoPublishStateChanged = "VideoPublishStateChanged"
const val AudioSubscribeStateChanged = "AudioSubscribeStateChanged"
const val VideoSubscribeStateChanged = "VideoSubscribeStateChanged"
const val RtmpStreamingEvent = "RtmpStreamingEvent"

fun toMap(): Map<String, String> {
return hashMapOf(
Expand Down Expand Up @@ -156,14 +149,7 @@ class RtcEngineEvents {
"AudioQuality" to AudioQuality,
"CameraReady" to CameraReady,
"VideoStopped" to VideoStopped,
"MetadataReceived" to MetadataReceived,
"FirstLocalAudioFramePublished" to FirstLocalAudioFramePublished,
"FirstLocalVideoFramePublished" to FirstLocalVideoFramePublished,
"AudioPublishStateChanged" to AudioPublishStateChanged,
"VideoPublishStateChanged" to VideoPublishStateChanged,
"AudioSubscribeStateChanged" to AudioSubscribeStateChanged,
"VideoSubscribeStateChanged" to VideoSubscribeStateChanged,
"RtmpStreamingEvent" to RtmpStreamingEvent
"MetadataReceived" to MetadataReceived
)
}
}
Expand Down Expand Up @@ -484,32 +470,4 @@ class RtcEngineEventHandler(
override fun onVideoStopped() {
callback(RtcEngineEvents.VideoStopped)
}

override fun onFirstLocalAudioFramePublished(elapsed: Int) {
callback(RtcEngineEvents.FirstLocalAudioFramePublished, elapsed)
}

override fun onFirstLocalVideoFramePublished(elapsed: Int) {
callback(RtcEngineEvents.FirstLocalVideoFramePublished, elapsed)
}

override fun onAudioPublishStateChanged(channel: String?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) {
callback(RtcEngineEvents.AudioPublishStateChanged, channel, oldState, newState, elapseSinceLastState)
}

override fun onVideoPublishStateChanged(channel: String?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) {
callback(RtcEngineEvents.VideoPublishStateChanged, channel, oldState, newState, elapseSinceLastState)
}

override fun onAudioSubscribeStateChanged(channel: String?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcEngineEvents.AudioSubscribeStateChanged, channel, uid, oldState, newState, elapseSinceLastState)
}

override fun onVideoSubscribeStateChanged(channel: String?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcEngineEvents.VideoSubscribeStateChanged, channel, uid, oldState, newState, elapseSinceLastState)
}

override fun onRtmpStreamingEvent(url: String?, @Annotations.AgoraRtmpStreamingEvent error: Int) {
callback(RtcEngineEvents.RtmpStreamingEvent, url, error)
}
}
Loading

0 comments on commit 21c7655

Please sign in to comment.