• R/O
  • HTTP
  • SSH
  • HTTPS

PKRemote: Commit

Pentax DSLR Remote Control app.


Commit MetaInfo

Revision29e46ae0b1f0d70412747797e16c2693cc7b8619 (tree)
Zeit2019-10-02 00:20:35
AutorMRSa <mrsa@myad...>
CommiterMRSa

Log Message

とりあえず、OOM抑止第二弾。

Ändern Zusammenfassung

Diff

--- a/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/PtpIpFullImageReceiver.java
+++ /dev/null
@@ -1,76 +0,0 @@
1-package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper;
2-
3-import android.util.Log;
4-
5-import androidx.annotation.NonNull;
6-
7-import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
8-import net.osdn.gokigen.pkremote.camera.interfaces.playback.IProgressEvent;
9-import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
10-
11-public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
12-{
13- private final String TAG = toString();
14- private final IDownloadContentCallback callback;
15- private int receivedLength;
16-
17- PtpIpFullImageReceiver(@NonNull IDownloadContentCallback callback)
18- {
19- this.callback = callback;
20- this.receivedLength = 0;
21- }
22-
23- @Override
24- public void receivedMessage(int id, byte[] rx_body)
25- {
26- try
27- {
28- Log.v(TAG, " receivedMessage() : onCompleted. " + id + " (" + receivedLength + " bytes.)");
29- callback.onCompleted();
30- }
31- catch (Exception e)
32- {
33- e.printStackTrace();
34- {
35- callback.onErrorOccurred(e);
36- }
37- }
38- }
39-
40- @Override
41- public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] body)
42- {
43- try
44- {
45- receivedLength = receivedLength + currentBytes;
46- //Log.v(TAG, " onReceiveProgress() " + receivedLength + "/" + totalBytes);
47-
48- callback.onProgress(body, currentBytes, new IProgressEvent() {
49- @Override
50- public float getProgress() {
51- return( (float) receivedLength / (float) totalBytes);
52- }
53-
54- @Override
55- public boolean isCancellable() {
56- return (false);
57- }
58-
59- @Override
60- public void requestCancellation() { }
61- });
62- }
63- catch (Exception e)
64- {
65- e.printStackTrace();
66- callback.onErrorOccurred(e);
67- }
68- }
69-
70- @Override
71- public boolean isReceiveMulti()
72- {
73- return (true);
74- }
75-
76-}
--- a/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/command/PtpIpCommandPublisher.java
+++ b/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/command/PtpIpCommandPublisher.java
@@ -22,9 +22,9 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
2222
2323 private static final int SEQUENCE_START_NUMBER = 1;
2424 private static final int BUFFER_SIZE = 1024 * 256 + 16; // バッファは 256kB
25- private static final int COMMAND_SEND_RECEIVE_DURATION_MS = 10;
25+ private static final int COMMAND_SEND_RECEIVE_DURATION_MS = 5;
2626 private static final int COMMAND_SEND_RECEIVE_DURATION_MAX = 1000;
27- private static final int COMMAND_POLL_QUEUE_MS = 10;
27+ private static final int COMMAND_POLL_QUEUE_MS = 5;
2828
2929 private final String ipAddress;
3030 private final int portNumber;
--- /dev/null
+++ b/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/playback/PtpIpFullImageReceiver.java
@@ -0,0 +1,185 @@
1+package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
2+
3+import android.app.Activity;
4+import android.graphics.BitmapFactory;
5+import android.util.Log;
6+
7+import androidx.annotation.NonNull;
8+import androidx.annotation.Nullable;
9+
10+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
11+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
12+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IProgressEvent;
13+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
14+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
15+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
16+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.specific.CanonRequestInnerDevelopEnd;
17+
18+public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
19+{
20+ private static final String TAG = PtpIpScreennailImageReceiver.class.getSimpleName();
21+
22+ private static final int BITMAP_MAX_PIXEL = 1024; // 小さい方のサイズ
23+
24+ private final Activity activity;
25+ private final IDownloadThumbnailImageCallback callback;
26+ private final IPtpIpCommandPublisher publisher;
27+ private final int objectId;
28+
29+ PtpIpFullImageReceiver(Activity activity, int objectId, IPtpIpCommandPublisher publisher, IDownloadThumbnailImageCallback callback)
30+ {
31+ this.activity = activity;
32+ this.callback = callback;
33+ this.publisher = publisher;
34+ this.objectId = objectId;
35+ Log.v(TAG, "PtpIpScreennailImageReceiver CREATED : " + objectId);
36+
37+ }
38+
39+ @Override
40+ public void receivedMessage(int id, byte[] rx_body)
41+ {
42+ try
43+ {
44+ if (rx_body != null)
45+ {
46+ Log.v(TAG, " receivedMessage() : " + id + " " + rx_body.length + " bytes.");
47+ }
48+ else
49+ {
50+ Log.v(TAG, " receivedMessage() : " + id + " NULL.");
51+ }
52+ if (id == objectId)
53+ {
54+ getRequestStatusEvent(rx_body);
55+ }
56+ else if (id == objectId + 1)
57+ {
58+ getPartialObject(rx_body);
59+ }
60+ else if (id == objectId + 2)
61+ {
62+ requestInnerDevelopEnd();
63+ }
64+ else if (id == objectId + 3)
65+ {
66+ finishedGetScreeennail();
67+ }
68+ else if (id == objectId + 4)
69+ {
70+ Log.v(TAG, " RECEIVED : " + id);
71+ }
72+ else if (id == objectId + 5)
73+ {
74+ Log.v(TAG, " RECEIVED STATUS EVENT : " + id);
75+ requestGetPartialObject(rx_body);
76+ }
77+ else
78+ {
79+ Log.v(TAG, " RECEIVED UNKNOWN ID : " + id);
80+ }
81+ }
82+ catch (Exception e)
83+ {
84+ e.printStackTrace();
85+ {
86+ callback.onErrorOccurred(e);
87+ }
88+ }
89+ }
90+
91+ @Override
92+ public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
93+ {
94+ int length = (rx_body == null) ? 0 : rx_body.length;
95+ Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " (" + length + " bytes.)");
96+ }
97+
98+ @Override
99+ public boolean isReceiveMulti()
100+ {
101+ return (false);
102+ }
103+
104+ private void requestGetPartialObject(@Nullable byte[] rx_body)
105+ {
106+ Log.v(TAG, " requestGetPartialObject() : " + objectId);
107+
108+ // 0x9107 : GetPartialObject (元は 0x00020000)
109+ int pictureLength;
110+ if ((rx_body != null)&&(rx_body.length > 52))
111+ {
112+ int dataIndex = 48;
113+ pictureLength = (rx_body[dataIndex] & 0xff);
114+ pictureLength = pictureLength + ((rx_body[dataIndex + 1] & 0xff) << 8);
115+ pictureLength = pictureLength + ((rx_body[dataIndex + 2] & 0xff) << 16);
116+ pictureLength = pictureLength + ((rx_body[dataIndex + 3] & 0xff) << 24);
117+ }
118+ else
119+ {
120+ pictureLength = 0x02000;
121+ }
122+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 1), true, objectId, 0x9107, 12, 0x01, 0x00, pictureLength));
123+ }
124+
125+ private void getRequestStatusEvent(byte[] rx_body)
126+ {
127+ Log.v(TAG, " getRequestStatusEvent : " + objectId);
128+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 5), true, objectId, 0x9116));
129+ }
130+
131+ private void getPartialObject(byte[] rx_body)
132+ {
133+ try
134+ {
135+ Log.v(TAG, " getPartialObject(), id : " + objectId + " size: " + rx_body.length);
136+
137+ BitmapFactory.Options opt = new BitmapFactory.Options();
138+ try
139+ {
140+ // OutOfMemoryエラー対策...一度読み込んで画像サイズを取得
141+ opt.inJustDecodeBounds = true;
142+ //opt.inDither = true;
143+ BitmapFactory.decodeByteArray(rx_body, 0, rx_body.length);
144+ }
145+ catch (Exception ex)
146+ {
147+ ex.printStackTrace();
148+ System.gc();
149+ }
150+ // 画像の縮小サイズを決定する (縦幅、横幅の小さいほうにあわせる)
151+ int widthBounds = opt.outWidth / BITMAP_MAX_PIXEL;
152+ int heightBounds = opt.outHeight / BITMAP_MAX_PIXEL;
153+ opt.inSampleSize = Math.min(widthBounds, heightBounds);
154+ opt.inJustDecodeBounds = false;
155+
156+ // ビットマップをリサイズして返す
157+ callback.onCompleted(BitmapFactory.decodeByteArray(rx_body, 0, rx_body.length, opt), null);
158+ //callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body)), null);
159+ }
160+ catch (Throwable t)
161+ {
162+ t.printStackTrace();
163+ System.gc();
164+ }
165+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 2), true, objectId, 0x9117, 4,0x01)); // 0x9117 : TransferComplete
166+
167+ // ファイルにバイナリデータをダンプする
168+ // binaryOutputToFile(activity, objectId + "_", rx_body);
169+ }
170+
171+ private void requestInnerDevelopEnd()
172+ {
173+ Log.v(TAG, " requestInnerDevelopEnd() : " + objectId);
174+ publisher.enqueueCommand(new CanonRequestInnerDevelopEnd(this, (objectId + 3), true, objectId)); // 0x9143 : RequestInnerDevelopEnd
175+ }
176+
177+ private void finishedGetScreeennail()
178+ {
179+ Log.v(TAG, " --- SCREENNAIL RECV FINISHED. : " + objectId + " --- ");
180+
181+ // リセットコマンドを送ってみる
182+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 4), false, objectId, 0x902f));
183+ }
184+
185+}
--- a/app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/ImagePagerViewFragment.java
+++ b/app/src/main/java/net/osdn/gokigen/pkremote/playback/detail/ImagePagerViewFragment.java
@@ -3,6 +3,8 @@ package net.osdn.gokigen.pkremote.playback.detail;
33
44 import android.app.Activity;
55 import android.graphics.Bitmap;
6+import android.graphics.drawable.BitmapDrawable;
7+import android.graphics.drawable.Drawable;
68 import android.os.Bundle;
79 import android.util.Log;
810 import android.view.LayoutInflater;
@@ -461,6 +463,22 @@ public class ImagePagerViewFragment extends Fragment
461463 @Override
462464 public void run()
463465 {
466+ try
467+ {
468+ BitmapDrawable draw = ((BitmapDrawable)view.getDrawable());
469+ if (draw != null)
470+ {
471+ Bitmap bmp = draw.getBitmap();
472+ if (bmp != null)
473+ {
474+ bmp.recycle();
475+ }
476+ }
477+ }
478+ catch (Exception e)
479+ {
480+ e.printStackTrace();
481+ }
464482 view.setImageBitmap(bitmap);
465483 }
466484 });
@@ -496,6 +514,22 @@ public class ImagePagerViewFragment extends Fragment
496514 public void run() {
497515 if ((bitmap != null) && (view != null) && (viewPager.indexOfChild(view) > -1))
498516 {
517+ try
518+ {
519+ BitmapDrawable draw = ((BitmapDrawable)view.getDrawable());
520+ if (draw != null)
521+ {
522+ Bitmap bmp = draw.getBitmap();
523+ if (bmp != null)
524+ {
525+ bmp.recycle();
526+ }
527+ }
528+ }
529+ catch (Exception e)
530+ {
531+ e.printStackTrace();
532+ }
499533 view.setImageBitmap(bitmap);
500534 }
501535 }
Show on old repository browser