1 package jp.osdn.gokigen.gokigenassets.camera.vendor.omds.status
3 import android.graphics.Color
4 import android.util.Log
5 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus
6 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusUpdateNotify
7 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusWatcher
8 import jp.osdn.gokigen.gokigenassets.liveview.message.IMessageDrawer
9 import java.lang.Exception
10 import kotlin.collections.ArrayList
12 class OmdsCameraStatusWatcher() : ICameraStatusWatcher, ICameraStatus
14 private var buffer: ByteArray? = null
15 private var isWatching = false
16 private var statusReceived = false
17 private var notifier: ICameraStatusUpdateNotify? = null
18 private var focusingStatus = 0
20 fun setRtpHeader(byteBuffer: ByteArray?)
24 //buffer = byteBuffer?.copyOf()
25 if (byteBuffer != null)
32 statusReceived = false
38 statusReceived = false
42 override fun startStatusWatch(indicator: IMessageDrawer?, notifier: ICameraStatusUpdateNotify?)
46 this.notifier = notifier
48 val waitMs = SLEEP_TIME_MS
56 statusReceived = false
69 private fun sleep(waitMs: Int)
73 Thread.sleep(waitMs.toLong())
81 private fun parseRtpHeader()
87 Log.v(TAG, " parseRtpHeader() : null")
91 val maxLength = buffer?.size ?: 0
92 while (position + 4 < maxLength)
94 val id: Int = ((buffer?.get(position) ?: 0).toInt() and 0xff) * 256 + ((buffer?.get(position + 1) ?: 0).toInt() and 0xff)
95 val length: Int = ((buffer?.get(position + 2) ?: 0).toInt() and 0xff) * 256 + ((buffer?.get(position + 3) ?: 0).toInt() and 0xff)
98 ID_AF_FRAME_INFO -> { checkFocused(buffer, position, length) }
99 ID_ZOOM_LENS_INFO, ID_FRAME_SIZE -> { }
102 position += 4 + length * 4 // header : 4bytes , data : length * 4 bytes
111 private fun checkFocused(buffer: ByteArray?, position: Int, length: Int)
113 if ((length != 5)||(buffer == null))
115 // データがそろっていないので何もしない
118 val status: Int = buffer[position + 7].toInt() and 0xff
119 if (status != focusingStatus)
121 // ドライブ停止時には、マーカの色は消さない
124 val focus = status == 1
125 val isError = status == 2
126 notifier?.updateFocusedStatus(focus, isError)
128 focusingStatus = status
132 override fun stopStatusWatch()
137 override fun getStatusList(key: String): List<String>
142 override fun getStatus(key: String): String
147 override fun getStatusColor(key: String): Int
152 override fun setStatus(key: String, value: String)
159 private val TAG = OmdsCameraStatusWatcher::class.java.simpleName
161 private const val SLEEP_TIME_MS = 250
162 private const val ID_FRAME_SIZE = 1
163 private const val ID_AF_FRAME_INFO = 2
164 private const val ID_ZOOM_LENS_INFO = 18