Skip to content

Commit 95e8ff4

Browse files
committed
copy result bitmap before invoke callback
1 parent b4b7c44 commit 95e8ff4

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

app/src/main/java/ir/am3n/rtsp.client.demo/LiveFragment.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ir.am3n.rtsp.client.demo
22

33
import android.annotation.SuppressLint
4-
import android.graphics.Bitmap
4+
import android.graphics.*
55
import android.media.Image
66
import android.os.Bundle
77
import android.text.Editable
@@ -74,7 +74,9 @@ class LiveFragment : Fragment() {
7474
}
7575

7676
override fun onVideoFrameReceived(image: Image?, bitmap: Bitmap?) {
77-
77+
binding.img.run {
78+
post { setImageBitmap(bitmap?.removeTimestamp()) }
79+
}
7880
}
7981

8082
override fun onAudioSampleReceived(frame: Frame?) {
@@ -172,4 +174,11 @@ class LiveFragment : Fragment() {
172174
liveViewModel.saveParams(requireContext())
173175
}
174176

177+
private fun Bitmap.removeTimestamp(): Bitmap {
178+
Canvas(this).apply {
179+
drawRect(Rect(19, 12, 444, 40), Paint().apply { color = Color.LTGRAY })
180+
}
181+
return this
182+
}
183+
175184
}

app/src/main/res/layout/fragment_live.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,11 @@
9494

9595
</FrameLayout>
9696

97+
<ImageView
98+
android:id="@+id/img"
99+
android:layout_width="wrap_content"
100+
android:layout_height="wrap_content"
101+
android:layout_alignParentBottom="true"
102+
tools:ignore="ContentDescription" />
103+
97104
</RelativeLayout>

rtsp-client/src/main/java/ir/am3n/rtsp/client/codec/VideoDecoder.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ir.am3n.rtsp.client.codec
22

3+
import android.graphics.Bitmap
34
import android.graphics.Rect
45
import android.media.MediaCodec
56
import android.media.MediaFormat
@@ -159,7 +160,10 @@ internal class VideoDecoder(
159160
null
160161
}
161162

162-
clientListener.onRtspVideoFrameReceived(decoder.getOutputImage(index), bitmap)
163+
clientListener.onRtspVideoFrameReceived(
164+
decoder.getOutputImage(index),
165+
bitmap?.copy(Bitmap.Config.RGB_565, true)
166+
)
163167

164168
if (bitmap != null) {
165169
surfaceView?.post {

0 commit comments

Comments
 (0)