package net.osdn.gokigen.a01d.camera.canon.operation;
+import android.util.Log;
+
import androidx.annotation.NonNull;
import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
-public class CanonCaptureControl implements ICaptureControl
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.REQUEST_SHUTTER_OFF;
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.REQUEST_SHUTTER_ON;
+
+public class CanonCaptureControl implements ICaptureControl, IPtpIpCommandCallback
{
+ private final String TAG = this.toString();
private final PtpIpCommandPublisher commandPublisher;
private final IAutoFocusFrameDisplay frameDisplayer;
+ private boolean isDumpLog = true;
public CanonCaptureControl(@NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer)
{
this.commandPublisher = commandPublisher;
this.frameDisplayer = frameDisplayer;
-
}
@Override
public void doCapture(int kind)
{
+ try
+ {
+ // シャッター
+ Log.v(TAG, " doCapture() ");
+
+ // シャッターONとOFF
+ commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, REQUEST_SHUTTER_ON, isDumpLog, 0, 0x9128, 8, 0x03, 0x00));
+ commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, REQUEST_SHUTTER_OFF, isDumpLog, 0, 0x9129, 4, 0x03));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ @Override
+ public void receivedMessage(int id, byte[] rx_body)
+ {
+ Log.v(TAG, " CanonCaptureControl::receivedMessage() : ");
+ }
+
+ @Override
+ public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
+ {
+ Log.v(TAG, " CanonCaptureControl::onReceiveProgress() : " + currentBytes + "/" + totalBytes);
+ }
+
+ @Override
+ public boolean isReceiveMulti()
+ {
+ return (false);
}
}
{
private final String TAG = toString();
- private static final int STREAM_PORT = 15742; // ??
private static final int ASYNC_RESPONSE_PORT = 15741; // ??
private static final int CONTROL_PORT = 15740;
private static final int EVENT_PORT = 15740;
{
this.activity = context;
commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT);
- liveViewControl = new CanonLiveViewControl(context, CAMERA_IP, STREAM_PORT);
+ liveViewControl = new CanonLiveViewControl(context, this, 10); //
asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
statusChecker = new CanonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
canonConnection = new CanonConnection(context, provider, this, statusChecker);
@Override
public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
{
- Log.v(TAG, "injectDisplay()");
+ Log.v(TAG, " injectDisplay()");
captureControl = new CanonCaptureControl(commandPublisher, frameDisplayer);
focusingControl = new CanonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
}
private final IPtpIpInterfaceProvider interfaceProvider;
private final IPtpIpCommandPublisher commandIssuer;
private final CanonStatusChecker statusChecker;
- private boolean isDumpLog = true;
+ private boolean isDumpLog = false;
CanonCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull CanonStatusChecker statusChecker)
{
import androidx.annotation.NonNull;
import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
import net.osdn.gokigen.a01d.liveview.liveviewlistener.IImageDataReceiver;
import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
-public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication
-{
- private final String TAG = this.toString();
+import java.util.Map;
- private final Activity context;
- private final String ipAddr;
- private final int portNo;
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_VIEWFRAME;
- public CanonLiveViewControl(@NonNull Activity context, @NonNull String ipAddr, int portNo)
+public class CanonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication, ICanonLiveViewImageCallback
+{
+ private final String TAG = this.toString();
+ private final IPtpIpCommandPublisher commandIssuer;
+ private final int delayMs;
+ private CanonLiveViewImageReceiver imageReceiver;
+ private IImageDataReceiver dataReceiver = null;
+ private boolean liveViewIsReceiving = false;
+ private boolean commandIssued = false;
+
+ public CanonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs)
{
- this.context = context;
- this.ipAddr = ipAddr;
- this.portNo = portNo;
+ this.commandIssuer = interfaceProvider.getCommandPublisher();
+ this.delayMs = delayMs;
+ this.imageReceiver = new CanonLiveViewImageReceiver(this);
}
public ILiveViewListener getLiveViewListener()
public void startLiveView()
{
Log.v(TAG, " startLiveView() ");
-
+ liveViewIsReceiving = true;
+ try
+ {
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run()
+ {
+ try
+ {
+ while (liveViewIsReceiving)
+ {
+ if (!commandIssued)
+ {
+ commandIssued = true;
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(imageReceiver, SEQ_GET_VIEWFRAME, false, 0, 0x9153, 12, 0x00200000, 0x01, 0x00));
+ }
+ try
+ {
+ Thread.sleep(delayMs);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
@Override
public void stopLiveView()
{
Log.v(TAG, " stopLiveView() ");
+ liveViewIsReceiving = false;
}
@Override
public void updateDigitalZoom()
{
+ Log.v(TAG, " updateDigitalZoom() ");
}
@Override
public void updateMagnifyingLiveViewScale(boolean isChangeScale)
{
-
+ Log.v(TAG, " updateMagnifyingLiveViewScale() ");
}
@Override
@Override
public void setCameraLiveImageView(IImageDataReceiver target)
{
-
+ Log.v(TAG, " setCameraLiveImageView() ");
+ this.dataReceiver = target;
}
@Override
{
Log.v(TAG, " disconnect() ");
}
+
+ @Override
+ public void onCompleted(byte[] data, Map<String, Object> metadata)
+ {
+ // Log.v(TAG, "RECEIVED LV IMAGE");
+ commandIssued = false;
+ try
+ {
+ if (dataReceiver != null)
+ {
+ dataReceiver.setImageData(data, metadata);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onErrorOccurred(Exception e)
+ {
+ Log.v(TAG, " onErrorOccurred () : " + e.getLocalizedMessage());
+ commandIssued = false;
+ }
}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.canon.wrapper.liveview;
+
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
+
+import java.util.Arrays;
+
+/**
+ * Canonサムネイル画像の受信
+ *
+ *
+ */
+public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
+{
+ private final String TAG = toString();
+ private final ICanonLiveViewImageCallback callback;
+
+ CanonLiveViewImageReceiver(@NonNull ICanonLiveViewImageCallback callback)
+ {
+ this.callback = callback;
+ }
+
+ @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;
+ }
+
+ /////// 受信データから、サムネイルの先頭(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);
+ }
+
+ @Override
+ public boolean isReceiveMulti()
+ {
+ return (false);
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.canon.wrapper.liveview;
+
+import android.graphics.Bitmap;
+
+import java.util.Map;
+
+public interface ICanonLiveViewImageCallback
+{
+ void onCompleted(byte[] data, Map<String, Object> metadata);
+ void onErrorOccurred(Exception e);
+}
Log.v(TAG, "received status length is short. (" + data.length + " bytes.)");
return;
}
+/*
int nofStatus = (data[13] * 256) + data[12];
int statusCount = 0;
int index = STATUS_MESSAGE_HEADER_SIZE;
index = index + 6;
statusCount++;
}
+*/
}
catch (Exception e)
{
int GET_STORAGE_HANDLE3 = 112;
int GET_PARTIAL_OBJECT= 113;
+ int REQUEST_SHUTTER_ON = 200;
+ int REQUEST_SHUTTER_OFF = 201;
+
/*
int SEQ_REGISTRATION = 1;
int SEQ_START = 2;
issueCommand(command);
}
Thread.sleep(COMMAND_POLL_QUEUE_MS);
+ // Log.v(TAG, " QUEUE SIZE : " + commandQueue.size());
}
catch (Exception e)
{
{
lenlen = ((((int) byte_array[position + 3]) & 0xff) << 24) + ((((int) byte_array[position + 2]) & 0xff) << 16) + ((((int) byte_array[position + 1]) & 0xff) << 8) + (((int) byte_array[position]) & 0xff);
packetType = (((int) byte_array[position + 4]) & 0xff);
+/*
if (packetType != 0x0a)
{
Log.v(TAG, " <><><> PACKET TYPE : " + packetType + " LENGTH : " + lenlen);
}
+*/
int copyByte = ((lenlen - 12) > (limit - (position + 12))) ? (limit - (position + 12)) : (lenlen - 12);
outputStream.write(byte_array, (position + 12), copyByte);
position = position + lenlen;