Skip to content

Commit

Permalink
refactor(*): rename preview view to camera preview view
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Jan 3, 2025
1 parent 441d80e commit cebda2f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ To simplify integration, StreamPack provides an `PreviewView`.
```xml

<layout>
<io.github.thibaultbee.streampack.views.PreviewView android:id="@+id/preview"
<io.github.thibaultbee.streampack.views.CameraPreviewView android:id="@+id/preview"
android:layout_width="match_parent" android:layout_height="match_parent"
app:enableZoomOnPinch="true" />
</layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import io.github.thibaultbee.streampack.app.R
import io.github.thibaultbee.streampack.app.databinding.MainFragmentBinding
import io.github.thibaultbee.streampack.app.utils.DialogUtils
import io.github.thibaultbee.streampack.app.utils.PermissionManager
import io.github.thibaultbee.streampack.ui.views.PreviewView
import io.github.thibaultbee.streampack.ui.views.CameraPreviewView
import kotlinx.coroutines.launch

class PreviewFragment : Fragment(R.layout.main_fragment) {
Expand Down Expand Up @@ -151,7 +151,7 @@ class PreviewFragment : Fragment(R.layout.main_fragment) {
private fun inflateStreamerPreview() {
val preview = binding.preview
// Set camera settings button when camera is started
preview.listener = object : PreviewView.Listener {
preview.listener = object : CameraPreviewView.Listener {
override fun onPreviewStarted() {
previewViewModel.onPreviewStarted()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import io.github.thibaultbee.streampack.core.streamers.single.startStream
import io.github.thibaultbee.streampack.core.utils.extensions.isClosedException
import io.github.thibaultbee.streampack.core.utils.extensions.isFrameRateSupported
import io.github.thibaultbee.streampack.ext.srt.regulator.controllers.DefaultSrtBitrateRegulatorController
import io.github.thibaultbee.streampack.ui.views.PreviewView
import io.github.thibaultbee.streampack.ui.views.CameraPreviewView
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
Expand Down Expand Up @@ -165,7 +165,7 @@ class PreviewViewModel(private val application: Application) : ObservableViewMod
}
}

fun setStreamerView(view: PreviewView) {
fun setStreamerView(view: CameraPreviewView) {
if (streamer is ICameraStreamer) {
view.streamer = streamer as ICameraStreamer
}
Expand Down
2 changes: 1 addition & 1 deletion demos/camera/src/main/res/layout/main_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_height="match_parent"
android:keepScreenOn="true">

<io.github.thibaultbee.streampack.ui.views.PreviewView
<io.github.thibaultbee.streampack.ui.views.CameraPreviewView
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.github.thibaultbee.streampack.ext.srt.regulator.controllers
import io.github.thibaultbee.streampack.core.configuration.BitrateRegulatorConfig
import io.github.thibaultbee.streampack.core.regulator.controllers.BitrateRegulatorController
import io.github.thibaultbee.streampack.core.regulator.controllers.DefaultBitrateRegulatorController
import io.github.thibaultbee.streampack.core.streamers.outputs.IStreamerEncodingOutput
import io.github.thibaultbee.streampack.core.streamers.single.ICoroutineSingleStreamer
import io.github.thibaultbee.streampack.ext.srt.regulator.DefaultSrtBitrateRegulator
import io.github.thibaultbee.streampack.ext.srt.regulator.SrtBitrateRegulator

Expand All @@ -31,7 +31,7 @@ class DefaultSrtBitrateRegulatorController {
private val bitrateRegulatorConfig: BitrateRegulatorConfig = BitrateRegulatorConfig(),
private val delayTimeInMs: Long = 500
) : BitrateRegulatorController.Factory() {
override fun newBitrateRegulatorController(streamer: IStreamerEncodingOutput): DefaultBitrateRegulatorController {
override fun newBitrateRegulatorController(streamer: ICoroutineSingleStreamer): DefaultBitrateRegulatorController {
return DefaultBitrateRegulatorController(
streamer.audioEncoder,
streamer.videoEncoder,
Expand All @@ -41,6 +41,5 @@ class DefaultSrtBitrateRegulatorController {
delayTimeInMs
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ import java.util.concurrent.CancellationException
*
* In the case, you are using it, do not call [ICameraCoroutineStreamer.startPreview] (or
* [ICameraCallbackStreamer.stopPreview]) and [ICameraCoroutineStreamer.stopPreview] on application
* side. It will be handled by the [PreviewView].
* side. It will be handled by the [CameraPreviewView].
*
* The [Manifest.permission.CAMERA] permission must be granted before using this view.
*/
class PreviewView @JvmOverloads constructor(
class CameraPreviewView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyle: Int = 0
) : FrameLayout(context, attrs, defStyle) {
private val cameraViewfinder = CameraViewfinder(context, attrs, defStyle)
Expand Down Expand Up @@ -103,7 +103,7 @@ class PreviewView @JvmOverloads constructor(
}

/**
* The position of the [PreviewView] within its container.
* The position of the [CameraPreviewView] within its container.
*/
var position: Position
get() = getPosition(cameraViewfinder.scaleType)
Expand All @@ -112,7 +112,7 @@ class PreviewView @JvmOverloads constructor(
}

/**
* The scale mode of the [PreviewView] within its container.
* The scale mode of the [CameraPreviewView] within its container.
*/
var scaleMode: ScaleMode
get() = getScaleMode(cameraViewfinder.scaleType)
Expand Down Expand Up @@ -428,7 +428,7 @@ class PreviewView @JvmOverloads constructor(


/**
* A listener for the [PreviewView].
* A listener for the [CameraPreviewView].
*/
interface Listener {
/**
Expand All @@ -449,21 +449,21 @@ class PreviewView @JvmOverloads constructor(
}

/**
* Options for the position of the [PreviewView] within its container.
* Options for the position of the [CameraPreviewView] within its container.
*/
enum class Position(val value: Int) {
/**
* The [PreviewView] is positioned at the top of its container.
* The [CameraPreviewView] is positioned at the top of its container.
*/
START(0),

/**
* The [PreviewView] is positioned in the center of its container.
* The [CameraPreviewView] is positioned in the center of its container.
*/
CENTER(1),

/**
* The [PreviewView] is positioned in the bottom of its container.
* The [CameraPreviewView] is positioned in the bottom of its container.
*/
END(2);

Expand All @@ -476,24 +476,24 @@ class PreviewView @JvmOverloads constructor(
}

/**
* Options for scaling the [PreviewView] within its container.
* Options for scaling the [CameraPreviewView] within its container.
*/
enum class ScaleMode(val value: Int) {
/**
* Scale the [PreviewView], maintaining the source aspect ratio, so it fills the entire
* Scale the [CameraPreviewView], maintaining the source aspect ratio, so it fills the entire
* parent.
*
* This may cause the [PreviewView] to be cropped.
* This may cause the [CameraPreviewView] to be cropped.
*/
FILL(0),

/**
* Scale the [PreviewView], maintaining the source aspect ratio, so it is entirely contained
* Scale the [CameraPreviewView], maintaining the source aspect ratio, so it is entirely contained
* within the parent. The background area not covered by the viewfinder stream will be black
* or the background of the [PreviewView].
* or the background of the [CameraPreviewView].
*
*
* Both dimensions of the [PreviewView] will be equal or less than the corresponding
* Both dimensions of the [CameraPreviewView] will be equal or less than the corresponding
* dimensions of its parent.
*/
FIT(1);
Expand Down

0 comments on commit cebda2f

Please sign in to comment.