@Override
public void onCompleted(byte[] data, Map<String, Object> metadata)
{
- // Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- ");
+ //Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- ");
try
{
if ((dataReceiver != null)&&(data != null))
{
+ Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- : " + data.length + " bytes.");
//dataReceiver.setImageData(data, metadata);
- dataReceiver.setImageData(Arrays.copyOfRange(data, 8, data.length), metadata);
+ if (data.length > 8)
+ {
+ dataReceiver.setImageData(Arrays.copyOfRange(data, 8, data.length), metadata); // ヘッダ部分を切り取って送る
+ }
}
}
catch (Exception e)
import androidx.annotation.NonNull;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
-import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
-
-/**
- * Canonサムネイル画像の受信
- *
- *
- */
-/*
-public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
-{
- private final String TAG = toString();
- private final ICanonLiveViewImageCallback callback;
- private ByteArrayOutputStream byteStream;
-
- CanonLiveViewImageReceiver(@NonNull ICanonLiveViewImageCallback callback)
- {
- this.callback = callback;
- byteStream = new ByteArrayOutputStream();
- }
-
-
- public void reset()
- {
- try
- {
- byteStream.flush();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- byteStream.reset();
- }
-
-
- @Override
- public void receivedMessage(int id, byte[] rx_body)
- {
- try
- {
- if (rx_body == null)
- {
- Log.v(TAG, " BITMAP IS NONE...");
- callback.onCompleted(null, null);
- return;
- }
- Log.v(TAG, " CanonLiveViewImageReceiver::receivedMessage() : " + rx_body.length);
-
- /////// 受信データから、サムネイルの先頭(0xff 0xd8)を検索する /////
- int offset = rx_body.length - 22;
- //byte[] thumbnail0 = Arrays.copyOfRange(rx_body, 0, rx_body.length);
- while (offset > 32)
- {
- if ((rx_body[offset] == (byte) 0xff)&&((rx_body[offset + 1] == (byte) 0xd8)))
- {
- break;
- }
- offset--;
- }
- byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length);
- callback.onCompleted(thumbnail, null);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- {
- callback.onErrorOccurred(e);
- }
- }
- }
-
- @Override
- public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
- {
- Log.v(TAG, " " + currentBytes + "/" + totalBytes);
- try
- {
- if (byteStream != null)
- {
- byteStream.write(body, 0, currentBytes);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- @Override
- public boolean isReceiveMulti()
- {
- return (true);
- }
-}
-
-*/
-
public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
{
@Override
public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
{
+ // Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
+
// 受信したデータから、通信のヘッダ部分を削除する
cutHeader(rx_body);
- Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
}
private void cutHeader(byte[] rx_body)
import androidx.annotation.NonNull;
+import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
+
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
private boolean receive_multi(@NonNull IPtpIpCommand command, int delayMs)
{
- int estimatedSize = command.estimatedReceiveDataSize();
+ //int estimatedSize = command.estimatedReceiveDataSize();
+ int maxRetryCount = 20;
int id = command.getId();
IPtpIpCommandCallback callback = command.responseCallback();
// 一時的な処理
if (callback != null)
{
- Log.v(TAG, " --- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : total_length : " + target_length + " buffer SIZE : " + byte_array.length);
+ Log.v(TAG, " --- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : target_length : " + target_length + " buffer SIZE : " + byte_array.length);
callback.onReceiveProgress(received_length, target_length, Arrays.copyOfRange(byte_array, 0, received_length));
}
read_bytes = is.available();
if (read_bytes == 0)
{
- Log.v(TAG, " WAIT is.available() ... " + received_length + " < " + estimatedSize);
+ Log.v(TAG, " WAIT is.available() ... [" + received_length + ", " + target_length + "] retry : " + maxRetryCount);
+ maxRetryCount--;
}
- } while ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
- while (read_bytes > 0)
+ } while ((read_bytes == 0)&&(maxRetryCount > 0)&&(received_length < target_length)); // ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
+
+ while ((read_bytes >= 0)&&(received_length < target_length))
{
read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
if (read_bytes <= 0)
}
//byteStream.write(byte_array, 0, read_bytes);
+ maxRetryCount = 20;
do
{
sleep(delayMs);
read_bytes = is.available();
//Log.v(TAG, " is.available() read_bytes : " + read_bytes + " " + received_length + " < " + estimatedSize);
- } while ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
+ if (read_bytes == 0)
+ {
+ Log.v(TAG, " WAIT is.available() ... [" + received_length + ", " + target_length + "] " + read_bytes + " retry : " + maxRetryCount);
+ maxRetryCount--;
+ }
+ } while ((read_bytes == 0)&&(maxRetryCount > 0)&&(received_length < target_length)); // while ((read_bytes == 0)&&(estimatedSize > 0)&&(received_length < estimatedSize));
}
//ByteArrayOutputStream outputStream = cutHeader(byteStream);
//receivedMessage(isDumpReceiveLog, id, outputStream.toByteArray(), callback);
// 終了報告...一時的?
if (callback != null)
{
- Log.v(TAG, " --- receive_multi : receivedMessage() : " + id + " (" + read_bytes + ") [" + estimatedSize + "] " + receive_message_buffer_size + " (" + received_length + ")");
+ Log.v(TAG, " --- receive_multi : " + id + " (" + read_bytes + ") [" + maxRetryCount + "] " + receive_message_buffer_size + " (" + received_length + ") ");
callback.receivedMessage(id, null);
}
System.gc();
lenlen = ((((int) byte_array[15]) & 0xff) << 24) + ((((int) byte_array[14]) & 0xff) << 16) + ((((int) byte_array[13]) & 0xff) << 8) + (((int) byte_array[12]) & 0xff);
packetType = (((int) byte_array[16]) & 0xff);
}
- Log.v(TAG, " --- RECEIVED MESSAGE : " + len + " bytes (BUFFER: " + byte_array.length + " bytes)" + " length : " + lenlen + " TYPE : " + packetType + " --- ");
+ // Log.v(TAG, " --- RECEIVED MESSAGE : " + len + " bytes (BUFFER: " + byte_array.length + " bytes)" + " length : " + lenlen + " TYPE : " + packetType + " --- ");
if (lenlen == 0)
{
// データとしては変なので、なにもしない