Working single stream in fixed-size tile
This commit is contained in:
parent
59a7fed77a
commit
876ab519e9
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
Ojo
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
@ -7,7 +7,8 @@
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -3,4 +3,17 @@ package it.danieleverducci.ojo.entities;
|
||||
public class Camera {
|
||||
private String name;
|
||||
private String rtspUrl;
|
||||
|
||||
public Camera(String name, String rtspUrl) {
|
||||
this.name = name;
|
||||
this.rtspUrl = rtspUrl;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRtspUrl() {
|
||||
return rtspUrl;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
package it.danieleverducci.ojo.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@ -20,12 +25,16 @@ import org.videolan.libvlc.MediaPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import it.danieleverducci.ojo.R;
|
||||
import it.danieleverducci.ojo.databinding.FragmentSurveillanceBinding;
|
||||
import it.danieleverducci.ojo.entities.Camera;
|
||||
|
||||
public class SurveillanceFragment extends Fragment implements MediaPlayer.EventListener, IVLCVout.Callback {
|
||||
|
||||
private FragmentSurveillanceBinding binding;
|
||||
|
||||
private CameraView cameraView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container,
|
||||
@ -49,22 +58,9 @@ public class SurveillanceFragment extends Fragment implements MediaPlayer.EventL
|
||||
// });
|
||||
|
||||
// Start stream on surface view 1
|
||||
SurfaceView mSurface = binding.surfaceView1;
|
||||
SurfaceHolder holder = mSurface.getHolder();
|
||||
|
||||
// Obtain surfaceview size
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
|
||||
ViewGroup.LayoutParams videoParams = mSurface.getLayoutParams();
|
||||
videoParams.width = displayMetrics.widthPixels;
|
||||
videoParams.height = displayMetrics.heightPixels;
|
||||
|
||||
|
||||
// media player
|
||||
MediaPlayer mMediaPlayer = null;
|
||||
|
||||
String rtspUrl = "rtsp://admin:Du4gdtPmXGCWT29@192.168.1.200:554/Streaming/Channels/101";
|
||||
Camera camera = new Camera("Camera 1", rtspUrl);
|
||||
|
||||
ArrayList<String> options = new ArrayList<String>();
|
||||
options.add("--aout=opensles");
|
||||
@ -75,28 +71,30 @@ public class SurveillanceFragment extends Fragment implements MediaPlayer.EventL
|
||||
options.add("--file-logging");
|
||||
options.add("--logfile=vlc-log.txt");
|
||||
|
||||
|
||||
LibVLC libvlc = new LibVLC(getContext(), options);
|
||||
holder.setKeepScreenOn(true);
|
||||
|
||||
// Create media player
|
||||
mMediaPlayer = new MediaPlayer(libvlc);
|
||||
mMediaPlayer.setEventListener(this);
|
||||
cameraView = new CameraView(
|
||||
getContext(),
|
||||
libvlc,
|
||||
camera,
|
||||
this
|
||||
);
|
||||
|
||||
// Set up video output
|
||||
final IVLCVout vout = mMediaPlayer.getVLCVout();
|
||||
vout.setVideoView(mSurface);
|
||||
vout.setWindowSize(videoParams.width,videoParams.height);
|
||||
vout.addCallback(this);
|
||||
vout.attachViews();
|
||||
// Add to layout
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1000, 500);
|
||||
binding.gridRowContainer.addView(cameraView.surfaceView, params);
|
||||
|
||||
Media m = new Media(libvlc, Uri.parse(rtspUrl));
|
||||
|
||||
mMediaPlayer.setMedia(m);
|
||||
mMediaPlayer.play();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
cameraView.startPlayback();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
@ -124,4 +122,55 @@ public class SurveillanceFragment extends Fragment implements MediaPlayer.EventL
|
||||
public void onSurfacesDestroyed(IVLCVout vlcVout) {
|
||||
|
||||
}
|
||||
|
||||
private void addCameraView(Camera camera) {
|
||||
|
||||
}
|
||||
|
||||
private class CameraView {
|
||||
protected SurfaceView surfaceView;
|
||||
protected MediaPlayer mediaPlayer;
|
||||
protected IVLCVout ivlcVout;
|
||||
protected Camera camera;
|
||||
protected LibVLC libvlc;
|
||||
|
||||
public CameraView(Context context, LibVLC libvlc, Camera camera, IVLCVout.Callback callback) {
|
||||
this.camera = camera;
|
||||
this.libvlc = libvlc;
|
||||
|
||||
surfaceView = new SurfaceView(context);
|
||||
SurfaceHolder holder = surfaceView.getHolder();
|
||||
|
||||
holder.setKeepScreenOn(true);
|
||||
|
||||
// Create media player
|
||||
mediaPlayer = new MediaPlayer(libvlc);
|
||||
// mediaPlayer.setEventListener(this);
|
||||
|
||||
// Set up video output
|
||||
ivlcVout = mediaPlayer.getVLCVout();
|
||||
ivlcVout.setVideoView(surfaceView);
|
||||
ivlcVout.addCallback(callback);
|
||||
ivlcVout.attachViews();
|
||||
|
||||
// Load media and start playing
|
||||
Media m = new Media(libvlc, Uri.parse(camera.getRtspUrl()));
|
||||
mediaPlayer.setMedia(m);
|
||||
|
||||
// Register for view resize events
|
||||
final ViewTreeObserver observer= surfaceView.getViewTreeObserver();
|
||||
observer.addOnGlobalLayoutListener(() -> {
|
||||
// Set rendering size
|
||||
ivlcVout.setWindowSize(surfaceView.getWidth(), surfaceView.getHeight());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the playback.
|
||||
* This must be called after the view has been laid out
|
||||
*/
|
||||
public void startPlayback() {
|
||||
mediaPlayer.play();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user