1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 // System dependencies
31 #include <pthread.h>
32 #include <string.h>
33 #include <math.h>
34 
35 // JPEG dependencies
36 #include "mm_jpeg_dbg.h"
37 #include "mm_jpeg.h"
38 
39 
40 #define LOWER(a)               ((a) & 0xFFFF)
41 #define UPPER(a)               (((a)>>16) & 0xFFFF)
42 #define CHANGE_ENDIAN_16(a)  ((0x00FF & ((a)>>8)) | (0xFF00 & ((a)<<8)))
43 #define ROUND(a) \
44         ((a >= 0) ? (uint32_t)(a + 0.5) : (uint32_t)(a - 0.5))
45 
46 
47 /** addExifEntry:
48  *
49  *  Arguments:
50  *   @exif_info : Exif info struct
51  *   @p_session: job session
52  *   @tagid   : exif tag ID
53  *   @type    : data type
54  *   @count   : number of data in uint of its type
55  *   @data    : input data ptr
56  *
57  *  Retrun     : int32_t type of status
58  *               0  -- success
59  *              none-zero failure code
60  *
61  *  Description:
62  *       Function to add an entry to exif data
63  *
64  **/
addExifEntry(QOMX_EXIF_INFO * p_exif_info,exif_tag_id_t tagid,exif_tag_type_t type,uint32_t count,void * data)65 int32_t addExifEntry(QOMX_EXIF_INFO *p_exif_info, exif_tag_id_t tagid,
66   exif_tag_type_t type, uint32_t count, void *data)
67 {
68     int32_t rc = 0;
69     uint32_t numOfEntries = (uint32_t)p_exif_info->numOfEntries;
70     QEXIF_INFO_DATA *p_info_data = p_exif_info->exif_data;
71     if(numOfEntries >= MAX_EXIF_TABLE_ENTRIES) {
72         LOGE("Number of entries exceeded limit");
73         return -1;
74     }
75 
76     p_info_data[numOfEntries].tag_id = tagid;
77     p_info_data[numOfEntries].tag_entry.type = type;
78     p_info_data[numOfEntries].tag_entry.count = count;
79     p_info_data[numOfEntries].tag_entry.copy = 1;
80     switch (type) {
81     case EXIF_BYTE: {
82       if (count > 1) {
83         uint8_t *values = (uint8_t *)malloc(count);
84         if (values == NULL) {
85           LOGE("No memory for byte array");
86           rc = -1;
87         } else {
88           memcpy(values, data, count);
89           p_info_data[numOfEntries].tag_entry.data._bytes = values;
90         }
91       } else {
92         p_info_data[numOfEntries].tag_entry.data._byte = *(uint8_t *)data;
93       }
94     }
95     break;
96     case EXIF_ASCII: {
97       char *str = NULL;
98       str = (char *)malloc(count + 1);
99       if (str == NULL) {
100         LOGE("No memory for ascii string");
101         rc = -1;
102       } else {
103         memset(str, 0, count + 1);
104         memcpy(str, data, count);
105         p_info_data[numOfEntries].tag_entry.data._ascii = str;
106       }
107     }
108     break;
109     case EXIF_SHORT: {
110       if (count > 1) {
111         uint16_t *values = (uint16_t *)malloc(count * sizeof(uint16_t));
112         if (values == NULL) {
113           LOGE("No memory for short array");
114           rc = -1;
115         } else {
116           memcpy(values, data, count * sizeof(uint16_t));
117           p_info_data[numOfEntries].tag_entry.data._shorts = values;
118         }
119       } else {
120         p_info_data[numOfEntries].tag_entry.data._short = *(uint16_t *)data;
121       }
122     }
123     break;
124     case EXIF_LONG: {
125       if (count > 1) {
126         uint32_t *values = (uint32_t *)malloc(count * sizeof(uint32_t));
127         if (values == NULL) {
128           LOGE("No memory for long array");
129           rc = -1;
130         } else {
131           memcpy(values, data, count * sizeof(uint32_t));
132           p_info_data[numOfEntries].tag_entry.data._longs = values;
133         }
134       } else {
135         p_info_data[numOfEntries].tag_entry.data._long = *(uint32_t *)data;
136       }
137     }
138     break;
139     case EXIF_RATIONAL: {
140       if (count > 1) {
141         rat_t *values = (rat_t *)malloc(count * sizeof(rat_t));
142         if (values == NULL) {
143           LOGE("No memory for rational array");
144           rc = -1;
145         } else {
146           memcpy(values, data, count * sizeof(rat_t));
147           p_info_data[numOfEntries].tag_entry.data._rats = values;
148         }
149       } else {
150         p_info_data[numOfEntries].tag_entry.data._rat = *(rat_t *)data;
151       }
152     }
153     break;
154     case EXIF_UNDEFINED: {
155       uint8_t *values = (uint8_t *)malloc(count);
156       if (values == NULL) {
157         LOGE("No memory for undefined array");
158         rc = -1;
159       } else {
160         memcpy(values, data, count);
161         p_info_data[numOfEntries].tag_entry.data._undefined = values;
162       }
163     }
164     break;
165     case EXIF_SLONG: {
166       if (count > 1) {
167         int32_t *values = (int32_t *)malloc(count * sizeof(int32_t));
168         if (values == NULL) {
169           LOGE("No memory for signed long array");
170           rc = -1;
171         } else {
172           memcpy(values, data, count * sizeof(int32_t));
173           p_info_data[numOfEntries].tag_entry.data._slongs = values;
174         }
175       } else {
176         p_info_data[numOfEntries].tag_entry.data._slong = *(int32_t *)data;
177       }
178     }
179     break;
180     case EXIF_SRATIONAL: {
181       if (count > 1) {
182         srat_t *values = (srat_t *)malloc(count * sizeof(srat_t));
183         if (values == NULL) {
184           LOGE("No memory for signed rational array");
185           rc = -1;
186         } else {
187           memcpy(values, data, count * sizeof(srat_t));
188           p_info_data[numOfEntries].tag_entry.data._srats = values;
189         }
190       } else {
191         p_info_data[numOfEntries].tag_entry.data._srat = *(srat_t *)data;
192       }
193     }
194     break;
195     }
196 
197     // Increase number of entries
198     p_exif_info->numOfEntries++;
199     return rc;
200 }
201 
202 /** releaseExifEntry
203  *
204  *  Arguments:
205  *   @p_exif_data : Exif info struct
206  *
207  *  Retrun     : int32_t type of status
208  *               0  -- success
209  *              none-zero failure code
210  *
211  *  Description:
212  *       Function to release an entry from exif data
213  *
214  **/
releaseExifEntry(QEXIF_INFO_DATA * p_exif_data)215 int32_t releaseExifEntry(QEXIF_INFO_DATA *p_exif_data)
216 {
217  switch (p_exif_data->tag_entry.type) {
218   case EXIF_BYTE: {
219     if (p_exif_data->tag_entry.count > 1 &&
220       p_exif_data->tag_entry.data._bytes != NULL) {
221       free(p_exif_data->tag_entry.data._bytes);
222       p_exif_data->tag_entry.data._bytes = NULL;
223     }
224   }
225   break;
226   case EXIF_ASCII: {
227     if (p_exif_data->tag_entry.data._ascii != NULL) {
228       free(p_exif_data->tag_entry.data._ascii);
229       p_exif_data->tag_entry.data._ascii = NULL;
230     }
231   }
232   break;
233   case EXIF_SHORT: {
234     if (p_exif_data->tag_entry.count > 1 &&
235       p_exif_data->tag_entry.data._shorts != NULL) {
236       free(p_exif_data->tag_entry.data._shorts);
237       p_exif_data->tag_entry.data._shorts = NULL;
238     }
239   }
240   break;
241   case EXIF_LONG: {
242     if (p_exif_data->tag_entry.count > 1 &&
243       p_exif_data->tag_entry.data._longs != NULL) {
244       free(p_exif_data->tag_entry.data._longs);
245       p_exif_data->tag_entry.data._longs = NULL;
246     }
247   }
248   break;
249   case EXIF_RATIONAL: {
250     if (p_exif_data->tag_entry.count > 1 &&
251       p_exif_data->tag_entry.data._rats != NULL) {
252       free(p_exif_data->tag_entry.data._rats);
253       p_exif_data->tag_entry.data._rats = NULL;
254     }
255   }
256   break;
257   case EXIF_UNDEFINED: {
258     if (p_exif_data->tag_entry.data._undefined != NULL) {
259       free(p_exif_data->tag_entry.data._undefined);
260       p_exif_data->tag_entry.data._undefined = NULL;
261     }
262   }
263   break;
264   case EXIF_SLONG: {
265     if (p_exif_data->tag_entry.count > 1 &&
266       p_exif_data->tag_entry.data._slongs != NULL) {
267       free(p_exif_data->tag_entry.data._slongs);
268       p_exif_data->tag_entry.data._slongs = NULL;
269     }
270   }
271   break;
272   case EXIF_SRATIONAL: {
273     if (p_exif_data->tag_entry.count > 1 &&
274       p_exif_data->tag_entry.data._srats != NULL) {
275       free(p_exif_data->tag_entry.data._srats);
276       p_exif_data->tag_entry.data._srats = NULL;
277     }
278   }
279   break;
280   } /*end of switch*/
281 
282   return 0;
283 }
284 
285 /** process_sensor_data:
286  *
287  *  Arguments:
288  *   @p_sensor_params : ptr to sensor data
289  *
290  *  Return     : int32_t type of status
291  *               NO_ERROR  -- success
292  *              none-zero failure code
293  *
294  *  Description:
295  *       process sensor data
296  *
297  *  Notes: this needs to be filled for the metadata
298  **/
process_sensor_data(cam_sensor_params_t * p_sensor_params,QOMX_EXIF_INFO * exif_info)299 int process_sensor_data(cam_sensor_params_t *p_sensor_params,
300   QOMX_EXIF_INFO *exif_info)
301 {
302   int rc = 0;
303   rat_t val_rat;
304 
305   if (NULL == p_sensor_params) {
306     LOGE("Sensor params are null");
307     return 0;
308   }
309 
310   LOGD("From metadata aperture = %f ",
311     p_sensor_params->aperture_value );
312 
313   if (p_sensor_params->aperture_value >= 1.0) {
314     double apex_value;
315     apex_value = (double)2.0 * log(p_sensor_params->aperture_value) / log(2.0);
316     val_rat.num = (uint32_t)(apex_value * 100);
317     val_rat.denom = 100;
318     rc = addExifEntry(exif_info, EXIFTAGID_APERTURE, EXIF_RATIONAL, 1, &val_rat);
319     if (rc) {
320       LOGE(": Error adding Exif Entry");
321     }
322 
323     val_rat.num = (uint32_t)(p_sensor_params->aperture_value * 100);
324     val_rat.denom = 100;
325     rc = addExifEntry(exif_info, EXIFTAGID_F_NUMBER, EXIF_RATIONAL, 1, &val_rat);
326     if (rc) {
327       LOGE(": Error adding Exif Entry");
328     }
329   }
330 
331   /*Flash*/
332   short val_short = 0;
333   int flash_mode_exif, flash_fired;
334   if (p_sensor_params->flash_state == CAM_FLASH_STATE_FIRED) {
335     flash_fired = 1;
336   } else {
337     flash_fired = 0;
338   }
339   LOGD("Flash mode %d flash state %d",
340     p_sensor_params->flash_mode, p_sensor_params->flash_state);
341 
342   switch(p_sensor_params->flash_mode) {
343   case  CAM_FLASH_MODE_OFF:
344     flash_mode_exif = MM_JPEG_EXIF_FLASH_MODE_OFF;
345     break;
346   case CAM_FLASH_MODE_ON:
347     flash_mode_exif = MM_JPEG_EXIF_FLASH_MODE_ON;
348     break;
349   case CAM_FLASH_MODE_AUTO:
350     flash_mode_exif = MM_JPEG_EXIF_FLASH_MODE_AUTO;
351     break;
352   default:
353     flash_mode_exif = MM_JPEG_EXIF_FLASH_MODE_AUTO;
354     LOGE(": Unsupported flash mode");
355   }
356   val_short = (short)(flash_fired | (flash_mode_exif << 3));
357 
358   rc = addExifEntry(exif_info, EXIFTAGID_FLASH, EXIF_SHORT, 1, &val_short);
359   if (rc) {
360     LOGE(": Error adding flash exif entry");
361   }
362   /* Sensing Method */
363   val_short = (short) p_sensor_params->sensing_method;
364   rc = addExifEntry(exif_info, EXIFTAGID_SENSING_METHOD, EXIF_SHORT,
365     sizeof(val_short)/2, &val_short);
366   if (rc) {
367     LOGE(": Error adding flash Exif Entry");
368   }
369 
370   /* Focal Length in 35 MM Film */
371   val_short = (short)
372     ((p_sensor_params->focal_length * p_sensor_params->crop_factor) + 0.5f);
373   rc = addExifEntry(exif_info, EXIFTAGID_FOCAL_LENGTH_35MM, EXIF_SHORT,
374     1, &val_short);
375   if (rc) {
376     LOGE(": Error adding Exif Entry");
377   }
378 
379   /* F Number */
380   val_rat.num = (uint32_t)(p_sensor_params->f_number * 100);
381   val_rat.denom = 100;
382   rc = addExifEntry(exif_info, EXIFTAGTYPE_F_NUMBER, EXIF_RATIONAL, 1, &val_rat);
383   if (rc) {
384     LOGE(": Error adding Exif Entry");
385   }
386   return rc;
387 }
388 
389 
390 /** process_3a_data:
391  *
392  *  Arguments:
393  *   @p_3a_params : ptr to 3a data
394  *   @exif_info : Exif info struct
395  *
396  *  Return     : int32_t type of status
397  *               NO_ERROR  -- success
398  *               none-zero failure code
399  *
400  *  Description:
401  *       process 3a data
402  *
403  *  Notes: this needs to be filled for the metadata
404  **/
process_3a_data(cam_3a_params_t * p_3a_params,QOMX_EXIF_INFO * exif_info)405 int process_3a_data(cam_3a_params_t *p_3a_params, QOMX_EXIF_INFO *exif_info)
406 {
407   int rc = 0;
408   srat_t val_srat;
409   rat_t val_rat;
410   double shutter_speed_value;
411 
412   if (NULL == p_3a_params) {
413     LOGE("3A params are null");
414     return 0;
415   }
416 
417   LOGD("exp_time %f, iso_value %d, wb_mode %d",
418     p_3a_params->exp_time, p_3a_params->iso_value, p_3a_params->wb_mode);
419 
420   /* Exposure time */
421   if (p_3a_params->exp_time <= 0.0f) {
422     val_rat.num = 0;
423     val_rat.denom = 0;
424   } else if (p_3a_params->exp_time < 1.0f) {
425     val_rat.num = 1;
426     val_rat.denom = ROUND(1.0/p_3a_params->exp_time);
427   } else {
428     val_rat.num = ROUND(p_3a_params->exp_time);
429     val_rat.denom = 1;
430   }
431   LOGD("numer %d denom %d %zd", val_rat.num, val_rat.denom,
432     sizeof(val_rat) / (8));
433 
434   rc = addExifEntry(exif_info, EXIFTAGID_EXPOSURE_TIME, EXIF_RATIONAL,
435     (sizeof(val_rat)/(8)), &val_rat);
436   if (rc) {
437     LOGE(": Error adding Exif Entry Exposure time");
438   }
439 
440   /* Shutter Speed*/
441   if (p_3a_params->exp_time > 0) {
442     shutter_speed_value = log10(1/p_3a_params->exp_time)/log10(2);
443     val_srat.num = (int32_t)(shutter_speed_value * 1000);
444     val_srat.denom = 1000;
445   } else {
446     val_srat.num = 0;
447     val_srat.denom = 0;
448   }
449   rc = addExifEntry(exif_info, EXIFTAGID_SHUTTER_SPEED, EXIF_SRATIONAL,
450     (sizeof(val_srat)/(8)), &val_srat);
451   if (rc) {
452     LOGE(": Error adding Exif Entry");
453   }
454 
455   /*ISO*/
456   short val_short;
457   val_short = (short)p_3a_params->iso_value;
458   rc = addExifEntry(exif_info, EXIFTAGID_ISO_SPEED_RATING, EXIF_SHORT,
459     sizeof(val_short)/2, &val_short);
460   if (rc) {
461      LOGE(": Error adding Exif Entry");
462   }
463 
464   /*WB mode*/
465   if (p_3a_params->wb_mode == CAM_WB_MODE_AUTO)
466     val_short = 0;
467   else
468     val_short = 1;
469   rc = addExifEntry(exif_info, EXIFTAGID_WHITE_BALANCE, EXIF_SHORT,
470     sizeof(val_short)/2, &val_short);
471   if (rc) {
472     LOGE(": Error adding Exif Entry");
473   }
474 
475   /* Metering Mode   */
476   val_short = (short) p_3a_params->metering_mode;
477   rc = addExifEntry(exif_info,EXIFTAGID_METERING_MODE, EXIF_SHORT,
478      sizeof(val_short)/2, &val_short);
479   if (rc) {
480      LOGE(": Error adding Exif Entry");
481    }
482 
483   /*Exposure Program*/
484    val_short = (short) p_3a_params->exposure_program;
485    rc = addExifEntry(exif_info,EXIFTAGID_EXPOSURE_PROGRAM, EXIF_SHORT,
486       sizeof(val_short)/2, &val_short);
487    if (rc) {
488       LOGE(": Error adding Exif Entry");
489     }
490 
491    /*Exposure Mode */
492     val_short = (short) p_3a_params->exposure_mode;
493     rc = addExifEntry(exif_info,EXIFTAGID_EXPOSURE_MODE, EXIF_SHORT,
494        sizeof(val_short)/2, &val_short);
495     if (rc) {
496        LOGE(": Error adding Exif Entry");
497      }
498 
499     /*Scenetype*/
500      uint8_t val_undef;
501      val_undef = (uint8_t) p_3a_params->scenetype;
502      rc = addExifEntry(exif_info,EXIFTAGID_SCENE_TYPE, EXIF_UNDEFINED,
503         sizeof(val_undef), &val_undef);
504      if (rc) {
505         LOGE(": Error adding Exif Entry");
506       }
507 
508      LOGD("brightness %f",
509        p_3a_params->brightness);
510 
511     /* Brightness Value*/
512      val_srat.num = (int32_t) (p_3a_params->brightness * 100.0f);
513      val_srat.denom = 100;
514      rc = addExifEntry(exif_info,EXIFTAGID_BRIGHTNESS, EXIF_SRATIONAL,
515                  (sizeof(val_srat)/(8)), &val_srat);
516      if (rc) {
517         LOGE(": Error adding Exif Entry");
518      }
519 
520   return rc;
521 }
522 
523 /** process_meta_data
524  *
525  *  Arguments:
526  *   @p_meta : ptr to metadata
527  *   @exif_info: Exif info struct
528  *   @mm_jpeg_exif_params: exif params
529  *
530  *  Return     : int32_t type of status
531  *               NO_ERROR  -- success
532  *              none-zero failure code
533  *
534  *  Description:
535  *       Extract exif data from the metadata
536  **/
process_meta_data(metadata_buffer_t * p_meta,QOMX_EXIF_INFO * exif_info,mm_jpeg_exif_params_t * p_cam_exif_params,cam_hal_version_t hal_version)537 int process_meta_data(metadata_buffer_t *p_meta, QOMX_EXIF_INFO *exif_info,
538   mm_jpeg_exif_params_t *p_cam_exif_params, cam_hal_version_t hal_version)
539 {
540   int rc = 0;
541   cam_sensor_params_t p_sensor_params;
542   cam_3a_params_t p_3a_params;
543   bool is_3a_meta_valid = false, is_sensor_meta_valid = false;
544 
545   memset(&p_3a_params,  0,  sizeof(cam_3a_params_t));
546   memset(&p_sensor_params, 0, sizeof(cam_sensor_params_t));
547 
548   if (p_meta) {
549     /* for HAL V1*/
550     if (hal_version == CAM_HAL_V1) {
551 
552       IF_META_AVAILABLE(cam_3a_params_t, l_3a_params, CAM_INTF_META_AEC_INFO,
553           p_meta) {
554         p_3a_params = *l_3a_params;
555         is_3a_meta_valid = true;
556       }
557 
558       IF_META_AVAILABLE(int32_t, wb_mode, CAM_INTF_PARM_WHITE_BALANCE, p_meta) {
559         p_3a_params.wb_mode = *wb_mode;
560       }
561 
562       IF_META_AVAILABLE(cam_sensor_params_t, l_sensor_params,
563           CAM_INTF_META_SENSOR_INFO, p_meta) {
564         p_sensor_params = *l_sensor_params;
565         is_sensor_meta_valid = true;
566       }
567     } else {
568       /* HAL V3 */
569       IF_META_AVAILABLE(int32_t, iso, CAM_INTF_META_SENSOR_SENSITIVITY, p_meta) {
570         p_3a_params.iso_value= *iso;
571       } else {
572         LOGE("Cannot extract Iso value");
573       }
574 
575       IF_META_AVAILABLE(int64_t, sensor_exposure_time,
576           CAM_INTF_META_SENSOR_EXPOSURE_TIME, p_meta) {
577         p_3a_params.exp_time =
578           (float)((double)(*sensor_exposure_time) / 1000000000.0);
579       } else {
580         LOGE("Cannot extract Exp time value");
581       }
582 
583       IF_META_AVAILABLE(int32_t, wb_mode, CAM_INTF_PARM_WHITE_BALANCE, p_meta) {
584         p_3a_params.wb_mode = *wb_mode;
585       } else {
586         LOGE("Cannot extract white balance mode");
587       }
588 
589       /* Process sensor data */
590       IF_META_AVAILABLE(float, aperture, CAM_INTF_META_LENS_APERTURE, p_meta) {
591         p_sensor_params.aperture_value = *aperture;
592       } else {
593         LOGE("Cannot extract Aperture value");
594       }
595 
596       IF_META_AVAILABLE(uint32_t, flash_mode, CAM_INTF_META_FLASH_MODE, p_meta) {
597         p_sensor_params.flash_mode = *flash_mode;
598       } else {
599         LOGE("Cannot extract flash mode value");
600       }
601 
602       IF_META_AVAILABLE(int32_t, flash_state, CAM_INTF_META_FLASH_STATE, p_meta) {
603         p_sensor_params.flash_state = (cam_flash_state_t) *flash_state;
604       } else {
605         LOGE("Cannot extract flash state value");
606       }
607     }
608   }
609 
610   /* take the cached values if meta is invalid */
611   if ((!is_3a_meta_valid) && (hal_version == CAM_HAL_V1)) {
612     p_3a_params = p_cam_exif_params->cam_3a_params;
613     LOGW("Warning using cached values for 3a");
614   }
615 
616   if ((!is_sensor_meta_valid) && (hal_version == CAM_HAL_V1)) {
617     p_sensor_params = p_cam_exif_params->sensor_params;
618     LOGW("Warning using cached values for sensor");
619   }
620 
621   if ((hal_version != CAM_HAL_V1) || (p_sensor_params.sens_type != CAM_SENSOR_YUV)) {
622     rc = process_3a_data(&p_3a_params, exif_info);
623     if (rc) {
624       LOGE("Failed to add 3a exif params");
625     }
626   }
627 
628   rc = process_sensor_data(&p_sensor_params, exif_info);
629   if (rc) {
630     LOGE("Failed to extract sensor params");
631   }
632 
633   if (p_meta) {
634     short val_short = 0;
635     cam_asd_decision_t *scene_info = NULL;
636 
637     IF_META_AVAILABLE(cam_asd_decision_t, scene_cap_type,
638         CAM_INTF_META_ASD_SCENE_INFO, p_meta) {
639       scene_info = (cam_asd_decision_t*)scene_cap_type;
640       val_short = (short) scene_info->detected_scene;
641     }
642 
643     rc = addExifEntry(exif_info, EXIFTAGID_SCENE_CAPTURE_TYPE, EXIF_SHORT,
644       sizeof(val_short)/2, &val_short);
645     if (rc) {
646       LOGE(": Error adding ASD Exif Entry");
647     }
648   } else {
649     LOGE(": Error adding ASD Exif Entry, no meta");
650   }
651   return rc;
652 }
653