1 package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper;
3 import android.util.Log;
5 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
6 import net.osdn.gokigen.gr2control.camera.utils.SimpleHttpClient;
7 import net.osdn.gokigen.gr2control.camera.utils.SimpleLiveviewSlicer;
8 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.CameraLiveViewListenerImpl;
9 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
11 import androidx.annotation.NonNull;
17 public class RicohGr2LiveViewControl implements ILiveViewControl
19 private final String TAG = toString();
20 private final CameraLiveViewListenerImpl liveViewListener;
21 private final boolean useGrCommand;
22 private String cameraDisplayUrl = "http://192.168.0.1/v1/display"; // カメラの画面をコピーする場合...
23 private String liveViewUrl = "http://192.168.0.1/v1/liveview"; // 何も表示しない(ライブビューモード)の場合...
24 private float cropScale = 1.0f;
25 private boolean whileFetching = false;
26 private static final int FETCH_ERROR_MAX = 30;
32 RicohGr2LiveViewControl(boolean useGrControl)
34 this.useGrCommand = useGrControl;
35 liveViewListener = new CameraLiveViewListenerImpl();
39 public void setLiveViewAddress(@NonNull String address, @NonNull String page)
41 cameraDisplayUrl = "http://" + address + "/" + page;
46 public void changeLiveViewSize(String size)
52 public void startLiveView(final boolean useCameraScreen)
54 final boolean isCameraScreen = useGrCommand && useCameraScreen;
55 Log.v(TAG, "startLiveView()");
58 Thread thread = new Thread(new Runnable()
67 start(cameraDisplayUrl);
90 public void stopLiveView()
92 Log.v(TAG, "stopLiveView()");
93 whileFetching = false;
97 private void start(@NonNull final String streamUrl)
101 Log.v(TAG, "start() already starting.");
103 whileFetching = true;
105 // A thread for retrieving liveview data from server.
108 Thread thread = new Thread(new Runnable()
113 Log.d(TAG, "Starting retrieving streaming data from server.");
114 SimpleLiveviewSlicer slicer = null;
115 int continuousNullDataReceived = 0;
118 // Create Slicer to open the stream and parse it.
119 slicer = new SimpleLiveviewSlicer();
120 slicer.open(streamUrl);
122 while (whileFetching)
124 final SimpleLiveviewSlicer.Payload payload = slicer.nextPayloadForMotionJpeg();
127 //Log.v(TAG, "Liveview Payload is null.");
128 continuousNullDataReceived++;
129 if (continuousNullDataReceived > FETCH_ERROR_MAX)
131 Log.d(TAG, " FETCH ERROR MAX OVER ");
136 //if (mJpegQueue.size() == 2)
138 // mJpegQueue.remove();
140 //mJpegQueue.add(payload.getJpegData());
141 liveViewListener.onUpdateLiveView(payload.getJpegData(), null);
142 continuousNullDataReceived = 0;
162 //mJpegQueue.clear();
163 if ((!whileFetching)&&(continuousNullDataReceived > FETCH_ERROR_MAX))
165 // 再度ライブビューのスタートをやってみる。
166 whileFetching = false;
167 //continuousNullDataReceived = 0;
183 public void updateDigitalZoom()
193 public float getDigitalZoomScale()
203 public void updateMagnifyingLiveViewScale(final boolean isChangeScale)
210 if (cropScale == 1.0f)
214 else if (cropScale == 1.25f)
223 Thread thread = new Thread(new Runnable()
230 String cropSize = "CROP_SIZE_ORIGINAL";
231 int timeoutMs = 5000;
232 String grCmdUrl = "http://192.168.0.1/_gr";
237 postData = "mpget=CROP_SHOOTING";
238 result = SimpleHttpClient.httpPost(grCmdUrl, postData, timeoutMs);
239 if ((result == null) || (result.length() < 1))
241 Log.v(TAG, "reply is null.");
243 } else if (result.contains("SIZE_M")) {
244 cropSize = "CROP_SIZE_S";
246 } else if (result.contains("SIZE_S")) {
247 cropSize = "CROP_SIZE_ORIGINAL";
250 cropSize = "CROP_SIZE_M";
254 postData = "mpset=CROP_SHOOTING " + cropSize;
255 result = SimpleHttpClient.httpPost(grCmdUrl, postData, timeoutMs);
256 Log.v(TAG, "RESULT1 : " + result);
258 postData = "cmd=mode refresh";
259 result = SimpleHttpClient.httpPost(grCmdUrl, postData, timeoutMs);
260 Log.v(TAG, "RESULT2 : " + result);
277 * ライブビュー拡大倍率の設定値を応答する
281 public float getMagnifyingLiveViewScale()
286 public ILiveViewListener getLiveViewListener()
288 return (liveViewListener);