mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-09-12 11:37:52 +01:00
Extract postprocessor lambda into interface.
This commit is contained in:
committed by
Greyson Parrelli
parent
52120afdbd
commit
c41795e7f0
+8
-5
@@ -19,23 +19,23 @@ import java.io.SequenceInputStream
|
||||
* A post processor that takes a stream of bytes, and using [Mp4Sanitizer], moves the metadata to the front of the file.
|
||||
*
|
||||
* @property inputStreamFactory factory for the [InputStream]. May be called multiple times.
|
||||
* @property inputLength the exact stream of the [InputStream]
|
||||
* @property inputLength the exact length of the [InputStream]
|
||||
*/
|
||||
class Mp4FaststartPostProcessor(private val inputStreamFactory: () -> InputStream, private val inputLength: Long) {
|
||||
class Mp4FaststartPostProcessor(private val inputStreamFactory: InputStreamFactory, private val inputLength: Long) {
|
||||
|
||||
/**
|
||||
* It is the responsibility of the called to close the resulting [InputStream]
|
||||
*/
|
||||
fun process(): InputStream {
|
||||
val metadata: SanitizedMetadata?
|
||||
inputStreamFactory().use {
|
||||
inputStreamFactory.create().use {
|
||||
metadata = Mp4Sanitizer.sanitize(it, inputLength)
|
||||
}
|
||||
if (metadata?.sanitizedMetadata == null) {
|
||||
throw VideoPostProcessingException("Mp4Sanitizer could not parse media metadata!")
|
||||
}
|
||||
|
||||
val inputStream = inputStreamFactory()
|
||||
val inputStream = inputStreamFactory.create()
|
||||
inputStream.skip(metadata.dataOffset)
|
||||
|
||||
return SequenceInputStream(ByteArrayInputStream(metadata.sanitizedMetadata), LimitedInputStream(inputStream, metadata.dataLength))
|
||||
@@ -47,6 +47,10 @@ class Mp4FaststartPostProcessor(private val inputStreamFactory: () -> InputStrea
|
||||
}
|
||||
}
|
||||
|
||||
fun interface InputStreamFactory {
|
||||
fun create(): InputStream
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "Mp4Faststart"
|
||||
}
|
||||
@@ -117,6 +121,5 @@ class Mp4FaststartPostProcessor(private val inputStreamFactory: () -> InputStrea
|
||||
left -= skipped
|
||||
return skipped
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user