Search in sources :

Example 1 with InvalidSurfaceException

use of net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException in project libstreaming by fyhertz.

the class Session method syncStart.

/** 
	 * Starts a stream in a synchronous manner. <br />
	 * Throws exceptions in addition to calling a callback.
	 * @param id The id of the stream to start
	 **/
public void syncStart(int id) throws CameraInUseException, StorageUnavailableException, ConfNotSupportedException, InvalidSurfaceException, UnknownHostException, IOException {
    Stream stream = id == 0 ? mAudioStream : mVideoStream;
    if (stream != null && !stream.isStreaming()) {
        try {
            InetAddress destination = InetAddress.getByName(mDestination);
            stream.setTimeToLive(mTimeToLive);
            stream.setDestinationAddress(destination);
            stream.start();
            if (getTrack(1 - id) == null || getTrack(1 - id).isStreaming()) {
                postSessionStarted();
            }
            if (getTrack(1 - id) == null || !getTrack(1 - id).isStreaming()) {
                mHandler.post(mUpdateBitrate);
            }
        } catch (UnknownHostException e) {
            postError(ERROR_UNKNOWN_HOST, id, e);
            throw e;
        } catch (CameraInUseException e) {
            postError(ERROR_CAMERA_ALREADY_IN_USE, id, e);
            throw e;
        } catch (StorageUnavailableException e) {
            postError(ERROR_STORAGE_NOT_READY, id, e);
            throw e;
        } catch (ConfNotSupportedException e) {
            postError(ERROR_CONFIGURATION_NOT_SUPPORTED, id, e);
            throw e;
        } catch (InvalidSurfaceException e) {
            postError(ERROR_INVALID_SURFACE, id, e);
            throw e;
        } catch (IOException e) {
            postError(ERROR_OTHER, id, e);
            throw e;
        } catch (RuntimeException e) {
            postError(ERROR_OTHER, id, e);
            throw e;
        }
    }
}
Also used : CameraInUseException(net.majorkernelpanic.streaming.exceptions.CameraInUseException) ConfNotSupportedException(net.majorkernelpanic.streaming.exceptions.ConfNotSupportedException) UnknownHostException(java.net.UnknownHostException) StorageUnavailableException(net.majorkernelpanic.streaming.exceptions.StorageUnavailableException) AudioStream(net.majorkernelpanic.streaming.audio.AudioStream) VideoStream(net.majorkernelpanic.streaming.video.VideoStream) IOException(java.io.IOException) InetAddress(java.net.InetAddress) InvalidSurfaceException(net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException)

Example 2 with InvalidSurfaceException

use of net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException in project libstreaming by fyhertz.

the class VideoStream method createCamera.

protected synchronized void createCamera() throws RuntimeException {
    if (mSurfaceView == null)
        throw new InvalidSurfaceException("Invalid surface !");
    if (mSurfaceView.getHolder() == null || !mSurfaceReady)
        throw new InvalidSurfaceException("Invalid surface !");
    if (mCamera == null) {
        openCamera();
        mUpdated = false;
        mUnlocked = false;
        mCamera.setErrorCallback(new Camera.ErrorCallback() {

            @Override
            public void onError(int error, Camera camera) {
                // Whether or not this callback may be called really depends on the phone
                if (error == Camera.CAMERA_ERROR_SERVER_DIED) {
                    // In this case the application must release the camera and instantiate a new one
                    Log.e(TAG, "Media server died !");
                    // We don't know in what thread we are so stop needs to be synchronized
                    mCameraOpenedManually = false;
                    stop();
                } else {
                    Log.e(TAG, "Error unknown with the camera: " + error);
                }
            }
        });
        try {
            // If the phone has a flash, we turn it on/off according to mFlashEnabled
            // setRecordingHint(true) is a very nice optimization if you plane to only use the Camera for recording
            Parameters parameters = mCamera.getParameters();
            if (parameters.getFlashMode() != null) {
                parameters.setFlashMode(mFlashEnabled ? Parameters.FLASH_MODE_TORCH : Parameters.FLASH_MODE_OFF);
            }
            parameters.setRecordingHint(true);
            mCamera.setParameters(parameters);
            mCamera.setDisplayOrientation(mOrientation);
            try {
                if (mMode == MODE_MEDIACODEC_API_2) {
                    mSurfaceView.startGLThread();
                    mCamera.setPreviewTexture(mSurfaceView.getSurfaceTexture());
                } else {
                    mCamera.setPreviewDisplay(mSurfaceView.getHolder());
                }
            } catch (IOException e) {
                throw new InvalidSurfaceException("Invalid surface !");
            }
        } catch (RuntimeException e) {
            destroyCamera();
            throw e;
        }
    }
}
Also used : Parameters(android.hardware.Camera.Parameters) Camera(android.hardware.Camera) IOException(java.io.IOException) InvalidSurfaceException(net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException) SuppressLint(android.annotation.SuppressLint)

Aggregations

IOException (java.io.IOException)2 InvalidSurfaceException (net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException)2 SuppressLint (android.annotation.SuppressLint)1 Camera (android.hardware.Camera)1 Parameters (android.hardware.Camera.Parameters)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 AudioStream (net.majorkernelpanic.streaming.audio.AudioStream)1 CameraInUseException (net.majorkernelpanic.streaming.exceptions.CameraInUseException)1 ConfNotSupportedException (net.majorkernelpanic.streaming.exceptions.ConfNotSupportedException)1 StorageUnavailableException (net.majorkernelpanic.streaming.exceptions.StorageUnavailableException)1 VideoStream (net.majorkernelpanic.streaming.video.VideoStream)1