1 package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.status;
3 import android.util.Log;
5 import androidx.annotation.NonNull;
7 import net.osdn.gokigen.a01d.camera.ICameraStatus;
8 import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
9 import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
11 import java.util.List;
13 import static net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper.dump_bytes;
15 public class OlympusPenCameraStatusWatcher implements ICameraStatusWatcher, ICameraStatus
17 private final String TAG = toString();
19 private byte[] buffer = null;
20 private boolean isWatching = false;
21 private boolean statusReceived = false;
22 private final int SLEEP_TIME_MS = 250;
23 private ICameraStatusUpdateNotify notifier = null;
24 private int focusingStatus = 0;
25 private static final int ID_FRAME_SIZE = 1;
26 private static final int ID_AF_FRAME_INFO = 2;
27 private static final int ID_ZOOM_LENS_INFO = 18;
30 public OlympusPenCameraStatusWatcher()
35 public void setRtpHeader(byte[] byteBuffer)
40 statusReceived = true;
45 statusReceived = false;
50 public void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier)
54 this.notifier = notifier;
55 Thread thread = new Thread(new Runnable() {
59 int waitMs = SLEEP_TIME_MS;
67 statusReceived = false;
81 private void sleep(int waitMs)
93 private void parseRtpHeader()
99 Log.v(TAG, " parseRtpHeader() : null");
103 int maxLength = buffer.length;
104 while ((position + 4) < maxLength)
106 int id = ((buffer[position] & 0xff) * 256) + (buffer[position + 1] & 0xff);
107 int length = ((buffer[position + 2] & 0xff) * 256) + (buffer[position + 3] & 0xff);
110 case ID_AF_FRAME_INFO:
112 checkFocused(buffer, position, length);
115 case ID_ZOOM_LENS_INFO:
119 // Log.v(TAG, " ID : " + id + " LENGTH : " + length);
122 position = position + 4 + (length * 4); // header : 4bytes , data : length * 4 bytes
131 private void checkFocused(byte[] buffer, int position, int length)
135 // データがそろっていないので何もしない
138 int status = (buffer[position + 7] & 0xff);
139 if (status != focusingStatus)
141 boolean focus = (status == 1);
142 boolean isError = (status == 2);
143 //Log.v(TAG, "FOCUS : " + focus + "(" + isError + ") " + status);
144 notifier.updateFocusedStatus(focus, isError);
145 focusingStatus = status;
150 public void stopStatusWatch()
156 public List<String> getStatusList(String key)
162 public String getStatus(String key)
168 public void setStatus(String key, String value)