private static final String TAG = PtpIpCommandPublisher.class.getSimpleName();
private static final int SEQUENCE_START_NUMBER = 1;
- private static final int BUFFER_SIZE = 1024 * 256 + 16; // バッファは 256kB
+ private static final int BUFFER_SIZE = 1024 * 256 + 16; // 受信バッファは 256kB
private static final int COMMAND_SEND_RECEIVE_DURATION_MS = 5;
private static final int COMMAND_SEND_RECEIVE_DURATION_MAX = 1000;
private static final int COMMAND_POLL_QUEUE_MS = 5;
isHold = true;
holdId = command.getHoldId();
}
-
//Log.v(TAG, "Enqueue : " + command.getId());
return (commandQueue.offer(command));
}
}
byte[] receive_body = Arrays.copyOfRange(byte_array, 0, (position < 1) ? 1 : position);
Log.v(TAG, " RECEIVED : [" + position + "]");
- receivedMessage(isDumpReceiveLog, id, receive_body, callback);
+ receivedAllMessage(isDumpReceiveLog, id, receive_body, callback);
}
catch (Throwable e)
{
*/
private boolean receive_from_camera(@NonNull IPtpIpCommand command)
{
+ IPtpIpCommandCallback callback = command.responseCallback();
+ if ((callback != null)&&(callback.isReceiveMulti()))
+ {
+ // 受信したら逐次「受信したよ」と応答するパターン
+ return (receive_multi(command));
+ }
+ // 受信した後、すべてをまとめて「受信したよ」と応答するパターン
+ return (receive_single(command));
+ }
+
+ private boolean receive_single(@NonNull IPtpIpCommand command)
+ {
boolean isDumpReceiveLog = command.dumpLog();
int id = command.getId();
IPtpIpCommandCallback callback = command.responseCallback();
try
{
- // boolean isFirstTime = true;
int receive_message_buffer_size = BUFFER_SIZE;
byte[] byte_array = new byte[receive_message_buffer_size];
InputStream is = socket.getInputStream();
sleep(delayMs);
read_bytes = is.available();
}
-
- // 積みなおしたByteArrayOutputStreamを取得する
ByteArrayOutputStream outputStream = cutHeader(byteStream);
- receivedMessage(isDumpReceiveLog, id, outputStream.toByteArray(), callback);
+ receivedAllMessage(isDumpReceiveLog, id, outputStream.toByteArray(), callback);
System.gc();
}
catch (Throwable e)
return (false);
}
+ private void receivedAllMessage(boolean isDumpReceiveLog, int id, byte[] body, IPtpIpCommandCallback callback)
+ {
+ if (isDumpReceiveLog)
+ {
+ // ログに受信メッセージを出力する
+ Log.v(TAG, "receive_from_camera() : " + body.length + " bytes.");
+ dump_bytes("RECV[" + body.length + "] ", body);
+ }
+ if (callback != null)
+ {
+ callback.receivedMessage(id, body);
+ }
+ }
+
+ private boolean receive_multi(@NonNull IPtpIpCommand command)
+ {
+ boolean isDumpReceiveLog = command.dumpLog();
+ int id = command.getId();
+ IPtpIpCommandCallback callback = command.responseCallback();
+ int delayMs = command.receiveDelayMs();
+ if ((delayMs < 0)||(delayMs > COMMAND_SEND_RECEIVE_DURATION_MAX))
+ {
+ delayMs = COMMAND_SEND_RECEIVE_DURATION_MS;
+ }
+
+ try
+ {
+ int receive_message_buffer_size = BUFFER_SIZE;
+ byte[] byte_array = new byte[receive_message_buffer_size];
+ InputStream is = socket.getInputStream();
+ if (is == null)
+ {
+ Log.v(TAG, " InputStream is NULL... RECEIVE ABORTED.");
+ return (false);
+ }
+
+ // 初回データが受信バッファにデータが溜まるまで待つ...
+ int received_length = 0;
+ int read_bytes = waitForReceive(is, delayMs);
+ if (read_bytes < 0)
+ {
+ // リトライオーバー...
+ Log.v(TAG, " RECEIVE : RETRY OVER...");
+ return (true);
+ }
+ // 受信したデータをバッファに突っ込む
+ //ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+
+ // 初回データの読み込み
+ read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
+ int target_length = parseDataLength(byte_array, read_bytes);
+ received_length = read_bytes;
+
+ // 一時的な処理
+ if (callback != null)
+ {
+ callback.onReceiveProgress(received_length, target_length, byte_array);
+ }
+
+ sleep(delayMs);
+ read_bytes = is.available();
+ while (read_bytes > 0)
+ {
+ read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
+ if (read_bytes <= 0)
+ {
+ Log.v(TAG, " RECEIVED MESSAGE FINISHED (" + read_bytes + ")");
+ break;
+ }
+ received_length = received_length + read_bytes;
+
+ // 一時的な処理
+ if (callback != null)
+ {
+ callback.onReceiveProgress(received_length, target_length, Arrays.copyOfRange(byte_array, 0, read_bytes));
+ }
+
+ //byteStream.write(byte_array, 0, read_bytes);
+ sleep(delayMs);
+ read_bytes = is.available();
+ }
+ //ByteArrayOutputStream outputStream = cutHeader(byteStream);
+ //receivedMessage(isDumpReceiveLog, id, outputStream.toByteArray(), callback);
+
+ // 終了報告...一時的?
+ if (callback != null)
+ {
+ callback.receivedMessage(id, null);
+ }
+ System.gc();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ System.gc();
+ }
+ return (false);
+ }
+
+ private void receivedMessage(boolean isDumpReceivedLog, int currentBytes, int totalBytes, byte[] body, IPtpIpCommandCallback callback)
+ {
+ if (isDumpReceivedLog)
+ {
+ // ログに受信メッセージを出力する
+ Log.v(TAG, "receive_from_camera() : " + body.length + " bytes.");
+ dump_bytes("RECV[" + body.length + "] ", body);
+ }
+ if (callback != null)
+ {
+ callback.onReceiveProgress(currentBytes, totalBytes, body);
+ }
+ }
+
+
+
+ private int parseDataLength(byte[] byte_array, int read_bytes)
+ {
+ int lenlen = 0;
+ try
+ {
+ if ((read_bytes > 20)&&((int) byte_array[4] == 0x09))
+ {
+ lenlen = ((((int) byte_array[15]) & 0xff) << 24) + ((((int) byte_array[14]) & 0xff) << 16) + ((((int) byte_array[13]) & 0xff) << 8) + (((int) byte_array[12]) & 0xff);
+ }
+ Log.v(TAG, " --- [[[ RECEIVED LARGE BLOCK MESSAGE : " + lenlen + " bytes. ]]] --- ");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (lenlen);
+ }
+
private ByteArrayOutputStream cutHeader(ByteArrayOutputStream receivedBuffer)
{
try
private int waitForReceive(InputStream is, int delayMs)
{
- int retry_count = 30;
+ int retry_count = 50;
int read_bytes = 0;
try
{
}
return (read_bytes);
}
-
- private void receivedMessage(boolean isDumpReceiveLog, int id, byte[] body, IPtpIpCommandCallback callback)
- {
- if (isDumpReceiveLog)
- {
- // ログに受信メッセージを出力する
- Log.v(TAG, "receive_from_camera() : " + body.length + " bytes.");
- dump_bytes("RECV[" + body.length + "] ", body);
- }
- if (callback != null)
- {
- if (callback.isReceiveMulti())
- {
- callback.receivedMessage(id, null);
- }
- else
- {
- callback.receivedMessage(id, body);
- //callback.receivedMessage(id, Arrays.copyOfRange(receive_body, 0, receive_body.length));
- }
- }
- }
}
package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
import android.app.Activity;
-import android.graphics.BitmapFactory;
import android.util.Log;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
-import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
import net.osdn.gokigen.pkremote.camera.interfaces.playback.IProgressEvent;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
-import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.specific.CanonRequestInnerDevelopEnd;
public class PtpIpFullImageReceiver implements IPtpIpCommandCallback
{
- private static final String TAG = PtpIpScreennailImageReceiver.class.getSimpleName();
-
- private static final int BITMAP_MAX_PIXEL = 1024; // 小さい方のサイズ
+ private static final String TAG = PtpIpFullImageReceiver.class.getSimpleName();
private final Activity activity;
- private final IDownloadThumbnailImageCallback callback;
private final IPtpIpCommandPublisher publisher;
- private final int objectId;
+ private IDownloadContentCallback callback = null;
+ private int objectId = 0;
- PtpIpFullImageReceiver(Activity activity, int objectId, IPtpIpCommandPublisher publisher, IDownloadThumbnailImageCallback callback)
+ PtpIpFullImageReceiver(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher publisher)
{
this.activity = activity;
- this.callback = callback;
+
this.publisher = publisher;
- this.objectId = objectId;
- Log.v(TAG, "PtpIpScreennailImageReceiver CREATED : " + objectId);
+ }
+ void issueCommand(int objectId, int imageSize, IDownloadContentCallback callback)
+ {
+ if (this.objectId != 0)
+ {
+ // already issued
+ Log.v(TAG, " COMMAND IS ALREADY ISSUED. : " + objectId);
+ return;
+ }
+ this.callback = callback;
+ Log.v(TAG, " GetPartialObject : " + objectId + " (size:" + imageSize + ")");
+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 1), true, objectId, 0x9107, 12, 0x01, 0x00, imageSize)); // 0x9107 : GetPartialObject
+ this.objectId = objectId;
}
@Override
{
try
{
- if (rx_body != null)
- {
- Log.v(TAG, " receivedMessage() : " + id + " " + rx_body.length + " bytes.");
- }
- else
- {
- Log.v(TAG, " receivedMessage() : " + id + " NULL.");
- }
- if (id == objectId)
- {
- getRequestStatusEvent(rx_body);
- }
- else if (id == objectId + 1)
+ if (id == objectId + 1)
{
- getPartialObject(rx_body);
+ getPartialObjectEnd();
}
else if (id == objectId + 2)
{
- requestInnerDevelopEnd();
- }
- else if (id == objectId + 3)
- {
- finishedGetScreeennail();
- }
- else if (id == objectId + 4)
- {
Log.v(TAG, " RECEIVED : " + id);
- }
- else if (id == objectId + 5)
- {
- Log.v(TAG, " RECEIVED STATUS EVENT : " + id);
- requestGetPartialObject(rx_body);
+
+ // end of receive sequence.
+ callback.onCompleted();
+ objectId = 0;
+ callback = null;
+ System.gc();
}
else
{
}
@Override
- public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
+ public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
{
int length = (rx_body == null) ? 0 : rx_body.length;
Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " (" + length + " bytes.)");
- }
+ callback.onProgress(rx_body, length, new IProgressEvent() {
+ @Override
+ public float getProgress() {
+ return ((float) currentBytes / (float) totalBytes);
+ }
- @Override
- public boolean isReceiveMulti()
- {
- return (false);
- }
+ @Override
+ public boolean isCancellable() {
+ return (false);
+ }
- private void requestGetPartialObject(@Nullable byte[] rx_body)
- {
- Log.v(TAG, " requestGetPartialObject() : " + objectId);
+ @Override
+ public void requestCancellation() {
- // 0x9107 : GetPartialObject (元は 0x00020000)
- int pictureLength;
- if ((rx_body != null)&&(rx_body.length > 52))
- {
- int dataIndex = 48;
- pictureLength = (rx_body[dataIndex] & 0xff);
- pictureLength = pictureLength + ((rx_body[dataIndex + 1] & 0xff) << 8);
- pictureLength = pictureLength + ((rx_body[dataIndex + 2] & 0xff) << 16);
- pictureLength = pictureLength + ((rx_body[dataIndex + 3] & 0xff) << 24);
- }
- else
- {
- pictureLength = 0x02000;
- }
- publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 1), true, objectId, 0x9107, 12, 0x01, 0x00, pictureLength));
+ }
+ });
}
- private void getRequestStatusEvent(byte[] rx_body)
+ @Override
+ public boolean isReceiveMulti()
{
- Log.v(TAG, " getRequestStatusEvent : " + objectId);
- publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 5), true, objectId, 0x9116));
+ return (true);
}
- private void getPartialObject(byte[] rx_body)
+ private void getPartialObjectEnd()
{
try
{
- Log.v(TAG, " getPartialObject(), id : " + objectId + " size: " + rx_body.length);
-
- BitmapFactory.Options opt = new BitmapFactory.Options();
- try
- {
- // OutOfMemoryエラー対策...一度読み込んで画像サイズを取得
- opt.inJustDecodeBounds = true;
- //opt.inDither = true;
- BitmapFactory.decodeByteArray(rx_body, 0, rx_body.length);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- System.gc();
- }
- // 画像の縮小サイズを決定する (縦幅、横幅の小さいほうにあわせる)
- int widthBounds = opt.outWidth / BITMAP_MAX_PIXEL;
- int heightBounds = opt.outHeight / BITMAP_MAX_PIXEL;
- opt.inSampleSize = Math.min(widthBounds, heightBounds);
- opt.inJustDecodeBounds = false;
-
- // ビットマップをリサイズして返す
- callback.onCompleted(BitmapFactory.decodeByteArray(rx_body, 0, rx_body.length, opt), null);
- //callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body)), null);
+ Log.v(TAG, " getPartialObjectEnd(), id : " + objectId);
+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 2), true, objectId, 0x9117, 4,0x01)); // 0x9117 : TransferComplete
}
catch (Throwable t)
{
t.printStackTrace();
System.gc();
}
- publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 2), true, objectId, 0x9117, 4,0x01)); // 0x9117 : TransferComplete
-
- // ファイルにバイナリデータをダンプする
- // binaryOutputToFile(activity, objectId + "_", rx_body);
}
-
- private void requestInnerDevelopEnd()
- {
- Log.v(TAG, " requestInnerDevelopEnd() : " + objectId);
- publisher.enqueueCommand(new CanonRequestInnerDevelopEnd(this, (objectId + 3), true, objectId)); // 0x9143 : RequestInnerDevelopEnd
- }
-
- private void finishedGetScreeennail()
- {
- Log.v(TAG, " --- SCREENNAIL RECV FINISHED. : " + objectId + " --- ");
-
- // リセットコマンドを送ってみる
- publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 4), false, objectId, 0x902f));
- }
-
}
import java.util.Date;
import java.util.TimeZone;
-
public class PtpIpImageContentInfo implements ICameraContent
{
private final String TAG = toString();
return (indexNumber);
}
+ int getOriginalSize()
+ {
+ try
+ {
+ return((rx_body[0x14] & 0xff) + ((rx_body[0x15] & 0xff) << 8) +
+ ((rx_body[0x16] & 0xff) << 16) + ((rx_body[0x17] & 0xff) << 24));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ // ちょっと大きめサイズを返す
+ return (0x02800000);
+ }
+
int getStorageId()
{
try
{
- int storageId = (rx_body[4] & 0xff) + ((rx_body[5] & 0xff) << 8);
- storageId = storageId + ((rx_body[6] & 0xff) << 16) + ((rx_body[7] & 0xff) << 24);
- return (storageId);
+ return ((rx_body[4] & 0xff) + ((rx_body[5] & 0xff) << 8) +
+ ((rx_body[6] & 0xff) << 16) + ((rx_body[7] & 0xff) << 24));
}
catch (Exception e)
{
private final String TAG = toString();
private final Activity activity;
private final PtpIpInterfaceProvider provider;
+ private final PtpIpFullImageReceiver fullImageReceiver;
+ private final PtpIpSmallImageReceiver smallImageReciever;
private String raw_suffix = "CR2";
private CanonImageObjectReceiver canonImageObjectReceiver;
{
this.activity = activity;
this.provider = provider;
+ this.fullImageReceiver = new PtpIpFullImageReceiver(activity, provider.getCommandPublisher());
+ this.smallImageReciever = new PtpIpSmallImageReceiver(activity, provider.getCommandPublisher());
canonImageObjectReceiver = new CanonImageObjectReceiver(provider);
try
@Override
public void downloadContent(String path, boolean isSmallSize, IDownloadContentCallback callback)
{
-/*
try
{
int start = 0;
{
start = 1;
}
- String indexStr = path.substring(start, path.indexOf("."));
- Log.v(TAG, "FujiX::downloadContent() : " + path + " " + indexStr);
- int index = Integer.parseInt(indexStr);
- //PtpIpImageContentInfo contentInfo = imageContentInfo.get(index); // 特にデータを更新しないから大丈夫か?
- if ((index > 0)&&(index <= imageContentInfo.size()))
+ final String indexStr = path.substring(start);
+ PtpIpImageContentInfo content = canonImageObjectReceiver.getContentObject(indexStr);
+ if (content != null)
{
- IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
- publisher.enqueueCommand(new GetFullImage(index, new PtpIpFullImageReceiver(callback)));
+ if (isSmallSize)
+ {
+ // スモールサイズの画像取得コマンド(シーケンス)を発行する
+ smallImageReciever.issueCommand(content.getId(), callback);
+ }
+ else
+ {
+ // オリジナル画像の取得コマンド(シーケンス)を発行する
+ fullImageReceiver.issueCommand(content.getId(), content.getOriginalSize(), callback);
+ }
}
}
- catch (Exception e)
+ catch (Throwable e)
{
e.printStackTrace();
}
-*/
}
@Override
{
try
{
- Log.v(TAG, "showPictureStarted() ");
+ Log.v(TAG, " showPictureStarted() ");
IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
publisher.flushHoldQueue();
{
try
{
- Log.v(TAG, "showPictureFinished() ");
+ Log.v(TAG, " showPictureFinished() ");
IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
publisher.flushHoldQueue();
}
}
-/*
- @Override
- public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
- {
- Log.v(TAG, " " + currentBytes + "/" + totalBytes);
- }
-
- @Override
- public boolean isReceiveMulti()
- {
- return (false);
- }
-
- @Override
- public void receivedMessage(int id, byte[] rx_body)
- {
- // イメージ数の一覧が取得できなかった場合にここで作る。
- if (rx_body.length < 16)
- {
- // インデックスデータがなくなったことを検出...データがそろったとして応答する。
- //Log.v(TAG, "IMAGE LIST : " + imageContentInfo.size());
- finishedCallback.onCompleted(getCameraContentList());
- finishedCallback = null;
- return;
- }
- try
- {
- Log.v(TAG, "RECEIVED IMAGE INFO : " + indexNumber);
-
- // 受信データを保管しておく
- imageContentInfo.append(indexNumber, new PtpIpImageContentInfo(indexNumber, rx_body));
-
- // 次のインデックスの情報を要求する
- indexNumber++;
- IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
- publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, this));
- }
- catch (Exception e)
- {
- // エラーになったら、そこで終了にする
- e.printStackTrace();
- finishedCallback.onCompleted(getCameraContentList());
- finishedCallback = null;
- }
- }
-*/
-
-/*
- private List<ICameraContent> getCameraContentList()
- {
- /// ダサいけど...コンテナクラスを詰め替えて応答する
- List<ICameraContent> contentList = new ArrayList<>();
- int listSize = imageContentInfo.size();
- for(int index = 0; index < listSize; index++)
- {
- contentList.add(imageContentInfo.valueAt(index));
- }
- return (contentList);
- }
-*/
-
}
--- /dev/null
+package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
+
+import android.app.Activity;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IProgressEvent;
+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.specific.CanonRequestInnerDevelopEnd;
+import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.specific.CanonRequestInnerDevelopStart;
+
+
+public class PtpIpSmallImageReceiver implements IPtpIpCommandCallback
+{
+ private static final String TAG = PtpIpSmallImageReceiver.class.getSimpleName();
+
+ private final Activity activity;
+ private final IPtpIpCommandPublisher publisher;
+
+ private IDownloadContentCallback callback = null;
+ private int objectId = 0;
+
+ PtpIpSmallImageReceiver(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher publisher)
+ {
+ this.activity = activity;
+ this.publisher = publisher;
+ }
+
+ void issueCommand(int objectId, IDownloadContentCallback callback)
+ {
+ if (this.objectId != 0)
+ {
+ // already issued
+ Log.v(TAG, " COMMAND IS ALREADY ISSUED. : " + objectId);
+ return;
+ }
+ this.callback = callback;
+ this.objectId = objectId;
+ publisher.enqueueCommand(new CanonRequestInnerDevelopStart(this, objectId, true, objectId, objectId)); // 0x9141 : RequestInnerDevelopStart
+ }
+
+ @Override
+ public void receivedMessage(int id, byte[] rx_body)
+ {
+ try
+ {
+ if (rx_body != null)
+ {
+ Log.v(TAG, " receivedMessage() : " + id + " " + rx_body.length + " bytes.");
+ }
+ else
+ {
+ Log.v(TAG, " receivedMessage() : " + id + " NULL.");
+ }
+ if (id == objectId)
+ {
+ getRequestStatusEvent(rx_body);
+ }
+ else if (id == objectId + 1)
+ {
+ getPartialObject(rx_body);
+ }
+ else if (id == objectId + 2)
+ {
+ requestInnerDevelopEnd();
+ }
+ else if (id == objectId + 3)
+ {
+ finishedGetSmallImage();
+ }
+ else if (id == objectId + 4)
+ {
+ // 画像取得終了
+ Log.v(TAG, " RECEIVED : " + id);
+ callback.onCompleted();
+ this.objectId = 0;
+ this.callback = null;
+ System.gc();
+ }
+ else if (id == objectId + 5)
+ {
+ Log.v(TAG, " RECEIVED STATUS EVENT : " + id);
+ requestGetPartialObject(rx_body);
+ }
+ else
+ {
+ Log.v(TAG, " RECEIVED UNKNOWN ID : " + id);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ {
+ callback.onErrorOccurred(e);
+ }
+ }
+ }
+
+ @Override
+ public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
+ {
+ int length = (rx_body == null) ? 0 : rx_body.length;
+ Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " (" + length + " bytes.)");
+ callback.onProgress(rx_body, length, new IProgressEvent() {
+ @Override
+ public float getProgress() {
+ return ((float) currentBytes / (float) totalBytes);
+ }
+
+ @Override
+ public boolean isCancellable() {
+ return (false);
+ }
+
+ @Override
+ public void requestCancellation() {
+
+ }
+ });
+ }
+
+ @Override
+ public boolean isReceiveMulti()
+ {
+ return (true);
+ }
+
+ private void requestGetPartialObject(@Nullable byte[] rx_body)
+ {
+ Log.v(TAG, " requestGetPartialObject() : " + objectId);
+
+ // 0x9107 : GetPartialObject (元は 0x00020000)
+ int pictureLength;
+ if ((rx_body != null)&&(rx_body.length > 52))
+ {
+ int dataIndex = 48;
+ pictureLength = (rx_body[dataIndex] & 0xff);
+ pictureLength = pictureLength + ((rx_body[dataIndex + 1] & 0xff) << 8);
+ pictureLength = pictureLength + ((rx_body[dataIndex + 2] & 0xff) << 16);
+ pictureLength = pictureLength + ((rx_body[dataIndex + 3] & 0xff) << 24);
+ }
+ else
+ {
+ pictureLength = 0x020000;
+ }
+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 1), true, objectId, 0x9107, 12, 0x01, 0x00, pictureLength));
+ }
+
+ private void getRequestStatusEvent(byte[] rx_body)
+ {
+ Log.v(TAG, " getRequestStatusEvent : " + objectId + " " + ((rx_body != null) ? rx_body.length : 0));
+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 5), true, objectId, 0x9116));
+ }
+
+ private void getPartialObject(byte[] rx_body)
+ {
+ Log.v(TAG, " getPartialObject(), id : " + objectId + " size: " + ((rx_body != null) ? rx_body.length : 0));
+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 2), true, objectId, 0x9117, 4,0x01)); // 0x9117 : TransferComplete
+
+ // ファイルにバイナリデータをダンプする
+ // binaryOutputToFile(activity, objectId + "_", rx_body);
+ }
+
+ private void requestInnerDevelopEnd()
+ {
+ Log.v(TAG, " requestInnerDevelopEnd() : " + objectId);
+ publisher.enqueueCommand(new CanonRequestInnerDevelopEnd(this, (objectId + 3), true, objectId)); // 0x9143 : RequestInnerDevelopEnd
+ }
+
+ private void finishedGetSmallImage()
+ {
+ Log.v(TAG, " --- SMALL IMAGE RECV FINISHED. : " + objectId + " --- ");
+
+ // リセットコマンドを送ってみる
+ publisher.enqueueCommand(new PtpIpCommandGeneric(this, (objectId + 4), false, objectId, 0x902f));
+ }
+
+}
package net.osdn.gokigen.pkremote.playback.detail;
-
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.0'
+ classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files