Skip to content

Commit

Permalink
refactor(core): move extensions and delete TAG extension.
Browse files Browse the repository at this point in the history
TAG extension was really convenient but it was not efficient.
  • Loading branch information
ThibaultBee committed Nov 15, 2023
1 parent 95d14e4 commit 56c552c
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.util.Log
import androidx.test.rule.GrantPermissionRule
import io.github.thibaultbee.streampack.streamers.bases.BaseAudioOnlyStreamer
import io.github.thibaultbee.streampack.utils.AndroidUtils
import io.github.thibaultbee.streampack.utils.TAG
import org.junit.Assert.fail
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -83,7 +82,7 @@ abstract class AudioOnlyStreamerTestCase :
AndroidUtils.fakeValidVideoConfig()
)
fail("Must not be possible to configure video")
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand All @@ -95,7 +94,7 @@ abstract class AudioOnlyStreamerTestCase :
AndroidUtils.fakeValidVideoConfig()
)
fail("Must not be possible to configure video")
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand All @@ -106,7 +105,7 @@ abstract class AudioOnlyStreamerTestCase :
AndroidUtils.fakeInvalidAudioConfig()
)
fail("Invalid configuration must throw an exception")
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand Down Expand Up @@ -207,4 +206,8 @@ abstract class AudioOnlyStreamerTestCase :
fail("Must be possible to call configure multiple times but catches exception: $e")
}
}

companion object {
private const val TAG = "AudioOnlyStreamerTestCase"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import android.view.Surface
import androidx.test.rule.GrantPermissionRule
import io.github.thibaultbee.streampack.streamers.bases.BaseCameraStreamer
import io.github.thibaultbee.streampack.utils.AndroidUtils
import io.github.thibaultbee.streampack.utils.TAG
import org.junit.After
import org.junit.Assert.fail
import org.junit.Before
Expand Down Expand Up @@ -91,7 +90,7 @@ abstract class CameraStreamerTestCase :
try {
streamer.startPreview(surface)
fail("startPreviewTest without configuration must throw an exception")
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand Down Expand Up @@ -248,4 +247,8 @@ abstract class CameraStreamerTestCase :
fail("Must be possible to startStream/stopStream multiple times but catches exception: $e")
}
}

companion object {
private const val TAG = "CameraStreamerTestCase"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import io.github.thibaultbee.streampack.streamers.bases.BaseStreamer
import io.github.thibaultbee.streampack.utils.AndroidUtils
import io.github.thibaultbee.streampack.utils.TAG
import org.junit.After
import org.junit.Assert.fail
import org.junit.Test
Expand Down Expand Up @@ -252,4 +251,8 @@ abstract class StreamerTestCase {
fail("Must be possible to startStream/stopStream multiple times but catches exception: $e")
}
}

companion object {
private const val TAG = "StreamerTestCase"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import io.github.thibaultbee.streampack.error.StreamPackError
import io.github.thibaultbee.streampack.internal.data.Frame
import io.github.thibaultbee.streampack.internal.events.EventHandler
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG


abstract class MediaCodecEncoder<T : Config>(
override val encoderListener: IEncoderListener,
Expand Down Expand Up @@ -235,4 +233,8 @@ abstract class MediaCodecEncoder<T : Config>(
mediaCodec?.release()
mediaCodec = null
}

companion object {
private const val TAG = "MediaCodecEncoder"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ package io.github.thibaultbee.streampack.internal.endpoints

import io.github.thibaultbee.streampack.internal.data.Packet
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG

/**
* A fake endpoint for test purpose.
*/
class FakeEndpoint() : IEndpoint {
class FakeEndpoint : IEndpoint {
override fun startStream() {
Logger.d(TAG, "startStream called")
}
Expand All @@ -42,4 +41,8 @@ class FakeEndpoint() : IEndpoint {
override fun release() {
Logger.d(TAG, "release called")
}

companion object {
private const val TAG = "FakeEndpoint"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import io.github.thibaultbee.streampack.internal.muxers.flv.tags.video.ExtendedV
import io.github.thibaultbee.streampack.internal.utils.av.FourCCs
import io.github.thibaultbee.streampack.internal.utils.extensions.numOfBits
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG
import java.io.IOException
import java.nio.ByteBuffer

Expand Down Expand Up @@ -145,6 +144,8 @@ class VideoMetadata(
val frameRate: Int
) : Metadata(dataRate) {
companion object {
private const val TAG = "VideoMetadata"

fun fromVideoConfig(
config: VideoConfig,
sourceOrientationProvider: ISourceOrientationProvider? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import io.github.thibaultbee.streampack.data.AudioConfig
import io.github.thibaultbee.streampack.internal.data.Frame
import io.github.thibaultbee.streampack.internal.utils.TimeUtils
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG
import java.nio.ByteBuffer

class AudioSource : IAudioSource {
Expand Down Expand Up @@ -159,6 +158,8 @@ class AudioSource : IAudioSource {
}

companion object {
private const val TAG = "AudioSource"

private val format = MediaFormat().apply {
setString(
MediaFormat.KEY_MIME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.view.Surface
import androidx.annotation.RequiresPermission
import io.github.thibaultbee.streampack.error.CameraError
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG
import io.github.thibaultbee.streampack.utils.getCameraFpsList
import kotlinx.coroutines.*
import java.security.InvalidParameterException
Expand Down Expand Up @@ -295,4 +294,8 @@ class CameraController(
updateBurstSession()
}
}

companion object {
private const val TAG = "CameraController"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import io.github.thibaultbee.streampack.internal.utils.extensions.landscapize
import io.github.thibaultbee.streampack.internal.utils.extensions.portraitize
import io.github.thibaultbee.streampack.listeners.OnErrorListener
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG
import java.nio.ByteBuffer

class ScreenSource(
Expand Down Expand Up @@ -69,12 +68,12 @@ class ScreenSource(
private val virtualDisplayCallback = object : VirtualDisplay.Callback() {
override fun onPaused() {
super.onPaused()
Logger.i(this@ScreenSource.TAG, "onPaused")
Logger.i(TAG, "onPaused")
}

override fun onStopped() {
super.onStopped()
Logger.i(this@ScreenSource.TAG, "onStopped")
Logger.i(TAG, "onStopped")

if (!isExplicitelyStopped) {
onErrorListener?.onError(StreamPackError("Screen source virtual display has been stopped"))
Expand All @@ -85,7 +84,7 @@ class ScreenSource(
private val mediaProjectionCallback = object : MediaProjection.Callback() {
override fun onStop() {
super.onStop()
Logger.i(this@ScreenSource.TAG, "onStop")
Logger.i(TAG, "onStop")

if (!isExplicitelyStopped) {
onErrorListener?.onError(StreamPackError("Screen source media projection has been stopped"))
Expand All @@ -94,6 +93,8 @@ class ScreenSource(
}

companion object {
private const val TAG = "ScreenSource"

private const val VIRTUAL_DISPLAY_NAME = "StreamPackScreenSource"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import io.github.thibaultbee.streampack.internal.utils.extensions.putShort
import io.github.thibaultbee.streampack.internal.utils.extensions.shl
import io.github.thibaultbee.streampack.internal.utils.extensions.toInt
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG
import java.nio.ByteBuffer

/**
Expand Down Expand Up @@ -75,6 +74,8 @@ data class VPCodecConfigurationRecord(
}

companion object {
private const val TAG = "VPCodecConfigurationRecord"

private const val VP_DECODER_CONFIGURATION_RECORD_SIZE = 8

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ class StreamPackLogger : ILogger {
override fun d(tag: String, message: String, tr: Throwable?) {
Log.d(tag, message, tr)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import io.github.thibaultbee.streampack.streamers.helpers.IConfigurationHelper
import io.github.thibaultbee.streampack.streamers.helpers.StreamerConfigurationHelper
import io.github.thibaultbee.streampack.streamers.interfaces.IStreamer
import io.github.thibaultbee.streampack.streamers.settings.BaseStreamerSettings
import io.github.thibaultbee.streampack.utils.TAG
import java.nio.ByteBuffer


Expand Down Expand Up @@ -382,4 +381,8 @@ abstract class BaseStreamer(

endpoint.release()
}

companion object {
private const val TAG = "BaseStreamer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.streamers.bases.BaseScreenRecorderStreamer
import io.github.thibaultbee.streampack.streamers.interfaces.ILiveStreamer
import io.github.thibaultbee.streampack.utils.NotificationUtils
import io.github.thibaultbee.streampack.utils.TAG
import io.github.thibaultbee.streampack.utils.getStreamer


/**
* Foreground service that manages screen recorder streamers.
*
Expand Down Expand Up @@ -244,6 +242,8 @@ abstract class BaseScreenRecorderService(
}

companion object {
private const val TAG = "BaseScreenRecorderService"

const val DEFAULT_NOTIFICATION_CHANNEL_ID =
"io.github.thibaultbee.streampack.streamers.services"
const val DEFAULT_NOTIFICATION_ID = 3782
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ class FocusMetering(
}

companion object {
private const val TAG = "CameraSettings"

private const val DEFAULT_AF_SIZE = 1.0f / 6.0f
private const val DEFAULT_AE_SIZE = DEFAULT_AF_SIZE * 1.5f
private const val DEFAULT_METERING_WEIGHT_MAX = MeteringRectangle.METERING_WEIGHT_MAX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ fun Context.hasSystemFeature(featureName: String) = packageManager.hasSystemFeat
/**
* Get if the system supports external cameras.
*
* @return true if the feature is supported, false otherwises
* @return true if the feature is supported, false otherwise
*/
fun Context.hasExternalCamera() = hasSystemFeature(PackageManager.FEATURE_CAMERA_EXTERNAL)


val Any.TAG: String
get() = this::class.java.simpleName
fun Context.hasExternalCamera() = hasSystemFeature(PackageManager.FEATURE_CAMERA_EXTERNAL)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.content.Context
import android.util.AttributeSet
import android.view.SurfaceView
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.utils.TAG
import kotlin.math.roundToInt

/**
Expand Down Expand Up @@ -73,4 +72,8 @@ open class AutoFitSurfaceView @JvmOverloads constructor(
setMeasuredDimension(newWidth, newHeight)
}
}

companion object {
private const val TAG = "AutoFitSurfaceView"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import io.github.thibaultbee.streampack.R
import io.github.thibaultbee.streampack.logger.Logger
import io.github.thibaultbee.streampack.streamers.interfaces.ICameraStreamer
import io.github.thibaultbee.streampack.utils.OrientationUtils
import io.github.thibaultbee.streampack.utils.TAG
import io.github.thibaultbee.streampack.utils.backCameraList
import io.github.thibaultbee.streampack.utils.frontCameraList
import io.github.thibaultbee.streampack.utils.getCameraCharacteristics
Expand Down Expand Up @@ -198,6 +197,8 @@ class PreviewView @JvmOverloads constructor(
}

companion object {
private const val TAG = "PreviewView"

private val DEFAULT_CAMERA_FACING = FacingDirection.BACK
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import androidx.appcompat.app.AppCompatActivity
import io.github.thibaultbee.streampack.app.R
import io.github.thibaultbee.streampack.app.databinding.MainActivityBinding
import io.github.thibaultbee.streampack.app.ui.settings.SettingsActivity
import io.github.thibaultbee.streampack.utils.TAG


class MainActivity : AppCompatActivity() {
private lateinit var binding: MainActivityBinding
Expand Down Expand Up @@ -76,4 +74,8 @@ class MainActivity : AppCompatActivity() {
menuInflater.inflate(R.menu.actions, menu)
return true
}

companion object {
private const val TAG = "MainActivity"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ import android.util.Rational
import androidx.annotation.RequiresPermission
import androidx.databinding.Bindable
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import io.github.thibaultbee.streampack.app.BR
import io.github.thibaultbee.streampack.app.utils.ObservableViewModel
import io.github.thibaultbee.streampack.app.utils.StreamerManager
Expand All @@ -38,7 +33,6 @@ import io.github.thibaultbee.streampack.error.StreamPackError
import io.github.thibaultbee.streampack.listeners.OnConnectionListener
import io.github.thibaultbee.streampack.listeners.OnErrorListener
import io.github.thibaultbee.streampack.streamers.StreamerLifeCycleObserver
import io.github.thibaultbee.streampack.utils.TAG
import io.github.thibaultbee.streampack.utils.isFrameRateSupported
import io.github.thibaultbee.streampack.views.PreviewView
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -274,4 +268,8 @@ class PreviewViewModel(private val streamerManager: StreamerManager) : Observabl
Log.e(TAG, "streamer.release failed", e)
}
}

companion object {
private const val TAG = "PreviewViewModel"
}
}
Loading

0 comments on commit 56c552c

Please sign in to comment.