QCamera3HWI.cpp revision 625515beb9c1347216a2d261930ceb0d85ba1c47
1/* Copyright (c) 2012-2013, The Linux Foundataion. 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#define LOG_TAG "QCamera3HWI"
31
32#include <cutils/properties.h>
33#include <hardware/camera3.h>
34#include <camera/CameraMetadata.h>
35#include <stdlib.h>
36#include <utils/Log.h>
37#include <utils/Errors.h>
38#include <gralloc_priv.h>
39#include "QCamera3HWI.h"
40#include "QCamera3Mem.h"
41#include "QCamera3Channel.h"
42
43using namespace android;
44
45//using namespace android;
46namespace qcamera {
47#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
48cam_capability_t *gCamCapability[MM_CAMERA_MAX_NUM_SENSORS];
49const camera_metadata_t *gStaticMetadata;
50
51
52camera3_device_ops_t QCamera3HardwareInterface::mCameraOps = {
53    initialize:                         QCamera3HardwareInterface::initialize,
54    configure_streams:                  QCamera3HardwareInterface::configure_streams,
55    register_stream_buffers:            QCamera3HardwareInterface::register_stream_buffers,
56    construct_default_request_settings: QCamera3HardwareInterface::construct_default_request_settings,
57    process_capture_request:            QCamera3HardwareInterface::process_capture_request,
58    get_metadata_vendor_tag_ops:        QCamera3HardwareInterface::get_metadata_vendor_tag_ops,
59    dump:                               QCamera3HardwareInterface::dump,
60};
61
62
63/*===========================================================================
64 * FUNCTION   : QCamera3HardwareInterface
65 *
66 * DESCRIPTION: constructor of QCamera3HardwareInterface
67 *
68 * PARAMETERS :
69 *   @cameraId  : camera ID
70 *
71 * RETURN     : none
72 *==========================================================================*/
73QCamera3HardwareInterface::QCamera3HardwareInterface(int cameraId)
74    : mCameraId(cameraId),
75      mCameraHandle(NULL),
76      mCameraOpened(false),
77      mCallbackOps(NULL)
78{
79    mCameraDevice.common.tag = HARDWARE_DEVICE_TAG;
80    mCameraDevice.common.version = CAMERA_DEVICE_API_VERSION_2_0;
81    //mCameraDevice.common.close = close_camera_device;
82    mCameraDevice.ops = &mCameraOps;
83    mCameraDevice.priv = this;
84    gCamCapability[cameraId]->version = CAM_HAL_V3;
85}
86
87/*===========================================================================
88 * FUNCTION   : ~QCamera3HardwareInterface
89 *
90 * DESCRIPTION: destructor of QCamera2HardwareInterface
91 *
92 * PARAMETERS : none
93 *
94 * RETURN     : none
95 *==========================================================================*/
96QCamera3HardwareInterface::~QCamera3HardwareInterface()
97{
98    closeCamera();
99}
100
101/*===========================================================================
102 * FUNCTION   : openCamera
103 *
104 * DESCRIPTION: open camera
105 *
106 * PARAMETERS :
107 *   @hw_device  : double ptr for camera device struct
108 *
109 * RETURN     : int32_t type of status
110 *              NO_ERROR  -- success
111 *              none-zero failure code
112 *==========================================================================*/
113int QCamera3HardwareInterface::openCamera(struct hw_device_t **hw_device)
114{
115    //int rc = NO_ERROR;
116    int rc = 0;
117    if (mCameraOpened) {
118        *hw_device = NULL;
119        return PERMISSION_DENIED;
120    }
121
122    rc = openCamera();
123    if (rc == 0)
124        *hw_device = &mCameraDevice.common;
125    else
126        *hw_device = NULL;
127    return rc;
128}
129
130/*===========================================================================
131 * FUNCTION   : openCamera
132 *
133 * DESCRIPTION: open camera
134 *
135 * PARAMETERS : none
136 *
137 * RETURN     : int32_t type of status
138 *              NO_ERROR  -- success
139 *              none-zero failure code
140 *==========================================================================*/
141int QCamera3HardwareInterface::openCamera()
142{
143    if (mCameraHandle) {
144        ALOGE("Failure: Camera already opened");
145        return ALREADY_EXISTS;
146    }
147    mCameraHandle = camera_open(mCameraId);
148    if (!mCameraHandle) {
149        ALOGE("camera_open failed.");
150        return UNKNOWN_ERROR;
151    }
152
153    mCameraOpened = true;
154
155    return NO_ERROR;
156}
157
158/*===========================================================================
159 * FUNCTION   : closeCamera
160 *
161 * DESCRIPTION: close camera
162 *
163 * PARAMETERS : none
164 *
165 * RETURN     : int32_t type of status
166 *              NO_ERROR  -- success
167 *              none-zero failure code
168 *==========================================================================*/
169int QCamera3HardwareInterface::closeCamera()
170{
171    int rc = NO_ERROR;
172
173    rc = mCameraHandle->ops->close_camera(mCameraHandle->camera_handle);
174    mCameraHandle = NULL;
175    mCameraOpened = false;
176
177    return rc;
178}
179
180/*===========================================================================
181 * FUNCTION   : sendCaptureResult
182 *
183 * DESCRIPTION: send completed capture result metadata buffer along with possibly
184 *              completed output stream buffers to the framework
185 *
186 * PARAMETERS :
187 *
188 * RETURN     :
189 *==========================================================================*/
190void QCamera3HardwareInterface::sendCaptureResult(const struct camera3_callback_ops *,
191                                                 const camera3_capture_result_t *result)
192{
193    //TODO - Implement
194}
195
196/*===========================================================================
197 * FUNCTION   : notify
198 *
199 * DESCRIPTION: Asynchronous notification callback to framework
200 *
201 * PARAMETERS :
202 *
203 * RETURN     :
204 *
205 *
206 *==========================================================================*/
207
208void QCamera3HardwareInterface::notify(const struct camera3_callback_ops *,
209                                       const camera3_notify_msg_t *msg)
210{
211    //TODO - Implement
212}
213
214
215/*===========================================================================
216 * FUNCTION   : initialize
217 *
218 * DESCRIPTION: Initialize frameworks callback functions
219 *
220 * PARAMETERS :
221 *   @callback_ops : callback function to frameworks
222 *
223 * RETURN     :
224 *
225 *==========================================================================*/
226int QCamera3HardwareInterface::initialize(
227        const struct camera3_callback_ops *callback_ops)
228{
229    mCallbackOps = callback_ops;
230
231    //TODO:Create metadata channel and initialize it
232    mMetadataChannel = new QCamera3MetadataChannel(mCameraHandle->camera_handle,
233                                        mCameraHandle->ops, channelCbRoutine);
234    if (mMetadataChannel == NULL) {
235        ALOGE("%s: failed to allocate metadata channel", __func__);
236        return -ENOMEM;
237    }
238    return mMetadataChannel->initialize();
239}
240
241/*===========================================================================
242 * FUNCTION   : configureStreams
243 *
244 * DESCRIPTION: Reset HAL camera device processing pipeline and set up new input
245 *              and output streams.
246 *
247 * PARAMETERS :
248 *   @stream_list : streams to be configured
249 *
250 * RETURN     :
251 *
252 *==========================================================================*/
253int QCamera3HardwareInterface::configureStreams(
254        camera3_stream_configuration_t *streamList)
255{
256    // Sanity check stream_list
257    if (streamList == NULL) {
258        ALOGE("%s: NULL stream configuration", __func__);
259        return BAD_VALUE;
260    }
261
262    if (streamList->streams == NULL) {
263        ALOGE("%s: NULL stream list", __func__);
264        return BAD_VALUE;
265    }
266
267    if (streamList->num_streams < 1) {
268        ALOGE("%s: Bad number of streams requested: %d", __func__,
269                streamList->num_streams);
270        return BAD_VALUE;
271    }
272
273    camera3_stream_t *inputStream = NULL;
274    for (size_t i = 0; i < streamList->num_streams; i++) {
275        camera3_stream_t *newStream = streamList->streams[i];
276        if (newStream->stream_type == CAMERA3_STREAM_INPUT) {
277            if (inputStream != NULL) {
278                ALOGE("%s: Multiple input streams requested!", __func__);
279                return BAD_VALUE;
280            }
281            inputStream = newStream;
282        }
283    }
284    mInputStream = inputStream;
285
286    /* TODO: Clean up no longer used streams, and maintain others if this
287     * is not the 1st time configureStreams is called */
288
289    /* TODO: Reconstruct/reset metadata stream/channel */
290
291    /* Allocate channel objects for the requested streams */
292    for (size_t i = 0; i < streamList->num_streams; i++) {
293        camera3_stream_t *newStream = streamList->streams[i];
294        if (newStream->priv == NULL) {
295            //New stream, construct channel
296
297            switch (newStream->stream_type) {
298            case CAMERA3_STREAM_INPUT:
299                newStream->usage = GRALLOC_USAGE_HW_CAMERA_READ;
300                newStream->max_buffers = QCamera3PicChannel::kMaxBuffers;
301                break;
302            case CAMERA3_STREAM_BIDIRECTIONAL:
303                newStream->usage = GRALLOC_USAGE_HW_CAMERA_READ |
304                    GRALLOC_USAGE_HW_CAMERA_WRITE;
305                newStream->max_buffers = QCamera3RegularChannel::kMaxBuffers;
306                break;
307            case CAMERA3_STREAM_OUTPUT:
308                newStream->usage = GRALLOC_USAGE_HW_CAMERA_WRITE;
309                newStream->max_buffers = QCamera3RegularChannel::kMaxBuffers;
310                break;
311            default:
312                ALOGE("%s: Invalid stream_type %d", __func__, newStream->stream_type);
313                break;
314            }
315
316            if (newStream->stream_type == CAMERA3_STREAM_OUTPUT ||
317                newStream->stream_type == CAMERA3_STREAM_BIDIRECTIONAL) {
318                QCamera3Channel *channel;
319                switch (newStream->format) {
320                case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
321                    channel = new QCamera3RegularChannel(mCameraHandle->camera_handle,
322                            mCameraHandle->ops, channelCbRoutine, newStream);
323                    if (channel == NULL) {
324                        ALOGE("%s: allocation of channel failed", __func__);
325                        return -ENOMEM;
326                    }
327
328                    newStream->priv = channel;
329                    break;
330                case HAL_PIXEL_FORMAT_BLOB:
331                    channel = new QCamera3PicChannel(mCameraHandle->camera_handle,
332                            mCameraHandle->ops, channelCbRoutine, newStream);
333                    if (channel == NULL) {
334                        ALOGE("%s: allocation of channel failed", __func__);
335                        return -ENOMEM;
336                    }
337
338                    newStream->priv = channel;
339                    break;
340
341                //TODO: Add support for app consumed format?
342                default:
343                    ALOGE("%s: not a supported format 0x%x", __func__, newStream->format);
344                    break;
345                }
346            }
347        } else {
348            // Channel already exists for this stream
349            // Do nothing for now
350        }
351    }
352    return 0;
353}
354
355/*===========================================================================
356 * FUNCTION   : registerStreamBuffers
357 *
358 * DESCRIPTION: Register buffers for a given stream with the HAL device.
359 *
360 * PARAMETERS :
361 *   @stream_list : streams to be configured
362 *
363 * RETURN     :
364 *
365 *==========================================================================*/
366int QCamera3HardwareInterface::registerStreamBuffers(
367        const camera3_stream_buffer_set_t *buffer_set)
368{
369    int rc = 0;
370    if (buffer_set == NULL) {
371        ALOGE("%s: Invalid buffer_set parameter.", __func__);
372        return -EINVAL;
373    }
374    if (buffer_set->stream == NULL) {
375        ALOGE("%s: Invalid stream parameter.", __func__);
376        return -EINVAL;
377    }
378    if (buffer_set->num_buffers < 1) {
379        ALOGE("%s: Invalid num_buffers %d.", __func__, buffer_set->num_buffers);
380        return -EINVAL;
381    }
382    if (buffer_set->buffers == NULL) {
383        ALOGE("%s: Invalid buffers parameter.", __func__);
384        return -EINVAL;
385    }
386
387    for (size_t i = 0; i < buffer_set->num_buffers; i++) {
388        camera3_stream_t *stream = buffer_set->stream;
389        QCamera3Channel *channel = (QCamera3Channel *)stream->priv;
390
391        if (stream->stream_type != CAMERA3_STREAM_OUTPUT) {
392            ALOGE("%s: not yet support non output type stream", __func__);
393            return -EINVAL;
394        }
395        rc = channel->registerBuffers(buffer_set->num_buffers, buffer_set->buffers);
396        if (rc < 0) {
397            ALOGE("%s: registerBUffers for stream %p failed", __func__, stream);
398            return -ENODEV;
399        }
400    }
401    return NO_ERROR;
402}
403
404#define DATA_PTR(MEM_OBJ,INDEX) MEM_OBJ->getPtr( INDEX )
405/*===========================================================================
406 * FUNCTION   : initCapabilities
407 *
408 * DESCRIPTION: initialize camera capabilities in static data struct
409 *
410 * PARAMETERS :
411 *   @cameraId  : camera Id
412 *
413 * RETURN     : int32_t type of status
414 *              NO_ERROR  -- success
415 *              none-zero failure code
416 *==========================================================================*/
417int QCamera3HardwareInterface::initCapabilities(int cameraId)
418{
419    int rc = 0;
420    mm_camera_vtbl_t *cameraHandle = NULL;
421    QCamera3HeapMemory *capabilityHeap = NULL;
422
423    cameraHandle = camera_open(cameraId);
424    if (!cameraHandle) {
425        ALOGE("%s: camera_open failed", __func__);
426        rc = -1;
427        goto open_failed;
428    }
429
430    /* Allocate memory for capability buffer */
431    capabilityHeap = new QCamera3HeapMemory();
432    rc = capabilityHeap->allocate(1, sizeof(cam_capability_t), false);
433    if(rc != OK) {
434        ALOGE("%s: No memory for cappability", __func__);
435        goto allocate_failed;
436    }
437
438    /* Map memory for capability buffer */
439    memset(DATA_PTR(capabilityHeap,0), 0, sizeof(cam_capability_t));
440    rc = cameraHandle->ops->map_buf(cameraHandle->camera_handle,
441                                CAM_MAPPING_BUF_TYPE_CAPABILITY,
442                                capabilityHeap->getFd(0),
443                                sizeof(cam_capability_t));
444    if(rc < 0) {
445        ALOGE("%s: failed to map capability buffer", __func__);
446        goto map_failed;
447    }
448
449    /* Query Capability */
450    rc = cameraHandle->ops->query_capability(cameraHandle->camera_handle);
451    if(rc < 0) {
452        ALOGE("%s: failed to query capability",__func__);
453        goto query_failed;
454    }
455    gCamCapability[cameraId] = (cam_capability_t *)malloc(sizeof(cam_capability_t));
456    if (!gCamCapability[cameraId]) {
457        ALOGE("%s: out of memory", __func__);
458        goto query_failed;
459    }
460    memcpy(gCamCapability[cameraId], DATA_PTR(capabilityHeap,0),
461                                        sizeof(cam_capability_t));
462    rc = 0;
463
464query_failed:
465    cameraHandle->ops->unmap_buf(cameraHandle->camera_handle,
466                            CAM_MAPPING_BUF_TYPE_CAPABILITY);
467map_failed:
468    capabilityHeap->deallocate();
469    delete capabilityHeap;
470allocate_failed:
471    cameraHandle->ops->close_camera(cameraHandle->camera_handle);
472    cameraHandle = NULL;
473open_failed:
474    return rc;
475}
476
477/*===========================================================================
478 * FUNCTION   : initStaticMetadata
479 *
480 * DESCRIPTION: initialize the static metadata
481 *
482 * PARAMETERS :
483 *   @cameraId  : camera Id
484 *
485 * RETURN     : int32_t type of status
486 *              0  -- success
487 *              non-zero failure code
488 *==========================================================================*/
489int QCamera3HardwareInterface::initStaticMetadata(int cameraId)
490{
491    int rc = 0;
492    android::CameraMetadata staticInfo;
493
494    staticInfo.update(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE,
495                    &gCamCapability[cameraId]->min_focus_distance, 1);
496
497    staticInfo.update(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE,
498                    &gCamCapability[cameraId]->hyper_focal_distance, 1);
499
500    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS,
501                      gCamCapability[cameraId]->focal_lengths,
502                      gCamCapability[cameraId]->focal_lengths_count);
503
504
505    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_APERTURES,
506                      gCamCapability[cameraId]->apertures,
507                      gCamCapability[cameraId]->apertures_count);
508
509    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES,
510                gCamCapability[cameraId]->filter_densities,
511                gCamCapability[cameraId]->filter_densities_count);
512
513
514    staticInfo.update(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
515                      (int*)gCamCapability[cameraId]->optical_stab_modes,
516                      gCamCapability[cameraId]->optical_stab_modes_count);
517
518
519   /* staticInfo.update(ANDROID_LENS_INFO_SHADING_MAP_SIZE,
520                      gCamCapability[cameraId]->lens_shading_map_size,
521                      sizeof(cam_dimension_t)/sizeof(int32_t)); */
522
523    staticInfo.update(ANDROID_LENS_POSITION,
524                gCamCapability[cameraId]->lens_position,
525                sizeof(gCamCapability[cameraId]->lens_position)/ sizeof(float));
526
527
528    gStaticMetadata = staticInfo.release();
529    return rc;
530}
531
532/*===========================================================================
533 * FUNCTION   : getCapabilities
534 *
535 * DESCRIPTION: query camera capabilities
536 *
537 * PARAMETERS :
538 *   @cameraId  : camera Id
539 *   @info      : camera info struct to be filled in with camera capabilities
540 *
541 * RETURN     : int32_t type of status
542 *              NO_ERROR  -- success
543 *              none-zero failure code
544 *==========================================================================*/
545int QCamera3HardwareInterface::getCamInfo(int cameraId,
546                                    struct camera_info *info)
547{
548    int rc = 0;
549
550    if (NULL == gCamCapability[cameraId]) {
551        rc = initCapabilities(cameraId);
552        if (rc < 0) {
553            //pthread_mutex_unlock(&g_camlock);
554            return rc;
555        }
556    }
557
558    if (NULL == gStaticMetadata) {
559        rc = initStaticMetadata(cameraId);
560        if (rc < 0) {
561            return rc;
562        }
563    }
564
565    switch(gCamCapability[cameraId]->position) {
566    case CAM_POSITION_BACK:
567        info->facing = CAMERA_FACING_BACK;
568        break;
569
570    case CAM_POSITION_FRONT:
571        info->facing = CAMERA_FACING_FRONT;
572        break;
573
574    default:
575        ALOGE("%s:Unknown position type for camera id:%d", __func__, cameraId);
576        rc = -1;
577        break;
578    }
579
580
581    info->orientation = gCamCapability[cameraId]->sensor_mount_angle;
582
583    info->static_camera_characteristics = gStaticMetadata;
584
585    return rc;
586}
587#if 0
588/*===========================================================================
589 * FUNCTION   : getMetadata
590 *
591 * DESCRIPTION: query camera metadata
592 *
593 * PARAMETERS :
594 *   @cameraId  : camera Id
595 *   @info      : camera info struct to be filled in with camera metadata
596 *
597 * RETURN     : int32_t type of status
598 *              NO_ERROR  -- success
599 *              none-zero failure code
600 *==========================================================================*/
601int QCamera3HardwareInterface::getMetadata(int type)
602{
603    QCamera3HeapMemory *metadataHeap = NULL;
604    int rc = 0;
605
606    metadataHeap = new QCamera3HeapMemory();
607    rc = metadataHeap->allocate(1, sizeof(metadata_type_t));
608    if(rc != 0) {
609        ALOGE("%s: No memory for metadata", __func__);
610    }
611
612    rc = mCameraHandle->ops->map_buf(mCameraHandle->camera_handle,
613                                CAM_MAPPING_BUF_TYPE_CAPABILITY,
614                                metadataHeap->getFd(0),
615                                sizeof(metadata_type_t));
616    if(rc < 0) {
617        ALOGE("%s: failed to map capability buffer", __func__);
618        metadataHeap->deallocate();
619        delete metadataHeap;
620    }
621
622       /* Query Metadata */
623    //rc = cameraHandle->ops->query_metadata(cameraHandle->camera_handle, type);
624    rc = mCameraHandle->ops->query_capability(mCameraHandle->camera_handle);
625
626    if(rc < 0) {
627        ALOGE("%s: failed to query metadata",__func__);
628        mCameraHandle->ops->unmap_buf(mCameraHandle->camera_handle,
629                                     CAM_MAPPING_BUF_TYPE_CAPABILITY);
630    }
631    /*delete the old metadata saved in the HAL*/
632    if (curr_metadata != NULL) {
633        free(curr_metadata);
634        curr_metadata = NULL;
635    }
636    curr_metadata = (metadata_type_t *)malloc(sizeof(metadata_type_t));
637    if (!curr_metadata) {
638        ALOGE("%s: out of memory", __func__);
639        mCameraHandle->ops->unmap_buf(mCameraHandle->camera_handle,
640                                     CAM_MAPPING_BUF_TYPE_CAPABILITY);
641    }
642    memcpy(curr_metadata, DATA_PTR(metadataHeap,0),
643            sizeof(metadata_type_t));
644
645    //metadata now saved in the HAL - still need to copy over to correct
646    //format and send to fwk
647    return rc;
648}
649#endif
650/*===========================================================================
651 * FUNCTION   : translateMetadata
652 *
653 * DESCRIPTION: translate the metadata into camera_metadata_t
654 *
655 * PARAMETERS : type of the request
656 *
657 *
658 * RETURN     : success: camera_metadata_t*
659 *              failure: NULL
660 *
661 *==========================================================================*/
662camera_metadata_t* QCamera3HardwareInterface::translateMetadata(int type)
663{
664    if (mDefaultMetadata[type] != NULL) {
665        return mDefaultMetadata[type];
666    }
667    //first time we are handling this request
668    //fill up the metadata structure using the wrapper class
669    android::CameraMetadata settings;
670    //translate from cam_capability_t to camera_metadata_tag_t
671    static const uint8_t requestType = ANDROID_REQUEST_TYPE_CAPTURE;
672    settings.update(ANDROID_REQUEST_TYPE, &requestType, 1);
673
674    /*control*/
675
676    uint8_t controlIntent = 0;
677    switch (type) {
678      case CAMERA3_TEMPLATE_PREVIEW:
679        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
680        break;
681      case CAMERA3_TEMPLATE_STILL_CAPTURE:
682        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
683        break;
684      case CAMERA3_TEMPLATE_VIDEO_RECORD:
685        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
686        break;
687      case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT:
688        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT;
689        break;
690      case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG:
691        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG;
692        break;
693      default:
694        controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM;
695        break;
696    }
697    settings.update(ANDROID_CONTROL_CAPTURE_INTENT, &controlIntent, 1);
698
699    settings.update(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, &gCamCapability[mCameraId]->exposure_compensation_default, 1);
700
701    static const uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF;
702    settings.update(ANDROID_CONTROL_AE_LOCK, &aeLock, 1);
703
704    static const uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF;
705    settings.update(ANDROID_CONTROL_AWB_LOCK, &awbLock, 1);
706
707    static const uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO;
708    settings.update(ANDROID_CONTROL_AWB_MODE, &awbMode, 1);
709
710    static const uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO;
711    settings.update(ANDROID_CONTROL_MODE, &controlMode, 1);
712
713    static const uint8_t effectMode = ANDROID_CONTROL_EFFECT_MODE_OFF;
714    settings.update(ANDROID_CONTROL_EFFECT_MODE, &effectMode, 1);
715
716    static const uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY; //similar to AUTO?
717    settings.update(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1);
718
719    /*flash*/
720    static const uint8_t flashMode = ANDROID_FLASH_MODE_OFF;
721    settings.update(ANDROID_FLASH_MODE, &flashMode, 1);
722
723
724    /* lens */
725    static const float default_aperture = gCamCapability[mCameraId]->apertures[0];
726    settings.update(ANDROID_LENS_APERTURE, &default_aperture, 1);
727
728    static const float default_filter_density = gCamCapability[mCameraId]->filter_densities[0];
729    settings.update(ANDROID_LENS_FILTER_DENSITY, &default_filter_density, 1);
730
731    static const float default_focal_length = gCamCapability[mCameraId]->focal_lengths[0];
732    settings.update(ANDROID_LENS_FOCAL_LENGTH, &default_focal_length, 1);
733
734
735    /* scalar */
736    //settings.update(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS, &gCamCapability[mCameraId]->min_duration, 1);
737    //settings.update(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, &gCamCapability[mCameraId]->raw_min_duration, 1);
738
739
740
741    mDefaultMetadata[type] = settings.release();
742    return mDefaultMetadata[type];
743}
744
745/*===========================================================================
746 * FUNCTION   : channelCbRoutine
747 *
748 * DESCRIPTION: Callback handler for all channels (streams, as well as metadata)
749 *
750 * PARAMETERS :
751 *   @frame  : frame information from mm-camera-interface
752 *   @buffer : actual gralloc buffer to be returned to frameworks. NULL if metadata.
753 *   @userdata: userdata
754 *
755 * RETURN     : NONE
756 *==========================================================================*/
757void QCamera3HardwareInterface::channelCbRoutine(mm_camera_buf_def_t *frame,
758                camera3_stream_buffer_t *buffer, void *userdata)
759{
760    QCamera3HardwareInterface *hw = (QCamera3HardwareInterface *)userdata;
761    if (hw == NULL) {
762        ALOGE("%s: Invalid hw %p", __func__, hw);
763        return;
764    }
765
766    //TODO: Gives frame and buffer to buffer aggregator.
767
768    return;
769}
770
771/*===========================================================================
772 * FUNCTION   : initialize
773 *
774 * DESCRIPTION: Pass framework callback pointers to HAL
775 *
776 * PARAMETERS :
777 *
778 *
779 * RETURN     : Success : 0
780 *              Failure: -ENODEV
781 *==========================================================================*/
782
783int QCamera3HardwareInterface::initialize(const struct camera3_device *device,
784                                  const camera3_callback_ops_t *callback_ops)
785{
786    QCamera3HardwareInterface *hw =
787        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
788    if (!hw) {
789        ALOGE("%s: NULL camera device", __func__);
790        return -ENODEV;
791    }
792
793    return hw->initialize(callback_ops);
794}
795
796/*===========================================================================
797 * FUNCTION   : configure_streams
798 *
799 * DESCRIPTION:
800 *
801 * PARAMETERS :
802 *
803 *
804 * RETURN     : Success: 0
805 *              Failure: -EINVAL (if stream configuration is invalid)
806 *                       -ENODEV (fatal error)
807 *==========================================================================*/
808
809int QCamera3HardwareInterface::configure_streams(
810        const struct camera3_device *device,
811        camera3_stream_configuration_t *stream_list)
812{
813    QCamera3HardwareInterface *hw =
814        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
815    if (!hw) {
816        ALOGE("%s: NULL camera device", __func__);
817        return -ENODEV;
818    }
819    return hw->configureStreams(stream_list);
820}
821
822/*===========================================================================
823 * FUNCTION   : register_stream_buffers
824 *
825 * DESCRIPTION: Register stream buffers with the device
826 *
827 * PARAMETERS :
828 *
829 * RETURN     :
830 *==========================================================================*/
831int QCamera3HardwareInterface::register_stream_buffers(
832        const struct camera3_device *device,
833        const camera3_stream_buffer_set_t *buffer_set)
834{
835    QCamera3HardwareInterface *hw =
836        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
837    if (!hw) {
838        ALOGE("%s: NULL camera device", __func__);
839        return -ENODEV;
840    }
841    return hw->registerStreamBuffers(buffer_set);
842}
843
844/*===========================================================================
845 * FUNCTION   : construct_default_request_settings
846 *
847 * DESCRIPTION: Configure a settings buffer to meet the required use case
848 *
849 * PARAMETERS :
850 *
851 *
852 * RETURN     : Success: Return valid metadata
853 *              Failure: Return NULL
854 *==========================================================================*/
855const camera_metadata_t* QCamera3HardwareInterface::construct_default_request_settings
856(const struct camera3_device *device, int type)
857{
858
859    camera_metadata_t* fwk_metadata = NULL;
860    QCamera3HardwareInterface *hw =
861        reinterpret_cast<QCamera3HardwareInterface *>(device->priv);
862    if (!hw) {
863        ALOGE("%s: NULL camera device", __func__);
864        return NULL;
865    }
866
867    fwk_metadata = hw->translateMetadata(type);
868
869    return fwk_metadata;
870}
871
872/*===========================================================================
873 * FUNCTION   : process_capture_request
874 *
875 * DESCRIPTION:
876 *
877 * PARAMETERS :
878 *
879 *
880 * RETURN     :
881 *==========================================================================*/
882int QCamera3HardwareInterface::process_capture_request(const struct camera3_device *,
883                                                       camera3_capture_request_t *request)
884{
885    /*TODO - Implement*/
886    return 0;
887}
888
889/*===========================================================================
890 * FUNCTION   : get_metadata_vendor_tag_ops
891 *
892 * DESCRIPTION:
893 *
894 * PARAMETERS :
895 *
896 *
897 * RETURN     :
898 *==========================================================================*/
899
900void QCamera3HardwareInterface::get_metadata_vendor_tag_ops(const struct camera3_device *,
901                                                           vendor_tag_query_ops_t* ops)
902{
903    /*TODO - Implement*/
904}
905
906/*===========================================================================
907 * FUNCTION   : dump
908 *
909 * DESCRIPTION:
910 *
911 * PARAMETERS :
912 *
913 *
914 * RETURN     :
915 *==========================================================================*/
916
917void QCamera3HardwareInterface::dump(const struct camera3_device *, int fd)
918{
919    /*TODO - Implement*/
920}
921
922}; //end namespace qcamera
923