Skip to content

Commit bbafada

Browse files
Merge pull request #720 from TakayukiHoshi1984/modify_host_plugin_settings
Modify host plugin settings
2 parents 3328f90 + 7506386 commit bbafada

12 files changed

Lines changed: 317 additions & 68 deletions

File tree

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/assets/org_deviceconnect_android_deviceplugin_host/api/mediaStreamRecording.json

Lines changed: 133 additions & 41 deletions
Large diffs are not rendered by default.

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.deviceconnect.android.deviceplugin.host.recorder.LiveStreaming;
2727
import org.deviceconnect.android.deviceplugin.host.recorder.camera.Camera2Recorder;
2828
import org.deviceconnect.android.deviceplugin.host.recorder.util.CapabilityUtil;
29+
import org.deviceconnect.android.deviceplugin.host.util.NetworkUtil;
2930
import org.deviceconnect.android.event.Event;
3031
import org.deviceconnect.android.event.EventError;
3132
import org.deviceconnect.android.event.EventManager;
@@ -1064,31 +1065,44 @@ public boolean onRequest(Intent request, Intent response) {
10641065
Integer right = parseInteger(request, "right");
10651066
Integer bottom = parseInteger(request, "bottom");
10661067
Integer duration = parseInteger(request, "duration");
1068+
Boolean visible = parseBoolean(request, "visible");
10671069

10681070
HostMediaRecorder recorder = mRecorderMgr.getRecorder(target);
10691071
if (recorder == null) {
10701072
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
10711073
return true;
10721074
}
10731075

1074-
if (left == null) {
1075-
MessageUtils.setInvalidRequestParameterError(response, "left is not set.");
1076-
return true;
1077-
}
1076+
if (left != null || top != null || right != null || bottom != null || duration != null) {
1077+
if (left == null) {
1078+
MessageUtils.setInvalidRequestParameterError(response, "left is not set.");
1079+
return true;
1080+
}
10781081

1079-
if (top == null) {
1080-
MessageUtils.setInvalidRequestParameterError(response, "top is not set.");
1081-
return true;
1082-
}
1082+
if (top == null) {
1083+
MessageUtils.setInvalidRequestParameterError(response, "top is not set.");
1084+
return true;
1085+
}
10831086

1084-
if (right == null) {
1085-
MessageUtils.setInvalidRequestParameterError(response, "right is not set.");
1086-
return true;
1087-
}
1087+
if (right == null) {
1088+
MessageUtils.setInvalidRequestParameterError(response, "right is not set.");
1089+
return true;
1090+
}
10881091

1089-
if (bottom == null) {
1090-
MessageUtils.setInvalidRequestParameterError(response, "bottom is not set.");
1091-
return true;
1092+
if (bottom == null) {
1093+
MessageUtils.setInvalidRequestParameterError(response, "bottom is not set.");
1094+
return true;
1095+
}
1096+
1097+
if (left >= right || top >= bottom) {
1098+
MessageUtils.setInvalidRequestParameterError(response, "parameter is invalid.");
1099+
return true;
1100+
}
1101+
1102+
if (duration == null) {
1103+
MessageUtils.setInvalidRequestParameterError(response, "duration is not set.");
1104+
return true;
1105+
}
10921106
}
10931107

10941108
List<String> encoderIdList = getEncoderSettings(recorder, name, true);
@@ -1097,16 +1111,16 @@ public boolean onRequest(Intent request, Intent response) {
10971111
return true;
10981112
}
10991113

1100-
if (left >= right || top >= bottom) {
1101-
MessageUtils.setInvalidRequestParameterError(response, "parameter is invalid.");
1102-
return true;
1103-
}
1104-
11051114
recorder.requestPermission(new HostMediaRecorder.PermissionCallback() {
11061115
@Override
11071116
public void onAllowed() {
11081117
for (String encoderId : encoderIdList) {
1109-
setCrop(recorder, encoderId, left, top, right, bottom, duration);
1118+
if (left != null && top != null && right != null && bottom != null) {
1119+
setCrop(recorder, encoderId, left, top, right, bottom, duration);
1120+
}
1121+
if (visible != null) {
1122+
setCropVisible(recorder, encoderId, visible);
1123+
}
11101124
}
11111125
setResult(response, DConnectMessage.RESULT_OK);
11121126
sendResponse(response);
@@ -1357,6 +1371,7 @@ private void setOptions(final Intent request, final Intent response) {
13571371
Integer previewClipBottom = parseInteger(request, "previewClipBottom");
13581372
Integer previewClipDuration = parseInteger(request, "previewClipDuration");
13591373
Boolean previewClipReset = parseBoolean(request, "previewClipReset");
1374+
Boolean previewClipVisible = parseBoolean(request, "previewClipVisible");
13601375

13611376
HostMediaRecorder.ProfileLevel profileLevel = null;
13621377
Range<Integer> fps = null;
@@ -1652,6 +1667,15 @@ private void setOptions(final Intent request, final Intent response) {
16521667
}
16531668
}
16541669

1670+
if (previewClipVisible != null) {
1671+
for (String encoderId : settings.getEncoderIdList()) {
1672+
HostMediaRecorder.EncoderSettings encoderSettings = settings.getEncoderSetting(encoderId);
1673+
if (encoderId != null && mimeType.equals(encoderSettings.getMimeType().getValue())) {
1674+
setCropVisible(recorder, encoderId, previewClipVisible);
1675+
}
1676+
}
1677+
}
1678+
16551679
if (isChangeConfig) {
16561680
try {
16571681
recorder.onConfigChange();
@@ -1664,6 +1688,25 @@ private void setOptions(final Intent request, final Intent response) {
16641688
setResult(response, DConnectMessage.RESULT_OK);
16651689
}
16661690

1691+
private void setCropVisible(HostMediaRecorder recorder, String encoderId, boolean visible) {
1692+
HostMediaRecorder.EncoderSettings encoderSettings = recorder.getSettings().getEncoderSetting(encoderId);
1693+
if (encoderSettings == null) {
1694+
return;
1695+
}
1696+
1697+
for (LiveStreaming previewServer : recorder.getServerProvider().getLiveStreamingList()) {
1698+
if (encoderId.equals(previewServer.getId())) {
1699+
((CropInterface) previewServer).setCropVisible(visible);
1700+
}
1701+
}
1702+
1703+
for (LiveStreaming broadcaster : recorder.getBroadcasterProvider().getLiveStreamingList()) {
1704+
if (encoderId.equals(broadcaster.getId())) {
1705+
((CropInterface) broadcaster).setCropVisible(visible);
1706+
}
1707+
}
1708+
}
1709+
16671710
private void setCrop(HostMediaRecorder recorder, String encoderId, int left, int top, int right, int bottom, int duration) {
16681711
HostMediaRecorder.EncoderSettings encoderSettings = recorder.getSettings().getEncoderSetting(encoderId);
16691712
if (encoderSettings == null) {
@@ -1829,6 +1872,21 @@ private Bundle createVideoEncoder(HostMediaRecorder.EncoderSettings s) {
18291872
}
18301873
}
18311874

1875+
String host = NetworkUtil.getIPAddress(getContext());
1876+
if (host.equals("0.0.0.0")) {
1877+
host = "localhost";
1878+
}
1879+
1880+
if ("video/x-mjpeg".equals(s.getMimeType().getValue())) {
1881+
bundle.putString("uri", "http://" + host + ":" + s.getPort() + "/mjpeg");
1882+
} else if ("video/x-rtp".equals(s.getMimeType().getValue())) {
1883+
bundle.putString("uri", "rtsp://" + host + ":" + s.getPort());
1884+
} else if ("video/MP2T".equals(s.getMimeType().getValue())) {
1885+
bundle.putString("uri", "srt://" + host + ":" + s.getPort());
1886+
} else if ("video/x-rtmp".equals(s.getMimeType().getValue())) {
1887+
bundle.putString("uri", s.getBroadcastURI());
1888+
}
1889+
18321890
if (s.getPort() > 0) {
18331891
bundle.putInt("port", s.getPort());
18341892
}
@@ -1842,6 +1900,7 @@ private Bundle createVideoEncoder(HostMediaRecorder.EncoderSettings s) {
18421900
drawingRect.putInt("right", rect.right);
18431901
drawingRect.putInt("bottom", rect.bottom);
18441902
bundle.putBundle("crop", drawingRect);
1903+
bundle.putBoolean("cropVisible", s.getCropVisible());
18451904
}
18461905

18471906
return bundle;

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/AbstractLiveStreaming.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ public Rect getCropRect() {
200200
return getEncoderSettings().getCropRect();
201201
}
202202

203+
@Override
204+
public void setCropVisible(boolean visible) {
205+
getEncoderSettings().setCropVisible(visible);
206+
postOnVisibleChanged(visible);
207+
}
208+
209+
@Override
210+
public boolean getCropVisible() {
211+
return getEncoderSettings().getCropVisible();
212+
}
213+
203214
@Override
204215
public void addOnEventListener(CropInterface.OnEventListener listener) {
205216
mOnEventListeners.add(listener);
@@ -247,6 +258,12 @@ private void postOnMoved(Rect rect) {
247258
}
248259
}
249260

261+
private void postOnVisibleChanged(boolean visible) {
262+
for (CropInterface.OnEventListener l : mOnEventListeners.get()) {
263+
l.onVisibleChanged(this, visible);
264+
}
265+
}
266+
250267
private void startMovingRectThread() {
251268
if (mMovingRectThread != null) {
252269
return;

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/CropInterface.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ public interface CropInterface {
3434
*/
3535
Rect getCropRect();
3636

37+
/**
38+
* クロップ範囲の表示フラグを設定します.
39+
*
40+
* @param visible クロップ範囲の表示フラグ
41+
*/
42+
void setCropVisible(boolean visible);
43+
44+
/**
45+
* クロップ範囲の表示フラグを取得します.
46+
*
47+
* @return クロップ範囲の表示フラグ
48+
*/
49+
boolean getCropVisible();
50+
3751
/**
3852
* イベントリスナーを追加します.
3953
*
@@ -63,5 +77,10 @@ interface OnEventListener {
6377
* クロップする矩形が移動したことを通知します.
6478
*/
6579
void onMoved(CropInterface crop, Rect cropRect);
80+
81+
/**
82+
* クロップ範囲を表示設定が変更されたことを通知します.
83+
*/
84+
void onVisibleChanged(CropInterface crop, boolean visible);
6685
}
6786
}

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,28 @@ public void setIntraRefresh(Integer refresh) {
844844
}
845845
}
846846

847+
/**
848+
* 切り抜き範囲の表示フラグを取得します.
849+
*
850+
* @return 切り抜き範囲の表示フラグ
851+
*/
852+
public Boolean getCropVisible() {
853+
return mProperty.getBoolean("preview_clip_visible", true);
854+
}
855+
856+
/**
857+
* 切り抜き範囲の表示フラグを設定します.
858+
*
859+
* @param visible 切り抜き範囲の表示フラグ
860+
*/
861+
public void setCropVisible(Boolean visible) {
862+
if (visible == null) {
863+
mProperty.remove("preview_clip_visible");
864+
} else {
865+
mProperty.put("preview_clip_visible", visible);
866+
}
867+
}
868+
847869
/**
848870
* 切り抜き範囲を取得します.
849871
*

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/ui/PreviewSurfaceView.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.Context;
55
import android.graphics.Rect;
66
import android.util.AttributeSet;
7-
import android.util.Log;
87
import android.util.Size;
98
import android.view.LayoutInflater;
109
import android.view.MotionEvent;
@@ -57,7 +56,7 @@ private void initView(Context context) {
5756
@Override
5857
public boolean onScale(ScaleGestureDetector detector) {
5958
CropRectHolder holder = getFocusedHolder();
60-
if (holder == null) {
59+
if (holder == null || !holder.mVisible) {
6160
return false;
6261
}
6362

@@ -144,7 +143,7 @@ public void onScaleEnd(ScaleGestureDetector detector) {
144143
{
145144
for (CropRectHolder holder : mCropRectMap.values()) {
146145
Rect cropRect = holder.mCropRect;
147-
if (cropRect.contains(orgX, orgY)) {
146+
if (holder.mVisible && cropRect.contains(orgX, orgY)) {
148147
clearFocusCropRect();
149148
mDragStartX = x;
150149
mDragStartY = y;
@@ -284,6 +283,22 @@ public void removeCropRange(Object key) {
284283
});
285284
}
286285

286+
/**
287+
* 切り抜き範囲の表示フラグを設定します.
288+
*
289+
* @param key 切り抜き範囲の枠を識別するキー
290+
* @param visible 表示フラグ
291+
*/
292+
public void setCropVisible(Object key, boolean visible) {
293+
post(() -> {
294+
CropRectHolder holder = mCropRectMap.get(key);
295+
if (holder != null) {
296+
holder.mVisible = visible;
297+
setCropRectView(holder);
298+
}
299+
});
300+
}
301+
287302
/**
288303
* 切り抜き範囲の枠の値が変更された時に呼び出されます.
289304
*
@@ -310,7 +325,7 @@ private void setCropRectView(CropRectHolder holder) {
310325
MarginLayoutParams mlp = (MarginLayoutParams) layoutParams;
311326
mlp.setMargins(left, top, 0, 0);
312327
frameView.setLayoutParams(layoutParams);
313-
frameView.setVisibility(VISIBLE);
328+
frameView.setVisibility(holder.mVisible ? VISIBLE : GONE);
314329
}
315330
}
316331

@@ -367,7 +382,6 @@ public void fullSurfaceView(int previewWidth, int previewHeight) {
367382
layoutParams.height = mSurfaceHeight;
368383
surfaceView.setLayoutParams(layoutParams);
369384
surfaceView.getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
370-
// surfaceView.getHolder().setFixedSize(previewWidth, previewHeight);
371385
});
372386
}
373387

@@ -395,7 +409,6 @@ public void adjustSurfaceView(int previewWidth, int previewHeight) {
395409
layoutParams.height = mSurfaceHeight;
396410
surfaceView.setLayoutParams(layoutParams);
397411
surfaceView.getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
398-
// surfaceView.getHolder().setFixedSize(previewWidth, previewHeight);
399412
});
400413
}
401414

@@ -438,5 +451,6 @@ private static class CropRectHolder {
438451
private Rect mCropRect;
439452
private View mView;
440453
private boolean mFocused;
454+
private boolean mVisible;
441455
}
442456
}

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/res/values-ja/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<string name="host_recorder_settings_cut_out_bottom">Bottom</string>
123123
<string name="host_recorder_settings_cut_out_reset">リセット</string>
124124
<string name="host_recorder_settings_cut_out_set">配信解像度を入力する</string>
125+
<string name="host_recorder_settings_cut_out_visible">切り抜き範囲表示フラグ</string>
125126
<string name="host_recorder_settings_clipboard_copy">クリップボードにコピーしました</string>
126127

127128
<!-- 音声設定 -->

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<string name="host_recorder_settings_cut_out_bottom">Bottom</string>
121121
<string name="host_recorder_settings_cut_out_reset">Reset</string>
122122
<string name="host_recorder_settings_cut_out_set">Set by delivery resolution</string>
123+
<string name="host_recorder_settings_cut_out_visible">Visible</string>
123124
<string name="host_recorder_settings_clipboard_copy">Copied to the clipboard</string>
124125

125126
<string name="host_recorder_settings_audio_enable">Enable</string>

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/res/xml/settings_host_recorder_broadcast.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,11 @@
135135
app:iconSpaceReserved="false"
136136
app:useSimpleSummaryProvider="true" />
137137

138+
<SwitchPreferenceCompat
139+
android:defaultValue="true"
140+
android:key="preview_clip_visible"
141+
android:title="@string/host_recorder_settings_cut_out_visible"
142+
app:iconSpaceReserved="false" />
143+
138144
</PreferenceCategory>
139145
</PreferenceScreen>

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/res/xml/settings_host_recorder_mjpeg.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,11 @@
8989
app:iconSpaceReserved="false"
9090
app:useSimpleSummaryProvider="true" />
9191

92+
<SwitchPreferenceCompat
93+
android:defaultValue="true"
94+
android:key="preview_clip_visible"
95+
android:title="@string/host_recorder_settings_cut_out_visible"
96+
app:iconSpaceReserved="false" />
97+
9298
</PreferenceCategory>
9399
</PreferenceScreen>

0 commit comments

Comments
 (0)