• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (c) 2012, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #include <pthread.h>
31 #include "mm_camera_dbg.h"
32 #include <errno.h>
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <poll.h>
38 #include <linux/ion.h>
39 #include "mm_qcamera_app.h"
40 
41 /*typedef enum {
42   STREAM_IMAGE,
43   STREAM_RAW,
44   STREAM_IMAGE_AND_RAW,
45   STREAM_RAW_AND_RAW,
46   STREAM_MAX,
47 } mm_camera_channel_stream_info_t;*/
48 
49 #define RDI_MASK STREAM_RAW
50 mm_camera_channel_stream_info_t rdi_mode;
51 
mm_app_set_rdi_fmt(int cam_id,mm_camera_image_fmt_t * fmt)52 static int mm_app_set_rdi_fmt(int cam_id,mm_camera_image_fmt_t *fmt)
53 {
54     int rc = MM_CAMERA_OK;
55     cam_ctrl_dimension_t dim;
56     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
57 
58     fmt->meta_header = MM_CAMEAR_META_DATA_TYPE_DEF;
59     //pme->cam->ops->get_parm(pme->cam->camera_handle,MM_CAMERA_PARM_DIMENSION, &dim);
60     fmt->fmt = CAMERA_BAYER_SBGGR10;//CAMERA_RDI;
61     fmt->width = 0;
62     fmt->height = 0;
63     fmt->rotation = 0;
64 
65     CDBG("%s: RDI Dimensions = %d X %d",__func__,fmt->width,fmt->height);
66     return rc;
67 }
68 
mm_app_open_rdi(int cam_id)69 int mm_app_open_rdi(int cam_id)
70 {
71     int rc = MM_CAMERA_OK;
72     int value = RDI_MASK;
73     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
74 
75     if (pme->cam_mode == RDI_MODE) {
76         return rc;
77     }
78 
79     if (MM_CAMERA_OK != (rc = stopPreview(cam_id))) {
80         CDBG_ERROR("%s:Stop preview err=%d\n", __func__, rc);
81         goto end;
82     }
83     pme->cam_mode = RDI_MODE;
84     end:
85     CDBG("%s: END, rc=%d\n", __func__, rc);
86     return rc;
87 }
88 
rdi_cb_signal(mm_camera_app_obj_t * pme)89 void rdi_cb_signal(mm_camera_app_obj_t *pme)
90 {
91     if (pme->cam_mode == RDI_MODE) {
92         mm_camera_app_done();
93     }
94 }
95 
mm_app_rdi_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)96 static void mm_app_rdi_notify_cb(mm_camera_super_buf_t *bufs,
97                                  void *user_data)
98 {
99     int rc;
100     mm_camera_buf_def_t *frame = NULL;
101     mm_camera_app_obj_t *pme = NULL;
102     CDBG("%s: BEGIN\n", __func__);
103     frame = bufs->bufs[0] ;
104     pme = (mm_camera_app_obj_t *)user_data;
105 
106     CDBG("%s: BEGIN - length=%d, frame idx = %d\n", __func__, frame->frame_len, frame->frame_idx);
107 
108     //dumpFrameToFile(frame->frame,pme->dim.display_width,pme->dim.display_height,"preview", 1);
109     dumpFrameToFile(frame,pme->dim.rdi0_width,pme->dim.rdi0_height,"rdi", 1);
110 
111     if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,frame)) {
112         CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
113         return;
114     }
115     if (my_cam_app.run_sanity) {
116         mm_camera_app_done(pme);
117     }
118     CDBG("%s: END\n", __func__);
119 
120 }
121 
mm_app_prepare_rdi(int cam_id)122 int mm_app_prepare_rdi(int cam_id)
123 {
124     int rc = MM_CAMERA_OK;
125     int op_mode;
126     int value = RDI_MASK;
127 
128     CDBG("%s: E",__func__);
129     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
130 
131     pme->mem_cam->get_buf = mm_stream_initbuf;
132     pme->mem_cam->put_buf = mm_stream_deinitbuf;
133     pme->mem_cam->user_data = pme;
134 
135     //pme->cam->ops->set_parm(pme->cam->camera_handle,MM_CAMERA_PARM_CH_INTERFACE, &value);
136     //pme->cam->ops->get_parm(pme->cam->camera_handle,MM_CAMERA_PARM_CH_INTERFACE, &rdi_mode);
137 
138     pme->stream[MM_CAMERA_RDI].id = pme->cam->ops->add_stream(pme->cam->camera_handle,pme->ch_id,
139                                                               mm_app_rdi_notify_cb,pme,
140                                                               MM_CAMERA_RDI, 0);
141 
142     if (!pme->stream[MM_CAMERA_RDI].id) {
143         CDBG_ERROR("%s:Add RDI error =%d\n", __func__, rc);
144         rc = -1;
145         goto end;
146     }
147     CDBG("%s :Add RDI stream is successfull stream ID = %d",__func__,pme->stream[MM_CAMERA_RDI].id);
148 
149     mm_app_set_rdi_fmt(cam_id,&pme->stream[MM_CAMERA_RDI].str_config.fmt);
150     pme->stream[MM_CAMERA_RDI].str_config.need_stream_on = 1;
151     pme->stream[MM_CAMERA_RDI].str_config.num_of_bufs = 7;
152 
153     if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_RDI].id,
154                                                            &pme->stream[MM_CAMERA_RDI].str_config))) {
155         CDBG_ERROR("%s:RDI streaming err=%d\n", __func__, rc);
156         goto end;
157     }
158 #if 0
159     if (rdi_mode == STREAM_IMAGE_AND_RAW) {
160         pme->stream[MM_CAMERA_PREVIEW].id = pme->cam->ops->add_stream(pme->cam->camera_handle,pme->ch_id,
161                                                                       mm_app_preview_notify_cb,pme,
162                                                                       MM_CAMERA_PREVIEW, 0);
163 
164         if (!pme->stream[MM_CAMERA_PREVIEW].id) {
165             CDBG_ERROR("%s:Add stream preview error =%d\n", __func__, rc);
166             rc = -1;
167             goto end;
168         }
169 
170         CDBG("%s :Add stream is successfull stream ID = %d",__func__,pme->stream[MM_CAMERA_PREVIEW].id);
171 
172         mm_app_set_preview_fmt(cam_id,&pme->stream[MM_CAMERA_PREVIEW].str_config.fmt);
173         pme->stream[MM_CAMERA_PREVIEW].str_config.need_stream_on = 1;
174         pme->stream[MM_CAMERA_PREVIEW].str_config.num_of_bufs = PREVIEW_BUF_NUM;
175 
176         if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id,
177                                                                &pme->stream[MM_CAMERA_PREVIEW].str_config))) {
178             CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
179             goto end;
180         }
181     }
182 #endif
183     end:
184     return rc;
185 }
186 
mm_app_unprepare_rdi(int cam_id)187 int mm_app_unprepare_rdi(int cam_id)
188 {
189     int rc = MM_CAMERA_OK;
190     return rc;
191 }
192 
mm_app_streamon_rdi(int cam_id)193 int mm_app_streamon_rdi(int cam_id)
194 {
195     int rc = MM_CAMERA_OK;
196     int stream[2];
197     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
198     int num_of_streams;
199 
200     /*if(rdi_mode == STREAM_IMAGE_AND_RAW){
201         num_of_streams = 2;
202         stream[0] = pme->stream[MM_CAMERA_RDI].id;
203         stream[1] = pme->stream[MM_CAMERA_PREVIEW].id;
204     }else */{
205         num_of_streams = 1;
206         stream[0] = pme->stream[MM_CAMERA_RDI].id;
207     }
208 
209     if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,num_of_streams,&stream))) {
210         CDBG_ERROR("%s : Start RDI Stream preview Error",__func__);
211         goto end;
212     }
213     pme->cam_state = CAMERA_STATE_RDI;
214     end:
215     CDBG("%s: X rc = %d",__func__,rc);
216     return rc;
217 }
218 
mm_app_start_rdi(int cam_id)219 int mm_app_start_rdi(int cam_id)
220 {
221     int rc = MM_CAMERA_OK;
222 
223     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
224     int op_mode = 0;
225 
226     CDBG("pme = %p, pme->cam =%p, pme->cam->camera_handle = %d",
227          pme,pme->cam,pme->cam->camera_handle);
228 
229     if (pme->cam_state == CAMERA_STATE_RDI) {
230         return rc;
231     }
232 
233     if (MM_CAMERA_OK != (rc = mm_app_prepare_rdi(cam_id))) {
234         CDBG_ERROR("%s:Prepare RDI failed rc=%d\n", __func__, rc);
235         goto end;
236     }
237 
238     if (MM_CAMERA_OK != (rc = mm_app_streamon_rdi(cam_id))) {
239         CDBG_ERROR("%s:Stream On RDI failed rc=%d\n", __func__, rc);
240         goto end;
241     }
242 
243     end:
244     CDBG("%s: END, rc=%d\n", __func__, rc);
245     return rc;
246 }
247 
mm_app_streamoff_rdi(int cam_id)248 static int mm_app_streamoff_rdi(int cam_id)
249 {
250     int rc = MM_CAMERA_OK;
251     int stream[2];
252     int num_of_streams;
253 
254     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
255 
256     /*if(rdi_mode == STREAM_IMAGE_AND_RAW){
257         num_of_streams = 2;
258         stream[0] = pme->stream[MM_CAMERA_RDI].id;
259         stream[1] = pme->stream[MM_CAMERA_PREVIEW].id;
260     }else*/{
261         num_of_streams = 1;
262         stream[0] = pme->stream[MM_CAMERA_RDI].id;
263     }
264 
265     if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,num_of_streams,&stream))) {
266         CDBG_ERROR("%s : RDI Stream off Error",__func__);
267         goto end;
268     }
269 
270     /*if(rdi_mode == STREAM_IMAGE_AND_RAW) {
271         if(MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id)))
272         {
273             CDBG_ERROR("%s : Delete Preview error",__func__);
274             goto end;
275         }
276     }*/
277     if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_RDI].id))) {
278         CDBG_ERROR("%s : Delete Stream RDI error",__func__);
279         goto end;
280     }
281     CDBG("del_stream successfull");
282     pme->cam_state = CAMERA_STATE_OPEN;
283     end:
284     CDBG("%s: END, rc=%d\n", __func__, rc);
285 
286     return rc;
287 }
288 
startRdi(int cam_id)289 int startRdi(int cam_id)
290 {
291     int rc = MM_CAMERA_OK;
292 
293     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
294 
295     CDBG("%s: Start Preview",__func__);
296 
297     if (pme->cam_mode == ZSL_MODE || pme->cam_mode == RECORDER_MODE || pme->cam_mode == CAMERA_MODE) {
298         switch (pme->cam_state) {
299         case CAMERA_STATE_RECORD:
300             if (MM_CAMERA_OK != mm_app_stop_video(cam_id)) {
301                 CDBG_ERROR("%s:Cannot stop video err=%d\n", __func__, rc);
302                 return -1;
303             }
304         case CAMERA_STATE_PREVIEW:
305             if (MM_CAMERA_OK != mm_app_open_rdi(cam_id)) {
306                 CDBG_ERROR("%s: Cannot switch to camera mode=%d\n", __func__);
307                 return -1;
308             }
309         case CAMERA_STATE_SNAPSHOT:
310         default:
311             break;
312         }
313     }
314     mm_app_start_rdi(cam_id);
315     return rc;
316 }
317 
stopRdi(int cam_id)318 int stopRdi(int cam_id)
319 {
320     int rc = MM_CAMERA_OK;
321     mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
322 
323     mm_app_streamoff_rdi(cam_id);
324 
325     end:
326     return rc;
327 }
328 
329 
330