B4A Library libStreaming v1.3

This is a wrap for this github project. Especially the Client part (Stream the camera to a streamingserver)

Streaming
Author:
DonManfred (wrapper)
Version: 1.3
  • AudioQuality
    Methods:
    • Initialize (samplingRate As Int, bitRate As Int)
      Represents a quality for an audio stream.
      samplingRate: The sampling rate
      bitRate: The bitrate in bit per seconds
    • IsInitialized As Boolean
  • RtspClient
    Methods:
    • Initialize (EventName As String)
    • IsInitialized As Boolean
    • isStreaming As Boolean
    • release
    • setCredentials (username As String, password As String) As RtspClientWrapper
      If authentication is enabled on the server, you need to call this with a valid login/password pair.
      Only implements Digest Access Authentication according to RFC 2069.
      username: The login
      password: The password
    • setServerAddress (host As String, port As Int) As RtspClientWrapper
      Sets the destination address of the RTSP server.
      host: The destination address
      port: The destination port
    • setSession (session As Session) As RtspClientWrapper
      The {@link Session} that will be used to stream to the server.
      If not called before {@link #startStream()}, a it will be created.
      Return type: @return:
    • setStreamPath (path As String) As RtspClientWrapper
      The path to which the stream will be sent to.
      path: The path
    • setTransportMode (mode As Int) As RtspClientWrapper
      Call this with {@link #TRANSPORT_TCP} or {@value #TRANSPORT_UDP} to choose the
      transport protocol that will be used to send RTP/RTCP packets.
      Not ready yet !
    • startStream
      Connects to the RTSP server to publish the stream, and the effectively starts streaming.
      You need to call {@link #setServerAddress(String, int)} and optionally {@link #setSession(Session)}
      and {@link #setCredentials(String, String)} before calling this.
      Should be called of the main thread !
    • stopStream
      Stops the stream, and informs the RTSP server.
    Properties:
    • Session As Session [read only]
  • SessionBuilder
    Events:
    • onBitrateUpdate (bitrate As Long)
    • onPreviewStarted ( As )
    • onSessionStarted ( As )
    • onSessionStopped ( As )
    • onSessionconfigured ( As )
    • onSesstionError (reason As Int, StreamType As Int, message As String, info As String)
    Methods:
    • Initialize (EventName As String) As SessionBuilderWrapper
    • IsInitialized As Boolean
    • build As Session
      Creates a new {@link Session}.
      Return type: @return:The new Session
    • clone As SessionBuilder
      Returns a new {@link SessionBuilder} with the same configuration.
    • setAudioEncoder (encoder As Int) As SessionBuilderWrapper
      Sets the audio encoder.
    • setAudioQuality (quality As AudioQuality) As SessionBuilderWrapper
      Sets the audio quality.
    • setCamera (camera As Int) As SessionBuilderWrapper
    • setDestination (destination As String) As SessionBuilderWrapper
      Sets the destination of the session.
    • setFlashEnabled (enabled As Boolean) As SessionBuilderWrapper
    • setOrigin (origin As String) As SessionBuilderWrapper
      Sets the origin of the session. It appears in the SDP of the session.
    • setPreviewOrientation (orientation As Int) As SessionBuilderWrapper
      Sets the orientation of the preview.
      orientation: The orientation of the preview
    • setSurfaceView (surfaceView As SurfaceView) As SessionBuilderWrapper
      Sets the SurfaceView required to preview the video stream.
    • setTimeToLive (ttl As Int) As SessionBuilderWrapper
    • setVideoEncoder (encoder As Int) As SessionBuilderWrapper
      Sets the default video encoder.
    • setVideoQuality (quality As VideoQuality) As SessionBuilderWrapper
      Sets the video stream quality.
    Properties:
    • AudioEncoder As Int [read only]
      Returns the audio encoder set with {@link #setAudioEncoder(int)}.
    • AudioQuality As AudioQuality [read only]
      Returns the AudioQuality set with {@link #setAudioQuality(AudioQuality)}.
    • Camera As Int [read only]
      Returns the id of the {@link android.hardware.Camera} set with {@link #setCamera(int)}.
    • Context As Context [read only]
      Returns the context set with {@link #setContext(Context)}
    • Destination As String [read only]
      Returns the destination ip address set with {@link #setDestination(String)}.
    • FlashState As Boolean [read only]
      Returns the flash state set with {@link #setFlashEnabled(boolean)}.
    • Origin As String [read only]
      Returns the origin ip address set with {@link #setOrigin(String)}.
    • SurfaceView As SurfaceView [read only]
      Returns the SurfaceView set with {@link #setSurfaceView(SurfaceView)}.
    • TimeToLive As Int [read only]
      Returns the time to live set with {@link #setTimeToLive(int)}.
    • VideoEncoder As Int [read only]
      Returns the video encoder set with {@link #setVideoEncoder(int)}.
    • VideoQuality As VideoQuality [read only]
      Returns the VideoQuality set with {@link #setVideoQuality(VideoQuality)}.
  • SurfaceView
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • addMediaCodecSurface (surface As Surface)
    • removeMediaCodecSurface
    • requestAspectRatio (aspectRatio As Double)
      Requests a certain aspect ratio for the preview. You don't have to call this yourself,
      the {@link VideoStream} will do it when it's needed.
    • run
    • startGLThread
    Properties:
    • AspectRatioMode As Int [write only]
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Parent As Object [read only]
    • SurfaceTexture As SurfaceTexture [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
  • VideoQuality
    Methods:
    • Initialize (resX As Int, resY As Int, framerate As Int, bitrate As Int)
      Represents a quality for a video stream.
      resX: The horizontal resolution
      resY: The vertical resolution
      framerate: The framerate in frame per seconds
      bitrate: The bitrate in bit per seconds
    • IsInitialized As Boolean

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim sBuilder As SessionBuilder
    Private Surface As SurfaceView
    Dim client As RtspClient
    Private btnStart As Button
    Private btnStop As Button
    Dim AQuality As AudioQuality
    Dim VQuality As VideoQuality
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    'session.Initialize("").
    AQuality.Initialize(16000,32000)
    VQuality.Initialize(176,144,20,500000)

    sBuilder.Initialize("rtsp").setOrigin("/videochat").setSurfaceView(Surface).setCamera(1).setTimeToLive(64).setDestination("ipofstreamingserver").setVideoEncoder(1).setVideoQuality(VQuality).setPreviewOrientation(90)    .setAudioEncoder(3)



    client.Initialize("rtspclient")
    client.setSession(sBuilder.build).setServerAddress("ipadress",1900).setStreamPath("/videochat/test") '.setCredentials("username","password")


End Sub

This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate (You can donate any amount you want to donate for the library (or my work building the wrapper)) :)
 

Attachments

  • libStreamingV1.3.0.zip
    139.9 KB · Views: 836
  • StreamingEx.zip
    8.4 KB · Views: 810
  • java_srcv1.3.zip
    112.8 KB · Views: 679
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Can you share the way you do to test the library , any online free streaming server or any pc software ?
Sorry, i can´t really help on this. I just wrote the wrap and was using the wowza server from a tester to test it.

https://www.wowza.com/products/streaming-engine

the wowza streaming-engine server for example is a windows software to download. I never configured a wowza server.
 

Leni Berry

Active Member
Licensed User
Longtime User
how to get this awesome library?

(i'm sorry i didnt look at the first post...)
 
Last edited:

Leni Berry

Active Member
Licensed User
Longtime User
the library is working well... but only video show... the audio off... how to enable the audio?
 

DonManfred

Expert
Licensed User
Longtime User
how to enable the audio?
set the audioencode to 3 or 5... (See Example-Code in post #1)
/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_NONE = 0;
/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_AMRNB = 3;
/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_AAC = 5
;
 

Leni Berry

Active Member
Licensed User
Longtime User
Dear Expert,

How to know another parameters value not just int 1 for setVideoEncoder?

thx
 

DonManfred

Expert
Licensed User
Longtime User
How to know another parameters value not just int 1 for setVideoEncoder?
You can use any static names for them...

B4X:
/** Can be used with {@link #setVideoEncoder}. */
    public final static int VIDEO_NONE = 0;

    /** Can be used with {@link #setVideoEncoder}. */
    public final static int VIDEO_H264 = 1;

    /** Can be used with {@link #setVideoEncoder}. */
    public final static int VIDEO_H263 = 2;

B4X:
dim VIDEO_NONE as int = 0
dim VIDEO_H264  as int = 1
dim  VIDEO_H263 as int = 2
 

Leni Berry

Active Member
Licensed User
Longtime User
You can use any static names for them...

B4X:
/** Can be used with {@link #setVideoEncoder}. */
    public final static int VIDEO_NONE = 0;

    /** Can be used with {@link #setVideoEncoder}. */
    public final static int VIDEO_H264 = 1;

    /** Can be used with {@link #setVideoEncoder}. */
    public final static int VIDEO_H263 = 2;

B4X:
dim VIDEO_NONE as int = 0
dim VIDEO_H264  as int = 1
dim  VIDEO_H263 as int = 2

thank you very much Manfred.... i'll try...
 

Descartex

Well-Known Member
Licensed User
Longtime User
Hi.
Is any way to stream audio only like the official Wowza app do???
I need to stream audio only, no video needed.
Thanks a lot in advance.
 

DonManfred

Expert
Licensed User
Longtime User
Is any way to stream audio only like the official Wowza app do?
Did you tried all variants of

setAudioEncoder (encoder As Int) As SessionBuilderWrapper
Sets the audio encoder.

One of the AudioEncode is NONE i guess... Did not use the lib a long time

Edit:

/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_NONE = 0;

/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_AMRNB = 3;

/** Can be used with {@link #setAudioEncoder}. */
public final static int AUDIO_AAC = 5;
 

Descartex

Well-Known Member
Licensed User
Longtime User
Yes, but i need to disable video, not audio...
 

RobertoBmb

Member
Licensed User
Hi Don, i have a problem with your wrap.
When i connect to my RTSP server, it writes this messages:

2020/04/17 17:38:58 [RTSP client 192.168.8.100:40380] connected
2020/04/17 17:38:58 [RTSP client 192.168.8.100:40380] ANNOUNCE
2020/04/17 17:38:58 [RTSP client 192.168.8.100:40380] SETUP
2020/04/17 17:38:58 [RTSP client 192.168.8.100:40380] ERR: transport header does not contain mode=record
2020/04/17 17:38:58 [RTSP client 192.168.8.100:40380] disconnected

How can i set the trasport header with mode=record ?

Thank you!
Roberto
 

moster67

Expert
Licensed User
Longtime User
I think the original libStreaming project on GitHub was discontinued quite some time ago.
For your information, I will be releasing a library shortly which supports initially only RTMP but I will probably add RTSP to it as well.
When released, I will announce it here in the forum.
 
Top