@@ -181,9 +181,13 @@ internal class SimpleVideoEncoder(
181181 * Borrows heavily from https://bigflake.com/mediacodec/EncodeAndMuxTest.java.txt
182182 */
183183 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+ }
185187 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+ }
187191 mediaCodec.signalEndOfInputStream()
188192 }
189193 var encoderOutputBuffers: Array <ByteBuffer ?>? = mediaCodec.outputBuffers
@@ -193,7 +197,7 @@ internal class SimpleVideoEncoder(
193197 // no output available yet
194198 if (! endOfStream) {
195199 break // out of while
196- } else {
200+ } else if (options.sessionReplay.isDebug) {
197201 options.logger.log(DEBUG , " [Encoder]: no output available, spinning to await EOS" )
198202 }
199203 } else if (encoderStatus == MediaCodec .INFO_OUTPUT_BUFFERS_CHANGED ) {
@@ -205,35 +209,48 @@ internal class SimpleVideoEncoder(
205209 throw RuntimeException (" format changed twice" )
206210 }
207211 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+ }
209215
210216 // now that we have the Magic Goodies, start the muxer
211217 frameMuxer.start(newFormat)
212218 } 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+ }
214222 // let's ignore it
215223 } else {
216224 val encodedData = encoderOutputBuffers?.get(encoderStatus)
217225 ? : throw RuntimeException (" encoderOutputBuffer $encoderStatus was null" )
218226 if (bufferInfo.flags and MediaCodec .BUFFER_FLAG_CODEC_CONFIG != 0 ) {
219227 // The codec config data was pulled out and fed to the muxer when we got
220228 // 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+ }
222232 bufferInfo.size = 0
223233 }
224234 if (bufferInfo.size != 0 ) {
225235 if (! frameMuxer.isStarted()) {
226236 throw RuntimeException (" muxer hasn't started" )
227237 }
228238 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+ }
230242 }
231243 mediaCodec.releaseOutputBuffer(encoderStatus, false )
232244 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+ }
237254 }
238255 break // out of while
239256 }
0 commit comments