Skip to content

Commit

Permalink
Bump up HaishinKit.kt to 0.13.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Feb 6, 2024
1 parent 9ecac10 commit ba96d2e
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 127 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ android {
}

dependencies {
implementation 'com.github.shogo4405.HaishinKit~kt:haishinkit:0.12.0'
implementation 'com.github.shogo4405.HaishinKit~kt:haishinkit:0.13.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ class HaishinKitPlugin : FlutterPlugin, MethodCallHandler {
handlers[handler.hashCode()] = handler
result.success(handler.hashCode())
}

"newRtmpStream" -> {
val connection = call.argument<Int>("connection")
val handler =
RtmpStreamHandler(this, handlers[connection] as? RtmpConnectionHandler)
RtmpStreamHandler(this, handlers[connection] as? RtmpConnectionHandler)
handlers[handler.hashCode()] = handler
result.success(handler.hashCode())
}

"getVersion" -> {
result.success(com.haishinkit.BuildConfig.VERSION_NAME)
}

else -> {
result.notImplemented()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.haishinkit.haishin_kit

import android.os.Handler
import android.os.Looper
import com.haishinkit.event.Event
import com.haishinkit.event.IEventListener
import com.haishinkit.rtmp.RtmpConnection
Expand All @@ -10,9 +8,9 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class RtmpConnectionHandler(
private val plugin: HaishinKitPlugin
private val plugin: HaishinKitPlugin
) : MethodChannel.MethodCallHandler, IEventListener,
EventChannel.StreamHandler {
EventChannel.StreamHandler {
companion object {
private const val TAG = "RtmpConnection"
}
Expand All @@ -26,8 +24,8 @@ class RtmpConnectionHandler(
init {
instance?.addEventListener(Event.RTMP_STATUS, this)
channel = EventChannel(
plugin.flutterPluginBinding.binaryMessenger,
"com.haishinkit.eventchannel/${hashCode()}"
plugin.flutterPluginBinding.binaryMessenger,
"com.haishinkit.eventchannel/${hashCode()}"
)
channel.setStreamHandler(this)
}
Expand All @@ -39,10 +37,12 @@ class RtmpConnectionHandler(
instance?.connect(command)
result.success(null)
}

"$TAG#close" -> {
instance?.close()
result.success(null)
}

"$TAG#dispose" -> {
eventSink?.endOfStream()
instance?.dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.haishinkit.haishin_kit

import android.content.Context
import android.graphics.Point
import android.hardware.camera2.CameraCharacteristics
import android.media.MediaFormat.KEY_LEVEL
import android.media.MediaFormat.KEY_PROFILE
Expand All @@ -14,13 +15,13 @@ import com.haishinkit.haishinkit.ProfileLevel
import com.haishinkit.media.AudioRecordSource
import com.haishinkit.media.Camera2Source
import com.haishinkit.rtmp.RtmpStream
import com.haishinkit.util.Rectangle
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import java.lang.Exception

class RtmpStreamHandler(
private val plugin: HaishinKitPlugin, handler: RtmpConnectionHandler?
private val plugin: HaishinKitPlugin, handler: RtmpConnectionHandler?
) : MethodChannel.MethodCallHandler, IEventListener, EventChannel.StreamHandler {
companion object {
private const val TAG = "RtmpStream"
Expand All @@ -41,11 +42,12 @@ class RtmpStreamHandler(

init {
handler?.instance?.let {
instance = RtmpStream(it)
instance = RtmpStream(plugin.flutterPluginBinding.applicationContext, it)
instance?.screen?.frame = Rectangle(Point(0, 0), Size(1024, 576))
instance?.addEventListener(Event.RTMP_STATUS, this)
}
channel = EventChannel(
plugin.flutterPluginBinding.binaryMessenger, "com.haishinkit.eventchannel/${hashCode()}"
plugin.flutterPluginBinding.binaryMessenger, "com.haishinkit.eventchannel/${hashCode()}"
)
channel.setStreamHandler(this)
}
Expand Down Expand Up @@ -110,7 +112,7 @@ class RtmpStreamHandler(
(source["profileLevel"] as? String)?.let {
try {
val profileLevel = ProfileLevel.valueOf(it)
var options = mutableListOf<CodecOption>()
val options = mutableListOf<CodecOption>()
options.add(CodecOption(KEY_PROFILE, profileLevel.profile))
options.add(CodecOption(KEY_LEVEL, profileLevel.level))
instance?.videoSetting?.options = options
Expand Down Expand Up @@ -164,30 +166,31 @@ class RtmpStreamHandler(
"$TAG#registerTexture" -> {
val netStream = instance
if (netStream?.drawable == null) {
val texture = NetStreamDrawableTexture(plugin.flutterPluginBinding)
val texture = StreamDrawableTexture(plugin.flutterPluginBinding)
texture.attachStream(netStream)
if (camera?.stream != null) {
camera?.open()
}
result.success(texture.id)
} else {
val texture = (netStream.drawable as? NetStreamDrawableTexture)
val texture = (netStream.drawable as? StreamDrawableTexture)
result.success(texture?.id)
}
}

"$TAG#unregisterTexture" -> {
result.success(null)
}

"$TAG#updateTextureSize" -> {
val netStream = instance
if (netStream?.drawable != null) {
val texture = (netStream.drawable as? NetStreamDrawableTexture)
val texture = (netStream.drawable as? StreamDrawableTexture)
val width = call.argument<Double>("width") ?: 0
val height = call.argument<Double>("height") ?: 0
texture?.imageExtent = Size(width.toInt(), height.toInt())
(plugin.flutterPluginBinding.applicationContext.getSystemService(Context.WINDOW_SERVICE) as? WindowManager)?.defaultDisplay?.orientation?.let {
netStream.deviceOrientation = it
netStream.videoSource?.screen?.deviceOrientation = it
}
result.success(texture?.id)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.haishinkit.haishin_kit

import android.util.Size
import android.view.Surface
import com.haishinkit.graphics.PixelTransform
import com.haishinkit.graphics.VideoGravity
import com.haishinkit.graphics.effect.VideoEffect
import com.haishinkit.media.Stream
import com.haishinkit.media.StreamDrawable
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.view.TextureRegistry

class StreamDrawableTexture(binding: FlutterPlugin.FlutterPluginBinding) :
StreamDrawable {
override var videoGravity: VideoGravity
get() = pixelTransform.videoGravity
set(value) {
pixelTransform.videoGravity = value
}

override var frameRate: Int
get() = pixelTransform.frameRate
set(value) {
pixelTransform.frameRate = value
}

override var videoEffect: VideoEffect
get() = pixelTransform.videoEffect
set(value) {
pixelTransform.videoEffect = value
}

val id: Long
get() = entry?.id() ?: 0

var imageExtent: Size
get() = pixelTransform.imageExtent
set(value) {
pixelTransform.imageExtent = value
entry?.surfaceTexture()?.setDefaultBufferSize(value.width, value.height)
}

private val pixelTransform: PixelTransform by lazy {
PixelTransform.create(binding.applicationContext)
}

private var stream: Stream? = null
set(value) {
field?.drawable = null
field = value
field?.drawable = this
pixelTransform.screen = value?.screen
}

private var entry: TextureRegistry.SurfaceTextureEntry? = null

init {
val entry = binding.textureRegistry.createSurfaceTexture()
pixelTransform.surface = Surface(entry.surfaceTexture())
this.entry = entry
}

override fun attachStream(stream: Stream?) {
this.stream = stream
}
}
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
audio_session: 4f3e461722055d21515cf3261b64c973c062f345
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
haishin_kit: 78778a018aeb3994a8e2e4dcda47b7dee2bbeb41
HaishinKit: 326e27c4d06427ba53bffc68e516a92033293051
Logboard: b78984e3f9fa5075d5bfd9308d51b453992aad0e
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -537,7 +537,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -586,7 +586,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down

0 comments on commit ba96d2e

Please sign in to comment.