0

I am trying to transmit the Android camera image via rtsp to Wowza, however without success. It does not return any error, but also in the local Wowza does not show any traffic. I have the local Wowza for testing in http://localhost:8088/ I am using the Libstreaming library to send the rtsp stream.

MainActivity.java

package com.security.testeslibstreaming;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.Window;
import android.view.WindowManager;
import net.majorkernelpanic.streaming.Session;
import net.majorkernelpanic.streaming.SessionBuilder;
import net.majorkernelpanic.streaming.audio.AudioQuality;
import net.majorkernelpanic.streaming.gl.SurfaceView;
import net.majorkernelpanic.streaming.rtsp.RtspClient;

public class MainActivity extends AppCompatActivity implements RtspClient.Callback, Session.Callback, SurfaceHolder.Callback {

    // log tag
    public final static String TAG = MainActivity.class.getSimpleName();

    // surfaceview
    private static SurfaceView mSurfaceView;

    // Rtsp session
    private Session mSession;
    private static RtspClient mClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_main);

        mSurfaceView = (SurfaceView) findViewById(R.id.surface);

        mSurfaceView.getHolder().addCallback(this);

        // Initialize RTSP client
        initRtspClient();

    }

    @Override
    protected void onResume() {
        super.onResume();

        toggleStreaming();
    }

    @Override
    protected void onPause(){
        super.onPause();

        toggleStreaming();
    }

    private void initRtspClient() {
        // Configures the SessionBuilder
        mSession = SessionBuilder.getInstance()
                .setContext(getApplicationContext())
                .setAudioEncoder(SessionBuilder.AUDIO_NONE)
                .setAudioQuality(new AudioQuality(8000, 16000))
                .setVideoEncoder(SessionBuilder.VIDEO_H264)
                .setSurfaceView(mSurfaceView).setPreviewOrientation(0)
                .setCallback(this).build();

        // Configures the RTSP client
        mClient = new RtspClient();
        mClient.setSession(mSession);
        mClient.setCallback(this);
        mSurfaceView.setAspectRatioMode(SurfaceView.ASPECT_RATIO_PREVIEW);
        String ip, port, path;

        // We parse the URI written in the Editext
        Pattern uri = Pattern.compile("rtsp://(.+):(\\d+)/(.+)");
        Matcher m = uri.matcher(AppConfig.STREAM_URL);
        m.find();
        ip = m.group(1);
        port = m.group(2);
        path = m.group(3);

        mClient.setCredentials(AppConfig.PUBLISHER_USERNAME,
                AppConfig.PUBLISHER_PASSWORD);
        mClient.setServerAddress(ip, Integer.parseInt(port));
        mClient.setStreamPath("/" + path);
    }

    private void toggleStreaming() {
        if (!mClient.isStreaming()) {
            // Start camera preview
            mSession.startPreview();

            // Start video stream
            mClient.startStream();
        } else {
            // already streaming, stop streaming
            // stop camera preview
            mSession.stopPreview();

            // stop streaming
            mClient.stopStream();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mClient.release();
        mSession.release();
        mSurfaceView.getHolder().removeCallback(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onSessionError(int reason, int streamType, Exception e) {
        switch (reason) {
            case Session.ERROR_CAMERA_ALREADY_IN_USE:
                break;
            case Session.ERROR_CAMERA_HAS_NO_FLASH:
                break;
            case Session.ERROR_INVALID_SURFACE:
                break;
            case Session.ERROR_STORAGE_NOT_READY:
                break;
            case Session.ERROR_CONFIGURATION_NOT_SUPPORTED:
                break;
            case Session.ERROR_OTHER:
                break;
        }

        if (e != null) {
            alertError(e.getMessage());
            e.printStackTrace();
        }
    }

    private void alertError(final String msg) {
        final String error = (msg == null) ? "Unknown error: " : msg;
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setMessage(error).setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    @Override
    public void onRtspUpdate(int message, Exception exception) {
        switch (message) {
            case RtspClient.ERROR_CONNECTION_FAILED:
            case RtspClient.ERROR_WRONG_CREDENTIALS:
                alertError(exception.getMessage());
                exception.printStackTrace();
                break;
        }
    }

    @Override
    public void onPreviewStarted() {
    }

    @Override
    public void onSessionConfigured() {
    }

    @Override
    public void onSessionStarted() {
    }

    @Override
    public void onSessionStopped() {
    }

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
    }

    @Override
    public void onBitrateUpdate(long bitrate) {

    }
}

AppConfig.java

package com.security.testeslibstreaming;

public class AppConfig {

    public static final String STREAM_URL = "rtsp://192.XXX.XX.XX:1935/live/myStream";
    public static final String PUBLISHER_USERNAME = "barrXXXXXXX";
    public static final String PUBLISHER_PASSWORD = "XXXXXXXXXX";

}
  • Did you test the `rtsp url` in VLC media player ? Enable logging in VLC to see if it's able to pull packets – Aak Feb 28 '21 at 15:26
  • Now that you said that, I tried to send the stream of some video to rtsp://192.xxx.x.x:1935/live using vlc media player, but without success. The local wowza gets no traffic. Any tips? – Barraviera Mar 01 '21 at 01:02
  • I did not quite understand your use-case. It seems that you are generating a RTSP stream through your code and then you want to send this stream to Wowza. Did you register the generated stream url in wowza as a stream file ? You should then connect to the stream file and see if Wowza is able to pull packets. – Aak Mar 01 '21 at 02:07
  • Yes, I am generating an rtsp stream from the android camera and need to display the image in a web browser. To capture the rtsp stream I am using Wowza locally, but it does not capture any traffic. Yes, I registered the generated url in a stream file, but still the local Wowza does not capture any traffic. rtsp://192.xxx.xx.xx:1935/live – Barraviera Mar 01 '21 at 17:08
  • When you connect to the stream file and then go to `incoming streams` tab, what is the status of your stream? Is it `Active` or `Waiting for stream` ? – Aak Mar 02 '21 at 02:58
  • Waiting for Stream – Barraviera Mar 02 '21 at 16:20
  • It means that the RTSP stream that you are generating itself isn't working. – Aak Mar 02 '21 at 16:45
  • Can you tell me if by VLC media player I can send an rstp stream to Wowza to test? For I think the problem is in Wowza Local. – Barraviera Mar 03 '21 at 17:09
  • For testing I was able to stream from OBS Studio to Wowza using RTMP protocol, but with RSTP it doesn't work, nothing streams into Wowza. – Barraviera Mar 03 '21 at 23:55
  • How can I send RTMP stream from android APP instead of RTSP? – Barraviera Mar 04 '21 at 00:25
  • I am not familiar with how to generate RTSP/RTMP from Android camera. You can search on the site for related questions. I found this - https://stackoverflow.com/questions/2550847/streaming-video-from-android-camera-to-server – Aak Mar 04 '21 at 06:19
  • 1
    Thank you. I ended up finding the Yasea library, I think it will be useful. If anyone needs it, follow the link: https://github.com/begeekmyfriend/yasea – Barraviera Mar 05 '21 at 15:14
  • What is the use-case for your project once the streams are coming into Wowza, Do you want to generate HLS playback from these streams ? – Aak Mar 05 '21 at 15:30
  • Yes, that's right. Display in a browser. – Barraviera Mar 05 '21 at 18:17
  • If latency is important to you then you should choose WebRTC playback otherwise use HLS – Aak Mar 06 '21 at 02:39

0 Answers0