Search in sources :

Example 21 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class HardwareServiceImpl method decodingStarted.

public void decodingStarted(String id, String shmPath, int width, int height, boolean isMixer) {
    Log.i(TAG, "decodingStarted() " + id + " " + width + "x" + height);
    Shm shm = new Shm();
    shm.id = id;
    shm.w = width;
    shm.h = height;
    videoInputs.put(id, shm);
    WeakReference<SurfaceHolder> weakSurfaceHolder = videoSurfaces.get(id);
    if (weakSurfaceHolder != null) {
        SurfaceHolder holder = weakSurfaceHolder.get();
        if (holder != null) {
            shm.window = startVideo(id, holder.getSurface(), width, height);
            if (shm.window == 0) {
                Log.i(TAG, "DRingService.decodingStarted() no window !");
                ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
                event.addEventInput(ServiceEvent.EventInput.VIDEO_START, true);
                setChanged();
                notifyObservers(event);
                return;
            }
            ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
            event.addEventInput(ServiceEvent.EventInput.VIDEO_CALL, shm.id);
            event.addEventInput(ServiceEvent.EventInput.VIDEO_STARTED, true);
            event.addEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, shm.w);
            event.addEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, shm.h);
            setChanged();
            notifyObservers(event);
        }
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) ServiceEvent(cx.ring.model.ServiceEvent)

Example 22 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class HardwareServiceImpl method startCapture.

@Override
public void startCapture(@Nullable String camId) {
    VideoParams videoParams;
    if (camId == null && previewParams != null) {
        videoParams = previewParams;
    } else if (camId != null) {
        videoParams = mParams.get(camId);
    } else if (mParams.size() == 2) {
        currentCamera = cameraFront;
        videoParams = mParams.get(cameraFront);
    } else {
        currentCamera = cameraBack;
        videoParams = mParams.get(cameraBack);
    }
    SurfaceHolder surface = mCameraPreviewSurface.get();
    if (surface == null) {
        Log.w(TAG, "Can't start capture: no surface registered.");
        previewParams = videoParams;
        ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
        event.addEventInput(ServiceEvent.EventInput.VIDEO_START, true);
        setChanged();
        notifyObservers(event);
        return;
    }
    if (videoParams == null) {
        Log.w(TAG, "startCapture: no video parameters ");
        return;
    }
    Log.d(TAG, "startCapture: startCapture " + videoParams.id + " " + videoParams.width + "x" + videoParams.height + " rot" + videoParams.rotation);
    final Camera preview;
    try {
        if (previewCamera != null) {
            previewCamera.release();
            previewCamera = null;
        }
        preview = Camera.open(videoParams.id);
        setCameraDisplayOrientation(videoParams.id, preview);
    } catch (Exception e) {
        Log.e(TAG, "Camera.open: " + e.getMessage());
        return;
    }
    try {
        preview.setPreviewDisplay(surface);
    } catch (IOException e) {
        Log.e(TAG, "setPreviewDisplay: " + e.getMessage());
        return;
    }
    Camera.Parameters parameters = preview.getParameters();
    parameters.setPreviewFormat(videoParams.format);
    parameters.setPreviewSize(videoParams.width, videoParams.height);
    parameters.setRotation(0);
    for (int[] fps : parameters.getSupportedPreviewFpsRange()) {
        if (videoParams.rate >= fps[Camera.Parameters.PREVIEW_FPS_MIN_INDEX] && videoParams.rate <= fps[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]) {
            parameters.setPreviewFpsRange(fps[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], fps[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
        }
    }
    try {
        preview.setParameters(parameters);
    } catch (RuntimeException e) {
        Log.e(TAG, "Error while settings preview parameters", e);
    }
    final int videoWidth = videoParams.width;
    final int heigth = videoParams.height;
    final int rotation = videoParams.rotation;
    preview.setPreviewCallbackWithBuffer((data, camera) -> {
        setVideoFrame(data, videoWidth, heigth, rotation);
        preview.addCallbackBuffer(data);
    });
    // enqueue first buffer
    int bufferSize = parameters.getPreviewSize().width * parameters.getPreviewSize().height * ImageFormat.getBitsPerPixel(parameters.getPreviewFormat()) / 8;
    preview.addCallbackBuffer(new byte[bufferSize]);
    preview.setErrorCallback((error, cam) -> {
        Log.w(TAG, "Camera onError " + error);
        if (preview == cam) {
            stopCapture();
        }
    });
    try {
        preview.startPreview();
    } catch (RuntimeException e) {
        Log.e(TAG, "startPreview: " + e.getMessage());
        return;
    }
    previewCamera = preview;
    previewParams = videoParams;
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_STARTED, true);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, videoParams.rotWidth);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, videoParams.rotHeight);
    setChanged();
    notifyObservers(event);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) ServiceEvent(cx.ring.model.ServiceEvent) Camera(android.hardware.Camera) IOException(java.io.IOException) IOException(java.io.IOException) Point(android.graphics.Point)

Example 23 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class AccountService method volumeChanged.

public void volumeChanged(String device, int value) {
    setChanged();
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VOLUME_CHANGED);
    event.addEventInput(ServiceEvent.EventInput.DEVICE, device);
    event.addEventInput(ServiceEvent.EventInput.VALUE, value);
    notifyObservers(event);
}
Also used : ServiceEvent(cx.ring.model.ServiceEvent)

Example 24 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class AccountService method registrationStateChanged.

public void registrationStateChanged(String accountId, String newState, int code, String detailString) {
    Log.d(TAG, "stun status registrationStateChanged: " + accountId + ", " + newState + ", " + code + ", " + detailString);
    Account account = getAccount(accountId);
    if (account == null) {
        return;
    }
    String oldState = account.getRegistrationState();
    if (oldState.contentEquals(AccountConfig.STATE_INITIALIZING) && !newState.contentEquals(AccountConfig.STATE_INITIALIZING)) {
        account.setDetails(getAccountDetails(account.getAccountID()));
        account.setCredentials(getCredentials(account.getAccountID()));
        account.setDevices(getKnownRingDevices(account.getAccountID()));
        account.setVolatileDetails(getVolatileAccountDetails(account.getAccountID()));
    } else {
        account.setRegistrationState(newState, code);
    }
    if (!oldState.equals(newState)) {
        setChanged();
        ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.REGISTRATION_STATE_CHANGED);
        event.addEventInput(ServiceEvent.EventInput.ACCOUNT_ID, accountId);
        event.addEventInput(ServiceEvent.EventInput.STATE, newState);
        event.addEventInput(ServiceEvent.EventInput.DETAIL_CODE, code);
        event.addEventInput(ServiceEvent.EventInput.DETAIL_STRING, detailString);
        notifyObservers(event);
    }
}
Also used : Account(cx.ring.model.Account) ServiceEvent(cx.ring.model.ServiceEvent)

Example 25 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class AccountService method registeredNameFound.

public void registeredNameFound(String accountId, int state, String address, String name) {
    Log.d(TAG, "registeredNameFound: " + accountId + ", " + state + ", " + name + ", " + address);
    Account account = getAccount(accountId);
    if (account != null) {
        if (state == 0) {
            CallContact contact = account.getContact(address);
            if (contact != null) {
                contact.setUsername(name);
            }
        }
        TrustRequest request = account.getRequest(address);
        if (request != null) {
            Log.d(TAG, "registeredNameFound: updating TrustRequest " + name);
            boolean resolved = request.isNameResolved();
            request.setUsername(name);
            if (!resolved) {
                Log.d(TAG, "registeredNameFound: TrustRequest resolved " + name);
                setChanged();
                ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.INCOMING_TRUST_REQUEST);
                event.addEventInput(ServiceEvent.EventInput.ACCOUNT_ID, accountId);
                event.addEventInput(ServiceEvent.EventInput.FROM, request.getContactId());
                notifyObservers(event);
            }
        }
    }
    setChanged();
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.REGISTERED_NAME_FOUND);
    event.addEventInput(ServiceEvent.EventInput.ACCOUNT_ID, accountId);
    event.addEventInput(ServiceEvent.EventInput.STATE, state);
    event.addEventInput(ServiceEvent.EventInput.ADDRESS, address);
    event.addEventInput(ServiceEvent.EventInput.NAME, name);
    notifyObservers(event);
}
Also used : Account(cx.ring.model.Account) ServiceEvent(cx.ring.model.ServiceEvent) TrustRequest(cx.ring.model.TrustRequest) CallContact(cx.ring.model.CallContact)

Aggregations

ServiceEvent (cx.ring.model.ServiceEvent)43 Account (cx.ring.model.Account)13 DataTransfer (cx.ring.model.DataTransfer)4 HistoryText (cx.ring.model.HistoryText)4 TextMessage (cx.ring.model.TextMessage)4 SQLException (java.sql.SQLException)4 SurfaceHolder (android.view.SurfaceHolder)3 CallContact (cx.ring.model.CallContact)3 Conversation (cx.ring.model.Conversation)3 HistoryCall (cx.ring.model.HistoryCall)3 SipCall (cx.ring.model.SipCall)3 Uri (cx.ring.model.Uri)3 IOException (java.io.IOException)3 Camera (android.hardware.Camera)2 StringMap (cx.ring.daemon.StringMap)2 DataTransferEventCode (cx.ring.model.DataTransferEventCode)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Point (android.graphics.Point)1 DataTransferInfo (cx.ring.daemon.DataTransferInfo)1