Coder Social home page Coder Social logo

venohum / haishinkit.kt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shogo4405/haishinkit.kt

0.0 0.0 0.0 19.39 MB

Camera and Microphone streaming library via RTMP for Android.

License: BSD 3-Clause "New" or "Revised" License

Ruby 0.38% C++ 25.57% Java 0.07% Kotlin 69.78% CMake 0.73% GLSL 3.47%

haishinkit.kt's Introduction

HaishinKit for Android, iOS, macOS and tvOS.

GitHub license

๐Ÿ’ฌ Communication

  • If you need help with making LiveStreaming requests using HaishinKit, use a GitHub Discussions with Q&A.
  • If you'd like to discuss a feature request, use a GitHub Discussions with Idea
  • If you met a HaishinKit's bug๐Ÿ›, use a GitHub Issue with Bug report template
    • If you don't use an issue template. I will immediately close the your issue without a comment.
  • If you want to contribute, submit a pull request!
  • If you want to support e-mail based communication without GitHub.
    • Consulting fee is $50/1 incident. I'm able to response a few days.
  • Discord chatroom.
  • ๆ—ฅๆœฌ่ชžใŒๅˆ†ใ‹ใ‚‹ๆ–นใฏๆ—ฅๆœฌ่ชžใงใŠ้ก˜ใ„ใ—ใพใ™๏ผ

๐ŸŒ Related projects

Project name Notes License
HaishinKit for iOS, macOS and tvOS. Camera and Microphone streaming library via RTMP for Android. BSD 3-Clause "New" or "Revised" License
SRTHaishinKit for iOS. Camera and Microphone streaming library via SRT. BSD 3-Clause "New" or "Revised" License
HaishinKit for Flutter. Camera and Microphone streaming library via RTMP for Flutter. BSD 3-Clause "New" or "Revised" License

๐ŸŽจ Features

RTMP

  • Authentication
  • Publish (H264/AAC)
  • Playback
  • Action Message Format
    • AMF0
    • AMF3
  • SharedObject
  • RTMPS
    • Native (RTMP over SSL/TSL)

Filter

Sources

  • Camera with Camera2 api
  • MediaProjection
  • Microphone with AudioRecord api.

View rendering

- HkSurfaceView HkTextureView
Engine SurfaceView TextureView
Playback beta beta
Publish โœ… Stable โœ… Stable
Note Recommend Android 7.0+ Recommend Android 5.0-6.0

Others

  • Hardware acceleration for H264 video encoding/AAC audio encoding.
    • Asynchronously processing.
  • Graphics api
    • โœ… OpenGL
    • ๐Ÿ› Vulkan (beta)

Settings

stream.audioSettings.bitrate = 32 * 1000

stream.videoSettings.width = 640 // The width resoulution of video output.
stream.videoSettings.height = 360 // The height resoulution of video output.
stream.videoSettings.bitrate = 160 * 1000 // The bitRate of video output.
stream.videoSettings.IFrameInterval = 2 // The key-frmae interval

๐ŸŒ Architecture Overview

Publishing Feature

๐Ÿพ Examples

Examples project are available for Android.

  • Camera and microphone publish.
  • RTMP Playback
git clone https://github.com/shogo4405/HaishinKit.kt.git
cd HaishinKit.kt
git submodule update --init

# Open [Android Studio] -> [Open] ...

๐Ÿ”ง Usage

Gradle dependency

JitPack

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
  implementation 'com.github.shogo4405.HaishinKit~kt:haishinkit:x.x.x'
  implementation 'com.github.shogo4405.HaishinKit~kt:vulkan:x.x.x'
}

GitHub Packages

allprojects {
  repositories {
    maven {
      url = uri("https://maven.pkg.github.com/shogo4405/HaishinKit.kt")
      credentials {
        username = System.getenv("GITHUB_USER")
        password = System.getenv("GITHUB_API_TOKEN")
      }
    }
  }
}

dependencies {
  implementation 'com.haishinkit:haishinkit:x.x.x'
  implementation 'com.haishinkit:vulkan:x.x.x'
}

Dependencies

- minSdk Android Requirements Status
haishinkit 21+ 5 Require Stable
vulkan 26+ 8 Optional Technical preview

Android manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

Prerequisites

ActivityCompat.requestPermissions(this,arrayOf(
    Manifest.permission.CAMERA,
    Manifest.permission.RECORD_AUDIO
), 1)

RTMP Usage

Real Time Messaging Protocol (RTMP).

class CameraTabFragment: Fragment(), IEventListener {
    private lateinit var connection: RtmpConnection
    private lateinit var stream: RtmpStream
    private lateinit var cameraView: HkGLSurfaceView
    private lateinit var cameraSource: CameraSource

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        activity?.let {
            val permissionCheck = ContextCompat.checkSelfPermission(it, Manifest.permission.CAMERA)
            if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(it, arrayOf(Manifest.permission.CAMERA), 1)
            }
            if (ContextCompat.checkSelfPermission(it, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(it, arrayOf(Manifest.permission.RECORD_AUDIO), 1)
            }
        }
        connection = RtmpConnection()
        stream = RtmpStream(connection)
        stream.attachAudio(AudioRecordSource())
        cameraSource = CameraSource(requireContext()).apply {
            open(CameraCharacteristics.LENS_FACING_BACK)
        }
        stream.attachVideo(cameraSource)
        connection.addEventListener(Event.RTMP_STATUS, this)
    }

    @SuppressLint("SetTextI18n")
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val v = inflater.inflate(R.layout.fragment_camera, container, false)
        val button = v.findViewById<Button>(R.id.button)
        button.setOnClickListener {
            if (button.text == "Publish") {
                connection.connect(Preference.shared.rtmpURL)
                button.text = "Stop"
            } else {
                connection.close()
                button.text = "Publish"
            }
        }
        val switchButton = v.findViewById<Button>(R.id.switch_button)
        switchButton.setOnClickListener {
            cameraSource.switchCamera()
        }
        cameraView = v.findViewById(R.id.camera)
        cameraView.attachStream(stream)
        return v
    }

    override fun onDestroy() {
        super.onDestroy()
        connection.dispose()
    }

    override fun handleEvent(event: Event) {
        Log.i("$TAG#handleEvent", event.toString())
        val data = EventUtils.toMap(event)
        val code = data["code"].toString()
        if (code == RtmpConnection.Code.CONNECT_SUCCESS.rawValue) {
            stream.publish(Preference.shared.streamName)
        }
    }

    companion object {
        fun newInstance(): CameraTabFragment {
            return CameraTabFragment()
        }

        private val TAG = CameraTabFragment::class.java.simpleName
    }
}

Filter API (v0.1)

- [assets]
  - [shaders]
    - custom-shader.vert(optional)
    - custom-shader.frag
package my.custom.filter

import com.haishinkit.graphics.filter.VideoEffect

class Monochrome2VideoEffect(
    override val name: String = "custom-shader"
) : VideoEffect
stream.videoEffect = Monochrome2VideoEffect()

๐Ÿ““ FAQ

How can I compile the vulkan module with Android 5 project?

AndroidManifest.xml

<uses-sdk tools:overrideLibrary="com.haishinkit.vulkan" />

MainActivity

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    PixelTransformFactory.registerPixelTransform(VkPixelTransform::class)
}

RTMP URL Format

  • rtmp://server-ip-address[:port]/application/[appInstance]/[prefix:[path1[/path2/]]]streamName
    • [] mark is an Optional.
    rtmpConneciton.connect("rtmp://server-ip-address[:port]/application/[appInstance]")
    rtmpStream.publish("[prefix:[path1[/path2/]]]streamName")
    
  • rtmp://localhost/live/streamName
    rtmpConneciton.connect("rtmp://localhost/live")
    rtmpStream.publish("streamName")
    

Related Project

๐Ÿ’  Sponsorship

Looking for sponsors. Sponsoring I will enable us to:

  • Purchase smartphones or peripheral devices for testing purposes.
  • Pay for testing on a specific streaming service or for testing on mobile lines.
  • Potentially private use to continue the OSS development

If you use any of our libraries for work, see if your employers would be interested in sponsorship. I have some special offers.ใ€€I would greatly appreciate. Thank you.

  • If you request I will note your name product our README.
  • If you mention on a discussion, an issue or pull request that you are sponsoring us I will prioritise helping you even higher.

ใ‚นใƒใƒณใ‚ตใƒผใ‚’ๅ‹Ÿ้›†ใ—ใฆใ„ใพใ™ใ€‚ๅˆฉ็”จ็”จ้€”ใจใ—ใฆใฏใ€

  • ใƒ†ใ‚นใƒˆ็›ฎ็š„ใงใ€ใ‚นใƒžใƒผใƒˆใƒ•ใ‚ฉใƒณใฎ่ณผๅ…ฅใ‚„ๅ‘จ่พบๆฉŸๅ™จใฎ่ณผๅ…ฅใ‚’่กŒใ„ใพใ™ใ€‚
  • ็‰นๅฎšใฎใ‚นใƒˆใƒชใƒผใƒŸใƒณใ‚ฐใ‚ตใƒผใƒ“ใ‚นใธใฎใƒ†ใ‚นใƒˆใฎๆ”ฏๆ‰•ใ„ใ‚„ใ€ใƒขใƒใ‚คใƒซๅ›ž็ทšใงใฎใƒ†ใ‚นใƒˆใฎๆ”ฏๆ‰•ใ„ใซๅˆฉ็”จใ—ใพใ™ใ€‚
  • ่‘—ๆ›ธใฎOSS้–‹็™บใ‚’็ถ™็ถš็š„ใซ่กŒใ†็‚บใซ็ง็š„ใซๅˆฉ็”จใ™ใ‚‹ๅฏ่ƒฝๆ€งใ‚‚ใ‚ใ‚Šใพใ™ใ€‚

ใ“ใฎใƒฉใ‚คใƒ–ใƒฉใƒชใƒผใ‚’ไป•ไบ‹ใง็ถ™็ถš็š„ใซๅˆฉ็”จใ—ใฆใ„ใ‚‹ๅ ดๅˆใฏใ€ใœใฒใ€‚้›‡็”จไธปใซใ€ใ‚นใƒใƒณใ‚ตใƒผใซ่ˆˆๅ‘ณใŒใชใ„ใ‹็ขบ่ชใ„ใŸใ ใ‘ใ‚‹ใจๅนธใ„ใงใ™ใ€‚ใ„ใใคใ‹็‰นๅ…ธใ‚’็”จๆ„ใ—ใฆใ„ใพใ™ใ€‚

  • README.mdใธใฎไผๆฅญใƒญใ‚ดใฎๆŽฒ่ผ‰
  • Issueใ‚„Pull Requestใฎๅ„ชๅ…ˆ็š„ใชๅฏพๅฟœ

Sponsorship

๐Ÿ“œ License

BSD-3-Clause

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.