/td> 44 44
 
45
-    private static final String MSG_TYPE_CAMERA_ERROR = "camero error";//相机错误,可能是线松动了。先exit,然后重新init
46
-    private static final String MSG_TYPE_NOT_INIT = "not init";  //需要初始化
47
-    private static final String MSG_TYPE_NAME_ERROR = "name error";  //继续调用waitforevent
48
-    private static final String MSG_TYPE_TIME_OUT = "time out";  //继续调用waitforevent
49
-    private static final String MSG_TYPE_CREATE_FILE_ERROR = "creat error";//照片文件创建失败
45
+    private PtpService ptp;
46
+    private Camera camera;
47
+    private int[] origin = new int[0];
50 48
 
51
-    private static final int MAX_NO_PHOTO_COUNT = 500;
52
-    private int count = 0;
49
+    @Override
50
+    public void onCreate() {
51
+        super.onCreate();
52
+        ptp = PtpService.Singleton.getInstance(this);
53
+    }
53 54
 
54 55
     @Override
55 56
     public IBinder onBind(Intent intent) {
@@ -59,40 +60,27 @@ public class CameraService extends Service {
59 60
     @Override
60 61
     public int onStartCommand(Intent intent, int flags, int startId) {
61 62
         LogHelper.d("czy","CameraService onStartCommand  ");
62
-        if(intent!=null&&intent.getIntExtra(EXTRA_CMD,0)>0){
63
+        if(camera == null){
64
+            startCamera(intent);
65
+        }else if(intent!=null&&intent.getIntExtra(EXTRA_CMD,0)>0){
63 66
             int cmd = intent.getIntExtra(EXTRA_CMD,0);
64 67
             if(cmd == CMD_EXIT_CAMERA_CONNECTION){
65 68
                 LogHelper.d("czy","CameraService 收到停止进程任务");
66
-                stopCameraService();
69
+                stopCamera();
67 70
             }else if(cmd == CMD_INIT_CAMERA_CONNECTION){
68
-                if(!isInitExecuted){
69
-                    LogHelper.d("czy","CameraService 收到初始化相机任务");
70
-                    count = 0;
71
-                    cameraInitTask = new CameraInitTask();
72
-                    cameraInitTask.execute();
73
-                }else{
74
-                    LogHelper.d("czy","CameraService 相机初始化成功");
71
+                if(camera != null){
75 72
                     Bundle bundle = new Bundle();
76 73
                     bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
77 74
                     sendCameraIntent(bundle);
78 75
                 }
79 76
             }else if(cmd == CMD_START_CAPTURE_PHOTO){
80
-                if(isInitExecuted){
77
+                if(camera !=null){
81 78
                     LogHelper.d("czy","CameraService 收到开始拍摄任务");
82
-                    sessionWorkingDirPath = intent.getStringExtra(EXTRA_SESSION_DIR);
83
-                    if(!TextUtils.isEmpty(sessionWorkingDirPath)){
84
-                        startCapture();
85
-                    }
79
+                   startCapture();
86 80
                 }
87 81
             }else if(cmd == CMD_STOP_CAPTURE_PHOTO){
88
-               stopCapture();
89
-            }
90
-        }else{
91
-            if(!isInitExecuted){
92
-                LogHelper.d("czy","CameraService自动重启,初始化相机");
93
-                count = 0;
94
-                cameraInitTask = new CameraInitTask();
95
-                cameraInitTask.execute();
82
+                LogHelper.d("czy","CameraService 收到结束拍摄任务");
83
+                stopCapture();
96 84
             }
97 85
         }
98 86
         return super.onStartCommand(intent, flags, startId);
@@ -100,89 +88,38 @@ public class CameraService extends Service {
100 88
 
101 89
     @Override
102 90
     public void onDestroy() {
91
+        stopCamera();
103 92
         super.onDestroy();
104 93
     }
105 94
 
106
-    private void stopCameraService(){
107
-        count = 0;
95
+    private void startCamera(Intent intent){
96
+        LogHelper.d("czy","CameraService 尝试与相机建立连接");
97
+        ptp.setCameraListener(this);
98
+        ptp.initialize(this, intent);
99
+    }
100
+    private void stopCamera(){
108 101
         LogHelper.d("czy","CameraService stopCameraService  ");
109
-        if(cameraInitTask!=null){
110
-            cameraInitTask.cancel();
111
-        }
112 102
         if(photoCaptureTimer !=null){
113 103
             photoCaptureTimer.cancel();
114 104
             photoCaptureTimer = null;
115 105
         }
116
-        new CameraExitTask().execute();
106
+        ptp.setCameraListener(null);
107
+        ptp.shutdown();
117 108
         stopSelf();
118 109
         Process.killProcess(Process.myPid());
119 110
         System.exit(0);
120 111
     }
121 112
 
122
-    class CameraInitTask extends AsyncTask<Void,Integer,Integer>{
123
-
124
-        private boolean isCancelled = false;
125
-
126
-        public void cancel(){
127
-            isCancelled = true;
128
-        }
129
-
130
-        @Override
131
-        protected Integer doInBackground(Void... params) {
132
-            LogHelper.d("czy","CameraService CameraInitTask  ");
133
-            try{
134
-                return  CameraJNIInterface.getInstance().java_mygpcamerainit();
135
-            }catch (Throwable t){
136
-                t.printStackTrace();
137
-                return -1;
138
-            }
139
-        }
140
-
141
-        @Override
142
-        protected void onPostExecute(Integer result) {
143
-
144
-            if(isCancelled){
145
-                return;
146
-            }
147
-            if(result>=0){
148
-                LogHelper.d("czy","CameraService 相机初始化成功");
149
-                isInitExecuted = true;
150
-                Bundle bundle = new Bundle();
151
-                bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
152
-                sendCameraIntent(bundle);
153
-            }else{
154
-                LogHelper.d("czy","CameraService 相机初始化失败,杀掉进程,返回值是"+result);
155
-                Bundle bundle = new Bundle();
156
-                bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
157
-                sendCameraIntent(bundle);
158
-                stopCameraService();
159
-            }
160
-        }
161
-    }
162
-
163
-    class CameraExitTask extends AsyncTask<Void,Integer,Integer>{
164
-
165
-
166
-        @Override
167
-        protected Integer doInBackground(Void... params) {
168
-            try{
169
-                return  CameraJNIInterface.getInstance().java_mygpcameraexit();
170
-            }catch (Throwable t){
171
-                t.printStackTrace();
172
-            }
173
-            return 0;
174
-        }
175 113
 
176
-    }
177 114
     public void startCapture() {
178 115
         stopCapture();
179 116
         photoCaptureTimer = new Timer();
180 117
         photoCaptureTimer.schedule(new TimerTask() {
181 118
             @Override
182 119
             public void run() {
183
-                fetchPhotoTask();
120
+                camera.retrieveImageHandles(CameraService.this, 0xFFFFFFFF, PtpConstants.ObjectFormat.EXIF_JPEG);
184 121
             }
185
-        },1000, Preferences.getInstance().getCameraQueryInterval());
122
+        },0, Preferences.getInstance().getCameraQueryInterval());
186 123
     }
187 124
 
188 125
     public void stopCapture(){
@@ -190,66 +127,174 @@ public class CameraService extends Service {
190 127
             photoCaptureTimer.cancel();
191 128
             photoCaptureTimer = null;
192 129
         }
130
+        origin = new int[0];
193 131
     }
194 132
 
195
-    private void fetchPhotoTask(){
196
-        if(!isLastQueryReturned){
197
-            LogHelper.d("czy","CameraService fetchPhotoTask last query not finished,return ");
198
-            return;
199
-        }
133
+    private void sendCameraIntent(Bundle bundle){
134
+        Intent intent = new Intent(ACTION_CAMERA_SERVICE_STATUS_CHANGE);
135
+        intent.putExtras(bundle);
136
+        sendBroadcast(intent);
137
+    }
200 138
 
201
-        isLastQueryReturned = false;
202
-        String eventMsg = CameraJNIInterface.getInstance().java_mygpcamerawaitforevent(sessionWorkingDirPath);
203
-        LogHelper.d("czy","CameraService mygpcamerawaitforevent return result = "+eventMsg);
204
-        if(eventMsg!=null && eventMsg.length()>0){
205
-            count = 0;
206
-            if(MSG_TYPE_NOT_INIT.equalsIgnoreCase(eventMsg)||MSG_TYPE_CAMERA_ERROR.equalsIgnoreCase(eventMsg)){
207
-                LogHelper.d("czy","CameraService fetchPhotoTask 相机连接错误,重新连接试试");
208
-                Bundle bundle = new Bundle();
209
-                bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
210
-                sendCameraIntent(bundle);
211
-                stopCameraService();
212
-            }else if(MSG_TYPE_TIME_OUT.equalsIgnoreCase(eventMsg)||MSG_TYPE_NAME_ERROR.equalsIgnoreCase(eventMsg)){
213
-                count++;
214
-                if(count>=MAX_NO_PHOTO_COUNT){
215
-                    LogHelper.d("czy","CameraService fetchPhotoTask 太久没发现新照片了,重新连接试试");
216
-                    Bundle bundle = new Bundle();
217
-                    bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
218
-                    sendCameraIntent(bundle);
219
-                    stopCameraService();
139
+
140
+    @Override
141
+    public void onCameraStarted(Camera camera) {
142
+        this.camera = camera;
143
+        LogHelper.d("czy","CameraService 相机初始化成功");
144
+        Bundle bundle = new Bundle();
145
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
146
+        sendCameraIntent(bundle);
147
+    }
148
+
149
+    @Override
150
+    public void onCameraStopped(Camera camera) {
151
+        this.camera = null;
152
+        Bundle bundle = new Bundle();
153
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
154
+        sendCameraIntent(bundle);
155
+    }
156
+
157
+    @Override
158
+    public void onNoCameraFound() {
159
+        this.camera = null;
160
+        Bundle bundle = new Bundle();
161
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
162
+        sendCameraIntent(bundle);
163
+    }
164
+
165
+    @Override
166
+    public void onError(String message) {
167
+        camera = null;
168
+        Bundle bundle = new Bundle();
169
+        bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
170
+        sendCameraIntent(bundle);
171
+    }
172
+
173
+    @Override
174
+    public void onPropertyChanged(int property, int value) {
175
+
176
+    }
177
+
178
+    @Override
179
+    public void onPropertyStateChanged(int property, boolean enabled) {
180
+
181
+    }
182
+
183
+    @Override
184
+    public void onPropertyDescChanged(int property, int[] values) {
185
+
186
+    }
187
+
188
+    @Override
189
+    public void onLiveViewStarted() {
190
+
191
+    }
192
+
193
+    @Override
194
+    public void onLiveViewData(LiveViewData data) {
195
+
196
+    }
197
+
198
+    @Override
199
+    public void onLiveViewStopped() {
200
+
201
+    }
202
+
203
+    @Override
204
+    public void onCapturedPictureReceived(int objectHandle, String filename, Bitmap thumbnail, Bitmap bitmap) {
205
+
206
+        LogHelper.d("czy","CameraService fetchPhotoTask new photo found");
207
+
208
+        Bundle bundle = new Bundle();
209
+        bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND);
210
+        bundle.putString(EXTRA_DATA_PART,filename);
211
+        sendCameraIntent(bundle);
212
+    }
213
+
214
+    @Override
215
+    public void onBulbStarted() {
216
+
217
+    }
218
+
219
+    @Override
220
+    public void onBulbExposureTime(int seconds) {
221
+
222
+    }
223
+
224
+    @Override
225
+    public void onBulbStopped() {
226
+
227
+    }
228
+
229
+    @Override
230
+    public void onFocusStarted() {
231
+
232
+    }
233
+
234
+    @Override
235
+    public void onFocusEnded(boolean hasFocused) {
236
+
237
+    }
238
+
239
+    @Override
240
+    public void onFocusPointsChanged() {
241
+
242
+    }
243
+
244
+    @Override
245
+    public void onObjectAdded(int handle) {
246
+
247
+    }
248
+
249
+    @Override
250
+    public void onLogMessage(String msg) {
251
+
252
+    }
253
+
254
+    @Override
255
+    public void onStorageFound(int handle, String label) {
256
+
257
+    }
258
+
259
+    @Override
260
+    public void onAllStoragesFound() {
261
+
262
+    }
263
+
264
+    @Override
265
+    public void onImageHandlesRetrieved(int[] handles) {
266
+        if(origin.length ==0){
267
+            origin = handles;
268
+        }else{
269
+            if(origin.length == handles.length){
270
+                return;
271
+            }
272
+            ArrayList<Integer> diff = new ArrayList<>();
273
+            for (int i = 0; i < handles.length; i++) {
274
+                boolean isMatch = false;
275
+                for (int j = 0; j < origin.length; j++) {
276
+                    if (origin[j] == handles[i]) {
277
+                        isMatch = true;
278
+                        break;
279
+                    }
220 280
                 }
221
-            }else if(MSG_TYPE_CREATE_FILE_ERROR.equalsIgnoreCase(eventMsg)){
222
-                Bundle bundle = new Bundle();
223
-                bundle.putInt(EXTRA_STATUS_PART, MSG_SDCARD_ERROR);
224
-                sendCameraIntent(bundle);
225
-            }else{
226
-                String sub = eventMsg.substring(0,1);
227
-                if(TextUtils.isDigitsOnly(sub)){
228
-                    LogHelper.d("czy","CameraService fetchPhotoTask new photo found");
229
-                    Bundle bundle = new Bundle();
230
-                    bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND);
231
-                    bundle.putString(EXTRA_DATA_PART,eventMsg);
232
-                    sendCameraIntent(bundle);
281
+                if (!isMatch) {
282
+                    diff.add(handles[i]);
233 283
                 }
234 284
             }
235
-        }else{
236
-            count++;
237
-            if(count>=MAX_NO_PHOTO_COUNT){
238
-                LogHelper.d("czy","CameraService fetchPhotoTask 太久没发现新照片了,重新连接试试");
239
-                Bundle bundle = new Bundle();
240
-                bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
241
-                sendCameraIntent(bundle);
242
-                stopCameraService();
285
+            if(camera != null && diff.size() >0){
286
+                for(int k = 0; k< diff.size();k++){
287
+                    camera.retrievePicture(diff.get(k));
288
+                }
243 289
             }
290
+            origin = handles;
244 291
         }
245
-
246
-        isLastQueryReturned = true;
247 292
     }
248 293
 
249
-    private void sendCameraIntent(Bundle bundle){
250
-        Intent intent = new Intent(ACTION_CAMERA_SERVICE_STATUS_CHANGE);
251
-        intent.putExtras(bundle);
252
-        sendBroadcast(intent);
294
+    @Override
295
+    public void onImageInfoRetrieved(int objectHandle, ObjectInfo objectInfo, Bitmap thumbnail) {
296
+
253 297
     }
254 298
 
299
+
255 300
 }

+ 21 - 0
app/src/main/res/xml/device_filter.xml

@@ -0,0 +1,21 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- Copyright (C) 2011 The Android Open Source Project
3
+
4
+     Licensed under the Apache License, Version 2.0 (the "License");
5
+     you may not use this file except in compliance with the License.
6
+     You may obtain a copy of the License at
7
+
8
+          http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+     Unless required by applicable law or agreed to in writing, software
11
+     distributed under the License is distributed on an "AS IS" BASIS,
12
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+     See the License for the specific language governing permissions and
14
+     limitations under the License.
15
+-->
16
+<resources>
17
+    <!-- vendor and product ID for EOS 600D -->
18
+    <!-- usb-device vendor-id="1193" product-id="12824" -->
19
+    <!-- usb-device protocol="0" / -->
20
+    <usb-device class="6" subclass="1" protocol="1" />
21
+</resources>

+ 1 - 1
ryc/src/main/java/com/remoteyourcam/usb/ptp/PtpUsbService.java

@@ -101,7 +101,7 @@ public class PtpUsbService implements PtpService {
101 101
             }
102 102
             camera.shutdownHard();
103 103
         }
104
-        UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
104
+        UsbDevice device = intent == null ? null :(UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
105 105
         if (device != null) {
106 106
             if (AppConfig.LOG) {
107 107
                 Log.i(TAG, "initialize: got device through intent");

pai2 - Gogs: Go Git Service

拍爱

Brightcells: f979433ffb Photo GEO 7 gadi atpakaļ
..
0001_initial.py e184e7dd5b add api group_create/group_join 10 gadi atpakaļ
0002_groupinfo_session_id.py e184e7dd5b add api group_create/group_join 10 gadi atpakaļ
0003_groupinfo_admin_id.py 7e305483ab add api group_detail/group_lock/group_pass/group_refuse 10 gadi atpakaļ
0004_auto_20151216_2337.py 7467a3e68a add api group_update/group_remove 10 gadi atpakaļ
0005_groupuserinfo_current_id.py f587f0a48f user can just see photo after he joined the group & zh_Hans replace zh_CN in settings.py 10 gadi atpakaļ
0006_groupuserinfo_avatar.py 4afdb94e20 add avatar for GroupUserInfo 10 gadi atpakaļ
0007_auto_20160112_2040.py df1df69fe3 add api upgrade/splash 10 gadi atpakaļ
0008_photocommentinfo.py c72d89f6e5 add api comment_submit_api/comment_list_api/thumbup_submit_api/thumbup_list_api/thumbup_cancel_api 10 gadi atpakaļ
0009_photothumbupinfo.py c72d89f6e5 add api comment_submit_api/comment_list_api/thumbup_submit_api/thumbup_list_api/thumbup_cancel_api 10 gadi atpakaļ
0010_auto_20160120_1830.py a121b75ff2 add db_index=True for status field 10 gadi atpakaļ
0011_auto_20160302_2048.py da2a81fff1 add api pai2_home 10 gadi atpakaļ
0012_groupinfo_group_avatar.py da2a81fff1 add api pai2_home 10 gadi atpakaļ
0013_groupinfo_group_default_avatar.py f6a88c632b add group_default_avatar field for GroupInfo 10 gadi atpakaļ
0014_auto_20160308_2347.py ca727b0362 store/return w/h for photo 10 gadi atpakaļ
0015_groupphotoinfo_avatar.py 88049b12db store/return more field for photo 10 gadi atpakaļ
0016_auto_20160321_1535.py 537bd9bd41 add api group_quit_api 10 gadi atpakaļ
0017_groupphotoinfo_photo_from.py dbea356558 add photo_from field for GroupPhotoInfo and return photo_from for some api 10 gadi atpakaļ
0018_auto_20160417_2246.py d64b3c216b add and return photo_thumbnail2 relative 10 gadi atpakaļ
0019_auto_20160422_1322.py 102152ca4a add api lensman_photo_bought & modify api wx_order_create_api and adjust return field 10 gadi atpakaļ
0020_groupphotoinfo_session_id.py 102152ca4a add api lensman_photo_bought & modify api wx_order_create_api and adjust return field 10 gadi atpakaļ
0021_photocommentinfo_to_uid.py fa36c26ce4 extend param to_uid for comment_submit_api 10 gadi atpakaļ
0022_auto_20160901_1439.py 6199c8f7ad add api lensman_origin_wanted_api/lensman_origin_photo_upload_api 9 gadi atpakaļ
0023_groupinfo_group_initio.py e06dc10006 Make join session group by scan group qrcode fetch group photos initio 9 gadi atpakaļ
0024_auto_20161214_1329.py f724e0f9c0 Add tour guide apis 9 gadi atpakaļ
0025_auto_20161214_1659.py ad69866b26 Add tour guide's name and phone in GroupInfo 9 gadi atpakaļ
0026_auto_20161216_1301.py 034acddb68 Add total_persons for GroupInfo 9 gadi atpakaļ
0027_groupuserinfo_authority.py 88f0697a89 Add authority field for GroupUserInfo 9 gadi atpakaļ
0028_auto_20161220_1815.py 272f181c50 Makemigrations 9 gadi atpakaļ
0029_auto_20161224_1616.py 564ff620d7 Add unique_together = (('group_id', 'user_id'),) for GroupUserInfo 9 gadi atpakaļ
0030_groupinfo_gather_location.py 90d377ee6e Add gather location 9 gadi atpakaļ
0031_groupphotoinfo_photo_md5.py d824fbd441 Add photo_md5 for GroupPhotoInfo 9 gadi atpakaļ
0032_groupinfo_gather_screenshot.py e8cd9652b7 Add gather_screenshot for api tg_group_gather_start_api 9 gadi atpakaļ
0033_groupphotoinfo_photo_id.py 3c6e34823b Add photo_id for GroupPhotoInfo replaced pk 9 gadi atpakaļ
0034_auto_20170411_1156.py 14d5d63e3b Add nomark/origin price for GroupPhotoInfo 9 gadi atpakaļ
0035_groupuserinfo_admin_status.py 9e4ac4fd3b Add admin_status for GroupUserInfo 9 gadi atpakaļ
0036_groupphotoinfo_has_watermark.py 3b92e37156 Add field has_watermark for GroupPhotoInfo 8 gadi atpakaļ
0037_auto_20170821_1600.py bf678fc740 Add unique_together = (('session_id', 'group_from'),) 8 gadi atpakaļ
0038_auto_20170821_1608.py 7060597dd6 Add unique_together = (('group_id', 'user_id', 'photo_md5'),) for GroupPhotoInfo 8 gadi atpakaļ
0039_auto_20170821_1613.py 9f4c919c29 Add unique_together = (('photo_id', 'user_id'),) for PhotoThumbUpInfo 8 gadi atpakaļ
0040_auto_20170825_1342.py e5ad69259f Add unique_together = (('group_id', 'session_id', 'user_id', 'photo_id', 'lensman_photo_id'),) for GroupPhotoOrderInfo 8 gadi atpakaļ
0041_auto_20170825_1342.py e5ad69259f Add unique_together = (('group_id', 'session_id', 'user_id', 'photo_id', 'lensman_photo_id'),) for GroupPhotoOrderInfo 8 gadi atpakaļ
0042_groupphotoinfo_lensman_type.py a6195fa70d Add outtake lensman 8 gadi atpakaļ
0043_auto_20180101_2220.py 9bb56c50cc Makemigrations 8 gadi atpakaļ
0044_auto_20180103_0446.py a7cbbf15a7 Update max_length for CharField 8 gadi atpakaļ
0045_auto_20180723_1641.py f979433ffb Photo GEO 7 gadi atpakaļ
__init__.py e184e7dd5b add api group_create/group_join 10 gadi atpakaļ