From: MRSa Date: Wed, 23 Dec 2020 15:11:21 +0000 (+0900) Subject: JPEGヘッダの探し方(のデフォルト方式)を変更。 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=0d8ad0678d3fe48fe309b272a1107a8b55abe00e;p=gokigen%2FA01d.git JPEGヘッダの探し方(のデフォルト方式)を変更。 --- diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.java index 6ac6bb7..8bfb328 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.java @@ -70,7 +70,7 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay String ipAddress; int delayMs = 30; int sequenceType = 0; - boolean isSearchJpegHeader = false; + boolean isSearchJpegHeader = true; try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -107,11 +107,9 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay { e.printStackTrace(); } - if (sequenceType == 1) - { - Log.v(TAG, " --- search JPEG header : true "); - isSearchJpegHeader = true; - } + + isSearchJpegHeader = !(sequenceType == 2); + Log.v(TAG, " --- search JPEG header : " + isSearchJpegHeader); } catch (Exception e) { diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.kt b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.kt new file mode 100644 index 0000000..b67ba8f --- /dev/null +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.kt @@ -0,0 +1,194 @@ +package net.osdn.gokigen.a01d.camera.canon.wrapper.liveview + +import android.app.Activity +import android.util.Log +import net.osdn.gokigen.a01d.camera.ILiveViewControl +import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider +import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication +import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages +import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGenericWithRetry +import net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview.IPtpIpLiveViewImageCallback +import net.osdn.gokigen.a01d.liveview.liveviewlistener.IImageDataReceiver +import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener +import java.util.* + +class CanonLiveViewControl(context: Activity, interfaceProvider: IPtpIpInterfaceProvider, private val delayMs: Int, private val isSearchJpegHeader: Boolean) : ILiveViewControl, ILiveViewListener, IPtpIpCommunication, IPtpIpLiveViewImageCallback +{ + private val commandIssuer = interfaceProvider.commandPublisher + private val isDumpLog = false + private val retryCount = 1200 + private val imageReceiver = CanonLiveViewImageReceiver(context, this) + private var dataReceiver: IImageDataReceiver? = null + private var liveViewIsReceiving = false + private var commandIssued = false + + fun getLiveViewListener(): ILiveViewListener + { + return (this) + } + + private fun mainLoop() + { + if (!commandIssued) + { + if (isDumpLog) + { + Log.v(TAG, " enqueueCommand() [ queue size : ${commandIssuer.currentQueueSize} ] ") + } + if (commandIssuer.currentQueueSize < 3) + { + commandIssued = true + commandIssuer.enqueueCommand(PtpIpCommandGenericWithRetry(imageReceiver, IPtpIpMessages.SEQ_GET_VIEWFRAME, delayMs, retryCount, isRetry = false, isDumpLog = false, holdId = 0, opcode = 0x9153, bodySize = 12, value = 0x00200000, value2 = 0x01, value3 = 0x00, value4 = 0x00)) + } + } + try + { + Thread.sleep(delayMs.toLong()) + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + override fun changeLiveViewSize(size: String) {} + + override fun startLiveView() + { + Log.v(TAG, " startLiveView() : delay $delayMs ms.") + liveViewIsReceiving = true + try + { + val thread = Thread { + try + { + while (liveViewIsReceiving) + { + mainLoop() + } + } + catch (e: Exception) + { + e.printStackTrace() + } + } + thread.start() + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + override fun stopLiveView() + { + Log.v(TAG, " stopLiveView() ") + liveViewIsReceiving = false + } + + override fun updateDigitalZoom() + { + Log.v(TAG, " updateDigitalZoom() ") + } + + override fun updateMagnifyingLiveViewScale(isChangeScale: Boolean) + { + Log.v(TAG, " updateMagnifyingLiveViewScale() ") + } + + override fun getMagnifyingLiveViewScale(): Float + { + return (0.0f) + } + + override fun getDigitalZoomScale(): Float + { + return (0.0f) + } + + override fun setCameraLiveImageView(target: IImageDataReceiver) + { + Log.v(TAG, " setCameraLiveImageView() ") + dataReceiver = target + } + + override fun connect(): Boolean + { + Log.v(TAG, " connect() ") + return (true) + } + + override fun disconnect() + { + Log.v(TAG, " disconnect() ") + } + + override fun onCompleted(data: ByteArray?, metadata: Map?) + { + //Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- "); + try + { + if ((dataReceiver != null)&&(data != null)) + { + if (isDumpLog) + { + Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- : " + data.size + " bytes.") + } + val headerSize = searchJpegHeader(data) + if (headerSize >= 0) + { + dataReceiver?.setImageData(Arrays.copyOfRange(data, headerSize, data.size), metadata) // ヘッダ部分を切り取って送る + } + } + } + catch (e: Exception) + { + e.printStackTrace() + } + commandIssued = false + } + + private fun searchJpegHeader(data: ByteArray): Int + { + if (data.size <= 8) + { + return -1 + } + if (!isSearchJpegHeader) + { + // JPEG ヘッダを探さない場合は、8バイト固定とする + return (8) + } + try + { + val size = (data.size - 1) + var index = 0 + while (index < size) + { + if (data[index] == 0xff.toByte() && data[index + 1] == 0xd8.toByte()) + { + return (index) + } + index++ + } + } + catch (e: Exception) + { + e.printStackTrace() + } + + // 見つからなかったときは 8 を返す + return (8) + } + + override fun onErrorOccurred(e: Exception) + { + Log.v(TAG, " onErrorOccurred () : " + e.localizedMessage) + commandIssued = false + } + + companion object + { + private const val TAG = "CanonLiveViewControl" + } +} diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControlPrev.java similarity index 89% rename from app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.java rename to app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControlPrev.java index 49ae960..25e000d 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControlPrev.java @@ -19,7 +19,7 @@ import java.util.Map; import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_VIEWFRAME; -public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication, IPtpIpLiveViewImageCallback +public class CanonLiveViewControlPrev implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication, IPtpIpLiveViewImageCallback { private final String TAG = this.toString(); private final IPtpIpCommandPublisher commandIssuer; @@ -32,7 +32,7 @@ public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener private boolean liveViewIsReceiving = false; private boolean commandIssued = false; - public CanonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs, boolean isSearchJpegHeader) + public CanonLiveViewControlPrev(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs, boolean isSearchJpegHeader) { this.commandIssuer = interfaceProvider.getCommandPublisher(); this.isSearchJpegHeader = isSearchJpegHeader; @@ -73,8 +73,11 @@ public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener { Log.v(TAG, " enqueueCommand() "); } - commandIssued = true; - commandIssuer.enqueueCommand(new PtpIpCommandGenericWithRetry(imageReceiver, SEQ_GET_VIEWFRAME, delayMs, retryCount, false, false, 0, 0x9153, 12, 0x00200000, 0x01, 0x00, 0x00)); + if (commandIssuer.getCurrentQueueSize() < 3) + { + commandIssued = true; + commandIssuer.enqueueCommand(new PtpIpCommandGenericWithRetry(imageReceiver, SEQ_GET_VIEWFRAME, delayMs, retryCount, false, false, 0, 0x9153, 12, 0x00200000, 0x01, 0x00, 0x00)); + } } try { diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.kt b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.kt index 8b2d805..a1ec671 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.kt +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.kt @@ -168,7 +168,7 @@ class CanonLiveViewImageReceiver(val activity: Activity, val callback: IPtpIpLiv companion object { - private val TAG = "CanonLiveViewReceiver" + private const val TAG = "CanonLiveViewReceiver" } } \ No newline at end of file diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisherLegacy.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisherLegacy.java index ca5959e..ae5affa 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisherLegacy.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisherLegacy.java @@ -254,6 +254,14 @@ public class PtpIpCommandPublisherLegacy implements IPtpIpCommandPublisher, IPtp return (commandQueue.size()); } + @Override + public boolean flushQueue() + { + Log.v(TAG, " flushHoldQueue() : CLEAR QUEUE : " + commandQueue.size()); + commandQueue.clear(); + System.gc(); + return (true); + } @Override public int isExistCommandMessageQueue(int id) diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/liveview/IPtpIpLiveViewImageCallback.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/liveview/IPtpIpLiveViewImageCallback.java index 749fe9e..d438492 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/liveview/IPtpIpLiveViewImageCallback.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/liveview/IPtpIpLiveViewImageCallback.java @@ -1,9 +1,11 @@ package net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview; +import androidx.annotation.Nullable; + import java.util.Map; public interface IPtpIpLiveViewImageCallback { - void onCompleted(byte[] data, Map metadata); + void onCompleted(@Nullable byte[] data, @Nullable Map metadata); void onErrorOccurred(Exception e); }