public final class CameraStreamingManager
extends java.lang.Object
It is used to set Camera setting, Streaming profile, Layout, View, Listener and Callback. This class is a manager of Streaming, including Audio Streaming, Video Streaming, AV Streaming, which manages the whole Streaming logical.
The calling sequence of the class should be:
CameraStreamingManager(Context, com.pili.pldroid.streaming.widget.AspectFrameLayout, GLSurfaceView, com.pili.pldroid.streaming.CameraStreamingManager.EncodingType)
prepare(com.pili.pldroid.streaming.StreamingProfile)
resume()
startStreaming()
/stopStreaming()
/switchCamera()
/captureFrame(int, int, com.pili.pldroid.streaming.FrameCapturedCallback)
/etc. pause()
destroy()
Modifier and Type | Class and Description |
---|---|
static class |
CameraStreamingManager.EncodingType
EncodingType that can be used.
|
static class |
CameraStreamingManager.STATE
STATE that notified by
CameraStreamingManager . |
static interface |
CameraStreamingManager.StreamingSessionListener
Callback interface for some particular Streaming incidents.
|
static interface |
CameraStreamingManager.StreamingStateListener
Callback interface for Streaming State.
|
Constructor and Description |
---|
CameraStreamingManager(Context ctx)
Standard
CameraStreamingManager constructor. |
CameraStreamingManager(Context ctx,
AspectFrameLayout layout,
GLSurfaceView view)
Constructor for AV streaming.
|
CameraStreamingManager(Context ctx,
AspectFrameLayout layout,
GLSurfaceView view,
CameraStreamingManager.EncodingType encodingType)
Constructor for AV streaming or Video Streaming.
|
CameraStreamingManager(Context ctx,
CameraStreamingManager.EncodingType type)
Constructor for Audio Streaming, without setting View and Layout.
|
Modifier and Type | Method and Description |
---|---|
void |
captureFrame(int width,
int height,
FrameCapturedCallback callback)
Send a capture frame request and
FrameCapturedCallback.onFrameCaptured(Bitmap) will be invoked
after finishing capturing. |
void |
destroy()
Destroy some non-critical resources.
|
void |
doPauseStreaming() |
void |
doResumeStreaming() |
void |
doSingleTapUp(int x,
int y)
Do single tap to trigger the
Camera#autoFocus(Camera.AutoFocusCallback) . |
void |
frameAvailable(int textureId,
SurfaceTexture texture,
boolean needCustomTextTarget) |
int |
getMaxZoom()
Gets the maximum zoom value allowed for preview and streaming.
|
int |
getZoom()
Gets current zoom value.
|
boolean |
isZoomSupported()
Returns true if zoom is supported.
|
void |
mute(boolean enable)
Enable or disable the mute feature.
|
void |
muxerStatusUpdate(EncodingConfig.MUXER_STATE muxerState) |
void |
muxerStatusUpdate(EncodingConfig.MUXER_STATE muxerState,
java.lang.Object extra) |
void |
networkBlocking() |
void |
noNV21PrvFormat() |
void |
notifyActivityOrientationChanged()
Notify Orientation of Activity Changed.
|
void |
notifyFirstEncodingAudioFrame(boolean isMicrophoneOpenFailed) |
void |
notifyFirstEncodingFrame() |
void |
notifyProfileChanged(StreamingProfile profile)
Deprecated.
|
void |
notifyPrvSizeChanged(Camera.Size size) |
void |
onDestroy()
Deprecated.
replaced by
destroy() |
void |
onEncoderExitDone() |
void |
onPause()
Deprecated.
replaced by
pause() |
boolean |
onPrepare(CameraStreamingSetting setting,
StreamingProfile profile)
Deprecated.
|
boolean |
onPrepare(StreamingProfile profile)
Deprecated.
replaced by
prepare(StreamingProfile) |
void |
onPreviewFrame(byte[] bytes,
Camera camera,
long ts) |
void |
onPreviewFrame(byte[] bytes,
long ts) |
Camera.Size |
onPreviewSizeSelected(java.util.List<Camera.Size> list) |
boolean |
onResume()
Deprecated.
replaced by
resume() |
void |
openCameraDeviceFailed(int camId) |
void |
pause()
Pause the
CameraStreamingManager . |
boolean |
prepare(CameraStreamingSetting camSetting,
MicrophoneStreamingSetting microphoneSetting,
StreamingProfile profile) |
boolean |
prepare(CameraStreamingSetting camSetting,
MicrophoneStreamingSetting microphoneSetting,
WatermarkSetting wmSetting,
StreamingProfile profile) |
boolean |
prepare(CameraStreamingSetting setting,
StreamingProfile profile)
|
boolean |
prepare(StreamingProfile profile)
Prepare the
StreamingProfile to CameraStreamingManager ,
only for pure Audio Streaming. |
boolean |
resume()
Resume the
CameraStreamingManager . |
void |
setFocusAreaIndicator(ViewGroup indicatorLayout,
View indicator)
Sets the indicator for focusing UI.
|
void |
setNativeLoggingEnabled(boolean enabled)
Enable or disable the native logs.
|
void |
setStreamingPreviewCallback(StreamingPreviewCallback callback)
Registers a callback to be invoked when a Preview Frame arrives.
|
void |
setStreamingProfile(StreamingProfile profile)
update the
StreamingProfile which associated with CameraStreamingManager . |
void |
setStreamingSessionListener(CameraStreamingManager.StreamingSessionListener listener)
Registers a listener to be notified when the CameraStreamingManager's Session is changed.
|
void |
setStreamingStateListener(CameraStreamingManager.StreamingStateListener listener)
Registers a listener to be notified when the CameraStreamingManager's State is updated.
|
void |
setStreamStatusCallback(StreamStatusCallback callback)
Registers a callback to notify
StreamingProfile.StreamStatus , including audioFps,
videoFps and totalAVBitrate. |
void |
setSurfaceTextureCallback(SurfaceTextureCallback callback)
Registers a callback to handle(filter) the display source to be rendered.
|
void |
setVideoFilterType(com.pili.pldroid.streaming.CameraStreamingSetting.VIDEO_FILTER_TYPE filterType) |
void |
setZoomValue(int value)
Sets current zoom value.
|
boolean |
startStreaming()
Start Streaming.
|
boolean |
stopStreaming()
Stop Streaming.
|
boolean |
switchCamera()
Switch to another camera.
|
boolean |
turnLightOff()
Turn flashlight off.
|
boolean |
turnLightOn()
Turn flashlight on.
|
void |
updateEncodingType(CameraStreamingManager.EncodingType newType)
update the EncodingType.
|
void |
updateFaceBeautySetting(com.pili.pldroid.streaming.CameraStreamingSetting.FaceBeautySetting fbSetting) |
public CameraStreamingManager(Context ctx)
CameraStreamingManager
constructor.
CameraStreamingManager.EncodingType.HW_AUDIO_CODEC
as the default CameraStreamingManager.EncodingType
.
ctx
- the Context of the App.public CameraStreamingManager(Context ctx, CameraStreamingManager.EncodingType type)
Ony CameraStreamingManager.EncodingType.SW_AUDIO_CODEC
and CameraStreamingManager.EncodingType.HW_AUDIO_CODEC
are accept in
this constructor, otherwise, IllegalStateException will be thrown.
ctx
- the Context of the App.type
- the CameraStreamingManager.EncodingType
of the CameraStreamingManager
.public CameraStreamingManager(Context ctx, AspectFrameLayout layout, GLSurfaceView view)
CameraStreamingManager.EncodingType.HW_VIDEO_WITH_HW_AUDIO_CODEC
as the default CameraStreamingManager.EncodingType
.
ctx
- the Context of the App.layout
- the Layout of the rendering viewview
- the View for displaying OpenGL rendering.public CameraStreamingManager(Context ctx, AspectFrameLayout layout, GLSurfaceView view, CameraStreamingManager.EncodingType encodingType)
CameraStreamingManager.EncodingType.HW_VIDEO_WITH_HW_AUDIO_CODEC
as the default CameraStreamingManager.EncodingType
.
ctx
- the Context of the App.layout
- the Layout of the rendering viewview
- the View for displaying OpenGL rendering.encodingType
- the CameraStreamingManager.EncodingType
of the CameraStreamingManager
.public final void setStreamingStateListener(CameraStreamingManager.StreamingStateListener listener)
listener
- the listener to notifypublic final void setStreamingSessionListener(CameraStreamingManager.StreamingSessionListener listener)
listener
- the listener to notifypublic final void setStreamingPreviewCallback(StreamingPreviewCallback callback)
callback
- the callback for NV21 Preview Framepublic final void setSurfaceTextureCallback(SurfaceTextureCallback callback)
callback
- the callback for SurfaceTexturepublic final void setStreamStatusCallback(StreamStatusCallback callback)
StreamingProfile.StreamStatus
, including audioFps,
videoFps and totalAVBitrate.
You should calls this after prepare(CameraStreamingSetting, StreamingProfile)
.
callback
- the callback for StreamStatuspublic final void setVideoFilterType(com.pili.pldroid.streaming.CameraStreamingSetting.VIDEO_FILTER_TYPE filterType)
public final void updateFaceBeautySetting(com.pili.pldroid.streaming.CameraStreamingSetting.FaceBeautySetting fbSetting)
public boolean prepare(StreamingProfile profile)
StreamingProfile
to CameraStreamingManager
,
only for pure Audio Streaming.
Should be called before onResume()
.
profile
- the StreamingProfile
for CameraStreamingManager
.public boolean prepare(CameraStreamingSetting setting, StreamingProfile profile)
CameraStreamingSetting
and StreamingProfile
to CameraStreamingManager
.
Must be called before onResume()
.
setting
- the CameraStreamingSetting
for CameraStreamingManager
.profile
- the StreamingProfile
for CameraStreamingManager
.public boolean prepare(CameraStreamingSetting camSetting, MicrophoneStreamingSetting microphoneSetting, WatermarkSetting wmSetting, StreamingProfile profile)
public boolean prepare(CameraStreamingSetting camSetting, MicrophoneStreamingSetting microphoneSetting, StreamingProfile profile)
public boolean resume()
CameraStreamingManager
.
It should be called after prepare(com.pili.pldroid.streaming.StreamingProfile)
.
In will open the camera asynchronously with video streaming. Some states by
CameraStreamingManager.StreamingStateListener.onStateChanged(int, java.lang.Object)
will be invoked as following:
CameraStreamingManager.STATE.READY
CameraStreamingManager.STATE.NO_SUPPORTED_PREVIEW_SIZE
CameraStreamingManager.STATE.OPEN_CAMERA_FAIL
It is highly recommended the method called in the onResume of Activity.
public void pause()
CameraStreamingManager
.
It should be called when the current Activity or others be PAUSED state.
stopStreaming()
- release camera - release other resources
The background-streaming is the unsupported behavior at present.
public void destroy()
public boolean onPrepare(StreamingProfile profile)
prepare(StreamingProfile)
public boolean onPrepare(CameraStreamingSetting setting, StreamingProfile profile)
prepare(CameraStreamingSetting, StreamingProfile)
public boolean onResume()
resume()
public void onPause()
pause()
public void onDestroy()
destroy()
public boolean startStreaming()
Must be called after getting CameraStreamingManager.STATE.READY
message and in non-ui thread.
The following situations maybe cause the failed start:
CameraStreamingManager.STATE.IOERROR
will be invoked.
public boolean stopStreaming()
It will close the Streaming-Connection and release some resources. And what's more,
CameraStreamingManager.STATE.SHUTDOWN
will be invoked.
The following situations may cause the failed stop:
public boolean turnLightOff()
The following situations will cause the failed invocation:
public boolean turnLightOn()
The following situations will cause the failed invocation:
public boolean switchCamera()
switchCamera()
in AV EncodingType under the CameraStreamingManager.STATE.STREAMING
state. And then, recovery the video streaming after
the request camera been activated as soon as possible.
The following situations will cause the failed invocation:
public void captureFrame(int width, int height, FrameCapturedCallback callback)
FrameCapturedCallback.onFrameCaptured(Bitmap)
will be invoked
after finishing capturing.width
- width of the capturing request in pixels.height
- height of the capturing request in pixels.callback
- the callback for capture frame.public void setNativeLoggingEnabled(boolean enabled)
It is highly recommended that disable the native logs in the release version.
enabled
- true means enable the log;
false means disable the native log.public void notifyProfileChanged(StreamingProfile profile)
setStreamingProfile(com.pili.pldroid.streaming.StreamingProfile)
public void setStreamingProfile(StreamingProfile profile)
StreamingProfile
which associated with CameraStreamingManager
.
profile
- the new StreamingProfile
.java.lang.IllegalArgumentException
- if profile is null.public void updateEncodingType(CameraStreamingManager.EncodingType newType)
newType
- the new EncodingType.java.lang.IllegalArgumentException
- if newType is null or same as current CameraStreamingManager.EncodingType
.public void notifyActivityOrientationChanged()
public void doSingleTapUp(int x, int y)
Camera#autoFocus(Camera.AutoFocusCallback)
.
You should call this after getting CameraStreamingManager.STATE.READY
.
x
- X axis of a motion event.y
- Y axis of a motion event.public void setFocusAreaIndicator(ViewGroup indicatorLayout, View indicator)
You should call this after getting CameraStreamingManager.STATE.READY
.
indicatorLayout
- the layout of the indicatorindicator
- the indicator for Focus UIpublic void setZoomValue(int value)
isZoomSupported()
before using this method.
You should call this after getting CameraStreamingManager.STATE.READY
.
value
- zoom value. The valid range is 0 to getMaxZoom()
.public int getMaxZoom()
setZoomValue(int)
.
Applications should call isZoomSupported()
before using this
method. This value may change in different preview size. Applications
should call this again after setting preview size.
You should call this after getting CameraStreamingManager.STATE.READY
.
public int getZoom()
isZoomSupported()
before
using this method.
You should call this after getting CameraStreamingManager.STATE.READY
.
getMaxZoom()
. 0 means the camera is not zoomed.public boolean isZoomSupported()
You should call this after getting CameraStreamingManager.STATE.READY
.
public void mute(boolean enable)
You should call this after prepare(CameraStreamingSetting, StreamingProfile)
enable
- true means mute; false means unmute.public void onEncoderExitDone()
public void muxerStatusUpdate(EncodingConfig.MUXER_STATE muxerState)
public void muxerStatusUpdate(EncodingConfig.MUXER_STATE muxerState, java.lang.Object extra)
public void networkBlocking()
public void doPauseStreaming()
public void doResumeStreaming()
public void frameAvailable(int textureId, SurfaceTexture texture, boolean needCustomTextTarget)
public void onPreviewFrame(byte[] bytes, Camera camera, long ts)
public void notifyFirstEncodingFrame()
public void notifyFirstEncodingAudioFrame(boolean isMicrophoneOpenFailed)
public void openCameraDeviceFailed(int camId)
public void notifyPrvSizeChanged(Camera.Size size)
public void noNV21PrvFormat()
public Camera.Size onPreviewSizeSelected(java.util.List<Camera.Size> list)
public void onPreviewFrame(byte[] bytes, long ts)