Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Jan 14, 2024
1 parent 3535ec9 commit d38cfcf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class MediaProjectionService : Service(), IEventListener {
MSG_SET_VIDEO_EFFECT -> {
if (msg.obj is LanczosVideoEffect) {
val lanczosVideoEffect = msg.obj as LanczosVideoEffect
lanczosVideoEffect.texelWidth = videoSource.resolution.width.toFloat()
lanczosVideoEffect.texelHeight = videoSource.resolution.height.toFloat()
lanczosVideoEffect.texelWidth = videoSource.size.width.toFloat()
lanczosVideoEffect.texelHeight = videoSource.size.height.toFloat()
stream.videoEffect = lanczosVideoEffect
return
}
Expand Down Expand Up @@ -95,8 +95,8 @@ class MediaProjectionService : Service(), IEventListener {
metrics
)
stream.attachVideo(source)
stream.videoSetting.width = source.resolution.width shr 2
stream.videoSetting.height = source.resolution.height shr 2
stream.videoSetting.width = source.size.width shr 2
stream.videoSetting.height = source.size.height shr 2
videoSource = source
Log.e(TAG, "${stream.videoSetting.width}:${stream.videoSetting.height}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.haishinkit.media

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.ImageFormat
import android.graphics.SurfaceTexture
import android.hardware.camera2.CameraAccessException
import android.hardware.camera2.CameraCaptureSession
Expand Down Expand Up @@ -57,7 +56,7 @@ class Camera2Source(
private set
override var stream: NetStream? = null
override val isRunning = AtomicBoolean(false)
override var resolution = Size(0, 0)
override var size = Size(0, 0)
private var cameraId: String = DEFAULT_CAMERA_ID
private var manager: CameraManager =
context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
Expand Down Expand Up @@ -174,16 +173,16 @@ class Camera2Source(
override fun onOpened(camera: CameraDevice) {
device = camera
surfaces.clear()
resolution = getCameraSize()
size = getCameraSize()
stream?.drawable?.apply {
imageOrientation = this@Camera2Source.imageOrientation
createInputSurface(resolution.width, resolution.height, IMAGE_FORMAT) {
createInputSurface(size.width, size.height, IMAGE_FORMAT) {
createCaptureSession(it)
}
}
stream?.videoCodec?.pixelTransform?.apply {
imageOrientation = this@Camera2Source.imageOrientation
createInputSurface(resolution.width, resolution.height, IMAGE_FORMAT) {
createInputSurface(size.width, size.height, IMAGE_FORMAT) {
createCaptureSession(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class MediaProjectionSource(
var isRotatesWithContent = true
override var stream: NetStream? = null
override val isRunning = AtomicBoolean(false)
override var resolution = Size(0, 0)
override var size = Size(0, 0)
set(value) {
if (field == value) {
return
}
field = value
stream?.videoCodec?.pixelTransform?.createInputSurface(
resolution.width,
resolution.height,
size.width,
size.height,
0x1
) {
var flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
Expand All @@ -82,8 +82,8 @@ class MediaProjectionSource(
}
virtualDisplay = mediaProjection.createVirtualDisplay(
DEFAULT_DISPLAY_NAME,
resolution.width,
resolution.height,
size.width,
size.height,
metrics.densityDpi,
flags,
it,
Expand Down Expand Up @@ -135,10 +135,10 @@ class MediaProjectionSource(
val windowManager =
context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
rotation = windowManager.defaultDisplay.rotation
resolution = if (resolution.width < resolution.height) {
resolution.swap(rotation == 1 || rotation == 3)
size = if (size.width < size.height) {
size.swap(rotation == 1 || rotation == 3)
} else {
resolution.swap(rotation == 0 || rotation == 4)
size.swap(rotation == 0 || rotation == 4)
}
}
}
Expand All @@ -161,7 +161,7 @@ class MediaProjectionSource(
// Android 14 must register an callback.
mediaProjection.registerCallback(callback, null)
rotation = windowManager.defaultDisplay.rotation
resolution =
size =
Size((metrics.widthPixels * scale).toInt(), (metrics.heightPixels * scale).toInt())
super.setUp()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface VideoSource : Source {
/**
* The video size that is the current source.
*/
val resolution: Size
val size: Size
}
4 changes: 2 additions & 2 deletions haishinkit/src/main/java/com/haishinkit/rtmp/RtmpStream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ class RtmpStream(internal var connection: RtmpConnection) :
private fun toMetaData(): Map<String, Any> {
val metadata = mutableMapOf<String, Any>()
videoSource?.let {
metadata["width"] = it.resolution.width
metadata["height"] = it.resolution.height
metadata["width"] = it.size.width
metadata["height"] = it.size.height
metadata["framerate"] = videoCodec.frameRate
metadata["videocodecid"] = FlvVideoCodec.AVC.toInt()
metadata["videodatarate"] = videoCodec.bitRate / 1000
Expand Down

0 comments on commit d38cfcf

Please sign in to comment.