{
Log.v(TAG, "onCameraConnected()");
- try
- {
- ICameraConnection connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
+ try {
+ ICameraConnection connection;
+ if (interfaceProvider.useOlympusCamera())
+ {
+ connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
+ } else
+ {
+ connection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
+ }
+
if (connection != null)
{
// クラス構造をミスった...のでこんなところで、無理やりステータスを更新する
package net.osdn.gokigen.a01d.camera;
import android.app.Activity;
+import android.content.SharedPreferences;
import android.support.annotation.NonNull;
+import android.support.v7.preference.PreferenceManager;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlympusLiveViewListener;
import net.osdn.gokigen.a01d.camera.sony.wrapper.IDisplayInjector;
import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.OlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.ISonyInterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.wrapper.SonyCameraWrapper;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
public class CameraInterfaceProvider implements IInterfaceProvider
{
+ private final Activity context;
private final OlympusInterfaceProvider olympus;
private final SonyCameraWrapper sony;
public CameraInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider)
{
+ this.context = context;
olympus = new OlympusInterfaceProvider(context, provider);
sony = new SonyCameraWrapper(context, provider);
}
}
@Override
+ public IOlympusLiveViewListener getOlympusLiveViewListener()
+ {
+ return (olympus.getLiveViewListener());
+ }
+
+ @Override
public ISonyInterfaceProvider getSonyInterface()
{
return (sony);
}
+
+ /**
+ * OPCカメラを使用するかどうか
+ *
+ * @return true : OPCカメラ / false : OPCカメラではない
+ */
+ public boolean useOlympusCamera()
+ {
+ boolean ret = true;
+ try
+ {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String connectionMethod = preferences.getString(IPreferencePropertyAccessor.CONNECTION_METHOD, "OPC");
+ ret = connectionMethod.contains("OPC");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (ret);
+ }
}
package net.osdn.gokigen.a01d.camera;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlympusLiveViewListener;
import net.osdn.gokigen.a01d.camera.sony.wrapper.IDisplayInjector;
import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.ISonyInterfaceProvider;
{
IOlympusInterfaceProvider getOlympusInterface();
IDisplayInjector getOlympusDisplayInjector();
+ IOlympusLiveViewListener getOlympusLiveViewListener();
ISonyInterfaceProvider getSonyInterface();
+
+ boolean useOlympusCamera();
}
-package net.osdn.gokigen.a01d.camera.olympus.wrapper;
-
-import net.osdn.gokigen.a01d.liveview.CameraLiveViewListenerImpl;
+package net.osdn.gokigen.a01d.camera;
/**
*
public interface ILiveViewControl
{
void changeLiveViewSize(String size);
- void setLiveViewListener(CameraLiveViewListenerImpl listener);
+
void startLiveView();
void stopLiveView();
-
void updateDigitalZoom();
void updateMagnifyingLiveViewScale(boolean isChangeScale);
float getMagnifyingLiveViewScale();
import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraInformation;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
-import net.osdn.gokigen.a01d.camera.olympus.wrapper.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlympusLiveViewListener;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.connection.ble.ICameraPowerOn;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
import net.osdn.gokigen.a01d.camera.ICameraConnection;
IFocusingControl getFocusingControl();
ICaptureControl getCaptureControl();
ICameraInformation getCameraInformation();
+
+ IOlympusLiveViewListener getLiveViewListener();
}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympus.wrapper;
+
+import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
+
+public interface IOlympusLiveViewListener
+{
+ void setOlympusLiveViewListener(OLYCameraLiveViewListener listener);
+}
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.CameraPropertyUtilities;
-import net.osdn.gokigen.a01d.liveview.CameraLiveViewListenerImpl;
import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
import java.util.Map;
import jp.co.olympus.camerakit.OLYCamera;
+import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
/**
*
*
*/
-class OlyCameraWrapper implements ICameraRunMode, ILiveViewControl
+class OlyCameraWrapper implements ICameraRunMode, ILiveViewControl, IOlympusLiveViewListener
{
private final String TAG = toString();
private final Activity context;
}
@Override
- public void setLiveViewListener(CameraLiveViewListenerImpl listener)
+ public void setOlympusLiveViewListener(OLYCameraLiveViewListener listener)
{
try
{
*/
private float getMagnifyingLiveViewScale(boolean isChangeScale)
{
- float scale = 1.0f;
+ float scale;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String value = preferences.getString(IPreferencePropertyAccessor.MAGNIFYING_LIVE_VIEW_SCALE, IPreferencePropertyAccessor.MAGNIFYING_LIVE_VIEW_SCALE_DEFAULT_VALUE);
try
*/
private float getDigitalZoomScalePreference()
{
- float scale = 1.0f;
+ float scale;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String value = preferences.getString(IPreferencePropertyAccessor.DIGITAL_ZOOM_LEVEL, IPreferencePropertyAccessor.DIGITAL_ZOOM_LEVEL_DEFAULT_VALUE);
try
import android.app.Activity;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
import net.osdn.gokigen.a01d.camera.sony.wrapper.IDisplayInjector;
import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.olympus.operation.ICaptureControl;
{
return (propertyListener);
}
+
+ @Override
+ public IOlympusLiveViewListener getLiveViewListener()
+ {
+ return (wrapper);
+ }
}
package net.osdn.gokigen.a01d.camera.sony;
import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
public interface ISonyInterfaceProvider
{
ICameraConnection getSonyCameraConnection();
-
+ ILiveViewControl getSonyLiveViewControl();
+ ILiveViewListener getSonyLiveViewListener();
}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.sony.wrapper;
+
+import java.util.Map;
+
+public interface ISonyCameraLiveViewListener
+{
+ void onUpdateLiveView(byte[] data, Map<String, Object> metadata);
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.sony.wrapper;
+
+public interface ISonyLiveViewListener
+{
+ void setSonyLiveViewListener(ISonyCameraLiveViewListener listener);
+}
import net.osdn.gokigen.a01d.camera.ICameraConnection;
import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
import net.osdn.gokigen.a01d.camera.sony.ISonyInterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.wrapper.connection.SonyCameraConnection;
import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.CameraEventObserver;
import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.ICameraChangeListener;
import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.ICameraEventObserver;
+import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.ICameraStatusHolder;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
public class SonyCameraWrapper implements ISonyCameraHolder, ISonyInterfaceProvider
{
private ISonyCamera sonyCamera = null;
private ISonyCameraApi sonyCameraApi = null;
private ICameraEventObserver eventObserver = null;
+ private SonyLiveViewControl liveViewControl = null;
public SonyCameraWrapper(final Activity context, final ICameraStatusReceiver statusReceiver)
{
Log.v(TAG, " prepare : " + sonyCamera.getFriendlyName() + " " + sonyCamera.getModelName());
sonyCameraApi = SonyCameraApi.newInstance(sonyCamera);
eventObserver = CameraEventObserver.newInstance(context, sonyCameraApi);
-
-}
+ liveViewControl = new SonyLiveViewControl(sonyCameraApi);
+ }
@Override
public void startEventWatch(@Nullable ICameraChangeListener listener)
}
eventObserver.activate();
eventObserver.start();
+ ICameraStatusHolder holder = eventObserver.getCameraStatusHolder();
+ holder.getLiveviewStatus();
}
}
catch (Exception e) {
{
return (new SonyCameraConnection(context, provider, this));
}
+
+ @Override
+ public ILiveViewControl getSonyLiveViewControl()
+ {
+ return (liveViewControl);
+ }
+
+ @Override
+ public ILiveViewListener getSonyLiveViewListener()
+ {
+ return (liveViewControl.getSonyLiveViewListener());
+ }
}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.sony.wrapper;
+
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.sony.wrapper.utils.SimpleLiveviewSlicer;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.SonyCameraLiveViewListenerImpl;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class SonyLiveViewControl implements ILiveViewControl
+{
+ private final String TAG = toString();
+ private final ISonyCameraApi cameraApi;
+ //private final BlockingQueue<byte[]> mJpegQueue = new ArrayBlockingQueue<>(2);
+ private final SonyCameraLiveViewListenerImpl liveViewListener;
+ private boolean whileFetching = false;
+ private static final int FETCH_ERROR_MAX = 30;
+
+ SonyLiveViewControl(@NonNull ISonyCameraApi cameraApi)
+ {
+ this.cameraApi = cameraApi;
+ liveViewListener = new SonyCameraLiveViewListenerImpl();
+ }
+
+ @Override
+ public void changeLiveViewSize(String size)
+ {
+
+ }
+
+ @Override
+ public void startLiveView()
+ {
+ Log.v(TAG, "startLiveView()");
+ try
+ {
+ Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ JSONObject replyJson;
+ replyJson = cameraApi.startLiveview();
+ if (!SonyCameraApi.isErrorReply(replyJson))
+ {
+ try
+ {
+ JSONArray resultsObj = replyJson.getJSONArray("result");
+ if (1 <= resultsObj.length())
+ {
+ // Obtain liveview URL from the result.
+ final String liveviewUrl = resultsObj.getString(0);
+ start(liveviewUrl);
+ }
+ }
+ 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()");
+ try
+ {
+ Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ cameraApi.stopLiveview();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void updateDigitalZoom()
+ {
+
+ }
+
+ @Override
+ public void updateMagnifyingLiveViewScale(boolean isChangeScale)
+ {
+
+ }
+
+ @Override
+ public float getMagnifyingLiveViewScale()
+ {
+ return (1.0f);
+ }
+
+ @Override
+ public float getDigitalZoomScale()
+ {
+ return (1.0f);
+ }
+
+
+
+ public boolean start(final String streamUrl)
+ {
+ if (streamUrl == null)
+ {
+ Log.e(TAG, "start() streamUrl is null.");
+ return (false);
+ }
+ if (whileFetching)
+ {
+ Log.v(TAG, "start() already starting.");
+ }
+ whileFetching = true;
+
+ // A thread for retrieving liveview data from server.
+ try
+ {
+ Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Log.d(TAG, "Starting retrieving streaming data from server.");
+ SimpleLiveviewSlicer slicer = null;
+ int continuousNullDataReceived = 0;
+ try
+ {
+ // Create Slicer to open the stream and parse it.
+ slicer = new SimpleLiveviewSlicer();
+ slicer.open(streamUrl);
+
+ while (whileFetching)
+ {
+ final SimpleLiveviewSlicer.Payload payload = slicer.nextPayload();
+ if (payload == null)
+ {
+ Log.v(TAG, "Liveview Payload is null.");
+ continuousNullDataReceived++;
+ if (continuousNullDataReceived > FETCH_ERROR_MAX)
+ {
+ Log.d(TAG, " FETCH ERROR MAX OVER ");
+ //break;
+ }
+ continue;
+ }
+ //if (mJpegQueue.size() == 2)
+ //{
+ // mJpegQueue.remove();
+ //}
+ //mJpegQueue.add(payload.getJpegData());
+ liveViewListener.onUpdateLiveView(payload.getJpegData(), null);
+ continuousNullDataReceived = 0;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (slicer != null)
+ {
+ slicer.close();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ //mJpegQueue.clear();
+ whileFetching = false;
+ if (continuousNullDataReceived > FETCH_ERROR_MAX)
+ {
+ // 再度ライブビューのスタートをやってみる。
+ continuousNullDataReceived = 0;
+ start(streamUrl);
+ }
+ }
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (true);
+ }
+
+ public ILiveViewListener getSonyLiveViewListener()
+ {
+ return (liveViewListener);
+ }
+}
package net.osdn.gokigen.a01d.camera.sony.wrapper.connection;
+import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCamera;
import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCameraHolder;
+import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.CameraChangeListerTemplate;
/**
public class SonyCameraConnectSequence implements Runnable, SonySsdpClient.ISearchResultCallback
{
private final String TAG = this.toString();
- private final Context context;
+ private final Activity context;
private final ICameraConnection cameraConnection;
private final ISonyCameraHolder cameraHolder;
private final ICameraStatusReceiver cameraStatusReceiver;
private final SonySsdpClient client;
- SonyCameraConnectSequence(Context context, ICameraStatusReceiver statusReceiver, final ICameraConnection cameraConnection, final @NonNull ISonyCameraHolder cameraHolder)
+ SonyCameraConnectSequence(Activity context, ICameraStatusReceiver statusReceiver, final ICameraConnection cameraConnection, final @NonNull ISonyCameraHolder cameraHolder)
{
Log.v(TAG, "SonyCameraConnectSequence");
this.context = context;
try
{
cameraHolder.prepare();
+ cameraHolder.startEventWatch(new CameraChangeListerTemplate());
}
catch (Exception e)
{
e.printStackTrace();
}
+ Log.v(TAG, "CameraConnectSequence:: connected.");
+ onConnectNotify();
}
});
thread.start();
}
}
+ private void onConnectNotify()
+ {
+ try
+ {
+ final Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ // カメラとの接続確立を通知する
+ cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_connected));
+ cameraStatusReceiver.onCameraConnected();
+ Log.v(TAG, "onConnectNotify()");
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void waitForAMoment(long mills)
+ {
+ if (mills > 0)
+ {
+ try {
+ Log.v(TAG, " WAIT " + mills + "ms");
+ Thread.sleep(mills);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
@Override
public void onErrorFinished(String reason)
{
cameraConnection.alertConnectingFailed(reason);
}
+
}
package net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener;
+import android.util.Log;
+
import java.util.List;
-class CameraChangeListerTemplate implements ICameraChangeListener
+public class CameraChangeListerTemplate implements ICameraChangeListener
{
- CameraChangeListerTemplate()
+ private static final String TAG = CameraChangeListerTemplate.class.getSimpleName();
+
+ public CameraChangeListerTemplate()
{
+ Log.v(TAG, "CameraChangeListerTemplate");
}
@Override
public void onApiListModified(List<String> apis)
{
-
+ Log.v(TAG, "onApiListModified() : " + apis.size());
}
@Override
public void onCameraStatusChanged(String status)
{
-
+ Log.v(TAG, "onCameraStatusChanged() : " + status);
}
@Override
public void onLiveviewStatusChanged(boolean status)
{
-
+ Log.v(TAG, "onLiveviewStatusChanged() : " + status);
}
@Override
public void onShootModeChanged(String shootMode)
{
-
+ Log.v(TAG, "onShootModeChanged() : " + shootMode);
}
@Override
public void onZoomPositionChanged(int zoomPosition)
{
-
+ Log.v(TAG, "onZoomPositionChanged() : " + zoomPosition);
}
@Override
public void onStorageIdChanged(String storageId)
{
-
+ Log.v(TAG, "onStorageIdChanged() : " + storageId);
}
@Override
public void onResponseError()
{
-
+ Log.v(TAG, "onResponseError() ");
}
}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.sony.wrapper.utils;
+
+import android.util.Log;
+
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class SimpleLiveviewSlicer
+{
+ private static final String TAG = SimpleLiveviewSlicer.class.getSimpleName();
+ public static final class Payload
+ {
+ // jpeg data container
+ final byte[] jpegData;
+
+ // padding data container
+ final byte[] paddingData;
+
+ /**
+ * Constructor
+ */
+ private Payload(byte[] jpeg, byte[] padding)
+ {
+ this.jpegData = jpeg;
+ this.paddingData = padding;
+ }
+ public byte[] getJpegData()
+ {
+ return (jpegData);
+ }
+ }
+
+ private static final int CONNECTION_TIMEOUT = 2000; // [msec]
+ private HttpURLConnection mHttpConn;
+ private InputStream mInputStream;
+
+ public void open(String liveviewUrl)
+ {
+ try
+ {
+ if ((mInputStream != null)||(mHttpConn != null))
+ {
+ Log.v(TAG, "Slicer is already open.");
+ return;
+ }
+
+ final URL urlObj = new URL(liveviewUrl);
+ mHttpConn = (HttpURLConnection) urlObj.openConnection();
+ mHttpConn.setRequestMethod("GET");
+ mHttpConn.setConnectTimeout(CONNECTION_TIMEOUT);
+ mHttpConn.connect();
+ if (mHttpConn.getResponseCode() == HttpURLConnection.HTTP_OK)
+ {
+ mInputStream = mHttpConn.getInputStream();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void close()
+ {
+ try
+ {
+ if (mInputStream != null)
+ {
+ mInputStream.close();
+ mInputStream = null;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ try
+ {
+ if (mHttpConn != null)
+ {
+ mHttpConn.disconnect();
+ mHttpConn = null;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public Payload nextPayload()
+ {
+ Payload payload = null;
+ try
+ {
+
+ while ((mInputStream != null)&&(payload == null))
+ {
+ // Common Header
+ int readLength = 1 + 1 + 2 + 4;
+ byte[] commonHeader = readBytes(mInputStream, readLength);
+ if ((commonHeader == null)||(commonHeader.length != readLength))
+ {
+ Log.v(TAG, "Cannot read stream for common header.");
+ payload = null;
+ break;
+ }
+ if (commonHeader[0] != (byte) 0xFF)
+ {
+ Log.v(TAG, "Unexpected data format. (Start byte)");
+ payload = null;
+ break;
+ }
+ switch (commonHeader[1])
+ {
+ case (byte) 0x12:
+ // This is information header for streaming. skip this packet.
+ readLength = 4 + 3 + 1 + 2 + 118 + 4 + 4 + 24;
+ //commonHeader = null;
+ readBytes(mInputStream, readLength);
+ break;
+
+ case (byte) 0x01:
+ case (byte) 0x11:
+ payload = readPayload();
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (payload);
+ }
+
+ private Payload readPayload()
+ {
+ try
+ {
+ if (mInputStream != null)
+ {
+ // Payload Header
+ int readLength = 4 + 3 + 1 + 4 + 1 + 115;
+ byte[] payloadHeader = readBytes(mInputStream, readLength);
+ if ((payloadHeader == null)||(payloadHeader.length != readLength))
+ {
+ throw new EOFException("Cannot read stream for payload header.");
+ }
+ if (payloadHeader[0] != (byte) 0x24 || payloadHeader[1] != (byte) 0x35
+ || payloadHeader[2] != (byte) 0x68
+ || payloadHeader[3] != (byte) 0x79)
+ {
+ throw new EOFException("Unexpected data format. (Start code)");
+ }
+ int jpegSize = bytesToInt(payloadHeader, 4, 3);
+ int paddingSize = bytesToInt(payloadHeader, 7, 1);
+
+ // Payload Data
+ byte[] jpegData = readBytes(mInputStream, jpegSize);
+ byte[] paddingData = readBytes(mInputStream, paddingSize);
+
+ return (new Payload(jpegData, paddingData));
+ }
+ }
+ catch (EOFException eo)
+ {
+ eo.printStackTrace();
+ close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (null);
+ }
+
+ private static int bytesToInt(byte[] byteData, int startIndex, int count)
+ {
+ int ret = 0;
+ try
+ {
+ for (int i = startIndex; i < startIndex + count; i++)
+ {
+ ret = (ret << 8) | (byteData[i] & 0xff);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (ret);
+ }
+
+ private static byte[] readBytes(InputStream in, int length)
+ {
+ byte[] ret;
+ try
+ {
+ ByteArrayOutputStream tmpByteArray = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ while (true)
+ {
+ int trialReadlen = Math.min(buffer.length, length - tmpByteArray.size());
+ int readlen = in.read(buffer, 0, trialReadlen);
+ if (readlen < 0)
+ {
+ break;
+ }
+ tmpByteArray.write(buffer, 0, readlen);
+ if (length <= tmpByteArray.size())
+ {
+ break;
+ }
+ }
+ ret = tmpByteArray.toByteArray();
+ tmpByteArray.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ ret = null;
+ }
+ return (ret);
+ }
+}
import net.osdn.gokigen.a01d.liveview.bitmapconvert.ImageConvertFactory;
import net.osdn.gokigen.a01d.liveview.gridframe.GridFrameFactory;
import net.osdn.gokigen.a01d.liveview.gridframe.IGridFrameDrawer;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.IImageDataReceiver;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.OlympusCameraLiveViewListenerImpl;
import net.osdn.gokigen.a01d.liveview.message.IMessageDrawer;
import net.osdn.gokigen.a01d.liveview.message.IMessageHolder;
import net.osdn.gokigen.a01d.liveview.message.ShowMessageHolder;
* (OLYMPUS の ImageCaptureSample そのまま)
*
*/
-public class CameraLiveImageView extends View implements CameraLiveViewListenerImpl.IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify, IIndicatorControl
+public class CameraLiveImageView extends View implements IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify, IIndicatorControl
{
private final String TAG = this.toString();
/**
* Sets a image to view.
- * (CameraLiveViewListenerImpl.IImageDataReceiver の実装)
+ * (OlympusCameraLiveViewListenerImpl.IImageDataReceiver の実装)
*
* @param data A image of live-view.
* @param metadata A metadata of the image.
*/
- public void setImageData(byte[] data, Map<String, Object> metadata) {
+ public void setImageData(byte[] data, Map<String, Object> metadata)
+ {
Bitmap bitmap;
int rotationDegrees;
- if (data != null && metadata != null) {
+ if (data != null)
+ {
// Create a bitmap.
- try {
+ try
+ {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
- } catch (OutOfMemoryError e) {
+ }
+ catch (OutOfMemoryError e)
+ {
e.printStackTrace();
return;
}
// Acquire a rotation degree of image.
int orientation = ExifInterface.ORIENTATION_UNDEFINED;
- if (metadata.containsKey(EXIF_ORIENTATION)) {
+ if ((metadata != null)&&(metadata.containsKey(EXIF_ORIENTATION)))
+ {
orientation = Integer.parseInt((String) metadata.get(EXIF_ORIENTATION));
}
- switch (orientation) {
+ switch (orientation)
+ {
case ExifInterface.ORIENTATION_NORMAL:
rotationDegrees = 0;
break;
imageBitmap = bitmap;
imageRotationDegrees = rotationDegrees;
}
-
refreshCanvas();
}
* @param point A point on image area. (e.g. a live preview image)
* @return A point on view area. (e.g. a touch panel view)
*/
- private PointF convertPointFromImageArea(PointF point) {
+ private PointF convertPointFromImageArea(PointF point)
+ {
if (imageBitmap == null) {
return new PointF();
}
import net.osdn.gokigen.a01d.IChangeScene;
import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.olympus.operation.ICaptureControl;
import net.osdn.gokigen.a01d.camera.olympus.operation.IFocusingControl;
private final ILiveImageStatusNotify statusNotify;
private final IStatusViewDrawer statusViewDrawer;
private final IChangeScene changeScene;
+ private final IInterfaceProvider interfaceProvider;
private final IFocusingControl focusingControl;
private final ICaptureControl captureControl;
private final IOlyCameraPropertyProvider propertyProvider;
private final ICameraConnection cameraConnection;
private final IFavoriteSettingDialogKicker dialogKicker;
- LiveViewClickTouchListener(Context context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IOlympusInterfaceProvider interfaceProvider, IFavoriteSettingDialogKicker dialogKicker)
+ LiveViewClickTouchListener(Context context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IInterfaceProvider interfaceProvider, IFavoriteSettingDialogKicker dialogKicker)
{
this.context = context;
this.statusNotify = imageStatusNotify;
this.statusViewDrawer = statusView;
this.changeScene = changeScene;
- this.focusingControl = interfaceProvider.getFocusingControl();
- this.captureControl = interfaceProvider.getCaptureControl();
- this.propertyProvider = interfaceProvider.getCameraPropertyProvider();
- this.cameraInformation = interfaceProvider.getCameraInformation();
- this.cameraConnection = interfaceProvider.getOlyCameraConnection();
+ this.interfaceProvider = interfaceProvider;
+ this.focusingControl = interfaceProvider.getOlympusInterface().getFocusingControl();
+ this.captureControl = interfaceProvider.getOlympusInterface().getCaptureControl();
+ this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();
+ this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
+ this.cameraConnection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
this.dialogKicker = dialogKicker;
}
Log.v(TAG, "showFavoriteDialog()");
try
{
- if (!useOlympusCamera())
+ if (!interfaceProvider.useOlympusCamera())
{
// OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
}
- /**
- * OPCカメラを使用するかどうか
- *
- * @return true : OPCカメラ / false : OPCカメラではない
- */
- private boolean useOlympusCamera()
- {
- boolean ret = true;
- try
- {
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- String connectionMethod = preferences.getString(IPreferencePropertyAccessor.CONNECTION_METHOD, "OPC");
- ret = connectionMethod.contains("OPC");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return (ret);
- }
-
-
}
import net.osdn.gokigen.a01d.R;
import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.wrapper.IDisplayInjector;
-import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.olympus.myolycameraprops.LoadSaveCameraProperties;
import net.osdn.gokigen.a01d.camera.olympus.myolycameraprops.LoadSaveMyCameraPropertyDialog;
import net.osdn.gokigen.a01d.camera.olympus.operation.IZoomLensControl;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraInformation;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.IFocusingModeNotify;
-import net.osdn.gokigen.a01d.camera.olympus.wrapper.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
import net.osdn.gokigen.a01d.camera.ICameraConnection;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraProperty;
import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.OlympusCameraLiveViewListenerImpl;
import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
/**
private ILiveViewControl liveViewControl = null;
private IZoomLensControl zoomLensControl = null;
- private IOlympusInterfaceProvider interfaceProvider = null;
+ private IInterfaceProvider interfaceProvider = null;
private IDisplayInjector interfaceInjector = null;
- private CameraLiveViewListenerImpl liveViewListener = null;
+ private OlympusCameraLiveViewListenerImpl liveViewListener = null;
private IChangeScene changeScene = null;
private ICameraInformation cameraInformation = null;
private LiveViewClickTouchListener onClickTouchListener = null;
public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
{
LiveViewFragment instance = new LiveViewFragment();
- instance.prepare(sceneSelector, provider.getOlympusInterface(), provider.getOlympusDisplayInjector());
+ instance.prepare(sceneSelector, provider, provider.getOlympusDisplayInjector());
// パラメータはBundleにまとめておく
Bundle arguments = new Bundle();
{
super.onCreate(savedInstanceState);
Log.v(TAG, "onCreate()");
-
if (liveViewListener == null)
{
- liveViewListener = new CameraLiveViewListenerImpl();
+ liveViewListener = new OlympusCameraLiveViewListenerImpl();
}
}
/**
*
*/
- private void prepare(IChangeScene sceneSelector, IOlympusInterfaceProvider interfaceProvider, IDisplayInjector interfaceInjector)
+ private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider, IDisplayInjector interfaceInjector)
{
+ Log.v(TAG, "prepare()");
this.changeScene = sceneSelector;
this.interfaceProvider = interfaceProvider;
- this.liveViewControl = interfaceProvider.getLiveViewControl();
- this.zoomLensControl = interfaceProvider.getZoomLensControl();
this.interfaceInjector = interfaceInjector;
- this.cameraInformation = interfaceProvider.getCameraInformation();
+
+ if (interfaceProvider.useOlympusCamera())
+ {
+ this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
+ this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
+ this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
+ }
+ else
+ {
+ this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
+ this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl(); // 要変更
+ this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation(); // 要変更
+ }
}
+
/**
* カメラとの接続状態の更新
*
{
if (liveViewControl == null)
{
- Log.v(TAG, "startLiveView() : liveViewControl is null.");
- return;
+ if (interfaceProvider.useOlympusCamera())
+ {
+ Log.v(TAG, "startLiveView() : liveViewControl is null.");
+ return;
+ }
+ else
+ {
+ // ダミー
+ prepare(changeScene, interfaceProvider, interfaceInjector);
+ }
}
try
{
// ライブビューの開始
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
- liveViewControl.setLiveViewListener(liveViewListener);
- liveViewListener.setCameraLiveImageView(imageView);
+ ILiveViewListener lvListener;
+ if (interfaceProvider.useOlympusCamera())
+ {
+ interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
+ lvListener = liveViewListener;
+ }
+ else
+ {
+ lvListener = interfaceProvider.getSonyInterface().getSonyLiveViewListener();
+ }
+ lvListener.setCameraLiveImageView(imageView);
liveViewControl.startLiveView();
// デジタルズームの設定
{
try
{
- IOlyCameraPropertyProvider propertyProvider = interfaceProvider.getCameraPropertyProvider();
+ IOlyCameraPropertyProvider propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();
if (propertyProvider != null)
{
propertyProvider.setCameraPropertyValue(IOlyCameraProperty.AE, IOlyCameraProperty.AE_PINPOINT);
{
Log.v(TAG, "showFavoriteSettingDialog()");
- // OPCチェック
-
-
LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
- dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider));
+ dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
dialog.show(getFragmentManager(), "my_dialog");
}
catch (Exception e)
--- /dev/null
+package net.osdn.gokigen.a01d.liveview.liveviewlistener;
+
+import java.util.Map;
+
+public interface IImageDataReceiver
+{
+ void setImageData(byte[] data, Map<String, Object> metadata);
+}
--- /dev/null
+package net.osdn.gokigen.a01d.liveview.liveviewlistener;
+
+public interface ILiveViewListener
+{
+ void setCameraLiveImageView(IImageDataReceiver target);
+}
-package net.osdn.gokigen.a01d.liveview;
+package net.osdn.gokigen.a01d.liveview.liveviewlistener;
import java.util.Map;
* (LiveViewFragment用)
*
*/
-public class CameraLiveViewListenerImpl implements OLYCameraLiveViewListener
+public class OlympusCameraLiveViewListenerImpl implements OLYCameraLiveViewListener, ILiveViewListener
{
private IImageDataReceiver imageView = null;
/**
* コンストラクタ
*/
- public CameraLiveViewListenerImpl()
+ public OlympusCameraLiveViewListenerImpl()
{
//
}
* 更新するImageViewを拾う
*
*/
+ @Override
public void setCameraLiveImageView(IImageDataReceiver target)
{
this.imageView = target;
imageView.setImageData(data, metadata);
}
}
-
- /**
- * CameraLiveImageView
- */
- public interface IImageDataReceiver
- {
- void setImageData(byte[] data, Map<String, Object> metadata);
- }
}
--- /dev/null
+package net.osdn.gokigen.a01d.liveview.liveviewlistener;
+
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCameraLiveViewListener;
+
+import java.util.Map;
+
+public class SonyCameraLiveViewListenerImpl implements ILiveViewListener, ISonyCameraLiveViewListener
+{
+ private final String TAG = toString();
+ private IImageDataReceiver imageView = null;
+
+ /**
+ * コンストラクタ
+ */
+ public SonyCameraLiveViewListenerImpl()
+ {
+
+ }
+
+ /**
+ * 更新するImageViewを拾う
+ *
+ */
+ @Override
+ public void setCameraLiveImageView(IImageDataReceiver target)
+ {
+ imageView = target;
+ }
+
+ /**
+ * LiveViewの画像データを更新する
+ *
+ */
+ @Override
+ public void onUpdateLiveView(byte[] data, Map<String, Object> metadata)
+ {
+ if (imageView != null)
+ {
+ //Log.v(TAG, "onUpdateLiveView() " + data.length);
+ imageView.setImageData(data, metadata);
+ }
+ }
+}