OSDN Git Service

LVとシャッター制御確認中。
authorMRSa <mrsa@myad.jp>
Sun, 9 Feb 2020 12:54:00 +0000 (21:54 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 9 Feb 2020 12:54:00 +0000 (21:54 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/operation/CanonCaptureControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/connection/CanonCameraConnectSequence.java
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/ICanonLiveViewImageCallback.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/status/CanonStatusChecker.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpMessages.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java

index f6ed42d..74b09b2 100644 (file)
@@ -1,27 +1,65 @@
 package net.osdn.gokigen.a01d.camera.canon.operation;
 
+import android.util.Log;
+
 import androidx.annotation.NonNull;
 
 import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 
-public class CanonCaptureControl implements ICaptureControl
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.REQUEST_SHUTTER_OFF;
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.REQUEST_SHUTTER_ON;
+
+public class CanonCaptureControl implements ICaptureControl, IPtpIpCommandCallback
 {
+    private final String TAG = this.toString();
     private final PtpIpCommandPublisher commandPublisher;
     private final IAutoFocusFrameDisplay frameDisplayer;
+    private boolean isDumpLog = true;
 
     public CanonCaptureControl(@NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer)
     {
         this.commandPublisher = commandPublisher;
         this.frameDisplayer = frameDisplayer;
-
     }
 
 
     @Override
     public void doCapture(int kind)
     {
+        try
+        {
+            // シャッター
+            Log.v(TAG, " doCapture() ");
+
+            // シャッターONとOFF
+            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, REQUEST_SHUTTER_ON, isDumpLog, 0, 0x9128, 8, 0x03, 0x00));
+            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, REQUEST_SHUTTER_OFF, isDumpLog, 0, 0x9129, 4, 0x03));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
 
+    @Override
+    public void receivedMessage(int id, byte[] rx_body)
+    {
+        Log.v(TAG, " CanonCaptureControl::receivedMessage() : ");
+    }
+
+    @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
+    {
+        Log.v(TAG, " CanonCaptureControl::onReceiveProgress() : " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
     }
 }
index 6664494..5445131 100644 (file)
@@ -41,7 +41,6 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
 {
     private final String TAG = toString();
 
-    private static final int STREAM_PORT = 15742;   // ??
     private static final int ASYNC_RESPONSE_PORT = 15741;  // ??
     private static final int CONTROL_PORT = 15740;
     private static final int EVENT_PORT = 15740;
@@ -65,7 +64,7 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     {
         this.activity = context;
         commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT);
-        liveViewControl = new CanonLiveViewControl(context, CAMERA_IP, STREAM_PORT);
+        liveViewControl = new CanonLiveViewControl(context, this, 10);  //
         asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
         statusChecker = new CanonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
         canonConnection = new CanonConnection(context, provider, this, statusChecker);
@@ -79,7 +78,7 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     @Override
     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
     {
-        Log.v(TAG, "injectDisplay()");
+        Log.v(TAG, " injectDisplay()");
         captureControl = new CanonCaptureControl(commandPublisher, frameDisplayer);
         focusingControl = new CanonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
     }
index 36d60c7..10d2b1b 100644 (file)
@@ -29,7 +29,7 @@ public class CanonCameraConnectSequence implements Runnable, IPtpIpCommandCallba
     private final IPtpIpInterfaceProvider interfaceProvider;
     private final IPtpIpCommandPublisher commandIssuer;
     private final CanonStatusChecker statusChecker;
-    private boolean isDumpLog = true;
+    private boolean isDumpLog = false;
 
     CanonCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull CanonStatusChecker statusChecker)
     {
index daf3b1f..dc6e2b5 100644 (file)
@@ -6,23 +6,32 @@ import android.util.Log;
 import androidx.annotation.NonNull;
 
 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.IImageDataReceiver;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
 
-public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication
-{
-    private final String TAG = this.toString();
+import java.util.Map;
 
-    private final Activity context;
-    private final String ipAddr;
-    private final int portNo;
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_VIEWFRAME;
 
-    public CanonLiveViewControl(@NonNull Activity context, @NonNull String ipAddr, int portNo)
+public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication, ICanonLiveViewImageCallback
+{
+    private final String TAG = this.toString();
+    private final IPtpIpCommandPublisher commandIssuer;
+    private final int delayMs;
+    private CanonLiveViewImageReceiver imageReceiver;
+    private IImageDataReceiver dataReceiver = null;
+    private boolean liveViewIsReceiving = false;
+    private boolean commandIssued = false;
+
+    public CanonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs)
     {
-        this.context = context;
-        this.ipAddr = ipAddr;
-        this.portNo = portNo;
+        this.commandIssuer = interfaceProvider.getCommandPublisher();
+        this.delayMs = delayMs;
+        this.imageReceiver = new CanonLiveViewImageReceiver(this);
     }
 
     public ILiveViewListener getLiveViewListener()
@@ -40,26 +49,65 @@ public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener
     public void startLiveView()
     {
         Log.v(TAG, " startLiveView() ");
-
+        liveViewIsReceiving = true;
+        try
+        {
+            Thread thread = new Thread(new Runnable() {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        while (liveViewIsReceiving)
+                        {
+                            if (!commandIssued)
+                            {
+                                commandIssued = true;
+                                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(imageReceiver, SEQ_GET_VIEWFRAME, false, 0, 0x9153, 12, 0x00200000, 0x01, 0x00));
+                            }
+                            try
+                            {
+                                Thread.sleep(delayMs);
+                            }
+                            catch (Exception e)
+                            {
+                                e.printStackTrace();
+                            }
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     @Override
     public void stopLiveView()
     {
         Log.v(TAG, " stopLiveView() ");
+        liveViewIsReceiving = false;
 
     }
 
     @Override
     public void updateDigitalZoom()
     {
+        Log.v(TAG, " updateDigitalZoom() ");
 
     }
 
     @Override
     public void updateMagnifyingLiveViewScale(boolean isChangeScale)
     {
-
+        Log.v(TAG, " updateMagnifyingLiveViewScale() ");
     }
 
     @Override
@@ -77,7 +125,8 @@ public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener
     @Override
     public void setCameraLiveImageView(IImageDataReceiver target)
     {
-
+        Log.v(TAG, " setCameraLiveImageView() ");
+        this.dataReceiver = target;
     }
 
     @Override
@@ -92,4 +141,29 @@ public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener
     {
         Log.v(TAG, " disconnect() ");
     }
+
+    @Override
+    public void onCompleted(byte[] data, Map<String, Object> metadata)
+    {
+        // Log.v(TAG, "RECEIVED LV IMAGE");
+        commandIssued = false;
+        try
+        {
+            if (dataReceiver != null)
+            {
+                dataReceiver.setImageData(data, metadata);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void onErrorOccurred(Exception e)
+    {
+        Log.v(TAG, " onErrorOccurred () : " + e.getLocalizedMessage());
+        commandIssued = false;
+    }
 }
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.java
new file mode 100644 (file)
index 0000000..526ff46
--- /dev/null
@@ -0,0 +1,71 @@
+package net.osdn.gokigen.a01d.camera.canon.wrapper.liveview;
+
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
+
+import java.util.Arrays;
+
+/**
+ *   Canonサムネイル画像の受信
+ *
+ *
+ */
+public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
+{
+    private final String TAG = toString();
+    private final ICanonLiveViewImageCallback callback;
+
+    CanonLiveViewImageReceiver(@NonNull ICanonLiveViewImageCallback callback)
+    {
+        this.callback = callback;
+    }
+
+    @Override
+    public void receivedMessage(int id, byte[] rx_body)
+    {
+        try
+        {
+            if (rx_body == null)
+            {
+                Log.v(TAG, " BITMAP IS NONE...");
+                callback.onCompleted(null, null);
+                return;
+            }
+
+            /////// 受信データから、サムネイルの先頭(0xff 0xd8)を検索する  /////
+            int offset = rx_body.length - 22;
+            //byte[] thumbnail0 = Arrays.copyOfRange(rx_body, 0, rx_body.length);
+            while (offset > 32)
+            {
+                if ((rx_body[offset] == (byte) 0xff)&&((rx_body[offset + 1] == (byte) 0xd8)))
+                {
+                    break;
+                }
+                offset--;
+            }
+            byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length);
+            callback.onCompleted(thumbnail, null);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            {
+                callback.onErrorOccurred(e);
+            }
+        }
+    }
+
+    @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/ICanonLiveViewImageCallback.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/ICanonLiveViewImageCallback.java
new file mode 100644 (file)
index 0000000..0697262
--- /dev/null
@@ -0,0 +1,11 @@
+package net.osdn.gokigen.a01d.camera.canon.wrapper.liveview;
+
+import android.graphics.Bitmap;
+
+import java.util.Map;
+
+public interface ICanonLiveViewImageCallback
+{
+    void onCompleted(byte[] data, Map<String, Object> metadata);
+    void onErrorOccurred(Exception  e);
+}
index 329d7e5..e1897c1 100644 (file)
@@ -83,6 +83,7 @@ public class CanonStatusChecker implements IPtpIpCommandCallback, ICameraStatusW
                 Log.v(TAG, "received status length is short. (" + data.length + " bytes.)");
                 return;
             }
+/*
             int nofStatus = (data[13] * 256) + data[12];
             int statusCount = 0;
             int index = STATUS_MESSAGE_HEADER_SIZE;
@@ -93,6 +94,7 @@ public class CanonStatusChecker implements IPtpIpCommandCallback, ICameraStatusW
                 index = index + 6;
                 statusCount++;
             }
+*/
         }
         catch (Exception e)
         {
index 497d093..1bff162 100644 (file)
@@ -34,6 +34,9 @@ public interface IPtpIpMessages
     int GET_STORAGE_HANDLE3 = 112;
     int GET_PARTIAL_OBJECT= 113;
 
+    int REQUEST_SHUTTER_ON = 200;
+    int REQUEST_SHUTTER_OFF = 201;
+
 /*
     int SEQ_REGISTRATION = 1;
     int SEQ_START = 2;
index 2049d1d..99e0d88 100644 (file)
@@ -146,6 +146,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                                 issueCommand(command);
                             }
                             Thread.sleep(COMMAND_POLL_QUEUE_MS);
+                            // Log.v(TAG, " QUEUE SIZE : " + commandQueue.size());
                         }
                         catch (Exception e)
                         {
@@ -580,10 +581,12 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             {
                 lenlen = ((((int) byte_array[position + 3]) & 0xff) << 24) + ((((int) byte_array[position + 2]) & 0xff) << 16) + ((((int) byte_array[position + 1]) & 0xff) << 8) + (((int) byte_array[position]) & 0xff);
                 packetType = (((int) byte_array[position + 4]) & 0xff);
+/*
                 if (packetType != 0x0a)
                 {
                     Log.v(TAG, " <><><> PACKET TYPE : " + packetType + " LENGTH : " + lenlen);
                 }
+*/
                 int copyByte = ((lenlen - 12) > (limit - (position + 12))) ? (limit - (position + 12)) : (lenlen - 12);
                 outputStream.write(byte_array, (position + 12), copyByte);
                 position = position + lenlen;