Add some more logging calls

This commit is contained in:
tzugen 2022-04-12 17:12:17 +02:00
parent 728afad00c
commit 7d33770fd6
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 21 additions and 13 deletions

View File

@ -132,6 +132,13 @@ open class APIDataSource private constructor(
@Suppress("LongMethod", "NestedBlockDepth") @Suppress("LongMethod", "NestedBlockDepth")
@Throws(HttpDataSourceException::class) @Throws(HttpDataSourceException::class)
override fun open(dataSpec: DataSpec): Long { override fun open(dataSpec: DataSpec): Long {
Timber.i(
"APIDatasource: Open: %s %s %s",
dataSpec.uri,
dataSpec.position,
dataSpec.toString()
)
this.dataSpec = dataSpec this.dataSpec = dataSpec
bytesRead = 0 bytesRead = 0
bytesToRead = 0 bytesToRead = 0
@ -140,22 +147,15 @@ open class APIDataSource private constructor(
val components = dataSpec.uri.toString().split('|') val components = dataSpec.uri.toString().split('|')
val id = components[0] val id = components[0]
val bitrate = components[1].toInt() val bitrate = components[1].toInt()
Timber.i("DATASOURCE: %s", "Start")
// FIXME
// WRONG API CLIENT
val request = subsonicAPIClient.api.stream(id, bitrate, offset = 0) val request = subsonicAPIClient.api.stream(id, bitrate, offset = 0)
val response: retrofit2.Response<ResponseBody>? val response: retrofit2.Response<ResponseBody>?
val streamResponse: StreamResponse val streamResponse: StreamResponse
Timber.i("DATASOURCE: %s", "Start2")
try { try {
this.response = request.execute() this.response = request.execute()
Timber.i("DATASOURCE: %s", "Start3")
response = this.response response = this.response
streamResponse = response!!.toStreamResponse() streamResponse = response!!.toStreamResponse()
Timber.i("DATASOURCE: %s", "Start4")
responseByteStream = streamResponse.stream responseByteStream = streamResponse.stream
Timber.i("DATASOURCE: %s", "Start5")
} catch (e: IOException) { } catch (e: IOException) {
throw HttpDataSourceException.createForIOException( throw HttpDataSourceException.createForIOException(
e, dataSpec, HttpDataSourceException.TYPE_OPEN e, dataSpec, HttpDataSourceException.TYPE_OPEN
@ -193,8 +193,6 @@ open class APIDataSource private constructor(
) )
} }
Timber.i("DATASOURCE: %s", "Start6")
// If we requested a range starting from a non-zero position and received a 200 rather than a // If we requested a range starting from a non-zero position and received a 200 rather than a
// 206, then the server does not support partial requests. We'll need to manually skip to the // 206, then the server does not support partial requests. We'll need to manually skip to the
// requested position. // requested position.
@ -216,13 +214,13 @@ open class APIDataSource private constructor(
closeConnectionQuietly() closeConnectionQuietly()
throw e throw e
} }
Timber.i("DATASOURCE: %s", "Start7")
return bytesToRead return bytesToRead
} }
@Throws(HttpDataSourceException::class) @Throws(HttpDataSourceException::class)
override fun read(buffer: ByteArray, offset: Int, length: Int): Int { override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
Timber.i("APIDatasource: Read: %s %s %s", buffer, offset, length)
return try { return try {
readInternal(buffer, offset, length) readInternal(buffer, offset, length)
} catch (e: IOException) { } catch (e: IOException) {
@ -233,6 +231,7 @@ open class APIDataSource private constructor(
} }
override fun close() { override fun close() {
Timber.i("APIDatasource: Close")
if (openedNetwork) { if (openedNetwork) {
openedNetwork = false openedNetwork = false
transferEnded() transferEnded()
@ -322,8 +321,7 @@ open class APIDataSource private constructor(
return C.RESULT_END_OF_INPUT return C.RESULT_END_OF_INPUT
} }
bytesRead += read.toLong() bytesRead += read.toLong()
// TODO bytesTransferred(read)
// bytesTransferred(read)
return read return read
} }

View File

@ -22,6 +22,7 @@ import java.io.InputStream
import org.moire.ultrasonic.util.AbstractFile import org.moire.ultrasonic.util.AbstractFile
import org.moire.ultrasonic.util.FileUtil import org.moire.ultrasonic.util.FileUtil
import org.moire.ultrasonic.util.Storage import org.moire.ultrasonic.util.Storage
import timber.log.Timber
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class CachedDataSource( class CachedDataSource(
@ -92,6 +93,13 @@ class CachedDataSource(
private var cacheFile: AbstractFile? = null private var cacheFile: AbstractFile? = null
override fun open(dataSpec: DataSpec): Long { override fun open(dataSpec: DataSpec): Long {
Timber.i(
"CachedDatasource: Open: %s %s %s",
dataSpec.uri,
dataSpec.position,
dataSpec.toString()
)
this.dataSpec = dataSpec this.dataSpec = dataSpec
bytesRead = 0 bytesRead = 0
bytesToRead = 0 bytesToRead = 0
@ -112,6 +120,7 @@ class CachedDataSource(
} }
override fun read(buffer: ByteArray, offset: Int, length: Int): Int { override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
Timber.i("CachedDatasource: Read: %s %s %s", buffer, offset, length)
return if (cachePath != null) { return if (cachePath != null) {
try { try {
readInternal(buffer, offset, length) readInternal(buffer, offset, length)
@ -156,6 +165,7 @@ class CachedDataSource(
} }
override fun close() { override fun close() {
Timber.i("CachedDatasource: close")
if (openedFile) { if (openedFile) {
openedFile = false openedFile = false
responseByteStream?.close() responseByteStream?.close()