public class Session
extends java.lang.Object
SessionBuilder
.VideoStream
and a AudioStream
together and provides
synchronous and asynchronous functions to start and stop those steams.
You should implement a callback interface Session.Callback
to receive notifications and error reports.RtspClient
.
If you don't use the RTSP protocol, you will still need to send a session description to the receiver
for him to be able to decode your audio/video streams. You can obtain this session description by calling
configure()
or syncConfigure()
to configure the session with its parameters
(audio samplingrate, video resolution) and then getSessionDescription()
.Modifier and Type | Class and Description |
---|---|
static interface |
Session.Callback
The callback interface you need to implement to get some feedback
Those will be called from the UI thread.
|
Modifier and Type | Field and Description |
---|---|
static int |
ERROR_CAMERA_ALREADY_IN_USE
Some app is already using a camera (Camera.open() has failed).
|
static int |
ERROR_CAMERA_HAS_NO_FLASH
The phone has no flash.
|
static int |
ERROR_CONFIGURATION_NOT_SUPPORTED
The phone may not support some streaming parameters that you are trying to use (bit rate, frame rate, resolution...).
|
static int |
ERROR_INVALID_SURFACE
The supplied SurfaceView is not a valid surface, or has not been created yet.
|
static int |
ERROR_OTHER
Some other error occurred !
|
static int |
ERROR_STORAGE_NOT_READY
The internal storage of the phone is not ready.
|
static int |
ERROR_UNKNOWN_HOST
The destination set with
setDestination(String) could not be resolved. |
static int |
STREAM_AUDIO |
static int |
STREAM_VIDEO |
static java.lang.String |
TAG |
Constructor and Description |
---|
Session()
Creates a streaming session that can be customized by adding tracks.
|
Modifier and Type | Method and Description |
---|---|
void |
configure()
Configures all streams of the session.
|
AudioStream |
getAudioTrack()
Returns the underlying
AudioStream used by the Session . |
long |
getBitrate()
Returns an approximation of the bandwidth consumed by the session in bit per second.
|
Session.Callback |
getCallback()
Returns the
Session.Callback interface that was set with
setCallback(Callback) or null if none was set. |
int |
getCamera()
Returns the id of the camera currently selected.
|
java.lang.String |
getDestination()
Returns the destination set with
setDestination(String) . |
java.lang.String |
getSessionDescription()
Returns a Session Description that can be stored in a file or sent to a client with RTSP.
|
Stream |
getTrack(int id) |
VideoStream |
getVideoTrack()
Returns the underlying
VideoStream used by the Session . |
boolean |
isStreaming()
Indicates if a track is currently running.
|
void |
release()
Deletes all existing tracks & release associated resources.
|
void |
setAudioQuality(AudioQuality quality)
Sets the configuration of the stream.
|
void |
setCallback(Session.Callback callback)
Sets the callback interface that will be called by the
Session . |
void |
setDestination(java.lang.String destination)
The destination address for all the streams of the session.
|
void |
setOrigin(java.lang.String origin)
The origin address of the session.
|
void |
setPreviewOrientation(int orientation)
Sets the orientation of the preview.
|
void |
setSurfaceView(SurfaceView view)
Sets a Surface to show a preview of recorded media (video).
|
void |
setTimeToLive(int ttl)
Set the TTL of all packets sent during the session.
|
void |
setVideoQuality(VideoQuality quality)
Sets the configuration of the stream.
|
void |
start()
Asynchronously starts all streams of the session.
|
void |
startPreview()
Asynchronously starts the camera preview.
|
void |
stop()
Stops all existing streams.
|
void |
stopPreview()
Asynchronously stops the camera preview.
|
void |
switchCamera()
Switch between the front facing and the back facing camera of the phone.
|
void |
syncConfigure()
Does the same thing as
configure() , but in a synchronous manner. |
void |
syncStart()
Does the same thing as
start() , but in a synchronous manner. |
void |
syncStart(int id)
Starts a stream in a synchronous manner.
|
void |
syncStop()
Stops all existing streams in a synchronous manner.
|
void |
toggleFlash()
Toggles the LED of the phone if it has one.
|
boolean |
trackExists(int id) |
public static final java.lang.String TAG
public static final int STREAM_VIDEO
public static final int STREAM_AUDIO
public static final int ERROR_CAMERA_ALREADY_IN_USE
public static final int ERROR_CONFIGURATION_NOT_SUPPORTED
public static final int ERROR_STORAGE_NOT_READY
public static final int ERROR_CAMERA_HAS_NO_FLASH
public static final int ERROR_INVALID_SURFACE
public static final int ERROR_UNKNOWN_HOST
setDestination(String)
could not be resolved.
May mean that the phone has no access to the internet, or that the DNS server could not
resolved the host name.public static final int ERROR_OTHER
public Session()
public AudioStream getAudioTrack()
AudioStream
used by the Session
.public VideoStream getVideoTrack()
VideoStream
used by the Session
.public void setCallback(Session.Callback callback)
Session
.callback
- The implementation of the Session.Callback
interfacepublic void setOrigin(java.lang.String origin)
origin
- The origin addresspublic void setDestination(java.lang.String destination)
destination
- The destination addresspublic void setTimeToLive(int ttl)
ttl
- The Time To Livepublic void setVideoQuality(VideoQuality quality)
configure()
.quality
- Quality of the streampublic void setSurfaceView(SurfaceView view)
start()
or startPreview()
.public void setPreviewOrientation(int orientation)
configure()
.orientation
- The orientation of the previewpublic void setAudioQuality(AudioQuality quality)
configure()
.quality
- Quality of the streampublic Session.Callback getCallback()
Session.Callback
interface that was set with
setCallback(Callback)
or null if none was set.public java.lang.String getSessionDescription()
java.lang.IllegalStateException
- Thrown when setDestination(String)
has never been called.public java.lang.String getDestination()
setDestination(String)
.public long getBitrate()
public boolean isStreaming()
public void configure()
public void syncConfigure() throws CameraInUseException, StorageUnavailableException, ConfNotSupportedException, InvalidSurfaceException, java.lang.RuntimeException, java.io.IOException
configure()
, but in a synchronous manner. Session.Callback.onSessionError(int, int, Exception)
when
an error occurs.CameraInUseException
StorageUnavailableException
ConfNotSupportedException
InvalidSurfaceException
java.lang.RuntimeException
java.io.IOException
public void start()
public void syncStart(int id) throws CameraInUseException, StorageUnavailableException, ConfNotSupportedException, InvalidSurfaceException, java.net.UnknownHostException, java.io.IOException
id
- The id of the stream to startCameraInUseException
StorageUnavailableException
ConfNotSupportedException
InvalidSurfaceException
java.net.UnknownHostException
java.io.IOException
public void syncStart() throws CameraInUseException, StorageUnavailableException, ConfNotSupportedException, InvalidSurfaceException, java.net.UnknownHostException, java.io.IOException
start()
, but in a synchronous manner. CameraInUseException
StorageUnavailableException
ConfNotSupportedException
InvalidSurfaceException
java.net.UnknownHostException
java.io.IOException
public void stop()
public void syncStop()
public void startPreview()
SurfaceView
to setSurfaceView(SurfaceView)
before calling this method. Otherwise, the Session.Callback.onSessionError(int, int, Exception)
callback will be called with ERROR_INVALID_SURFACE
.public void stopPreview()
public void switchCamera()
startPreview()
has been called, the preview will be briefly interrupted. start()
has been called, the stream will be briefly interrupted.getCamera()
public int getCamera()
CameraInfo#CAMERA_FACING_BACK
or
CameraInfo#CAMERA_FACING_FRONT
.public void toggleFlash()
getVideoTrack()
and VideoStream.getFlashState()
.public void release()
public boolean trackExists(int id)
public Stream getTrack(int id)