Skip to content

Commit

Permalink
Add 'android/src/main/java/io/agora/rtc/base/' from commit 'f1ed8250d…
Browse files Browse the repository at this point in the history
…d2620caae597670805228d6ed074c4f'

git-subtree-dir: android/src/main/java/io/agora/rtc/base
git-subtree-mainline: 460fefc
git-subtree-split: f1ed825
  • Loading branch information
LichKing-2234 committed Jun 8, 2020
2 parents 460fefc + f1ed825 commit 03bb2d4
Show file tree
Hide file tree
Showing 12 changed files with 2,575 additions and 0 deletions.
736 changes: 736 additions & 0 deletions android/src/main/java/io/agora/rtc/base/Annotations.java

Large diffs are not rendered by default.

171 changes: 171 additions & 0 deletions android/src/main/java/io/agora/rtc/base/BeanCovertor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package io.agora.rtc.base

import android.graphics.Color
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.video.*

fun mapToVideoDimensions(map: Map<*, *>): VideoEncoderConfiguration.VideoDimensions {
return VideoEncoderConfiguration.VideoDimensions().apply {
(map["width"] as? Number)?.let { width = it.toInt() }
(map["height"] as? Number)?.let { height = it.toInt() }
}
}

fun mapToVideoEncoderConfiguration(map: Map<*, *>): VideoEncoderConfiguration {
return VideoEncoderConfiguration().apply {
(map["dimensions"] as? Map<*, *>)?.let { dimensions = mapToVideoDimensions(it) }
(map["frameRate"] as? Number)?.let { frameRate = it.toInt() }
(map["minFrameRate"] as? Number)?.let { minFrameRate = it.toInt() }
(map["bitrate"] as? Number)?.let { bitrate = it.toInt() }
(map["minBitrate"] as? Number)?.let { minBitrate = it.toInt() }
(map["orientationMode"] as? Number)?.let { orientationMode = intToOrientationMode(it.toInt()) }
(map["degradationPrefer"] as? Number)?.let { degradationPrefer = intToDegradationPreference(it.toInt()) }
(map["mirrorMode"] as? Number)?.let { mirrorMode = it.toInt() }
}
}

fun mapToBeautyOptions(map: Map<*, *>): BeautyOptions {
return BeautyOptions().apply {
(map["lighteningContrastLevel"] as? Number)?.let { lighteningContrastLevel = it.toInt() }
(map["lighteningLevel"] as? Number)?.let { lighteningLevel = it.toFloat() }
(map["smoothnessLevel"] as? Number)?.let { smoothnessLevel = it.toFloat() }
(map["rednessLevel"] as? Number)?.let { rednessLevel = it.toFloat() }
}
}

fun mapToAgoraImage(map: Map<*, *>): AgoraImage {
return AgoraImage().apply {
(map["url"] as? String)?.let { url = it }
(map["x"] as? Number)?.let { x = it.toInt() }
(map["y"] as? Number)?.let { y = it.toInt() }
(map["width"] as? Number)?.let { width = it.toInt() }
(map["height"] as? Number)?.let { height = it.toInt() }
}
}

fun mapToTranscodingUser(map: Map<*, *>): TranscodingUser {
return TranscodingUser().apply {
(map["uid"] as? Number)?.let { uid = it.toInt() }
(map["x"] as? Number)?.let { x = it.toInt() }
(map["y"] as? Number)?.let { y = it.toInt() }
(map["width"] as? Number)?.let { width = it.toInt() }
(map["height"] as? Number)?.let { height = it.toInt() }
(map["zOrder"] as? Number)?.let { zOrder = it.toInt() }
(map["alpha"] as? Number)?.let { alpha = it.toFloat() }
(map["audioChannel"] as? Number)?.let { audioChannel = it.toInt() }
}
}

fun mapToColor(map: Map<*, *>): Int {
return Color.rgb(
(map["red"] as Number).toInt(),
(map["green"] as Number).toInt(),
(map["blue"] as Number).toInt()
)
}

fun mapToLiveTranscoding(map: Map<*, *>): LiveTranscoding {
return LiveTranscoding().apply {
(map["width"] as? Number)?.let { width = it.toInt() }
(map["height"] as? Number)?.let { height = it.toInt() }
(map["videoBitrate"] as? Number)?.let { videoBitrate = it.toInt() }
(map["videoFramerate"] as? Number)?.let { videoFramerate = it.toInt() }
(map["lowLatency"] as? Boolean)?.let { lowLatency = it }
(map["videoGop"] as? Number)?.let { videoGop = it.toInt() }
(map["watermark"] as? Map<*, *>)?.let { watermark = mapToAgoraImage(it) }
(map["backgroundImage"] as? Map<*, *>)?.let { backgroundImage = mapToAgoraImage(it) }
(map["audioSampleRate"] as? Number)?.let { audioSampleRate = intToLiveTranscodingAudioSampleRate(it.toInt()) }
(map["audioBitrate"] as? Number)?.let { audioBitrate = it.toInt() }
(map["audioChannels"] as? Number)?.let { audioChannels = it.toInt() }
(map["audioCodecProfile"] as? Number)?.let { audioCodecProfile = intToAudioCodecProfile(it.toInt()) }
(map["videoCodecProfile"] as? Number)?.let { videoCodecProfile = intToVideoCodecProfile(it.toInt()) }
(map["backgroundColor"] as? Map<*, *>)?.let { backgroundColor = mapToColor(it) }
(map["userConfigExtraInfo"] as? String)?.let { userConfigExtraInfo = it }
(map["transcodingUsers"] as? List<*>)?.let { list ->
list.forEach { item ->
(item as? Map<*, *>)?.let {
addUser(mapToTranscodingUser(it))
}
}
}
}
}

fun mapToChannelMediaInfo(map: Map<*, *>): ChannelMediaInfo {
return ChannelMediaInfo(
map["channelName"] as String,
map["token"] as String,
(map["uid"] as Number).toInt()
)
}

fun mapToChannelMediaRelayConfiguration(map: Map<*, *>): ChannelMediaRelayConfiguration {
return ChannelMediaRelayConfiguration().apply {
(map["srcInfo"] as? Map<*, *>)?.let { setSrcChannelInfo(mapToChannelMediaInfo(it)) }
(map["destInfos"] as? List<*>)?.let { list ->
list.forEach { item ->
(item as? Map<*, *>)?.let {
val info = mapToChannelMediaInfo(it)
setDestChannelInfo(info.channelName, info)
}
}
}
}
}

fun mapToLastmileProbeConfig(map: Map<*, *>): LastmileProbeConfig {
return LastmileProbeConfig().apply {
(map["probeUplink"] as? Boolean)?.let { probeUplink = it }
(map["probeDownlink"] as? Boolean)?.let { probeDownlink = it }
(map["expectedUplinkBitrate"] as? Number)?.let { expectedUplinkBitrate = it.toInt() }
(map["expectedDownlinkBitrate"] as? Number)?.let { expectedUplinkBitrate = it.toInt() }
}
}

fun mapToRectangle(map: Map<*, *>): WatermarkOptions.Rectangle {
return WatermarkOptions.Rectangle().apply {
(map["x"] as? Number)?.let { x = it.toInt() }
(map["y"] as? Number)?.let { y = it.toInt() }
(map["width"] as? Number)?.let { width = it.toInt() }
(map["height"] as? Number)?.let { height = it.toInt() }
}
}

fun mapToWatermarkOptions(map: Map<*, *>): WatermarkOptions {
return WatermarkOptions().apply {
(map["visibleInPreview"] as? Boolean)?.let { visibleInPreview = it }
(map["positionInLandscapeMode"] as? Map<*, *>)?.let { positionInLandscapeMode = mapToRectangle(it) }
(map["positionInPortraitMode"] as? Map<*, *>)?.let { positionInPortraitMode = mapToRectangle(it) }
}
}

fun mapToLiveInjectStreamConfig(map: Map<*, *>): LiveInjectStreamConfig {
return LiveInjectStreamConfig().apply {
(map["width"] as? Number)?.let { width = it.toInt() }
(map["height"] as? Number)?.let { height = it.toInt() }
(map["videoGop"] as? Number)?.let { videoGop = it.toInt() }
(map["videoFramerate"] as? Number)?.let { videoFramerate = it.toInt() }
(map["videoBitrate"] as? Number)?.let { videoBitrate = it.toInt() }
(map["audioSampleRate"] as? Number)?.let { audioSampleRate = intToLiveInjectStreamConfigAudioSampleRate(it.toInt()) }
(map["audioBitrate"] as? Number)?.let { audioBitrate = it.toInt() }
(map["audioChannels"] as? Number)?.let { audioChannels = it.toInt() }
}
}

fun mapToCameraCapturerConfiguration(map: Map<*, *>): CameraCapturerConfiguration {
return CameraCapturerConfiguration(
intToCapturerOutputPreference(map["preference"] as Int),
intToCameraDirection(map["cameraDirection"] as Int)
)
}

fun mapToChannelMediaOptions(map: Map<*, *>): ChannelMediaOptions {
return ChannelMediaOptions().apply {
(map["autoSubscribeAudio"] as? Boolean)?.let { autoSubscribeAudio = it }
(map["autoSubscribeVideo"] as? Boolean)?.let { autoSubscribeVideo = it }
}
}
20 changes: 20 additions & 0 deletions android/src/main/java/io/agora/rtc/base/Callback.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.agora.rtc.base

import io.agora.rtc.Constants
import io.agora.rtc.RtcEngine
import kotlin.math.abs

abstract class Callback<T> {
fun code(code: Int?) {
val newCode = code ?: Constants.ERR_NOT_INITIALIZED
if (newCode == 0) {
success(null)
} else if (newCode < 0) {
failure(newCode.toString(), RtcEngine.getErrorDescription(abs(newCode)))
}
}

abstract fun success(data: T?)

abstract fun failure(code: String, message: String)
}
87 changes: 87 additions & 0 deletions android/src/main/java/io/agora/rtc/base/EnumCovertor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.agora.rtc.base

import io.agora.rtc.live.LiveInjectStreamConfig
import io.agora.rtc.live.LiveTranscoding
import io.agora.rtc.video.CameraCapturerConfiguration
import io.agora.rtc.video.VideoEncoderConfiguration

fun intToFrameRate(@Annotations.AgoraVideoFrameRate intValue: Int): VideoEncoderConfiguration.FRAME_RATE {
for (value in VideoEncoderConfiguration.FRAME_RATE.values()) {
if (value.value == intValue) {
return value
}
}
throw RuntimeException("VideoEncoderConfiguration.FRAME_RATE not contains $intValue")
}

fun intToOrientationMode(@Annotations.AgoraVideoOutputOrientationMode intValue: Int): VideoEncoderConfiguration.ORIENTATION_MODE {
for (value in VideoEncoderConfiguration.ORIENTATION_MODE.values()) {
if (value.value == intValue) {
return value
}
}
throw RuntimeException("VideoEncoderConfiguration.ORIENTATION_MODE not contains $intValue")
}

fun intToDegradationPreference(@Annotations.AgoraDegradationPreference intValue: Int): VideoEncoderConfiguration.DEGRADATION_PREFERENCE {
for (value in VideoEncoderConfiguration.DEGRADATION_PREFERENCE.values()) {
if (value.value == intValue) {
return value
}
}
throw RuntimeException("VideoEncoderConfiguration.DEGRADATION_PREFERENCE not contains $intValue")
}

fun intToLiveTranscodingAudioSampleRate(@Annotations.AgoraAudioSampleRateType intValue: Int): LiveTranscoding.AudioSampleRateType {
for (value in LiveTranscoding.AudioSampleRateType.values()) {
if (LiveTranscoding.AudioSampleRateType.getValue(value) == intValue) {
return value
}
}
throw RuntimeException("LiveTranscoding.AudioSampleRateType not contains $intValue")
}

fun intToLiveInjectStreamConfigAudioSampleRate(@Annotations.AgoraAudioSampleRateType intValue: Int): LiveInjectStreamConfig.AudioSampleRateType {
for (value in LiveInjectStreamConfig.AudioSampleRateType.values()) {
if (LiveInjectStreamConfig.AudioSampleRateType.getValue(value) == intValue) {
return value
}
}
throw RuntimeException("LiveInjectStreamConfig.AudioSampleRateType not contains $intValue")
}

fun intToAudioCodecProfile(@Annotations.AgoraAudioCodecProfileType intValue: Int): LiveTranscoding.AudioCodecProfileType {
for (value in LiveTranscoding.AudioCodecProfileType.values()) {
if (LiveTranscoding.AudioCodecProfileType.getValue(value) == intValue) {
return value
}
}
throw RuntimeException("LiveTranscoding.AudioCodecProfileType not contains $intValue")
}

fun intToVideoCodecProfile(@Annotations.AgoraVideoCodecProfileType intValue: Int): LiveTranscoding.VideoCodecProfileType {
for (value in LiveTranscoding.VideoCodecProfileType.values()) {
if (LiveTranscoding.VideoCodecProfileType.getValue(value) == intValue) {
return value
}
}
throw RuntimeException("LiveTranscoding.VideoCodecProfileType not contains $intValue")
}

fun intToCapturerOutputPreference(@Annotations.AgoraCameraCaptureOutputPreference intValue: Int): CameraCapturerConfiguration.CAPTURER_OUTPUT_PREFERENCE {
for (value in CameraCapturerConfiguration.CAPTURER_OUTPUT_PREFERENCE.values()) {
if (value.value == intValue) {
return value
}
}
throw RuntimeException("CameraCapturerConfiguration.CAPTURER_OUTPUT_PREFERENCE not contains $intValue")
}

fun intToCameraDirection(@Annotations.AgoraCameraDirection intValue: Int): CameraCapturerConfiguration.CAMERA_DIRECTION {
for (value in CameraCapturerConfiguration.CAMERA_DIRECTION.values()) {
if (value.value == intValue) {
return value
}
}
throw RuntimeException("CameraCapturerConfiguration.CAMERA_DIRECTION not contains $intValue")
}
Loading

0 comments on commit 03bb2d4

Please sign in to comment.