• R/O
  • HTTP
  • SSH
  • HTTPS

A01d: Commit

OPC(Olympus Air)用望遠鏡アプリ。


Commit MetaInfo

Revision0519d4945d1249b23d7e01d4fb4cac097d4f6637 (tree)
Zeit2020-02-14 00:18:17
AutorMRSa <mrsa@myad...>
CommiterMRSa

Log Message

すこし画像表示の安定性を向上。

Ändern Zusammenfassung

Diff

--- 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/CanonLiveViewControl.java
@@ -146,13 +146,17 @@ public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener
146146 @Override
147147 public void onCompleted(byte[] data, Map<String, Object> metadata)
148148 {
149- // Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- ");
149+ //Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- ");
150150 try
151151 {
152152 if ((dataReceiver != null)&&(data != null))
153153 {
154+ Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- : " + data.length + " bytes.");
154155 //dataReceiver.setImageData(data, metadata);
155- dataReceiver.setImageData(Arrays.copyOfRange(data, 8, data.length), metadata);
156+ if (data.length > 8)
157+ {
158+ dataReceiver.setImageData(Arrays.copyOfRange(data, 8, data.length), metadata); // ヘッダ部分を切り取って送る
159+ }
156160 }
157161 }
158162 catch (Exception e)
--- 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
@@ -4,106 +4,8 @@ import android.util.Log;
44
55 import androidx.annotation.NonNull;
66 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
7-import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
87
98 import java.io.ByteArrayOutputStream;
10-import java.util.Arrays;
11-
12-/**
13- * Canonサムネイル画像の受信
14- *
15- *
16- */
17-/*
18-public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
19-{
20- private final String TAG = toString();
21- private final ICanonLiveViewImageCallback callback;
22- private ByteArrayOutputStream byteStream;
23-
24- CanonLiveViewImageReceiver(@NonNull ICanonLiveViewImageCallback callback)
25- {
26- this.callback = callback;
27- byteStream = new ByteArrayOutputStream();
28- }
29-
30-
31- public void reset()
32- {
33- try
34- {
35- byteStream.flush();
36- }
37- catch (Exception e)
38- {
39- e.printStackTrace();
40- }
41- byteStream.reset();
42- }
43-
44-
45- @Override
46- public void receivedMessage(int id, byte[] rx_body)
47- {
48- try
49- {
50- if (rx_body == null)
51- {
52- Log.v(TAG, " BITMAP IS NONE...");
53- callback.onCompleted(null, null);
54- return;
55- }
56- Log.v(TAG, " CanonLiveViewImageReceiver::receivedMessage() : " + rx_body.length);
57-
58- /////// 受信データから、サムネイルの先頭(0xff 0xd8)を検索する /////
59- int offset = rx_body.length - 22;
60- //byte[] thumbnail0 = Arrays.copyOfRange(rx_body, 0, rx_body.length);
61- while (offset > 32)
62- {
63- if ((rx_body[offset] == (byte) 0xff)&&((rx_body[offset + 1] == (byte) 0xd8)))
64- {
65- break;
66- }
67- offset--;
68- }
69- byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length);
70- callback.onCompleted(thumbnail, null);
71- }
72- catch (Exception e)
73- {
74- e.printStackTrace();
75- {
76- callback.onErrorOccurred(e);
77- }
78- }
79- }
80-
81- @Override
82- public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
83- {
84- Log.v(TAG, " " + currentBytes + "/" + totalBytes);
85- try
86- {
87- if (byteStream != null)
88- {
89- byteStream.write(body, 0, currentBytes);
90- }
91- }
92- catch (Exception e)
93- {
94- e.printStackTrace();
95- }
96- }
97-
98- @Override
99- public boolean isReceiveMulti()
100- {
101- return (true);
102- }
103-}
104-
105-*/
106-
1079
10810 public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
10911 {
@@ -154,9 +56,10 @@ public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
15456 @Override
15557 public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
15658 {
59+ // Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
60+
15761 // 受信したデータから、通信のヘッダ部分を削除する
15862 cutHeader(rx_body);
159- Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
16063 }
16164
16265 private void cutHeader(byte[] rx_body)
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java
@@ -4,6 +4,8 @@ import android.util.Log;
44
55 import androidx.annotation.NonNull;
66
7+import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
8+
79 import java.io.BufferedReader;
810 import java.io.ByteArrayOutputStream;
911 import java.io.DataOutputStream;
@@ -439,7 +441,8 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
439441
440442 private boolean receive_multi(@NonNull IPtpIpCommand command, int delayMs)
441443 {
442- int estimatedSize = command.estimatedReceiveDataSize();
444+ //int estimatedSize = command.estimatedReceiveDataSize();
445+ int maxRetryCount = 20;
443446 int id = command.getId();
444447 IPtpIpCommandCallback callback = command.responseCallback();
445448
@@ -472,7 +475,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
472475 // 一時的な処理
473476 if (callback != null)
474477 {
475- Log.v(TAG, " --- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : total_length : " + target_length + " buffer SIZE : " + byte_array.length);
478+ Log.v(TAG, " --- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : target_length : " + target_length + " buffer SIZE : " + byte_array.length);
476479 callback.onReceiveProgress(received_length, target_length, Arrays.copyOfRange(byte_array, 0, received_length));
477480 }
478481
@@ -482,10 +485,12 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
482485 read_bytes = is.available();
483486 if (read_bytes == 0)
484487 {
485- Log.v(TAG, " WAIT is.available() ... " + received_length + " < " + estimatedSize);
488+ Log.v(TAG, " WAIT is.available() ... [" + received_length + ", " + target_length + "] retry : " + maxRetryCount);
489+ maxRetryCount--;
486490 }
487- } while ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
488- while (read_bytes > 0)
491+ } while ((read_bytes == 0)&&(maxRetryCount > 0)&&(received_length < target_length)); // ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
492+
493+ while ((read_bytes >= 0)&&(received_length < target_length))
489494 {
490495 read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
491496 if (read_bytes <= 0)
@@ -503,12 +508,18 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
503508 }
504509 //byteStream.write(byte_array, 0, read_bytes);
505510
511+ maxRetryCount = 20;
506512 do
507513 {
508514 sleep(delayMs);
509515 read_bytes = is.available();
510516 //Log.v(TAG, " is.available() read_bytes : " + read_bytes + " " + received_length + " < " + estimatedSize);
511- } while ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
517+ if (read_bytes == 0)
518+ {
519+ Log.v(TAG, " WAIT is.available() ... [" + received_length + ", " + target_length + "] " + read_bytes + " retry : " + maxRetryCount);
520+ maxRetryCount--;
521+ }
522+ } while ((read_bytes == 0)&&(maxRetryCount > 0)&&(received_length < target_length)); // while ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
512523 }
513524 //ByteArrayOutputStream outputStream = cutHeader(byteStream);
514525 //receivedMessage(isDumpReceiveLog, id, outputStream.toByteArray(), callback);
@@ -516,7 +527,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
516527 // 終了報告...一時的?
517528 if (callback != null)
518529 {
519- Log.v(TAG, " --- receive_multi : receivedMessage() : " + id + " (" + read_bytes + ") [" + estimatedSize + "] " + receive_message_buffer_size + " (" + received_length + ")");
530+ Log.v(TAG, " --- receive_multi : " + id + " (" + read_bytes + ") [" + maxRetryCount + "] " + receive_message_buffer_size + " (" + received_length + ") ");
520531 callback.receivedMessage(id, null);
521532 }
522533 System.gc();
@@ -568,7 +579,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
568579 lenlen = ((((int) byte_array[15]) & 0xff) << 24) + ((((int) byte_array[14]) & 0xff) << 16) + ((((int) byte_array[13]) & 0xff) << 8) + (((int) byte_array[12]) & 0xff);
569580 packetType = (((int) byte_array[16]) & 0xff);
570581 }
571- Log.v(TAG, " --- RECEIVED MESSAGE : " + len + " bytes (BUFFER: " + byte_array.length + " bytes)" + " length : " + lenlen + " TYPE : " + packetType + " --- ");
582+ // Log.v(TAG, " --- RECEIVED MESSAGE : " + len + " bytes (BUFFER: " + byte_array.length + " bytes)" + " length : " + lenlen + " TYPE : " + packetType + " --- ");
572583 if (lenlen == 0)
573584 {
574585 // データとしては変なので、なにもしない
Show on old repository browser