Package buzz.getcoco.media
Class CameraStreamHandler
- java.lang.Object
-
- buzz.getcoco.media.DefaultStreamHandler
-
- buzz.getcoco.media.CameraStreamHandler
-
- All Implemented Interfaces:
MediaSession.StreamHandler
public class CameraStreamHandler extends DefaultStreamHandler
A managed camera2MediaSession.StreamHandler
usingMediaCodec
for encoding theCamera
stream to h264 frames and uploading toMediaSession.MediaSink
. A Typical use case would look like:session .addStream(new MediaSession.CameraStreamBuilder(CHANNEL_NAME, MediaSession.VideoQuality.HD, CameraSelector.DEFAULT_FRONT_CAMERA)) .observe(this, videoHandler -> { if (null == videoHandler) { Log.w(TAG, "onCreate: unable to start the stream"); return; } videoHandler.start(); videoHandler.bindToLifecycle(this, this); binding.cameraDisable.setOnClickListener(v -> videoHandler.stop()); });
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CameraStreamHandler.Builder
A builder forCameraStreamHandler
.static class
CameraStreamHandler.VideoQuality
Determines the quality of video that will be uploaded.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bindToLifecycle(android.content.Context context, androidx.lifecycle.LifecycleOwner lifecycleOwner, androidx.camera.view.PreviewView previewView)
Respects the lifecycle and starts sending the stream data along with preview.boolean
shouldClosePreviousStream(MediaSession.StreamHandler handler)
Determine if the handler should be closed.void
start()
void
stop()
java.lang.String
toString()
-
Methods inherited from class buzz.getcoco.media.DefaultStreamHandler
onDataAvailable, onSinkUpdated
-
-
-
-
Method Detail
-
start
public void start()
- Specified by:
start
in interfaceMediaSession.StreamHandler
- Overrides:
start
in classDefaultStreamHandler
-
stop
public void stop()
- Specified by:
stop
in interfaceMediaSession.StreamHandler
- Overrides:
stop
in classDefaultStreamHandler
-
bindToLifecycle
public void bindToLifecycle(@NonNull android.content.Context context, @NonNull androidx.lifecycle.LifecycleOwner lifecycleOwner, @Nullable androidx.camera.view.PreviewView previewView)
Respects the lifecycle and starts sending the stream data along with preview.- Parameters:
context
- The context which will be used to bind.lifecycleOwner
- The lifecycle which everything will bound to.previewView
- The view which will be used for preview.
-
shouldClosePreviousStream
public boolean shouldClosePreviousStream(MediaSession.StreamHandler handler)
Description copied from interface:MediaSession.StreamHandler
Determine if the handler should be closed.- Parameters:
handler
- The other stream in the same channel as this- Returns:
- true if it has to be
MediaSession.StreamHandler.stop()
ed
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-