OSDN Git Service

JPEGヘッダの探し方(のデフォルト方式)を変更。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / canon / wrapper / CanonInterfaceProvider.java
1 package net.osdn.gokigen.a01d.camera.canon.wrapper;
2
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.util.Log;
6
7 import androidx.annotation.NonNull;
8 import androidx.preference.PreferenceManager;
9
10 import net.osdn.gokigen.a01d.IInformationReceiver;
11 import net.osdn.gokigen.a01d.camera.ICameraConnection;
12 import net.osdn.gokigen.a01d.camera.ICameraInformation;
13 import net.osdn.gokigen.a01d.camera.ICameraStatus;
14 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
15 import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
16 import net.osdn.gokigen.a01d.camera.ICaptureControl;
17 import net.osdn.gokigen.a01d.camera.IDisplayInjector;
18 import net.osdn.gokigen.a01d.camera.IFocusingControl;
19 import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
20 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
21 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
22 import net.osdn.gokigen.a01d.camera.canon.operation.CanonCaptureControl;
23 import net.osdn.gokigen.a01d.camera.canon.operation.CanonFocusingControl;
24 import net.osdn.gokigen.a01d.camera.canon.wrapper.connection.CanonConnection;
25 import net.osdn.gokigen.a01d.camera.canon.operation.CanonZoomLensControl;
26 import net.osdn.gokigen.a01d.camera.canon.wrapper.hardware.CanonCameraInformation;
27 import net.osdn.gokigen.a01d.camera.canon.wrapper.liveview.CanonLiveViewControl;
28 import net.osdn.gokigen.a01d.camera.canon.wrapper.status.CanonStatusChecker;
29 import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
30 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
31 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
32 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
33 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
34 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
35 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.IPtpIpRunModeHolder;
36 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.PtpIpRunMode;
37 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
38 import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
39 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
40 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
41 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
42
43 public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplayInjector
44 {
45     private final String TAG = toString();
46
47     private static final int ASYNC_RESPONSE_PORT = 15741;  // ??
48     private static final int CONTROL_PORT = 15740;
49     private static final int EVENT_PORT = 15740;
50     //private static final String CAMERA_IP = "192.168.0.1";
51
52     private final Activity activity;
53     private final PtpIpRunMode runMode;
54     private final CanonCameraInformation cameraInformation;
55     private CanonCaptureControl captureControl;
56     private CanonFocusingControl focusingControl;
57     private final CanonConnection canonConnection;
58     private final PtpIpCommandPublisher commandPublisher;
59     private final CanonLiveViewControl liveViewControl;
60     private final PtpIpAsyncResponseReceiver asyncReceiver;
61     private final CanonZoomLensControl zoomControl;
62     private final CanonStatusChecker statusChecker;
63     private final ICameraStatusUpdateNotify statusListener;
64     private final IInformationReceiver informationReceiver;
65
66     public CanonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
67     {
68         this.activity = context;
69
70         String ipAddress;
71         int delayMs = 30;
72         int sequenceType = 0;
73         boolean isSearchJpegHeader = true;
74         try
75         {
76             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
77             ipAddress = preferences.getString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
78             if (ipAddress == null)
79             {
80                 ipAddress = "192.168.0.1";
81             }
82             try
83             {
84                 String delayMsStr = preferences.getString(IPreferencePropertyAccessor.CANON_LIVEVIEW_WAIT, IPreferencePropertyAccessor.CANON_LIVEVIEW_WAIT_DEFAULT_VALUE);
85                 if (delayMsStr != null)
86                 {
87                     delayMs = Integer.parseInt(delayMsStr);
88                 }
89                 if (delayMs < 10)
90                 {
91                     delayMs = 10;
92                 }
93             }
94             catch (Exception e)
95             {
96                 e.printStackTrace();
97             }
98             try
99             {
100                 String sequenceTypeStr = preferences.getString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
101                 if (sequenceTypeStr != null)
102                 {
103                     sequenceType = Integer.parseInt(sequenceTypeStr);
104                 }
105             }
106             catch (Exception e)
107             {
108                 e.printStackTrace();
109             }
110
111             isSearchJpegHeader = !(sequenceType == 2);
112             Log.v(TAG, " --- search JPEG header : " + isSearchJpegHeader);
113         }
114         catch (Exception e)
115         {
116             e.printStackTrace();
117             ipAddress = "192.168.0.1";
118         }
119         Log.v(TAG, " Canon IP : " + ipAddress);
120         commandPublisher = new PtpIpCommandPublisher(ipAddress, CONTROL_PORT, false, false);
121         liveViewControl = new CanonLiveViewControl(context, this, delayMs, isSearchJpegHeader);  //
122         asyncReceiver = new PtpIpAsyncResponseReceiver(ipAddress, ASYNC_RESPONSE_PORT);
123         statusChecker = new CanonStatusChecker(commandPublisher, ipAddress, EVENT_PORT);
124         canonConnection = new CanonConnection(context, provider, this, statusChecker);
125         cameraInformation = new CanonCameraInformation();
126         zoomControl = new CanonZoomLensControl(context, commandPublisher);
127         this.statusListener = statusListener;
128         this.runMode = new PtpIpRunMode();
129         this.informationReceiver = informationReceiver;
130     }
131
132     @Override
133     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
134     {
135         Log.v(TAG, " injectDisplay()");
136         captureControl = new CanonCaptureControl(commandPublisher, frameDisplayer);
137         focusingControl = new CanonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
138     }
139
140     @Override
141     public ICameraConnection getCameraConnection()
142     {
143         return (canonConnection);
144     }
145
146     @Override
147     public ILiveViewControl getLiveViewControl()
148     {
149         return (liveViewControl);
150     }
151
152     @Override
153     public ILiveViewListener getLiveViewListener()
154     {
155         return (liveViewControl.getLiveViewListener());
156     }
157
158     @Override
159     public IFocusingControl getFocusingControl()
160     {
161         return (focusingControl);
162     }
163
164     @Override
165     public ICameraInformation getCameraInformation()
166     {
167         return (cameraInformation);
168     }
169
170     @Override
171     public IZoomLensControl getZoomLensControl()
172     {
173         return (zoomControl);
174     }
175
176     @Override
177     public ICaptureControl getCaptureControl()
178     {
179         return (captureControl);
180     }
181
182     @Override
183     public IDisplayInjector getDisplayInjector()
184     {
185         return (this);
186     }
187
188     @Override
189     public IPtpIpRunModeHolder getRunModeHolder()
190     {
191         return (runMode);
192     }
193
194     @Override
195     public IPtpIpCommandCallback getStatusHolder() {
196         return (statusChecker);
197     }
198
199     @Override
200     public IPtpIpCommandPublisher getCommandPublisher()
201     {
202         return (commandPublisher);
203     }
204
205     @Override
206     public IPtpIpCommunication getLiveviewCommunication()
207     {
208         return (liveViewControl);
209     }
210
211     @Override
212     public IPtpIpCommunication getAsyncEventCommunication()
213     {
214         return (asyncReceiver);
215     }
216
217     @Override
218     public IPtpIpCommunication getCommandCommunication()
219     {
220         return (commandPublisher);
221     }
222
223     @Override
224     public ICameraStatusWatcher getCameraStatusWatcher()
225     {
226         return (statusChecker);
227     }
228
229     @Override
230     public ICameraStatusUpdateNotify getStatusListener()
231     {
232         return (statusListener);
233     }
234
235     @Override
236     public ICameraStatus getCameraStatusListHolder()
237     {
238         return (statusChecker);
239     }
240
241     @Override
242     public IInformationReceiver getInformationReceiver()
243     {
244         // ちょっとこの引き回しは気持ちがよくない...
245         return (informationReceiver);
246     }
247
248     @Override
249     public ICameraStatusWatcher getStatusWatcher()
250     {
251         return (statusChecker);
252     }
253
254     @Override
255     public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
256     {
257         asyncReceiver.setEventSubscriber(receiver);
258     }
259
260 }