Skip to content

Commit 55c6178

Browse files
committed
revert StreamBlockingQueue
1 parent bfbab08 commit 55c6178

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

common/src/main/java/com/pedro/common/base/BaseSender.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.pedro.common.BitrateManager
55
import com.pedro.common.ConnectChecker
66
import com.pedro.common.StreamBlockingQueue
77
import com.pedro.common.frame.MediaFrame
8+
import com.pedro.common.trySend
89
import kotlinx.coroutines.CoroutineScope
910
import kotlinx.coroutines.Dispatchers
1011
import kotlinx.coroutines.Job
@@ -14,6 +15,7 @@ import kotlinx.coroutines.delay
1415
import kotlinx.coroutines.isActive
1516
import kotlinx.coroutines.launch
1617
import java.nio.ByteBuffer
18+
import java.util.concurrent.LinkedBlockingQueue
1719

1820
abstract class BaseSender(
1921
protected val connectChecker: ConnectChecker,
@@ -24,7 +26,7 @@ abstract class BaseSender(
2426
protected var running = false
2527
private var cacheSize = 400
2628
@Volatile
27-
protected var queue = StreamBlockingQueue(cacheSize)
29+
protected var queue = LinkedBlockingQueue<MediaFrame>(cacheSize)
2830
protected var audioFramesSent: Long = 0
2931
protected var videoFramesSent: Long = 0
3032
var droppedAudioFrames: Long = 0
@@ -94,24 +96,24 @@ abstract class BaseSender(
9496
@Throws(IllegalArgumentException::class)
9597
fun hasCongestion(percentUsed: Float = 20f): Boolean {
9698
if (percentUsed < 0 || percentUsed > 100) throw IllegalArgumentException("the value must be in range 0 to 100")
97-
val size = queue.getSize().toFloat()
99+
val size = queue.size.toFloat()
98100
val remaining = queue.remainingCapacity().toFloat()
99101
val capacity = size + remaining
100102
return size >= capacity * (percentUsed / 100f)
101103
}
102104

103105
fun resizeCache(newSize: Int) {
104-
if (newSize < queue.getSize() - queue.remainingCapacity()) {
106+
if (newSize < queue.size - queue.remainingCapacity()) {
105107
throw RuntimeException("Can't fit current cache inside new cache size")
106108
}
107-
val tempQueue = StreamBlockingQueue(newSize)
109+
val tempQueue = LinkedBlockingQueue<MediaFrame>(newSize)
108110
queue.drainTo(tempQueue)
109111
queue = tempQueue
110112
}
111113

112114
fun getCacheSize(): Int = cacheSize
113115

114-
fun getItemsInCache(): Int = queue.getSize()
116+
fun getItemsInCache(): Int = queue.size
115117

116118
fun clearCache() {
117119
queue.clear()
@@ -148,7 +150,7 @@ abstract class BaseSender(
148150
fun getBitrateExponentialFactor() = bitrateManager.exponentialFactor
149151

150152
fun setDelay(delay: Long) {
151-
queue.setCacheTime(delay)
153+
// queue.setCacheTime(delay)
152154
}
153155

154156
fun resetBytesSend() {

0 commit comments

Comments
 (0)