Skip to content

Commit 0f4e718

Browse files
committed
Expose ReplayCache as public api
1 parent 65d35ec commit 0f4e718

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

sentry-android-replay/api/sentry-android-replay.api

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ public final class io/sentry/android/replay/BuildConfig {
66
public fun <init> ()V
77
}
88

9+
public final class io/sentry/android/replay/GeneratedVideo {
10+
public fun <init> (Ljava/io/File;IJ)V
11+
public final fun component1 ()Ljava/io/File;
12+
public final fun component2 ()I
13+
public final fun component3 ()J
14+
public final fun copy (Ljava/io/File;IJ)Lio/sentry/android/replay/GeneratedVideo;
15+
public static synthetic fun copy$default (Lio/sentry/android/replay/GeneratedVideo;Ljava/io/File;IJILjava/lang/Object;)Lio/sentry/android/replay/GeneratedVideo;
16+
public fun equals (Ljava/lang/Object;)Z
17+
public final fun getDuration ()J
18+
public final fun getFrameCount ()I
19+
public final fun getVideo ()Ljava/io/File;
20+
public fun hashCode ()I
21+
public fun toString ()Ljava/lang/String;
22+
}
23+
24+
public final class io/sentry/android/replay/ReplayCache : java/io/Closeable {
25+
public fun <init> (Lio/sentry/SentryOptions;Lio/sentry/protocol/SentryId;Lio/sentry/android/replay/ScreenshotRecorderConfig;)V
26+
public final fun addFrame (Ljava/io/File;J)V
27+
public fun close ()V
28+
public final fun createVideoOf (JJILjava/io/File;)Lio/sentry/android/replay/GeneratedVideo;
29+
public static synthetic fun createVideoOf$default (Lio/sentry/android/replay/ReplayCache;JJILjava/io/File;ILjava/lang/Object;)Lio/sentry/android/replay/GeneratedVideo;
30+
}
31+
932
public final class io/sentry/android/replay/ReplayIntegration : io/sentry/Integration, io/sentry/android/replay/ScreenshotRecorderCallback, java/io/Closeable {
1033
public static final field Companion Lio/sentry/android/replay/ReplayIntegration$Companion;
1134
public static final field VIDEO_BUFFER_DURATION J
@@ -33,6 +56,24 @@ public abstract interface class io/sentry/android/replay/ScreenshotRecorderCallb
3356
public abstract fun onScreenshotRecorded (Landroid/graphics/Bitmap;)V
3457
}
3558

59+
public final class io/sentry/android/replay/ScreenshotRecorderConfig {
60+
public fun <init> (IIFI)V
61+
public synthetic fun <init> (IIFIILkotlin/jvm/internal/DefaultConstructorMarker;)V
62+
public final fun component1 ()I
63+
public final fun component2 ()I
64+
public final fun component3 ()F
65+
public final fun component4 ()I
66+
public final fun copy (IIFI)Lio/sentry/android/replay/ScreenshotRecorderConfig;
67+
public static synthetic fun copy$default (Lio/sentry/android/replay/ScreenshotRecorderConfig;IIFIILjava/lang/Object;)Lio/sentry/android/replay/ScreenshotRecorderConfig;
68+
public fun equals (Ljava/lang/Object;)Z
69+
public final fun getFrameRate ()I
70+
public final fun getRecordingHeight ()I
71+
public final fun getRecordingWidth ()I
72+
public final fun getScaleFactor ()F
73+
public fun hashCode ()I
74+
public fun toString ()Ljava/lang/String;
75+
}
76+
3677
public abstract interface class io/sentry/android/replay/video/SimpleFrameMuxer {
3778
public abstract fun getVideoTime ()J
3879
public abstract fun isStarted ()Z

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayCache.kt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ import io.sentry.protocol.SentryId
1313
import java.io.Closeable
1414
import java.io.File
1515

16-
internal class ReplayCache(
16+
public class ReplayCache internal constructor(
1717
private val options: SentryOptions,
1818
private val replayId: SentryId,
1919
private val recorderConfig: ScreenshotRecorderConfig,
20-
private val encoderCreator: (File) -> SimpleVideoEncoder = { videoFile ->
20+
private val encoderCreator: (File) -> SimpleVideoEncoder
21+
) : Closeable {
22+
23+
public constructor(
24+
options: SentryOptions,
25+
replayId: SentryId,
26+
recorderConfig: ScreenshotRecorderConfig
27+
) : this(options, replayId, recorderConfig, encoderCreator = { videoFile ->
2128
SimpleVideoEncoder(
2229
options,
2330
MuxerConfig(
@@ -27,11 +34,10 @@ internal class ReplayCache(
2734
bitrate = 20 * 1000
2835
)
2936
).also { it.start() }
30-
}
31-
) : Closeable {
37+
})
3238

3339
private val encoderLock = Any()
34-
internal var encoder: SimpleVideoEncoder? = null
40+
private var encoder: SimpleVideoEncoder? = null
3541

3642
internal val replayCacheDir: File? by lazy {
3743
if (options.cacheDirPath.isNullOrEmpty()) {
@@ -48,7 +54,7 @@ internal class ReplayCache(
4854
// TODO: maybe account for multi-threaded access
4955
internal val frames = mutableListOf<ReplayFrame>()
5056

51-
fun addFrame(bitmap: Bitmap, frameTimestamp: Long) {
57+
internal fun addFrame(bitmap: Bitmap, frameTimestamp: Long) {
5258
if (replayCacheDir == null) {
5359
return
5460
}
@@ -61,11 +67,20 @@ internal class ReplayCache(
6167
it.flush()
6268
}
6369

70+
addFrame(screenshot, frameTimestamp)
71+
}
72+
73+
public fun addFrame(screenshot: File, frameTimestamp: Long) {
6474
val frame = ReplayFrame(screenshot, frameTimestamp)
6575
frames += frame
6676
}
6777

68-
fun createVideoOf(duration: Long, from: Long, segmentId: Int): GeneratedVideo? {
78+
public fun createVideoOf(
79+
duration: Long,
80+
from: Long,
81+
segmentId: Int,
82+
videoFile: File = File(replayCacheDir, "$segmentId.mp4")
83+
): GeneratedVideo? {
6984
if (frames.isEmpty()) {
7085
options.logger.log(
7186
DEBUG,
@@ -75,7 +90,6 @@ internal class ReplayCache(
7590
}
7691

7792
// TODO: reuse instance of encoder and just change file path to create a different muxer
78-
val videoFile = File(replayCacheDir, "$segmentId.mp4")
7993
encoder = synchronized(encoderLock) { encoderCreator(videoFile) }
8094

8195
val step = 1000 / recorderConfig.frameRate.toLong()
@@ -160,7 +174,7 @@ internal data class ReplayFrame(
160174
val timestamp: Long
161175
)
162176

163-
internal data class GeneratedVideo(
177+
public data class GeneratedVideo(
164178
val video: File,
165179
val frameCount: Int,
166180
val duration: Long

sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ internal class ScreenshotRecorder(
230230
}
231231
}
232232

233-
internal data class ScreenshotRecorderConfig(
233+
public data class ScreenshotRecorderConfig(
234234
val recordingWidth: Int,
235235
val recordingHeight: Int,
236236
val scaleFactor: Float,

0 commit comments

Comments
 (0)