This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
278 additions
and
159 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package eu.darken.fpv.dvca.dvr.core | ||
|
||
import android.net.Uri | ||
import okio.Source | ||
import okio.Sink | ||
|
||
interface DvrRecorder { | ||
|
||
fun record(source: Source, target: Uri): Session | ||
fun record(storagePath: Uri): Session | ||
|
||
interface Session { | ||
val sink: Sink | ||
|
||
fun stop() | ||
|
||
fun cancel() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/eu/darken/fpv/dvca/gear/goggles/common/TeeSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package eu.darken.fpv.dvca.gear.goggles.common | ||
|
||
import eu.darken.androidstarter.common.logging.v | ||
import eu.darken.androidstarter.common.logging.w | ||
import okio.* | ||
import java.io.IOException | ||
|
||
class TeeSource(private val upstream: Source) : Source { | ||
|
||
private val sideStreams = mutableListOf<BufferedSink>() | ||
|
||
fun addSideSink(sink: BufferedSink) { | ||
v { "addSideSink(sink=$sink)" } | ||
sideStreams.add(sink) | ||
} | ||
|
||
override fun read(sink: Buffer, byteCount: Long): Long { | ||
val bytesRead = try { | ||
upstream.read(sink, byteCount) | ||
} catch (e: IOException) { | ||
sideStreams.iterator().forEach { it.tryClose() } | ||
throw e | ||
} | ||
|
||
if (bytesRead == -1L) { | ||
sideStreams.iterator().forEach { it.tryClose() } | ||
return -1L | ||
} | ||
|
||
val offset = sink.size - bytesRead | ||
|
||
with(sideStreams.listIterator()) { | ||
forEach { | ||
if (!it.isOpen) { | ||
remove() | ||
return@forEach | ||
} | ||
|
||
sink.copyTo(it.buffer, offset, bytesRead) | ||
it.emitCompleteSegments() | ||
} | ||
|
||
return bytesRead | ||
} | ||
} | ||
|
||
override fun close() { | ||
sideStreams.iterator().forEach { it.tryClose() } | ||
upstream.close() | ||
} | ||
|
||
override fun timeout(): Timeout = upstream.timeout() | ||
|
||
private fun Sink.tryClose() = try { | ||
close() | ||
} catch (e: Exception) { | ||
w { "Sink failed to close: already closed: $e" } | ||
} | ||
} | ||
|
||
fun Source.tee(): TeeSource = TeeSource(this) |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/eu/darken/fpv/dvca/gear/goggles/djifpv/ExoDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package eu.darken.fpv.dvca.gear.goggles.djifpv | ||
|
||
import android.net.Uri | ||
import com.google.android.exoplayer2.C | ||
import com.google.android.exoplayer2.upstream.DataSource | ||
import com.google.android.exoplayer2.upstream.DataSpec | ||
import com.google.android.exoplayer2.upstream.TransferListener | ||
import eu.darken.fpv.dvca.gear.goggles.Goggles | ||
import okio.BufferedSource | ||
import okio.buffer | ||
import timber.log.Timber | ||
|
||
class ExoDataSource( | ||
private val videoFeed: Goggles.VideoFeed, | ||
private val tag: String, | ||
) : DataSource { | ||
private var exoBuffer: BufferedSource? = null | ||
|
||
override fun getUri(): Uri? = Uri.EMPTY | ||
|
||
override fun addTransferListener(transferListener: TransferListener) {} | ||
|
||
override fun open(dataSpec: DataSpec): Long { | ||
Timber.tag(tag).v("open(dataSpec=%s) this=%s", dataSpec, this) | ||
videoFeed.open() | ||
exoBuffer = videoFeed.source.buffer() | ||
|
||
return if (dataSpec.length != C.LENGTH_UNSET.toLong()) { | ||
dataSpec.length | ||
} else { | ||
C.LENGTH_UNSET.toLong() | ||
} | ||
} | ||
|
||
override fun read(target: ByteArray, offset: Int, length: Int): Int { | ||
return exoBuffer?.read(target, offset, length) ?: -1 | ||
} | ||
|
||
override fun close() { | ||
Timber.tag(tag).d("close(), source, this=%s", this) | ||
videoFeed.close() | ||
exoBuffer?.close() | ||
exoBuffer = null | ||
} | ||
} |
Oops, something went wrong.