Skip to content

Commit

Permalink
android finished
Browse files Browse the repository at this point in the history
LichKing-2234 committed Sep 27, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 51b093b commit d69a73d
Showing 9 changed files with 1,123 additions and 423 deletions.
84 changes: 48 additions & 36 deletions Annotations.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package io.agora.rtc.base;

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

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import io.agora.rtc.Constants;
import io.agora.rtc.IMetadataObserver;
import io.agora.rtc.RtcEngineConfig;
import io.agora.rtc.video.BeautyOptions;
import io.agora.rtc.video.VideoCanvas;

@SuppressWarnings("deprecation")
public class Annotations {

@IntDef({
AgoraRtcAppType.NATIVE,
AgoraRtcAppType.COCOS,
@@ -131,15 +130,6 @@ public class Annotations {
public @interface AgoraAudioProfile {
}

@IntDef({
Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY,
Constants.RAW_AUDIO_FRAME_OP_MODE_WRITE_ONLY,
Constants.RAW_AUDIO_FRAME_OP_MODE_READ_WRITE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraAudioRawFrameOperationMode {
}

@IntDef({
Constants.AUDIO_RECORDING_QUALITY_LOW,
Constants.AUDIO_RECORDING_QUALITY_MEDIUM,
@@ -386,16 +376,20 @@ public class Annotations {
int MAINTAIN_BALANCED = 2;
}

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

@IntDef({
@@ -419,6 +413,7 @@ 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,
@@ -543,24 +538,6 @@ public class Annotations {
public @interface AgoraLogFilter {
}

@IntDef({
Constants.MEDIA_TYPE_NONE,
Constants.MEDIA_TYPE_AUDIO_ONLY,
Constants.MEDIA_TYPE_VIDEO_ONLY,
Constants.MEDIA_TYPE_AUDIO_AND_VIDEO,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraMediaType {
}

@IntDef({
IMetadataObserver.UNKNOWN_METADATA,
IMetadataObserver.VIDEO_METADATA,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AgoraMetadataType {
}

@IntDef({
Constants.QUALITY_UNKNOWN,
Constants.QUALITY_EXCELLENT,
@@ -766,15 +743,50 @@ 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_ADM_IMPROPER_SETTINGS,
Constants.WARN_APM_RESIDUAL_ECHO,
})
@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,
})
@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 {
}
}
8 changes: 8 additions & 0 deletions BeanCovertor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.agora.rtc.base

import android.graphics.Color
import io.agora.rtc.internal.EncryptionConfig
import io.agora.rtc.internal.LastmileProbeConfig
import io.agora.rtc.live.LiveInjectStreamConfig
import io.agora.rtc.live.LiveTranscoding
@@ -169,3 +170,10 @@ fun mapToChannelMediaOptions(map: Map<*, *>): ChannelMediaOptions {
(map["autoSubscribeVideo"] as? Boolean)?.let { autoSubscribeVideo = 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: 10 additions & 0 deletions EnumCovertor.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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
@@ -85,3 +86,12 @@ 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")
}
354 changes: 239 additions & 115 deletions RtcChannel.kt

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion RtcChannelEvent.kt
Original file line number Diff line number Diff line change
@@ -37,6 +37,11 @@ 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(
@@ -69,7 +74,12 @@ class RtcChannelEvents {
"StreamMessageError" to StreamMessageError,
"ChannelMediaRelayStateChanged" to ChannelMediaRelayStateChanged,
"ChannelMediaRelayEvent" to ChannelMediaRelayEvent,
"MetadataReceived" to MetadataReceived
"MetadataReceived" to MetadataReceived,
"AudioPublishStateChanged" to AudioPublishStateChanged,
"VideoPublishStateChanged" to VideoPublishStateChanged,
"AudioSubscribeStateChanged" to AudioSubscribeStateChanged,
"VideoSubscribeStateChanged" to VideoSubscribeStateChanged,
"RtmpStreamingEvent" to RtmpStreamingEvent
)
}
}
@@ -206,4 +216,24 @@ 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, oldState, newState, elapseSinceLastState)
}

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

override fun onAudioSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, 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, uid, oldState, newState, elapseSinceLastState)
}

override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, errCode: Int) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, errCode)
}
}
943 changes: 702 additions & 241 deletions RtcEngine.kt

Large diffs are not rendered by default.

46 changes: 44 additions & 2 deletions RtcEngineEvent.kt
Original file line number Diff line number Diff line change
@@ -77,6 +77,13 @@ 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(
@@ -149,7 +156,14 @@ class RtcEngineEvents {
"AudioQuality" to AudioQuality,
"CameraReady" to CameraReady,
"VideoStopped" to VideoStopped,
"MetadataReceived" to MetadataReceived
"MetadataReceived" to MetadataReceived,
"FirstLocalAudioFramePublished" to FirstLocalAudioFramePublished,
"FirstLocalVideoFramePublished" to FirstLocalVideoFramePublished,
"AudioPublishStateChanged" to AudioPublishStateChanged,
"VideoPublishStateChanged" to VideoPublishStateChanged,
"AudioSubscribeStateChanged" to AudioSubscribeStateChanged,
"VideoSubscribeStateChanged" to VideoSubscribeStateChanged,
"RtmpStreamingEvent" to RtmpStreamingEvent
)
}
}
@@ -183,7 +197,7 @@ class RtcEngineEventHandler(
}

override fun onRejoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) {
callback(RtcEngineEvents.RejoinChannelSuccess, uid, elapsed)
callback(RtcEngineEvents.RejoinChannelSuccess, channel, uid, elapsed)
}

override fun onLeaveChannel(stats: RtcStats?) {
@@ -470,4 +484,32 @@ 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?, error: Int) {
callback(RtcEngineEvents.RtmpStreamingEvent, url, error)
}
}
3 changes: 1 addition & 2 deletions RtcSurfaceView.kt
Original file line number Diff line number Diff line change
@@ -19,8 +19,7 @@ class RtcSurfaceView(
try {
surface = RtcEngine.CreateRendererView(context)
} catch (e: UnsatisfiedLinkError) {
surface = SurfaceView(context)
e.printStackTrace()
throw RuntimeException("Please init RtcEngine first!")
}
canvas = VideoCanvas(surface)
addView(surface)
66 changes: 40 additions & 26 deletions RtcTextureView.kt
Original file line number Diff line number Diff line change
@@ -1,59 +1,73 @@
package io.agora.rtc.base

import android.content.Context
import android.view.TextureView
import android.widget.FrameLayout
import io.agora.rtc.RtcChannel
import io.agora.rtc.RtcEngine
import io.agora.rtc.mediaio.AgoraTextureView
import io.agora.rtc.mediaio.MediaIO
import io.agora.rtc.video.VideoCanvas
import java.lang.ref.WeakReference

class RtcTextureView(
context: Context
) : FrameLayout(context) {
private var texture: AgoraTextureView = AgoraTextureView(context)
private var uid: Int = 0
private var texture: TextureView
private var canvas: VideoCanvas
private var channel: WeakReference<RtcChannel>? = null

init {
texture.init(null)
texture.setBufferType(MediaIO.BufferType.BYTE_ARRAY)
texture.setPixelFormat(MediaIO.PixelFormat.I420)
try {
texture = RtcEngine.CreateTextureView(context)
} catch (e: UnsatisfiedLinkError) {
throw RuntimeException("Please init RtcEngine first!")
}
canvas = VideoCanvas(texture)
addView(texture)
}

fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Int) {
this.channel = if (channel != null) WeakReference(channel) else null
this.uid = uid
setupVideoRenderer(engine)
canvas.channelId = this.channel?.get()?.channelId()
canvas.uid = uid
setupVideoCanvas(engine)
}

fun setMirror(engine: RtcEngine, mirror: Boolean) {
texture.setMirror(mirror)
setupVideoRenderer(engine)
fun resetVideoCanvas(engine: RtcEngine) {
val canvas = VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode)
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}

fun resetVideoRender(engine: RtcEngine) {
if (uid == 0) {
engine.setLocalVideoRenderer(null)
private fun setupVideoCanvas(engine: RtcEngine) {
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
} else {
channel?.get()?.let {
it.setRemoteVideoRenderer(uid, null)
return@resetVideoRender
}
engine.setRemoteVideoRenderer(uid, null)
engine.setupRemoteVideo(canvas)
}
}

private fun setupVideoRenderer(engine: RtcEngine) {
if (uid == 0) {
engine.setLocalVideoRenderer(texture)
fun setRenderMode(engine: RtcEngine, @Annotations.AgoraVideoRenderMode renderMode: Int) {
canvas.renderMode = renderMode
setupRenderMode(engine)
}

fun setMirrorMode(engine: RtcEngine, @Annotations.AgoraVideoMirrorMode mirrorMode: Int) {
canvas.mirrorMode = mirrorMode
setupRenderMode(engine)
}

private fun setupRenderMode(engine: RtcEngine) {
if (canvas.uid == 0) {
engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode)
} else {
channel?.get()?.let {
it.setRemoteVideoRenderer(uid, texture)
return@setupVideoRenderer
it.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
return@setupRenderMode
}
engine.setRemoteVideoRenderer(uid, texture)
engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode)
}
}

0 comments on commit d69a73d

Please sign in to comment.