Search in sources :

Example 1 with CameraInUseException

use of net.majorkernelpanic.streaming.exceptions.CameraInUseException 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 CameraInUseException

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

the class VideoStream method openCamera.

/**
	 * Opens the camera in a new Looper thread so that the preview callback is not called from the main thread
	 * If an exception is thrown in this Looper thread, we bring it back into the main thread.
	 * @throws RuntimeException Might happen if another app is already using the camera.
	 */
private void openCamera() throws RuntimeException {
    final Semaphore lock = new Semaphore(0);
    final RuntimeException[] exception = new RuntimeException[1];
    mCameraThread = new Thread(new Runnable() {

        @Override
        public void run() {
            Looper.prepare();
            mCameraLooper = Looper.myLooper();
            try {
                mCamera = Camera.open(mCameraId);
            } catch (RuntimeException e) {
                exception[0] = e;
            } finally {
                lock.release();
                Looper.loop();
            }
        }
    });
    mCameraThread.start();
    lock.acquireUninterruptibly();
    if (exception[0] != null)
        throw new CameraInUseException(exception[0].getMessage());
}
Also used : CameraInUseException(net.majorkernelpanic.streaming.exceptions.CameraInUseException) Semaphore(java.util.concurrent.Semaphore)

Aggregations

CameraInUseException (net.majorkernelpanic.streaming.exceptions.CameraInUseException)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Semaphore (java.util.concurrent.Semaphore)1 AudioStream (net.majorkernelpanic.streaming.audio.AudioStream)1 ConfNotSupportedException (net.majorkernelpanic.streaming.exceptions.ConfNotSupportedException)1 InvalidSurfaceException (net.majorkernelpanic.streaming.exceptions.InvalidSurfaceException)1 StorageUnavailableException (net.majorkernelpanic.streaming.exceptions.StorageUnavailableException)1 VideoStream (net.majorkernelpanic.streaming.video.VideoStream)1