@@ -181,9 +181,13 @@ internal class SimpleVideoEncoder(
181
181
* Borrows heavily from https://bigflake.com/mediacodec/EncodeAndMuxTest.java.txt
182
182
*/
183
183
private fun drainCodec (endOfStream : Boolean ) {
184
- options.logger.log(DEBUG , " [Encoder]: drainCodec($endOfStream )" )
184
+ if (options.sessionReplay.isDebug) {
185
+ options.logger.log(DEBUG , " [Encoder]: drainCodec($endOfStream )" )
186
+ }
185
187
if (endOfStream) {
186
- options.logger.log(DEBUG , " [Encoder]: sending EOS to encoder" )
188
+ if (options.sessionReplay.isDebug) {
189
+ options.logger.log(DEBUG , " [Encoder]: sending EOS to encoder" )
190
+ }
187
191
mediaCodec.signalEndOfInputStream()
188
192
}
189
193
var encoderOutputBuffers: Array <ByteBuffer ?>? = mediaCodec.outputBuffers
@@ -193,7 +197,7 @@ internal class SimpleVideoEncoder(
193
197
// no output available yet
194
198
if (! endOfStream) {
195
199
break // out of while
196
- } else {
200
+ } else if (options.sessionReplay.isDebug) {
197
201
options.logger.log(DEBUG , " [Encoder]: no output available, spinning to await EOS" )
198
202
}
199
203
} else if (encoderStatus == MediaCodec .INFO_OUTPUT_BUFFERS_CHANGED ) {
@@ -205,35 +209,48 @@ internal class SimpleVideoEncoder(
205
209
throw RuntimeException (" format changed twice" )
206
210
}
207
211
val newFormat: MediaFormat = mediaCodec.outputFormat
208
- options.logger.log(DEBUG , " [Encoder]: encoder output format changed: $newFormat " )
212
+ if (options.sessionReplay.isDebug) {
213
+ options.logger.log(DEBUG , " [Encoder]: encoder output format changed: $newFormat " )
214
+ }
209
215
210
216
// now that we have the Magic Goodies, start the muxer
211
217
frameMuxer.start(newFormat)
212
218
} else if (encoderStatus < 0 ) {
213
- options.logger.log(DEBUG , " [Encoder]: unexpected result from encoder.dequeueOutputBuffer: $encoderStatus " )
219
+ if (options.sessionReplay.isDebug) {
220
+ options.logger.log(DEBUG , " [Encoder]: unexpected result from encoder.dequeueOutputBuffer: $encoderStatus " )
221
+ }
214
222
// let's ignore it
215
223
} else {
216
224
val encodedData = encoderOutputBuffers?.get(encoderStatus)
217
225
? : throw RuntimeException (" encoderOutputBuffer $encoderStatus was null" )
218
226
if (bufferInfo.flags and MediaCodec .BUFFER_FLAG_CODEC_CONFIG != 0 ) {
219
227
// The codec config data was pulled out and fed to the muxer when we got
220
228
// the INFO_OUTPUT_FORMAT_CHANGED status. Ignore it.
221
- options.logger.log(DEBUG , " [Encoder]: ignoring BUFFER_FLAG_CODEC_CONFIG" )
229
+ if (options.sessionReplay.isDebug) {
230
+ options.logger.log(DEBUG , " [Encoder]: ignoring BUFFER_FLAG_CODEC_CONFIG" )
231
+ }
222
232
bufferInfo.size = 0
223
233
}
224
234
if (bufferInfo.size != 0 ) {
225
235
if (! frameMuxer.isStarted()) {
226
236
throw RuntimeException (" muxer hasn't started" )
227
237
}
228
238
frameMuxer.muxVideoFrame(encodedData, bufferInfo)
229
- options.logger.log(DEBUG , " [Encoder]: sent ${bufferInfo.size} bytes to muxer" )
239
+ if (options.sessionReplay.isDebug) {
240
+ options.logger.log(DEBUG , " [Encoder]: sent ${bufferInfo.size} bytes to muxer" )
241
+ }
230
242
}
231
243
mediaCodec.releaseOutputBuffer(encoderStatus, false )
232
244
if (bufferInfo.flags and MediaCodec .BUFFER_FLAG_END_OF_STREAM != 0 ) {
233
- if (! endOfStream) {
234
- options.logger.log(DEBUG , " [Encoder]: reached end of stream unexpectedly" )
235
- } else {
236
- options.logger.log(DEBUG , " [Encoder]: end of stream reached" )
245
+ if (options.sessionReplay.isDebug) {
246
+ if (! endOfStream) {
247
+ options.logger.log(
248
+ DEBUG ,
249
+ " [Encoder]: reached end of stream unexpectedly"
250
+ )
251
+ } else {
252
+ options.logger.log(DEBUG , " [Encoder]: end of stream reached" )
253
+ }
237
254
}
238
255
break // out of while
239
256
}
0 commit comments