Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ public synchronized void stopRecording() throws CameraWrapperException {
close();
if (mIsPreview) {
startPreview(mPreviewSurface, true);
} else if (mIsTouchOn) {
mIsTouchOn = false;
turnOnTorch();
}
notifyCameraEvent(CameraEvent.STOPPED_VIDEO_RECORDING);
}
Expand Down Expand Up @@ -623,17 +626,21 @@ public void onCaptureBufferLost(@NonNull CameraCaptureSession session, @NonNull
}
resumeRepeatingRequest();
throw new CameraWrapperException(e);
} finally {
mIsTakingStillImage = false;
}
}

private void resumeRepeatingRequest() {
mIsTakingStillImage = false;

try {
if (mIsRecording) {
startRecording(mRecordingSurface, true);
} else if (mIsPreview) {
startPreview(mPreviewSurface, true);
} else if (mIsTouchOn) {
mIsTouchOn = false;
turnOnTorch();
} else {
close();
}
Expand Down Expand Up @@ -794,7 +801,12 @@ public synchronized void turnOnTorch(final @Nullable TorchOnListener listener,
if (mTargetSurface != null) {
requestBuilder.addTarget(mTargetSurface);
}
} else {
}
if (mIsRecording) {
requestBuilder.addTarget(mRecordingSurface);
}

if (!mIsPreview && !mIsRecording) {
requestBuilder.addTarget(mDummyPreviewReader.getSurface());
}
requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
Expand Down Expand Up @@ -848,6 +860,8 @@ public synchronized void turnOffTorch(final @Nullable TorchOffListener listener,
throw new IllegalArgumentException(e);
} catch (CameraWrapperException e) {
throw new IllegalArgumentException(e);
} finally {
resumeRepeatingRequest();
}
notifyTorchOffEvent(listener, handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ public boolean onRequest(final Intent request, final Intent response) {
new PermissionUtility.PermissionRequestCallback() {
@Override
public void onSuccess() {
if (!(isCameraAvailable())) {
MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running.");
sendResponse(response);
return;
}

Bundle lightParam = new Bundle();
setName(lightParam, HOST_DEFAULT_LIGHT_NAME);
setConfig(lightParam, "");
Expand Down Expand Up @@ -144,12 +138,6 @@ public boolean onRequest(final Intent request, final Intent response) {
new PermissionUtility.PermissionRequestCallback() {
@Override
public void onSuccess() {
if (!(isCameraAvailable())) {
MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running.");
sendResponse(response);
return;
}

if (flashing != null) {
flashing(HOST_LIGHT_ID, flashing);
setResult(response, DConnectMessage.RESULT_OK);
Expand Down Expand Up @@ -213,12 +201,6 @@ public boolean onRequest(final Intent request, final Intent response) {
new PermissionUtility.PermissionRequestCallback() {
@Override
public void onSuccess() {
if (!(isCameraAvailable())) {
MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running.");
sendResponse(response);
return;
}

mPhotoRec.turnOffFlashLight(new HostDevicePhotoRecorder.TurnOffFlashLightListener() {
@Override
public void onRequested() {
Expand Down Expand Up @@ -294,18 +276,6 @@ private Handler createHandler(final String name) {
return new Handler(thread.getLooper());
}

/**
* カメラが使用可能どうかをチェックする.
*
* @return 使用可能の場合は true, そうでない場合は false.
*/
private boolean isCameraAvailable() {
if (((HostMediaRecorder) mPhotoRec).getState() != HostMediaRecorder.RecorderState.INACTTIVE) {
return false;
}
return true;
}

/**
* 点滅制御.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class HostLiveStreamingProfile extends DConnectProfile implements LiveStr
private static final String VIDEO_URI_FALSE = "false";
private static final String VIDEO_URI_CAMERA_FRONT = "camera-front";
private static final String VIDEO_URI_CAMERA_BACK = "camera-back";
private static final String VIDEO_URI_CAMERA_0 = "camera_0";
private static final String VIDEO_URI_CAMERA_1 = "camera_1";
private static final String AUDIO_URI_TRUE = "true";
private static final String AUDIO_URI_FALSE = "false";
private static final int CAMERA_TYPE_FRONT = 0;
Expand Down Expand Up @@ -108,6 +110,8 @@ public boolean onRequest(final Intent request, final Intent response) {
case VIDEO_URI_FALSE:
case VIDEO_URI_CAMERA_FRONT:
case VIDEO_URI_CAMERA_BACK:
case VIDEO_URI_CAMERA_0:
case VIDEO_URI_CAMERA_1:
break;
default:
MessageUtils.setInvalidRequestParameterError(response, "video parameter illegal");
Expand Down Expand Up @@ -353,35 +357,42 @@ public boolean onRequest(final Intent request, final Intent response) {
});
}

private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() {
private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() {
if (DEBUG) {
Log.d(TAG, "getHostDeviceLiveStreamRecorder()");
Log.d(TAG, "mVideoURI : " + mVideoURI);
}
switch (mVideoURI) {
case VIDEO_URI_TRUE: {
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(null);
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
}
break;
}
case VIDEO_URI_TRUE:
case VIDEO_URI_FALSE: {
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(null);
if (mHostMediaRecorderManager.usingStreamingRecorder()) {
throw new RuntimeException("Another target in using.");
}

if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
}
break;
}
case VIDEO_URI_CAMERA_FRONT: {
HostMediaRecorder hostMediaRecorder = getRecorder(CAMERA_TYPE_FRONT);
case VIDEO_URI_CAMERA_FRONT:
case VIDEO_URI_CAMERA_1: {
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_1);
if (mHostMediaRecorderManager.usingStreamingRecorder()) {
throw new RuntimeException("Another target in using.");
}
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
}
break;
}
case VIDEO_URI_CAMERA_BACK: {
HostMediaRecorder hostMediaRecorder = getRecorder(CAMERA_TYPE_BACK);
case VIDEO_URI_CAMERA_BACK:
case VIDEO_URI_CAMERA_0: {
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_0);
if (mHostMediaRecorderManager.usingPreviewOrStreamingRecorder(hostMediaRecorder.getId())) {
throw new RuntimeException("Another target in using.");
}

if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
}
Expand All @@ -392,31 +403,6 @@ private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() {
throw new RuntimeException("recorder not found");
}


private HostMediaRecorder getRecorder(int type) {
if (DEBUG) {
Log.d(TAG, "getRecorder()");
Log.d(TAG, "type" + type);
}
for(HostMediaRecorder hostMediaRecorder : mHostMediaRecorderManager.getRecorders()) {
if (DEBUG) {
Log.d(TAG, "name : " + hostMediaRecorder.getName());
}
if (hostMediaRecorder.getName().matches("^Camera [0-9] \\((Front|Back)\\)")) {
if (type == CAMERA_TYPE_FRONT) {
if (hostMediaRecorder.getName().contains("Front")) {
return hostMediaRecorder;
}
} else if (type == CAMERA_TYPE_BACK) {
if (hostMediaRecorder.getName().contains("Back")) {
return hostMediaRecorder;
}
}
}
}
return null;
}

@Override
public void onStart() {
if (DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ private void setOptions(final Intent request, final Intent response) {
return;
}

if (recorder.getState() != HostMediaRecorder.RecorderState.INACTTIVE) {
if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE
&& recorder.getState() != HostMediaRecorder.RecorderState.PREVIEW) {
MessageUtils.setInvalidRequestParameterError(response, "settings of active target cannot be changed.");
return;
}
Expand Down Expand Up @@ -431,6 +432,10 @@ public boolean onRequest(final Intent request, final Intent response) {
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
return true;
}
if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) {
MessageUtils.setInvalidRequestParameterError(response, "Another target in using.");
return true;
}

if (!(recorder instanceof HostDevicePhotoRecorder)) {
MessageUtils.setNotSupportAttributeError(response,
Expand Down Expand Up @@ -501,7 +506,10 @@ public boolean onRequest(final Intent request, final Intent response) {
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
return true;
}

if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) {
MessageUtils.setInvalidRequestParameterError(response, "Another target in using.");
return true;
}
recorder.requestPermission(new HostMediaRecorder.PermissionCallback() {
@Override
public void onAllowed() {
Expand Down Expand Up @@ -559,7 +567,6 @@ public boolean onRequest(final Intent request, final Intent response) {
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
return true;
}

recorder.requestPermission(new HostMediaRecorder.PermissionCallback() {
@Override
public void onAllowed() {
Expand Down Expand Up @@ -678,14 +685,19 @@ public boolean onRequest(final Intent request, final Intent response) {
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
return true;
}
if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) {
MessageUtils.setInvalidRequestParameterError(response, "Another target in using.");
return true;
}

if (!(recorder instanceof HostDeviceStreamRecorder)) {
MessageUtils.setNotSupportAttributeError(response,
"target does not support stream recording.");
return true;
}

if (recorder.getState() != HostMediaRecorder.RecorderState.INACTTIVE) {
if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE
&& recorder.getState() != HostMediaRecorder.RecorderState.PREVIEW) {
MessageUtils.setIllegalDeviceStateError(response,
recorder.getName() + " is already running.");
return true;
Expand Down Expand Up @@ -744,14 +756,13 @@ public boolean onRequest(final Intent request, final Intent response) {
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
return true;
}

if (!(recorder instanceof HostDeviceStreamRecorder)) {
MessageUtils.setNotSupportAttributeError(response,
"target does not support stream recording.");
return true;
}

if (recorder.getState() == HostMediaRecorder.RecorderState.INACTTIVE) {
if (recorder.getState() == HostMediaRecorder.RecorderState.INACTIVE) {
MessageUtils.setIllegalDeviceStateError(response, "recorder is stopped already.");
return true;
}
Expand Down Expand Up @@ -907,7 +918,6 @@ public void onDisallowed() {
public HostMediaStreamingRecordingProfile(final HostMediaRecorderManager mgr, final FileManager fileMgr) {
mRecorderMgr = mgr;
mFileManager = fileMgr;

addApi(mGetMediaRecorderApi);
addApi(mGetOptionsApi);
addApi(mPutOptionsApi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class AbstractPreviewServerProvider implements PreviewServerProv
*/
private HostMediaRecorder mRecorder;

private boolean mIsShownNotification;
/**
* コンストラクタ.
* @param context コンテキスト
Expand All @@ -60,6 +61,7 @@ public AbstractPreviewServerProvider(final Context context, final HostMediaRecor
mContext = context;
mRecorder = recorder;
mNotificationId = notificationId;
mIsShownNotification = false;
}

// PreviewServerProvider
Expand Down Expand Up @@ -118,6 +120,7 @@ public void onFail() {
// TODO タイムアウト処理
} else {
sendNotification(mRecorder.getId(), mRecorder.getName());
mIsShownNotification = true;
}
} catch (InterruptedException e) {
// ignore.
Expand Down Expand Up @@ -171,6 +174,7 @@ private void hideNotification(String id) {
.getSystemService(Service.NOTIFICATION_SERVICE);
if (manager != null) {
manager.cancel(id, getNotificationId());
mIsShownNotification = false;
}
}

Expand Down Expand Up @@ -252,4 +256,9 @@ private PendingIntent createPendingIntent(String id) {
intent.putExtra(EXTRA_CAMERA_ID, id);
return PendingIntent.getBroadcast(mContext, getNotificationId(), intent, 0);
}

@Override
public boolean isShownCameraNotification() {
return mIsShownNotification;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ enum RecorderState {
/**
* 動作していない.
*/
INACTTIVE,
INACTIVE,

/**
* 録画が一時停止中の状態.
Expand All @@ -299,6 +299,11 @@ enum RecorderState {
*/
RECORDING,

/**
* プレビューが表示されている状態.
*/
PREVIEW,

/**
* エラーで停止している状態.
*/
Expand Down
Loading