Skip to content

Commit 07f53ff

Browse files
committed
fix BufferVideoSource
1 parent c066dc9 commit 07f53ff

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/src/main/java/com/pedro/streamer/rotation/RotationActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class RotationActivity : AppCompatActivity(), OnTouchListener {
111111
val source = BufferVideoSource(BufferVideoSource.Format.ARGB, cameraFragment.vBitrate)
112112
cameraFragment.genericStream.changeVideoSource(source)
113113
CoroutineScope(Dispatchers.IO).launch {
114-
while (source.isRunning()) {
114+
while (cameraFragment.genericStream.videoSource is BufferVideoSource) {
115115
source.setBuffer(data.clone())
116116
delay(1000 / 30)
117117
}

encoder/src/main/java/com/pedro/encoder/input/sources/video/BufferVideoSource.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class BufferVideoSource(
4848
})
4949
private var scope = CoroutineScope(Dispatchers.IO)
5050
private val queue: BlockingQueue<Frame> = ArrayBlockingQueue(80)
51+
private var surface: Surface? = null
5152

5253
fun setBuffer(data: ByteBuffer) {
5354
setBuffer(data.toByteArray())
@@ -90,8 +91,11 @@ class BufferVideoSource(
9091
scope = CoroutineScope(Dispatchers.IO)
9192
queue.clear()
9293
running = true
94+
videoEncoder.prepareVideoEncoder(width, height, fps, bitrate, rotation, 2, FormatVideoEncoder.YUV420Dynamical)
95+
decoder.prepare(width, height, fps, rotation)
9396
videoEncoder.start()
94-
decoder.start(Surface(surfaceTexture))
97+
surface = Surface(surfaceTexture)
98+
decoder.start(surface)
9599
when (format) {
96100
Format.RGB, Format.ARGB, Format.NV21, Format.NV12 -> {
97101
scope.launch {
@@ -111,6 +115,7 @@ class BufferVideoSource(
111115
videoEncoder.stop()
112116
decoder.stop()
113117
queue.clear()
118+
surface?.release()
114119
}
115120

116121
override fun release() { }

0 commit comments

Comments
 (0)