OSDN Git Service

とりあえず保管。
authorMRSa <mrsa@myad.jp>
Sun, 1 Mar 2020 07:49:55 +0000 (16:49 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 1 Mar 2020 07:49:55 +0000 (16:49 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/operation/NikonFocusingControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonLiveViewRequestMessage.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewImageReceiver.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpCommand.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/messages/PtpIpCommandBase.java

index 0a39cf1..d19811d 100644 (file)
@@ -137,8 +137,7 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
             int y = (0x0000ffff & (Math.round(point.y * maxPointLimitHeight) + 1));
             Log.v(TAG, "Lock AF: [" + x + ","+ y + "]");
             commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_LOCK, isDumpLog, 0, 0x9205, 8, x, y));
-            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
-
+            //commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
         }
         catch (Exception e)
         {
@@ -215,6 +214,7 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
             if ((id == FOCUS_LOCK)||(id == FOCUS_LOCK_PRE))
             {
                 Log.v(TAG, "FOCUS LOCKED");
+                commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));  // OKのときは駆動
                 if (preFocusFrameRect != null)
                 {
                     // showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Focused, 1.0);  // 1秒だけ表示
@@ -251,6 +251,6 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     @Override
     public boolean isReceiveMulti()
     {
-        return (false);
+        return (true);
     }
 }
index 4186ee2..aea84a0 100644 (file)
@@ -11,7 +11,6 @@ import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
 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.IPtpIpResponseReceiver;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpResponseReceiver;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview.IPtpIpLiveViewImageCallback;
@@ -103,7 +102,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
                             if (!commandIssued)
                             {
                                 commandIssued = true;
-                                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 90, isDumpLog));
+                                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 30, isDumpLog));
                             }
                             try
                             {
@@ -185,7 +184,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
                 //Log.v(TAG, "  ---+++--- RECEIVED LV IMAGE ---+++--- : " + data.length + " bytes.");
                 //SimpleLogDumper.dump_bytes(" [LVLV] " + ": ", Arrays.copyOfRange(data, 0, (0 + 512)));
                 //dataReceiver.setImageData(data, metadata);
-                int offset = 384;
+                int offset = searchJpegHeader(data);
                 if (data.length > 8)
                 {
                     dataReceiver.setImageData(Arrays.copyOfRange(data, offset, data.length), metadata);  // ヘッダ部分を切り取って送る
@@ -199,6 +198,32 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
         commandIssued = false;
     }
 
+    private int searchJpegHeader(byte[] data)
+    {
+        try
+        {
+            int pos = 0;
+
+            // 先頭の 1024bytesまで
+            int limit = (data.length < 1024) ? (data.length - 1): 1024;
+            while (pos < limit)
+            {
+                if ((data[pos] == (byte) 0xff)&&(data[pos + 1] == (byte) 0xd8))
+                {
+
+                    return (pos);
+                }
+                pos++;
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (384);
+    }
+
+
     @Override
     public void onErrorOccurred(Exception e)
     {
index 10fb5dd..865a52b 100644 (file)
@@ -5,8 +5,10 @@ import android.util.Log;
 import androidx.annotation.NonNull;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview.IPtpIpLiveViewImageCallback;
+import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
 
 import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
 
 public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
 {
@@ -30,12 +32,70 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
     @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
+        if (isReceiveMulti())
+        {
+            receivedMessage_multi(id, rx_body);
+        }
+        else
+        {
+            receivedMessage_single(id, rx_body);
+        }
+    }
+
+    @Override
+    public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
+    {
+        int body_length = 0;
+        if (rx_body != null)
+        {
+            body_length = rx_body.length;
+        }
+        Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " LENGTH: " + body_length + " bytes.");
+
+        // 受信したデータから、通信のヘッダ部分を削除する
+        cutHeader(rx_body);
+    }
+
+    private void receivedMessage_single(int id, byte[] rx_body)
+    {
         try
         {
+            if (rx_body != null)
+            {
+                Log.v(TAG, "receivedMessage_single() : " + rx_body.length + " bytes.");
+                if (rx_body.length > 64)
+                {
+                    SimpleLogDumper.dump_bytes(" LV (FIRST) : ", Arrays.copyOfRange(rx_body, 0, 64));
+                    SimpleLogDumper.dump_bytes(" LV (-END-) : ", Arrays.copyOfRange(rx_body, (rx_body.length - 64), rx_body.length));
+                }
+                callback.onCompleted(rx_body, null);
+            }
+            else
+            {
+                Log.v(TAG, "receivedMessage_single() : NULL");
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void receivedMessage_multi(int id, byte[] rx_body)
+    {
+        try
+        {
+            int body_length = 0;
+            if (rx_body != null)
+            {
+                body_length = rx_body.length;
+            }
+            Log.v(TAG, " receivedMessage_multi()  id[" + id + "] size : " + body_length + " target length : " +  target_image_size + " ");
+
             // end of receive sequence.
-            byte [] thumbnail = byteStream.toByteArray();
+            //byte [] thumbnail = byteStream.toByteArray();
             //byte [] thumbnail = rx_body;
-            Log.v(TAG, " TransferComplete() RECEIVED  id[" + id + "] size : " + target_image_size + " (" + thumbnail.length + ")");
+            //Log.v(TAG, " TransferComplete() RECEIVED  id[" + id + "] size : " + target_image_size + " (" + thumbnail.length + ")");
             //SimpleLogDumper.dump_bytes(" [xxxxx]", Arrays.copyOfRange(thumbnail, 0, (512)));
             //SimpleLogDumper.dump_bytes(" [zzzzz]", Arrays.copyOfRange(thumbnail, (thumbnail.length - 128), (thumbnail.length)));
             callback.onCompleted(byteStream.toByteArray(), null);
@@ -55,15 +115,6 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
         }
     }
 
-    @Override
-    public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
-    {
-        //Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
-
-        // 受信したデータから、通信のヘッダ部分を削除する
-        cutHeader(rx_body);
-    }
-
     private void cutHeader(byte[] rx_body)
     {
         if (rx_body == null)
index 950a180..787b589 100644 (file)
@@ -58,4 +58,8 @@ public interface IPtpIpCommand
 
     // 受信待ち再試行回数
     int maxRetryCount();
+
+    // リトライオーバーで再送するとき、SeqNoをインクリメントするか
+    boolean isIncrementSequenceNumberToRetry();
+
 }
index 9b2cb9b..883043d 100644 (file)
@@ -275,8 +275,11 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                         //  コマンドを再送信しない場合はここで抜ける
                         break;
                     }
-                    // 再送信...のために、シーケンス番号を戻す...
-                    sequenceNumber--;
+                    if (!command.isIncrementSequenceNumberToRetry())
+                    {
+                        // 再送信...のために、シーケンス番号を戻す...
+                        sequenceNumber--;
+                    }
                 }
             }
         }
@@ -387,6 +390,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             if (is == null)
             {
                 Log.v(TAG, " InputStream is NULL... RECEIVE ABORTED.");
+                receivedAllMessage(isDumpReceiveLog, id, null, callback);
                 return (false);
             }
 
@@ -396,6 +400,11 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             {
                 // リトライオーバー...
                 Log.v(TAG, " RECEIVE : RETRY OVER...");
+                if (!command.isRetrySend())
+                {
+                    // 再送しない場合には、応答がないことを通知する
+                    receivedAllMessage(isDumpReceiveLog, id, null, callback);
+                }
                 return (true);
             }
 
index ced2c4a..1790bb2 100644 (file)
@@ -119,4 +119,11 @@ public class PtpIpCommandBase implements IPtpIpCommand, IPtpIpMessages
     {
         return (20);
     }
+
+    @Override
+    public boolean isIncrementSequenceNumberToRetry()
+    {
+        return (false);
+    }
+
 }