1 package net.osdn.gokigen.pkremote.camera.vendor.sony.wrapper;
3 import android.util.Log;
5 import androidx.annotation.NonNull;
7 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewControl;
8 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewListener;
9 import net.osdn.gokigen.pkremote.camera.liveview.CameraLiveViewListenerImpl;
10 import net.osdn.gokigen.pkremote.camera.utils.SimpleLiveviewSlicer;
12 import org.json.JSONArray;
13 import org.json.JSONObject;
15 public class SonyLiveViewControl implements ILiveViewControl
17 private final String TAG = toString();
18 private final ISonyCameraApi cameraApi;
19 //private final BlockingQueue<byte[]> mJpegQueue = new ArrayBlockingQueue<>(2);
20 private final CameraLiveViewListenerImpl liveViewListener;
21 private boolean whileFetching = false;
22 private static final int FETCH_ERROR_MAX = 30;
24 SonyLiveViewControl(@NonNull ISonyCameraApi cameraApi)
26 this.cameraApi = cameraApi;
27 liveViewListener = new CameraLiveViewListenerImpl();
31 public void changeLiveViewSize(String size)
37 public void startLiveView(boolean isCameraScreen)
39 Log.v(TAG, "startLiveView() : " + isCameraScreen);
42 Thread thread = new Thread(new Runnable()
50 replyJson = cameraApi.startLiveview();
51 if (!SonyCameraApi.isErrorReply(replyJson))
55 JSONArray resultsObj = replyJson.getJSONArray("result");
56 if (1 <= resultsObj.length())
58 // Obtain liveview URL from the result.
59 final String liveviewUrl = resultsObj.getString(0);
84 public void stopLiveView()
86 Log.v(TAG, "stopLiveView()");
89 Thread thread = new Thread(new Runnable()
96 JSONObject resultsObj = cameraApi.stopLiveview();
97 if (resultsObj == null)
99 Log.v(TAG, "stopLiveview() reply is null.");
117 public void updateDigitalZoom()
123 public void updateMagnifyingLiveViewScale(boolean isChangeScale)
129 public float getMagnifyingLiveViewScale()
135 public float getDigitalZoomScale()
142 public boolean start(final String streamUrl)
144 if (streamUrl == null)
146 Log.e(TAG, "start() streamUrl is null.");
151 Log.v(TAG, "start() already starting.");
153 whileFetching = true;
155 // A thread for retrieving liveview data from server.
158 Thread thread = new Thread(new Runnable()
163 Log.d(TAG, "Starting retrieving streaming data from server.");
164 SimpleLiveviewSlicer slicer = null;
165 int continuousNullDataReceived = 0;
168 // Create Slicer to open the stream and parse it.
169 slicer = new SimpleLiveviewSlicer();
170 slicer.open(streamUrl);
172 while (whileFetching)
174 final SimpleLiveviewSlicer.Payload payload = slicer.nextPayload();
177 //Log.v(TAG, "Liveview Payload is null.");
178 continuousNullDataReceived++;
179 if (continuousNullDataReceived > FETCH_ERROR_MAX)
181 Log.d(TAG, " FETCH ERROR MAX OVER ");
186 //if (mJpegQueue.size() == 2)
188 // mJpegQueue.remove();
190 //mJpegQueue.add(payload.getJpegData());
191 liveViewListener.onUpdateLiveView(payload.getJpegData(), null);
192 continuousNullDataReceived = 0;
212 //mJpegQueue.clear();
213 if ((!whileFetching)&&(continuousNullDataReceived > FETCH_ERROR_MAX))
215 // 再度ライブビューのスタートをやってみる。
216 whileFetching = false;
217 //continuousNullDataReceived = 0;
232 public ILiveViewListener getLiveViewListener()
234 return (liveViewListener);