• R/O
  • HTTP
  • SSH
  • HTTPS

PKRemote: Commit

Pentax DSLR Remote Control app.


Commit MetaInfo

Revision4bef75d5b1960aec67411fd3e8943807c437d6b1 (tree)
Time2019-10-08 23:42:04
AuthorMRSa <mrsa@myad...>
CommiterMRSa

Log Message

フルサイズは途中。

Change Summary

Incremental Difference

--- a/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/playback/PtpIpFullImageReceiver.java
+++ b/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/playback/PtpIpFullImageReceiver.java
@@ -7,10 +7,14 @@ import androidx.annotation.NonNull;
77
88 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
99 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IProgressEvent;
10+import net.osdn.gokigen.pkremote.camera.utils.SimpleLogDumper;
1011 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
1112 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
1213 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
1314
15+import java.io.ByteArrayOutputStream;
16+import java.util.Arrays;
17+
1418 public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
1519 {
1620 private static final String TAG = PtpIpFullImageReceiver.class.getSimpleName();
@@ -20,6 +24,9 @@ public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
2024 private IDownloadContentCallback callback = null;
2125 private int objectId = 0;
2226
27+ private int received_total_bytes = 0;
28+ private int received_remain_bytes = 0;
29+
2330 PtpIpFullImageReceiver(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher publisher)
2431 {
2532 this.activity = activity;
@@ -77,9 +84,10 @@ public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
7784 @Override
7885 public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
7986 {
80- int length = (rx_body == null) ? 0 : rx_body.length;
87+ byte[] body = cutHeader(rx_body);
88+ int length = (body == null) ? 0 : body.length;
8189 Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " (" + length + " bytes.)");
82- callback.onProgress(rx_body, length, new IProgressEvent() {
90+ callback.onProgress(body, length, new IProgressEvent() {
8391 @Override
8492 public float getProgress() {
8593 return ((float) currentBytes / (float) totalBytes);
@@ -97,6 +105,87 @@ public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
97105 });
98106 }
99107
108+ private byte[] cutHeader(byte[] rx_body)
109+ {
110+ if (rx_body == null)
111+ {
112+ return (null);
113+ }
114+ int length = rx_body.length;
115+ int data_position = 0;
116+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
117+ if (received_total_bytes == 0)
118+ {
119+ // データを最初に読んだとき。ヘッダ部分を読み飛ばす
120+ data_position = (int) rx_body[0] & (0xff);
121+ }
122+ else if (received_remain_bytes > 0)
123+ {
124+
125+ Log.v(TAG, " >>> [ remain_bytes : " + received_remain_bytes + "] ( length : " + length + ") " + data_position);
126+ SimpleLogDumper.dump_bytes("[zzz]", Arrays.copyOfRange(rx_body, data_position, (data_position + 160)));
127+
128+ // データの読み込みが途中だった場合...
129+ if (length < received_remain_bytes)
130+ {
131+ // 全部コピーする、足りないバイト数は残す
132+ received_remain_bytes = received_remain_bytes - length;
133+ received_total_bytes = received_total_bytes + rx_body.length;
134+ return (rx_body);
135+ }
136+ else
137+ {
138+ byteStream.write(rx_body, data_position, received_remain_bytes);
139+ data_position = received_remain_bytes;
140+ received_remain_bytes = 0;
141+ }
142+ }
143+
144+ while (data_position <= (length - 12))
145+ {
146+ int body_size = (rx_body[data_position] & 0xff) + ((rx_body[data_position + 1] & 0xff) << 8) +
147+ ((rx_body[data_position + 2] & 0xff) << 16) + ((rx_body[data_position + 3] & 0xff) << 24);
148+ if (body_size <= 12)
149+ {
150+ Log.v(TAG, " BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + " ");
151+
152+ int startpos = (data_position > 48) ? (data_position - 48) : 0;
153+ SimpleLogDumper.dump_bytes("[xxx]", Arrays.copyOfRange(rx_body, startpos, (data_position + 48)));
154+
155+ break;
156+ }
157+
158+ Log.v(TAG, " RX DATA : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] (" + received_total_bytes + ")");
159+ SimpleLogDumper.dump_bytes("[yyy] " + data_position + ": ", Arrays.copyOfRange(rx_body, data_position, (data_position + 64)));
160+
161+
162+ if ((data_position + body_size) > length)
163+ {
164+ // データがすべてバッファ内になかったときは、バッファすべてコピーして残ったサイズを記憶しておく。
165+ int copysize = (length - ((data_position + 12)));
166+ byteStream.write(rx_body, (data_position + 12), copysize);
167+ received_remain_bytes = body_size - copysize - 12; // マイナス12は、ヘッダ分
168+ received_total_bytes = received_total_bytes + copysize;
169+ Log.v(TAG, " --- copy : " + (data_position + 12) + " " + copysize + " remain : " + received_remain_bytes + " body size : " + body_size);
170+ break;
171+ }
172+ try
173+ {
174+ byteStream.write(rx_body, (data_position + 12), (body_size - 12));
175+ data_position = data_position + body_size;
176+ received_total_bytes = received_total_bytes + 12;
177+ Log.v(TAG, " --- COPY : " + (data_position + 12) + " " + (body_size - 12) + " remain : " + received_remain_bytes);
178+
179+ }
180+ catch (Exception e)
181+ {
182+ Log.v(TAG, " pos : " + data_position + " size : " + body_size + " length : " + length);
183+ e.printStackTrace();
184+ }
185+ }
186+ return (byteStream.toByteArray());
187+ }
188+
100189 @Override
101190 public boolean isReceiveMulti()
102191 {
Show on old repository browser