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;
29 public OlympusPenCameraStatusWatcher()
34 public void setRtpHeader(byte[] byteBuffer)
39 statusReceived = true;
44 statusReceived = false;
49 public void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier)
53 this.notifier = notifier;
54 Thread thread = new Thread(new Runnable() {
58 int waitMs = SLEEP_TIME_MS;
66 statusReceived = false;
80 private void sleep(int waitMs)
92 private void parseRtpHeader()
98 Log.v(TAG, " parseRtpHeader() : null");
102 int maxLength = buffer.length;
103 while ((position + 4) < maxLength)
105 int id = ((buffer[position] & 0xff) * 256) + (buffer[position + 1] & 0xff);
106 int length = ((buffer[position + 2] & 0xff) * 256) + (buffer[position + 3] & 0xff);
109 case ID_AF_FRAME_INFO:
111 checkFocused(buffer, position, length);
116 // Log.v(TAG, " ID : " + id + " LENGTH : " + length);
119 position = position + 4 + (length * 4); // header : 4bytes , data : length * 4 bytes
128 private void checkFocused(byte[] buffer, int position, int length)
132 // データがそろっていないので何もしない
135 int status = (buffer[position + 7] & 0xff);
136 if (status != focusingStatus)
138 boolean focus = (status == 1);
139 boolean isError = (status == 2);
140 notifier.updateFocusedStatus(focus, isError);
141 focusingStatus = status;
146 public void stopStatusWatch()
152 public List<String> getStatusList(String key)
158 public String getStatus(String key)
164 public void setStatus(String key, String value)