Skip to content

uizaio/snake.sdk.android-broadcast

Repository files navigation

Welcome to UIZA BroadCast Snake SDK

Simple Streaming at scale.

Uiza is the complete toolkit for building a powerful video streaming application with unlimited scalability. We design Uiza so simple that you only need a few lines of codes to start streaming, but sophisticated enough for you to build complex products on top of it.

Read CHANGELOG here.



Importing the Library

Step 1. Add the JitPack repository to your build.gradle file

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

Step 2. Add the dependency

dependencies {
    implementation 'com.github.uizaio:snake.sdk.android-broadcast:x.y.z'
}

Get latest release number HERE.





How to Broadcast (Foreground)?:

It's very easy, plz follow these steps below to implement:

XML:

<com.uiza.broadcast.UZBroadCastView
    android:id="@+id/uzBroadCastView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />   

Pls take a look at class BroadCastAdvancedActivity for more information.

Here are some points you need to remember:

uzBroadCastView.onSurfaceChanged =
            { _: SurfaceHolder, _: Int, _: Int, _: Int ->
                    uzBroadCastView.startPreview(
                    cameraFacing = CameraHelper.Facing.BACK,
                    width = 640,
                    height = 480,
                    rotation = CameraHelper.getCameraOrientation(this)
                    )
            }
    val linkStream = "Your link"
    uzBroadCastView.startStream(linkStream)

Enable or disable Anti aliasing (This method use FXAA).
_AAEnabled – true is AA enabled, false is AA disabled. False by default.

    fun enableAA(AAEnabled: Boolean)

Set a filter to stream.
You can select any filter or create your own filter if you extends from BaseFilterRender
baseFilterRender – filter to set.
You can modify parameters to filter after set it to stream

    fun setFilter(baseFilterRender: BaseFilterRender)

Capture an Image
_takePhotoCallback – callback where you will get your image like a bitmap.

    fun takePhoto(takePhotoCallback: TakePhotoCallback)

Start camera preview. Ignored, if stream or preview is started.
_cameraFacing – front or back camera. Like: CameraHelper.Facing.BACK CameraHelper.Facing.FRONT
_width – of preview in px.
_height – of preview in px.
_rotation – camera rotation (0, 90, 180, 270). Recommended: CameraHelper.getCameraOrientation(Context)\

    fun startPreview(
        cameraFacing: CameraHelper.Facing,
        width: Int,
        height: Int,
        rotation: Int,
    )

Stop camera preview

    fun stopPreview()

Call this method before use @startStream. If not you will do a stream without audio.
_bitrate – AAC in kb.
_sampleRate – of audio in hz. Can be 8000, 16000, 22500, 32000, 44100.
_isStereo – true if you want Stereo audio (2 audio channels), false if you want Mono audio (1 audio channel).
_echoCanceler – true enable echo canceler, false disable.
_noiseSuppressor – true enable noise suppressor, false disable.
Returns: true if success, false if you get a error (Normally because the encoder selected doesn't support any configuration seated or your device hasn't a AAC encoder).

    fun prepareAudio(
        audioBitrate: Int,
        audioSampleRate: Int,
        audioIsStereo: Boolean,
        audioEchoCanceler: Boolean,
        audioNoiseSuppressor: Boolean,
    )

Call this method before use @startStream. If not you will do a stream without video. NOTE: Rotation with encoder is silence ignored in some devices Params _width – resolution in px.
_height – resolution in px.
_fps – frames per second of the stream.
_bitrate – H264 in bps.
_rotation – could be 90, 180, 270 or 0. You should use CameraHelper.getCameraOrientation with SurfaceView or TextureView and 0 with OpenGlView or LightOpenGlView. NOTE: Rotation with encoder is silence ignored in some devices.
Returns: true if success, false if you get a error (Normally because the encoder selected doesn't support any configuration seated or your device hasn't a H264 encoder).

    fun prepareVideo(
        videoWidth: Int,
        videoHeight: Int,
        videoFps: Int,
        videoBitrate: Int,
        videoRotation: Int? = null,
    )

Start stream by url

    fun startStream(url: String) 

Stop stream started with @startStream.

    fun stopStream() 

Get list resolution of back camera

    fun getResolutionsBack(): List<CameraSize>

Get list resolution of front camera

    fun getResolutionsFront(): List<CameraSize>

Mute microphone, can be called before, while and after stream.

    fun disableAudio()

Enable a muted microphone, can be called before, while and after stream.

    fun enableAudio()

Get mute state of microphone.
Returns: true if muted, false if enabled

    fun isAudioMuted(): Boolean?

Switch front and back camera

    fun switchCamera()

Starts recording an MP4 video. Needs to be called while streaming
Params:
_path – Where file will be saved.
Throws: IOException – If initialized before a stream.

    fun startRecord(path: String)

Stop record MP4 video started with @startRecord. If you don't call it file will be unreadable.

    fun stopRecord()

Change preview orientation can be called while stream.
Params:
_orientation – of the camera preview. Could be 90, 180, 270 or 0.

    fun setPreviewOrientation(orientation: Int)




How to Broadcast (Background)?:

    <com.uiza.background.UZBackgroundView
        android:id="@+id/uzBackgroundView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Pls take a look at class BackgroundAdvancedActivity for more information.

Here are some points you need to remember:


Start camera preview. Ignored, if stream or preview is started.

    fun startPreview(
        videoWidth: Int,
        videoHeight: Int,
    )

Stop camera preview. Ignored if streaming or already stopped. You need call it after

    fun stopPreview() 

Strop straming

    fun stopStream()

Start straming

    fun startStream(
        endPoint: String,
        videoWidth: Int,
        videoHeight: Int,
        videoFps: Int,
        videoBitrate: Int,
        audioBitrate: Int,
        audioSampleRate: Int,
        audioIsStereo: Boolean,
        audioEchoCanceler: Boolean,
        audiNoiseSuppressor: Boolean
    )

Get supported preview resolutions of back camera in px Return list of preview resolutions supported by back camera

    fun getResolutionsBack(): List<CameraSize>

Get supported preview resolutions of front camera in px.
Return list of preview resolutions supported by front camera

    fun getResolutionsFront(): List<CameraSize> 

Mute microphone, can be called before, while and after stream.

    fun disableAudio()

Enable a muted microphone, can be called before, while and after stream.

    fun enableAudio()

Get mute state of microphone.

    fun isAudioMuted()

Switch camera used. Can be called anytime
throws CameraOpenException If the other camera doesn't support same resolution.

    fun switchCamera()

Get stream state.
Reeturn true if streaming, false if not streaming.

    fun isStreaming(): Boolean?




How to broadcast your screen?

        <com.uiza.display.UZDisplayView
        android:id="@+id/uzDisplayBroadCast"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

See example in class DisplayAdvancedActivity:

Here are some points you need to remember:


Get stream state.
Returns:
_true if streaming, false if not streaming.

    fun isStreaming(): Boolean

Get record state.
Returns:
_true if recording, false if not recoding.

    fun isRecording(): Boolean

Init stream config by this function

    fun onActivityResult(
        requestCode: Int,
        resultCode: Int,
        data: Intent?,
        endPoint: String,
        videoWidth: Int,
        videoHeight: Int,
        videoFps: Int,
        videoBitrate: Int,
        videoRotation: Int,
        videoDpi: Int,
        audioBitrate: Int,
        audioSampleRate: Int,
        audioIsStereo: Boolean,
        audioEchoCanceler: Boolean,
        audioNoiseSuppressor: Boolean,
    )

Starts recording an MP4 video. Needs to be called while streaming.
Params:
_path – Where file will be saved.
Throws: IOException – If initialized before a stream.

    fun startRecord(path: String, listener: RecordController.Listener?)

Stop record MP4 video started with @startRecord. If you don't call it file will be unreadable.

    fun stopRecord() 

Mute microphone, can be called before, while and after stream.

    fun disableAudio()

Enable a muted microphone, can be called before, while and after stream.

    fun enableAudio()

Get mute state of microphone.
Returns: true if muted, false if enabled

    fun isAudioMuted(): Boolean?




# Real time filters

This library support OpenGL real time filters

AnalogTV

drawing

Android view

drawing

Basic deformation

drawing

Beauty

drawing

Black

drawing

Blur

drawing

Brightness

drawing

Cartoon

drawing

Chroma

drawing

Circle

drawing

Color

drawing

Contrast

drawing

Duotone

drawing

EarlyBird

drawing

Edge detection

drawing

Exposure

drawing

Fire

drawing

Gamma

drawing

Glitch

drawing

Gif

drawing

Grey scale

drawing

Halftone lines

drawing

Images 70s

drawing

Lamoish

drawing

Money

drawing

Negative

drawing

Pixelated

drawing

Polygonization

drawing

Rainbow

drawing

RGB saturate

drawing

Ripple

drawing

Rotation

drawing

Saturation

drawing

Sepia

drawing

Sharpness

drawing

Snow

drawing

Swirl

drawing

Surface filter

drawing

Temperature

drawing

Text

drawing

Zebra

drawing





Features:

  • Android min API 21.
  • Support camera1 and camera2 API
  • Encoder type buffer to buffer.
  • Encoder type surface to buffer.
  • RTMP/RTMPS auth.
  • Audio noise suppressor.
  • Audio echo cancellation.
  • Disable/Enable video and audio while streaming.
  • Switch camera while streaming.
  • Change video bitrate while streaming.
  • Get upload bandwidth used.
  • Record MP4 file while streaming.
  • H264 and AAC hardware encoding.
  • Force H264 and AAC Codec hardware/software encoding (Not recommended).
  • Stream device display.
  • OpenGL real time filters and watermarks. More info




For contributors

Uiza Checkstyle configuration is based on the Google coding conventions from Google Java Style that can be found at here.



Supported devices

Support all devices which have Android 5.0 (API level 21) above. For a given use case, we aim to support UizaSDK on all Android devices that satisfy the minimum version requirement.

Note: Some Android emulators do not properly implement components of Android’s media stack, and as a result do not support UizaSDK. This is an issue with the emulator, not with UizaSDK. Android’s official emulator (“Virtual Devices” in Android Studio) supports UizaSDK provided the system image has an API level of at least 23. System images with earlier API levels do not support UizaSDK. The level of support provided by third party emulators varies. Issues running UizaSDK on third party emulators should be reported to the developer of the emulator rather than to the UizaSDK team. Where possible, we recommend testing media applications on physical devices rather than emulators.





Support

If you've found an error in this sample, please file an issue

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please feel free to contact me anytime: loitp@uiza.io for more details.

Email: loitp@uiza.io Website: uiza.io



License

UizaSDK is released under the BSD license. See LICENSE for details.