Skip to content

Commit

Permalink
move BitrateManager and TimeUtils to common module
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 3, 2023
1 parent 825f733 commit 7654005
Show file tree
Hide file tree
Showing 37 changed files with 50 additions and 447 deletions.
12 changes: 5 additions & 7 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@ plugins {

android {
namespace 'com.pedro.common'
compileSdk 33
compileSdk 34

defaultConfig {
minSdk 16

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
targetSdkVersion 34
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package com.pedro.srt.utils
package com.pedro.common

import com.pedro.common.ConnectChecker

/**
* Created by pedro on 8/04/21.
Expand Down
14 changes: 14 additions & 0 deletions common/src/main/java/com/pedro/common/Extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pedro.common

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Created by pedro on 3/11/23.
*/

suspend fun onMainThread(code: () -> Unit) {
withContext(Dispatchers.Main) {
code()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pedro.rtsp.utils
package com.pedro.common

/**
* Created by pedro on 30/8/23.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package com.pedro.rtmp.utils
package com.pedro.common

import com.pedro.rtmp.MainDispatcherRule
import com.pedro.rtmp.Utils
import com.pedro.common.util.MainDispatcherRule
import com.pedro.common.util.Utils
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Assert.assertTrue
Expand All @@ -42,7 +42,7 @@ class BitrateManagerTest {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()
@Mock
private lateinit var connectCheckerRtmp: ConnectCheckerRtmp
private lateinit var connectChecker: ConnectChecker
private val timeUtilsMocked = Mockito.mockStatic(TimeUtils::class.java)
private var fakeTime = 7502849023L

Expand All @@ -59,7 +59,7 @@ class BitrateManagerTest {
@Test
fun `WHEN set multiple values THEN return total of values each second`() = runTest {
Utils.useStatics(listOf(timeUtilsMocked)) {
val bitrateManager = BitrateManager(connectCheckerRtmp)
val bitrateManager = BitrateManager(connectChecker)
val fakeValues = arrayOf(100L, 200L, 300L, 400L, 500L)
var expectedResult = 0L
fakeValues.forEach {
Expand All @@ -71,7 +71,7 @@ class BitrateManagerTest {
bitrateManager.calculateBitrate(value)
expectedResult += value
val resultValue = argumentCaptor<Long>()
verify(connectCheckerRtmp, times(1)).onNewBitrateRtmp(resultValue.capture())
verify(connectChecker, times(1)).onNewBitrate(resultValue.capture())
val marginError = 20
assertTrue(expectedResult - marginError <= resultValue.firstValue && resultValue.firstValue <= expectedResult + marginError)
}
Expand Down
17 changes: 0 additions & 17 deletions common/src/test/java/com/pedro/common/ExampleUnitTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pedro.rtsp
package com.pedro.common.util

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pedro.rtmp
package com.pedro.common.util

import org.mockito.MockedStatic

Expand Down
2 changes: 1 addition & 1 deletion rtmp/src/main/java/com/pedro/rtmp/amf/v0/AmfDate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.pedro.rtmp.amf.v0

import com.pedro.rtmp.utils.TimeUtils
import com.pedro.common.TimeUtils
import com.pedro.rtmp.utils.readUntil
import java.io.IOException
import java.io.InputStream
Expand Down
2 changes: 1 addition & 1 deletion rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.pedro.rtmp.rtmp

import android.util.Log
import com.pedro.common.TimeUtils
import com.pedro.rtmp.amf.v0.*
import com.pedro.rtmp.flv.FlvPacket
import com.pedro.rtmp.rtmp.message.*
Expand All @@ -25,7 +26,6 @@ import com.pedro.rtmp.rtmp.message.control.Type
import com.pedro.rtmp.rtmp.message.control.UserControl
import com.pedro.rtmp.utils.CommandSessionHistory
import com.pedro.rtmp.utils.RtmpConfig
import com.pedro.rtmp.utils.TimeUtils
import com.pedro.rtmp.utils.socket.RtmpSocket
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand Down
2 changes: 1 addition & 1 deletion rtmp/src/main/java/com/pedro/rtmp/rtmp/Handshake.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.pedro.rtmp.rtmp

import android.util.Log
import com.pedro.rtmp.utils.TimeUtils
import com.pedro.common.TimeUtils
import com.pedro.rtmp.utils.readUntil
import com.pedro.rtmp.utils.socket.RtmpSocket
import java.io.IOException
Expand Down
4 changes: 2 additions & 2 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package com.pedro.rtmp.rtmp
import android.media.MediaCodec
import android.util.Log
import com.pedro.common.ConnectChecker
import com.pedro.common.TimeUtils
import com.pedro.common.onMainThread
import com.pedro.rtmp.amf.AmfVersion
import com.pedro.rtmp.flv.video.ProfileIop
import com.pedro.rtmp.rtmp.message.*
Expand All @@ -27,8 +29,6 @@ import com.pedro.rtmp.rtmp.message.control.Type
import com.pedro.rtmp.rtmp.message.control.UserControl
import com.pedro.rtmp.utils.AuthUtil
import com.pedro.rtmp.utils.RtmpConfig
import com.pedro.rtmp.utils.TimeUtils
import com.pedro.rtmp.utils.onMainThread
import com.pedro.rtmp.utils.socket.RtmpSocket
import com.pedro.rtmp.utils.socket.TcpSocket
import com.pedro.rtmp.utils.socket.TcpTunneledSocket
Expand Down
4 changes: 2 additions & 2 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ package com.pedro.rtmp.rtmp

import android.media.MediaCodec
import android.util.Log
import com.pedro.common.BitrateManager
import com.pedro.common.ConnectChecker
import com.pedro.common.onMainThread
import com.pedro.rtmp.flv.FlvPacket
import com.pedro.rtmp.flv.FlvType
import com.pedro.rtmp.flv.audio.AacPacket
import com.pedro.rtmp.flv.video.H264Packet
import com.pedro.rtmp.flv.video.H265Packet
import com.pedro.rtmp.flv.video.ProfileIop
import com.pedro.rtmp.utils.BitrateManager
import com.pedro.rtmp.utils.onMainThread
import com.pedro.rtmp.utils.socket.RtmpSocket
import com.pedro.rtmp.utils.trySend
import kotlinx.coroutines.CoroutineScope
Expand Down
42 changes: 0 additions & 42 deletions rtmp/src/main/java/com/pedro/rtmp/utils/BitrateManager.kt

This file was deleted.

29 changes: 0 additions & 29 deletions rtmp/src/main/java/com/pedro/rtmp/utils/TimeUtils.kt

This file was deleted.

6 changes: 0 additions & 6 deletions rtmp/src/main/java/com/pedro/rtmp/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ inline infix fun <reified T: Any> BlockingQueue<T>.trySend(item: T): Boolean {
}
}

suspend fun onMainThread(code: () -> Unit) {
withContext(Dispatchers.Main) {
code()
}
}

fun InputStream.readUntil(byteArray: ByteArray) {
var bytesRead = 0
while (bytesRead < byteArray.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.pedro.rtmp.utils.socket

import android.util.Log
import com.pedro.rtmp.utils.TimeUtils
import com.pedro.common.TimeUtils
import java.io.*
import java.net.HttpURLConnection
import java.net.SocketTimeoutException
Expand Down
23 changes: 0 additions & 23 deletions rtmp/src/test/java/com/pedro/rtmp/MainDispatcherRule.kt

This file was deleted.

2 changes: 1 addition & 1 deletion rtsp/src/main/java/com/pedro/rtsp/rtcp/BaseSenderReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.pedro.rtsp.rtcp

import com.pedro.common.TimeUtils
import com.pedro.rtsp.rtsp.Protocol
import com.pedro.rtsp.rtsp.RtpFrame
import com.pedro.rtsp.utils.RtpConstants
import com.pedro.rtsp.utils.TimeUtils
import com.pedro.rtsp.utils.setLong
import java.io.IOException
import java.io.OutputStream
Expand Down
2 changes: 1 addition & 1 deletion rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package com.pedro.rtsp.rtsp
import android.media.MediaCodec
import android.util.Log
import com.pedro.common.ConnectChecker
import com.pedro.common.onMainThread
import com.pedro.rtsp.rtsp.commands.CommandsManager
import com.pedro.rtsp.rtsp.commands.Method
import com.pedro.rtsp.utils.CreateSSLSocket.createSSlSocket
import com.pedro.rtsp.utils.RtpConstants
import com.pedro.rtsp.utils.onMainThread
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down
Loading

0 comments on commit 7654005

Please sign in to comment.